Changeset 121562 in webkit


Ignore:
Timestamp:
Jun 29, 2012 8:21:02 AM (12 years ago)
Author:
kling@webkit.org
Message:

Separate mutating CSSStyleDeclaration operations.
<http://webkit.org/b/89945>

Reviewed by Antti Koivisto.

Use separate paths for mutating the StylePropertySet wrapped by a CSSStyleDeclaration.
PropertySetCSSStyleDeclaration now has:

  • propertySet() const
  • ensureMutablePropertySet()

This is prep work for supporting immutable ElementAttributeData objects, the idea being
that calling ensureMutablePropertySet() may cause the element to convert its internal
attribute storage (which also holds the inline StylePropertySet.)

To that end, also removed the weird logic that allowed you to kill the inline style object
by removing the 'style' attribute. We now simply clear out all the properties in that case
which saves us a bunch of hassle (no need for a ~StyledElement anymore.)
Note that InlineCSSStyleDeclaration now refs the element rather than the inline style.

There should be no web-facing behavior change from any of this.

  • css/PropertySetCSSStyleDeclaration.cpp:

(WebCore::PropertySetCSSStyleDeclaration::length):
(WebCore::PropertySetCSSStyleDeclaration::item):
(WebCore::PropertySetCSSStyleDeclaration::cssText):
(WebCore::PropertySetCSSStyleDeclaration::setCssText):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValue):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyValue):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyPriority):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyShorthand):
(WebCore::PropertySetCSSStyleDeclaration::isPropertyImplicit):
(WebCore::PropertySetCSSStyleDeclaration::setProperty):
(WebCore::PropertySetCSSStyleDeclaration::removeProperty):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyValueInternal):
(WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
(WebCore::PropertySetCSSStyleDeclaration::copy):
(WebCore::PropertySetCSSStyleDeclaration::makeMutable):
(WebCore::PropertySetCSSStyleDeclaration::cssPropertyMatches):
(WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
(WebCore::InlineCSSStyleDeclaration::ref):
(WebCore::InlineCSSStyleDeclaration::deref):
(WebCore::InlineCSSStyleDeclaration::didMutate):
(WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
(WebCore::InlineCSSStyleDeclaration::ensureMutablePropertySet):

  • css/PropertySetCSSStyleDeclaration.h:

(PropertySetCSSStyleDeclaration):
(WebCore::PropertySetCSSStyleDeclaration::propertySet):
(WebCore::PropertySetCSSStyleDeclaration::ensureMutablePropertySet):
(InlineCSSStyleDeclaration):

  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):

  • css/StylePropertySet.h:

(StylePropertySet):

  • dom/ElementAttributeData.cpp:
  • dom/ElementAttributeData.h:

(ElementAttributeData):

  • dom/StyledElement.cpp:

(WebCore::StyledElement::styleAttributeChanged):

  • dom/StyledElement.h:

(WebCore::StyledElement::~StyledElement):
(StyledElement):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121560 r121562  
     12012-06-29  Andreas Kling  <kling@webkit.org>
     2
     3        Separate mutating CSSStyleDeclaration operations.
     4        <http://webkit.org/b/89945>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Use separate paths for mutating the StylePropertySet wrapped by a CSSStyleDeclaration.
     9        PropertySetCSSStyleDeclaration now has:
     10
     11            - propertySet() const
     12            - ensureMutablePropertySet()
     13
     14        This is prep work for supporting immutable ElementAttributeData objects, the idea being
     15        that calling ensureMutablePropertySet() may cause the element to convert its internal
     16        attribute storage (which also holds the inline StylePropertySet.)
     17
     18        To that end, also removed the weird logic that allowed you to kill the inline style object
     19        by removing the 'style' attribute. We now simply clear out all the properties in that case
     20        which saves us a bunch of hassle (no need for a ~StyledElement anymore.)
     21        Note that InlineCSSStyleDeclaration now refs the element rather than the inline style.
     22
     23        There should be no web-facing behavior change from any of this.
     24
     25        * css/PropertySetCSSStyleDeclaration.cpp:
     26        (WebCore::PropertySetCSSStyleDeclaration::length):
     27        (WebCore::PropertySetCSSStyleDeclaration::item):
     28        (WebCore::PropertySetCSSStyleDeclaration::cssText):
     29        (WebCore::PropertySetCSSStyleDeclaration::setCssText):
     30        (WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValue):
     31        (WebCore::PropertySetCSSStyleDeclaration::getPropertyValue):
     32        (WebCore::PropertySetCSSStyleDeclaration::getPropertyPriority):
     33        (WebCore::PropertySetCSSStyleDeclaration::getPropertyShorthand):
     34        (WebCore::PropertySetCSSStyleDeclaration::isPropertyImplicit):
     35        (WebCore::PropertySetCSSStyleDeclaration::setProperty):
     36        (WebCore::PropertySetCSSStyleDeclaration::removeProperty):
     37        (WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal):
     38        (WebCore::PropertySetCSSStyleDeclaration::getPropertyValueInternal):
     39        (WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
     40        (WebCore::PropertySetCSSStyleDeclaration::copy):
     41        (WebCore::PropertySetCSSStyleDeclaration::makeMutable):
     42        (WebCore::PropertySetCSSStyleDeclaration::cssPropertyMatches):
     43        (WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
     44        (WebCore::InlineCSSStyleDeclaration::ref):
     45        (WebCore::InlineCSSStyleDeclaration::deref):
     46        (WebCore::InlineCSSStyleDeclaration::didMutate):
     47        (WebCore::InlineCSSStyleDeclaration::parentStyleSheet):
     48        (WebCore::InlineCSSStyleDeclaration::ensureMutablePropertySet):
     49        * css/PropertySetCSSStyleDeclaration.h:
     50        (PropertySetCSSStyleDeclaration):
     51        (WebCore::PropertySetCSSStyleDeclaration::propertySet):
     52        (WebCore::PropertySetCSSStyleDeclaration::ensureMutablePropertySet):
     53        (InlineCSSStyleDeclaration):
     54        * css/StylePropertySet.cpp:
     55        (WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):
     56        * css/StylePropertySet.h:
     57        (StylePropertySet):
     58        * dom/ElementAttributeData.cpp:
     59        * dom/ElementAttributeData.h:
     60        (ElementAttributeData):
     61        * dom/StyledElement.cpp:
     62        (WebCore::StyledElement::styleAttributeChanged):
     63        * dom/StyledElement.h:
     64        (WebCore::StyledElement::~StyledElement):
     65        (StyledElement):
     66
    1672012-06-29  Kwang Yul Seo  <skyul@company100.net>
    268
  • trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp

    r118194 r121562  
    133133unsigned PropertySetCSSStyleDeclaration::length() const
    134134{
    135     return m_propertySet->propertyCount();
     135    return propertySet()->propertyCount();
    136136}
    137137
    138138String PropertySetCSSStyleDeclaration::item(unsigned i) const
    139139{
    140     if (i >= m_propertySet->propertyCount())
     140    if (i >= propertySet()->propertyCount())
    141141        return "";
    142     return getPropertyName(m_propertySet->propertyAt(i).id());
     142    return getPropertyName(propertySet()->propertyAt(i).id());
    143143}
    144144
    145145String PropertySetCSSStyleDeclaration::cssText() const
    146146{
    147     return m_propertySet->asText();
     147    return propertySet()->asText();
    148148}
    149149   
     
    157157    ec = 0;
    158158    // FIXME: Detect syntax errors and set ec.
    159     m_propertySet->parseDeclaration(text, contextStyleSheet());
     159    ensureMutablePropertySet()->parseDeclaration(text, contextStyleSheet());
    160160
    161161    didMutate(PropertyChanged);
     
    171171    if (!propertyID)
    172172        return 0;
    173     return cloneAndCacheForCSSOM(m_propertySet->getPropertyCSSValue(propertyID).get());
     173    return cloneAndCacheForCSSOM(propertySet()->getPropertyCSSValue(propertyID).get());
    174174}
    175175
     
    179179    if (!propertyID)
    180180        return String();
    181     return m_propertySet->getPropertyValue(propertyID);
     181    return propertySet()->getPropertyValue(propertyID);
    182182}
    183183
     
    187187    if (!propertyID)
    188188        return String();
    189     return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
     189    return propertySet()->propertyIsImportant(propertyID) ? "important" : "";
    190190}
    191191
     
    195195    if (!propertyID)
    196196        return String();
    197     CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);
     197    CSSPropertyID shorthandID = propertySet()->getPropertyShorthand(propertyID);
    198198    if (!shorthandID)
    199199        return String();
     
    206206    if (!propertyID)
    207207        return false;
    208     return m_propertySet->isPropertyImplicit(propertyID);
     208    return propertySet()->isPropertyImplicit(propertyID);
    209209}
    210210
     
    223223
    224224    ec = 0;
    225     bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
     225    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
    226226
    227227    didMutate(changed ? PropertyChanged : NoChanges);
     
    249249    ec = 0;
    250250    String result;
    251     bool changed = m_propertySet->removeProperty(propertyID, &result);
     251    bool changed = ensureMutablePropertySet()->removeProperty(propertyID, &result);
    252252
    253253    didMutate(changed ? PropertyChanged : NoChanges);
     
    263263PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
    264264{
    265     return m_propertySet->getPropertyCSSValue(propertyID);
     265    return propertySet()->getPropertyCSSValue(propertyID);
    266266}
    267267
    268268String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
    269269{
    270     return m_propertySet->getPropertyValue(propertyID);
     270    return propertySet()->getPropertyValue(propertyID);
    271271}
    272272
     
    279279
    280280    ec = 0;
    281     bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
     281    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
    282282
    283283    didMutate(changed ? PropertyChanged : NoChanges);
     
    314314PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
    315315{
    316     return m_propertySet->copy();
     316    return propertySet()->copy();
    317317}
    318318
    319319PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable()
    320320{
    321     return m_propertySet;
     321    return ensureMutablePropertySet();
    322322}
    323323
    324324bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
    325325{
    326     return m_propertySet->propertyMatches(property);
     326    return propertySet()->propertyMatches(property);
    327327}
    328328   
     
    381381}
    382382
     383InlineCSSStyleDeclaration::InlineCSSStyleDeclaration(StyledElement* parentElement)
     384    : PropertySetCSSStyleDeclaration(const_cast<StylePropertySet*>(parentElement->inlineStyle()))
     385    , m_parentElement(parentElement)
     386{
     387}
     388
     389void InlineCSSStyleDeclaration::ref()
     390{
     391    m_parentElement->ref();
     392}
     393
     394void InlineCSSStyleDeclaration::deref()
     395{
     396    m_parentElement->deref();
     397}
     398
    383399void InlineCSSStyleDeclaration::didMutate(MutationType type)
    384400{
     
    388404    m_cssomCSSValueClones.clear();
    389405
    390     if (!m_parentElement)
    391         return;
    392406    m_parentElement->setNeedsStyleRecalc(InlineStyleChange);
    393407    m_parentElement->invalidateStyleAttribute();
     
    397411CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
    398412{
    399     return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
     413    return m_parentElement->document()->elementSheet();
     414}
     415
     416StylePropertySet* InlineCSSStyleDeclaration::ensureMutablePropertySet()
     417{
     418    ASSERT(m_propertySet);
     419    ASSERT(m_propertySet == m_parentElement->inlineStyle());
     420    return m_propertySet;
    400421}
    401422
  • trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h

    r118194 r121562  
    4343   
    4444    virtual StyledElement* parentElement() const { return 0; }
    45     virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
    4645    StyleSheetContents* contextStyleSheet() const;
    4746   
    4847    virtual void ref() OVERRIDE;
    4948    virtual void deref() OVERRIDE;
     49
     50protected:
     51    const StylePropertySet* propertySet() const { return m_propertySet; }
     52    virtual StylePropertySet* ensureMutablePropertySet() { return m_propertySet; }
    5053
    5154private:
     
    107110    virtual void didMutate(MutationType) OVERRIDE;
    108111
     112    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE { return m_propertySet; }
     113
    109114    unsigned m_refCount;
    110115    CSSRule* m_parentRule;
     
    114119{
    115120public:
    116     InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement)
    117         : PropertySetCSSStyleDeclaration(propertySet)
    118         , m_parentElement(parentElement)
    119     {
    120     }
     121    InlineCSSStyleDeclaration(StyledElement*);
     122
     123    virtual void ref() OVERRIDE;
     124    virtual void deref() OVERRIDE;
    121125   
    122126private:
    123127    virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    124128    virtual StyledElement* parentElement() const OVERRIDE { return m_parentElement; }
    125     virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }
    126129
    127130    virtual void didMutate(MutationType) OVERRIDE;
     131
     132    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE;
    128133   
    129134    StyledElement* m_parentElement;
  • trunk/Source/WebCore/css/StylePropertySet.cpp

    r121442 r121562  
    10521052    }
    10531053    m_ownsCSSOMWrapper = true;
    1054     PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StylePropertySet*>(this), const_cast<StyledElement*>(parentElement));
     1054    PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StyledElement*>(parentElement));
    10551055    propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
    10561056    return cssomWrapper;
    1057 }
    1058 
    1059 void StylePropertySet::clearParentElement(StyledElement* element)
    1060 {
    1061     if (!m_ownsCSSOMWrapper)
    1062         return;
    1063     ASSERT_UNUSED(element, propertySetCSSOMWrapperMap().get(this)->parentElement() == element);
    1064     propertySetCSSOMWrapperMap().get(this)->clearParentElement();
    10651057}
    10661058
  • trunk/Source/WebCore/css/StylePropertySet.h

    r121022 r121562  
    104104    String asText() const;
    105105   
    106     void clearParentElement(StyledElement*);
    107 
    108106    CSSStyleDeclaration* ensureCSSStyleDeclaration() const;
    109107    CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const;
  • trunk/Source/WebCore/dom/ElementAttributeData.cpp

    r121539 r121562  
    162162}
    163163
    164 void ElementAttributeData::destroyInlineStyle(StyledElement* element)
    165 {
    166     if (!m_inlineStyleDecl)
    167         return;
    168     m_inlineStyleDecl->clearParentElement(element);
    169     m_inlineStyleDecl = 0;
    170 }
    171 
    172164void ElementAttributeData::addAttribute(const Attribute& attribute, Element* element, EInUpdateStyleAttribute inUpdateStyleAttribute)
    173165{
  • trunk/Source/WebCore/dom/ElementAttributeData.h

    r121539 r121562  
    6868    StylePropertySet* ensureMutableInlineStyle(StyledElement*);
    6969    void updateInlineStyleAvoidingMutation(StyledElement*, const String& text);
    70     void destroyInlineStyle(StyledElement*);
    7170
    7271    StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); }
  • trunk/Source/WebCore/dom/StyledElement.cpp

    r119846 r121562  
    136136}
    137137
    138 StyledElement::~StyledElement()
    139 {
    140     destroyInlineStyle();
    141 }
    142 
    143138CSSStyleDeclaration* StyledElement::style()
    144139{
     
    184179        if (document() && document()->scriptableDocumentParser() && !document()->isInDocumentWrite())
    185180            startLineNumber = document()->scriptableDocumentParser()->lineNumber();
    186         if (newStyleString.isNull())
    187             destroyInlineStyle();
    188         else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber))
     181        if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber))
    189182            ensureAttributeData()->updateInlineStyleAvoidingMutation(this, newStyleString);
    190183        setIsStyleAttributeValid();
  • trunk/Source/WebCore/dom/StyledElement.h

    r119776 r121562  
    3636class StyledElement : public Element {
    3737public:
    38     virtual ~StyledElement();
     38    virtual ~StyledElement() { }
    3939
    4040    virtual StylePropertySet* additionalAttributeStyle() { return 0; }
     
    8787    void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const;
    8888    void updateAttributeStyle();
    89 
    90     void destroyInlineStyle()
    91     {
    92         if (attributeData())
    93             attributeData()->destroyInlineStyle(this);
    94     }
    9589};
    9690
Note: See TracChangeset for help on using the changeset viewer.