void MutableStylePropertySet::parseDeclarationList(const String& styleDeclaration, StyleSheetContents* contextStyleSheet) { m_propertyVector.clear(); CSSParserContext context(cssParserMode(), UseCounter::getFrom(contextStyleSheet)); if (contextStyleSheet) { context = contextStyleSheet->parserContext(); context.setMode(cssParserMode()); } CSSParser::parseDeclarationList(context, this, styleDeclaration); }
unsigned CSSStyleSheet::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec) { ec = 0; if (index > length()) { ec = INDEX_SIZE_ERR; return 0; } CSSParser p(cssParserMode()); RefPtr<StyleRuleBase> rule = p.parseRule(this, ruleString); if (!rule) { ec = SYNTAX_ERR; return 0; } // 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. ec = HIERARCHY_REQUEST_ERR; return 0; } --childVectorIndex; } if (childVectorIndex < m_importRules.size() || (childVectorIndex == m_importRules.size() && rule->isImportRule())) { // Inserting non-import rule before @import is not allowed. if (!rule->isImportRule()) { ec = HIERARCHY_REQUEST_ERR; return 0; } m_importRules.insert(childVectorIndex, static_cast<StyleRuleImport*>(rule.get())); m_importRules[childVectorIndex]->requestStyleSheet(); goto success; } // Inserting @import rule after a non-import rule is not allowed. if (rule->isImportRule()) { ec = HIERARCHY_REQUEST_ERR; return 0; } childVectorIndex -= m_importRules.size(); m_childRules.insert(childVectorIndex, rule.release()); success: if (!m_childRuleCSSOMWrappers.isEmpty()) m_childRuleCSSOMWrappers.insert(index, RefPtr<CSSRule>()); // FIXME: Stylesheet doesn't actually change meaningfully before the imported sheets are loaded. styleSheetChanged(); return index; }
PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const { if (!isMutable()) return toImmutableStylePropertySet(const_cast<StylePropertySet*>(this)); const MutableStylePropertySet* mutableThis = toMutableStylePropertySet(this); return ImmutableStylePropertySet::create(mutableThis->m_propertyVector.data(), mutableThis->m_propertyVector.size(), cssParserMode()); }