Changeset 109285 in webkit


Ignore:
Timestamp:
Feb 29, 2012 5:03:41 PM (12 years ago)
Author:
kling@webkit.org
Message:

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):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r109280 r109285  
     12012-02-29  Andreas Kling  <awesomekling@apple.com>
     2
     3        IsSynchronizingStyleAttributeFlag could be purged.
     4        <http://webkit.org/b/79313>
     5
     6        Reviewed by Anders Carlsson.
     7
     8        We were using IsSynchronizingStyleAttributeFlag to prevent various things from
     9        happening below setAttribute() when serializing the "style" attribute based on
     10        an element's inline style.
     11
     12        Simplify the whole thing by adding a way to set an attribute without triggering
     13        any callbacks (a 'notifyChanged' argument to Element::setAttribute().)
     14        This removes the need for IsSynchronizingStyleAttributeFlag in the first place
     15        and makes StyledElement::updateStyleAttribute() a bit cheaper to boot.
     16
     17        * dom/Element.cpp:
     18        (WebCore::Element::setAttribute):
     19        (WebCore::Element::setAttributeInternal):
     20        (WebCore::Element::willModifyAttribute):
     21        (WebCore::Element::didModifyAttribute):
     22        (WebCore::Element::didRemoveAttribute):
     23        * dom/Element.h:
     24        * dom/Node.h:
     25        * dom/StyledElement.cpp:
     26        (WebCore::StyledElement::updateStyleAttribute):
     27        (WebCore::StyledElement::attributeChanged):
     28        * html/HTMLElement.cpp:
     29        (WebCore::StyledElement::copyNonAttributeProperties):
     30
    1312012-02-29  Daniel Cheng  <dcheng@chromium.org>
    232
  • trunk/Source/WebCore/dom/Element.cpp

    r109203 r109285  
    625625}
    626626
    627 void Element::setAttribute(const QualifiedName& name, const AtomicString& value)
    628 {
    629     setAttributeInternal(ensureUpdatedAttributeData()->getAttributeItemIndex(name), name, value);
    630 }
    631 
    632 inline void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& value)
     627void Element::setAttribute(const QualifiedName& name, const AtomicString& value, bool notifyChanged)
     628{
     629    setAttributeInternal(ensureUpdatedAttributeData()->getAttributeItemIndex(name), name, value, notifyChanged);
     630}
     631
     632inline void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& value, bool notifyChanged)
    633633{
    634634    ElementAttributeData* attributeData = &m_attributeMap->m_attributeData;
     
    645645    }
    646646
    647     willModifyAttribute(name, old ? old->value() : nullAtom, value);
     647    if (notifyChanged)
     648        willModifyAttribute(name, old ? old->value() : nullAtom, value);
    648649
    649650    if (Attr* attrNode = old->attr())
     
    652653        old->setValue(value);
    653654
    654     didModifyAttribute(old);
     655    if (notifyChanged)
     656        didModifyAttribute(old);
    655657}
    656658
     
    19401942
    19411943#if ENABLE(MUTATION_OBSERVERS)
    1942     if (!isSynchronizingStyleAttribute()) {
    1943         if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
    1944             recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
    1945     }
     1944    if (OwnPtr<MutationObserverInterestGroup> recipients = MutationObserverInterestGroup::createForAttributesMutation(this, name))
     1945        recipients->enqueueMutationRecord(MutationRecord::createAttributes(this, name, oldValue));
    19461946#endif
    19471947
    19481948#if ENABLE(INSPECTOR)
    1949     if (!isSynchronizingStyleAttribute())
    1950         InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
     1949    InspectorInstrumentation::willModifyDOMAttr(document(), this, oldValue, newValue);
    19511950#endif
    19521951}
     
    19561955    attributeChanged(attr);
    19571956
    1958     if (!isSynchronizingStyleAttribute()) {
    1959         InspectorInstrumentation::didModifyDOMAttr(document(), this, attr->name().localName(), attr->value());
    1960         dispatchSubtreeModifiedEvent();
    1961     }
     1957    InspectorInstrumentation::didModifyDOMAttr(document(), this, attr->name().localName(), attr->value());
     1958    dispatchSubtreeModifiedEvent();
    19621959}
    19631960
     
    19721969    attr->setValue(savedValue);
    19731970
    1974     if (!isSynchronizingStyleAttribute()) {
    1975         InspectorInstrumentation::didRemoveDOMAttr(document(), this, attr->name().localName());
    1976         dispatchSubtreeModifiedEvent();
    1977     }
     1971    InspectorInstrumentation::didRemoveDOMAttr(document(), this, attr->name().localName());
     1972    dispatchSubtreeModifiedEvent();
    19781973}
    19791974
  • trunk/Source/WebCore/dom/Element.h

    r109084 r109285  
    114114    bool hasAttribute(const QualifiedName&) const;
    115115    const AtomicString& getAttribute(const QualifiedName&) const;
    116     void setAttribute(const QualifiedName&, const AtomicString& value);
     116    void setAttribute(const QualifiedName&, const AtomicString& value, bool notifyChanged = true);
    117117    void removeAttribute(const QualifiedName&);
    118118
     
    430430    virtual bool childTypeAllowed(NodeType) const;
    431431
    432     void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value);
     432    void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, bool notifyChanged = true);
    433433
    434434#ifndef NDEBUG
  • trunk/Source/WebCore/dom/Node.h

    r109097 r109285  
    8989typedef int ExceptionCode;
    9090
    91 const int nodeStyleChangeShift = 23;
     91const int nodeStyleChangeShift = 22;
    9292
    9393// SyntheticStyleChange means that we need to go through the entire style change logic even though
     
    655655        IsParsingChildrenFinishedFlag = 1 << 17, // Element
    656656        IsStyleAttributeValidFlag = 1 << 18, // StyledElement
    657         IsSynchronizingStyleAttributeFlag = 1 << 19, // StyledElement
    658657#if ENABLE(SVG)
    659         AreSVGAttributesValidFlag = 1 << 20, // Element
    660         IsSynchronizingSVGAttributesFlag = 1 << 21, // SVGElement
    661         HasSVGRareDataFlag = 1 << 22, // SVGElement
     658        AreSVGAttributesValidFlag = 1 << 19, // Element
     659        IsSynchronizingSVGAttributesFlag = 1 << 20, // SVGElement
     660        HasSVGRareDataFlag = 1 << 21, // SVGElement
    662661#endif
    663662
    664663        StyleChangeMask = 1 << nodeStyleChangeShift | 1 << (nodeStyleChangeShift + 1),
    665664
    666         SelfOrAncestorHasDirAutoFlag = 1 << 25,
    667         HasCustomWillOrDidRecalcStyleFlag = 1 << 26,
    668         HasCustomStyleForRendererFlag = 1 << 27,
    669 
    670         HasNameFlag = 1 << 28,
    671 
    672         AttributeStyleDirtyFlag = 1 << 31,
     665        SelfOrAncestorHasDirAutoFlag = 1 << 24,
     666        HasCustomWillOrDidRecalcStyleFlag = 1 << 25,
     667        HasCustomStyleForRendererFlag = 1 << 26,
     668
     669        HasNameFlag = 1 << 27,
     670
     671        AttributeStyleDirtyFlag = 1 << 28,
    673672
    674673#if ENABLE(SVG)
     
    776775    void setIsStyleAttributeValid() const { setFlag(IsStyleAttributeValidFlag); }
    777776    void clearIsStyleAttributeValid() { clearFlag(IsStyleAttributeValidFlag); }
    778     bool isSynchronizingStyleAttribute() const { return getFlag(IsSynchronizingStyleAttributeFlag); }
    779     void setIsSynchronizingStyleAttribute(bool f) { setFlag(f, IsSynchronizingStyleAttributeFlag); }
    780     void setIsSynchronizingStyleAttribute() const { setFlag(IsSynchronizingStyleAttributeFlag); }
    781     void clearIsSynchronizingStyleAttribute() const { clearFlag(IsSynchronizingStyleAttributeFlag); }
    782777
    783778#if ENABLE(SVG)
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r109149 r109285  
    5151    ASSERT(!isStyleAttributeValid());
    5252    setIsStyleAttributeValid();
    53     setIsSynchronizingStyleAttribute();
    5453    if (StylePropertySet* inlineStyle = inlineStyleDecl())
    55         const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->asText());
    56     clearIsSynchronizingStyleAttribute();
     54        const_cast<StyledElement*>(this)->setAttribute(styleAttr, inlineStyle->asText(), /*notifyChanged*/ false);
    5755}
    5856
     
    6462void StyledElement::attributeChanged(Attribute* attr)
    6563{
    66     if (!(attr->name() == styleAttr && isSynchronizingStyleAttribute()))
    67         parseAttribute(attr);
     64    parseAttribute(attr);
    6865
    6966    if (isPresentationAttribute(attr->name())) {
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r109251 r109285  
    11151115
    11161116    setIsStyleAttributeValid(source->isStyleAttributeValid());
    1117     setIsSynchronizingStyleAttribute(source->isSynchronizingStyleAttribute());
    1118    
     1117
    11191118    Element::copyNonAttributeProperties(sourceElement);
    11201119}
Note: See TracChangeset for help on using the changeset viewer.