Move PropertySetCSSStyleDeclaration to a file of its own
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2012 18:38:48 +0000 (18:38 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 21 Feb 2012 18:38:48 +0000 (18:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=79121

Rubber-stamped by Andreas Kling.

This makes StylePropertySet.cpp more readable.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* css/PropertySetCSSStyleDeclaration.cpp: Copied from Source/WebCore/css/StylePropertySet.cpp.
(WebCore::PropertySetCSSStyleDeclaration::ref):
(WebCore::PropertySetCSSStyleDeclaration::deref):
(WebCore):
* css/PropertySetCSSStyleDeclaration.h: Added.
(WebCore):
(PropertySetCSSStyleDeclaration):
(WebCore::PropertySetCSSStyleDeclaration::PropertySetCSSStyleDeclaration):
(WebCore::PropertySetCSSStyleDeclaration::parentElement):
(WebCore::PropertySetCSSStyleDeclaration::clearParentRule):
(WebCore::PropertySetCSSStyleDeclaration::clearParentElement):
(WebCore::PropertySetCSSStyleDeclaration::contextStyleSheet):
(WebCore::PropertySetCSSStyleDeclaration::setNeedsStyleRecalc):
(RuleCSSStyleDeclaration):
(WebCore::RuleCSSStyleDeclaration::RuleCSSStyleDeclaration):
(WebCore::RuleCSSStyleDeclaration::parentRule):
(WebCore::RuleCSSStyleDeclaration::clearParentRule):
(InlineCSSStyleDeclaration):
(WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
(WebCore::InlineCSSStyleDeclaration::parentElement):
(WebCore::InlineCSSStyleDeclaration::clearParentElement):
* css/StylePropertySet.cpp:
(WebCore):

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

Source/WebCore/CMakeLists.txt
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/css/PropertySetCSSStyleDeclaration.cpp [new file with mode: 0644]
Source/WebCore/css/PropertySetCSSStyleDeclaration.h [new file with mode: 0644]
Source/WebCore/css/StylePropertySet.cpp

index bdd288e..5bd9183 100644 (file)
@@ -489,6 +489,7 @@ SET(WebCore_SOURCES
     css/MediaQueryList.cpp
     css/MediaQueryListListener.cpp
     css/MediaQueryMatcher.cpp
+    css/PropertySetCSSStyleDeclaration.cpp
     css/RGBColor.cpp
     css/SelectorChecker.cpp
     css/ShadowValue.cpp
index 1de4a24..a524adb 100644 (file)
@@ -1,3 +1,42 @@
+2012-02-21  Antti Koivisto  <antti@apple.com>
+
+        Move PropertySetCSSStyleDeclaration to a file of its own
+        https://bugs.webkit.org/show_bug.cgi?id=79121
+
+        Rubber-stamped by Andreas Kling.
+
+        This makes StylePropertySet.cpp more readable.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/PropertySetCSSStyleDeclaration.cpp: Copied from Source/WebCore/css/StylePropertySet.cpp.
+        (WebCore::PropertySetCSSStyleDeclaration::ref):
+        (WebCore::PropertySetCSSStyleDeclaration::deref):
+        (WebCore):
+        * css/PropertySetCSSStyleDeclaration.h: Added.
+        (WebCore):
+        (PropertySetCSSStyleDeclaration):
+        (WebCore::PropertySetCSSStyleDeclaration::PropertySetCSSStyleDeclaration):
+        (WebCore::PropertySetCSSStyleDeclaration::parentElement):
+        (WebCore::PropertySetCSSStyleDeclaration::clearParentRule):
+        (WebCore::PropertySetCSSStyleDeclaration::clearParentElement):
+        (WebCore::PropertySetCSSStyleDeclaration::contextStyleSheet):
+        (WebCore::PropertySetCSSStyleDeclaration::setNeedsStyleRecalc):
+        (RuleCSSStyleDeclaration):
+        (WebCore::RuleCSSStyleDeclaration::RuleCSSStyleDeclaration):
+        (WebCore::RuleCSSStyleDeclaration::parentRule):
+        (WebCore::RuleCSSStyleDeclaration::clearParentRule):
+        (InlineCSSStyleDeclaration):
+        (WebCore::InlineCSSStyleDeclaration::InlineCSSStyleDeclaration):
+        (WebCore::InlineCSSStyleDeclaration::parentElement):
+        (WebCore::InlineCSSStyleDeclaration::clearParentElement):
+        * css/StylePropertySet.cpp:
+        (WebCore):
+
 2012-02-21  Philippe Normand  <pnormand@igalia.com>
 
         [GTK] WebAudio build is broken
index 45e5397..6781432 100644 (file)
@@ -1409,6 +1409,8 @@ webcore_sources += \
        Source/WebCore/css/MediaQueryMatcher.cpp \
        Source/WebCore/css/MediaQueryMatcher.h \
        Source/WebCore/css/Pair.h \
+       Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp \
+       Source/WebCore/css/PropertySetCSSStyleDeclaration.h \
        Source/WebCore/css/Rect.h \
        Source/WebCore/css/RGBColor.cpp \
        Source/WebCore/css/RGBColor.h \
index c76ce97..8fa53db 100644 (file)
@@ -451,6 +451,7 @@ SOURCES += \
     css/MediaQueryList.cpp \
     css/MediaQueryListListener.cpp \
     css/MediaQueryMatcher.cpp \
+    css/PropertySetCSSStyleDeclaration.cpp \
     css/RGBColor.cpp \
     css/SelectorChecker.cpp \
     css/ShadowValue.cpp \
index 3cc1442..32547cc 100644 (file)
             'css/MediaQueryListListener.h',
             'css/MediaQueryMatcher.cpp',
             'css/MediaQueryMatcher.h',
+            'css/PropertySetCSSStyleDeclaration.cpp',
+            'css/PropertySetCSSStyleDeclaration.h',
             'css/RGBColor.cpp',
             'css/RGBColor.h',
             'css/Rect.h',
index 3629c68..f402640 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\css\PropertySetCSSStyleDeclaration.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\css\PropertySetCSSStyleDeclaration.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\css\quirks.css"
                                >
                        </File>
index 170e14b..cb21b3a 100644 (file)
                E4AFD00E0DAF335500F5F55C /* SMILTimeContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AFD0080DAF335400F5F55C /* SMILTimeContainer.h */; };
                E4AFD00F0DAF335500F5F55C /* SVGSMILElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4AFD0090DAF335400F5F55C /* SVGSMILElement.cpp */; };
                E4AFD0100DAF335500F5F55C /* SVGSMILElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E4AFD00A0DAF335400F5F55C /* SVGSMILElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */; };
+               E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = E4BBED0D14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h */; };
                E4C1789A0EE6903800824D69 /* CSSSelectorList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C178950EE6903800824D69 /* CSSSelectorList.cpp */; };
                E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C178960EE6903800824D69 /* CSSSelectorList.h */; };
                E4C279580CF9741900E97B98 /* RenderMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C279560CF9741900E97B98 /* RenderMedia.cpp */; };
                E4B423800CBFB73C00AF2ECE /* JSHTMLMediaElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLMediaElement.h; sourceTree = "<group>"; };
                E4B423850CBFB73C00AF2ECE /* JSProgressEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSProgressEvent.cpp; sourceTree = "<group>"; };
                E4B423860CBFB73C00AF2ECE /* JSProgressEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSProgressEvent.h; sourceTree = "<group>"; };
+               E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PropertySetCSSStyleDeclaration.cpp; sourceTree = "<group>"; };
+               E4BBED0D14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertySetCSSStyleDeclaration.h; sourceTree = "<group>"; };
                E4C178950EE6903800824D69 /* CSSSelectorList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSSelectorList.cpp; sourceTree = "<group>"; };
                E4C178960EE6903800824D69 /* CSSSelectorList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSelectorList.h; sourceTree = "<group>"; };
                E4C279560CF9741900E97B98 /* RenderMedia.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMedia.cpp; sourceTree = "<group>"; };
                                D3AA10F1123A98AA0092152B /* MediaQueryMatcher.cpp */,
                                D3AA10F2123A98AA0092152B /* MediaQueryMatcher.h */,
                                A80E6CD10A1989CA007FB8C5 /* Pair.h */,
+                               E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */,
+                               E4BBED0D14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h */,
                                93CA4C9F09DF93FA00DF8677 /* quirks.css */,
                                BC4368E70C226E32005EFB5F /* Rect.h */,
                                A80E79960A19BD21007FB8C5 /* Rect.idl */,
                                E1BE512E0CF6C512002EA959 /* XSLTUnicodeSort.h in Headers */,
                                977E2E0F12F0FC9C00C13379 /* XSSAuditor.h in Headers */,
                                FD537353137B651800008DCE /* ZeroPole.h in Headers */,
+                               E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+                               E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp b/Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
new file mode 100644 (file)
index 0000000..428f195
--- /dev/null
@@ -0,0 +1,321 @@
+/*
+ * (C) 1999-2003 Lars Knoll (knoll@kde.org)
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "PropertySetCSSStyleDeclaration.h"
+
+#include "CSSParser.h"
+#include "HTMLNames.h"
+#include "InspectorInstrumentation.h"
+#include "MutationObserverInterestGroup.h"
+#include "MutationRecord.h"
+#include "StylePropertySet.h"
+#include "StyledElement.h"
+
+using namespace std;
+
+namespace WebCore {
+
+namespace {
+
+class StyleAttributeMutationScope {
+    WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
+public:
+    StyleAttributeMutationScope(PropertySetCSSStyleDeclaration* decl)
+    {
+        ++s_scopeCount;
+
+        if (s_scopeCount != 1) {
+            ASSERT(s_currentDecl == decl);
+            return;
+        }
+
+        ASSERT(!s_currentDecl);
+        s_currentDecl = decl;
+
+#if ENABLE(MUTATION_OBSERVERS)
+        if (!s_currentDecl->parentElement())
+            return;
+        m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(s_currentDecl->parentElement(), HTMLNames::styleAttr);
+        if (!m_mutationRecipients)
+            return;
+
+        AtomicString oldValue = m_mutationRecipients->isOldValueRequested() ? s_currentDecl->parentElement()->getAttribute(HTMLNames::styleAttr) : nullAtom;
+        m_mutation = MutationRecord::createAttributes(s_currentDecl->parentElement(), HTMLNames::styleAttr, oldValue);
+#endif
+    }
+
+    ~StyleAttributeMutationScope()
+    {
+        --s_scopeCount;
+        if (s_scopeCount)
+            return;
+
+#if ENABLE(MUTATION_OBSERVERS)
+        if (m_mutation && s_shouldDeliver)
+            m_mutationRecipients->enqueueMutationRecord(m_mutation);
+        s_shouldDeliver = false;
+#endif
+        if (!s_shouldNotifyInspector) {
+            s_currentDecl = 0;
+            return;
+        }
+        // We have to clear internal state before calling Inspector's code.
+        PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
+        s_currentDecl = 0;
+        s_shouldNotifyInspector = false;
+        if (localCopyStyleDecl->parentElement() && localCopyStyleDecl->parentElement()->document())
+            InspectorInstrumentation::didInvalidateStyleAttr(localCopyStyleDecl->parentElement()->document(), localCopyStyleDecl->parentElement());
+    }
+
+#if ENABLE(MUTATION_OBSERVERS)
+    void enqueueMutationRecord()
+    {
+        s_shouldDeliver = true;
+    }
+#endif
+
+    void didInvalidateStyleAttr()
+    {
+        s_shouldNotifyInspector = true;
+    }
+
+private:
+    static unsigned s_scopeCount;
+    static PropertySetCSSStyleDeclaration* s_currentDecl;
+    static bool s_shouldNotifyInspector;
+#if ENABLE(MUTATION_OBSERVERS)
+    static bool s_shouldDeliver;
+
+    OwnPtr<MutationObserverInterestGroup> m_mutationRecipients;
+    RefPtr<MutationRecord> m_mutation;
+#endif
+};
+
+unsigned StyleAttributeMutationScope::s_scopeCount = 0;
+PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
+bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
+#if ENABLE(MUTATION_OBSERVERS)
+bool StyleAttributeMutationScope::s_shouldDeliver = false;
+#endif
+
+} // namespace
+    
+void PropertySetCSSStyleDeclaration::ref()
+{ 
+    m_propertySet->ref();
+}
+
+void PropertySetCSSStyleDeclaration::deref()
+{ 
+    m_propertySet->deref(); 
+}
+
+unsigned PropertySetCSSStyleDeclaration::length() const
+{
+    return m_propertySet->propertyCount();
+}
+
+String PropertySetCSSStyleDeclaration::item(unsigned i) const
+{
+    if (i >= m_propertySet->propertyCount())
+        return "";
+    return getPropertyName(static_cast<CSSPropertyID>(m_propertySet->propertyAt(i).id()));
+}
+
+String PropertySetCSSStyleDeclaration::cssText() const
+{
+    return m_propertySet->asText();
+}
+    
+void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCode& ec)
+{
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
+    ec = 0;
+    // FIXME: Detect syntax errors and set ec.
+    m_propertySet->parseDeclaration(text, contextStyleSheet());
+
+    setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+    mutationScope.enqueueMutationRecord();    
+#endif
+}
+
+PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
+{
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return 0;
+    return m_propertySet->getPropertyCSSValue(propertyID);
+}
+
+String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
+{
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return String();
+    return m_propertySet->getPropertyValue(propertyID);
+}
+
+String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
+{
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return String();
+    return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
+}
+
+String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
+{
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return String();
+    int shorthandID = m_propertySet->getPropertyShorthand(propertyID);
+    if (!shorthandID)
+        return String();
+    return getPropertyName(static_cast<CSSPropertyID>(shorthandID));
+}
+
+bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName)
+{
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return false;
+    return m_propertySet->isPropertyImplicit(propertyID);
+}
+
+void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
+{
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return;
+    bool important = priority.find("important", 0, false) != notFound;
+    ec = 0;
+    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+    if (changed) {
+        // CSS DOM requires raising SYNTAX_ERR of parsing failed, but this is too dangerous for compatibility,
+        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
+}
+
+String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
+{
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
+    int propertyID = cssPropertyID(propertyName);
+    if (!propertyID)
+        return String();
+    ec = 0;
+    String result;
+    bool changes = m_propertySet->removeProperty(propertyID, &result);
+    if (changes) {
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
+    return result;
+}
+
+PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
+{ 
+    return m_propertySet->getPropertyCSSValue(propertyID); 
+}
+
+String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
+{ 
+    return m_propertySet->getPropertyValue(propertyID); 
+}
+
+void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
+{ 
+#if ENABLE(MUTATION_OBSERVERS)
+    StyleAttributeMutationScope mutationScope(this);
+#endif
+    ec = 0;
+    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
+    if (changed) {
+        setNeedsStyleRecalc();
+#if ENABLE(MUTATION_OBSERVERS)
+        mutationScope.enqueueMutationRecord();
+#endif
+    }
+}
+
+CSSStyleSheet* PropertySetCSSStyleDeclaration::parentStyleSheet() const
+{ 
+    return contextStyleSheet(); 
+}
+
+PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
+{
+    return m_propertySet->copy();
+}
+
+PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable()
+{
+    return m_propertySet;
+}
+
+bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
+{
+    return m_propertySet->propertyMatches(property);
+}
+
+void RuleCSSStyleDeclaration::setNeedsStyleRecalc()
+{
+    if (CSSStyleSheet* styleSheet = contextStyleSheet()) {
+        if (Document* document = styleSheet->findDocument())
+            document->styleSelectorChanged(DeferRecalcStyle);
+    }
+}
+    
+CSSStyleSheet* RuleCSSStyleDeclaration::contextStyleSheet() const
+{
+    return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
+}
+
+void InlineCSSStyleDeclaration::setNeedsStyleRecalc()
+{
+    if (!m_parentElement)
+        return;
+    m_parentElement->setNeedsStyleRecalc(InlineStyleChange);
+    m_parentElement->invalidateStyleAttribute();
+    StyleAttributeMutationScope(this).didInvalidateStyleAttr();
+    return;
+}
+
+CSSStyleSheet* InlineCSSStyleDeclaration::contextStyleSheet() const
+{
+    return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/PropertySetCSSStyleDeclaration.h b/Source/WebCore/css/PropertySetCSSStyleDeclaration.h
new file mode 100644 (file)
index 0000000..0edb98c
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2012 Apple Inc. All rights reserved.
+ *
+ * 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 PropertySetCSSStyleDeclaration_h
+#define PropertySetCSSStyleDeclaration_h
+
+#include "CSSStyleDeclaration.h"
+
+namespace WebCore {
+
+class CSSRule;
+class CSSProperty;
+class CSSStyleSheet;
+class CSSValue;
+class StylePropertySet;
+class StyledElement;
+
+class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
+public:
+    PropertySetCSSStyleDeclaration(StylePropertySet* propertySet) : m_propertySet(propertySet) { }
+    
+    virtual StyledElement* parentElement() const { return 0; }
+    virtual void clearParentRule() { ASSERT_NOT_REACHED(); }
+    virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
+    virtual CSSStyleSheet* contextStyleSheet() const { return 0; }
+    
+private:
+    virtual void ref() OVERRIDE;
+    virtual void deref() OVERRIDE;
+    
+    virtual CSSRule* parentRule() const OVERRIDE { return 0; };
+    virtual unsigned length() const OVERRIDE;
+    virtual String item(unsigned index) const OVERRIDE;
+    virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE;
+    virtual String getPropertyValue(const String& propertyName) OVERRIDE;
+    virtual String getPropertyPriority(const String& propertyName) OVERRIDE;
+    virtual String getPropertyShorthand(const String& propertyName) OVERRIDE;
+    virtual bool isPropertyImplicit(const String& propertyName) OVERRIDE;
+    virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode&) OVERRIDE;
+    virtual String removeProperty(const String& propertyName, ExceptionCode&) OVERRIDE;
+    virtual String cssText() const OVERRIDE;
+    virtual void setCssText(const String&, ExceptionCode&) OVERRIDE;
+    virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) OVERRIDE;
+    virtual String getPropertyValueInternal(CSSPropertyID) OVERRIDE;
+    virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&) OVERRIDE;
+    
+    virtual bool cssPropertyMatches(const CSSProperty*) const OVERRIDE;
+    virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
+    virtual PassRefPtr<StylePropertySet> copy() const OVERRIDE;
+    virtual PassRefPtr<StylePropertySet> makeMutable() OVERRIDE;
+    virtual void setNeedsStyleRecalc() { }    
+    
+protected:
+    StylePropertySet* m_propertySet;
+};
+
+class RuleCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
+{
+public:
+    RuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule)
+        : PropertySetCSSStyleDeclaration(propertySet)
+        , m_parentRule(parentRule) 
+    {
+    }
+    
+private:    
+    virtual CSSRule* parentRule() const { return m_parentRule; };
+    virtual void clearParentRule() { m_parentRule = 0; }
+    virtual void setNeedsStyleRecalc();
+    virtual CSSStyleSheet* contextStyleSheet() const;
+    
+    CSSRule* m_parentRule;
+};
+
+class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
+{
+public:
+    InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement)
+        : PropertySetCSSStyleDeclaration(propertySet)
+        , m_parentElement(parentElement) 
+    {
+    }
+    
+private:
+    virtual StyledElement* parentElement() const { return m_parentElement; }
+    virtual void clearParentElement() { m_parentElement = 0; }
+    virtual void setNeedsStyleRecalc();
+    virtual CSSStyleSheet* contextStyleSheet() const;
+    
+    StyledElement* m_parentElement;
+};
+
+} // namespace WebCore
+
+#endif
index a74c5c0..8e1870f 100644 (file)
@@ -34,9 +34,7 @@
 #include "Document.h"
 #include "ExceptionCode.h"
 #include "HTMLNames.h"
-#include "InspectorInstrumentation.h"
-#include "MutationObserverInterestGroup.h"
-#include "MutationRecord.h"
+#include "PropertySetCSSStyleDeclaration.h"
 #include "StyledElement.h"
 #include "WebKitMutationObserver.h"
 #include <wtf/text/StringBuilder.h>
@@ -53,166 +51,6 @@ static PropertySetCSSOMWrapperMap& propertySetCSSOMWrapperMap()
     return propertySetCSSOMWrapperMapInstance;
 }
 
-class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
-public:
-    PropertySetCSSStyleDeclaration(StylePropertySet* propertySet) : m_propertySet(propertySet) { }
-    
-    virtual StyledElement* parentElement() const { return 0; }
-    virtual void clearParentRule() { ASSERT_NOT_REACHED(); }
-    virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
-    virtual CSSStyleSheet* contextStyleSheet() const { return 0; }
-
-private:
-    virtual void ref() OVERRIDE { m_propertySet->ref(); }
-    virtual void deref() OVERRIDE { m_propertySet->deref(); }
-
-    virtual CSSRule* parentRule() const OVERRIDE { return 0; };
-    virtual unsigned length() const OVERRIDE;
-    virtual String item(unsigned index) const OVERRIDE;
-    virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE;
-    virtual String getPropertyValue(const String& propertyName) OVERRIDE;
-    virtual String getPropertyPriority(const String& propertyName) OVERRIDE;
-    virtual String getPropertyShorthand(const String& propertyName) OVERRIDE;
-    virtual bool isPropertyImplicit(const String& propertyName) OVERRIDE;
-    virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode&) OVERRIDE;
-    virtual String removeProperty(const String& propertyName, ExceptionCode&) OVERRIDE;
-    virtual String cssText() const OVERRIDE;
-    virtual void setCssText(const String&, ExceptionCode&) OVERRIDE;
-    virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) OVERRIDE;
-    virtual String getPropertyValueInternal(CSSPropertyID) OVERRIDE;
-    virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&) OVERRIDE;
-    
-    virtual bool cssPropertyMatches(const CSSProperty*) const OVERRIDE;
-    virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
-    virtual PassRefPtr<StylePropertySet> copy() const OVERRIDE;
-    virtual PassRefPtr<StylePropertySet> makeMutable() OVERRIDE;
-    virtual void setNeedsStyleRecalc() { }    
-
-protected:
-    StylePropertySet* m_propertySet;
-};
-
-class RuleCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
-{
-public:
-    RuleCSSStyleDeclaration(StylePropertySet* propertySet, CSSRule* parentRule)
-        : PropertySetCSSStyleDeclaration(propertySet)
-        , m_parentRule(parentRule) 
-    {
-    }
-
-private:    
-    virtual CSSRule* parentRule() const { return m_parentRule; };
-    virtual void clearParentRule() { m_parentRule = 0; }
-    virtual void setNeedsStyleRecalc();
-    virtual CSSStyleSheet* contextStyleSheet() const;
-    
-    CSSRule* m_parentRule;
-};
-
-class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
-{
-public:
-    InlineCSSStyleDeclaration(StylePropertySet* propertySet, StyledElement* parentElement)
-        : PropertySetCSSStyleDeclaration(propertySet)
-        , m_parentElement(parentElement) 
-    {
-    }
-
-private:
-    virtual StyledElement* parentElement() const { return m_parentElement; }
-    virtual void clearParentElement() { m_parentElement = 0; }
-    virtual void setNeedsStyleRecalc();
-    virtual CSSStyleSheet* contextStyleSheet() const;
-
-    StyledElement* m_parentElement;
-};
-
-namespace {
-
-class StyleAttributeMutationScope {
-    WTF_MAKE_NONCOPYABLE(StyleAttributeMutationScope);
-public:
-    StyleAttributeMutationScope(PropertySetCSSStyleDeclaration* decl)
-    {
-        ++s_scopeCount;
-
-        if (s_scopeCount != 1) {
-            ASSERT(s_currentDecl == decl);
-            return;
-        }
-
-        ASSERT(!s_currentDecl);
-        s_currentDecl = decl;
-
-#if ENABLE(MUTATION_OBSERVERS)
-        if (!s_currentDecl->parentElement())
-            return;
-        m_mutationRecipients = MutationObserverInterestGroup::createForAttributesMutation(s_currentDecl->parentElement(), HTMLNames::styleAttr);
-        if (!m_mutationRecipients)
-            return;
-
-        AtomicString oldValue = m_mutationRecipients->isOldValueRequested() ? s_currentDecl->parentElement()->getAttribute(HTMLNames::styleAttr) : nullAtom;
-        m_mutation = MutationRecord::createAttributes(s_currentDecl->parentElement(), HTMLNames::styleAttr, oldValue);
-#endif
-    }
-
-    ~StyleAttributeMutationScope()
-    {
-        --s_scopeCount;
-        if (s_scopeCount)
-            return;
-
-#if ENABLE(MUTATION_OBSERVERS)
-        if (m_mutation && s_shouldDeliver)
-            m_mutationRecipients->enqueueMutationRecord(m_mutation);
-        s_shouldDeliver = false;
-#endif
-        if (!s_shouldNotifyInspector) {
-            s_currentDecl = 0;
-            return;
-        }
-        // We have to clear internal state before calling Inspector's code.
-        PropertySetCSSStyleDeclaration* localCopyStyleDecl = s_currentDecl;
-        s_currentDecl = 0;
-        s_shouldNotifyInspector = false;
-        if (localCopyStyleDecl->parentElement() && localCopyStyleDecl->parentElement()->document())
-            InspectorInstrumentation::didInvalidateStyleAttr(localCopyStyleDecl->parentElement()->document(), localCopyStyleDecl->parentElement());
-    }
-
-#if ENABLE(MUTATION_OBSERVERS)
-    void enqueueMutationRecord()
-    {
-        s_shouldDeliver = true;
-    }
-#endif
-
-    void didInvalidateStyleAttr()
-    {
-        s_shouldNotifyInspector = true;
-    }
-
-private:
-    static unsigned s_scopeCount;
-    static PropertySetCSSStyleDeclaration* s_currentDecl;
-    static bool s_shouldNotifyInspector;
-#if ENABLE(MUTATION_OBSERVERS)
-    static bool s_shouldDeliver;
-
-    OwnPtr<MutationObserverInterestGroup> m_mutationRecipients;
-    RefPtr<MutationRecord> m_mutation;
-#endif
-};
-
-unsigned StyleAttributeMutationScope::s_scopeCount = 0;
-PropertySetCSSStyleDeclaration* StyleAttributeMutationScope::s_currentDecl = 0;
-bool StyleAttributeMutationScope::s_shouldNotifyInspector = false;
-#if ENABLE(MUTATION_OBSERVERS)
-bool StyleAttributeMutationScope::s_shouldDeliver = false;
-#endif
-
-} // namespace
-
 StylePropertySet::StylePropertySet()
     : m_strictParsing(false)
     , m_hasCSSOMWrapper(false)
@@ -1083,195 +921,6 @@ void StylePropertySet::clearParentElement(StyledElement* element)
     propertySetCSSOMWrapperMap().get(this)->clearParentElement();
 }
 
-unsigned PropertySetCSSStyleDeclaration::length() const
-{
-    return m_propertySet->propertyCount();
-}
-
-String PropertySetCSSStyleDeclaration::item(unsigned i) const
-{
-    if (i >= m_propertySet->propertyCount())
-        return "";
-    return getPropertyName(static_cast<CSSPropertyID>(m_propertySet->propertyAt(i).id()));
-}
-
-String PropertySetCSSStyleDeclaration::cssText() const
-{
-    return m_propertySet->asText();
-}
-    
-void PropertySetCSSStyleDeclaration::setCssText(const String& text, ExceptionCode& ec)
-{
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-    ec = 0;
-    // FIXME: Detect syntax errors and set ec.
-    m_propertySet->parseDeclaration(text, contextStyleSheet());
-
-    setNeedsStyleRecalc();
-#if ENABLE(MUTATION_OBSERVERS)
-    mutationScope.enqueueMutationRecord();    
-#endif
-}
-
-PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValue(const String& propertyName)
-{
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return 0;
-    return m_propertySet->getPropertyCSSValue(propertyID);
-}
-
-String PropertySetCSSStyleDeclaration::getPropertyValue(const String &propertyName)
-{
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return String();
-    return m_propertySet->getPropertyValue(propertyID);
-}
-
-String PropertySetCSSStyleDeclaration::getPropertyPriority(const String& propertyName)
-{
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return String();
-    return m_propertySet->propertyIsImportant(propertyID) ? "important" : "";
-}
-
-String PropertySetCSSStyleDeclaration::getPropertyShorthand(const String& propertyName)
-{
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return String();
-    int shorthandID = m_propertySet->getPropertyShorthand(propertyID);
-    if (!shorthandID)
-        return String();
-    return getPropertyName(static_cast<CSSPropertyID>(shorthandID));
-}
-
-bool PropertySetCSSStyleDeclaration::isPropertyImplicit(const String& propertyName)
-{
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return false;
-    return m_propertySet->isPropertyImplicit(propertyID);
-}
-
-void PropertySetCSSStyleDeclaration::setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode& ec)
-{
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return;
-    bool important = priority.find("important", 0, false) != notFound;
-    ec = 0;
-    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
-    if (changed) {
-        // CSS DOM requires raising SYNTAX_ERR of parsing failed, but this is too dangerous for compatibility,
-        // see <http://bugs.webkit.org/show_bug.cgi?id=7296>.
-        setNeedsStyleRecalc();
-#if ENABLE(MUTATION_OBSERVERS)
-        mutationScope.enqueueMutationRecord();
-#endif
-    }
-}
-
-String PropertySetCSSStyleDeclaration::removeProperty(const String& propertyName, ExceptionCode& ec)
-{
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-    int propertyID = cssPropertyID(propertyName);
-    if (!propertyID)
-        return String();
-    ec = 0;
-    String result;
-    bool changes = m_propertySet->removeProperty(propertyID, &result);
-    if (changes) {
-        setNeedsStyleRecalc();
-#if ENABLE(MUTATION_OBSERVERS)
-        mutationScope.enqueueMutationRecord();
-#endif
-    }
-    return result;
-}
-
-PassRefPtr<CSSValue> PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal(CSSPropertyID propertyID)
-{ 
-    return m_propertySet->getPropertyCSSValue(propertyID); 
-}
-
-String PropertySetCSSStyleDeclaration::getPropertyValueInternal(CSSPropertyID propertyID)
-{ 
-    return m_propertySet->getPropertyValue(propertyID); 
-}
-
-void PropertySetCSSStyleDeclaration::setPropertyInternal(CSSPropertyID propertyID, const String& value, bool important, ExceptionCode& ec)
-{ 
-#if ENABLE(MUTATION_OBSERVERS)
-    StyleAttributeMutationScope mutationScope(this);
-#endif
-    ec = 0;
-    bool changed = m_propertySet->setProperty(propertyID, value, important, contextStyleSheet());
-    if (changed) {
-        setNeedsStyleRecalc();
-#if ENABLE(MUTATION_OBSERVERS)
-        mutationScope.enqueueMutationRecord();
-#endif
-    }
-}
-
-CSSStyleSheet* PropertySetCSSStyleDeclaration::parentStyleSheet() const
-{ 
-    return contextStyleSheet(); 
-}
-
-PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::copy() const
-{
-    return m_propertySet->copy();
-}
-
-PassRefPtr<StylePropertySet> PropertySetCSSStyleDeclaration::makeMutable()
-{
-    return m_propertySet;
-}
-
-bool PropertySetCSSStyleDeclaration::cssPropertyMatches(const CSSProperty* property) const
-{
-    return m_propertySet->propertyMatches(property);
-}
-
-void RuleCSSStyleDeclaration::setNeedsStyleRecalc()
-{
-    if (CSSStyleSheet* styleSheet = contextStyleSheet()) {
-        if (Document* document = styleSheet->findDocument())
-            document->styleSelectorChanged(DeferRecalcStyle);
-    }
-}
-    
-CSSStyleSheet* RuleCSSStyleDeclaration::contextStyleSheet() const
-{
-    return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
-}
-
-void InlineCSSStyleDeclaration::setNeedsStyleRecalc()
-{
-    if (!m_parentElement)
-        return;
-    m_parentElement->setNeedsStyleRecalc(InlineStyleChange);
-    m_parentElement->invalidateStyleAttribute();
-    StyleAttributeMutationScope(this).didInvalidateStyleAttr();
-    return;
-}
-
-CSSStyleSheet* InlineCSSStyleDeclaration::contextStyleSheet() const
-{
-    return m_parentElement ? m_parentElement->document()->elementSheet() : 0;
-}
-
 class SameSizeAsStylePropertySet : public RefCounted<SameSizeAsStylePropertySet> {
     Vector<CSSProperty, 4> properties;
     unsigned bitfield;