summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-01-07 12:30:21 +0000
committerGitHub <noreply@github.com>2020-01-07 12:30:21 +0000
commitc66b70c4da6877303d8951c10ce47dce0ff01366 (patch)
tree1b1284a85bf5ecfdbc134f75abd9c877f3fab01f
parente30d68b699bb3dca89534727974a08d4b43b62f8 (diff)
parentb4d686d62da679acabdbb7b30153a2971a200f79 (diff)
downloadUXP-c66b70c4da6877303d8951c10ce47dce0ff01366.tar
UXP-c66b70c4da6877303d8951c10ce47dce0ff01366.tar.gz
UXP-c66b70c4da6877303d8951c10ce47dce0ff01366.tar.lz
UXP-c66b70c4da6877303d8951c10ce47dce0ff01366.tar.xz
UXP-c66b70c4da6877303d8951c10ce47dce0ff01366.zip
Merge pull request #1346 from JustOff/PR_CSSStyleSheet_legacy
Issue #1345 - Implement non-standard legacy CSSStyleSheet rules
-rw-r--r--dom/webidl/CSSStyleSheet.webidl8
-rw-r--r--layout/style/StyleSheet.cpp26
-rw-r--r--layout/style/StyleSheet.h3
3 files changed, 37 insertions, 0 deletions
diff --git a/dom/webidl/CSSStyleSheet.webidl b/dom/webidl/CSSStyleSheet.webidl
index 15c110b8b..677d3ec52 100644
--- a/dom/webidl/CSSStyleSheet.webidl
+++ b/dom/webidl/CSSStyleSheet.webidl
@@ -26,4 +26,12 @@ interface CSSStyleSheet : StyleSheet {
unsigned long insertRule(DOMString rule, optional unsigned long index = 0);
[Throws, NeedsSubjectPrincipal]
void deleteRule(unsigned long index);
+
+ // Non-standard WebKit things, see https://github.com/w3c/csswg-drafts/pull/3900.
+ [Throws, NeedsSubjectPrincipal, BinaryName="cssRules"]
+ readonly attribute CSSRuleList rules;
+ [Throws, NeedsSubjectPrincipal, BinaryName="deleteRule"]
+ void removeRule(optional unsigned long index = 0);
+ [Throws, NeedsSubjectPrincipal]
+ long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index);
};
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<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 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<uint32_t>& aIndex,
+ nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv);
// WebIDL miscellaneous bits
inline dom::ParentObject GetParentObject() const;