diff --git a/dom/webidl/CSSStyleSheet.webidl b/dom/webidl/CSSStyleSheet.webidl index dc88888c3..4d7079fec 100644 --- a/dom/webidl/CSSStyleSheet.webidl +++ b/dom/webidl/CSSStyleSheet.webidl @@ -18,4 +18,12 @@ interface CSSStyleSheet : StyleSheet { unsigned long insertRule(DOMString rule, optional unsigned long index = 0); [Throws] void deleteRule(unsigned long index); + + // Non-standard WebKit things, see https://github.com/w3c/csswg-drafts/pull/3900. + [Throws, BinaryName="cssRules"] + readonly attribute CSSRuleList rules; + [Throws, BinaryName="deleteRule"] + void removeRule(optional unsigned long index = 0); + [Throws] + long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index); }; diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 0c3a99d4d..b8089ad9a 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -1918,6 +1918,40 @@ CSSStyleSheet::InsertRule(const nsAString& aRule, return InsertRuleInternal(aRule, aIndex, aReturn); } +/* TenFourFox issue 592 */ +int32_t +CSSStyleSheet::AddRule(const nsAString& aSelector, const nsAString& aBlock, + const Optional& aIndex, ErrorResult& aRv) +{ + uint32_t index; + if (aIndex.WasPassed()) { + index = aIndex.Value(); + } else { + CSSRuleList* collection = GetCssRules(aRv); + if (!collection) { + // Must have thrown. + return -1; + } + index = collection->Length(); + } + + nsAutoString rule; + rule.Append(aSelector); + rule.AppendLiteral(" { "); + if (!aBlock.IsEmpty()) { + rule.Append(aBlock); + rule.Append(' '); + } + rule.Append('}'); + + uint32_t retval; // unused + nsresult rv = InsertRuleInternal(rule, index, &retval); + if (NS_FAILED(rv)) aRv.Throw(rv); + + // As per Microsoft documentation, always return -1. + return -1; +} + static bool RuleHasPendingChildSheet(css::Rule *cssRule) { diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h index 6b670699a..f1fd6c7d3 100644 --- a/layout/style/CSSStyleSheet.h +++ b/layout/style/CSSStyleSheet.h @@ -320,6 +320,8 @@ public: void DeleteRule(uint32_t aIndex, ErrorResult& aRv) { aRv = DeleteRule(aIndex); } + int32_t AddRule(const nsAString& aSelector, const nsAString& aBlock, + const dom::Optional& aIndex, ErrorResult& aRv); // WebIDL miscellaneous bits dom::ParentObject GetParentObject() const {