Split remaining CSSRules into internal and CSSOM types
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Apr 2012 19:50:34 +0000 (19:50 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 2 Apr 2012 19:50:34 +0000 (19:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82728

Reviewed by Andreas Kling.

This will complete the move to internal types for CSS rules. The only remaining unsplit type is
the CSSStyleSheet itself.

By separating internal types from the CSSOM we save memory immediately and enable future performance
optimizations as we are no longer tied to the structure of the API.

CSSOM type              Internal type

CSSStyleRule            StyleRule -> StyleRuleBase
CSSPageRule             StyleRulePage -> StyleRuleBase
CSSFontFaceRule         StyleRuleFontFace -> StyleRuleBase
CSSMediaRule            StyleRuleMedia -> StyleRuleBlock -> StyleRuleBase
CSSImportRule           StyleRuleImport -> StyleRuleBase
CSSCharsetRule          String (owned by CSSStyleSheet)
CSSUnknownRule          Never instantiated
WebKitCSSRegionRule     StyleRuleRegion -> StyleRuleBlock -> StyleRuleBase
WebKitKeyframesRule     StyleRuleKeyframes -> StyleRuleBase
WebKitKeyframeRule      StyleKeyframe (owned by StyleRuleKeyframes)

StyleRuleBase is refcounted.

The CSSOM objects contain the public API functions and their implementations (almost) nothing else. Unlike the
CSSOM types they don't have parent pointers, saving memory.

The CSSOM tree is constructed on demand only. The CSSOM wrapper instances are constructed and owned by
the parent wrapper in the tree. Wrappers ref the corresponding internal type. The trees are kept in sync
when mutating.

All rules shrink by a pointer (from the parent pointer removal). The immediate memory savings from this patch are
larger as some earlier patches temporarily increased the memory use to allow incremental refactoring.

* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSDOMBinding.h:
(WebCore):
* css/CSSFontFaceRule.cpp:
(WebCore::CSSFontFaceRule::CSSFontFaceRule):
(WebCore::CSSFontFaceRule::style):
(WebCore::CSSFontFaceRule::cssText):
(WebCore):
* css/CSSFontFaceRule.h:
(WebCore):
(WebCore::CSSFontFaceRule::create):
(CSSFontFaceRule):
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::addFontFaceRule):
* css/CSSFontSelector.h:
(WebCore):
* css/CSSGrammar.y:
* css/CSSImportRule.cpp:
(WebCore::StyleRuleImport::create):
(WebCore::StyleRuleImport::StyleRuleImport):
(WebCore::StyleRuleImport::~StyleRuleImport):
(WebCore::StyleRuleImport::setCSSStyleSheet):
(WebCore::StyleRuleImport::isLoading):
(WebCore::StyleRuleImport::requestStyleSheet):
(WebCore::CSSImportRule::CSSImportRule):
(WebCore):
(WebCore::CSSImportRule::media):
(WebCore::CSSImportRule::cssText):
* css/CSSImportRule.h:
(StyleRuleImport):
(WebCore::StyleRuleImport::parentStyleSheet):
(WebCore::StyleRuleImport::clearParentStyleSheet):
(WebCore::StyleRuleImport::href):
(WebCore::StyleRuleImport::ImportedStyleSheetClient::ImportedStyleSheetClient):
(ImportedStyleSheetClient):
(CSSImportRule):
(WebCore::CSSImportRule::create):
(WebCore::CSSImportRule::href):
(WebCore::CSSImportRule::styleSheet):
(WebCore):
* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::CSSMediaRule):
(WebCore::CSSMediaRule::~CSSMediaRule):
(WebCore::CSSMediaRule::insertRule):
(WebCore::CSSMediaRule::deleteRule):
(WebCore::CSSMediaRule::cssText):
(WebCore::CSSMediaRule::media):
(WebCore):
(WebCore::CSSMediaRule::length):
(WebCore::CSSMediaRule::item):
(WebCore::CSSMediaRule::cssRules):
* css/CSSMediaRule.h:
(WebCore):
(WebCore::CSSMediaRule::create):
(CSSMediaRule):
* css/CSSPageRule.cpp:
(WebCore::CSSPageRule::CSSPageRule):
(WebCore::CSSPageRule::style):
(WebCore::CSSPageRule::selectorText):
(WebCore::CSSPageRule::setSelectorText):
(WebCore::CSSPageRule::cssText):
* css/CSSPageRule.h:
(WebCore):
(WebCore::CSSPageRule::create):
(CSSPageRule):
* css/CSSParser.cpp:
(WebCore::CSSParser::parseRule):
(WebCore::CSSParser::createImportRule):
(WebCore::CSSParser::createMediaRule):
(WebCore::CSSParser::createKeyframesRule):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::createFontFaceRule):
(WebCore::CSSParser::createPageRule):
(WebCore::CSSParser::createRegionRule):
(WebCore::CSSParser::createMarginAtRule):
* css/CSSParser.h:
(WebCore):
(CSSParser):
* css/CSSPropertySourceData.h:
(WebCore):
* css/CSSStyleRule.cpp:
(WebCore):
(WebCore::selectorTextCache):
(WebCore::CSSStyleRule::CSSStyleRule):
(WebCore::CSSStyleRule::~CSSStyleRule):
(WebCore::CSSStyleRule::setSelectorText):
* css/CSSStyleRule.h:
(WebCore):
(WebCore::CSSStyleRule::create):
(CSSStyleRule):
* css/CSSStyleSelector.cpp:
(RuleSet):
(WebCore::RuleSet::pageRules):
(WebCore::CSSStyleSelector::addKeyframeStyle):
(WebCore::CSSStyleSelector::sortAndTransferMatchedRules):
(WebCore::CSSStyleSelector::collectMatchingRulesForList):
* css/CSSStyleSelector.h:
(CSSStyleSelector):
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::CSSStyleSheet):
(WebCore::CSSStyleSheet::parserAppendRule):
(WebCore::CSSStyleSheet::createChildRuleCSSOMWrapper):
(WebCore::CSSStyleSheet::item):
(WebCore::CSSStyleSheet::clearCharsetRule):
(WebCore::CSSStyleSheet::clearRules):
(WebCore::CSSStyleSheet::rules):
(WebCore::CSSStyleSheet::insertRule):
(WebCore::CSSStyleSheet::deleteRule):
(WebCore::CSSStyleSheet::addSubresourceStyleURLs):
(WebCore::CSSStyleSheet::ensureCSSOMWrapper):
(WebCore):
(WebCore::CSSStyleSheet::ownerRule):
(WebCore::CSSStyleSheet::parentStyleSheet):
* css/CSSStyleSheet.h:
(WebCore):
(WebCore::CSSStyleSheet::create):
(CSSStyleSheet):
(WebCore::CSSStyleSheet::childRules):
(WebCore::CSSStyleSheet::importRules):
(WebCore::CSSStyleSheet::clearOwnerRule):
(WebCore::CSSStyleSheet::hasCharsetRule):
* css/StyleRule.cpp:
(WebCore::StyleRuleBase::createCSSOMWrapper):
(WebCore):
(WebCore::StyleRuleBase::destroy):
(WebCore::StyleRule::StyleRule):
(WebCore::StyleRule::setProperties):
(WebCore::StyleRulePage::StyleRulePage):
(WebCore::StyleRulePage::~StyleRulePage):
(WebCore::StyleRulePage::setProperties):
(WebCore::StyleRuleFontFace::StyleRuleFontFace):
(WebCore::StyleRuleFontFace::~StyleRuleFontFace):
(WebCore::StyleRuleFontFace::setProperties):
(WebCore::StyleRuleBlock::StyleRuleBlock):
(WebCore::StyleRuleBlock::wrapperInsertRule):
(WebCore::StyleRuleBlock::wrapperRemoveRule):
(WebCore::StyleRuleMedia::StyleRuleMedia):
(WebCore::StyleRuleRegion::StyleRuleRegion):
* css/StyleRule.h:
(WebCore):
(WebCore::StyleRuleBase::type):
(StyleRuleBase):
(WebCore::StyleRuleBase::isCharsetRule):
(WebCore::StyleRuleBase::isFontFaceRule):
(WebCore::StyleRuleBase::isKeyframesRule):
(WebCore::StyleRuleBase::isMediaRule):
(WebCore::StyleRuleBase::isPageRule):
(WebCore::StyleRuleBase::isStyleRule):
(WebCore::StyleRuleBase::isRegionRule):
(WebCore::StyleRuleBase::isImportRule):
(WebCore::StyleRuleBase::sourceLine):
(WebCore::StyleRuleBase::deref):
(WebCore::StyleRuleBase::StyleRuleBase):
(WebCore::StyleRuleBase::~StyleRuleBase):
(StyleRule):
(WebCore::StyleRule::create):
(WebCore::StyleRule::parserAdoptSelectorVector):
(WebCore::StyleRule::wrapperAdoptSelectorList):
(StyleRuleFontFace):
(WebCore::StyleRuleFontFace::create):
(WebCore::StyleRuleFontFace::properties):
(StyleRulePage):
(WebCore::StyleRulePage::create):
(WebCore::StyleRulePage::selector):
(WebCore::StyleRulePage::properties):
(WebCore::StyleRulePage::parserAdoptSelectorVector):
(WebCore::StyleRulePage::wrapperAdoptSelectorList):
(StyleRuleBlock):
(WebCore::StyleRuleBlock::childRules):
(StyleRuleMedia):
(WebCore::StyleRuleMedia::create):
(WebCore::StyleRuleMedia::mediaQueries):
(StyleRuleRegion):
(WebCore::StyleRuleRegion::create):
(WebCore::StyleRuleRegion::selectorList):
* css/StyleSheet.cpp:
(WebCore::StyleSheet::StyleSheet):
(WebCore):
* css/StyleSheet.h:
(WebCore):
(WebCore::StyleSheet::ownerRule):
(WebCore::StyleSheet::parentStyleSheet):
(StyleSheet):
* css/WebKitCSSKeyframesRule.cpp:
(WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
(WebCore):
(WebCore::StyleRuleKeyframes::~StyleRuleKeyframes):
(WebCore::StyleRuleKeyframes::parserAppendKeyframe):
(WebCore::StyleRuleKeyframes::wrapperAppendKeyframe):
(WebCore::StyleRuleKeyframes::wrapperRemoveKeyframe):
(WebCore::StyleRuleKeyframes::findKeyframeIndex):
(WebCore::WebKitCSSKeyframesRule::WebKitCSSKeyframesRule):
(WebCore::WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule):
(WebCore::WebKitCSSKeyframesRule::setName):
(WebCore::WebKitCSSKeyframesRule::insertRule):
(WebCore::WebKitCSSKeyframesRule::deleteRule):
(WebCore::WebKitCSSKeyframesRule::findRule):
(WebCore::WebKitCSSKeyframesRule::cssText):
(WebCore::WebKitCSSKeyframesRule::length):
(WebCore::WebKitCSSKeyframesRule::item):
* css/WebKitCSSKeyframesRule.h:
(WebCore):
(StyleRuleKeyframes):
(WebCore::StyleRuleKeyframes::create):
(WebCore::StyleRuleKeyframes::keyframes):
(WebCore::StyleRuleKeyframes::name):
(WebCore::StyleRuleKeyframes::setName):
(WebCore::WebKitCSSKeyframesRule::create):
(WebCore::WebKitCSSKeyframesRule::name):
(WebKitCSSKeyframesRule):
* css/WebKitCSSRegionRule.cpp:
(WebCore::WebKitCSSRegionRule::WebKitCSSRegionRule):
(WebCore::WebKitCSSRegionRule::~WebKitCSSRegionRule):
(WebCore::WebKitCSSRegionRule::cssText):
(WebCore::WebKitCSSRegionRule::length):
(WebCore):
(WebCore::WebKitCSSRegionRule::item):
(WebCore::WebKitCSSRegionRule::cssRules):
* css/WebKitCSSRegionRule.h:
(WebCore):
(WebCore::WebKitCSSRegionRule::create):
(WebKitCSSRegionRule):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::willMatchRuleImpl):
(WebCore::InspectorInstrumentation::willProcessRuleImpl):
* inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::ensureSourceData):
* inspector/InspectorStyleSheet.h:
(WebCore):
* svg/SVGFontFaceElement.cpp:
(WebCore::SVGFontFaceElement::SVGFontFaceElement):
(WebCore::SVGFontFaceElement::parseAttribute):
(WebCore::SVGFontFaceElement::fontFamily):
(WebCore::SVGFontFaceElement::rebuildFontFace):
(WebCore::SVGFontFaceElement::insertedIntoDocument):
(WebCore::SVGFontFaceElement::removedFromDocument):
* svg/SVGFontFaceElement.h:
(WebCore):
(WebCore::SVGFontFaceElement::fontFaceRule):
(SVGFontFaceElement):

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

35 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/css/CSSFontFaceRule.cpp
Source/WebCore/css/CSSFontFaceRule.h
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/css/CSSGrammar.y
Source/WebCore/css/CSSImportRule.cpp
Source/WebCore/css/CSSImportRule.h
Source/WebCore/css/CSSMediaRule.cpp
Source/WebCore/css/CSSMediaRule.h
Source/WebCore/css/CSSPageRule.cpp
Source/WebCore/css/CSSPageRule.h
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h
Source/WebCore/css/CSSPropertySourceData.h
Source/WebCore/css/CSSStyleRule.cpp
Source/WebCore/css/CSSStyleRule.h
Source/WebCore/css/CSSStyleSelector.cpp
Source/WebCore/css/CSSStyleSelector.h
Source/WebCore/css/CSSStyleSheet.cpp
Source/WebCore/css/CSSStyleSheet.h
Source/WebCore/css/StyleRule.cpp
Source/WebCore/css/StyleRule.h
Source/WebCore/css/StyleSheet.cpp
Source/WebCore/css/StyleSheet.h
Source/WebCore/css/WebKitCSSKeyframesRule.cpp
Source/WebCore/css/WebKitCSSKeyframesRule.h
Source/WebCore/css/WebKitCSSRegionRule.cpp
Source/WebCore/css/WebKitCSSRegionRule.h
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorStyleSheet.cpp
Source/WebCore/inspector/InspectorStyleSheet.h
Source/WebCore/svg/SVGFontFaceElement.cpp
Source/WebCore/svg/SVGFontFaceElement.h

index ed4a4e2..74bedeb 100644 (file)
@@ -1,3 +1,282 @@
+2012-04-02  Antti Koivisto  <antti@apple.com>
+
+        Split remaining CSSRules into internal and CSSOM types
+        https://bugs.webkit.org/show_bug.cgi?id=82728
+
+        Reviewed by Andreas Kling.
+
+        This will complete the move to internal types for CSS rules. The only remaining unsplit type is
+        the CSSStyleSheet itself.
+        
+        By separating internal types from the CSSOM we save memory immediately and enable future performance
+        optimizations as we are no longer tied to the structure of the API.
+        
+        CSSOM type              Internal type
+        
+        CSSStyleRule            StyleRule -> StyleRuleBase
+        CSSPageRule             StyleRulePage -> StyleRuleBase
+        CSSFontFaceRule         StyleRuleFontFace -> StyleRuleBase
+        CSSMediaRule            StyleRuleMedia -> StyleRuleBlock -> StyleRuleBase
+        CSSImportRule           StyleRuleImport -> StyleRuleBase
+        CSSCharsetRule          String (owned by CSSStyleSheet)
+        CSSUnknownRule          Never instantiated
+        WebKitCSSRegionRule     StyleRuleRegion -> StyleRuleBlock -> StyleRuleBase
+        WebKitKeyframesRule     StyleRuleKeyframes -> StyleRuleBase
+        WebKitKeyframeRule      StyleKeyframe (owned by StyleRuleKeyframes)
+        
+        StyleRuleBase is refcounted. 
+        
+        The CSSOM objects contain the public API functions and their implementations (almost) nothing else. Unlike the 
+        CSSOM types they don't have parent pointers, saving memory.  
+        
+        The CSSOM tree is constructed on demand only. The CSSOM wrapper instances are constructed and owned by 
+        the parent wrapper in the tree. Wrappers ref the corresponding internal type. The trees are kept in sync
+        when mutating.
+        
+        All rules shrink by a pointer (from the parent pointer removal). The immediate memory savings from this patch are
+        larger as some earlier patches temporarily increased the memory use to allow incremental refactoring. 
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSDOMBinding.h:
+        (WebCore):
+        * css/CSSFontFaceRule.cpp:
+        (WebCore::CSSFontFaceRule::CSSFontFaceRule):
+        (WebCore::CSSFontFaceRule::style):
+        (WebCore::CSSFontFaceRule::cssText):
+        (WebCore):
+        * css/CSSFontFaceRule.h:
+        (WebCore):
+        (WebCore::CSSFontFaceRule::create):
+        (CSSFontFaceRule):
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::addFontFaceRule):
+        * css/CSSFontSelector.h:
+        (WebCore):
+        * css/CSSGrammar.y:
+        * css/CSSImportRule.cpp:
+        (WebCore::StyleRuleImport::create):
+        (WebCore::StyleRuleImport::StyleRuleImport):
+        (WebCore::StyleRuleImport::~StyleRuleImport):
+        (WebCore::StyleRuleImport::setCSSStyleSheet):
+        (WebCore::StyleRuleImport::isLoading):
+        (WebCore::StyleRuleImport::requestStyleSheet):
+        (WebCore::CSSImportRule::CSSImportRule):
+        (WebCore):
+        (WebCore::CSSImportRule::media):
+        (WebCore::CSSImportRule::cssText):
+        * css/CSSImportRule.h:
+        (StyleRuleImport):
+        (WebCore::StyleRuleImport::parentStyleSheet):
+        (WebCore::StyleRuleImport::clearParentStyleSheet):
+        (WebCore::StyleRuleImport::href):
+        (WebCore::StyleRuleImport::ImportedStyleSheetClient::ImportedStyleSheetClient):
+        (ImportedStyleSheetClient):
+        (CSSImportRule):
+        (WebCore::CSSImportRule::create):
+        (WebCore::CSSImportRule::href):
+        (WebCore::CSSImportRule::styleSheet):
+        (WebCore):
+        * css/CSSMediaRule.cpp:
+        (WebCore::CSSMediaRule::CSSMediaRule):
+        (WebCore::CSSMediaRule::~CSSMediaRule):
+        (WebCore::CSSMediaRule::insertRule):
+        (WebCore::CSSMediaRule::deleteRule):
+        (WebCore::CSSMediaRule::cssText):
+        (WebCore::CSSMediaRule::media):
+        (WebCore):
+        (WebCore::CSSMediaRule::length):
+        (WebCore::CSSMediaRule::item):
+        (WebCore::CSSMediaRule::cssRules):
+        * css/CSSMediaRule.h:
+        (WebCore):
+        (WebCore::CSSMediaRule::create):
+        (CSSMediaRule):
+        * css/CSSPageRule.cpp:
+        (WebCore::CSSPageRule::CSSPageRule):
+        (WebCore::CSSPageRule::style):
+        (WebCore::CSSPageRule::selectorText):
+        (WebCore::CSSPageRule::setSelectorText):
+        (WebCore::CSSPageRule::cssText):
+        * css/CSSPageRule.h:
+        (WebCore):
+        (WebCore::CSSPageRule::create):
+        (CSSPageRule):
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::parseRule):
+        (WebCore::CSSParser::createImportRule):
+        (WebCore::CSSParser::createMediaRule):
+        (WebCore::CSSParser::createKeyframesRule):
+        (WebCore::CSSParser::createStyleRule):
+        (WebCore::CSSParser::createFontFaceRule):
+        (WebCore::CSSParser::createPageRule):
+        (WebCore::CSSParser::createRegionRule):
+        (WebCore::CSSParser::createMarginAtRule):
+        * css/CSSParser.h:
+        (WebCore):
+        (CSSParser):
+        * css/CSSPropertySourceData.h:
+        (WebCore):
+        * css/CSSStyleRule.cpp:
+        (WebCore):
+        (WebCore::selectorTextCache):
+        (WebCore::CSSStyleRule::CSSStyleRule):
+        (WebCore::CSSStyleRule::~CSSStyleRule):
+        (WebCore::CSSStyleRule::setSelectorText):
+        * css/CSSStyleRule.h:
+        (WebCore):
+        (WebCore::CSSStyleRule::create):
+        (CSSStyleRule):
+        * css/CSSStyleSelector.cpp:
+        (RuleSet):
+        (WebCore::RuleSet::pageRules):
+        (WebCore::CSSStyleSelector::addKeyframeStyle):
+        (WebCore::CSSStyleSelector::sortAndTransferMatchedRules):
+        (WebCore::CSSStyleSelector::collectMatchingRulesForList):
+        * css/CSSStyleSelector.h:
+        (CSSStyleSelector):
+        * css/CSSStyleSheet.cpp:
+        (WebCore::CSSStyleSheet::CSSStyleSheet):
+        (WebCore::CSSStyleSheet::parserAppendRule):
+        (WebCore::CSSStyleSheet::createChildRuleCSSOMWrapper):
+        (WebCore::CSSStyleSheet::item):
+        (WebCore::CSSStyleSheet::clearCharsetRule):
+        (WebCore::CSSStyleSheet::clearRules):
+        (WebCore::CSSStyleSheet::rules):
+        (WebCore::CSSStyleSheet::insertRule):
+        (WebCore::CSSStyleSheet::deleteRule):
+        (WebCore::CSSStyleSheet::addSubresourceStyleURLs):
+        (WebCore::CSSStyleSheet::ensureCSSOMWrapper):
+        (WebCore):
+        (WebCore::CSSStyleSheet::ownerRule):
+        (WebCore::CSSStyleSheet::parentStyleSheet):
+        * css/CSSStyleSheet.h:
+        (WebCore):
+        (WebCore::CSSStyleSheet::create):
+        (CSSStyleSheet):
+        (WebCore::CSSStyleSheet::childRules):
+        (WebCore::CSSStyleSheet::importRules):
+        (WebCore::CSSStyleSheet::clearOwnerRule):
+        (WebCore::CSSStyleSheet::hasCharsetRule):
+        * css/StyleRule.cpp:
+        (WebCore::StyleRuleBase::createCSSOMWrapper):
+        (WebCore):
+        (WebCore::StyleRuleBase::destroy):
+        (WebCore::StyleRule::StyleRule):
+        (WebCore::StyleRule::setProperties):
+        (WebCore::StyleRulePage::StyleRulePage):
+        (WebCore::StyleRulePage::~StyleRulePage):
+        (WebCore::StyleRulePage::setProperties):
+        (WebCore::StyleRuleFontFace::StyleRuleFontFace):
+        (WebCore::StyleRuleFontFace::~StyleRuleFontFace):
+        (WebCore::StyleRuleFontFace::setProperties):
+        (WebCore::StyleRuleBlock::StyleRuleBlock):
+        (WebCore::StyleRuleBlock::wrapperInsertRule):
+        (WebCore::StyleRuleBlock::wrapperRemoveRule):
+        (WebCore::StyleRuleMedia::StyleRuleMedia):
+        (WebCore::StyleRuleRegion::StyleRuleRegion):
+        * css/StyleRule.h:
+        (WebCore):
+        (WebCore::StyleRuleBase::type):
+        (StyleRuleBase):
+        (WebCore::StyleRuleBase::isCharsetRule):
+        (WebCore::StyleRuleBase::isFontFaceRule):
+        (WebCore::StyleRuleBase::isKeyframesRule):
+        (WebCore::StyleRuleBase::isMediaRule):
+        (WebCore::StyleRuleBase::isPageRule):
+        (WebCore::StyleRuleBase::isStyleRule):
+        (WebCore::StyleRuleBase::isRegionRule):
+        (WebCore::StyleRuleBase::isImportRule):
+        (WebCore::StyleRuleBase::sourceLine):
+        (WebCore::StyleRuleBase::deref):
+        (WebCore::StyleRuleBase::StyleRuleBase):
+        (WebCore::StyleRuleBase::~StyleRuleBase):
+        (StyleRule):
+        (WebCore::StyleRule::create):
+        (WebCore::StyleRule::parserAdoptSelectorVector):
+        (WebCore::StyleRule::wrapperAdoptSelectorList):
+        (StyleRuleFontFace):
+        (WebCore::StyleRuleFontFace::create):
+        (WebCore::StyleRuleFontFace::properties):
+        (StyleRulePage):
+        (WebCore::StyleRulePage::create):
+        (WebCore::StyleRulePage::selector):
+        (WebCore::StyleRulePage::properties):
+        (WebCore::StyleRulePage::parserAdoptSelectorVector):
+        (WebCore::StyleRulePage::wrapperAdoptSelectorList):
+        (StyleRuleBlock):
+        (WebCore::StyleRuleBlock::childRules):
+        (StyleRuleMedia):
+        (WebCore::StyleRuleMedia::create):
+        (WebCore::StyleRuleMedia::mediaQueries):
+        (StyleRuleRegion):
+        (WebCore::StyleRuleRegion::create):
+        (WebCore::StyleRuleRegion::selectorList):
+        * css/StyleSheet.cpp:
+        (WebCore::StyleSheet::StyleSheet):
+        (WebCore):
+        * css/StyleSheet.h:
+        (WebCore):
+        (WebCore::StyleSheet::ownerRule):
+        (WebCore::StyleSheet::parentStyleSheet):
+        (StyleSheet):
+        * css/WebKitCSSKeyframesRule.cpp:
+        (WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
+        (WebCore):
+        (WebCore::StyleRuleKeyframes::~StyleRuleKeyframes):
+        (WebCore::StyleRuleKeyframes::parserAppendKeyframe):
+        (WebCore::StyleRuleKeyframes::wrapperAppendKeyframe):
+        (WebCore::StyleRuleKeyframes::wrapperRemoveKeyframe):
+        (WebCore::StyleRuleKeyframes::findKeyframeIndex):
+        (WebCore::WebKitCSSKeyframesRule::WebKitCSSKeyframesRule):
+        (WebCore::WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule):
+        (WebCore::WebKitCSSKeyframesRule::setName):
+        (WebCore::WebKitCSSKeyframesRule::insertRule):
+        (WebCore::WebKitCSSKeyframesRule::deleteRule):
+        (WebCore::WebKitCSSKeyframesRule::findRule):
+        (WebCore::WebKitCSSKeyframesRule::cssText):
+        (WebCore::WebKitCSSKeyframesRule::length):
+        (WebCore::WebKitCSSKeyframesRule::item):
+        * css/WebKitCSSKeyframesRule.h:
+        (WebCore):
+        (StyleRuleKeyframes):
+        (WebCore::StyleRuleKeyframes::create):
+        (WebCore::StyleRuleKeyframes::keyframes):
+        (WebCore::StyleRuleKeyframes::name):
+        (WebCore::StyleRuleKeyframes::setName):
+        (WebCore::WebKitCSSKeyframesRule::create):
+        (WebCore::WebKitCSSKeyframesRule::name):
+        (WebKitCSSKeyframesRule):
+        * css/WebKitCSSRegionRule.cpp:
+        (WebCore::WebKitCSSRegionRule::WebKitCSSRegionRule):
+        (WebCore::WebKitCSSRegionRule::~WebKitCSSRegionRule):
+        (WebCore::WebKitCSSRegionRule::cssText):
+        (WebCore::WebKitCSSRegionRule::length):
+        (WebCore):
+        (WebCore::WebKitCSSRegionRule::item):
+        (WebCore::WebKitCSSRegionRule::cssRules):
+        * css/WebKitCSSRegionRule.h:
+        (WebCore):
+        (WebCore::WebKitCSSRegionRule::create):
+        (WebKitCSSRegionRule):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::willMatchRuleImpl):
+        (WebCore::InspectorInstrumentation::willProcessRuleImpl):
+        * inspector/InspectorStyleSheet.cpp:
+        (WebCore::InspectorStyleSheet::ensureSourceData):
+        * inspector/InspectorStyleSheet.h:
+        (WebCore):
+        * svg/SVGFontFaceElement.cpp:
+        (WebCore::SVGFontFaceElement::SVGFontFaceElement):
+        (WebCore::SVGFontFaceElement::parseAttribute):
+        (WebCore::SVGFontFaceElement::fontFamily):
+        (WebCore::SVGFontFaceElement::rebuildFontFace):
+        (WebCore::SVGFontFaceElement::insertedIntoDocument):
+        (WebCore::SVGFontFaceElement::removedFromDocument):
+        * svg/SVGFontFaceElement.h:
+        (WebCore):
+        (WebCore::SVGFontFaceElement::fontFaceRule):
+        (SVGFontFaceElement):
+
 2012-04-02  Rakesh KN  <rakesh.kn@motorola.com>
 
         Scroll position is lost after hide/show element
index 2f0025a..229aaf0 100644 (file)
                E4BBED0E14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */; };
                E4BBED0F14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = E4BBED0D14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.h */; };
                E4BBED4C14FCDBA1003F0B98 /* StyleRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4BBED4A14FCDBA1003F0B98 /* StyleRule.cpp */; };
-               E4BBED4D14FCDBA1003F0B98 /* StyleRule.h in Headers */ = {isa = PBXBuildFile; fileRef = E4BBED4B14FCDBA1003F0B98 /* StyleRule.h */; };
+               E4BBED4D14FCDBA1003F0B98 /* StyleRule.h in Headers */ = {isa = PBXBuildFile; fileRef = E4BBED4B14FCDBA1003F0B98 /* StyleRule.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E4C1789A0EE6903800824D69 /* CSSSelectorList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C178950EE6903800824D69 /* CSSSelectorList.cpp */; };
-               E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C178960EE6903800824D69 /* CSSSelectorList.h */; };
+               E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C178960EE6903800824D69 /* CSSSelectorList.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E4C279580CF9741900E97B98 /* RenderMedia.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4C279560CF9741900E97B98 /* RenderMedia.cpp */; };
                E4C279590CF9741900E97B98 /* RenderMedia.h in Headers */ = {isa = PBXBuildFile; fileRef = E4C279570CF9741900E97B98 /* RenderMedia.h */; };
                E4D687770ED7AE3D006EA978 /* PurgeableBufferMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4D687760ED7AE3D006EA978 /* PurgeableBufferMac.cpp */; };
                        isa = PBXHeadersBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */,
+                               E4BBED4D14FCDBA1003F0B98 /* StyleRule.h in Headers */,
                                97BC69DB1505F076001B74AC /* AbstractDatabase.h in Headers */,
                                41E1B1D10FF5986900576B3B /* AbstractWorker.h in Headers */,
                                29A8122E0FBB9C1D00510293 /* AccessibilityARIAGridCell.h in Headers */,
                                A80E6CF20A1989CA007FB8C5 /* CSSRuleList.h in Headers */,
                                371F51A10D262FA000ECE0D5 /* CSSSegmentedFontFace.h in Headers */,
                                A80E73520A199C77007FB8C5 /* CSSSelector.h in Headers */,
-                               E4C1789B0EE6903800824D69 /* CSSSelectorList.h in Headers */,
                                809DD1E0130DE2AD00CAE3ED /* CSSStyleApplyProperty.h in Headers */,
                                A80E6E0F0A19911C007FB8C5 /* CSSStyleDeclaration.h in Headers */,
                                A80E6D0C0A1989CA007FB8C5 /* CSSStyleRule.h in Headers */,
                                BC2272E40E82EE9B00E7F975 /* StyleRareInheritedData.h in Headers */,
                                BC2272BD0E82EAAE00E7F975 /* StyleRareNonInheritedData.h in Headers */,
                                BC2272870E82E70700E7F975 /* StyleReflection.h in Headers */,
-                               E4BBED4D14FCDBA1003F0B98 /* StyleRule.h in Headers */,
                                3138A9E51474434600B0ED12 /* StyleShader.h in Headers */,
                                A8EA800C0A19516E00A8EF5F /* StyleSheet.h in Headers */,
                                A8EA800A0A19516E00A8EF5F /* StyleSheetList.h in Headers */,
index d5b2d3a..7b611bb 100644 (file)
 #include "CSSFontFaceRule.h"
 
 #include "StylePropertySet.h"
+#include "StyleRule.h"
 
 namespace WebCore {
 
-CSSFontFaceRule::CSSFontFaceRule(CSSStyleSheet* parent)
+CSSFontFaceRule::CSSFontFaceRule(StyleRuleFontFace* fontFaceRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::FONT_FACE_RULE)
+    , m_fontFaceRule(fontFaceRule)
 {
 }
 
@@ -40,7 +42,7 @@ CSSFontFaceRule::~CSSFontFaceRule()
 CSSStyleDeclaration* CSSFontFaceRule::style() const
 {
     if (!m_propertiesCSSOMWrapper)
-        m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_style.get(), const_cast<CSSFontFaceRule*>(this));
+        m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_fontFaceRule->properties(), const_cast<CSSFontFaceRule*>(this));
     return m_propertiesCSSOMWrapper.get();
 }
 
@@ -48,15 +50,9 @@ String CSSFontFaceRule::cssText() const
 {
     String result("@font-face");
     result += " { ";
-    result += m_style->asText();
+    result += m_fontFaceRule->properties()->asText();
     result += "}";
     return result;
 }
 
-void CSSFontFaceRule::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
-{
-    if (m_style)
-        m_style->addSubresourceStyleURLs(urls, parentStyleSheet());
-}
-
 } // namespace WebCore
index ff88eae..222fc31 100644 (file)
 
 #include "CSSRule.h"
 #include "PropertySetCSSStyleDeclaration.h"
-#include "StylePropertySet.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
-    
+
+class CSSStyleDeclaration;
+class StyleRuleFontFace;
 class StyleRuleCSSStyleDeclaration;
 
 class CSSFontFaceRule : public CSSRule {
 public:
-    static PassRefPtr<CSSFontFaceRule> create()
-    {
-        return adoptRef(new CSSFontFaceRule(0));
-    }
-    static PassRefPtr<CSSFontFaceRule> create(CSSStyleSheet* parent)
-    {
-        return adoptRef(new CSSFontFaceRule(parent));
-    }
+    static PassRefPtr<CSSFontFaceRule> create(StyleRuleFontFace* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSFontFaceRule(rule, sheet)); }
 
     ~CSSFontFaceRule();
 
@@ -49,15 +43,10 @@ public:
 
     String cssText() const;
 
-    StylePropertySet* declaration() const { return m_style.get(); }
-    void setDeclaration(PassRefPtr<StylePropertySet> style) { m_style = style; }
-
-    void addSubresourceStyleURLs(ListHashSet<KURL>& urls);
-
 private:
-    CSSFontFaceRule(CSSStyleSheet* parent);
+    CSSFontFaceRule(StyleRuleFontFace*, CSSStyleSheet* parent);
 
-    RefPtr<StylePropertySet> m_style;
+    RefPtr<StyleRuleFontFace> m_fontFaceRule;
     
     mutable RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
index e002f2f..578a8fe 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "CachedFont.h"
 #include "CSSFontFace.h"
-#include "CSSFontFaceRule.h"
 #include "CSSFontFaceSource.h"
 #include "CSSFontFaceSrcValue.h"
 #include "CSSPrimitiveValue.h"
@@ -47,6 +46,7 @@
 #include "Settings.h"
 #include "SimpleFontData.h"
 #include "StylePropertySet.h"
+#include "StyleRule.h"
 #include "WebKitFontFamilyNames.h"
 #include <wtf/text/AtomicString.h>
 
@@ -83,10 +83,10 @@ bool CSSFontSelector::isEmpty() const
     return m_fonts.isEmpty();
 }
 
-void CSSFontSelector::addFontFaceRule(const CSSFontFaceRule* fontFaceRule)
+void CSSFontSelector::addFontFaceRule(const StyleRuleFontFace* fontFaceRule)
 {
     // Obtain the font-family property and the src property.  Both must be defined.
-    const StylePropertySet* style = fontFaceRule->declaration();
+    const StylePropertySet* style = fontFaceRule->properties();
     RefPtr<CSSValue> fontFamily = style->getPropertyCSSValue(CSSPropertyFontFamily);
     RefPtr<CSSValue> src = style->getPropertyCSSValue(CSSPropertySrc);
     RefPtr<CSSValue> unicodeRange = style->getPropertyCSSValue(CSSPropertyUnicodeRange);
index a5f8db5..3e7bda3 100644 (file)
@@ -43,6 +43,7 @@ class CSSSegmentedFontFace;
 class CachedFont;
 class Document;
 class FontDescription;
+class StyleRuleFontFace;
 
 class CSSFontSelector : public FontSelector {
 public:
@@ -58,7 +59,7 @@ public:
 
     void clearDocument();
 
-    void addFontFaceRule(const CSSFontFaceRule*);
+    void addFontFaceRule(const StyleRuleFontFace*);
 
     void fontLoaded();
     virtual void fontCacheInvalidated();
index 2819e0e..8f124cb 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "config.h"
 
-#include "CSSMediaRule.h"
 #include "CSSParser.h"
 #include "CSSParserMode.h"
 #include "CSSPrimitiveValue.h"
@@ -36,6 +35,7 @@
 #include "HTMLNames.h"
 #include "MediaList.h"
 #include "MediaQueryExp.h"
+#include "StyleRule.h"
 #include "WebKitCSSKeyframeRule.h"
 #include "WebKitCSSKeyframesRule.h"
 #include <wtf/FastMalloc.h>
@@ -68,8 +68,8 @@ using namespace HTMLNames;
     double number;
     CSSParserString string;
 
-    CSSRule* rule;
-    Vector<RefPtr<CSSRule> >* ruleList;
+    StyleRuleBase* rule;
+    Vector<RefPtr<StyleRuleBase> >* ruleList;
     CSSParserSelector* selector;
     Vector<OwnPtr<CSSParserSelector> >* selectorList;
     CSSSelector::MarginBoxType marginBox;
@@ -82,7 +82,7 @@ using namespace HTMLNames;
     CSSParserValueList* valueList;
     Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
     StyleKeyframe* keyframe;
-    WebKitCSSKeyframesRule* keyframesRule;
+    StyleRuleKeyframes* keyframesRule;
     float val;
 }
 
@@ -613,7 +613,7 @@ medium:
 keyframes:
     WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name maybe_space '{' maybe_space keyframes_rule '}' {
         $$ = $7;
-        $7->setNameInternal($3);
+        $7->setName($3);
     }
     ;
   
index f6b3218..04edf6a 100644 (file)
 
 namespace WebCore {
 
-PassRefPtr<CSSImportRule> CSSImportRule::create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
+PassRefPtr<StyleRuleImport> StyleRuleImport::create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
 {
-    return adoptRef(new CSSImportRule(parent, href, media));
+    return adoptRef(new StyleRuleImport(parent, href, media));
 }
 
-CSSImportRule::CSSImportRule(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
-    : CSSRule(parent, CSSRule::IMPORT_RULE)
+StyleRuleImport::StyleRuleImport(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet> media)
+    : StyleRuleBase(Import, 0)
+    , m_parentStyleSheet(parent)
     , m_styleSheetClient(this)
     , m_strHref(href)
     , m_mediaQueries(media)
@@ -51,7 +52,7 @@ CSSImportRule::CSSImportRule(CSSStyleSheet* parent, const String& href, PassRefP
         m_mediaQueries = MediaQuerySet::create(String());
 }
 
-CSSImportRule::~CSSImportRule()
+StyleRuleImport::~StyleRuleImport()
 {
     if (m_styleSheet)
         m_styleSheet->clearOwnerRule();
@@ -59,7 +60,7 @@ CSSImportRule::~CSSImportRule()
         m_cachedSheet->removeClient(&m_styleSheetClient);
 }
 
-void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
+void StyleRuleImport::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
 {
     if (m_styleSheet)
         m_styleSheet->clearOwnerRule();
@@ -67,10 +68,9 @@ void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, co
 
     bool crossOriginCSS = false;
     bool validMIMEType = false;
-    CSSStyleSheet* parent = parentStyleSheet();
-    CSSParserMode cssParserMode = parent ? parent->cssParserMode() : CSSStrictMode;
+    CSSParserMode cssParserMode = m_parentStyleSheet ? m_parentStyleSheet->cssParserMode() : CSSStrictMode;
     bool enforceMIMEType = isStrictParserMode(cssParserMode);
-    Document* document = parent ? parent->findDocument() : 0;
+    Document* document = m_parentStyleSheet ? m_parentStyleSheet->findDocument() : 0;
     bool needsSiteSpecificQuirks = document && document->settings() && document->settings()->needsSiteSpecificQuirks();
 
 #ifdef BUILDING_ON_LEOPARD
@@ -106,23 +106,22 @@ void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, co
 
     m_loading = false;
 
-    if (parent) {
-        parent->notifyLoadedSheet(sheet);
-        parent->checkLoaded();
+    if (m_parentStyleSheet) {
+        m_parentStyleSheet->notifyLoadedSheet(sheet);
+        m_parentStyleSheet->checkLoaded();
     }
 }
 
-bool CSSImportRule::isLoading() const
+bool StyleRuleImport::isLoading() const
 {
     return m_loading || (m_styleSheet && m_styleSheet->isLoading());
 }
 
-void CSSImportRule::requestStyleSheet()
+void StyleRuleImport::requestStyleSheet()
 {
-    CSSStyleSheet* parentSheet = parentStyleSheet();
-    if (!parentSheet)
+    if (!m_parentStyleSheet)
         return;
-    Document* document = parentSheet->findDocument();
+    Document* document = m_parentStyleSheet->findDocument();
     if (!document)
         return;
 
@@ -131,14 +130,14 @@ void CSSImportRule::requestStyleSheet()
         return;
 
     String absHref = m_strHref;
-    if (!parentSheet->finalURL().isNull())
+    if (!m_parentStyleSheet->finalURL().isNull())
         // use parent styleheet's URL as the base URL
-        absHref = KURL(parentSheet->finalURL(), m_strHref).string();
+        absHref = KURL(m_parentStyleSheet->finalURL(), m_strHref).string();
 
     // Check for a cycle in our import chain.  If we encounter a stylesheet
     // in our parent chain with the same URL, then just bail.
-    CSSStyleSheet* rootSheet = parentSheet;
-    for (CSSStyleSheet* sheet = parentSheet; sheet; sheet = sheet->parentStyleSheet()) {
+    CSSStyleSheet* rootSheet = m_parentStyleSheet;
+    for (CSSStyleSheet* sheet = m_parentStyleSheet; sheet; sheet = sheet->parentStyleSheet()) {
         // FIXME: This is wrong if the finalURL was updated via document::updateBaseURL.
         if (absHref == sheet->finalURL().string())
             return;
@@ -146,46 +145,46 @@ void CSSImportRule::requestStyleSheet()
     }
 
     ResourceRequest request(document->completeURL(absHref));
-    if (parentSheet->isUserStyleSheet())
-        m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, parentSheet->charset());
+    if (m_parentStyleSheet->isUserStyleSheet())
+        m_cachedSheet = cachedResourceLoader->requestUserCSSStyleSheet(request, m_parentStyleSheet->charset());
     else
-        m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, parentSheet->charset());
+        m_cachedSheet = cachedResourceLoader->requestCSSStyleSheet(request, m_parentStyleSheet->charset());
     if (m_cachedSheet) {
         // if the import rule is issued dynamically, the sheet may be
         // removed from the pending sheet count, so let the doc know
         // the sheet being imported is pending.
-        if (parentSheet && parentSheet->loadCompleted() && rootSheet == parentSheet)
-            parentSheet->startLoadingDynamicSheet();
+        if (m_parentStyleSheet && m_parentStyleSheet->loadCompleted() && rootSheet == m_parentStyleSheet)
+            m_parentStyleSheet->startLoadingDynamicSheet();
         m_loading = true;
         m_cachedSheet->addClient(&m_styleSheetClient);
     }
 }
 
+CSSImportRule::CSSImportRule(StyleRuleImport* importRule, CSSStyleSheet* parent)
+    : CSSRule(parent, CSSRule::IMPORT_RULE)
+    , m_importRule(importRule)
+{
+}
+
 MediaList* CSSImportRule::media()
 {
-    return m_mediaQueries->ensureMediaList(parentStyleSheet());
+    return m_importRule->mediaQueries()->ensureMediaList(parentStyleSheet());
 }
 
 String CSSImportRule::cssText() const
 {
     StringBuilder result;
     result.append("@import url(\"");
-    result.append(m_strHref);
+    result.append(m_importRule->href());
     result.append("\")");
 
-    if (m_mediaQueries) {
+    if (m_importRule->mediaQueries()) {
         result.append(' ');
-        result.append(m_mediaQueries->mediaText());
+        result.append(m_importRule->mediaQueries()->mediaText());
     }
     result.append(';');
-
+    
     return result.toString();
 }
 
-void CSSImportRule::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
-{
-    if (m_styleSheet)
-        addSubresourceURL(urls, m_styleSheet->baseURL());
-}
-
 } // namespace WebCore
index 9ac1c2e..3661b7f 100644 (file)
@@ -26,6 +26,7 @@
 #include "CachedResourceHandle.h"
 #include "CachedStyleSheetClient.h"
 #include "PlatformString.h"
+#include "StyleRule.h"
 
 namespace WebCore {
 
@@ -33,45 +34,46 @@ class CachedCSSStyleSheet;
 class MediaList;
 class MediaQuerySet;
 
-class CSSImportRule : public CSSRule {
+class StyleRuleImport : public StyleRuleBase {
 public:
-    static PassRefPtr<CSSImportRule> create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
+    static PassRefPtr<StyleRuleImport> create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
 
-    ~CSSImportRule();
+    ~StyleRuleImport();
+    
+    CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
+    void clearParentStyleSheet() { m_parentStyleSheet = 0; }
 
     String href() const { return m_strHref; }
-    MediaList* media();
     CSSStyleSheet* styleSheet() const { return m_styleSheet.get(); }
 
-    String cssText() const;
-
     // Not part of the CSSOM.
     bool isLoading() const;
     MediaQuerySet* mediaQueries() { return m_mediaQueries.get(); }
 
-    void addSubresourceStyleURLs(ListHashSet<KURL>& urls);
-
     void requestStyleSheet();
 
 private:
     // NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it
-    // to avoid adding a vptr to CSSImportRule.
+    // to avoid adding a vptr to StyleRuleImport.
     class ImportedStyleSheetClient : public CachedStyleSheetClient {
     public:
-        ImportedStyleSheetClient(CSSImportRule* ownerRule) : m_ownerRule(ownerRule) { }
+        ImportedStyleSheetClient(StyleRuleImport* ownerRule) : m_ownerRule(ownerRule) { }
         virtual ~ImportedStyleSheetClient() { }
         virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
         {
             m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet);
         }
     private:
-        CSSImportRule* m_ownerRule;
+        StyleRuleImport* m_ownerRule;
     };
 
     void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
     friend class ImportedStyleSheetClient;
 
-    CSSImportRule(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
+    StyleRuleImport(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaQuerySet>);
+
+    // FXIME: This needs to go away.
+    CSSStyleSheet* m_parentStyleSheet;
 
     ImportedStyleSheetClient m_styleSheetClient;
     String m_strHref;
@@ -81,6 +83,22 @@ private:
     bool m_loading;
 };
 
+class CSSImportRule : public CSSRule {
+public:
+    static PassRefPtr<CSSImportRule> create(StyleRuleImport* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSImportRule(rule, sheet)); }
+
+    String href() const { return m_importRule->href(); }
+    MediaList* media();
+    CSSStyleSheet* styleSheet() const { return m_importRule->styleSheet(); }
+    
+    String cssText() const;
+
+private:
+    CSSImportRule(StyleRuleImport*, CSSStyleSheet*);
+
+    RefPtr<StyleRuleImport> m_importRule;
+};
+
 } // namespace WebCore
 
 #endif // CSSImportRule_h
index 5ed5efc..ec88ade 100644 (file)
 #include "CSSParser.h"
 #include "CSSRuleList.h"
 #include "ExceptionCode.h"
+#include "StyleRule.h"
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
 
-CSSMediaRule::CSSMediaRule(CSSStyleSheet* parent, PassRefPtr<MediaQuerySet> media, Vector<RefPtr<CSSRule> >& adoptRules)
+CSSMediaRule::CSSMediaRule(StyleRuleMedia* mediaRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::MEDIA_RULE)
-    , m_mediaQueries(media)
+    , m_mediaRule(mediaRule)
+    , m_childRuleCSSOMWrappers(mediaRule->childRules().size())
 {
-    m_childRules.swap(adoptRules);
-
-    unsigned size = m_childRules.size();
-    for (unsigned i = 0; i < size; i++)
-        m_childRules[i]->setParentRule(this);
 }
 
 CSSMediaRule::~CSSMediaRule()
 {
-    unsigned size = m_childRules.size();
-    for (unsigned i = 0; i < size; i++)
-        m_childRules[i]->setParentRule(0);
-}
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_mediaRule->childRules().size());
 
-unsigned CSSMediaRule::append(CSSRule* rule)
-{
-    if (!rule)
-        return 0;
-
-    rule->setParentRule(this);
-    m_childRules.append(rule);
-    return m_childRules.size() - 1;
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->setParentRule(0);
+    }
 }
 
-unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionCode& ec)
+unsigned CSSMediaRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec)
 {
-    if (index > m_childRules.size()) {
+    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 p(cssParserMode());
-    RefPtr<CSSRule> newRule = p.parseRule(parentStyleSheet(), rule);
+    RefPtr<StyleRuleBase> newRule = p.parseRule(parentStyleSheet(), ruleString);
     if (!newRule) {
         // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable.
         ec = SYNTAX_ERR;
@@ -85,9 +77,9 @@ unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionC
         ec = HIERARCHY_REQUEST_ERR;
         return 0;
     }
+    m_mediaRule->wrapperInsertRule(index, newRule);
 
-    newRule->setParentRule(this);
-    m_childRules.insert(index, newRule.get());
+    m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
 
     if (CSSStyleSheet* styleSheet = parentStyleSheet())
         styleSheet->styleSheetChanged();
@@ -97,15 +89,19 @@ unsigned CSSMediaRule::insertRule(const String& rule, unsigned index, ExceptionC
 
 void CSSMediaRule::deleteRule(unsigned index, ExceptionCode& ec)
 {
-    if (index >= m_childRules.size()) {
+    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;
     }
+    m_mediaRule->wrapperRemoveRule(index);
 
-    m_childRules[index]->setParentRule(0);
-    m_childRules.remove(index);
+    if (m_childRuleCSSOMWrappers[index])
+        m_childRuleCSSOMWrappers[index]->setParentRule(0);
+    m_childRuleCSSOMWrappers.remove(index);
 
     if (CSSStyleSheet* styleSheet = parentStyleSheet())
         styleSheet->styleSheetChanged();
@@ -115,15 +111,16 @@ String CSSMediaRule::cssText() const
 {
     StringBuilder result;
     result.append("@media ");
-    if (m_mediaQueries) {
-        result.append(m_mediaQueries->mediaText());
+    if (m_mediaRule->mediaQueries()) {
+        result.append(m_mediaRule->mediaQueries()->mediaText());
         result.append(' ');
     }
     result.append("{ \n");
     
-    for (unsigned i = 0; i < m_childRules.size(); ++i) {
+    unsigned size = length();
+    for (unsigned i = 0; i < size; ++i) {
         result.append("  ");
-        result.append(m_childRules[i]->cssText());
+        result.append(item(i)->cssText());
         result.append('\n');
     }
 
@@ -131,10 +128,31 @@ String CSSMediaRule::cssText() const
     return result.toString();
 }
 
-CSSRuleList* CSSMediaRule::cssRules()
+MediaList* CSSMediaRule::media() const 
+{ 
+    return m_mediaRule->mediaQueries() ? m_mediaRule->mediaQueries()->ensureMediaList(parentStyleSheet()) : 0; 
+}
+
+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>(this));
+        m_ruleListCSSOMWrapper = adoptPtr(new LiveCSSRuleList<CSSMediaRule>(const_cast<CSSMediaRule*>(this)));
     return m_ruleListCSSOMWrapper.get();
 }
 
index fa41735..dc2fdbc 100644 (file)
 namespace WebCore {
 
 class CSSRuleList;
+class StyleRuleMedia;
 
 class CSSMediaRule : public CSSRule {
 public:
-    static PassRefPtr<CSSMediaRule> create(CSSStyleSheet* parent, PassRefPtr<MediaQuerySet> media, Vector<RefPtr<CSSRule> >& adoptRules)
-    {
-        return adoptRef(new CSSMediaRule(parent, media, adoptRules));
-    }
+    static PassRefPtr<CSSMediaRule> create(StyleRuleMedia* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSMediaRule(rule, sheet)); }
+
     ~CSSMediaRule();
 
-    MediaList* media() const { return m_mediaQueries ? m_mediaQueries->ensureMediaList(parentStyleSheet()) : 0; }
-    CSSRuleList* cssRules();
+    MediaList* media() const;
+    CSSRuleList* cssRules() const;
 
     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
     void deleteRule(unsigned index, ExceptionCode&);
 
     String cssText() const;
-
-    // Not part of the CSSOM
-    unsigned append(CSSRule*);
-    MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
-
-    unsigned ruleCount() const { return m_childRules.size(); }
-    CSSRule* ruleAt(unsigned index) const { return m_childRules[index].get(); }
-    
+        
     // For CSSRuleList
-    unsigned length() const { return ruleCount(); }
-    CSSRule* item(unsigned index) const { return index < ruleCount() ? ruleAt(index) : 0; }
+    unsigned length() const;
+    CSSRule* item(unsigned index) const;
 
 private:
-    CSSMediaRule(CSSStyleSheet* parent, PassRefPtr<MediaQuerySet>, Vector<RefPtr<CSSRule> >& adoptRules);
+    CSSMediaRule(StyleRuleMedia*, CSSStyleSheet*);
+    
+    RefPtr<StyleRuleMedia> m_mediaRule;
 
-    RefPtr<MediaQuerySet> m_mediaQueries;
-    Vector<RefPtr<CSSRule> > m_childRules;
+    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
+    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
     
-    OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
+    friend class StyleRule;
 };
 
 } // namespace WebCore
index 8e36496..64d499d 100644 (file)
 #include "CSSParser.h"
 #include "CSSSelector.h"
 #include "Document.h"
+#include "PropertySetCSSStyleDeclaration.h"
 #include "StylePropertySet.h"
+#include "StyleRule.h"
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
-CSSPageRule::CSSPageRule(CSSStyleSheet* parent)
+CSSPageRule::CSSPageRule(StyleRulePage* pageRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::PAGE_RULE)
+    , m_pageRule(pageRule)
 {
 }
 
@@ -44,14 +47,14 @@ CSSPageRule::~CSSPageRule()
 CSSStyleDeclaration* CSSPageRule::style() const
 {
     if (!m_propertiesCSSOMWrapper)
-        m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_style.get(), const_cast<CSSPageRule*>(this));
+        m_propertiesCSSOMWrapper = StyleRuleCSSStyleDeclaration::create(m_pageRule->properties(), const_cast<CSSPageRule*>(this));
     return m_propertiesCSSOMWrapper.get();
 }
 
 String CSSPageRule::selectorText() const
 {
     String text = "@page";
-    const CSSSelector* selector = this->selector();
+    const CSSSelector* selector = m_pageRule->selector();
     if (selector) {
         String pageSpecification = selector->selectorText();
         if (!pageSpecification.isEmpty() && pageSpecification != starAtom)
@@ -75,7 +78,7 @@ void CSSPageRule::setSelectorText(const String& selectorText)
         return;
     
     String oldSelectorText = this->selectorText();
-    m_selectorList.adopt(selectorList);
+    m_pageRule->wrapperAdoptSelectorList(selectorList);
     
     if (this->selectorText() == oldSelectorText)
         return;
@@ -86,7 +89,7 @@ String CSSPageRule::cssText() const
 {
     String result = selectorText();
     result += " { ";
-    result += m_style->asText();
+    result += m_pageRule->properties()->asText();
     result += "}";
     return result;
 }
index adf16ec..69a578d 100644 (file)
 #define CSSPageRule_h
 
 #include "CSSRule.h"
-#include "CSSSelectorList.h"
-#include "PropertySetCSSStyleDeclaration.h"
-#include "StylePropertySet.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
-class CSSSelector;
-class CSSSelectorList;
+class CSSStyleDeclaration;
+class CSSStyleSheet;
+class StyleRulePage;
 class StyleRuleCSSStyleDeclaration;
 
 class CSSPageRule : public CSSRule {
 public:
-    static PassRefPtr<CSSPageRule> create(CSSStyleSheet* parent)
-    {
-        return adoptRef(new CSSPageRule(parent));
-    }
+    static PassRefPtr<CSSPageRule> create(StyleRulePage* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSPageRule(rule, sheet)); }
+
     ~CSSPageRule();
 
     CSSStyleDeclaration* style() const;
@@ -50,17 +46,10 @@ public:
 
     String cssText() const;
     
-    const CSSSelector* selector() const { return m_selectorList.first(); }
-    StylePropertySet* properties() const { return m_style.get(); }
-    
-    void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
-    void setDeclaration(PassRefPtr<StylePropertySet> style) { m_style = style; }
-
 private:
-    CSSPageRule(CSSStyleSheet* parent);
-
-    RefPtr<StylePropertySet> m_style;
-    CSSSelectorList m_selectorList;
+    CSSPageRule(StyleRulePage*, CSSStyleSheet*);
+    
+    RefPtr<StyleRulePage> m_pageRule;
 
     mutable RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
index a33dbdf..abc6735 100644 (file)
@@ -277,7 +277,7 @@ void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string, int start
     m_rule = 0;
 }
 
-PassRefPtr<CSSRule> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
+PassRefPtr<StyleRuleBase> CSSParser::parseRule(CSSStyleSheet* sheet, const String& string)
 {
     setStyleSheet(sheet);
     m_allowNamespaceDeclarations = false;
@@ -9012,23 +9012,23 @@ MediaQuerySet* CSSParser::createMediaQuerySet()
     return result;
 }
 
-CSSRule* CSSParser::createImportRule(const CSSParserString& url, MediaQuerySet* media)
+StyleRuleBase* CSSParser::createImportRule(const CSSParserString& url, MediaQuerySet* media)
 {
     if (!media || !m_styleSheet || !m_allowImportRules)
         return 0;
-    RefPtr<CSSImportRule> rule = CSSImportRule::create(m_styleSheet, url, media);
-    CSSImportRule* result = rule.get();
+    RefPtr<StyleRuleImport> rule = StyleRuleImport::create(m_styleSheet, url, media);
+    StyleRuleImport* result = rule.get();
     m_parsedRules.append(rule.release());
     return result;
 }
 
-CSSRule* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules)
+StyleRuleBase* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules)
 {
     if (!media || !rules || !m_styleSheet)
         return 0;
     m_allowImportRules = m_allowNamespaceDeclarations = false;
-    RefPtr<CSSMediaRule> rule = CSSMediaRule::create(m_styleSheet, media, *rules);
-    CSSMediaRule* result = rule.get();
+    RefPtr<StyleRuleMedia> rule = StyleRuleMedia::create(media, *rules);
+    StyleRuleMedia* result = rule.get();
     m_parsedRules.append(rule.release());
     return result;
 }
@@ -9042,26 +9042,26 @@ CSSParser::RuleList* CSSParser::createRuleList()
     return listPtr;
 }
 
-WebKitCSSKeyframesRule* CSSParser::createKeyframesRule()
+StyleRuleKeyframes* CSSParser::createKeyframesRule()
 {
     m_allowImportRules = m_allowNamespaceDeclarations = false;
-    RefPtr<WebKitCSSKeyframesRule> rule = WebKitCSSKeyframesRule::create(m_styleSheet);
-    WebKitCSSKeyframesRule* rulePtr = rule.get();
+    RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create();
+    StyleRuleKeyframes* rulePtr = rule.get();
     m_parsedRules.append(rule.release());
     return rulePtr;
 }
 
-CSSRule* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
+StyleRuleBase* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
 {
-    CSSStyleRule* result = 0;
+    StyleRule* result = 0;
     markRuleBodyEnd();
     if (selectors) {
         m_allowImportRules = m_allowNamespaceDeclarations = false;
-        RefPtr<CSSStyleRule> rule = CSSStyleRule::create(m_styleSheet, m_lastSelectorLineNumber);
-        rule->styleRule()->adoptSelectorVector(*selectors);
+        RefPtr<StyleRule> rule = StyleRule::create(m_lastSelectorLineNumber);
+        rule->parserAdoptSelectorVector(*selectors);
         if (m_hasFontFaceOnlyValues)
             deleteFontFaceOnlyValues();
-        rule->styleRule()->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
+        rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
         result = rule.get();
         m_parsedRules.append(rule.release());
         if (m_ruleRangeMap) {
@@ -9080,7 +9080,7 @@ CSSRule* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selector
     return result;
 }
 
-CSSRule* CSSParser::createFontFaceRule()
+StyleRuleBase* CSSParser::createFontFaceRule()
 {
     m_allowImportRules = m_allowNamespaceDeclarations = false;
     for (unsigned i = 0; i < m_parsedProperties.size(); ++i) {
@@ -9096,10 +9096,10 @@ CSSRule* CSSParser::createFontFaceRule()
             return 0;
         }
     }
-    RefPtr<CSSFontFaceRule> rule = CSSFontFaceRule::create(m_styleSheet);
-    rule->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
+    RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create();
+    rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
     clearProperties();
-    CSSFontFaceRule* result = rule.get();
+    StyleRuleFontFace* result = rule.get();
     m_parsedRules.append(rule.release());
     return result;
 }
@@ -9158,17 +9158,17 @@ CSSParserSelector* CSSParser::updateSpecifiers(CSSParserSelector* specifiers, CS
     return specifiers;
 }
 
-CSSRule* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
+StyleRuleBase* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
 {
     // FIXME: Margin at-rules are ignored.
     m_allowImportRules = m_allowNamespaceDeclarations = false;
-    CSSPageRule* pageRule = 0;
+    StyleRulePage* pageRule = 0;
     if (pageSelector) {
-        RefPtr<CSSPageRule> rule = CSSPageRule::create(m_styleSheet);
+        RefPtr<StyleRulePage> rule = StyleRulePage::create();
         Vector<OwnPtr<CSSParserSelector> > selectorVector;
         selectorVector.append(pageSelector);
-        rule->adoptSelectorVector(selectorVector);
-        rule->setDeclaration(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
+        rule->parserAdoptSelectorVector(selectorVector);
+        rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_cssParserMode));
         pageRule = rule.get();
         m_parsedRules.append(rule.release());
     }
@@ -9182,22 +9182,22 @@ void CSSParser::setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector>
         m_reusableRegionSelectorVector.swap(*selectors);
 }
 
-CSSRule* CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules)
+StyleRuleBase* CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules)
 {
     if (!cssRegionsEnabled() || !regionSelector || !rules)
         return 0;
 
     m_allowImportRules = m_allowNamespaceDeclarations = false;
 
-    RefPtr<WebKitCSSRegionRule> regionRule = WebKitCSSRegionRule::create(m_styleSheet, regionSelector, *rules);
+    RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(regionSelector, *rules);
 
-    WebKitCSSRegionRule* result = regionRule.get();
+    StyleRuleRegion* result = regionRule.get();
     m_parsedRules.append(regionRule.release());
 
     return result;
 }
 
-CSSRule* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
+StyleRuleBase* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
 {
     // FIXME: Implement margin at-rule here, using:
     //        - marginBox: margin box
index 959db92..ad7baa6 100644 (file)
@@ -49,7 +49,6 @@ class CSSBorderImageSliceValue;
 class CSSPrimitiveValue;
 class CSSValuePool;
 class CSSProperty;
-class CSSRule;
 class CSSSelectorList;
 class CSSStyleSheet;
 class CSSValue;
@@ -58,11 +57,13 @@ class CSSWrapShape;
 class Document;
 class MediaQueryExp;
 class MediaQuerySet;
+class StyleKeyframe;
 class StylePropertySet;
 class StylePropertyShorthand;
+class StyleRuleBase;
+class StyleRuleKeyframes;
 class StyleKeyframe;
 class StyledElement;
-class WebKitCSSKeyframesRule;
 
 class CSSParser {
 public:
@@ -71,7 +72,7 @@ public:
     ~CSSParser();
 
     void parseSheet(CSSStyleSheet*, const String&, int startLineNumber = 0, StyleRuleRangeMap* ruleRangeMap = 0);
-    PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&);
+    PassRefPtr<StyleRuleBase> parseRule(CSSStyleSheet*, const String&);
     PassRefPtr<StyleKeyframe> parseKeyframeRule(CSSStyleSheet*, const String&);
     static bool parseValue(StylePropertySet*, int propId, const String&, bool important, CSSParserMode, CSSStyleSheet* contextStyleSheet);
     static bool parseColor(RGBA32& color, const String&, bool strict = false);
@@ -246,18 +247,18 @@ public:
     CSSParserValue& sinkFloatingValue(CSSParserValue&);
 
     MediaQuerySet* createMediaQuerySet();
-    CSSRule* createImportRule(const CSSParserString&, MediaQuerySet*);
+    StyleRuleBase* createImportRule(const CSSParserString&, MediaQuerySet*);
     StyleKeyframe* createKeyframe(CSSParserValueList*);
-    WebKitCSSKeyframesRule* createKeyframesRule();
+    StyleRuleKeyframes* createKeyframesRule();
 
-    typedef Vector<RefPtr<CSSRule> > RuleList;
-    CSSRule* createMediaRule(MediaQuerySet*, RuleList*);
+    typedef Vector<RefPtr<StyleRuleBase> > RuleList;
+    StyleRuleBase* createMediaRule(MediaQuerySet*, RuleList*);
     RuleList* createRuleList();
-    CSSRule* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
-    CSSRule* createFontFaceRule();
-    CSSRule* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
-    CSSRule* createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules);
-    CSSRule* createMarginAtRule(CSSSelector::MarginBoxType marginBox);
+    StyleRuleBase* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
+    StyleRuleBase* createFontFaceRule();
+    StyleRuleBase* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
+    StyleRuleBase* createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules);
+    StyleRuleBase* createMarginAtRule(CSSSelector::MarginBoxType);
     void startDeclarationsForMarginBox();
     void endDeclarationsForMarginBox();
 
@@ -289,7 +290,7 @@ public:
     bool m_important;
     int m_id;
     CSSStyleSheet* m_styleSheet;
-    RefPtr<CSSRule> m_rule;
+    RefPtr<StyleRuleBase> m_rule;
     RefPtr<StyleKeyframe> m_keyframe;
     OwnPtr<MediaQuery> m_mediaQuery;
     OwnPtr<CSSParserValueList> m_valueList;
@@ -403,7 +404,7 @@ private:
     bool m_allowImportRules;
     bool m_allowNamespaceDeclarations;
 
-    Vector<RefPtr<CSSRule> > m_parsedRules;
+    Vector<RefPtr<StyleRuleBase> > m_parsedRules;
     Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes;
     Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets;
     Vector<OwnPtr<RuleList> > m_parsedRuleLists;
index f20af1a..5803f94 100644 (file)
@@ -40,7 +40,7 @@
 
 namespace WebCore {
 
-class CSSStyleRule;
+class StyleRule;
 
 struct SourceRange {
     SourceRange();
@@ -93,7 +93,7 @@ struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> {
     SourceRange selectorListRange;
     RefPtr<CSSStyleSourceData> styleSourceData;
 };
-typedef HashMap<CSSStyleRule*, RefPtr<CSSRuleSourceData> > StyleRuleRangeMap;
+typedef HashMap<StyleRule*, RefPtr<CSSRuleSourceData> > StyleRuleRangeMap;
 
 } // namespace WebCore
 
index cafc7d5..ace76bc 100644 (file)
 
 namespace WebCore {
 
-CSSStyleRule::CSSStyleRule(CSSStyleSheet* parent, int line)
+typedef HashMap<const CSSStyleRule*, String> SelectorTextCache;
+static SelectorTextCache& selectorTextCache()
+{
+    DEFINE_STATIC_LOCAL(SelectorTextCache, cache, ());
+    return cache;
+}
+
+CSSStyleRule::CSSStyleRule(StyleRule* styleRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::STYLE_RULE)
-    , m_styleRule(adoptPtr(new StyleRule(line, this)))
+    , m_styleRule(styleRule)
 {
 }
 
 CSSStyleRule::~CSSStyleRule()
 {
-    cleanup();
     if (m_propertiesCSSOMWrapper)
         m_propertiesCSSOMWrapper->clearParentRule();
+
+    if (hasCachedSelectorText()) {
+        selectorTextCache().remove(this);
+        setHasCachedSelectorText(false);
+    }
 }
 
 CSSStyleDeclaration* CSSStyleRule::style() const
@@ -53,21 +64,6 @@ CSSStyleDeclaration* CSSStyleRule::style() const
     return m_propertiesCSSOMWrapper.get();
 }
 
-typedef HashMap<const CSSStyleRule*, String> SelectorTextCache;
-static SelectorTextCache& selectorTextCache()
-{
-    DEFINE_STATIC_LOCAL(SelectorTextCache, cache, ());
-    return cache;
-}
-
-inline void CSSStyleRule::cleanup()
-{
-    if (hasCachedSelectorText()) {
-        selectorTextCache().remove(this);
-        setHasCachedSelectorText(false);
-    }
-}
-
 String CSSStyleRule::generateSelectorText() const
 {
     StringBuilder builder;
@@ -108,7 +104,7 @@ void CSSStyleRule::setSelectorText(const String& selectorText)
         return;
 
     String oldSelectorText = this->selectorText();
-    m_styleRule->adoptSelectorList(selectorList);
+    m_styleRule->wrapperAdoptSelectorList(selectorList);
 
     if (hasCachedSelectorText()) {
         ASSERT(selectorTextCache().contains(this));
index 18ae9ea..ae03b58 100644 (file)
 
 namespace WebCore {
 
-class CSSSelector;
 class CSSStyleDeclaration;
 class StyleRuleCSSStyleDeclaration;
 class StyleRule;
 
 class CSSStyleRule : public CSSRule {
 public:
-    static PassRefPtr<CSSStyleRule> create(CSSStyleSheet* parent, int line)
-    {
-        return adoptRef(new CSSStyleRule(parent, line));
-    }
+    static PassRefPtr<CSSStyleRule> create(StyleRule* rule, CSSStyleSheet* sheet) { return adoptRef(new CSSStyleRule(rule, sheet)); }
+
     ~CSSStyleRule();
 
     String selectorText() const;
@@ -48,15 +45,15 @@ public:
 
     String cssText() const;
     
+    // FIXME: Not CSSOM. Remove.
     StyleRule* styleRule() const { return m_styleRule.get(); }
 
 private:
-    CSSStyleRule(CSSStyleSheet* parent, int sourceLine);
+    CSSStyleRule(StyleRule*, CSSStyleSheet*);
 
-    void cleanup();
     String generateSelectorText() const;
 
-    OwnPtr<StyleRule> m_styleRule;
+    RefPtr<StyleRule> m_styleRule;    
 
     mutable RefPtr<StyleRuleCSSStyleDeclaration> m_propertiesCSSOMWrapper;
 };
index 8fc6392..22778a2 100644 (file)
@@ -239,9 +239,9 @@ public:
 
     void addStyleRule(StyleRule*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
     void addRule(StyleRule*, CSSSelector*, bool hasDocumentSecurityOrigin, bool canUseFastCheckSelector, bool isInRegionRule = false);
-    void addPageRule(CSSPageRule*);
+    void addPageRule(StyleRulePage*);
     void addToRuleSet(AtomicStringImpl* key, AtomRuleMap&, const RuleData&);
-    void addRegionRule(WebKitCSSRegionRule*, bool hasDocumentSecurityOrigin);
+    void addRegionRule(StyleRuleRegion*, bool hasDocumentSecurityOrigin);
     void shrinkToFit();
     void disableAutoShrinkToFit() { m_autoShrinkToFitEnabled = false; }
 
@@ -254,7 +254,7 @@ public:
     const Vector<RuleData>* linkPseudoClassRules() const { return &m_linkPseudoClassRules; }
     const Vector<RuleData>* focusPseudoClassRules() const { return &m_focusPseudoClassRules; }
     const Vector<RuleData>* universalRules() const { return &m_universalRules; }
-    const Vector<CSSPageRule*>& pageRules() const { return m_pageRules; }
+    const Vector<StyleRulePage*>& pageRules() const { return m_pageRules; }
 
 public:
     RuleSet();
@@ -266,7 +266,7 @@ public:
     Vector<RuleData> m_linkPseudoClassRules;
     Vector<RuleData> m_focusPseudoClassRules;
     Vector<RuleData> m_universalRules;
-    Vector<CSSPageRule*> m_pageRules;
+    Vector<StyleRulePage*> m_pageRules;
     unsigned m_ruleCount;
     bool m_autoShrinkToFitEnabled;
     CSSStyleSelector::Features m_features;
@@ -297,7 +297,8 @@ RenderStyle* CSSStyleSelector::s_styleNotYetAvailable;
 
 static void loadFullDefaultStyle();
 static void loadSimpleDefaultStyle();
-static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >&, CSSStyleSheet*);
+template <class ListType>
+static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >&, ListType*);
 
 // FIXME: It would be nice to use some mechanism that guarantees this is in sync with the real UA stylesheet.
 static const char* simpleUserAgentStyleSheet = "html,body,div{display:block}head{display:none}body{margin:8px}div:focus,span:focus{outline:auto 5px -webkit-focus-ring-color}a:-webkit-any-link{color:-webkit-link;text-decoration:underline}a:-webkit-any-link:active{color:-webkit-activelink}";
@@ -612,7 +613,7 @@ void CSSStyleSelector::popParentShadowRoot(const ShadowRoot* shadowRoot)
 }
 
 // This is a simplified style setting function for keyframe styles
-void CSSStyleSelector::addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule> rule)
+void CSSStyleSelector::addKeyframeStyle(PassRefPtr<StyleRuleKeyframes> rule)
 {
     AtomicString s(rule->name());
     m_keyframesRuleMap.set(s.impl(), rule);
@@ -868,7 +869,7 @@ void CSSStyleSelector::sortAndTransferMatchedRules(MatchResult& result)
         if (!m_ruleList)
             m_ruleList = StaticCSSRuleList::create();
         for (unsigned i = 0; i < m_matchedRules.size(); ++i)
-            m_ruleList->rules().append(m_matchedRules[i]->rule()->ensureCSSStyleRule());
+            m_ruleList->rules().append(m_matchedRules[i]->rule()->createCSSOMWrapper());
         return;
     }
 
@@ -1704,7 +1705,7 @@ void CSSStyleSelector::keyframeStylesForAnimation(Element* e, const RenderStyle*
     if (it == m_keyframesRuleMap.end())
         return;
 
-    const WebKitCSSKeyframesRule* keyframesRule = it->second.get();
+    const StyleRuleKeyframes* keyframesRule = it->second.get();
 
     // Construct and populate the style for each keyframe
     const Vector<RefPtr<StyleKeyframe> >& keyframes = keyframesRule->keyframes();
@@ -2236,7 +2237,7 @@ bool CSSStyleSelector::determineStylesheetSelectorScopes(CSSStyleSheet* styleshe
 {
     ASSERT(!stylesheet->isLoading());
 
-    const Vector<RefPtr<CSSImportRule> >& importRules = stylesheet->importRules();
+    const Vector<RefPtr<StyleRuleImport> >& importRules = stylesheet->importRules();
     for (unsigned i = 0; i < importRules.size(); ++i) {
         if (!importRules[i]->styleSheet())
             continue;
@@ -2244,11 +2245,11 @@ bool CSSStyleSelector::determineStylesheetSelectorScopes(CSSStyleSheet* styleshe
             return false;
     }
 
-    const Vector<RefPtr<CSSRule> >& rules = stylesheet->childRules();
+    const Vector<RefPtr<StyleRuleBase> >& rules = stylesheet->childRules();
     for (unsigned i = 0; i < rules.size(); i++) {
-        CSSRule* rule = rules[i].get();
+        StyleRuleBase* rule = rules[i].get();
         if (rule->isStyleRule()) {
-            StyleRule* styleRule = static_cast<CSSStyleRule*>(rule)->styleRule();
+            StyleRule* styleRule = static_cast<StyleRule*>(rule);
             if (!SelectorChecker::determineSelectorScopes(styleRule->selectorList(), idScopes, classScopes))
                 return false;
             continue;
@@ -2431,12 +2432,12 @@ void RuleSet::addRule(StyleRule* rule, CSSSelector* selector, bool hasDocumentSe
     m_universalRules.append(ruleData);
 }
 
-void RuleSet::addPageRule(CSSPageRule* rule)
+void RuleSet::addPageRule(StyleRulePage* rule)
 {
     m_pageRules.append(rule);
 }
 
-void RuleSet::addRegionRule(WebKitCSSRegionRule* regionRule, bool hasDocumentSecurityOrigin)
+void RuleSet::addRegionRule(StyleRuleRegion* regionRule, bool hasDocumentSecurityOrigin)
 {
     OwnPtr<RuleSet> regionRuleSet = RuleSet::create();
     // The region rule set should take into account the position inside the parent rule set.
@@ -2445,11 +2446,11 @@ void RuleSet::addRegionRule(WebKitCSSRegionRule* regionRule, bool hasDocumentSec
     regionRuleSet->m_ruleCount = m_ruleCount;
 
     // Collect the region rules into a rule set
-    unsigned rulesSize = regionRule->ruleCount();
-    for (unsigned i = 0; i < rulesSize; ++i) {
-        CSSRule* regionStylingRule = regionRule->ruleAt(i);
+    const Vector<RefPtr<StyleRuleBase> >& childRules = regionRule->childRules();
+    for (unsigned i = 0; i < childRules.size(); ++i) {
+        StyleRuleBase* regionStylingRule = childRules[i].get();
         if (regionStylingRule->isStyleRule())
-            regionRuleSet->addStyleRule(static_cast<CSSStyleRule*>(regionStylingRule)->styleRule(), hasDocumentSecurityOrigin, true, true);
+            regionRuleSet->addStyleRule(static_cast<StyleRule*>(regionStylingRule), hasDocumentSecurityOrigin, true, true);
     }
     // Update the "global" rule count so that proper order is maintained
     m_ruleCount = regionRuleSet->m_ruleCount;
@@ -2466,40 +2467,41 @@ void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
     if (sheet->mediaQueries() && !medium.eval(sheet->mediaQueries(), styleSelector))
         return; // the style sheet doesn't apply
     
-    const Vector<RefPtr<CSSImportRule> >& importRules = sheet->importRules();
+    const Vector<RefPtr<StyleRuleImport> >& importRules = sheet->importRules();
     for (unsigned i = 0; i < importRules.size(); ++i) {
-        CSSImportRule* importRule = importRules[i].get();
+        StyleRuleImport* importRule = importRules[i].get();
         if (importRule->styleSheet() && (!importRule->mediaQueries() || medium.eval(importRule->mediaQueries(), styleSelector)))
             addRulesFromSheet(importRule->styleSheet(), medium, styleSelector, scope);
     }
     bool hasDocumentSecurityOrigin = styleSelector && styleSelector->document()->securityOrigin()->canRequest(sheet->baseURL());
 
-    const Vector<RefPtr<CSSRule> >& rules = sheet->childRules();
+    const Vector<RefPtr<StyleRuleBase> >& rules = sheet->childRules();
     for (unsigned i = 0; i < rules.size(); ++i) {
-        CSSRule* rule = rules[i].get();
+        StyleRuleBase* rule = rules[i].get();
 
         ASSERT(!rule->isImportRule());
         if (rule->isStyleRule())
-            addStyleRule(static_cast<CSSStyleRule*>(rule)->styleRule(), hasDocumentSecurityOrigin, !scope);
+            addStyleRule(static_cast<StyleRule*>(rule), hasDocumentSecurityOrigin, !scope);
         else if (rule->isPageRule())
-            addPageRule(static_cast<CSSPageRule*>(rule));
+            addPageRule(static_cast<StyleRulePage*>(rule));
         else if (rule->isMediaRule()) {
-            CSSMediaRule* mediaRule = static_cast<CSSMediaRule*>(rule);
+            StyleRuleMedia* mediaRule = static_cast<StyleRuleMedia*>(rule);
 
-            if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueries(), styleSelector)) && mediaRule->ruleCount()) {
+            if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueries(), styleSelector))) {
                 // Traverse child elements of the @media rule.
-                for (unsigned j = 0; j < mediaRule->ruleCount(); j++) {
-                    CSSRule* childRule = mediaRule->ruleAt(j);
+                const Vector<RefPtr<StyleRuleBase> >& childRules = mediaRule->childRules();
+                for (unsigned j = 0; j < childRules.size(); ++j) {
+                    StyleRuleBase* childRule = childRules[j].get();
                     if (childRule->isStyleRule())
-                        addStyleRule(static_cast<CSSStyleRule*>(childRule)->styleRule(), hasDocumentSecurityOrigin, !scope);
+                        addStyleRule(static_cast<StyleRule*>(childRule), hasDocumentSecurityOrigin, !scope);
                     else if (childRule->isPageRule())
-                        addPageRule(static_cast<CSSPageRule*>(childRule));
+                        addPageRule(static_cast<StyleRulePage*>(childRule));
                     else if (childRule->isFontFaceRule() && styleSelector) {
                         // Add this font face to our set.
                         // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets for the moment.
                         if (scope)
                             continue;
-                        const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(childRule);
+                        const StyleRuleFontFace* fontFaceRule = static_cast<StyleRuleFontFace*>(childRule);
                         styleSelector->fontSelector()->addFontFaceRule(fontFaceRule);
                         styleSelector->invalidateMatchedPropertiesCache();
                     } else if (childRule->isKeyframesRule() && styleSelector) {
@@ -2507,7 +2509,7 @@ void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
                         // FIXME(BUG 72462): We don't add @keyframe rules of scoped style sheets for the moment.
                         if (scope)
                             continue;
-                        styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(childRule));
+                        styleSelector->addKeyframeStyle(static_cast<StyleRuleKeyframes*>(childRule));
                     }
                 }   // for rules
             }   // if rules
@@ -2516,19 +2518,19 @@ void RuleSet::addRulesFromSheet(CSSStyleSheet* sheet, const MediaQueryEvaluator&
             // FIXME(BUG 72461): We don't add @font-face rules of scoped style sheets for the moment.
             if (scope)
                 continue;
-            const CSSFontFaceRule* fontFaceRule = static_cast<CSSFontFaceRule*>(rule);
+            const StyleRuleFontFace* fontFaceRule = static_cast<StyleRuleFontFace*>(rule);
             styleSelector->fontSelector()->addFontFaceRule(fontFaceRule);
             styleSelector->invalidateMatchedPropertiesCache();
         } else if (rule->isKeyframesRule()) {
             // FIXME (BUG 72462): We don't add @keyframe rules of scoped style sheets for the moment.
             if (scope)
                 continue;
-            styleSelector->addKeyframeStyle(static_cast<WebKitCSSKeyframesRule*>(rule));
+            styleSelector->addKeyframeStyle(static_cast<StyleRuleKeyframes*>(rule));
         } else if (rule->isRegionRule() && styleSelector) {
             // FIXME (BUG 72472): We don't add @-webkit-region rules of scoped style sheets for the moment.
             if (scope)
                 continue;
-            addRegionRule(static_cast<WebKitCSSRegionRule*>(rule), hasDocumentSecurityOrigin);
+            addRegionRule(static_cast<StyleRuleRegion*>(rule), hasDocumentSecurityOrigin);
         }
     }
     if (m_autoShrinkToFitEnabled)
@@ -2810,7 +2812,7 @@ void CSSStyleSelector::applyMatchedProperties(const MatchResult& matchResult)
     addToMatchedPropertiesCache(m_style.get(), m_parentStyle, cacheHash, matchResult);
 }
 
-static inline bool comparePageRules(const CSSPageRule* r1, const CSSPageRule* r2)
+static inline bool comparePageRules(const StyleRulePage* r1, const StyleRulePage* r2)
 {
     return r1->selector()->specificity() < r2->selector()->specificity();
 }
@@ -2820,7 +2822,7 @@ void CSSStyleSelector::matchPageRules(MatchResult& result, RuleSet* rules, bool
     if (!rules)
         return;
 
-    Vector<CSSPageRule*> matchedPageRules;
+    Vector<StyleRulePage*> matchedPageRules;
     matchPageRulesForList(matchedPageRules, rules->pageRules(), isLeftPage, isFirstPage, pageName);
     if (matchedPageRules.isEmpty())
         return;
@@ -2831,11 +2833,11 @@ void CSSStyleSelector::matchPageRules(MatchResult& result, RuleSet* rules, bool
         addMatchedProperties(result, matchedPageRules[i]->properties());
 }
 
-void CSSStyleSelector::matchPageRulesForList(Vector<CSSPageRule*>& matchedRules, const Vector<CSSPageRule*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName)
+void CSSStyleSelector::matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName)
 {
     unsigned size = rules.size();
     for (unsigned i = 0; i < size; ++i) {
-        CSSPageRule* rule = rules[i];
+        StyleRulePage* rule = rules[i];
         const AtomicString& selectorLocalName = rule->selector()->tag().localName();
         if (selectorLocalName != starAtom && selectorLocalName != pageName)
             continue;
@@ -2876,17 +2878,20 @@ String CSSStyleSelector::pageName(int /* pageIndex */) const
     return "";
 }
 
-static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, CSSRuleList* ruleList)
+template <class ListType>
+static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, ListType* listType)
 {
-    unsigned size = ruleList->length();
+    if (!listType)
+        return;
+    unsigned size = listType->length();
     for (unsigned i = 0; i < size; ++i) {
-        CSSRule* cssRule = ruleList->item(i);
+        CSSRule* cssRule = listType->item(i);
         if (cssRule->isImportRule())
             collectCSSOMWrappers(wrapperMap, static_cast<CSSImportRule*>(cssRule)->styleSheet());
         else if (cssRule->isMediaRule())
-            collectCSSOMWrappers(wrapperMap, static_cast<CSSMediaRule*>(cssRule)->cssRules());
+            collectCSSOMWrappers(wrapperMap, static_cast<CSSMediaRule*>(cssRule));
         else if (cssRule->isRegionRule())
-            collectCSSOMWrappers(wrapperMap, static_cast<WebKitCSSRegionRule*>(cssRule)->cssRules());
+            collectCSSOMWrappers(wrapperMap, static_cast<WebKitCSSRegionRule*>(cssRule));
         else if (cssRule->isStyleRule()) {
             CSSStyleRule* cssStyleRule = static_cast<CSSStyleRule*>(cssRule);
             wrapperMap.add(cssStyleRule->styleRule(), cssStyleRule);
@@ -2894,13 +2899,6 @@ static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wra
     }
 }
 
-static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, CSSStyleSheet* styleSheet)
-{
-    if (!styleSheet)
-        return;
-    collectCSSOMWrappers(wrapperMap, styleSheet->cssRules().get());
-}
-
 static void collectCSSOMWrappers(HashMap<StyleRule*, RefPtr<CSSStyleRule> >& wrapperMap, Document* document)
 {
     const Vector<RefPtr<StyleSheet> >& styleSheets = document->styleSheets()->vector();
index b78c57f..e4bb541 100644 (file)
@@ -75,13 +75,14 @@ class StyleKeyframe;
 class StylePendingImage;
 class StylePropertySet;
 class StyleRule;
+class StyleRuleKeyframes;
+class StyleRulePage;
+class StyleRuleRegion;
 class StyleShader;
 class StyleSheet;
 class StyleSheetList;
 class StyledElement;
-class WebKitCSSKeyframesRule;
 class WebKitCSSFilterValue;
-class WebKitCSSRegionRule;
 class WebKitCSSShaderValue;
 
 #if ENABLE(CSS_SHADERS)
@@ -229,7 +230,7 @@ public:
     void allVisitedStateChanged() { m_checker.allVisitedStateChanged(); }
     void visitedStateChanged(LinkHash visitedHash) { m_checker.visitedStateChanged(visitedHash); }
 
-    void addKeyframeStyle(PassRefPtr<WebKitCSSKeyframesRule>);
+    void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>);
 
     bool checkRegionStyle(Element* regionElement);
 
@@ -358,7 +359,7 @@ private:
     static bool isValidRegionStyleProperty(int id);
 
     void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName);
-    void matchPageRulesForList(Vector<CSSPageRule*>& matchedRules, const Vector<CSSPageRule*>&, bool isLeftPage, bool isFirstPage, const String& pageName);
+    void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>&, bool isLeftPage, bool isFirstPage, const String& pageName);
     bool isLeftPage(int pageIndex) const;
     bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
     bool isFirstPage(int pageIndex) const;
@@ -376,7 +377,7 @@ private:
     FillLayer m_backgroundData;
     Color m_backgroundColor;
 
-    typedef HashMap<AtomicStringImpl*, RefPtr<WebKitCSSKeyframesRule> > KeyframesRuleMap;
+    typedef HashMap<AtomicStringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRuleMap;
     KeyframesRuleMap m_keyframesRuleMap;
 
 public:
index 3200b15..6ce666b 100644 (file)
@@ -36,6 +36,7 @@
 #include "Node.h"
 #include "SVGNames.h"
 #include "SecurityOrigin.h"
+#include "StylePropertySet.h"
 #include "StyleRule.h"
 #include "TextEncoding.h"
 #include <wtf/Deque.h>
@@ -75,6 +76,7 @@ static bool isAcceptableCSSStyleSheetParent(Node* parentNode)
 
 CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& baseURL, const String& charset)
     : StyleSheet(parentNode, href, baseURL)
+    , m_ownerRule(0)
     , m_charset(charset)
     , m_loadCompleted(false)
     , m_cssParserMode(CSSQuirksMode)
@@ -85,11 +87,12 @@ CSSStyleSheet::CSSStyleSheet(Node* parentNode, const String& href, const KURL& b
     ASSERT(isAcceptableCSSStyleSheetParent(parentNode));
 }
 
-CSSStyleSheet::CSSStyleSheet(CSSImportRule* ownerRule, const String& href, const KURL& baseURL, const String& charset)
-    : StyleSheet(ownerRule, href, baseURL)
+CSSStyleSheet::CSSStyleSheet(StyleRuleImport* ownerRule, const String& href, const KURL& baseURL, const String& charset)
+    : StyleSheet(href, baseURL)
+    , m_ownerRule(ownerRule)
     , m_charset(charset)
     , m_loadCompleted(false)
-    , m_cssParserMode(ownerRule ? ownerRule->cssParserMode() : CSSStrictMode)
+    , m_cssParserMode((ownerRule && ownerRule->parentStyleSheet()) ? ownerRule->parentStyleSheet()->cssParserMode() : CSSStrictMode)
     , m_hasSyntacticallyValidCSSHeader(true)
     , m_didLoadErrorOccur(false)
 {
@@ -102,25 +105,34 @@ CSSStyleSheet::~CSSStyleSheet()
     clearRules();
 }
 
-void CSSStyleSheet::parserAppendRule(PassRefPtr<CSSRule> rule)
+void CSSStyleSheet::parserAppendRule(PassRefPtr<StyleRuleBase> rule)
 {
     ASSERT(!rule->isCharsetRule());
     if (rule->isImportRule()) {
         // Parser enforces that @import rules come before anything else except @charset.
         ASSERT(m_childRules.isEmpty());
-        m_importRules.append(static_cast<CSSImportRule*>(rule.get()));
+        m_importRules.append(static_cast<StyleRuleImport*>(rule.get()));
         m_importRules.last()->requestStyleSheet();
         return;
     }
     m_childRules.append(rule);
 }
 
-CSSCharsetRule* CSSStyleSheet::ensureCharsetRule()
+PassRefPtr<CSSRule> CSSStyleSheet::createChildRuleCSSOMWrapper(unsigned index)
 {
-    // Note that mutating charset has absolutely no effect.
-    if (!m_charsetRuleCSSOMWrapper)
-        m_charsetRuleCSSOMWrapper = CSSCharsetRule::create(this, m_encodingFromCharsetRule);
-    return m_charsetRuleCSSOMWrapper.get();
+    ASSERT(index < length());
+    
+    unsigned childVectorIndex = index;
+    if (hasCharsetRule()) {
+        if (index == 0)
+            return CSSCharsetRule::create(this, m_encodingFromCharsetRule);
+        --childVectorIndex;
+    }
+    if (childVectorIndex < m_importRules.size())
+        return m_importRules[childVectorIndex]->createCSSOMWrapper(this);
+    
+    childVectorIndex -= m_importRules.size();
+    return m_childRules[childVectorIndex]->createCSSOMWrapper(this);
 }
 
 unsigned CSSStyleSheet::length() const
@@ -134,27 +146,23 @@ unsigned CSSStyleSheet::length() const
 
 CSSRule* CSSStyleSheet::item(unsigned index)
 {
-    unsigned childVectorIndex = index;
-    if (hasCharsetRule()) {
-        if (index == 0)
-            return ensureCharsetRule();
-        --childVectorIndex;
-    }
-    if (childVectorIndex < m_importRules.size())
-        return m_importRules[childVectorIndex].get();
-
-    childVectorIndex -= m_importRules.size();
+    unsigned ruleCount = length();
+    if (index >= ruleCount)
+        return 0;
+    
+    if (m_childRuleCSSOMWrappers.isEmpty())
+        m_childRuleCSSOMWrappers.grow(ruleCount);
+    ASSERT(m_childRuleCSSOMWrappers.size() == ruleCount);
 
-    return childVectorIndex < m_childRules.size() ? m_childRules[childVectorIndex].get() : 0; 
+    RefPtr<CSSRule>& cssRule = m_childRuleCSSOMWrappers[index];
+    if (!cssRule)
+        cssRule = createChildRuleCSSOMWrapper(index);
+    return cssRule.get();
 }
 
 void CSSStyleSheet::clearCharsetRule()
 {
     m_encodingFromCharsetRule = String();
-    if (m_charsetRuleCSSOMWrapper) {
-        m_charsetRuleCSSOMWrapper->setParentStyleSheet(0);
-        m_charsetRuleCSSOMWrapper.clear();
-    }
 }
 
 void CSSStyleSheet::clearRules()
@@ -162,18 +170,18 @@ void CSSStyleSheet::clearRules()
     // For style rules outside the document, .parentStyleSheet can become null even if the style rule
     // is still observable from JavaScript. This matches the behavior of .parentNode for nodes, but
     // it's not ideal because it makes the CSSOM's behavior depend on the timing of garbage collection.
-    for (unsigned i = 0; i < m_childRules.size(); ++i) {
-        ASSERT(m_childRules[i]->parentStyleSheet() == this);
-        m_childRules[i]->setParentStyleSheet(0);
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->setParentStyleSheet(0);
     }
-    m_childRules.clear();
+    m_childRuleCSSOMWrappers.clear();
 
     for (unsigned i = 0; i < m_importRules.size(); ++i) {
         ASSERT(m_importRules.at(i)->parentStyleSheet() == this);
-        m_importRules[i]->setParentStyleSheet(0);
+        m_importRules[i]->clearParentStyleSheet();
     }
     m_importRules.clear();
-
+    m_childRules.clear();
     clearCharsetRule();
 }
 
@@ -192,8 +200,13 @@ PassRefPtr<CSSRuleList> CSSStyleSheet::rules()
         return 0;
     // IE behavior.
     RefPtr<StaticCSSRuleList> nonCharsetRules = StaticCSSRuleList::create();
-    nonCharsetRules->rules().append(m_importRules.data(), m_importRules.size());
-    nonCharsetRules->rules().append(m_childRules.data(), m_childRules.size());
+    unsigned ruleCount = length();
+    for (unsigned i = 0; i < ruleCount; ++i) {
+        CSSRule* rule = item(i);
+        if (rule->isCharsetRule())
+            continue;
+        nonCharsetRules->rules().append(rule);
+    }
     return nonCharsetRules.release();
 }
 
@@ -205,7 +218,7 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
         return 0;
     }
     CSSParser p(cssParserMode());
-    RefPtr<CSSRule> rule = p.parseRule(this, ruleString);
+    RefPtr<StyleRuleBase> rule = p.parseRule(this, ruleString);
 
     if (!rule) {
         ec = SYNTAX_ERR;
@@ -217,7 +230,7 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
     unsigned childVectorIndex = index;
     // m_childRules does not contain @charset which is always in index 0 if it exists.
     if (hasCharsetRule()) {
-        if (index == 0) {
+        if (childVectorIndex == 0) {
             // Nothing can be inserted before @charset.
             ec = HIERARCHY_REQUEST_ERR;
             return 0;
@@ -231,12 +244,9 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
             ec = HIERARCHY_REQUEST_ERR;
             return 0;
         }
-        m_importRules.insert(childVectorIndex, static_cast<CSSImportRule*>(rule.get()));
+        m_importRules.insert(childVectorIndex, static_cast<StyleRuleImport*>(rule.get()));
         m_importRules[childVectorIndex]->requestStyleSheet();
-
-        // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
-        styleSheetChanged();
-        return index;
+        goto success;
     }
     // Inserting @import rule after a non-import rule is not allowed.
     if (rule->isImportRule()) {
@@ -246,7 +256,12 @@ unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, Exc
     childVectorIndex -= m_importRules.size();
  
     m_childRules.insert(childVectorIndex, rule.release());
+    
+success:
+    if (!m_childRuleCSSOMWrappers.isEmpty())
+        m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>());
 
+    // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded.
     styleSheetChanged();
     return index;
 }
@@ -285,23 +300,27 @@ void CSSStyleSheet::deleteRule(unsigned index, ExceptionCode& ec)
     ec = 0;
     unsigned childVectorIndex = index;
     if (hasCharsetRule()) {
-        if (index == 0) {
+        if (childVectorIndex == 0) {
             clearCharsetRule();
-            styleSheetChanged();
-            return;
+            goto success;
         }
         --childVectorIndex;
     }
     if (childVectorIndex < m_importRules.size()) {
-        m_importRules[childVectorIndex]->setParentStyleSheet(0);
+        m_importRules[childVectorIndex]->clearParentStyleSheet();
         m_importRules.remove(childVectorIndex);
-        styleSheetChanged();
-        return;
+        goto success;
     }
     childVectorIndex -= m_importRules.size();
 
-    m_childRules[childVectorIndex]->setParentStyleSheet(0);
     m_childRules.remove(childVectorIndex);
+
+success:
+    if (!m_childRuleCSSOMWrappers.isEmpty()) {
+        m_childRuleCSSOMWrappers[index]->setParentStyleSheet(0);
+        m_childRuleCSSOMWrappers.remove(index);
+    }
+
     styleSheetChanged();
 }
 
@@ -451,20 +470,41 @@ void CSSStyleSheet::addSubresourceStyleURLs(ListHashSet<KURL>& urls)
         CSSStyleSheet* styleSheet = styleSheetQueue.takeFirst();
         
         for (unsigned i = 0; i < styleSheet->m_importRules.size(); ++i) {
-            CSSImportRule* importRule = styleSheet->m_importRules[i].get();
-            if (importRule->styleSheet())
+            StyleRuleImport* importRule = styleSheet->m_importRules[i].get();
+            if (importRule->styleSheet()) {
                 styleSheetQueue.append(importRule->styleSheet());
-            importRule->addSubresourceStyleURLs(urls);
+                addSubresourceURL(urls, importRule->styleSheet()->baseURL());
+            }
         }
-
         for (unsigned i = 0; i < styleSheet->m_childRules.size(); ++i) {
-            CSSRule* rule = styleSheet->m_childRules[i].get();
-            if (rule->isFontFaceRule())
-                static_cast<CSSFontFaceRule*>(rule)->addSubresourceStyleURLs(urls);
-            else if (rule->isStyleRule())
-                static_cast<CSSStyleRule*>(rule)->styleRule()->addSubresourceStyleURLs(urls, this);
+            StyleRuleBase* rule = styleSheet->m_childRules[i].get();
+            if (rule->isStyleRule())
+                static_cast<StyleRule*>(rule)->properties()->addSubresourceStyleURLs(urls, this);
+            else if (rule->isFontFaceRule())
+                static_cast<StyleRuleFontFace*>(rule)->properties()->addSubresourceStyleURLs(urls, this);
         }
     }
 }
 
+CSSImportRule* CSSStyleSheet::ensureCSSOMWrapper(StyleRuleImport* importRule)
+{
+     for (unsigned i = 0; i < m_importRules.size(); ++i) {
+         if (m_importRules[i] == importRule)
+             return static_cast<CSSImportRule*>(item(i));
+     }
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+CSSImportRule* CSSStyleSheet::ownerRule() const 
+{  
+    return parentStyleSheet() ? parentStyleSheet()->ensureCSSOMWrapper(m_ownerRule) : 0; 
+}
+
+CSSStyleSheet* CSSStyleSheet::parentStyleSheet() const
+{
+    ASSERT(isCSSStyleSheet());
+    return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
+}
+
 }
index 6445bff..097af35 100644 (file)
 
 namespace WebCore {
 
-struct CSSNamespace;
-class CSSParser;
 class CSSCharsetRule;
 class CSSImportRule;
+class CSSParser;
 class CSSRule;
 class CSSRuleList;
 class CachedCSSStyleSheet;
 class CachedResourceLoader;
 class Document;
 class MediaQuerySet;
+class StyleRuleBase;
+class StyleRuleImport;
+struct CSSNamespace;
 
 typedef int ExceptionCode;
 
@@ -43,7 +45,7 @@ class CSSStyleSheet : public StyleSheet {
 public:
     static PassRefPtr<CSSStyleSheet> create()
     {
-        return adoptRef(new CSSStyleSheet(static_cast<CSSImportRule*>(0), String(), KURL(), String()));
+        return adoptRef(new CSSStyleSheet(static_cast<StyleRuleImport*>(0), String(), KURL(), String()));
     }
     static PassRefPtr<CSSStyleSheet> create(Node* ownerNode)
     {
@@ -53,7 +55,7 @@ public:
     {
         return adoptRef(new CSSStyleSheet(ownerNode, originalURL, finalURL, charset));
     }
-    static PassRefPtr<CSSStyleSheet> create(CSSImportRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
+    static PassRefPtr<CSSStyleSheet> create(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset)
     {
         return adoptRef(new CSSStyleSheet(ownerRule, originalURL, finalURL, charset));
     }
@@ -64,12 +66,7 @@ public:
 
     virtual ~CSSStyleSheet();
 
-    CSSStyleSheet* parentStyleSheet() const
-    {
-        StyleSheet* parentSheet = StyleSheet::parentStyleSheet();
-        ASSERT(!parentSheet || parentSheet->isCSSStyleSheet());
-        return static_cast<CSSStyleSheet*>(parentSheet);
-    }
+    virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
 
     PassRefPtr<CSSRuleList> cssRules();
     unsigned insertRule(const String& rule, unsigned index, ExceptionCode&);
@@ -113,7 +110,7 @@ public:
     void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
     bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
 
-    void parserAppendRule(PassRefPtr<CSSRule>);
+    void parserAppendRule(PassRefPtr<StyleRuleBase>);
     void parserSetEncodingFromCharsetRule(const String& encoding); 
 
     void clearRules();
@@ -122,8 +119,8 @@ public:
     CSSRule* item(unsigned index);
 
     // Rules other than @charset and @import.
-    const Vector<RefPtr<CSSRule> >& childRules() const { return m_childRules; }
-    const Vector<RefPtr<CSSImportRule> >& importRules() const { return m_importRules; }
+    const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
+    const Vector<RefPtr<StyleRuleImport> >& importRules() const { return m_importRules; }
 
     virtual MediaList* media() const OVERRIDE;
 
@@ -131,22 +128,28 @@ public:
     void setMediaQueries(PassRefPtr<MediaQuerySet>);
 
     void notifyLoadedSheet(const CachedCSSStyleSheet*);
+    
+    virtual CSSImportRule* ownerRule() const OVERRIDE;
+    void clearOwnerRule() { m_ownerRule = 0; }
+    
+    CSSImportRule* ensureCSSOMWrapper(StyleRuleImport*);
 
 private:
     CSSStyleSheet(Node* ownerNode, const String& originalURL, const KURL& finalURL, const String& charset);
-    CSSStyleSheet(CSSImportRule* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
+    CSSStyleSheet(StyleRuleImport* ownerRule, const String& originalURL, const KURL& finalURL, const String& charset);
 
     virtual bool isCSSStyleSheet() const { return true; }
     virtual String type() const { return "text/css"; }
     
     void clearCharsetRule();
-    bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull() || m_charsetRuleCSSOMWrapper; }
-    CSSCharsetRule* ensureCharsetRule();
+    bool hasCharsetRule() const { return !m_encodingFromCharsetRule.isNull(); }
+
+    PassRefPtr<CSSRule> createChildRuleCSSOMWrapper(unsigned index);
 
+    StyleRuleImport* m_ownerRule;
     String m_encodingFromCharsetRule;
-    RefPtr<CSSCharsetRule> m_charsetRuleCSSOMWrapper;
-    Vector<RefPtr<CSSImportRule> > m_importRules;
-    Vector<RefPtr<CSSRule> > m_childRules;
+    Vector<RefPtr<StyleRuleImport> > m_importRules;
+    Vector<RefPtr<StyleRuleBase> > m_childRules;
     OwnPtr<CSSNamespace> m_namespaces;
     String m_charset;
     RefPtr<MediaQuerySet> m_mediaQueries;
@@ -156,8 +159,9 @@ private:
     bool m_isUserStyleSheet : 1;
     bool m_hasSyntacticallyValidCSSHeader : 1;
     bool m_didLoadErrorOccur : 1;
-    
-    OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
+
+    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
+    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
 
 } // namespace
index fc0f9d6..0766120 100644 (file)
 #include "config.h"
 #include "StyleRule.h"
 
+#include "CSSCharsetRule.h"
+#include "CSSFontFaceRule.h"
+#include "CSSImportRule.h"
+#include "CSSMediaRule.h"
+#include "CSSPageRule.h"
+#include "CSSStyleRule.h"
+#include "WebKitCSSKeyframeRule.h"
+#include "WebKitCSSKeyframesRule.h"
+#include "WebKitCSSRegionRule.h"
+
 namespace WebCore {
 
-StyleRule::StyleRule(int line, CSSStyleRule* wrapper)
-    : m_sourceLine(line)
-    , m_cssomWrapper(wrapper)
+PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const
 {
+    return createCSSOMWrapper(parentSheet, 0);
 }
-    
+
+PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const
+{ 
+    return createCSSOMWrapper(0, parentRule);
+}
+
+void StyleRuleBase::destroy()
+{
+    switch (type()) {
+    case Style:
+        delete static_cast<StyleRule*>(this);
+        return;
+    case Page:
+        delete static_cast<StyleRulePage*>(this);
+        return;
+    case FontFace:
+        delete static_cast<StyleRuleFontFace*>(this);
+        return;
+    case Media:
+        delete static_cast<StyleRuleMedia*>(this);
+        return;
+    case Region:
+        delete static_cast<StyleRuleRegion*>(this);
+        return;
+    case Import:
+        delete static_cast<StyleRuleImport*>(this);
+        return;
+    case Keyframes:
+        delete static_cast<StyleRuleKeyframes*>(this);
+        return;
+    case Unknown:
+    case Charset:
+    case Keyframe:
+        ASSERT_NOT_REACHED();
+        return;
+    }
+    ASSERT_NOT_REACHED();
+}
+
+PassRefPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const
+{
+    RefPtr<CSSRule> rule;
+    StyleRuleBase* self = const_cast<StyleRuleBase*>(this);
+    switch (type()) {
+    case Style:
+        rule = CSSStyleRule::create(static_cast<StyleRule*>(self), parentSheet);
+        break;
+    case Page:
+        rule = CSSPageRule::create(static_cast<StyleRulePage*>(self), parentSheet);
+        break;
+    case FontFace:
+        rule = CSSFontFaceRule::create(static_cast<StyleRuleFontFace*>(self), parentSheet);
+        break;
+    case Media:
+        rule = CSSMediaRule::create(static_cast<StyleRuleMedia*>(self), parentSheet);
+        break;
+    case Region:
+        rule = WebKitCSSRegionRule::create(static_cast<StyleRuleRegion*>(self), parentSheet);
+        break;
+    case Import:
+        rule = CSSImportRule::create(static_cast<StyleRuleImport*>(self), parentSheet);
+        break;
+    case Keyframes:
+        rule = WebKitCSSKeyframesRule::create(static_cast<StyleRuleKeyframes*>(self), parentSheet);
+        break;
+    case Unknown:
+    case Charset:
+    case Keyframe:
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+    if (parentRule)
+        rule->setParentRule(parentRule);
+    return rule.release();
+}
+
+StyleRule::StyleRule(int sourceLine)
+    : StyleRuleBase(Style, sourceLine)
+{
+}
+
 StyleRule::~StyleRule()
 {
 }
-    
-void StyleRule::addSubresourceStyleURLs(ListHashSet<KURL>& urls, CSSStyleSheet* styleSheet) 
+
+void StyleRule::setProperties(PassRefPtr<StylePropertySet> properties)
+{ 
+    m_properties = properties;
+}
+
+StyleRulePage::StyleRulePage()
+    : StyleRuleBase(Page)
 {
-    if (!m_properties)
-        return;
-    m_properties->addSubresourceStyleURLs(urls, styleSheet);
+}
+
+StyleRulePage::~StyleRulePage()
+{
+}
+
+void StyleRulePage::setProperties(PassRefPtr<StylePropertySet> properties)
+{ 
+    m_properties = properties;
+}
+
+StyleRuleFontFace::StyleRuleFontFace()
+    : StyleRuleBase(FontFace, 0)
+{
+}
+
+StyleRuleFontFace::~StyleRuleFontFace()
+{
+}
+
+void StyleRuleFontFace::setProperties(PassRefPtr<StylePropertySet> properties)
+{ 
+    m_properties = properties;
+}
+
+StyleRuleBlock::StyleRuleBlock(Type type, Vector<RefPtr<StyleRuleBase> >& adoptRule)
+    : StyleRuleBase(type, 0)
+{
+    m_childRules.swap(adoptRule);
+}
+
+void StyleRuleBlock::wrapperInsertRule(unsigned index, PassRefPtr<StyleRuleBase> rule)
+{
+    m_childRules.insert(index, rule);
 }
     
-CSSStyleRule* StyleRule::ensureCSSStyleRule() const
+void StyleRuleBlock::wrapperRemoveRule(unsigned index)
+{
+    m_childRules.remove(index);
+}
+
+StyleRuleMedia::StyleRuleMedia(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase> >& adoptRules)
+    : StyleRuleBlock(Media, adoptRules)
+    , m_mediaQueries(media)
+{
+}
+
+StyleRuleRegion::StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<StyleRuleBase> >& adoptRules)
+    : StyleRuleBlock(Region, adoptRules)
 {
-    ASSERT(m_cssomWrapper);
-    return m_cssomWrapper;
+    m_selectorList.adoptSelectorVector(*selectors);
 }
 
 } // namespace WebCore
index e230a94..c7d4248 100644 (file)
 #define StyleRule_h
 
 #include "CSSSelectorList.h"
-#include "StylePropertySet.h"
-#include <wtf/PassRefPtr.h>
+#include "MediaList.h"
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
+class CSSRule;
 class CSSStyleRule;
+class CSSStyleSheet;
+class StylePropertySet;
 
-class StyleRule {
-    WTF_MAKE_NONCOPYABLE(StyleRule); WTF_MAKE_FAST_ALLOCATED;
+class StyleRuleBase : public WTF::RefCountedBase {
 public:
-    StyleRule(int sourceLine, CSSStyleRule*);
+    enum Type {
+        Unknown, // Not used.
+        Style,
+        Charset, // Not used. These are internally strings owned by the style sheet.
+        Import,
+        Media,
+        FontFace,
+        Page,
+        Keyframes,
+        Keyframe, // Not used. These are internally non-rule StyleKeyframe objects.
+        Region
+    };
+    Type type() const { return static_cast<Type>(m_type); }
+    
+    bool isCharsetRule() const { return type() == Charset; }
+    bool isFontFaceRule() const { return type() == FontFace; }
+    bool isKeyframesRule() const { return type() == Keyframes; }
+    bool isMediaRule() const { return type() == Media; }
+    bool isPageRule() const { return type() == Page; }
+    bool isStyleRule() const { return type() == Style; }
+    bool isRegionRule() const { return type() == Region; }
+    bool isImportRule() const { return type() == Import; }
+    
+    int sourceLine() const { return m_sourceLine; }
+
+    void deref()
+    {
+        if (derefBase())
+            destroy();
+    }
+
+    // FIXME: There shouldn't be any need for the null parent version.
+    PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = 0) const;
+    PassRefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
+
+protected:
+    StyleRuleBase(Type type, signed sourceLine = 0) : m_type(type), m_sourceLine(sourceLine) { }
+    ~StyleRuleBase() { }
+
+private:
+    void destroy();
+    
+    PassRefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
+
+    unsigned m_type : 4;
+    signed m_sourceLine : 28;
+};
+
+class StyleRule : public StyleRuleBase {
+public:
+    static PassRefPtr<StyleRule> create(int sourceLine) { return adoptRef(new StyleRule(sourceLine)); }
+    
     ~StyleRule();
-            
+
     const CSSSelectorList& selectorList() const { return m_selectorList; }
     StylePropertySet* properties() const { return m_properties.get(); }
     
-    void addSubresourceStyleURLs(ListHashSet<KURL>& urls, CSSStyleSheet*);
+    void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
+    void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
+    void setProperties(PassRefPtr<StylePropertySet>);
 
-    int sourceLine() const { return m_sourceLine; }
-    
-    CSSStyleRule* ensureCSSStyleRule() const;
-    
-    void adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
-    void adoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
-    void setProperties(PassRefPtr<StylePropertySet> properties) { m_properties = properties; }
+private:
+    StyleRule(int sourceLine);
+
+    RefPtr<StylePropertySet> m_properties;
+    CSSSelectorList m_selectorList;
+};
+
+class StyleRuleFontFace : public StyleRuleBase {
+public:
+    static PassRefPtr<StyleRuleFontFace> create() { return adoptRef(new StyleRuleFontFace); }
     
+    ~StyleRuleFontFace();
+
+    StylePropertySet* properties() const { return m_properties.get(); }
+
+    void setProperties(PassRefPtr<StylePropertySet>);
+
 private:
+    StyleRuleFontFace();
+
+    RefPtr<StylePropertySet> m_properties;
+};
+
+class StyleRulePage : public StyleRuleBase {
+public:
+    static PassRefPtr<StyleRulePage> create() { return adoptRef(new StyleRulePage); }
+
+    ~StyleRulePage();
+
+    const CSSSelector* selector() const { return m_selectorList.first(); }    
+    StylePropertySet* properties() const { return m_properties.get(); }
+
+    void parserAdoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectors) { m_selectorList.adoptSelectorVector(selectors); }
+    void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList.adopt(selectors); }
+    void setProperties(PassRefPtr<StylePropertySet>);
+
+private:
+    StyleRulePage();
+    
     RefPtr<StylePropertySet> m_properties;
     CSSSelectorList m_selectorList;
-    signed m_sourceLine;
+};
 
-    CSSStyleRule* m_cssomWrapper;
+class StyleRuleBlock : public StyleRuleBase {
+public:
+    const Vector<RefPtr<StyleRuleBase> >& childRules() const { return m_childRules; }
+    
+    void wrapperInsertRule(unsigned, PassRefPtr<StyleRuleBase>);
+    void wrapperRemoveRule(unsigned);
+    
+protected:
+    StyleRuleBlock(Type, Vector<RefPtr<StyleRuleBase> >& adoptRule);
+    
+private:
+    Vector<RefPtr<StyleRuleBase> > m_childRules;
+};
+
+class StyleRuleMedia : public StyleRuleBlock {
+public:
+    static PassRefPtr<StyleRuleMedia> create(PassRefPtr<MediaQuerySet> media, Vector<RefPtr<StyleRuleBase> >& adoptRules)
+    {
+        return adoptRef(new StyleRuleMedia(media, adoptRules));
+    }
+
+    const MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
+
+private:
+    StyleRuleMedia(PassRefPtr<MediaQuerySet>, Vector<RefPtr<StyleRuleBase> >& adoptRules);
+
+    RefPtr<MediaQuerySet> m_mediaQueries;
+};
+
+class StyleRuleRegion : public StyleRuleBlock {
+public:
+    static PassRefPtr<StyleRuleRegion> create(Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<StyleRuleBase> >& adoptRules)
+    {
+        return adoptRef(new StyleRuleRegion(selectors, adoptRules));
+    }
+
+    const CSSSelectorList& selectorList() const { return m_selectorList; }
+
+private:
+    StyleRuleRegion(Vector<OwnPtr<CSSParserSelector> >*, Vector<RefPtr<StyleRuleBase> >& adoptRules);
+    
+    CSSSelectorList m_selectorList;
 };
 
 } // namespace WebCore
index 202ba35..6b65413 100644 (file)
@@ -29,16 +29,14 @@ namespace WebCore {
 
 StyleSheet::StyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL)
     : m_disabled(false)
-    , m_ownerRule(0)
     , m_ownerNode(parentNode)
     , m_originalURL(originalURL)
     , m_finalURL(finalURL)
 {
 }
 
-StyleSheet::StyleSheet(CSSImportRule* parentRule, const String& originalURL, const KURL& finalURL)
+StyleSheet::StyleSheet(const String& originalURL, const KURL& finalURL)
     : m_disabled(false)
-    , m_ownerRule(parentRule)
     , m_ownerNode(0)
     , m_originalURL(originalURL)
     , m_finalURL(finalURL)
@@ -49,12 +47,6 @@ StyleSheet::~StyleSheet()
 {
 }
 
-StyleSheet* StyleSheet::parentStyleSheet() const
-{
-    ASSERT(isCSSStyleSheet());
-    return m_ownerRule ? m_ownerRule->parentStyleSheet() : 0;
-}
-
 KURL StyleSheet::baseURL() const
 {
     if (!m_finalURL.isNull())
index 5eb5fc4..e715c38 100644 (file)
@@ -32,6 +32,8 @@ namespace WebCore {
 class CSSImportRule;
 class MediaList;
 class Node;
+class StyleRuleImport;
+class StyleSheet;
 
 class StyleSheet : public RefCounted<StyleSheet> {
 public:
@@ -43,10 +45,9 @@ public:
     Node* ownerNode() const { return m_ownerNode; }
     void clearOwnerNode() { m_ownerNode = 0; }
 
-    CSSImportRule* ownerRule() const { return m_ownerRule; }
-    void clearOwnerRule() { m_ownerRule = 0; }
+    virtual CSSImportRule* ownerRule() const { return 0; }
 
-    StyleSheet* parentStyleSheet() const;
+    virtual StyleSheet* parentStyleSheet() const { return 0; }
 
     // Note that href is the URL that started the redirect chain that led to
     // this style sheet. This property probably isn't useful for much except
@@ -72,11 +73,10 @@ public:
 
 protected:
     StyleSheet(Node* ownerNode, const String& href, const KURL& finalURL);
-    StyleSheet(CSSImportRule* parentRule, const String& href, const KURL& finalURL);
+    StyleSheet(const String& href, const KURL& finalURL);
 
 private:
     bool m_disabled;
-    CSSImportRule* m_ownerRule;
     Node* m_ownerNode;
     String m_originalURL;
     KURL m_finalURL;
index fa73f81..ad766f7 100644 (file)
 
 namespace WebCore {
 
-WebKitCSSKeyframesRule::WebKitCSSKeyframesRule(CSSStyleSheet* parent)
+StyleRuleKeyframes::StyleRuleKeyframes()
+    : StyleRuleBase(Keyframes, 0)
+{
+}
+    
+StyleRuleKeyframes::~StyleRuleKeyframes()
+{
+}
+
+void StyleRuleKeyframes::parserAppendKeyframe(PassRefPtr<StyleKeyframe> keyframe)
+{
+    if (!keyframe)
+        return;
+    m_keyframes.append(keyframe);
+}
+
+void StyleRuleKeyframes::wrapperAppendKeyframe(PassRefPtr<StyleKeyframe> keyframe)
+{
+    m_keyframes.append(keyframe);
+}
+
+void StyleRuleKeyframes::wrapperRemoveKeyframe(unsigned index)
+{
+    m_keyframes.remove(index);
+}
+
+int StyleRuleKeyframes::findKeyframeIndex(const String& key) const
+{
+    String percentageString;
+    if (equalIgnoringCase(key, "from"))
+        percentageString = "0%";
+    else if (equalIgnoringCase(key, "to"))
+        percentageString = "100%";
+    else
+        percentageString = key;
+    
+    for (unsigned i = 0; i < m_keyframes.size(); ++i) {
+        if (m_keyframes[i]->keyText() == percentageString)
+            return i;
+    }
+    return -1;
+}
+
+WebKitCSSKeyframesRule::WebKitCSSKeyframesRule(StyleRuleKeyframes* keyframesRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::WEBKIT_KEYFRAMES_RULE)
+    , m_keyframesRule(keyframesRule)
+    , m_childRuleCSSOMWrappers(keyframesRule->keyframes().size())
 {
 }
 
 WebKitCSSKeyframesRule::~WebKitCSSKeyframesRule()
 {
-    if (m_childRuleCSSOMWrappers) {
-        ASSERT(m_childRuleCSSOMWrappers->size() == m_keyframes.size());
-        for (unsigned i = 0; i < m_childRuleCSSOMWrappers->size(); ++i) {
-            if (m_childRuleCSSOMWrappers->at(i))
-                m_childRuleCSSOMWrappers->at(i)->setParentRule(0);
-        }
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size());
+
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->setParentRule(0);
     }
 }
 
 void WebKitCSSKeyframesRule::setName(const String& name)
 {
-    m_name = name;
+    m_keyframesRule->setName(name);
 
     // Since the name is used in the keyframe map list in CSSStyleSelector, we need
     // to recompute the style sheet to get the updated name.
@@ -61,94 +105,72 @@ void WebKitCSSKeyframesRule::setName(const String& name)
         styleSheet->styleSheetChanged();
 }
 
-void WebKitCSSKeyframesRule::parserAppendKeyframe(PassRefPtr<StyleKeyframe> keyframe)
-{
-    ASSERT(!m_childRuleCSSOMWrappers);
-    if (!keyframe)
-        return;
-    m_keyframes.append(keyframe);
-}
-
 void WebKitCSSKeyframesRule::insertRule(const String& ruleText)
 {
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size());
+
     CSSParser p(cssParserMode());
     RefPtr<StyleKeyframe> keyframe = p.parseKeyframeRule(parentStyleSheet(), ruleText);
     if (!keyframe)
         return;
 
-    m_keyframes.append(keyframe);
+    m_keyframesRule->wrapperAppendKeyframe(keyframe);
 
-    if (m_childRuleCSSOMWrappers)
-        m_childRuleCSSOMWrappers->grow(m_keyframes.size());
+    m_childRuleCSSOMWrappers.grow(length());
 }
 
 void WebKitCSSKeyframesRule::deleteRule(const String& s)
 {
-    int i = findKeyframeIndex(s);
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size());
+
+    int i = m_keyframesRule->findKeyframeIndex(s);
     if (i < 0)
         return;
 
-    m_keyframes.remove(i);
+    m_keyframesRule->wrapperRemoveKeyframe(i);
 
-    if (m_childRuleCSSOMWrappers) {
-        if (m_childRuleCSSOMWrappers->at(i))
-            m_childRuleCSSOMWrappers->at(i)->setParentRule(0);
-        m_childRuleCSSOMWrappers->remove(i);
-    }
+    if (m_childRuleCSSOMWrappers[i])
+        m_childRuleCSSOMWrappers[i]->setParentRule(0);
+    m_childRuleCSSOMWrappers.remove(i);
 }
 
 WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::findRule(const String& s)
 {
-    int i = findKeyframeIndex(s);
+    int i = m_keyframesRule->findKeyframeIndex(s);
     return (i >= 0) ? item(i) : 0;
 }
 
-int WebKitCSSKeyframesRule::findKeyframeIndex(const String& key) const
-{
-    String percentageString;
-    if (equalIgnoringCase(key, "from"))
-        percentageString = "0%";
-    else if (equalIgnoringCase(key, "to"))
-        percentageString = "100%";
-    else
-        percentageString = key;
-
-    for (unsigned i = 0; i < m_keyframes.size(); ++i) {
-        if (m_keyframes[i]->keyText() == percentageString)
-            return i;
-    }
-
-    return -1;
-}
-
 String WebKitCSSKeyframesRule::cssText() const
 {
     StringBuilder result;
     result.append("@-webkit-keyframes ");
-    result.append(m_name);
+    result.append(name());
     result.append(" { \n");
 
-    for (unsigned i = 0; i < m_keyframes.size(); ++i) {
+    unsigned size = length();
+    for (unsigned i = 0; i < size; ++i) {
         result.append("  ");
-        result.append(m_keyframes[i]->cssText());
+        result.append(m_keyframesRule->keyframes()[i]->cssText());
         result.append("\n");
     }
-
     result.append("}");
     return result.toString();
 }
 
+unsigned WebKitCSSKeyframesRule::length() const
+{ 
+    return m_keyframesRule->keyframes().size(); 
+}
+
 WebKitCSSKeyframeRule* WebKitCSSKeyframesRule::item(unsigned index) const
 { 
-    if (index >= m_keyframes.size())
+    if (index >= length())
         return 0;
-    if (!m_childRuleCSSOMWrappers)
-        m_childRuleCSSOMWrappers = adoptPtr(new Vector<RefPtr<WebKitCSSKeyframeRule> >(m_keyframes.size()));
 
-    ASSERT(m_childRuleCSSOMWrappers->size() == m_keyframes.size());
-    RefPtr<WebKitCSSKeyframeRule>& rule = m_childRuleCSSOMWrappers->at(index);
+    ASSERT(m_childRuleCSSOMWrappers.size() == m_keyframesRule->keyframes().size());
+    RefPtr<WebKitCSSKeyframeRule>& rule = m_childRuleCSSOMWrappers[index];
     if (!rule)
-        rule = adoptRef(new WebKitCSSKeyframeRule(m_keyframes[index].get(), const_cast<WebKitCSSKeyframesRule*>(this)));
+        rule = adoptRef(new WebKitCSSKeyframeRule(m_keyframesRule->keyframes()[index].get(), const_cast<WebKitCSSKeyframesRule*>(this)));
 
     return rule.get(); 
 }
index a7ab6d3..98ff148 100644 (file)
@@ -27,6 +27,7 @@
 #define WebKitCSSKeyframesRule_h
 
 #include "CSSRule.h"
+#include "StyleRule.h"
 #include <wtf/Forward.h>
 #include <wtf/RefPtr.h>
 #include <wtf/text/AtomicString.h>
@@ -38,31 +39,40 @@ class StyleKeyframe;
 class WebKitCSSKeyframeRule;
 
 typedef int ExceptionCode;
+    
+class StyleRuleKeyframes : public StyleRuleBase {
+public:
+    static PassRefPtr<StyleRuleKeyframes> create() { return adoptRef(new StyleRuleKeyframes()); }
+    
+    ~StyleRuleKeyframes();
+    
+    const Vector<RefPtr<StyleKeyframe> >& keyframes() const { return m_keyframes; }
+    
+    void parserAppendKeyframe(PassRefPtr<StyleKeyframe>);
+    void wrapperAppendKeyframe(PassRefPtr<StyleKeyframe>);
+    void wrapperRemoveKeyframe(unsigned);
+
+    String name() const { return m_name; }    
+    void setName(const String& name) { m_name = AtomicString(name); }
+    
+    int findKeyframeIndex(const String& key) const;
+
+private:
+    StyleRuleKeyframes();
+    
+    Vector<RefPtr<StyleKeyframe> > m_keyframes;
+    AtomicString m_name;
+};
 
 class WebKitCSSKeyframesRule : public CSSRule {
 public:
-    static PassRefPtr<WebKitCSSKeyframesRule> create()
-    {
-        return adoptRef(new WebKitCSSKeyframesRule(0));
-    }
-    static PassRefPtr<WebKitCSSKeyframesRule> create(CSSStyleSheet* parent)
-    {
-        return adoptRef(new WebKitCSSKeyframesRule(parent));
-    }
+    static PassRefPtr<WebKitCSSKeyframesRule> create(StyleRuleKeyframes* rule, CSSStyleSheet* sheet) { return adoptRef(new WebKitCSSKeyframesRule(rule, sheet)); }
 
     ~WebKitCSSKeyframesRule();
 
-    String name() const { return m_name; }
+    String name() const { return m_keyframesRule->name(); }
     void setName(const String&);
 
-    // This version of setName does not call styleSheetChanged to avoid
-    // unnecessary work. It assumes callers will either make that call
-    // themselves, or know that it will get called later.
-    void setNameInternal(const String& name)
-    {
-        m_name = AtomicString(name);
-    }
-
     CSSRuleList* cssRules();
 
     void insertRule(const String& rule);
@@ -71,24 +81,16 @@ public:
 
     String cssText() const;
 
-    // Not part of the CSSOM.
-    const Vector<RefPtr<StyleKeyframe> >& keyframes() const { return m_keyframes; }
-
-    void parserAppendKeyframe(PassRefPtr<StyleKeyframe>);
-    
     // For IndexedGetter and CSSRuleList.
-    unsigned length() const { return m_keyframes.size(); }
+    unsigned length() const;
     WebKitCSSKeyframeRule* item(unsigned index) const;
 
 private:
-    WebKitCSSKeyframesRule(CSSStyleSheet* parent);
-
-    int findKeyframeIndex(const String& key) const;
+    WebKitCSSKeyframesRule(StyleRuleKeyframes*, CSSStyleSheet* parent);
 
-    Vector<RefPtr<StyleKeyframe> > m_keyframes;
-    AtomicString m_name;
+    RefPtr<StyleRuleKeyframes> m_keyframesRule;
 
-    mutable OwnPtr<Vector<RefPtr<WebKitCSSKeyframeRule> > > m_childRuleCSSOMWrappers;
+    mutable Vector<RefPtr<WebKitCSSKeyframeRule> > m_childRuleCSSOMWrappers;
     mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
 
index 7cfaec6..df1c9b0 100644 (file)
 #include "WebKitCSSRegionRule.h"
 
 #include "CSSParser.h"
-#include "CSSParserValues.h"
 #include "CSSRuleList.h"
-#include "Document.h"
-#include "ExceptionCode.h"
+#include "StyleRule.h"
 #include <wtf/text/StringBuilder.h>
 
 namespace WebCore {
-WebKitCSSRegionRule::WebKitCSSRegionRule(CSSStyleSheet* parent, Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<CSSRule> >& rules)
+WebKitCSSRegionRule::WebKitCSSRegionRule(StyleRuleRegion* regionRule, CSSStyleSheet* parent)
     : CSSRule(parent, CSSRule::WEBKIT_REGION_RULE)
+    , m_regionRule(regionRule)
+    , m_childRuleCSSOMWrappers(regionRule->childRules().size())
 {
-    m_selectorList.adoptSelectorVector(*selectors);
-    m_childRules.swap(rules);
-    
-    for (unsigned i = 0; i < m_childRules.size(); ++i)
-        m_childRules[i]->setParentRule(this);
 }
 
 WebKitCSSRegionRule::~WebKitCSSRegionRule()
 {
-    for (unsigned i = 0; i < m_childRules.size(); ++i)
-        m_childRules[i]->setParentRule(0);
+    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
+        if (m_childRuleCSSOMWrappers[i])
+            m_childRuleCSSOMWrappers[i]->setParentRule(0);
+    }
 }
 
 String WebKitCSSRegionRule::cssText() const
@@ -61,25 +58,43 @@ String WebKitCSSRegionRule::cssText() const
     result.append("@-webkit-region ");
 
     // First add the selectors.
-    result.append(m_selectorList.selectorsText());
+    result.append(m_regionRule->selectorList().selectorsText());
 
     // Then add the rules.
     result.append(" { \n");
 
-    for (unsigned i = 0; i < m_childRules.size(); ++i) {
+    unsigned size = length();
+    for (unsigned i = 0; i < size; ++i) {
         result.append("  ");
-        result.append(m_childRules[i]->cssText());
+        result.append(item(i)->cssText());
         result.append("\n");
     }
     result.append("}");
     return result.toString();
 }
 
-CSSRuleList* WebKitCSSRegionRule::cssRules()
+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>(this));
+        m_ruleListCSSOMWrapper = adoptPtr(new LiveCSSRuleList<WebKitCSSRegionRule>(const_cast<WebKitCSSRegionRule*>(this)));
     return m_ruleListCSSOMWrapper.get();
 }
 
+
 } // namespace WebCore
index d7c56e4..ff57623 100644 (file)
 #ifndef WebKitCSSRegionRule_h
 #define WebKitCSSRegionRule_h
 
-#include "CSSSelectorList.h"
-#include "CSSStyleRule.h"
-
+#include "CSSRule.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
-class CSSParserSelector;
 class CSSRuleList;
+class StyleRuleRegion;
 
-class WebKitCSSRegionRule: public CSSRule {
+class WebKitCSSRegionRule : public CSSRule {
 public:
-    static PassRefPtr<WebKitCSSRegionRule> create(CSSStyleSheet* parent, Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<CSSRule> >& rules)
-    {
-        return adoptRef(new WebKitCSSRegionRule(parent, selectors, rules));
-    }
+    static PassRefPtr<WebKitCSSRegionRule> create(StyleRuleRegion* rule, CSSStyleSheet* sheet) { return adoptRef(new WebKitCSSRegionRule(rule, sheet)); }
 
     ~WebKitCSSRegionRule();
 
     String cssText() const;
-    const CSSSelectorList& selectorList() const { return m_selectorList; }
-    CSSRuleList* cssRules();
-
-    // Not part of the CSSOM.
-    unsigned ruleCount() const { return m_childRules.size(); }
-    CSSRule* ruleAt(unsigned index) const { return m_childRules[index].get(); }
+    CSSRuleList* cssRules() const;
     
     // For CSSRuleList
-    unsigned length() const { return ruleCount(); }
-    CSSRule* item(unsigned index) const { return index < ruleCount() ? ruleAt(index) : 0; }
+    unsigned length() const;
+    CSSRule* item(unsigned index) const;
 
 private:
-    WebKitCSSRegionRule(CSSStyleSheet* parent, Vector<OwnPtr<CSSParserSelector> >* selectors, Vector<RefPtr<CSSRule> >&);
+    WebKitCSSRegionRule(StyleRuleRegion*, CSSStyleSheet* parent);
 
-    CSSSelectorList m_selectorList;
-    Vector<RefPtr<CSSRule> > m_childRules;
+    RefPtr<StyleRuleRegion> m_regionRule;
+    
+    mutable Vector<RefPtr<CSSRule> > m_childRuleCSSOMWrappers;
+    mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
     
-    OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
+    friend class StyleRuleBlock;
 };
 
 }
index 5a53160..ac56e4b 100644 (file)
@@ -488,7 +488,8 @@ InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(Instr
 {
     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
     if (cssAgent) {
-        cssAgent->willMatchRule(rule->ensureCSSStyleRule());
+        RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper();
+        cssAgent->willMatchRule(static_cast<CSSStyleRule*>(cssRule.get()));
         return InspectorInstrumentationCookie(instrumentingAgents, 1);
     }
 
@@ -506,7 +507,8 @@ InspectorInstrumentationCookie InspectorInstrumentation::willProcessRuleImpl(Ins
 {
     InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
     if (cssAgent) {
-        cssAgent->willProcessRule(rule->ensureCSSStyleRule());
+        RefPtr<CSSRule> cssRule = rule->createCSSOMWrapper();
+        cssAgent->willProcessRule(static_cast<CSSStyleRule*>(cssRule.get()));
         return InspectorInstrumentationCookie(instrumentingAgents, 1);
     }
 
index 3b9e4ee..052be28 100644 (file)
@@ -1097,7 +1097,7 @@ bool InspectorStyleSheet::ensureSourceData()
     RefPtr<CSSRuleList> ruleList = asCSSRuleList(newStyleSheet.get());
     collectFlatRules(ruleList, &rules);
     for (unsigned i = 0, size = rules.size(); i < size; ++i) {
-        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i));
+        StyleRuleRangeMap::iterator it = ruleRangeMap.find(rules.at(i)->styleRule());
         if (it != ruleRangeMap.end()) {
             fixUnparsedPropertyRanges(it->second.get(), m_parsedStyleSheet->text());
             rangesVector->append(it->second);
index 9c8eae0..8d80f29 100644 (file)
@@ -45,6 +45,7 @@ namespace WebCore {
 
 class CSSRuleList;
 class CSSStyleDeclaration;
+class CSSStyleRule;
 class CSSStyleSheet;
 class Document;
 class Element;
index dd0b540..92750af 100644 (file)
@@ -25,7 +25,6 @@
 #include "SVGFontFaceElement.h"
 
 #include "Attribute.h"
-#include "CSSFontFaceRule.h"
 #include "CSSFontFaceSrcValue.h"
 #include "CSSParser.h"
 #include "CSSProperty.h"
@@ -41,6 +40,7 @@
 #include "SVGFontFaceSrcElement.h"
 #include "SVGGlyphElement.h"
 #include "SVGNames.h"
+#include "StyleRule.h"
 #include <math.h>
 
 namespace WebCore {
@@ -49,11 +49,11 @@ using namespace SVGNames;
 
 inline SVGFontFaceElement::SVGFontFaceElement(const QualifiedName& tagName, Document* document)
     : SVGElement(tagName, document)
-    , m_fontFaceRule(CSSFontFaceRule::create())
+    , m_fontFaceRule(StyleRuleFontFace::create())
 {
     ASSERT(hasTagName(font_faceTag));
     RefPtr<StylePropertySet> styleDeclaration = StylePropertySet::create(CSSStrictMode);
-    m_fontFaceRule->setDeclaration(styleDeclaration.release());
+    m_fontFaceRule->setProperties(styleDeclaration.release());
 }
 
 PassRefPtr<SVGFontFaceElement> SVGFontFaceElement::create(const QualifiedName& tagName, Document* document)
@@ -113,7 +113,7 @@ void SVGFontFaceElement::parseAttribute(Attribute* attr)
 {    
     int propId = cssPropertyIdForSVGAttributeName(attr->name());
     if (propId > 0) {
-        m_fontFaceRule->declaration()->setProperty(propId, attr->value(), false);
+        m_fontFaceRule->properties()->setProperty(propId, attr->value(), false);
         rebuildFontFace();
         return;
     }
@@ -258,7 +258,7 @@ int SVGFontFaceElement::descent() const
 
 String SVGFontFaceElement::fontFamily() const
 {
-    return m_fontFaceRule->declaration()->getPropertyValue(CSSPropertyFontFamily);
+    return m_fontFaceRule->properties()->getPropertyValue(CSSPropertyFontFamily);
 }
 
 SVGFontElement* SVGFontFaceElement::associatedFontElement() const
@@ -298,11 +298,11 @@ void SVGFontFaceElement::rebuildFontFace()
 
     // Parse in-memory CSS rules
     CSSProperty srcProperty(CSSPropertySrc, list);
-    m_fontFaceRule->declaration()->addParsedProperties(&srcProperty, 1);
+    m_fontFaceRule->properties()->addParsedProperties(&srcProperty, 1);
 
     if (describesParentFont) {    
         // Traverse parsed CSS values and associate CSSFontFaceSrcValue elements with ourselves.
-        RefPtr<CSSValue> src = m_fontFaceRule->declaration()->getPropertyCSSValue(CSSPropertySrc);
+        RefPtr<CSSValue> src = m_fontFaceRule->properties()->getPropertyCSSValue(CSSPropertySrc);
         CSSValueList* srcList = static_cast<CSSValueList*>(src.get());
 
         unsigned srcLength = srcList ? srcList->length() : 0;
@@ -320,7 +320,6 @@ void SVGFontFaceElement::insertedIntoDocument()
     SVGElement::insertedIntoDocument();
 
     document()->accessSVGExtensions()->registerSVGFontFaceElement(this);
-    m_fontFaceRule->setParentStyleSheet(document()->elementSheet());
 
     rebuildFontFace();
 }
@@ -330,7 +329,7 @@ void SVGFontFaceElement::removedFromDocument()
     SVGElement::removedFromDocument();
 
     document()->accessSVGExtensions()->unregisterSVGFontFaceElement(this);
-    m_fontFaceRule->declaration()->parseDeclaration(emptyString(), 0);
+    m_fontFaceRule->properties()->parseDeclaration(emptyString(), 0);
 
     document()->styleSelectorChanged(DeferRecalcStyle);
 }
index b458139..75af8cd 100644 (file)
@@ -27,8 +27,8 @@
 
 namespace WebCore {
 
-class CSSFontFaceRule;
 class SVGFontElement;
+class StyleRuleFontFace;
 
 class SVGFontFaceElement : public SVGElement {
 public:
@@ -49,7 +49,7 @@ public:
     SVGFontElement* associatedFontElement() const;
     void rebuildFontFace();
     
-    CSSFontFaceRule* fontFaceRule() const { return m_fontFaceRule.get(); }
+    StyleRuleFontFace* fontFaceRule() const { return m_fontFaceRule.get(); }
 
 private:
     SVGFontFaceElement(const QualifiedName&, Document*);
@@ -60,7 +60,7 @@ private:
     virtual void insertedIntoDocument();
     virtual void removedFromDocument();
 
-    RefPtr<CSSFontFaceRule> m_fontFaceRule;
+    RefPtr<StyleRuleFontFace> m_fontFaceRule;
     RefPtr<SVGFontElement> m_fontElement;
 };