bool StyleSheetContents::wrapperInsertRule(StyleRuleBase* rule, unsigned index) { ASSERT(m_isMutable); SECURITY_DCHECK(index <= ruleCount()); if (index < m_importRules.size() || (index == m_importRules.size() && rule->isImportRule())) { // Inserting non-import rule before @import is not allowed. if (!rule->isImportRule()) return false; StyleRuleImport* importRule = toStyleRuleImport(rule); if (importRule->mediaQueries()) setHasMediaQueries(); m_importRules.insert(index, importRule); m_importRules[index]->setParentStyleSheet(this); m_importRules[index]->requestStyleSheet(); // FIXME: Stylesheet doesn't actually change meaningfully before the // imported sheets are loaded. return true; } // Inserting @import rule after a non-import rule is not allowed. if (rule->isImportRule()) return false; index -= m_importRules.size(); if (index < m_namespaceRules.size() || (index == m_namespaceRules.size() && rule->isNamespaceRule())) { // Inserting non-namespace rules other than import rule before @namespace is // not allowed. if (!rule->isNamespaceRule()) return false; // Inserting @namespace rule when rules other than import/namespace/charset // are present is not allowed. if (!m_childRules.isEmpty()) return false; StyleRuleNamespace* namespaceRule = toStyleRuleNamespace(rule); m_namespaceRules.insert(index, namespaceRule); // For now to be compatible with IE and Firefox if namespace rule with same // prefix is added irrespective of adding the rule at any index, last added // rule's value is considered. // TODO ([email protected]): As per spec last valid rule should be // considered, which means if namespace rule is added in the middle of // existing namespace rules, rule which comes later in rule list with same // prefix needs to be considered. parserAddNamespace(namespaceRule->prefix(), namespaceRule->uri()); return true; } if (rule->isNamespaceRule()) return false; index -= m_namespaceRules.size(); m_childRules.insert(index, rule); return true; }
void StyleSheetContents::parserAppendRule(StyleRuleBase* rule) { if (rule->isImportRule()) { // Parser enforces that @import rules come before anything else ASSERT(m_childRules.isEmpty()); StyleRuleImport* importRule = toStyleRuleImport(rule); if (importRule->mediaQueries()) setHasMediaQueries(); m_importRules.append(importRule); m_importRules.last()->setParentStyleSheet(this); m_importRules.last()->requestStyleSheet(); return; } if (rule->isNamespaceRule()) { // Parser enforces that @namespace rules come before all rules other than // import/charset rules ASSERT(m_childRules.isEmpty()); StyleRuleNamespace& namespaceRule = toStyleRuleNamespace(*rule); parserAddNamespace(namespaceRule.prefix(), namespaceRule.uri()); m_namespaceRules.append(&namespaceRule); return; } m_childRules.append(rule); }
bool StyleSheetContents::wrapperInsertRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule, unsigned index) { ASSERT(m_isMutable); ASSERT_WITH_SECURITY_IMPLICATION(index <= ruleCount()); // Parser::parseRule doesn't currently allow @charset so we don't need to deal with it. ASSERT(!rule->isCharsetRule()); unsigned childVectorIndex = index; // m_childRules does not contain @charset which is always in index 0 if it exists. if (hasCharsetRule()) { if (childVectorIndex == 0) { // Nothing can be inserted before @charset. return false; } --childVectorIndex; } if (childVectorIndex < m_importRules.size() || (childVectorIndex == m_importRules.size() && rule->isImportRule())) { // Inserting non-import rule before @import is not allowed. if (!rule->isImportRule()) return false; StyleRuleImport* importRule = toStyleRuleImport(rule.get()); if (importRule->mediaQueries()) setHasMediaQueries(); m_importRules.insert(childVectorIndex, importRule); m_importRules[childVectorIndex]->setParentStyleSheet(this); m_importRules[childVectorIndex]->requestStyleSheet(); // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded. return true; } // Inserting @import rule after a non-import rule is not allowed. if (rule->isImportRule()) return false; if (rule->isMediaRule()) setHasMediaQueries(); childVectorIndex -= m_importRules.size(); if (rule->isFontFaceRule()) setHasFontFaceRule(true); m_childRules.insert(childVectorIndex, rule); return true; }
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 StyleSheetContents::parserAppendRule(PassRefPtrWillBeRawPtr<StyleRuleBase> rule) { ASSERT(!rule->isCharsetRule()); if (rule->isImportRule()) { // Parser enforces that @import rules come before anything else except @charset. ASSERT(m_childRules.isEmpty()); StyleRuleImport* importRule = toStyleRuleImport(rule.get()); if (importRule->mediaQueries()) setHasMediaQueries(); m_importRules.append(importRule); m_importRules.last()->setParentStyleSheet(this); m_importRules.last()->requestStyleSheet(); return; } // Add warning message to inspector if dpi/dpcm values are used for screen media. if (rule->isMediaRule()) { setHasMediaQueries(); reportMediaQueryWarningIfNeeded(singleOwnerDocument(), toStyleRuleMedia(rule.get())->mediaQueries()); } m_childRules.append(rule); }