Skip to content
Permalink
Browse files
IsSynchronizingStyleAttributeFlag could be purged.
<http://webkit.org/b/79313>

Reviewed by Anders Carlsson.

We were using IsSynchronizingStyleAttributeFlag to prevent various things from
happening below setAttribute() when serializing the "style" attribute based on
an element's inline style.

Simplify the whole thing by adding a way to set an attribute without triggering
any callbacks (a 'notifyChanged' argument to Element::setAttribute().)
This removes the need for IsSynchronizingStyleAttributeFlag in the first place
and makes StyledElement::updateStyleAttribute() a bit cheaper to boot.

* dom/Element.cpp:
(WebCore::Element::setAttribute):
(WebCore::Element::setAttributeInternal):
(WebCore::Element::willModifyAttribute):
(WebCore::Element::didModifyAttribute):
(WebCore::Element::didRemoveAttribute):
* dom/Element.h:
* dom/Node.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateStyleAttribute):
(WebCore::StyledElement::attributeChanged):
* html/HTMLElement.cpp:
(WebCore::StyledElement::copyNonAttributeProperties):


Canonical link: https://commits.webkit.org/97038@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@109285 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Mar 1, 2012
1 parent f51a582 commit 0969043ce473e9bc81aee9089fa37e89912525c2
Showing with 58 additions and 42 deletions.
  1. +30 −0 Source/WebCore/ChangeLog
  2. +14 −19 Source/WebCore/dom/Element.cpp
  3. +2 −2 Source/WebCore/dom/Element.h
  4. +9 −14 Source/WebCore/dom/Node.h
  5. +2 −5 Source/WebCore/dom/StyledElement.cpp
  6. +1 −2 Source/WebCore/html/HTMLElement.cpp
@@ -1,3 +1,33 @@
2012-02-29 Andreas Kling <awesomekling@apple.com>

IsSynchronizingStyleAttributeFlag could be purged.
<http://webkit.org/b/79313>

Reviewed by Anders Carlsson.

We were using IsSynchronizingStyleAttributeFlag to prevent various things from
happening below setAttribute() when serializing the "style" attribute based on
an element's inline style.

Simplify the whole thing by adding a way to set an attribute without triggering
any callbacks (a 'notifyChanged' argument to Element::setAttribute().)
This removes the need for IsSynchronizingStyleAttributeFlag in the first place
and makes StyledElement::updateStyleAttribute() a bit cheaper to boot.

* dom/Element.cpp:
(WebCore::Element::setAttribute):
(WebCore::Element::setAttributeInternal):
(WebCore::Element::willModifyAttribute):
(WebCore::Element::didModifyAttribute):
(WebCore::Element::didRemoveAttribute):
* dom/Element.h:
* dom/Node.h:
* dom/StyledElement.cpp:
(WebCore::StyledElement::updateStyleAttribute):
(WebCore::StyledElement::attributeChanged):
* html/HTMLElement.cpp:
(WebCore::StyledElement::copyNonAttributeProperties):

2012-02-29 Daniel Cheng <dcheng@chromium.org>

[chromium] REGRESSION: Cannot drag a file out
@@ -624,12 +624,12 @@ void Element::setAttribute(const AtomicString& name, const AtomicString& value,
setAttributeInternal(index, qName, value);
}

void Element::setAttribute(const QualifiedName& name, const AtomicString& value)
void Element::setAttribute(const QualifiedName& name, const AtomicString& value, bool notifyChanged)
{
setAttributeInternal(ensureUpdatedAttributeData()->getAttributeItemIndex(name), name, value);
setAttributeInternal(ensureUpdatedAttributeData()->getAttributeItemIndex(name), name, value, notifyChanged);
}

inline void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& value)
inline void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& value, bool notifyChanged)
{
ElementAttributeData* attributeData = &m_attributeMap->m_attributeData;
Attribute* old = index != notFound ? attributeData->attributeItem(index) : 0;
@@ -644,14 +644,16 @@ inline void Element::setAttributeInternal(size_t index, const QualifiedName& nam
return;
}

willModifyAttribute(name, old ? old->value() : nullAtom, value);
if (notifyChanged)
willModifyAttribute(name, old ? old->value() : nullAtom, value);

if (Attr* attrNode = old->attr())
attrNode->setValue(value);
else
old->setValue(value);

didModifyAttribute(old);
if (notifyChanged)
didModifyAttribute(old);
}

void Element::attributeChanged(Attribute* attr)
@@ -1939,26 +1941,21 @@ void Element::willModifyAttribute(const QualifiedName& name, const AtomicString&
updateName(oldValue, newValue);

#if ENABLE(MUTATION_OBSERVERS)
if (!isSynchronizingStyleAttribute()) {
if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
}
if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
#endif

#if ENABLE(INSPECTOR)
if (!isSynchronizingStyleAttribute())
InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
#endif
}

void Element::didModifyAttribute(Attribute* attr)
{
attributeChanged(attr);

if (!isSynchronizingStyleAttribute()) {
InspectorInstrumentation::didModifyDOMAttr(document(), this, attr->name().localName(), attr->value());
dispatchSubtreeModifiedEvent();
}
InspectorInstrumentation::didModifyDOMAttr(document(), this, attr->name().localName(), attr->value());
dispatchSubtreeModifiedEvent();
}

void Element::didRemoveAttribute(Attribute* attr)
@@ -1971,10 +1968,8 @@ void Element::didRemoveAttribute(Attribute* attr)
attributeChanged(attr);
attr->setValue(savedValue);

if (!isSynchronizingStyleAttribute()) {
InspectorInstrumentation::didRemoveDOMAttr(document(), this, attr->name().localName());
dispatchSubtreeModifiedEvent();
}
InspectorInstrumentation::didRemoveDOMAttr(document(), this, attr->name().localName());
dispatchSubtreeModifiedEvent();
}


@@ -113,7 +113,7 @@ class Element : public ContainerNode {

bool hasAttribute(const QualifiedName&) const;
const AtomicString& getAttribute(const QualifiedName&) const;
void setAttribute(const QualifiedName&, const AtomicString& value);
void setAttribute(const QualifiedName&, const AtomicString& value, bool notifyChanged = true);
void removeAttribute(const QualifiedName&);

// Typed getters and setters for language bindings.
@@ -429,7 +429,7 @@ class Element : public ContainerNode {
virtual NodeType nodeType() const;
virtual bool childTypeAllowed(NodeType) const;

void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value);
void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, bool notifyChanged = true);

#ifndef NDEBUG
virtual void formatForDebugger(char* buffer, unsigned length) const;
@@ -88,7 +88,7 @@ class HTMLPropertiesCollection;

typedef int ExceptionCode;

const int nodeStyleChangeShift = 23;
const int nodeStyleChangeShift = 22;

// SyntheticStyleChange means that we need to go through the entire style change logic even though
// no style property has actually changed. It is used to restructure the tree when, for instance,
@@ -654,22 +654,21 @@ class Node : public EventTarget, public ScriptWrappable, public TreeShared<Conta
// be stored in the same memory word as the Node bits above.
IsParsingChildrenFinishedFlag = 1 << 17, // Element
IsStyleAttributeValidFlag = 1 << 18, // StyledElement
IsSynchronizingStyleAttributeFlag = 1 << 19, // StyledElement
#if ENABLE(SVG)
AreSVGAttributesValidFlag = 1 << 20, // Element
IsSynchronizingSVGAttributesFlag = 1 << 21, // SVGElement
HasSVGRareDataFlag = 1 << 22, // SVGElement
AreSVGAttributesValidFlag = 1 << 19, // Element
IsSynchronizingSVGAttributesFlag = 1 << 20, // SVGElement
HasSVGRareDataFlag = 1 << 21, // SVGElement
#endif

StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),

SelfOrAncestorHasDirAutoFlag = 1 << 25,
HasCustomWillOrDidRecalcStyleFlag = 1 << 26,
HasCustomStyleForRendererFlag = 1 << 27,
SelfOrAncestorHasDirAutoFlag = 1 << 24,
HasCustomWillOrDidRecalcStyleFlag = 1 << 25,
HasCustomStyleForRendererFlag = 1 << 26,

HasNameFlag = 1 << 28,
HasNameFlag = 1 << 27,

AttributeStyleDirtyFlag = 1 << 31,
AttributeStyleDirtyFlag = 1 << 28,

#if ENABLE(SVG)
DefaultNodeFlags = IsParsingChildrenFinishedFlag | IsStyleAttributeValidFlag | AreSVGAttributesValidFlag
@@ -775,10 +774,6 @@ class Node : public EventTarget, public ScriptWrappable, public TreeShared<Conta
void setIsStyleAttributeValid(bool f) { setFlag(f, IsStyleAttributeValidFlag); }
void setIsStyleAttributeValid() const { setFlag(IsStyleAttributeValidFlag); }
void clearIsStyleAttributeValid() { clearFlag(IsStyleAttributeValidFlag); }
bool isSynchronizingStyleAttribute() const { return getFlag(IsSynchronizingStyleAttributeFlag); }
void setIsSynchronizingStyleAttribute(bool f) { setFlag(f, IsSynchronizingStyleAttributeFlag); }
void setIsSynchronizingStyleAttribute() const { setFlag(IsSynchronizingStyleAttributeFlag); }
void clearIsSynchronizingStyleAttribute() const { clearFlag(IsSynchronizingStyleAttributeFlag); }

#if ENABLE(SVG)
bool areSVGAttributesValid() const { return getFlag(AreSVGAttributesValidFlag); }
@@ -50,10 +50,8 @@ void StyledElement::updateStyleAttribute() const
{
ASSERT(!isStyleAttributeValid());
setIsStyleAttributeValid();
setIsSynchronizingStyleAttribute();
if (StylePropertySet* inlineStyle = inlineStyleDecl())
const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->asText());
clearIsSynchronizingStyleAttribute();
const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->asText(), /*notifyChanged*/ false);
}

StyledElement::~StyledElement()
@@ -63,8 +61,7 @@ StyledElement::~StyledElement()

void StyledElement::attributeChanged(Attribute* attr)
{
if (!(attr->name() == styleAttr && isSynchronizingStyleAttribute()))
parseAttribute(attr);
parseAttribute(attr);

if (isPresentationAttribute(attr->name())) {
setAttributeStyleDirty();
@@ -1114,8 +1114,7 @@ void StyledElement::copyNonAttributeProperties(const Element* sourceElement)
inlineStyle->setStrictParsing(source->inlineStyleDecl()->useStrictParsing());

setIsStyleAttributeValid(source->isStyleAttributeValid());
setIsSynchronizingStyleAttribute(source->isSynchronizingStyleAttribute());


Element::copyNonAttributeProperties(sourceElement);
}

0 comments on commit 0969043

Please sign in to comment.