From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/css/StyleRule.cpp | 282 +++++++++++++++++++++++++-------------- 1 file changed, 184 insertions(+), 98 deletions(-) (limited to 'Source/WebCore/css/StyleRule.cpp') diff --git a/Source/WebCore/css/StyleRule.cpp b/Source/WebCore/css/StyleRule.cpp index 172498507..60d1dbb42 100644 --- a/Source/WebCore/css/StyleRule.cpp +++ b/Source/WebCore/css/StyleRule.cpp @@ -22,84 +22,85 @@ #include "config.h" #include "StyleRule.h" -#include "CSSCharsetRule.h" +#include "CSSDeferredParser.h" #include "CSSFontFaceRule.h" -#include "CSSHostRule.h" #include "CSSImportRule.h" +#include "CSSKeyframeRule.h" +#include "CSSKeyframesRule.h" #include "CSSMediaRule.h" +#include "CSSNamespaceRule.h" #include "CSSPageRule.h" #include "CSSStyleRule.h" #include "CSSSupportsRule.h" #include "CSSUnknownRule.h" +#include "MediaList.h" #include "StyleProperties.h" #include "StyleRuleImport.h" -#include "WebKitCSSKeyframeRule.h" -#include "WebKitCSSKeyframesRule.h" #include "WebKitCSSRegionRule.h" #include "WebKitCSSViewportRule.h" namespace WebCore { struct SameSizeAsStyleRuleBase : public WTF::RefCountedBase { - unsigned bitfields; + unsigned bitfields : 5; }; COMPILE_ASSERT(sizeof(StyleRuleBase) == sizeof(SameSizeAsStyleRuleBase), StyleRuleBase_should_stay_small); -PassRefPtr StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const +RefPtr StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const { - return createCSSOMWrapper(parentSheet, 0); + return createCSSOMWrapper(parentSheet, nullptr); } -PassRefPtr StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const +RefPtr StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const { - return createCSSOMWrapper(0, parentRule); + return createCSSOMWrapper(nullptr, parentRule); } void StyleRuleBase::destroy() { switch (type()) { case Style: - delete static_cast(this); + delete downcast(this); return; case Page: - delete static_cast(this); + delete downcast(this); return; case FontFace: - delete static_cast(this); + delete downcast(this); return; case Media: - delete static_cast(this); + delete downcast(this); return; -#if ENABLE(CSS3_CONDITIONAL_RULES) case Supports: - delete static_cast(this); + delete downcast(this); return; -#endif #if ENABLE(CSS_REGIONS) case Region: - delete static_cast(this); + delete downcast(this); return; #endif case Import: - delete static_cast(this); + delete downcast(this); return; case Keyframes: - delete static_cast(this); - return; -#if ENABLE(SHADOW_DOM) - case HostInternal: - delete static_cast(this); + delete downcast(this); return; -#endif #if ENABLE(CSS_DEVICE_ADAPTATION) case Viewport: - delete static_cast(this); + delete downcast(this); return; #endif - case Unknown: - case Charset: + case Namespace: + delete downcast(this); + return; case Keyframe: + delete downcast(this); + return; + case Charset: + delete downcast(this); + return; + case Unknown: #if !ENABLE(CSS_REGIONS) case Region: #endif @@ -109,37 +110,32 @@ void StyleRuleBase::destroy() ASSERT_NOT_REACHED(); } -PassRef StyleRuleBase::copy() const +Ref StyleRuleBase::copy() const { switch (type()) { case Style: - return static_cast(this)->copy(); + return downcast(*this).copy(); case Page: - return static_cast(this)->copy(); + return downcast(*this).copy(); case FontFace: - return static_cast(this)->copy(); + return downcast(*this).copy(); case Media: - return static_cast(this)->copy(); -#if ENABLE(CSS3_CONDITIONAL_RULES) + return downcast(*this).copy(); case Supports: - return static_cast(this)->copy(); -#endif + return downcast(*this).copy(); #if ENABLE(CSS_REGIONS) case Region: - return static_cast(this)->copy(); + return downcast(*this).copy(); #endif case Keyframes: - return static_cast(this)->copy(); -#if ENABLE(SHADOW_DOM) - case HostInternal: - return static_cast(this)->copy(); -#endif + return downcast(*this).copy(); #if ENABLE(CSS_DEVICE_ADAPTATION) case Viewport: - return static_cast(this)->copy(); + return downcast(*this).copy(); #endif case Import: - // FIXME: Copy import rules. + case Namespace: + // FIXME: Copy import and namespace rules. break; case Unknown: case Charset: @@ -150,53 +146,47 @@ PassRef StyleRuleBase::copy() const break; } CRASH(); - // HACK: EFL won't build without this (old GCC with crappy -Werror=return-type) - return PassRef(*static_cast(nullptr)); } -PassRefPtr StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const +RefPtr StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const { RefPtr rule; - StyleRuleBase* self = const_cast(this); + StyleRuleBase& self = const_cast(*this); switch (type()) { case Style: - rule = CSSStyleRule::create(static_cast(self), parentSheet); + rule = CSSStyleRule::create(downcast(self), parentSheet); break; case Page: - rule = CSSPageRule::create(static_cast(self), parentSheet); + rule = CSSPageRule::create(downcast(self), parentSheet); break; case FontFace: - rule = CSSFontFaceRule::create(static_cast(self), parentSheet); + rule = CSSFontFaceRule::create(downcast(self), parentSheet); break; case Media: - rule = CSSMediaRule::create(static_cast(self), parentSheet); + rule = CSSMediaRule::create(downcast(self), parentSheet); break; -#if ENABLE(CSS3_CONDITIONAL_RULES) case Supports: - rule = CSSSupportsRule::create(static_cast(self), parentSheet); + rule = CSSSupportsRule::create(downcast(self), parentSheet); break; -#endif #if ENABLE(CSS_REGIONS) case Region: - rule = WebKitCSSRegionRule::create(static_cast(self), parentSheet); + rule = WebKitCSSRegionRule::create(downcast(self), parentSheet); break; #endif case Import: - rule = CSSImportRule::create(static_cast(self), parentSheet); + rule = CSSImportRule::create(downcast(self), parentSheet); break; case Keyframes: - rule = WebKitCSSKeyframesRule::create(static_cast(self), parentSheet); + rule = CSSKeyframesRule::create(downcast(self), parentSheet); break; #if ENABLE(CSS_DEVICE_ADAPTATION) case Viewport: - rule = WebKitCSSViewportRule::create(static_cast(self), parentSheet); + rule = WebKitCSSViewportRule::create(downcast(self), parentSheet); break; #endif -#if ENABLE(SHADOW_DOM) - case HostInternal: - rule = CSSHostRule::create(static_cast(self), parentSheet); + case Namespace: + rule = CSSNamespaceRule::create(downcast(self), parentSheet); break; -#endif case Unknown: case Charset: case Keyframe: @@ -204,11 +194,11 @@ PassRefPtr StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet case Region: #endif ASSERT_NOT_REACHED(); - return 0; + return nullptr; } if (parentRule) rule->setParentRule(parentRule); - return rule.release(); + return rule; } unsigned StyleRule::averageSizeInBytes() @@ -216,15 +206,15 @@ unsigned StyleRule::averageSizeInBytes() return sizeof(StyleRule) + sizeof(CSSSelector) + StyleProperties::averageSizeInBytes(); } -StyleRule::StyleRule(int sourceLine, PassRef properties) - : StyleRuleBase(Style, sourceLine) - , m_properties(std::move(properties)) +StyleRule::StyleRule(Ref&& properties) + : StyleRuleBase(Style) + , m_properties(WTFMove(properties)) { } StyleRule::StyleRule(const StyleRule& o) : StyleRuleBase(o) - , m_properties(o.m_properties->mutableCopy()) + , m_properties(o.properties().mutableCopy()) , m_selectorList(o.m_selectorList) { } @@ -233,21 +223,28 @@ StyleRule::~StyleRule() { } +const StyleProperties& StyleRule::properties() const +{ + if (m_properties->type() == DeferredPropertiesType) + m_properties = downcast(m_properties.get()).parseDeferredProperties(); + return downcast(m_properties.get()); +} + MutableStyleProperties& StyleRule::mutableProperties() { - if (!m_properties->isMutable()) - m_properties = m_properties->mutableCopy(); - return static_cast(m_properties.get()); + if (!is(m_properties.get())) + m_properties = properties().mutableCopy(); + return downcast(m_properties.get()); } -PassRef StyleRule::create(int sourceLine, const Vector& selectors, PassRef properties) +Ref StyleRule::create(const Vector& selectors, Ref&& properties) { ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty()); CSSSelector* selectorListArray = reinterpret_cast(fastMalloc(sizeof(CSSSelector) * selectors.size())); for (unsigned i = 0; i < selectors.size(); ++i) new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i)); selectorListArray[selectors.size() - 1].setLastInSelectorList(); - auto rule = StyleRule::create(sourceLine, std::move(properties)); + auto rule = StyleRule::create(WTFMove(properties)); rule.get().parserAdoptSelectorArray(selectorListArray); return rule; } @@ -265,7 +262,7 @@ Vector> StyleRule::splitIntoMultipleRulesWithMaximumSelectorCo componentsInThisSelector.append(component); if (componentsInThisSelector.size() + componentsSinceLastSplit.size() > maxCount && !componentsSinceLastSplit.isEmpty()) { - rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast(m_properties.get()))); + rules.append(create(componentsSinceLastSplit, const_cast(properties()))); componentsSinceLastSplit.clear(); } @@ -273,14 +270,14 @@ Vector> StyleRule::splitIntoMultipleRulesWithMaximumSelectorCo } if (!componentsSinceLastSplit.isEmpty()) - rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast(m_properties.get()))); + rules.append(create(componentsSinceLastSplit, const_cast(properties()))); return rules; } -StyleRulePage::StyleRulePage(PassRef properties) +StyleRulePage::StyleRulePage(Ref&& properties) : StyleRuleBase(Page) - , m_properties(std::move(properties)) + , m_properties(WTFMove(properties)) { } @@ -297,14 +294,14 @@ StyleRulePage::~StyleRulePage() MutableStyleProperties& StyleRulePage::mutableProperties() { - if (!m_properties->isMutable()) + if (!is(m_properties.get())) m_properties = m_properties->mutableCopy(); - return static_cast(m_properties.get()); + return downcast(m_properties.get()); } -StyleRuleFontFace::StyleRuleFontFace(PassRef properties) - : StyleRuleBase(FontFace, 0) - , m_properties(std::move(properties)) +StyleRuleFontFace::StyleRuleFontFace(Ref&& properties) + : StyleRuleBase(FontFace) + , m_properties(WTFMove(properties)) { } @@ -320,39 +317,85 @@ StyleRuleFontFace::~StyleRuleFontFace() MutableStyleProperties& StyleRuleFontFace::mutableProperties() { - if (!m_properties->isMutable()) + if (!is(m_properties.get())) m_properties = m_properties->mutableCopy(); - return static_cast(m_properties.get()); + return downcast(m_properties.get()); +} + +DeferredStyleGroupRuleList::DeferredStyleGroupRuleList(const CSSParserTokenRange& range, CSSDeferredParser& parser) + : m_parser(parser) +{ + size_t length = range.end() - range.begin(); + m_tokens.reserveCapacity(length); + m_tokens.append(range.begin(), length); +} + +void DeferredStyleGroupRuleList::parseDeferredRules(Vector>& childRules) +{ + m_parser->parseRuleList(m_tokens, childRules); } +void DeferredStyleGroupRuleList::parseDeferredKeyframes(StyleRuleKeyframes& keyframesRule) +{ + m_parser->parseKeyframeList(m_tokens, keyframesRule); +} + StyleRuleGroup::StyleRuleGroup(Type type, Vector>& adoptRule) - : StyleRuleBase(type, 0) + : StyleRuleBase(type) { m_childRules.swap(adoptRule); } +StyleRuleGroup::StyleRuleGroup(Type type, std::unique_ptr&& deferredRules) + : StyleRuleBase(type) + , m_deferredRules(WTFMove(deferredRules)) +{ +} + StyleRuleGroup::StyleRuleGroup(const StyleRuleGroup& o) : StyleRuleBase(o) { - m_childRules.reserveInitialCapacity(o.m_childRules.size()); - for (unsigned i = 0, size = o.m_childRules.size(); i < size; ++i) - m_childRules.uncheckedAppend(o.m_childRules[i]->copy()); + m_childRules.reserveInitialCapacity(o.childRules().size()); + for (auto& childRule : o.childRules()) + m_childRules.uncheckedAppend(childRule->copy()); +} + +const Vector>& StyleRuleGroup::childRules() const +{ + parseDeferredRulesIfNeeded(); + return m_childRules; } -void StyleRuleGroup::wrapperInsertRule(unsigned index, PassRef rule) +void StyleRuleGroup::wrapperInsertRule(unsigned index, Ref&& rule) { - m_childRules.insert(index, std::move(rule)); + parseDeferredRulesIfNeeded(); + m_childRules.insert(index, WTFMove(rule)); } void StyleRuleGroup::wrapperRemoveRule(unsigned index) { + parseDeferredRulesIfNeeded(); m_childRules.remove(index); } - -StyleRuleMedia::StyleRuleMedia(PassRefPtr media, Vector>& adoptRules) +void StyleRuleGroup::parseDeferredRulesIfNeeded() const +{ + if (!m_deferredRules) + return; + + m_deferredRules->parseDeferredRules(m_childRules); + m_deferredRules = nullptr; +} + +StyleRuleMedia::StyleRuleMedia(Ref&& media, Vector>& adoptRules) : StyleRuleGroup(Media, adoptRules) - , m_mediaQueries(media) + , m_mediaQueries(WTFMove(media)) +{ +} + +StyleRuleMedia::StyleRuleMedia(Ref&& media, std::unique_ptr&& deferredRules) + : StyleRuleGroup(Media, WTFMove(deferredRules)) + , m_mediaQueries(WTFMove(media)) { } @@ -364,7 +407,6 @@ StyleRuleMedia::StyleRuleMedia(const StyleRuleMedia& o) } -#if ENABLE(CSS3_CONDITIONAL_RULES) StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector>& adoptRules) : StyleRuleGroup(Supports, adoptRules) , m_conditionText(conditionText) @@ -372,20 +414,32 @@ StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool condition { } +StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, std::unique_ptr&& deferredRules) + : StyleRuleGroup(Supports, WTFMove(deferredRules)) + , m_conditionText(conditionText) + , m_conditionIsSupported(conditionIsSupported) +{ +} + StyleRuleSupports::StyleRuleSupports(const StyleRuleSupports& o) : StyleRuleGroup(o) , m_conditionText(o.m_conditionText) , m_conditionIsSupported(o.m_conditionIsSupported) { } -#endif -StyleRuleRegion::StyleRuleRegion(Vector>* selectors, Vector>& adoptRules) +StyleRuleRegion::StyleRuleRegion(Vector>* selectors, Vector>& adoptRules) : StyleRuleGroup(Region, adoptRules) { m_selectorList.adoptSelectorVector(*selectors); } +StyleRuleRegion::StyleRuleRegion(CSSSelectorList& selectors, Vector>& adoptRules) + : StyleRuleGroup(Region, adoptRules) + , m_selectorList(WTFMove(selectors)) +{ +} + StyleRuleRegion::StyleRuleRegion(const StyleRuleRegion& o) : StyleRuleGroup(o) , m_selectorList(o.m_selectorList) @@ -394,9 +448,9 @@ StyleRuleRegion::StyleRuleRegion(const StyleRuleRegion& o) #if ENABLE(CSS_DEVICE_ADAPTATION) -StyleRuleViewport::StyleRuleViewport(PassRef properties) +StyleRuleViewport::StyleRuleViewport(Ref&& properties) : StyleRuleBase(Viewport, 0) - , m_properties(std::move(properties)) + , m_properties(WTFMove(properties)) { } @@ -418,4 +472,36 @@ MutableStyleProperties& StyleRuleViewport::mutableProperties() } #endif // ENABLE(CSS_DEVICE_ADAPTATION) +StyleRuleCharset::StyleRuleCharset() + : StyleRuleBase(Charset) +{ +} + +StyleRuleCharset::StyleRuleCharset(const StyleRuleCharset& o) + : StyleRuleBase(o) +{ +} + +StyleRuleCharset::~StyleRuleCharset() +{ +} + +StyleRuleNamespace::StyleRuleNamespace(AtomicString prefix, AtomicString uri) + : StyleRuleBase(Namespace) + , m_prefix(prefix) + , m_uri(uri) +{ +} + +StyleRuleNamespace::StyleRuleNamespace(const StyleRuleNamespace& o) + : StyleRuleBase(o) + , m_prefix(o.m_prefix) + , m_uri(o.m_uri) +{ +} + +StyleRuleNamespace::~StyleRuleNamespace() +{ +} + } // namespace WebCore -- cgit v1.2.1