void StyleSheetContents::wrapperDeleteRule(unsigned index) { ASSERT(m_isMutable); ASSERT_WITH_SECURITY_IMPLICATION(index < ruleCount()); unsigned childVectorIndex = index; if (hasCharsetRule()) { if (childVectorIndex == 0) { clearCharsetRule(); return; } --childVectorIndex; } if (childVectorIndex < m_importRules.size()) { m_importRules[childVectorIndex]->clearParentStyleSheet(); if (m_importRules[childVectorIndex]->isFontFaceRule()) notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[childVectorIndex].get())); m_importRules.remove(childVectorIndex); return; } childVectorIndex -= m_importRules.size(); if (m_childRules[childVectorIndex]->isFontFaceRule()) notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[childVectorIndex].get())); m_childRules.remove(childVectorIndex); }
bool StyleSheetContents::wrapperDeleteRule(unsigned index) { ASSERT(m_isMutable); SECURITY_DCHECK(index < ruleCount()); if (index < m_importRules.size()) { m_importRules[index]->clearParentStyleSheet(); if (m_importRules[index]->isFontFaceRule()) notifyRemoveFontFaceRule(toStyleRuleFontFace(m_importRules[index].get())); m_importRules.remove(index); return true; } index -= m_importRules.size(); if (index < m_namespaceRules.size()) { if (!m_childRules.isEmpty()) return false; m_namespaceRules.remove(index); return true; } index -= m_namespaceRules.size(); if (m_childRules[index]->isFontFaceRule()) notifyRemoveFontFaceRule(toStyleRuleFontFace(m_childRules[index].get())); m_childRules.remove(index); return true; }
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; }
void CSSFontFaceRule::reattach(StyleRuleBase* rule) { ASSERT(rule); m_fontFaceRule = toStyleRuleFontFace(rule); if (m_propertiesCSSOMWrapper) m_propertiesCSSOMWrapper->reattach(m_fontFaceRule->mutableProperties()); }
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; }
PassRefPtrWillBeRawPtr<CSSValue> CSSParser::parseFontFaceDescriptor(CSSPropertyID propertyID, const String& propertyValue, const CSSParserContext& context) { StringBuilder builder; builder.appendLiteral("@font-face { "); builder.append(getPropertyNameString(propertyID)); builder.appendLiteral(" : "); builder.append(propertyValue); builder.appendLiteral("; }"); RefPtrWillBeRawPtr<StyleRuleBase> rule = parseRule(context, nullptr, builder.toString()); if (!rule || !rule->isFontFaceRule()) return nullptr; return toStyleRuleFontFace(rule.get())->properties().getPropertyCSSValue(propertyID); }
static void findFontFaceRulesFromRules(const WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase> >& rules, WillBeHeapVector<RawPtrWillBeMember<const StyleRuleFontFace> >& fontFaceRules) { for (unsigned i = 0; i < rules.size(); ++i) { StyleRuleBase* rule = rules[i].get(); if (rule->isFontFaceRule()) { fontFaceRules.append(toStyleRuleFontFace(rule)); } else if (rule->isMediaRule()) { StyleRuleMedia* mediaRule = toStyleRuleMedia(rule); // We cannot know whether the media rule matches or not, but // for safety, remove @font-face in the media rule (if exists). findFontFaceRulesFromRules(mediaRule->childRules(), fontFaceRules); } } }
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 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); } } }