void StyleSheetContents::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<StyleRuleImport*>(rule.get())); m_importRules.last()->setParentStyleSheet(this); m_importRules.last()->requestStyleSheet(); return; } #if ENABLE(RESOLUTION_MEDIA_QUERY) // Add warning message to inspector if dpi/dpcm values are used for screen media. if (rule->isMediaRule()) reportMediaQueryWarningIfNeeded(singleOwnerDocument(), static_cast<StyleRuleMedia*>(rule.get())->mediaQueries()); #endif // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369> // If we're adding a rule with a huge number of selectors, split it up into multiple rules if (rule->isStyleRule() && toStyleRule(rule.get())->selectorList().componentCount() > RuleData::maximumSelectorComponentCount) { Vector<RefPtr<StyleRule>> rules = toStyleRule(rule.get())->splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount); m_childRules.appendVector(rules); return; } m_childRules.append(rule); }
void CSSStyleRule::reattach(StyleRuleBase* rule) { ASSERT(rule); m_styleRule = toStyleRule(rule); if (m_propertiesCSSOMWrapper) m_propertiesCSSOMWrapper->reattach(m_styleRule->mutableProperties()); }
PassRefPtrWillBeRawPtr<StyleRuleBase> StyleRuleBase::copy() const { switch (type()) { case Style: return toStyleRule(this)->copy(); case Page: return toStyleRulePage(this)->copy(); case FontFace: return toStyleRuleFontFace(this)->copy(); case Media: return toStyleRuleMedia(this)->copy(); case Supports: return toStyleRuleSupports(this)->copy(); case Import: // FIXME: Copy import rules. ASSERT_NOT_REACHED(); return nullptr; case Keyframes: return toStyleRuleKeyframes(this)->copy(); case Viewport: return toStyleRuleViewport(this)->copy(); case Filter: return toStyleRuleFilter(this)->copy(); case Unknown: case Charset: case Keyframe: ASSERT_NOT_REACHED(); return nullptr; } ASSERT_NOT_REACHED(); return nullptr; }
StyleRuleBase* StyleRuleBase::copy() const { switch (type()) { case Style: return toStyleRule(this)->copy(); case Page: return toStyleRulePage(this)->copy(); case FontFace: return toStyleRuleFontFace(this)->copy(); case Media: return toStyleRuleMedia(this)->copy(); case Supports: return toStyleRuleSupports(this)->copy(); case Import: // FIXME: Copy import rules. NOTREACHED(); return nullptr; case Keyframes: return toStyleRuleKeyframes(this)->copy(); case Viewport: return toStyleRuleViewport(this)->copy(); case Namespace: return toStyleRuleNamespace(this)->copy(); case Charset: case Keyframe: ASSERT_NOT_REACHED(); return nullptr; } ASSERT_NOT_REACHED(); return nullptr; }
static bool childRulesHaveFailedOrCanceledSubresources( const HeapVector<Member<StyleRuleBase>>& rules) { for (unsigned i = 0; i < rules.size(); ++i) { const StyleRuleBase* rule = rules[i].get(); switch (rule->type()) { case StyleRuleBase::Style: if (toStyleRule(rule)->propertiesHaveFailedOrCanceledSubresources()) return true; break; case StyleRuleBase::FontFace: if (toStyleRuleFontFace(rule) ->properties() .hasFailedOrCanceledSubresources()) return true; break; case StyleRuleBase::Media: if (childRulesHaveFailedOrCanceledSubresources( toStyleRuleMedia(rule)->childRules())) return true; break; case StyleRuleBase::Charset: case StyleRuleBase::Import: case StyleRuleBase::Namespace: ASSERT_NOT_REACHED(); case StyleRuleBase::Page: case StyleRuleBase::Keyframes: case StyleRuleBase::Keyframe: case StyleRuleBase::Supports: case StyleRuleBase::Viewport: break; } } return false; }
static bool hasDistributedRule(StyleSheetContents* styleSheetContents) { const Vector<RefPtr<StyleRuleBase> >& rules = styleSheetContents->childRules(); for (unsigned i = 0; i < rules.size(); i++) { const StyleRuleBase* rule = rules[i].get(); if (!rule->isStyleRule()) continue; const StyleRule* styleRule = toStyleRule(rule); const CSSSelectorList& selectorList = styleRule->selectorList(); for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = selectorList.indexOfNextSelectorAfter(selectorIndex)) { if (selectorList.hasShadowDistributedAt(selectorIndex)) return true; } } return false; }
PassRefPtrWillBeRawPtr<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const { RefPtrWillBeRawPtr<CSSRule> rule; StyleRuleBase* self = const_cast<StyleRuleBase*>(this); switch (type()) { case Style: rule = CSSStyleRule::create(toStyleRule(self), parentSheet); break; case Page: rule = CSSPageRule::create(toStyleRulePage(self), parentSheet); break; case FontFace: rule = CSSFontFaceRule::create(toStyleRuleFontFace(self), parentSheet); break; case Media: rule = CSSMediaRule::create(toStyleRuleMedia(self), parentSheet); break; case Supports: rule = CSSSupportsRule::create(toStyleRuleSupports(self), parentSheet); break; case Import: rule = CSSImportRule::create(toStyleRuleImport(self), parentSheet); break; case Keyframes: rule = CSSKeyframesRule::create(toStyleRuleKeyframes(self), parentSheet); break; case Viewport: rule = CSSViewportRule::create(toStyleRuleViewport(self), parentSheet); break; case Filter: rule = CSSFilterRule::create(toStyleRuleFilter(self), parentSheet); break; case Unknown: case Charset: case Keyframe: ASSERT_NOT_REACHED(); return nullptr; } if (parentRule) rule->setParentRule(parentRule); return rule.release(); }
CSSRule* StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const { CSSRule* rule = nullptr; StyleRuleBase* self = const_cast<StyleRuleBase*>(this); switch (type()) { case Style: rule = CSSStyleRule::create(toStyleRule(self), parentSheet); break; case Page: rule = CSSPageRule::create(toStyleRulePage(self), parentSheet); break; case FontFace: rule = CSSFontFaceRule::create(toStyleRuleFontFace(self), parentSheet); break; case Media: rule = CSSMediaRule::create(toStyleRuleMedia(self), parentSheet); break; case Supports: rule = CSSSupportsRule::create(toStyleRuleSupports(self), parentSheet); break; case Import: rule = CSSImportRule::create(toStyleRuleImport(self), parentSheet); break; case Keyframes: rule = CSSKeyframesRule::create(toStyleRuleKeyframes(self), parentSheet); break; case Namespace: rule = CSSNamespaceRule::create(toStyleRuleNamespace(self), parentSheet); break; case Viewport: rule = CSSViewportRule::create(toStyleRuleViewport(self), parentSheet); break; case Keyframe: case Charset: ASSERT_NOT_REACHED(); return nullptr; } if (parentRule) rule->setParentRule(parentRule); return rule; }
void StyleRuleBase::finalizeGarbageCollectedObject() { switch (type()) { case Charset: toStyleRuleCharset(this)->~StyleRuleCharset(); return; case Style: toStyleRule(this)->~StyleRule(); return; case Page: toStyleRulePage(this)->~StyleRulePage(); return; case FontFace: toStyleRuleFontFace(this)->~StyleRuleFontFace(); return; case Media: toStyleRuleMedia(this)->~StyleRuleMedia(); return; case Supports: toStyleRuleSupports(this)->~StyleRuleSupports(); return; case Import: toStyleRuleImport(this)->~StyleRuleImport(); return; case Keyframes: toStyleRuleKeyframes(this)->~StyleRuleKeyframes(); return; case Keyframe: toStyleRuleKeyframe(this)->~StyleRuleKeyframe(); return; case Namespace: toStyleRuleNamespace(this)->~StyleRuleNamespace(); return; case Viewport: toStyleRuleViewport(this)->~StyleRuleViewport(); return; case Unknown: return; } ASSERT_NOT_REACHED(); }
void StyleRuleBase::destroy() { switch (type()) { case Charset: delete toStyleRuleCharset(this); return; case Style: delete toStyleRule(this); return; case Page: delete toStyleRulePage(this); return; case FontFace: delete toStyleRuleFontFace(this); return; case Media: delete toStyleRuleMedia(this); return; case Supports: delete toStyleRuleSupports(this); return; case Import: delete toStyleRuleImport(this); return; case Keyframes: delete toStyleRuleKeyframes(this); return; case Keyframe: delete toStyleRuleKeyframe(this); return; case Namespace: delete toStyleRuleNamespace(this); return; case Viewport: delete toStyleRuleViewport(this); return; case Unknown: return; } ASSERT_NOT_REACHED(); }
void StyleSheetInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheetContents) { // Updating the style on the shadow DOM for image fallback content can bring us here when imports // are still getting loaded in the main document. Just need to exit early as we will return here // when the imports finish loading. if (styleSheetContents->isLoading()) return; // See if all rules on the sheet are scoped to some specific ids or classes. // Then test if we actually have any of those in the tree at the moment. const WillBeHeapVector<RefPtrWillBeMember<StyleRuleImport>>& importRules = styleSheetContents->importRules(); for (unsigned i = 0; i < importRules.size(); ++i) { if (!importRules[i]->styleSheet()) continue; analyzeStyleSheet(importRules[i]->styleSheet()); if (m_dirtiesAllStyle) return; } if (m_treeScope->rootNode().isShadowRoot()) return; const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase>>& rules = styleSheetContents->childRules(); for (unsigned i = 0; i < rules.size(); i++) { StyleRuleBase* rule = rules[i].get(); if (!rule->isStyleRule()) { if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { m_dirtiesAllStyle = true; return; } continue; } StyleRule* styleRule = toStyleRule(rule); if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_classScopes)) { m_dirtiesAllStyle = true; return; } } }
void StyleInvalidationAnalysis::analyzeStyleSheet(StyleSheetContents* styleSheetContents) { ASSERT(!styleSheetContents->isLoading()); // See if all rules on the sheet are scoped to some specific ids or classes. // Then test if we actually have any of those in the tree at the moment. const Vector<RefPtr<StyleRuleImport> >& importRules = styleSheetContents->importRules(); for (unsigned i = 0; i < importRules.size(); ++i) { if (!importRules[i]->styleSheet()) continue; analyzeStyleSheet(importRules[i]->styleSheet()); if (m_dirtiesAllStyle) return; } if (styleSheetContents->hasSingleOwnerNode()) { Node* ownerNode = styleSheetContents->singleOwnerNode(); if (ownerNode && ownerNode->hasTagName(HTMLNames::styleTag) && toHTMLStyleElement(ownerNode)->isRegisteredAsScoped()) { m_scopingNodes.append(determineScopingNodeForStyleScoped(toHTMLStyleElement(ownerNode), styleSheetContents)); return; } } const Vector<RefPtr<StyleRuleBase> >& rules = styleSheetContents->childRules(); for (unsigned i = 0; i < rules.size(); i++) { StyleRuleBase* rule = rules[i].get(); if (!rule->isStyleRule()) { if (ruleAdditionMightRequireDocumentStyleRecalc(rule)) { m_dirtiesAllStyle = true; return; } continue; } StyleRule* styleRule = toStyleRule(rule); if (!determineSelectorScopes(styleRule->selectorList(), m_idScopes, m_classScopes)) { m_dirtiesAllStyle = true; return; } } }
void StyleRuleBase::finalize() { switch (type()) { case Style: toStyleRule(this)->~StyleRule(); return; case Page: toStyleRulePage(this)->~StyleRulePage(); return; case FontFace: toStyleRuleFontFace(this)->~StyleRuleFontFace(); return; case Media: toStyleRuleMedia(this)->~StyleRuleMedia(); return; case Supports: toStyleRuleSupports(this)->~StyleRuleSupports(); return; case Import: toStyleRuleImport(this)->~StyleRuleImport(); return; case Keyframes: toStyleRuleKeyframes(this)->~StyleRuleKeyframes(); return; case Viewport: toStyleRuleViewport(this)->~StyleRuleViewport(); return; case Filter: toStyleRuleFilter(this)->~StyleRuleFilter(); return; case Unknown: case Charset: case Keyframe: ASSERT_NOT_REACHED(); return; } ASSERT_NOT_REACHED(); }
void StyleRuleBase::trace(Visitor* visitor) { switch (type()) { case Style: toStyleRule(this)->traceAfterDispatch(visitor); return; case Page: toStyleRulePage(this)->traceAfterDispatch(visitor); return; case FontFace: toStyleRuleFontFace(this)->traceAfterDispatch(visitor); return; case Media: toStyleRuleMedia(this)->traceAfterDispatch(visitor); return; case Supports: toStyleRuleSupports(this)->traceAfterDispatch(visitor); return; case Import: toStyleRuleImport(this)->traceAfterDispatch(visitor); return; case Keyframes: toStyleRuleKeyframes(this)->traceAfterDispatch(visitor); return; case Viewport: toStyleRuleViewport(this)->traceAfterDispatch(visitor); return; case Filter: toStyleRuleFilter(this)->traceAfterDispatch(visitor); return; case Unknown: case Charset: case Keyframe: ASSERT_NOT_REACHED(); return; } ASSERT_NOT_REACHED(); }
void RuleSet::addChildRules(const Vector<RefPtr<StyleRuleBase> >& rules, const MediaQueryEvaluator& medium, AddRuleFlags addRuleFlags) { for (unsigned i = 0; i < rules.size(); ++i) { StyleRuleBase* rule = rules[i].get(); if (rule->isStyleRule()) { StyleRule* styleRule = toStyleRule(rule); const CSSSelectorList& selectorList = styleRule->selectorList(); for (size_t selectorIndex = 0; selectorIndex != kNotFound; selectorIndex = selectorList.indexOfNextSelectorAfter(selectorIndex)) addRule(styleRule, selectorIndex, addRuleFlags); } else if (rule->isMediaRule()) { StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); if ((!mediaRule->mediaQueries() || medium.eval(mediaRule->mediaQueries(), &m_viewportDependentMediaQueryResults))) addChildRules(mediaRule->childRules(), medium, addRuleFlags); } else if (rule->isFontFaceRule()) { addFontFaceRule(toStyleRuleFontFace(rule)); } else if (rule->isKeyframesRule()) { addKeyframesRule(toStyleRuleKeyframes(rule)); } else if (rule->isSupportsRule() && toStyleRuleSupports(rule)->conditionIsSupported()) { addChildRules(toStyleRuleSupports(rule)->childRules(), medium, addRuleFlags); } } }