Title: [121562] trunk/Source/WebCore
Revision
121562
Author
[email protected]
Date
2012-06-29 08:21:02 -0700 (Fri, 29 Jun 2012)

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (121561 => 121562)


--- trunk/Source/WebCore/ChangeLog	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/ChangeLog	2012-06-29 15:21:02 UTC (rev 121562)
@@ -1,3 +1,69 @@
+2012-06-29  Andreas Kling  <[email protected]>
+
+        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):
+
 2012-06-29  Kwang Yul Seo  <[email protected]>
 
         Don't call SegmentedString::toString() twice in XMLDocumentParser::append(const SegmentedString&)

Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp (121561 => 121562)


--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-06-29 15:21:02 UTC (rev 121562)
@@ -132,19 +132,19 @@
 
 unsigned PropertySetCSSStyleDeclaration::length() const
 {
-    return m_propertySet->propertyCount();
+    return propertySet()->propertyCount();
 }
 
 String PropertySetCSSStyleDeclaration::item(unsigned i) const
 {
-    if (i >= m_propertySet->propertyCount())
+    if (i >= propertySet()->propertyCount())
         return "";
-    return getPropertyName(m_propertySet->propertyAt(i).id());
+    return getPropertyName(propertySet()->propertyAt(i).id());
 }
 
 String PropertySetCSSStyleDeclaration::cssText() const
 {
-    return m_propertySet->asText();
+    return propertySet()->asText();
 }
     
 void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCode& ec)
@@ -156,7 +156,7 @@
 
     ec = 0;
     // FIXME: Detect syntax errors and set ec.
-    m_propertySet->parseDeclaration(text, contextStyleSheet());
+    ensureMutablePropertySet()->parseDeclaration(text, contextStyleSheet());
 
     didMutate(PropertyChanged);
 
@@ -170,7 +170,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return 0;
-    return cloneAndCacheForCSSOM(m_propertySet->getPropertyCSSValue(propertyID).get());
+    return cloneAndCacheForCSSOM(propertySet()->getPropertyCSSValue(propertyID).get());
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
@@ -178,7 +178,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    return m_propertySet->getPropertyValue(propertyID);
+    return propertySet()->getPropertyValue(propertyID);
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
@@ -186,7 +186,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
+    return propertySet()->propertyIsImportant(propertyID) ? "important" : "";
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
@@ -194,7 +194,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);
+    CSSPropertyID shorthandID = propertySet()->getPropertyShorthand(propertyID);
     if (!shorthandID)
         return String();
     return getPropertyName(shorthandID);
@@ -205,7 +205,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return false;
-    return m_propertySet->isPropertyImplicit(propertyID);
+    return propertySet()->isPropertyImplicit(propertyID);
 }
 
 void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
@@ -222,7 +222,7 @@
     willMutate();
 
     ec = 0;
-    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -248,7 +248,7 @@
 
     ec = 0;
     String result;
-    bool changed = m_propertySet->removeProperty(propertyID, &result);
+    bool changed = ensureMutablePropertySet()->removeProperty(propertyID, &result);
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -262,12 +262,12 @@
 
 PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
 {
-    return m_propertySet->getPropertyCSSValue(propertyID);
+    return propertySet()->getPropertyCSSValue(propertyID);
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
 { 
-    return m_propertySet->getPropertyValue(propertyID); 
+    return propertySet()->getPropertyValue(propertyID);
 }
 
 void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
@@ -278,7 +278,7 @@
     willMutate();
 
     ec = 0;
-    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -313,17 +313,17 @@
 
 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
 {
-    return m_propertySet->copy();
+    return propertySet()->copy();
 }
 
 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable()
 {
-    return m_propertySet;
+    return ensureMutablePropertySet();
 }
 
 bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
 {
-    return m_propertySet->propertyMatches(property);
+    return propertySet()->propertyMatches(property);
 }
     
 StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule)
@@ -380,6 +380,22 @@
     m_propertySet->ref();
 }
 
+InlineCSSStyleDeclaration::InlineCSSStyleDeclaration(StyledElement* parentElement)
+    : PropertySetCSSStyleDeclaration(const_cast<StylePropertySet*>(parentElement->inlineStyle()))
+    , m_parentElement(parentElement)
+{
+}
+
+void InlineCSSStyleDeclaration::ref()
+{
+    m_parentElement->ref();
+}
+
+void InlineCSSStyleDeclaration::deref()
+{
+    m_parentElement->deref();
+}
+
 void InlineCSSStyleDeclaration::didMutate(MutationType type)
 {
     if (type == NoChanges)
@@ -387,8 +403,6 @@
 
     m_cssomCSSValueClones.clear();
 
-    if (!m_parentElement)
-        return;
     m_parentElement->setNeedsStyleRecalc(InlineStyleChange);
     m_parentElement->invalidateStyleAttribute();
     StyleAttributeMutationScope(this).didInvalidateStyleAttr();
@@ -396,7 +410,14 @@
 
 CSSStyleSheet* InlineCSSStyleDeclaration::parentStyleSheet() const
 {
-    return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
+    return m_parentElement->document()->elementSheet();
 }
 
+StylePropertySet* InlineCSSStyleDeclaration::ensureMutablePropertySet()
+{
+    ASSERT(m_propertySet);
+    ASSERT(m_propertySet == m_parentElement->inlineStyle());
+    return m_propertySet;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h (121561 => 121562)


--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h	2012-06-29 15:21:02 UTC (rev 121562)
@@ -42,12 +42,15 @@
     PropertySetCSSStyleDeclaration(StylePropertySet* propertySet) : m_propertySet(propertySet) { }
     
     virtual StyledElement* parentElement() const { return 0; }
-    virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
     StyleSheetContents* contextStyleSheet() const;
     
     virtual void ref() OVERRIDE;
     virtual void deref() OVERRIDE;
 
+protected:
+    const StylePropertySet* propertySet() const { return m_propertySet; }
+    virtual StylePropertySet* ensureMutablePropertySet() { return m_propertySet; }
+
 private:
     virtual CSSRule* parentRule() const OVERRIDE { return 0; };
     virtual unsigned length() const OVERRIDE;
@@ -106,6 +109,8 @@
     virtual void willMutate() OVERRIDE;
     virtual void didMutate(MutationType) OVERRIDE;
 
+    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE { return m_propertySet; }
+
     unsigned m_refCount;
     CSSRule* m_parentRule;
 };
@@ -113,18 +118,18 @@
 class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
 {
 public:
-    InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement)
-        : PropertySetCSSStyleDeclaration(propertySet)
-        , m_parentElement(parentElement) 
-    {
-    }
+    InlineCSSStyleDeclaration(StyledElement*);
+
+    virtual void ref() OVERRIDE;
+    virtual void deref() OVERRIDE;
     
 private:
     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
     virtual StyledElement* parentElement() const OVERRIDE { return m_parentElement; }
-    virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }
 
     virtual void didMutate(MutationType) OVERRIDE;
+
+    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE;
     
     StyledElement* m_parentElement;
 };

Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (121561 => 121562)


--- trunk/Source/WebCore/css/StylePropertySet.cpp	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp	2012-06-29 15:21:02 UTC (rev 121562)
@@ -1051,19 +1051,11 @@
         return propertySetCSSOMWrapperMap().get(this);
     }
     m_ownsCSSOMWrapper = true;
-    PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StylePropertySet*>(this), const_cast<StyledElement*>(parentElement));
+    PropertySetCSSStyleDeclaration* cssomWrapper = new InlineCSSStyleDeclaration(const_cast<StyledElement*>(parentElement));
     propertySetCSSOMWrapperMap().add(this, adoptPtr(cssomWrapper));
     return cssomWrapper;
 }
 
-void StylePropertySet::clearParentElement(StyledElement* element)
-{
-    if (!m_ownsCSSOMWrapper)
-        return;
-    ASSERT_UNUSED(element, propertySetCSSOMWrapperMap().get(this)->parentElement() == element);
-    propertySetCSSOMWrapperMap().get(this)->clearParentElement();
-}
-
 unsigned StylePropertySet::averageSizeInBytes()
 {
     // Please update this if the storage scheme changes so that this longer reflects the actual size.

Modified: trunk/Source/WebCore/css/StylePropertySet.h (121561 => 121562)


--- trunk/Source/WebCore/css/StylePropertySet.h	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/css/StylePropertySet.h	2012-06-29 15:21:02 UTC (rev 121562)
@@ -103,8 +103,6 @@
     
     String asText() const;
     
-    void clearParentElement(StyledElement*);
-
     CSSStyleDeclaration* ensureCSSStyleDeclaration() const;
     CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const;
 

Modified: trunk/Source/WebCore/dom/ElementAttributeData.cpp (121561 => 121562)


--- trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/dom/ElementAttributeData.cpp	2012-06-29 15:21:02 UTC (rev 121562)
@@ -161,14 +161,6 @@
     m_inlineStyleDecl->parseDeclaration(text, element->document()->elementSheet()->contents());
 }
 
-void ElementAttributeData::destroyInlineStyle(StyledElement* element)
-{
-    if (!m_inlineStyleDecl)
-        return;
-    m_inlineStyleDecl->clearParentElement(element);
-    m_inlineStyleDecl = 0;
-}
-
 void ElementAttributeData::addAttribute(const Attribute& attribute, Element* element, EInUpdateStyleAttribute inUpdateStyleAttribute)
 {
     if (element && inUpdateStyleAttribute == NotInUpdateStyleAttribute)

Modified: trunk/Source/WebCore/dom/ElementAttributeData.h (121561 => 121562)


--- trunk/Source/WebCore/dom/ElementAttributeData.h	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/dom/ElementAttributeData.h	2012-06-29 15:21:02 UTC (rev 121562)
@@ -67,7 +67,6 @@
     StylePropertySet* ensureInlineStyle(StyledElement*);
     StylePropertySet* ensureMutableInlineStyle(StyledElement*);
     void updateInlineStyleAvoidingMutation(StyledElement*, const String& text);
-    void destroyInlineStyle(StyledElement*);
 
     StylePropertySet* attributeStyle() const { return m_attributeStyle.get(); }
     void setAttributeStyle(PassRefPtr<StylePropertySet> style) { m_attributeStyle = style; }

Modified: trunk/Source/WebCore/dom/StyledElement.cpp (121561 => 121562)


--- trunk/Source/WebCore/dom/StyledElement.cpp	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/dom/StyledElement.cpp	2012-06-29 15:21:02 UTC (rev 121562)
@@ -135,11 +135,6 @@
 {
 }
 
-StyledElement::~StyledElement()
-{
-    destroyInlineStyle();
-}
-
 CSSStyleDeclaration* StyledElement::style()
 {
     return ensureAttributeData()->ensureMutableInlineStyle(this)->ensureInlineCSSStyleDeclaration(this); 
@@ -183,9 +178,7 @@
         WTF::OrdinalNumber startLineNumber = WTF::OrdinalNumber::beforeFirst();
         if (document() && document()->scriptableDocumentParser() && !document()->isInDocumentWrite())
             startLineNumber = document()->scriptableDocumentParser()->lineNumber();
-        if (newStyleString.isNull())
-            destroyInlineStyle();
-        else if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber))
+        if (document()->contentSecurityPolicy()->allowInlineStyle(document()->url(), startLineNumber))
             ensureAttributeData()->updateInlineStyleAvoidingMutation(this, newStyleString);
         setIsStyleAttributeValid();
     }

Modified: trunk/Source/WebCore/dom/StyledElement.h (121561 => 121562)


--- trunk/Source/WebCore/dom/StyledElement.h	2012-06-29 15:19:32 UTC (rev 121561)
+++ trunk/Source/WebCore/dom/StyledElement.h	2012-06-29 15:21:02 UTC (rev 121562)
@@ -35,7 +35,7 @@
 
 class StyledElement : public Element {
 public:
-    virtual ~StyledElement();
+    virtual ~StyledElement() { }
 
     virtual StylePropertySet* additionalAttributeStyle() { return 0; }
     void invalidateStyleAttribute();
@@ -86,12 +86,6 @@
 
     void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const;
     void updateAttributeStyle();
-
-    void destroyInlineStyle()
-    {
-        if (attributeData())
-            attributeData()->destroyInlineStyle(this);
-    }
 };
 
 inline const SpaceSplitString& StyledElement::classNames() const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to