Title: [124779] trunk/Source/WebCore
Revision
124779
Author
kl...@webkit.org
Date
2012-08-06 10:04:28 -0700 (Mon, 06 Aug 2012)

Log Message

Simplify CSSOM style declaration's grabbing at internals.
<http://webkit.org/b/93261>

Reviewed by Antti Koivisto.

It was already the case that StylePropertySets exposed in CSSOM were guaranteed mutable,
so remove the mechanism to convert immutable backing objects to mutable ones.

Made ensureCSSStyleDeclaration() non-const to prevent callers that may have an
immutable StylePropertySet from wrapping a CSSOM object around it.

* css/PropertySetCSSStyleDeclaration.h:
(PropertySetCSSStyleDeclaration):
* 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):

    Remove indirection and access StylePropertySet member directly.

* css/StylePropertySet.h:
* css/StylePropertySet.cpp:
(WebCore::StylePropertySet::ensureCSSStyleDeclaration):
(WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):

    Made these two non-const. CSSOM wrappers should only ever be constructed around
    mutable StylePropertySets.
    Also added ASSERT(isMutable()).

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):

    Cast away the constness of StyledElement::attributeStyle(). It's not pretty,
    but these objects are guaranteed mutable, and there's an assertion to protect
    us in ensureCSSStyleDeclaration() if something changes in the future.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (124778 => 124779)


--- trunk/Source/WebCore/ChangeLog	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/ChangeLog	2012-08-06 17:04:28 UTC (rev 124779)
@@ -1,3 +1,55 @@
+2012-08-06  Andreas Kling  <kl...@webkit.org>
+
+        Simplify CSSOM style declaration's grabbing at internals.
+        <http://webkit.org/b/93261>
+
+        Reviewed by Antti Koivisto.
+
+        It was already the case that StylePropertySets exposed in CSSOM were guaranteed mutable,
+        so remove the mechanism to convert immutable backing objects to mutable ones.
+
+        Made ensureCSSStyleDeclaration() non-const to prevent callers that may have an
+        immutable StylePropertySet from wrapping a CSSOM object around it.
+
+        * css/PropertySetCSSStyleDeclaration.h:
+        (PropertySetCSSStyleDeclaration):
+        * 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):
+
+            Remove indirection and access StylePropertySet member directly.
+
+        * css/StylePropertySet.h:
+        * css/StylePropertySet.cpp:
+        (WebCore::StylePropertySet::ensureCSSStyleDeclaration):
+        (WebCore::StylePropertySet::ensureInlineCSSStyleDeclaration):
+
+            Made these two non-const. CSSOM wrappers should only ever be constructed around
+            mutable StylePropertySets.
+            Also added ASSERT(isMutable()).
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::buildObjectForAttributesStyle):
+
+            Cast away the constness of StyledElement::attributeStyle(). It's not pretty,
+            but these objects are guaranteed mutable, and there's an assertion to protect
+            us in ensureCSSStyleDeclaration() if something changes in the future.
+
 2012-08-06  Andrei Poenaru  <poen...@adobe.com>
 
         Web Inspector: Protocol: Add "namedFlowCreated" and "namedFlowRemoved" events

Modified: trunk/Source/WebCore/WebCore.exp.in (124778 => 124779)


--- trunk/Source/WebCore/WebCore.exp.in	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/WebCore.exp.in	2012-08-06 17:04:28 UTC (rev 124779)
@@ -1200,7 +1200,6 @@
 __ZNK7WebCore16HTMLInputElement18shouldAutocompleteEv
 __ZNK7WebCore16IconDatabaseBase12databasePathEv
 __ZNK7WebCore16ResourceResponse13nsURLResponseEv
-__ZNK7WebCore16StylePropertySet25ensureCSSStyleDeclarationEv
 __ZNK7WebCore16VisibleSelection17isContentEditableEv
 __ZNK7WebCore16VisibleSelection17toNormalizedRangeEv
 __ZNK7WebCore16VisibleSelection19rootEditableElementEv
@@ -1533,6 +1532,7 @@
 __ZN7WebCore16FontPlatformDataC2EP6NSFontfbbbNS_15FontOrientationENS_15TextOrientationENS_16FontWidthVariantE
 __ZN7WebCore16colorFromNSColorEP7NSColor
 __ZN7WebCore16enclosingIntRectERK7_NSRect
+__ZN7WebCore16StylePropertySet25ensureCSSStyleDeclarationEv
 __ZN7WebCore21DeviceOrientationData6createEbdbdbdbb
 __ZN7WebCore18SearchPopupMenuMacC1EPNS_15PopupMenuClientE
 __ZN7WebCore19applicationIsSafariEv

Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp (124778 => 124779)


--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp	2012-08-06 17:04:28 UTC (rev 124779)
@@ -141,19 +141,19 @@
 
 unsigned PropertySetCSSStyleDeclaration::length() const
 {
-    return propertySet()->propertyCount();
+    return m_propertySet->propertyCount();
 }
 
 String PropertySetCSSStyleDeclaration::item(unsigned i) const
 {
-    if (i >= propertySet()->propertyCount())
+    if (i >= m_propertySet->propertyCount())
         return "";
-    return getPropertyName(propertySet()->propertyAt(i).id());
+    return getPropertyName(m_propertySet->propertyAt(i).id());
 }
 
 String PropertySetCSSStyleDeclaration::cssText() const
 {
-    return propertySet()->asText();
+    return m_propertySet->asText();
 }
     
 void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCode& ec)
@@ -165,7 +165,7 @@
 
     ec = 0;
     // FIXME: Detect syntax errors and set ec.
-    ensureMutablePropertySet()->parseDeclaration(text, contextStyleSheet());
+    m_propertySet->parseDeclaration(text, contextStyleSheet());
 
     didMutate(PropertyChanged);
 
@@ -179,7 +179,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return 0;
-    return cloneAndCacheForCSSOM(propertySet()->getPropertyCSSValue(propertyID).get());
+    return cloneAndCacheForCSSOM(m_propertySet->getPropertyCSSValue(propertyID).get());
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
@@ -187,7 +187,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    return propertySet()->getPropertyValue(propertyID);
+    return m_propertySet->getPropertyValue(propertyID);
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
@@ -195,7 +195,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    return propertySet()->propertyIsImportant(propertyID) ? "important" : "";
+    return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
@@ -203,7 +203,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return String();
-    CSSPropertyID shorthandID = propertySet()->getPropertyShorthand(propertyID);
+    CSSPropertyID shorthandID = m_propertySet->getPropertyShorthand(propertyID);
     if (!shorthandID)
         return String();
     return getPropertyName(shorthandID);
@@ -214,7 +214,7 @@
     CSSPropertyID propertyID = cssPropertyID(propertyName);
     if (!propertyID)
         return false;
-    return propertySet()->isPropertyImplicit(propertyID);
+    return m_propertySet->isPropertyImplicit(propertyID);
 }
 
 void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
@@ -231,7 +231,7 @@
     willMutate();
 
     ec = 0;
-    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
+    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -257,7 +257,7 @@
 
     ec = 0;
     String result;
-    bool changed = ensureMutablePropertySet()->removeProperty(propertyID, &result);
+    bool changed = m_propertySet->removeProperty(propertyID, &result);
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -271,12 +271,12 @@
 
 PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
 {
-    return propertySet()->getPropertyCSSValue(propertyID);
+    return m_propertySet->getPropertyCSSValue(propertyID);
 }
 
 String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
 { 
-    return propertySet()->getPropertyValue(propertyID);
+    return m_propertySet->getPropertyValue(propertyID);
 }
 
 void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
@@ -287,7 +287,7 @@
     willMutate();
 
     ec = 0;
-    bool changed = ensureMutablePropertySet()->setProperty(propertyID, value, important, contextStyleSheet());
+    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
 
     didMutate(changed ? PropertyChanged : NoChanges);
 
@@ -322,17 +322,18 @@
 
 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
 {
-    return propertySet()->copy();
+    return m_propertySet->copy();
 }
 
 PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable()
 {
-    return ensureMutablePropertySet();
+    ASSERT(m_propertySet->isMutable());
+    return m_propertySet;
 }
 
 bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
 {
-    return propertySet()->propertyMatches(property);
+    return m_propertySet->propertyMatches(property);
 }
     
 StyleRuleCSSStyleDeclaration::StyleRuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule)
@@ -423,11 +424,4 @@
     return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
 }
 
-StylePropertySet* InlineCSSStyleDeclaration::ensureMutablePropertySet()
-{
-    ASSERT(m_propertySet);
-    ASSERT(m_propertySet->isMutable());
-    return m_propertySet;
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h (124778 => 124779)


--- trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/css/PropertySetCSSStyleDeclaration.h	2012-08-06 17:04:28 UTC (rev 124779)
@@ -50,10 +50,6 @@
 
     virtual void reportMemoryUsage(MemoryObjectInfo*) const 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;
@@ -114,8 +110,6 @@
     virtual void willMutate() OVERRIDE;
     virtual void didMutate(MutationType) OVERRIDE;
 
-    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE { return m_propertySet; }
-
     unsigned m_refCount;
     CSSRule* m_parentRule;
 };
@@ -138,8 +132,6 @@
 
     virtual void didMutate(MutationType) OVERRIDE;
 
-    virtual StylePropertySet* ensureMutablePropertySet() OVERRIDE;
-    
     StyledElement* m_parentElement;
 };
 

Modified: trunk/Source/WebCore/css/StylePropertySet.cpp (124778 => 124779)


--- trunk/Source/WebCore/css/StylePropertySet.cpp	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/css/StylePropertySet.cpp	2012-08-06 17:04:28 UTC (rev 124779)
@@ -1046,8 +1046,10 @@
     return StylePropertySet::create(list.data(), list.size());
 }
 
-CSSStyleDeclaration* StylePropertySet::ensureCSSStyleDeclaration() const
+CSSStyleDeclaration* StylePropertySet::ensureCSSStyleDeclaration()
 {
+    ASSERT(isMutable());
+
     if (m_ownsCSSOMWrapper) {
         ASSERT(!static_cast<CSSStyleDeclaration*>(propertySetCSSOMWrapperMap().get(this))->parentRule());
         ASSERT(!propertySetCSSOMWrapperMap().get(this)->parentElement());
@@ -1059,8 +1061,10 @@
     return cssomWrapper;
 }
 
-CSSStyleDeclaration* StylePropertySet::ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const
+CSSStyleDeclaration* StylePropertySet::ensureInlineCSSStyleDeclaration(const StyledElement* parentElement)
 {
+    ASSERT(isMutable());
+
     if (m_ownsCSSOMWrapper) {
         ASSERT(propertySetCSSOMWrapperMap().get(this)->parentElement() == parentElement);
         return propertySetCSSOMWrapperMap().get(this);

Modified: trunk/Source/WebCore/css/StylePropertySet.h (124778 => 124779)


--- trunk/Source/WebCore/css/StylePropertySet.h	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/css/StylePropertySet.h	2012-08-06 17:04:28 UTC (rev 124779)
@@ -105,8 +105,8 @@
     
     void clearParentElement(StyledElement*);
 
-    CSSStyleDeclaration* ensureCSSStyleDeclaration() const;
-    CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement) const;
+    CSSStyleDeclaration* ensureCSSStyleDeclaration();
+    CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(const StyledElement* parentElement);
 
     bool isMutable() const { return m_isMutable; }
 

Modified: trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp (124778 => 124779)


--- trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2012-08-06 16:39:56 UTC (rev 124778)
+++ trunk/Source/WebCore/inspector/InspectorCSSAgent.cpp	2012-08-06 17:04:28 UTC (rev 124779)
@@ -1068,7 +1068,7 @@
     if (!attributeStyle)
         return 0;
 
-    RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), attributeStyle->ensureCSSStyleDeclaration(), 0);
+    RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), const_cast<StylePropertySet*>(attributeStyle)->ensureCSSStyleDeclaration(), 0);
     return inspectorStyle->buildObjectForStyle();
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to