#592: implement CSSStyleSheet rules and addRule

This commit is contained in:
Cameron Kaiser 2020-02-18 17:30:24 -08:00
parent bbc9a12a5d
commit 2eb5ba7f62
3 changed files with 44 additions and 0 deletions

View File

@ -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);
};

View File

@ -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<uint32_t>& 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)
{

View File

@ -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<uint32_t>& aIndex, ErrorResult& aRv);
// WebIDL miscellaneous bits
dom::ParentObject GetParentObject() const {