Factor element pointer out of CSSMutableStyleDeclaration.
authorandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 14:44:55 +0000 (14:44 +0000)
committerandreas.kling@nokia.com <andreas.kling@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 Nov 2011 14:44:55 +0000 (14:44 +0000)
<http://webkit.org/b/73121>

Reviewed by Antti Koivisto.

Move the StyledElement pointer out of CSSMutableStyleDeclaration and into a subclass
for the cases where it's needed. This reduces the size of vanilla style declarations
by one CPU word (4 or 8 bytes, depending on architecture.)

* css/CSSMutableStyleDeclaration.h:
(WebCore::CSSElementStyleDeclaration::element):
(WebCore::CSSElementStyleDeclaration::setElement):
(WebCore::CSSElementStyleDeclaration::CSSElementStyleDeclaration):
(WebCore::CSSElementStyleDeclaration::~CSSElementStyleDeclaration):

    Added CSSElementStyleDeclaration, a common parent class for inline styles
    and mapped attributes. It extends CSSMutableStyleDeclaration by adding a backpointer
    to the StyledElement that owns it.

* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSInlineStyleDeclaration.h: Added.
(WebCore::CSSInlineStyleDeclaration::~CSSInlineStyleDeclaration):
(WebCore::CSSInlineStyleDeclaration::create):
(WebCore::CSSInlineStyleDeclaration::CSSInlineStyleDeclaration):

    Added CSSInlineStyleDeclaration.

* bindings/js/JSDOMBinding.h:
(WebCore::root):
* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc):
* css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::setSelectorText):

    Only follow the associated element on CSSElementStyleDeclarations.

* css/CSSMutableStyleDeclaration.cpp:
(WebCore::CSSMutableStyleDeclaration::CSSMutableStyleDeclaration):
(WebCore::CSSMutableStyleDeclaration::operator=):

    Remove comment about m_element since the field was moved to a subclass.

* css/CSSStyleDeclaration.cpp:
(WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
* css/CSSStyleDeclaration.h:
(WebCore::CSSStyleDeclaration::isElementStyleDeclaration):
(WebCore::CSSStyleDeclaration::isInlineStyleDeclaration):

    We no longer need to track whether a style declaration is mutable or not,
    so the constructors are slightly simplified.
    Added two bits (isElementStyleDeclaration and isInlineStyleDeclaration) for
    runtime type checking. These are protected and set by the CSSElementStyleDeclaration
    constructor.

* dom/CSSMappedAttributeDeclaration.h:
(WebCore::CSSMappedAttributeDeclaration::create):
(WebCore::CSSMappedAttributeDeclaration::CSSMappedAttributeDeclaration):

    Remove pointless CSSRule* argument to constructor since we always passed 0.

* dom/StyledElement.h:
(WebCore::StyledElement::inlineStyleDecl):
* dom/StyledElement.cpp:
(WebCore::StyledElement::createInlineStyleDecl):
(WebCore::StyledElement::getInlineStyleDecl):
(WebCore::StyledElement::addSubresourceAttributeURLs):

    Make the inline style on StyledElement a CSSInlineStyleDeclaration.

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

    Slightly simplified by having CSSInlineStyleDeclaration.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@101172 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/css/CSSInlineStyleDeclaration.h [new file with mode: 0644]
Source/WebCore/css/CSSMutableStyleDeclaration.cpp
Source/WebCore/css/CSSMutableStyleDeclaration.h
Source/WebCore/css/CSSStyleDeclaration.cpp
Source/WebCore/css/CSSStyleDeclaration.h
Source/WebCore/css/CSSStyleRule.cpp
Source/WebCore/dom/CSSMappedAttributeDeclaration.h
Source/WebCore/dom/StyledElement.cpp
Source/WebCore/dom/StyledElement.h
Source/WebCore/inspector/InspectorCSSAgent.cpp

index 52216d0..cdd7408 100644 (file)
@@ -1,3 +1,83 @@
+2011-11-25  Andreas Kling  <kling@webkit.org>
+
+        Factor element pointer out of CSSMutableStyleDeclaration.
+        <http://webkit.org/b/73121>
+
+        Reviewed by Antti Koivisto.
+
+        Move the StyledElement pointer out of CSSMutableStyleDeclaration and into a subclass
+        for the cases where it's needed. This reduces the size of vanilla style declarations
+        by one CPU word (4 or 8 bytes, depending on architecture.)
+
+        * css/CSSMutableStyleDeclaration.h:
+        (WebCore::CSSElementStyleDeclaration::element):
+        (WebCore::CSSElementStyleDeclaration::setElement):
+        (WebCore::CSSElementStyleDeclaration::CSSElementStyleDeclaration):
+        (WebCore::CSSElementStyleDeclaration::~CSSElementStyleDeclaration):
+
+            Added CSSElementStyleDeclaration, a common parent class for inline styles
+            and mapped attributes. It extends CSSMutableStyleDeclaration by adding a backpointer
+            to the StyledElement that owns it.
+
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSInlineStyleDeclaration.h: Added.
+        (WebCore::CSSInlineStyleDeclaration::~CSSInlineStyleDeclaration):
+        (WebCore::CSSInlineStyleDeclaration::create):
+        (WebCore::CSSInlineStyleDeclaration::CSSInlineStyleDeclaration):
+
+            Added CSSInlineStyleDeclaration.
+
+        * bindings/js/JSDOMBinding.h:
+        (WebCore::root):
+        * css/CSSMutableStyleDeclaration.cpp:
+        (WebCore::CSSMutableStyleDeclaration::setNeedsStyleRecalc):
+        * css/CSSStyleRule.cpp:
+        (WebCore::CSSStyleRule::setSelectorText):
+
+            Only follow the associated element on CSSElementStyleDeclarations.
+
+        * css/CSSMutableStyleDeclaration.cpp:
+        (WebCore::CSSMutableStyleDeclaration::CSSMutableStyleDeclaration):
+        (WebCore::CSSMutableStyleDeclaration::operator=):
+
+            Remove comment about m_element since the field was moved to a subclass.
+
+        * css/CSSStyleDeclaration.cpp:
+        (WebCore::CSSStyleDeclaration::CSSStyleDeclaration):
+        * css/CSSStyleDeclaration.h:
+        (WebCore::CSSStyleDeclaration::isElementStyleDeclaration):
+        (WebCore::CSSStyleDeclaration::isInlineStyleDeclaration):
+
+            We no longer need to track whether a style declaration is mutable or not,
+            so the constructors are slightly simplified.
+            Added two bits (isElementStyleDeclaration and isInlineStyleDeclaration) for
+            runtime type checking. These are protected and set by the CSSElementStyleDeclaration
+            constructor.
+
+        * dom/CSSMappedAttributeDeclaration.h:
+        (WebCore::CSSMappedAttributeDeclaration::create):
+        (WebCore::CSSMappedAttributeDeclaration::CSSMappedAttributeDeclaration):
+
+            Remove pointless CSSRule* argument to constructor since we always passed 0.
+
+        * dom/StyledElement.h:
+        (WebCore::StyledElement::inlineStyleDecl):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::createInlineStyleDecl):
+        (WebCore::StyledElement::getInlineStyleDecl):
+        (WebCore::StyledElement::addSubresourceAttributeURLs):
+
+            Make the inline style on StyledElement a CSSInlineStyleDeclaration.
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::inlineStyleElement):
+
+            Slightly simplified by having CSSInlineStyleDeclaration.
+
 2011-11-25  Pavel Feldman  <pfeldman@google.com>
 
         Web Inspector: unflake timeline-network tests
index b4ae023..3c09230 100644 (file)
@@ -1011,6 +1011,7 @@ webcore_sources += \
        Source/WebCore/css/CSSInheritedValue.h \
        Source/WebCore/css/CSSInitialValue.cpp \
        Source/WebCore/css/CSSInitialValue.h \
+       Source/WebCore/css/CSSInlineStyleDeclaration.h \
        Source/WebCore/css/CSSLineBoxContainValue.cpp \
        Source/WebCore/css/CSSLineBoxContainValue.h \
        Source/WebCore/css/CSSMediaRule.cpp \
index 630f081..2263ea2 100644 (file)
@@ -1511,6 +1511,7 @@ HEADERS += \
     css/CSSImportRule.h \
     css/CSSInheritedValue.h \
     css/CSSInitialValue.h \
+    css/CSSInlineStyleDeclaration.h \
     css/CSSMediaRule.h \
     css/CSSMutableStyleDeclaration.h \
     css/CSSOMUtils.h \
index d727152..4490fce 100644 (file)
             'css/CSSHelper.h',
             'css/CSSImageGeneratorValue.h',
             'css/CSSImageValue.h',
+            'css/CSSInlineStyleDeclaration.h',
             'css/CSSLineBoxContainValue.h',
             'css/CSSMutableStyleDeclaration.h',
             'css/CSSParserValues.h',
index b6fdc0b..3bbde8b 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\css\CSSInlineStyleDeclaration.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\css\CSSLineBoxContainValue.cpp"
                                >
                        </File>
index 3fcac61..a016558 100644 (file)
                8CADF2AB135C7B36009EF43F /* LevelDBDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CADF2A5135C7B36009EF43F /* LevelDBDatabase.h */; };
                8CADF2AD135C7B36009EF43F /* LevelDBIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CADF2A7135C7B36009EF43F /* LevelDBIterator.h */; };
                8CADF2AE135C7B36009EF43F /* LevelDBSlice.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CADF2A8135C7B36009EF43F /* LevelDBSlice.h */; };
+               8CF7DDE4147ECF940041A6F2 /* CSSInlineStyleDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = 8CF7DDE1147E432D0041A6F2 /* CSSInlineStyleDeclaration.h */; settings = {ATTRIBUTES = (Private, ); }; };
                8F67561B1288B17B0047ACA3 /* EventQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 8F6756191288B17B0047ACA3 /* EventQueue.h */; settings = {ATTRIBUTES = (Private, ); }; };
                8FAC774D119872CB0015AE94 /* JSMainThreadExecState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8F934D841189F1EE00508D5D /* JSMainThreadExecState.cpp */; };
                9001774012E0347800648462 /* OESStandardDerivatives.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9001773D12E0347800648462 /* OESStandardDerivatives.cpp */; };
                8CADF2A5135C7B36009EF43F /* LevelDBDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBDatabase.h; sourceTree = "<group>"; };
                8CADF2A7135C7B36009EF43F /* LevelDBIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBIterator.h; sourceTree = "<group>"; };
                8CADF2A8135C7B36009EF43F /* LevelDBSlice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LevelDBSlice.h; sourceTree = "<group>"; };
+               8CF7DDE1147E432D0041A6F2 /* CSSInlineStyleDeclaration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSInlineStyleDeclaration.h; sourceTree = "<group>"; };
                8F6756191288B17B0047ACA3 /* EventQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventQueue.h; sourceTree = "<group>"; };
                8F934D831189F1EE00508D5D /* JSMainThreadExecState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMainThreadExecState.h; sourceTree = "<group>"; };
                8F934D841189F1EE00508D5D /* JSMainThreadExecState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMainThreadExecState.cpp; sourceTree = "<group>"; };
                F523D18402DE42E8018635CA /* css */ = {
                        isa = PBXGroup;
                        children = (
+                               8CF7DDE1147E432D0041A6F2 /* CSSInlineStyleDeclaration.h */,
                                5038BC0614711CDB0095E0D1 /* WebKitCSSShaderValue.cpp */,
                                50B42157146976960087E604 /* WebKitCSSShaderValue.h */,
                                AD03AAF81468453900A39B5B /* CSSValue.cpp */,
                        isa = PBXHeadersBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               8CF7DDE4147ECF940041A6F2 /* CSSInlineStyleDeclaration.h in Headers */,
                                A3BB59F41457A40D00AC56FE /* DocumentEventQueue.h in Headers */,
                                3106037014327D2E00ABF4BA /* WebKitCSSFilterValue.h in Headers */,
                                A8EA800C0A19516E00A8EF5F /* StyleSheet.h in Headers */,
index d913813..12ab9f1 100644 (file)
@@ -22,6 +22,7 @@
 #ifndef JSDOMBinding_h
 #define JSDOMBinding_h
 
+#include "CSSMutableStyleDeclaration.h"
 #include "CSSRule.h"
 #include "CSSStyleSheet.h"
 #include "JSDOMGlobalObject.h"
@@ -206,9 +207,9 @@ enum ParameterMissingPolicy {
             return root(parentRule);
         if (CSSStyleSheet* styleSheet = style->parentStyleSheet())
             return root(styleSheet);
-        if (style->isMutableStyleDeclaration()) {
-            if (Node* node = static_cast<CSSMutableStyleDeclaration*>(style)->element())
-                return root(node);
+        if (style->isElementStyleDeclaration()) {
+            if (StyledElement* element = static_cast<CSSElementStyleDeclaration*>(style)->element())
+                return root(element);
         }
         return style;
     }
diff --git a/Source/WebCore/css/CSSInlineStyleDeclaration.h b/Source/WebCore/css/CSSInlineStyleDeclaration.h
new file mode 100644 (file)
index 0000000..d22c552
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef CSSInlineStyleDeclaration_h
+#define CSSInlineStyleDeclaration_h
+
+#include "CSSMutableStyleDeclaration.h"
+
+namespace WebCore {
+
+class CSSInlineStyleDeclaration : public CSSElementStyleDeclaration {
+public:
+    virtual ~CSSInlineStyleDeclaration() { }
+
+    static PassRefPtr<CSSInlineStyleDeclaration> create()
+    {
+        return adoptRef(new CSSInlineStyleDeclaration);
+    }
+
+private:
+    CSSInlineStyleDeclaration()
+        : CSSElementStyleDeclaration(/* isInline */ true)
+    {
+    }
+};
+
+} // namespace WebCore
+
+#endif // CSSInlineStyleDeclaration_h
index b79ead9..ebfd082 100644 (file)
@@ -107,31 +107,27 @@ CSSMutableStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
 #endif // ENABLE(MUTATION_OBSERVERS)
 
 CSSMutableStyleDeclaration::CSSMutableStyleDeclaration()
-    : CSSStyleDeclaration(0, /* isMutable */ true)
-    , m_element(0)
+    : CSSStyleDeclaration(0)
 {
     // This constructor is used for various inline style declarations, so disable strict parsing.
     m_strictParsing = false;
 }
 
 CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(CSSRule* parent)
-    : CSSStyleDeclaration(parent, /* isMutable */ true)
-    , m_element(0)
+    : CSSStyleDeclaration(parent)
 {
 }
 
 CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(CSSRule* parent, const Vector<CSSProperty>& properties)
-    : CSSStyleDeclaration(parent, /* isMutable */ true)
+    : CSSStyleDeclaration(parent)
     , m_properties(properties)
-    , m_element(0)
 {
     m_properties.shrinkToFit();
     // FIXME: This allows duplicate properties.
 }
 
 CSSMutableStyleDeclaration::CSSMutableStyleDeclaration(CSSRule* parent, const CSSProperty* const * properties, int numProperties)
-    : CSSStyleDeclaration(parent, /* isMutable */ true)
-    , m_element(0)
+    : CSSStyleDeclaration(parent)
 {
     m_properties.reserveInitialCapacity(numProperties);
     HashMap<int, bool> candidates;
@@ -156,7 +152,6 @@ CSSMutableStyleDeclaration::~CSSMutableStyleDeclaration()
 CSSMutableStyleDeclaration& CSSMutableStyleDeclaration::operator=(const CSSMutableStyleDeclaration& other)
 {
     ASSERT(!m_iteratorCount);
-    // don't attach it to the same element, just leave the current m_element value
     m_properties = other.m_properties;
     m_strictParsing = other.m_strictParsing;
     return *this;
@@ -614,24 +609,18 @@ String CSSMutableStyleDeclaration::removeProperty(int propertyID, bool notifyCha
     return value;
 }
 
-bool CSSMutableStyleDeclaration::isInlineStyleDeclaration()
-{
-    // FIXME: Ideally, this should be factored better and there
-    // should be a subclass of CSSMutableStyleDeclaration just
-    // for inline style declarations that handles this
-    return m_element && m_element->inlineStyleDecl() == this;
-}
-
 void CSSMutableStyleDeclaration::setNeedsStyleRecalc()
 {
-    if (m_element) {
-        if (isInlineStyleDeclaration()) {
-            m_element->setNeedsStyleRecalc(InlineStyleChange);
-            m_element->invalidateStyleAttribute();
-            if (m_element->document())
-                InspectorInstrumentation::didInvalidateStyleAttr(m_element->document(), m_element);
-        } else
-            m_element->setNeedsStyleRecalc(FullStyleChange);
+    if (isElementStyleDeclaration() && static_cast<CSSElementStyleDeclaration*>(this)->element()) {
+        StyledElement* element = static_cast<CSSElementStyleDeclaration*>(this)->element();
+        if (!isInlineStyleDeclaration())
+            element->setNeedsStyleRecalc(FullStyleChange);
+        else {
+            element->setNeedsStyleRecalc(InlineStyleChange);
+            element->invalidateStyleAttribute();
+            if (Document* document = element->document())
+                InspectorInstrumentation::didInvalidateStyleAttr(document, element);
+        }
         return;
     }
 
index 717b21f..32fa239 100644 (file)
@@ -83,10 +83,6 @@ public:
     const_iterator begin() { return const_iterator(this, m_properties.begin()); }
     const_iterator end() { return const_iterator(this, m_properties.end()); }
 
-    void setElement(StyledElement* element) { m_element = element; }
-
-    StyledElement* element() const { return m_element; }
-
     virtual String cssText() const;
     virtual void setCssText(const String&, ExceptionCode&);
 
@@ -139,13 +135,11 @@ public:
 
     bool propertiesEqual(const CSSMutableStyleDeclaration* o) const { return m_properties == o->m_properties; }
 
-    bool isInlineStyleDeclaration();
-
 protected:
     CSSMutableStyleDeclaration(CSSRule* parentRule);
+    CSSMutableStyleDeclaration();
 
 private:
-    CSSMutableStyleDeclaration();
     CSSMutableStyleDeclaration(CSSRule* parentRule, const Vector<CSSProperty>&);
     CSSMutableStyleDeclaration(CSSRule* parentRule, const CSSProperty* const *, int numProperties);
 
@@ -178,11 +172,29 @@ private:
 
     Vector<CSSProperty, 4> m_properties;
 
-    StyledElement* m_element;
-
     friend class CSSMutableStyleDeclarationConstIterator;
 };
 
+class CSSElementStyleDeclaration : public CSSMutableStyleDeclaration {
+public:
+    StyledElement* element() const { return m_element; }
+    void setElement(StyledElement* element) { m_element = element; }
+
+protected:
+    CSSElementStyleDeclaration(bool isInline)
+        : CSSMutableStyleDeclaration()
+        , m_element(0)
+    {
+        m_isElementStyleDeclaration = true;
+        m_isInlineStyleDeclaration = isInline;
+    }
+
+    virtual ~CSSElementStyleDeclaration() { }
+
+private:
+    StyledElement* m_element;
+};
+
 inline CSSMutableStyleDeclarationConstIterator::CSSMutableStyleDeclarationConstIterator(const CSSMutableStyleDeclaration* decl, CSSProperty* current)
 : m_decl(decl)
 , m_current(current)
index 228bda2..84a8322 100644 (file)
@@ -38,12 +38,13 @@ using namespace WTF;
 
 namespace WebCore {
 
-CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parent, bool isMutable)
+CSSStyleDeclaration::CSSStyleDeclaration(CSSRule* parent)
     : m_strictParsing(!parent || parent->useStrictParsing())
 #ifndef NDEBUG
     , m_iteratorCount(0)
 #endif
-    , m_isMutableStyleDeclaration(isMutable)
+    , m_isElementStyleDeclaration(false)
+    , m_isInlineStyleDeclaration(false)
     , m_parentIsRule(true)
     , m_parentRule(parent)
 {
index 267bacd..33edc74 100644 (file)
@@ -102,22 +102,28 @@ public:
     void showStyle();
 #endif
 
-    bool isMutableStyleDeclaration() const { return m_isMutableStyleDeclaration; }
+    bool isElementStyleDeclaration() const { return m_isElementStyleDeclaration; }
+    bool isInlineStyleDeclaration() const { return m_isInlineStyleDeclaration; }
 
 protected:
-    CSSStyleDeclaration(CSSRule* parentRule = 0, bool isMutable = false);
+    CSSStyleDeclaration(CSSRule* parentRule = 0);
 
     virtual bool cssPropertyMatches(const CSSProperty*) const;
 
-    // These bits are only used by CSSMutableStyleDeclaration but kept here
+    // The bits in this section are only used by specific subclasses but kept here
     // to maximize struct packing.
+
+    // CSSMutableStyleDeclaration bits:
     bool m_strictParsing : 1;
 #ifndef NDEBUG
     unsigned m_iteratorCount : 4;
 #endif
 
+    // CSSElementStyleDeclaration bits:
+    bool m_isElementStyleDeclaration : 1;
+    bool m_isInlineStyleDeclaration : 1;
+
 private:
-    bool m_isMutableStyleDeclaration : 1;
     bool m_parentIsRule : 1;
     union {
         CSSRule* m_parentRule;
index 3916f26..ab12cbc 100644 (file)
@@ -66,8 +66,10 @@ void CSSStyleRule::setSelectorText(const String& selectorText)
     if (CSSStyleSheet* styleSheet = m_style->parentStyleSheet())
         doc = styleSheet->findDocument();
 
-    if (!doc)
-        doc = m_style->element() ? m_style->element()->document() : 0;
+    if (!doc && m_style->isElementStyleDeclaration()) {
+        if (StyledElement* element = static_cast<CSSElementStyleDeclaration*>(m_style.get())->element())
+            doc = element->document();
+    }
 
     if (!doc)
         return;
index 19ba5a0..d397866 100644 (file)
 
 namespace WebCore {
 
-class CSSMappedAttributeDeclaration : public CSSMutableStyleDeclaration {
+class CSSMappedAttributeDeclaration : public CSSElementStyleDeclaration {
 public:
     static PassRefPtr<CSSMappedAttributeDeclaration> create()
     {
-        return adoptRef(new CSSMappedAttributeDeclaration(0));
+        return adoptRef(new CSSMappedAttributeDeclaration);
     }
 
     virtual ~CSSMappedAttributeDeclaration();
@@ -48,13 +48,13 @@ public:
     }
 
 private:
-    CSSMappedAttributeDeclaration(CSSRule* parentRule)
-        : CSSMutableStyleDeclaration(parentRule)
+    CSSMappedAttributeDeclaration()
+        : CSSElementStyleDeclaration(/* isInline */ false)
         , m_entryType(eNone)
         , m_attrName(anyQName())
     {
     }
-    
+
     MappedAttributeEntry m_entryType;
     QualifiedName m_attrName;
     AtomicString m_attrValue;
index c9fe19a..7bde0e8 100644 (file)
@@ -25,7 +25,7 @@
 #include "StyledElement.h"
 
 #include "Attribute.h"
-#include "CSSMutableStyleDeclaration.h"
+#include "CSSInlineStyleDeclaration.h"
 #include "CSSStyleSelector.h"
 #include "CSSStyleSheet.h"
 #include "CSSValueKeywords.h"
@@ -129,7 +129,7 @@ PassRefPtr<Attribute> StyledElement::createAttribute(const QualifiedName& name,
 
 void StyledElement::createInlineStyleDecl()
 {
-    m_inlineStyleDecl = CSSMutableStyleDeclaration::create();
+    m_inlineStyleDecl = CSSInlineStyleDeclaration::create();
     m_inlineStyleDecl->setParentStyleSheet(document()->elementSheet());
     m_inlineStyleDecl->setElement(this);
     m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inQuirksMode());
@@ -249,7 +249,7 @@ void StyledElement::parseMappedAttribute(Attribute* attr)
     }
 }
 
-CSSMutableStyleDeclaration* StyledElement::getInlineStyleDecl()
+CSSInlineStyleDeclaration* StyledElement::getInlineStyleDecl()
 {
     if (!m_inlineStyleDecl)
         createInlineStyleDecl();
@@ -446,7 +446,7 @@ void StyledElement::copyNonAttributeProperties(const Element *sourceElement)
 
 void StyledElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
 {
-    if (CSSMutableStyleDeclaration* style = inlineStyleDecl())
+    if (CSSInlineStyleDeclaration* style = inlineStyleDecl())
         style->addSubresourceStyleURLs(urls);
 }
 
index 32fc4c2..8282c29 100644 (file)
@@ -25,6 +25,7 @@
 #ifndef StyledElement_h
 #define StyledElement_h
 
+#include "CSSInlineStyleDeclaration.h"
 #include "Element.h"
 #include "MappedAttributeEntry.h"
 
@@ -32,7 +33,6 @@ namespace WebCore {
 
 class Attribute;
 class CSSMappedAttributeDeclaration;
-class CSSMutableStyleDeclaration;
 
 class StyledElement : public Element {
 public:
@@ -54,10 +54,10 @@ public:
     static CSSMappedAttributeDeclaration* getMappedAttributeDecl(MappedAttributeEntry, Attribute*);
     static void setMappedAttributeDecl(MappedAttributeEntry, Attribute*, CSSMappedAttributeDeclaration*);
 
-    CSSMutableStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
+    CSSInlineStyleDeclaration* inlineStyleDecl() const { return m_inlineStyleDecl.get(); }
     virtual bool canHaveAdditionalAttributeStyleDecls() const { return false; }
     virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&) { }
-    CSSMutableStyleDeclaration* getInlineStyleDecl();
+    CSSInlineStyleDeclaration* getInlineStyleDecl();
     CSSStyleDeclaration* style();
     void invalidateStyleAttribute();
 
@@ -93,7 +93,7 @@ private:
     void destroyInlineStyleDecl();
     virtual void updateStyleAttribute() const;
 
-    RefPtr<CSSMutableStyleDeclaration> m_inlineStyleDecl;
+    RefPtr<CSSInlineStyleDeclaration> m_inlineStyleDecl;
 };
 
 inline const SpaceSplitString& StyledElement::classNames() const
index ca1d275..aef34a5 100644 (file)
@@ -442,12 +442,9 @@ void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<Inspector
 // static
 Element* InspectorCSSAgent::inlineStyleElement(CSSStyleDeclaration* style)
 {
-    if (!style || !style->isMutableStyleDeclaration())
+    if (!style || !style->isInlineStyleDeclaration())
         return 0;
-    CSSMutableStyleDeclaration* mutableStyle = static_cast<CSSMutableStyleDeclaration*>(style);
-    if (!mutableStyle->isInlineStyleDeclaration())
-        return 0;
-    return mutableStyle->element();
+    return static_cast<CSSInlineStyleDeclaration*>(style)->element();
 }
 
 InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Element* element)