From b4d686d62da679acabdbb7b30153a2971a200f79 Mon Sep 17 00:00:00 2001 From: JustOff Date: Tue, 7 Jan 2020 13:05:05 +0200 Subject: Issue #1345 - Implement non-standard legacy CSSStyleSheet rules --- layout/style/StyleSheet.cpp | 26 ++++++++++++++++++++++++++ layout/style/StyleSheet.h | 3 +++ 2 files changed, 29 insertions(+) (limited to 'layout/style') diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp index 9ff90b8d2..f307f3918 100644 --- a/layout/style/StyleSheet.cpp +++ b/layout/style/StyleSheet.cpp @@ -259,6 +259,32 @@ StyleSheet::DeleteRule(uint32_t aIndex, FORWARD_INTERNAL(DeleteRuleInternal, (aIndex, aRv)) } +int32_t +StyleSheet::AddRule(const nsAString& aSelector, const nsAString& aBlock, + const Optional& aIndex, + nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) +{ + if (!AreRulesAvailable(aSubjectPrincipal, aRv)) { + return -1; + } + + nsAutoString rule; + rule.Append(aSelector); + rule.AppendLiteral(" { "); + if (!aBlock.IsEmpty()) { + rule.Append(aBlock); + rule.Append(' '); + } + rule.Append('}'); + + auto index = + aIndex.WasPassed() ? aIndex.Value() : GetCssRules(aSubjectPrincipal, aRv)->Length(); + + FORWARD_INTERNAL(InsertRuleInternal, (rule, index, aRv)); + // As per Microsoft documentation, always return -1. + return -1; +} + #undef FORWARD_INTERNAL void diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index f21a6d648..863f6d22f 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -143,6 +143,9 @@ public: void DeleteRule(uint32_t aIndex, nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); + int32_t AddRule(const nsAString& aSelector, const nsAString& aBlock, + const dom::Optional& aIndex, + nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); // WebIDL miscellaneous bits inline dom::ParentObject GetParentObject() const; -- cgit v1.2.3