Implement CSSGroupingRule for @host @-rules and @supports.
authortasak@google.com <tasak@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2013 07:08:28 +0000 (07:08 +0000)
committertasak@google.com <tasak@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 Jan 2013 07:08:28 +0000 (07:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106418

Reviewed by Antti Koivisto.

CSSGroupingRule is to share code between CSSMediaRule, CSSSupportsRule
and CSSHostRule. @supports and @host @-rules are dervied from
CSSGroupingRule:
http://www.w3.org/TR/2012/WD-css3-conditional/#the-cssgroupingrule-interface
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#css-host-rule-interface
Since @media is also derived from CSSGroupingRule and @region has the
same interface as CSSGroupingRule, modify to use CSSGroupingRule:
http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule

No new tests, because no new feature is implemented.

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
Added CSSGroupingRule.h and CSSGroupingRule.cpp.
* css/CSSAllInOne.cpp:
Modified to include CSSGroupingRule.cpp.
* css/CSSGroupingRule.cpp: Added.
(WebCore):
(WebCore::CSSGroupingRule::CSSGroupingRule):
(WebCore::CSSGroupingRule::~CSSGroupingRule):
(WebCore::CSSGroupingRule::insertRule):
(WebCore::CSSGroupingRule::deleteRule):
(WebCore::CSSGroupingRule::appendCssTextForItems):
(WebCore::CSSGroupingRule::length):
(WebCore::CSSGroupingRule::item):
(WebCore::CSSGroupingRule::cssRules):
(WebCore::CSSGroupingRule::reattach):
(WebCore::CSSGroupingRule::reportMemoryUsage):
These codes are moved from CSSMediaRule and WebKitCSSRegionRule.
* css/CSSGroupingRule.h:
(WebCore):
(CSSGroupingRule):
* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::CSSMediaRule):
(WebCore::CSSMediaRule::~CSSMediaRule):
Make CSSMediaRule inherit CSSGroupingRule.
(WebCore::CSSMediaRule::media):
(WebCore::CSSMediaRule::reattach):
Keep the code for updating media queries' CSSOMWrapper.
(WebCore::CSSMediaRule::reportMemoryUsage):
We need to report media queries' CSSOMWrapper memory usage.
(WebCore::CSSMediaRule::mediaQueries):
(WebCore::CSSMediaRule::cssText):
* css/CSSMediaRule.h:
* css/WebKitCSSRegionRule.cpp:
Make WebKitCSSRegionRule inherit CSSGroupingRule.
(WebCore::WebKitCSSRegionRule::WebKitCSSRegionRule):
(WebCore::WebKitCSSRegionRule::cssText):
* css/WebKitCSSRegionRule.h:
* css/StyleRule.h:
Added inlined accessor to obtain StyleRuleMedia* and StyleRuleRegion*
from StyleRuleBlock*.

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

15 files changed:
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/CSSAllInOne.cpp
Source/WebCore/css/CSSGroupingRule.cpp [new file with mode: 0644]
Source/WebCore/css/CSSGroupingRule.h [new file with mode: 0644]
Source/WebCore/css/CSSMediaRule.cpp
Source/WebCore/css/CSSMediaRule.h
Source/WebCore/css/StyleRule.h
Source/WebCore/css/WebKitCSSRegionRule.cpp
Source/WebCore/css/WebKitCSSRegionRule.h

index 6500f44..1bce621 100644 (file)
@@ -1033,6 +1033,7 @@ set(WebCore_SOURCES
     css/CSSFontSelector.cpp
     css/CSSFunctionValue.cpp
     css/CSSGradientValue.cpp
+    css/CSSGroupingRule.cpp
     css/CSSImageGeneratorValue.cpp
     css/CSSImageSetValue.cpp
     css/CSSImageValue.cpp
index 6e7c0c5..fe0b188 100644 (file)
@@ -1,3 +1,67 @@
+2013-01-10  Takashi Sakamoto  <tasak@google.com>
+
+        Implement CSSGroupingRule for @host @-rules and @supports.
+        https://bugs.webkit.org/show_bug.cgi?id=106418
+
+        Reviewed by Antti Koivisto.
+
+        CSSGroupingRule is to share code between CSSMediaRule, CSSSupportsRule
+        and CSSHostRule. @supports and @host @-rules are dervied from
+        CSSGroupingRule:
+        http://www.w3.org/TR/2012/WD-css3-conditional/#the-cssgroupingrule-interface
+        https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html#css-host-rule-interface
+        Since @media is also derived from CSSGroupingRule and @region has the
+        same interface as CSSGroupingRule, modify to use CSSGroupingRule:
+        http://dev.w3.org/csswg/css3-regions/#the-at-region-style-rule
+
+        No new tests, because no new feature is implemented.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        Added CSSGroupingRule.h and CSSGroupingRule.cpp.
+        * css/CSSAllInOne.cpp:
+        Modified to include CSSGroupingRule.cpp.
+        * css/CSSGroupingRule.cpp: Added.
+        (WebCore):
+        (WebCore::CSSGroupingRule::CSSGroupingRule):
+        (WebCore::CSSGroupingRule::~CSSGroupingRule):
+        (WebCore::CSSGroupingRule::insertRule):
+        (WebCore::CSSGroupingRule::deleteRule):
+        (WebCore::CSSGroupingRule::appendCssTextForItems):
+        (WebCore::CSSGroupingRule::length):
+        (WebCore::CSSGroupingRule::item):
+        (WebCore::CSSGroupingRule::cssRules):
+        (WebCore::CSSGroupingRule::reattach):
+        (WebCore::CSSGroupingRule::reportMemoryUsage):
+        These codes are moved from CSSMediaRule and WebKitCSSRegionRule.
+        * css/CSSGroupingRule.h:
+        (WebCore):
+        (CSSGroupingRule):
+        * css/CSSMediaRule.cpp:
+        (WebCore::CSSMediaRule::CSSMediaRule):
+        (WebCore::CSSMediaRule::~CSSMediaRule):
+        Make CSSMediaRule inherit CSSGroupingRule.
+        (WebCore::CSSMediaRule::media):
+        (WebCore::CSSMediaRule::reattach):
+        Keep the code for updating media queries' CSSOMWrapper.
+        (WebCore::CSSMediaRule::reportMemoryUsage):
+        We need to report media queries' CSSOMWrapper memory usage.
+        (WebCore::CSSMediaRule::mediaQueries):
+        (WebCore::CSSMediaRule::cssText):
+        * css/CSSMediaRule.h:
+        * css/WebKitCSSRegionRule.cpp:
+        Make WebKitCSSRegionRule inherit CSSGroupingRule.
+        (WebCore::WebKitCSSRegionRule::WebKitCSSRegionRule):
+        (WebCore::WebKitCSSRegionRule::cssText):
+        * css/WebKitCSSRegionRule.h:
+        * css/StyleRule.h:
+        Added inlined accessor to obtain StyleRuleMedia* and StyleRuleRegion*
+        from StyleRuleBlock*.
+
 2012-12-28  Andrey Adaikin  <aandrey@chromium.org>
 
         Web Inspector: [Canvas] add an option to reload the page if there is an uninstrumented canvas
index 6d4a026..66e9f9e 100644 (file)
@@ -2543,6 +2543,8 @@ webcore_sources += \
        Source/WebCore/css/CSSFunctionValue.h \
        Source/WebCore/css/CSSGradientValue.cpp \
        Source/WebCore/css/CSSGradientValue.h \
+       Source/WebCore/css/CSSGroupingRule.cpp \
+       Source/WebCore/css/CSSGroupingRule.h \
        Source/WebCore/css/CSSHelper.h \
        Source/WebCore/css/CSSImageGeneratorValue.cpp \
        Source/WebCore/css/CSSImageGeneratorValue.h \
index ebe403e..34f50f0 100644 (file)
@@ -263,6 +263,7 @@ SOURCES += \
     css/CSSFontFaceSource.cpp \
     css/CSSFunctionValue.cpp \
     css/CSSGradientValue.cpp \
+    css/CSSGroupingRule.cpp \
     css/CSSImageValue.cpp \
     css/CSSImageGeneratorValue.cpp \
     css/CSSImageSetValue.cpp \
@@ -1473,6 +1474,7 @@ HEADERS += \
     css/CSSFontSelector.h \
     css/CSSFunctionValue.h \
     css/CSSGradientValue.h \
+    css/CSSGroupingRule.h \
     css/CSSHelper.h \
     css/CSSImageGeneratorValue.h \
     css/CSSImageValue.h \
index fd0a7e5..aa8d287 100644 (file)
             'css/CSSFunctionValue.h',
             'css/CSSGradientValue.cpp',
             'css/CSSGradientValue.h',
+            'css/CSSGroupingRule.cpp',
+            'css/CSSGroupingRule.h',
             'css/CSSImageGeneratorValue.cpp',
             'css/CSSImageSetValue.cpp',
             'css/CSSImageValue.cpp',
index 20f6e17..2719553 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\css\CSSGroupingRule.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Debug|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Release_Cairo_CFLite|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Debug_All|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Production|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath="..\css\CSSGroupingRule.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\css\CSSHelper.h"
                                >
                        </File>
index 481085c..92a8145 100644 (file)
                FABE72FD1059C21100D999DD /* MathMLElementFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FABE72FB1059C21100D999DD /* MathMLElementFactory.cpp */; };
                FABE72FE1059C21100D999DD /* MathMLNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FABE72FC1059C21100D999DD /* MathMLNames.cpp */; };
                FB2C15C3165D649D0039C9F8 /* CachedSVGDocumentReference.h in Headers */ = {isa = PBXBuildFile; fileRef = FB2C15C2165D64900039C9F8 /* CachedSVGDocumentReference.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               FB3056C2169E5DAC0096A232 /* CSSGroupingRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */; };
                FB78AD2E151BF5E600FE54D3 /* CSSParserMode.h in Headers */ = {isa = PBXBuildFile; fileRef = FB78AD2C151BF5D200FE54D3 /* CSSParserMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FB92DF4B15FED08700994433 /* ClipPathOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = FB92DF4915FED08700994433 /* ClipPathOperation.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FBC220DF1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBC220DE1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp */; };
                FBD6AF8B15EF25E5008B7110 /* CSSBasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */; };
                FBD6AF8C15EF2604008B7110 /* BasicShapes.h in Headers */ = {isa = PBXBuildFile; fileRef = FBD6AF8315EF21A3008B7110 /* BasicShapes.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FBD6AF8D15EF260A008B7110 /* BasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8215EF21A3008B7110 /* BasicShapes.cpp */; };
+               FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */; };
                FD00D7A414A3F61900734011 /* SincResampler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FD00D7A214A3F61900734011 /* SincResampler.cpp */; };
                FD00D7A514A3F61900734011 /* SincResampler.h in Headers */ = {isa = PBXBuildFile; fileRef = FD00D7A314A3F61900734011 /* SincResampler.h */; };
                FD06DFA5134A4DEF006F5D7D /* DefaultAudioDestinationNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FD06DFA3134A4DEF006F5D7D /* DefaultAudioDestinationNode.cpp */; };
                FABE72FB1059C21100D999DD /* MathMLElementFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLElementFactory.cpp; sourceTree = "<group>"; };
                FABE72FC1059C21100D999DD /* MathMLNames.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MathMLNames.cpp; sourceTree = "<group>"; };
                FB2C15C2165D64900039C9F8 /* CachedSVGDocumentReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CachedSVGDocumentReference.h; sourceTree = "<group>"; };
+               FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSGroupingRule.h; sourceTree = "<group>"; };
                FB78AD2C151BF5D200FE54D3 /* CSSParserMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSParserMode.h; sourceTree = "<group>"; };
                FB92DF4915FED08700994433 /* ClipPathOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipPathOperation.h; sourceTree = "<group>"; };
                FBC220DE1237FBEB00BCF788 /* GraphicsContext3DOpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContext3DOpenGL.cpp; sourceTree = "<group>"; };
                FBD6AF8515EF21D4008B7110 /* BasicShapeFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicShapeFunctions.h; sourceTree = "<group>"; };
                FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBasicShapes.cpp; sourceTree = "<group>"; };
                FBD6AF8715EF21D4008B7110 /* CSSBasicShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBasicShapes.h; sourceTree = "<group>"; };
+               FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGroupingRule.cpp; sourceTree = "<group>"; };
                FCEBCD711623A7910029965E /* CSSGrammar.y.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; path = CSSGrammar.y.in; sourceTree = "<group>"; };
                FCEBCD721623A7910029965E /* CSSGrammar.y.includes */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.yacc; path = CSSGrammar.y.includes; sourceTree = "<group>"; };
                FD00D7A214A3F61900734011 /* SincResampler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SincResampler.cpp; sourceTree = "<group>"; };
                                BC53C6910DA591140021EB5D /* CSSGradientValue.h */,
                                FCEBCD711623A7910029965E /* CSSGrammar.y.in */,
                                FCEBCD721623A7910029965E /* CSSGrammar.y.includes */,
+                               FB3056C1169E5DAC0096A232 /* CSSGroupingRule.h */,
+                               FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */,
                                BC772B360C4EA91E0083285F /* CSSHelper.h */,
                                BC23E76B0DAE88A9009FDC91 /* CSSImageGeneratorValue.cpp */,
                                BC23EE910DAED2BC009FDC91 /* CSSImageGeneratorValue.h */,
                                BC02A63C0E09A9CF004B6D2B /* CSSFunctionValue.h in Headers */,
                                BC53C6920DA591140021EB5D /* CSSGradientValue.h in Headers */,
                                650F53DC09D15DDA00C9B0C8 /* CSSGrammar.h in Headers */,
+                               FB3056C2169E5DAC0096A232 /* CSSGroupingRule.h in Headers */,
                                BC772B3C0C4EA91E0083285F /* CSSHelper.h in Headers */,
                                BC23EE920DAED2BC009FDC91 /* CSSImageGeneratorValue.h in Headers */,
                                9393E600151A99F200066F06 /* CSSImageSetValue.h in Headers */,
                                E1BE512D0CF6C512002EA959 /* XSLTUnicodeSort.cpp in Sources */,
                                977E2E0E12F0FC9C00C13379 /* XSSAuditor.cpp in Sources */,
                                FD537352137B651800008DCE /* ZeroPole.cpp in Sources */,
+                               FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 6b7a8b9..b06a68d 100644 (file)
@@ -41,6 +41,7 @@
 #include "CSSFontSelector.cpp"
 #include "CSSFunctionValue.cpp"
 #include "CSSGradientValue.cpp"
+#include "CSSGroupingRule.cpp"
 #include "CSSImageGeneratorValue.cpp"
 #include "CSSImageValue.cpp"
 #include "CSSImportRule.cpp"
diff --git a/Source/WebCore/css/CSSGroupingRule.cpp b/Source/WebCore/css/CSSGroupingRule.cpp
new file mode 100644 (file)
index 0000000..1a19ecc
--- /dev/null
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
+ * 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 THE COPYRIGHT HOLDER "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 THE COPYRIGHT HOLDER 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.
+ */
+
+#include "config.h"
+
+#include "CSSGroupingRule.h"
+
+#include "CSSParser.h"
+#include "CSSRuleList.h"
+#include "CSSStyleSheet.h"
+#include "ExceptionCode.h"
+#include "StyleRule.h"
+#include "WebCoreMemoryInstrumentation.h"
+#include <wtf/MemoryInstrumentationVector.h>
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+CSSGroupingRule::CSSGroupingRule(StyleRuleBlock* groupRule, CSSStyleSheet* parent)
+    : CSSRule(parent)
+    , m_groupRule(groupRule)
+    , m_childRuleCSSOMWrappers(groupRule->childRules().size())
+{
+}
+
+CSSGroupingRule::~CSSGroupingRule()
+{
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->setParentRule(0);
+    }
+}
+
+unsigned CSSGroupingRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
+{
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
+
+    if (index > m_groupRule->childRules().size()) {
+        // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point.
+        ec = INDEX_SIZE_ERR;
+        return 0;
+    }
+
+    CSSParser parser(parserContext());
+    CSSStyleSheet* styleSheet = parentStyleSheet();
+    RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->contents() : 0, ruleString);
+    if (!newRule) {
+        // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
+        ec = SYNTAX_ERR;
+        return 0;
+    }
+
+    if (newRule->isImportRule()) {
+        // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested
+        // @media rule. They are currently not getting parsed, resulting in a SYNTAX_ERR
+        // to get raised above.
+
+        // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified
+        // index, e.g., if an @import rule is inserted after a standard rule set or other
+        // at-rule.
+        ec = HIERARCHY_REQUEST_ERR;
+        return 0;
+    }
+    CSSStyleSheet::RuleMutationScope mutationScope(this);
+
+    m_groupRule->wrapperInsertRule(index, newRule);
+
+    m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
+    return index;
+}
+
+void CSSGroupingRule::deleteRule(unsigned index, ExceptionCode& ec)
+{
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
+
+    if (index >= m_groupRule->childRules().size()) {
+        // INDEX_SIZE_ERR: Raised if the specified index does not correspond to a
+        // rule in the media rule list.
+        ec = INDEX_SIZE_ERR;
+        return;
+    }
+
+    CSSStyleSheet::RuleMutationScope mutationScope(this);
+
+    m_groupRule->wrapperRemoveRule(index);
+
+    if (m_childRuleCSSOMWrappers[index])
+        m_childRuleCSSOMWrappers[index]->setParentRule(0);
+    m_childRuleCSSOMWrappers.remove(index);
+}
+
+void CSSGroupingRule::appendCssTextForItems(StringBuilder& result) const
+{
+    unsigned size = length();
+    for (unsigned i = 0; i < size; ++i) {
+        result.appendLiteral("  ");
+        result.append(item(i)->cssText());
+        result.append('\n');
+    }
+}
+
+unsigned CSSGroupingRule::length() const
+{ 
+    return m_groupRule->childRules().size(); 
+}
+
+CSSRule* CSSGroupingRule::item(unsigned index) const
+{ 
+    if (index >= length())
+        return 0;
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
+    RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index];
+    if (!rule)
+        rule = m_groupRule->childRules()[index]->createCSSOMWrapper(const_cast<CSSGroupingRule*>(this));
+    return rule.get();
+}
+
+CSSRuleList* CSSGroupingRule::cssRules() const
+{
+    if (!m_ruleListCSSOMWrapper)
+        m_ruleListCSSOMWrapper = adoptPtr(new LiveCSSRuleList<CSSGroupingRule>(const_cast<CSSGroupingRule*>(this)));
+    return m_ruleListCSSOMWrapper.get();
+}
+
+void CSSGroupingRule::reattach(StyleRuleBase* rule)
+{
+    ASSERT(rule);
+    m_groupRule = static_cast<StyleRuleBlock*>(rule);
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->reattach(m_groupRule->childRules()[i].get());
+    }
+}
+
+void CSSGroupingRule::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+{
+    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
+    CSSRule::reportMemoryUsage(memoryObjectInfo);
+    info.addMember(m_childRuleCSSOMWrappers);
+    info.addMember(m_ruleListCSSOMWrapper);
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/CSSGroupingRule.h b/Source/WebCore/css/CSSGroupingRule.h
new file mode 100644 (file)
index 0000000..b2bcf3e
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * (C) 1999-2003 Lars Knoll (knoll@kde.org)
+ * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
+ * Copyright (C) 2002, 2006, 2008, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
+ *
+ * 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.
+ */
+
+#ifndef CSSGroupingRule_h
+#define CSSGroupingRule_h
+
+#include "CSSRule.h"
+#include "StyleRule.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class CSSRuleList;
+
+class CSSGroupingRule : public CSSRule {
+public:
+    virtual ~CSSGroupingRule();
+
+    virtual void reattach(StyleRuleBase*) OVERRIDE;
+    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
+
+    CSSRuleList* cssRules() const;
+
+    unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
+    void deleteRule(unsigned index, ExceptionCode&);
+        
+    // For CSSRuleList
+    unsigned length() const;
+    CSSRule* item(unsigned index) const;
+
+protected:
+    CSSGroupingRule(StyleRuleBlock* groupRule, CSSStyleSheet* parent);
+    
+    void appendCssTextForItems(StringBuilder&) const;
+
+    RefPtr<StyleRuleBlock> m_groupRule;
+    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
+    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
+};
+
+} // namespace WebCore
+
+#endif // CSSGroupingRule_h
index fc8624d..a843127 100644 (file)
 namespace WebCore {
 
 CSSMediaRule::CSSMediaRule(StyleRuleMedia* mediaRule, CSSStyleSheet* parent)
-    : CSSRule(parent)
-    , m_mediaRule(mediaRule)
-    , m_childRuleCSSOMWrappers(mediaRule->childRules().size())
+    : CSSGroupingRule(mediaRule, parent)
 {
 }
 
 CSSMediaRule::~CSSMediaRule()
 {
-    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());
-
-    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
-        if (m_childRuleCSSOMWrappers[i])
-            m_childRuleCSSOMWrappers[i]->setParentRule(0);
-    }
     if (m_mediaCSSOMWrapper)
         m_mediaCSSOMWrapper->clearParentRule();
 }
 
-unsigned CSSMediaRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
+MediaQuerySet* CSSMediaRule::mediaQueries() const
 {
-    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());
-
-    if (index > m_mediaRule->childRules().size()) {
-        // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point.
-        ec = INDEX_SIZE_ERR;
-        return 0;
-    }
-
-    CSSParser parser(parserContext());
-    CSSStyleSheet* styleSheet = parentStyleSheet();
-    RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? styleSheet->contents() : 0, ruleString);
-    if (!newRule) {
-        // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
-        ec = SYNTAX_ERR;
-        return 0;
-    }
-
-    if (newRule->isImportRule()) {
-        // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested
-        // @media rule.  They are currently not getting parsed, resulting in a SYNTAX_ERR
-        // to get raised above.
-
-        // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified
-        // index, e.g., if an @import rule is inserted after a standard rule set or other
-        // at-rule.
-        ec = HIERARCHY_REQUEST_ERR;
-        return 0;
-    }
-    CSSStyleSheet::RuleMutationScope mutationScope(this);
-
-    m_mediaRule->wrapperInsertRule(index, newRule);
-
-    m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
-    return index;
-}
-
-void CSSMediaRule::deleteRule(unsigned index, ExceptionCode& ec)
-{
-    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());
-
-    if (index >= m_mediaRule->childRules().size()) {
-        // INDEX_SIZE_ERR: Raised if the specified index does not correspond to a
-        // rule in the media rule list.
-        ec = INDEX_SIZE_ERR;
-        return;
-    }
-
-    CSSStyleSheet::RuleMutationScope mutationScope(this);
-
-    m_mediaRule->wrapperRemoveRule(index);
-
-    if (m_childRuleCSSOMWrappers[index])
-        m_childRuleCSSOMWrappers[index]->setParentRule(0);
-    m_childRuleCSSOMWrappers.remove(index);
+    return toStyleRuleMedia(m_groupRule.get())->mediaQueries();
 }
 
 String CSSMediaRule::cssText() const
 {
     StringBuilder result;
     result.append("@media ");
-    if (m_mediaRule->mediaQueries()) {
-        result.append(m_mediaRule->mediaQueries()->mediaText());
+    if (mediaQueries()) {
+        result.append(mediaQueries()->mediaText());
         result.append(' ');
     }
-    result.append("{ \n");
-    
-    unsigned size = length();
-    for (unsigned i = 0; i < size; ++i) {
-        result.append("  ");
-        result.append(item(i)->cssText());
-        result.append('\n');
-    }
-
+    result.appendLiteral("{ \n");
+    appendCssTextForItems(result);
     result.append('}');
     return result.toString();
 }
 
 MediaList* CSSMediaRule::media() const
 {
-    if (!m_mediaRule->mediaQueries())
+    if (!mediaQueries())
         return 0;
     if (!m_mediaCSSOMWrapper)
-        m_mediaCSSOMWrapper = MediaList::create(m_mediaRule->mediaQueries(), const_cast<CSSMediaRule*>(this));
+        m_mediaCSSOMWrapper = MediaList::create(mediaQueries(), const_cast<CSSMediaRule*>(this));
     return m_mediaCSSOMWrapper.get();
 }
 
-unsigned CSSMediaRule::length() const
-{ 
-    return m_mediaRule->childRules().size(); 
-}
-
-CSSRule* CSSMediaRule::item(unsigned index) const
-{ 
-    if (index >= length())
-        return 0;
-    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());
-    RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index];
-    if (!rule)
-        rule = m_mediaRule->childRules()[index]->createCSSOMWrapper(const_cast<CSSMediaRule*>(this));
-    return rule.get();
-}
-
-CSSRuleList* CSSMediaRule::cssRules() const
-{
-    if (!m_ruleListCSSOMWrapper)
-        m_ruleListCSSOMWrapper = adoptPtr(new LiveCSSRuleList<CSSMediaRule>(const_cast<CSSMediaRule*>(this)));
-    return m_ruleListCSSOMWrapper.get();
-}
-
 void CSSMediaRule::reattach(StyleRuleBase* rule)
 {
-    ASSERT(rule);
-    ASSERT(rule->isMediaRule());
-    m_mediaRule = static_cast<StyleRuleMedia*>(rule);
-    if (m_mediaCSSOMWrapper && m_mediaRule->mediaQueries())
-        m_mediaCSSOMWrapper->reattach(m_mediaRule->mediaQueries());
-    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
-        if (m_childRuleCSSOMWrappers[i])
-            m_childRuleCSSOMWrappers[i]->reattach(m_mediaRule->childRules()[i].get());
-    }
+    CSSGroupingRule::reattach(rule);
+    if (m_mediaCSSOMWrapper && mediaQueries())
+        m_mediaCSSOMWrapper->reattach(mediaQueries());
 }
 
 void CSSMediaRule::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
-    CSSRule::reportMemoryUsage(memoryObjectInfo);
+    CSSGroupingRule::reportMemoryUsage(memoryObjectInfo);
     info.addMember(m_mediaCSSOMWrapper);
-    info.addMember(m_childRuleCSSOMWrappers);
-    info.addMember(m_ruleListCSSOMWrapper);
 }
 
 } // namespace WebCore
index 8783594..9d74900 100644 (file)
 #ifndef CSSMediaRule_h
 #define CSSMediaRule_h
 
-#include "CSSRule.h"
+#include "CSSGroupingRule.h"
 #include "MediaList.h"
 
 namespace WebCore {
 
-class CSSRuleList;
 class StyleRuleMedia;
 
-class CSSMediaRule : public CSSRule {
+class CSSMediaRule : public CSSGroupingRule {
 public:
     static PassRefPtr<CSSMediaRule> create(StyleRuleMedia* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSMediaRule(rule, sheet)); }
 
@@ -43,22 +42,13 @@ public:
     virtual String cssText() const OVERRIDE;
 
     MediaList* media() const;
-    CSSRuleList* cssRules() const;
-
-    unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
-    void deleteRule(unsigned index, ExceptionCode&);
-        
-    // For CSSRuleList
-    unsigned length() const;
-    CSSRule* item(unsigned index) const;
 
 private:
     CSSMediaRule(StyleRuleMedia*, CSSStyleSheet*);
+
+    MediaQuerySet* mediaQueries() const;
     
-    RefPtr<StyleRuleMedia> m_mediaRule;
     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
-    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
-    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
 
 } // namespace WebCore
index 4ef7642..7464b1f 100644 (file)
@@ -275,6 +275,18 @@ private:
 };
 #endif // ENABLE(CSS_DEVICE_ADAPTATION)
 
+inline const StyleRuleMedia* toStyleRuleMedia(const StyleRuleBlock* rule)
+{
+    ASSERT(!rule || rule->isMediaRule());
+    return static_cast<const StyleRuleMedia*>(rule);
+}
+
+inline const StyleRuleRegion* toStyleRuleRegion(const StyleRuleBlock* rule)
+{
+    ASSERT(!rule || rule->isRegionRule());
+    return static_cast<const StyleRuleRegion*>(rule);
+}
+
 } // namespace WebCore
 
 #endif // StyleRule_h
index 68db964..6b748ca 100644 (file)
 
 namespace WebCore {
 WebKitCSSRegionRule::WebKitCSSRegionRule(StyleRuleRegion* regionRule, CSSStyleSheet* parent)
-    : CSSRule(parent)
-    , m_regionRule(regionRule)
-    , m_childRuleCSSOMWrappers(regionRule->childRules().size())
+    : CSSGroupingRule(regionRule, parent)
 {
 }
 
-WebKitCSSRegionRule::~WebKitCSSRegionRule()
-{
-    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
-        if (m_childRuleCSSOMWrappers[i])
-            m_childRuleCSSOMWrappers[i]->setParentRule(0);
-    }
-}
-
 String WebKitCSSRegionRule::cssText() const
 {
     StringBuilder result;
-    result.append("@-webkit-region ");
+    result.appendLiteral("@-webkit-region ");
 
     // First add the selectors.
-    result.append(m_regionRule->selectorList().selectorsText());
+    result.append(toStyleRuleRegion(m_groupRule.get())->selectorList().selectorsText());
 
     // Then add the rules.
-    result.append(" { \n");
-
-    unsigned size = length();
-    for (unsigned i = 0; i < size; ++i) {
-        result.append("  ");
-        result.append(item(i)->cssText());
-        result.append("\n");
-    }
-    result.append("}");
+    result.appendLiteral(" { \n");
+    appendCssTextForItems(result);
+    result.append('}');
     return result.toString();
 }
 
-unsigned WebKitCSSRegionRule::length() const
-{ 
-    return m_regionRule->childRules().size(); 
-}
-
-CSSRule* WebKitCSSRegionRule::item(unsigned index) const
-{ 
-    if (index >= length())
-        return 0;
-    ASSERT(m_childRuleCSSOMWrappers.size() == m_regionRule->childRules().size());
-    RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index];
-    if (!rule)
-        rule = m_regionRule->childRules()[index]->createCSSOMWrapper(const_cast<WebKitCSSRegionRule*>(this));
-    return rule.get();
-}
-
-CSSRuleList* WebKitCSSRegionRule::cssRules() const
-{
-    if (!m_ruleListCSSOMWrapper)
-        m_ruleListCSSOMWrapper = adoptPtr(new LiveCSSRuleList<WebKitCSSRegionRule>(const_cast<WebKitCSSRegionRule*>(this)));
-    return m_ruleListCSSOMWrapper.get();
-}
-
-void WebKitCSSRegionRule::reattach(StyleRuleBase* rule)
-{
-    ASSERT(rule);
-    ASSERT(rule->isRegionRule());
-    m_regionRule = static_cast<StyleRuleRegion*>(rule);
-    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
-        if (m_childRuleCSSOMWrappers[i])
-            m_childRuleCSSOMWrappers[i]->reattach(m_regionRule->childRules()[i].get());
-    }
-}
-
-void WebKitCSSRegionRule::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
-{
-    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
-    CSSRule::reportMemoryUsage(memoryObjectInfo);
-    info.addMember(m_regionRule);
-    info.addMember(m_childRuleCSSOMWrappers);
-    info.addMember(m_ruleListCSSOMWrapper);
-}
-
 } // namespace WebCore
 
 #endif
index a68ba11..6892f5b 100644 (file)
 #ifndef WebKitCSSRegionRule_h
 #define WebKitCSSRegionRule_h
 
-#include "CSSRule.h"
-#include <wtf/Vector.h>
+#include "CSSGroupingRule.h"
 
 #if ENABLE(CSS_REGIONS)
 
 namespace WebCore {
 
-class CSSRuleList;
 class StyleRuleRegion;
 
-class WebKitCSSRegionRule : public CSSRule {
+class WebKitCSSRegionRule : public CSSGroupingRule {
 public:
     static PassRefPtr<WebKitCSSRegionRule> create(StyleRuleRegion* rule, CSSStyleSheet* sheet) { return adoptRef(new WebKitCSSRegionRule(rule, sheet)); }
 
-    virtual ~WebKitCSSRegionRule();
-
     virtual CSSRule::Type type() const OVERRIDE { return WEBKIT_REGION_RULE; }
     virtual String cssText() const OVERRIDE;
-    virtual void reattach(StyleRuleBase*) OVERRIDE;
-    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
-
-    CSSRuleList* cssRules() const;
-    
-    // For CSSRuleList
-    unsigned length() const;
-    CSSRule* item(unsigned index) const;
 
 private:
     WebKitCSSRegionRule(StyleRuleRegion*, CSSStyleSheet* parent);
-
-    RefPtr<StyleRuleRegion> m_regionRule;
-    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
-    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
-    
-    friend class StyleRuleBlock;
 };
 
 }