diff options
Diffstat (limited to 'Source/WebCore/css/CSSGroupingRule.cpp')
-rw-r--r-- | Source/WebCore/css/CSSGroupingRule.cpp | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/Source/WebCore/css/CSSGroupingRule.cpp b/Source/WebCore/css/CSSGroupingRule.cpp index 664c9b9a1..42bb83bd1 100644 --- a/Source/WebCore/css/CSSGroupingRule.cpp +++ b/Source/WebCore/css/CSSGroupingRule.cpp @@ -41,10 +41,10 @@ namespace WebCore { -CSSGroupingRule::CSSGroupingRule(StyleRuleGroup* groupRule, CSSStyleSheet* parent) +CSSGroupingRule::CSSGroupingRule(StyleRuleGroup& groupRule, CSSStyleSheet* parent) : CSSRule(parent) , m_groupRule(groupRule) - , m_childRuleCSSOMWrappers(groupRule->childRules().size()) + , m_childRuleCSSOMWrappers(groupRule.childRules().size()) { } @@ -57,26 +57,23 @@ CSSGroupingRule::~CSSGroupingRule() } } -unsigned CSSGroupingRule::insertRule(const String& ruleString, unsigned index, ExceptionCode& ec) +ExceptionOr<unsigned> CSSGroupingRule::insertRule(const String& ruleString, unsigned index) { ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); if (index > m_groupRule->childRules().size()) { // INDEX_SIZE_ERR: Raised if the specified index is not a valid insertion point. - ec = INDEX_SIZE_ERR; - return 0; + return Exception { INDEX_SIZE_ERR }; } - CSSParser parser(parserContext()); CSSStyleSheet* styleSheet = parentStyleSheet(); - RefPtr<StyleRuleBase> newRule = parser.parseRule(styleSheet ? &styleSheet->contents() : nullptr, ruleString); + RefPtr<StyleRuleBase> newRule = CSSParser::parseRule(parserContext(), styleSheet ? &styleSheet->contents() : nullptr, ruleString); if (!newRule) { // SYNTAX_ERR: Raised if the specified rule has a syntax error and is unparsable. - ec = SYNTAX_ERR; - return 0; + return Exception { SYNTAX_ERR }; } - if (newRule->isImportRule()) { + if (newRule->isImportRule() || newRule->isNamespaceRule()) { // FIXME: an HIERARCHY_REQUEST_ERR should also be thrown for a @charset or a nested // @media rule. They are currently not getting parsed, resulting in a SYNTAX_ERR // to get raised above. @@ -84,8 +81,7 @@ unsigned CSSGroupingRule::insertRule(const String& ruleString, unsigned index, E // HIERARCHY_REQUEST_ERR: Raised if the rule cannot be inserted at the specified // index, e.g., if an @import rule is inserted after a standard rule set or other // at-rule. - ec = HIERARCHY_REQUEST_ERR; - return 0; + return Exception { HIERARCHY_REQUEST_ERR }; } CSSStyleSheet::RuleMutationScope mutationScope(this); @@ -95,15 +91,14 @@ unsigned CSSGroupingRule::insertRule(const String& ruleString, unsigned index, E return index; } -void CSSGroupingRule::deleteRule(unsigned index, ExceptionCode& ec) +ExceptionOr<void> CSSGroupingRule::deleteRule(unsigned index) { ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); if (index >= m_groupRule->childRules().size()) { // INDEX_SIZE_ERR: Raised if the specified index does not correspond to a // rule in the media rule list. - ec = INDEX_SIZE_ERR; - return; + return Exception { INDEX_SIZE_ERR }; } CSSStyleSheet::RuleMutationScope mutationScope(this); @@ -113,6 +108,8 @@ void CSSGroupingRule::deleteRule(unsigned index, ExceptionCode& ec) if (m_childRuleCSSOMWrappers[index]) m_childRuleCSSOMWrappers[index]->setParentRule(0); m_childRuleCSSOMWrappers.remove(index); + + return { }; } void CSSGroupingRule::appendCssTextForItems(StringBuilder& result) const @@ -133,7 +130,7 @@ unsigned CSSGroupingRule::length() const CSSRule* CSSGroupingRule::item(unsigned index) const { if (index >= length()) - return 0; + return nullptr; ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size()); RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index]; if (!rule) @@ -141,20 +138,19 @@ CSSRule* CSSGroupingRule::item(unsigned index) const return rule.get(); } -CSSRuleList* CSSGroupingRule::cssRules() const +CSSRuleList& CSSGroupingRule::cssRules() const { if (!m_ruleListCSSOMWrapper) - m_ruleListCSSOMWrapper = std::make_unique<LiveCSSRuleList<CSSGroupingRule>>(const_cast<CSSGroupingRule*>(this)); - return m_ruleListCSSOMWrapper.get(); + m_ruleListCSSOMWrapper = std::make_unique<LiveCSSRuleList<CSSGroupingRule>>(const_cast<CSSGroupingRule&>(*this)); + return *m_ruleListCSSOMWrapper; } -void CSSGroupingRule::reattach(StyleRuleBase* rule) +void CSSGroupingRule::reattach(StyleRuleBase& rule) { - ASSERT(rule); - m_groupRule = static_cast<StyleRuleGroup*>(rule); + m_groupRule = static_cast<StyleRuleGroup&>(rule); for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) { if (m_childRuleCSSOMWrappers[i]) - m_childRuleCSSOMWrappers[i]->reattach(m_groupRule->childRules()[i].get()); + m_childRuleCSSOMWrappers[i]->reattach(*m_groupRule.get().childRules()[i]); } } |