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):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@112923 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/css/StyleRule.cpp b/Source/WebCore/css/StyleRule.cpp
index fc0f9d6..0766120 100644
--- a/Source/WebCore/css/StyleRule.cpp
+++ b/Source/WebCore/css/StyleRule.cpp
@@ -22,29 +22,166 @@
#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)
{
- ASSERT(m_cssomWrapper);
- return m_cssomWrapper;
+ 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)
+{
+ m_selectorList.adoptSelectorVector(*selectors);
}
} // namespace WebCore