summaryrefslogtreecommitdiff
path: root/layout
diff options
context:
space:
mode:
authorJustOff <Off.Just.Off@gmail.com>2020-01-07 13:05:05 +0200
committerJustOff <Off.Just.Off@gmail.com>2020-01-07 13:05:05 +0200
commitb05f89dcd4a88bcc07cc2fa4245362f705e8e2af (patch)
tree1b1284a85bf5ecfdbc134f75abd9c877f3fab01f /layout
parent26dc2759c50e230f8dee9ee676d1089171f33bc4 (diff)
downloaduxp-b05f89dcd4a88bcc07cc2fa4245362f705e8e2af.tar.gz
Issue mcp-graveyard/UXP#1345 - Implement non-standard legacy CSSStyleSheet rules
Diffstat (limited to 'layout')
-rw-r--r--layout/style/StyleSheet.cpp26
-rw-r--r--layout/style/StyleSheet.h3
2 files changed, 29 insertions, 0 deletions
diff --git a/layout/style/StyleSheet.cpp b/layout/style/StyleSheet.cpp
index 9ff90b8d2c..f307f39188 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<uint32_t>& 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 f21a6d648b..863f6d22fa 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<uint32_t>& aIndex,
+ nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
// WebIDL miscellaneous bits
inline dom::ParentObject GetParentObject() const;