From 73edd3878f7632c75eabbffd6e7b8c4dd8deea40 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 6 Apr 2024 14:08:41 +0200 Subject: [PATCH 01/22] Issue #2495 - Implement webkitURL legacy window alias for URL Resolves #2495 --- dom/url/URL.h | 8 ++++++++ dom/webidl/URL.webidl | 1 + 2 files changed, 9 insertions(+) diff --git a/dom/url/URL.h b/dom/url/URL.h index a0afd8b8b6..53164b7b95 100644 --- a/dom/url/URL.h +++ b/dom/url/URL.h @@ -55,6 +55,14 @@ public: Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv); + // Helper for window.URL constructor + static already_AddRefed + WebkitURL(const GlobalObject& aGlobal, const nsAString& aURL, + const Optional& aBase, ErrorResult& aRv) + { + return Constructor(aGlobal, aURL, aBase, aRv); + } + // Helper for Fetch API static already_AddRefed WorkerConstructor(const GlobalObject& aGlobal, const nsAString& aURL, diff --git a/dom/webidl/URL.webidl b/dom/webidl/URL.webidl index 4d491e1b36..a12635ce3f 100644 --- a/dom/webidl/URL.webidl +++ b/dom/webidl/URL.webidl @@ -15,6 +15,7 @@ // [Constructor(DOMString url, optional (URL or DOMString) base = "about:blank")] [Constructor(DOMString url, URL base), Constructor(DOMString url, optional DOMString base), + NamedConstructor=webkitURL(DOMString url, optional DOMString base), Exposed=(Window,Worker,WorkerDebugger)] interface URL { // Bug 824857: no support for stringifier attributes yet. From d6ec56a4c415bff80dcebcbfcee8be1872df6295 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Fri, 29 Mar 2024 18:18:36 +0100 Subject: [PATCH 02/22] Issue #2490 - Part 1: Make all CSS rules cycle-collected. --- dom/base/nsWrapperCache.h | 2 +- layout/style/CSSStyleSheet.cpp | 6 +- layout/style/Declaration.h | 2 + layout/style/GroupRule.h | 5 +- layout/style/ImportRule.h | 5 +- layout/style/NameSpaceRule.h | 3 +- layout/style/Rule.h | 9 ++ layout/style/StyleRule.cpp | 35 ++++- layout/style/StyleRule.h | 8 +- layout/style/nsCSSRules.cpp | 225 ++++++++++++++++++++++++--------- layout/style/nsCSSRules.h | 22 ++-- 11 files changed, 237 insertions(+), 85 deletions(-) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 8bdc1b93b6..ef67e91ddb 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -144,7 +144,7 @@ public: } } - bool PreservingWrapper() + bool PreservingWrapper() const { return HasWrapperFlag(WRAPPER_BIT_PRESERVED); } diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 5b8a9912fc..bca4820e2e 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -1238,8 +1238,10 @@ CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb) const nsCOMArray& rules = mInner->mOrderedRules; for (int32_t i = 0, count = rules.Count(); i < count; ++i) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mOrderedRules[i]"); - cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule()); + if (!rules[i]->IsCCLeaf()) { + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mOrderedRules[i]"); + cb.NoteXPCOMChild(rules[i]); + } } } diff --git a/layout/style/Declaration.h b/layout/style/Declaration.h index e7701e7380..f5b43439fd 100644 --- a/layout/style/Declaration.h +++ b/layout/style/Declaration.h @@ -96,6 +96,8 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_DECLARATION_IMPL_CID) + // If this ever becomes cycle-collected, please change the CC implementation + // for StyleRule to traverse it. NS_DECL_ISUPPORTS private: diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index ec781fae68..d9770dd1ec 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -38,8 +38,9 @@ protected: virtual ~GroupRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule) - NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule) + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; // implement part of Rule DECL_STYLE_RULE_INHERIT_NO_DOMRULE diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index f0803ba9d0..4db2bdf44d 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -34,8 +34,9 @@ private: ImportRule(const ImportRule& aCopy); ~ImportRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ImportRule, mozilla::css::Rule) - NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ImportRule, Rule) + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; DECL_STYLE_RULE_INHERIT diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 92d910cf5d..2165796071 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -37,7 +37,8 @@ private: public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_NAMESPACE_RULE_IMPL_CID) - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 7abe71174e..ac72297765 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -52,6 +52,12 @@ protected: public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS(Rule) + // Return true if this rule is known to be a cycle collection leaf, in the + // sense that it doesn't have any outgoing owning edges. + virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE; + #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; #endif @@ -124,6 +130,9 @@ public: const MOZ_MUST_OVERRIDE = 0; protected: + // True if we're known-live for cycle collection purposes. + bool IsKnownLive() const; + // This is sometimes null (e.g., for style attributes). CSSStyleSheet* mSheet; // When the parent GroupRule is destroyed, it will call SetParentRule(nullptr) diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 5c3ec354d5..df25a0c5c6 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1460,8 +1460,15 @@ StyleRule::StyleRule(const StyleRule& aCopy) StyleRule::~StyleRule() { delete mSelector; + DropReferences(); +} + +void +StyleRule::DropReferences() +{ if (mDOMRule) { mDOMRule->DOMDeclaration()->DropReference(); + mDOMRule = nullptr; } if (mDeclaration) { @@ -1470,18 +1477,36 @@ StyleRule::~StyleRule() } // QueryInterface implementation for StyleRule -NS_INTERFACE_MAP_BEGIN(StyleRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) if (aIID.Equals(NS_GET_IID(mozilla::css::StyleRule))) { *aInstancePtr = this; NS_ADDREF_THIS(); return NS_OK; } else - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) -NS_IMPL_ADDREF(StyleRule) -NS_IMPL_RELEASE(StyleRule) +NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) +NS_IMPL_RELEASE_INHERITED(StyleRule, Rule) + +NS_IMPL_CYCLE_COLLECTION_CLASS(StyleRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StyleRule, Rule) + tmp->DropReferences(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StyleRule, Rule) + // Keep this in sync with IsCCLeaf. + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +bool +StyleRule::IsCCLeaf() const +{ + if (!Rule::IsCCLeaf()) { + return false; + } + + return !mDOMRule || !mDOMRule->DOMDeclaration()->PreservingWrapper(); +} /* virtual */ int32_t StyleRule::GetType() const diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index f2af2717b5..ef21acc137 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -334,7 +334,9 @@ private: public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID) - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StyleRule, Rule) + virtual bool IsCCLeaf() const override; // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -366,6 +368,10 @@ public: private: ~StyleRule(); + // Drop our references to mDeclaration and mRule, and let them know we're + // doing that. + void DropReferences(); + private: nsCSSSelectorList* mSelector; // null for style attribute RefPtr mDeclaration; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1642516979..f2fd229167 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -37,6 +37,7 @@ #include "nsFont.h" #include "nsIURI.h" #include "mozAutoDocUpdate.h" +#include "nsCCUncollectableMarker.h" using namespace mozilla; using namespace mozilla::dom; @@ -55,6 +56,52 @@ IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) namespace mozilla { namespace css { +NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule) +NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTION_0(Rule) + +bool +Rule::IsCCLeaf() const +{ + return true; +} + +bool +Rule::IsKnownLive() const +{ + StyleSheet* sheet = GetStyleSheet(); + if (!sheet) { + return false; + } + + if (!sheet->IsOwnedByDocument()) { + return false; + } + + return nsCCUncollectableMarker::InGeneration( + sheet->GetAssociatedDocument()->GetMarkedCCGeneration()); +} + +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Rule) + return tmp->IsCCLeaf() || tmp->IsKnownLive(); +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END + +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(Rule) + // Note that we can't make use of IsKnownLive() here directly, because we may + // be subclassed by something that needs tracing. Once we have a wrapper + // cache we should be able to do better here. + return tmp->IsCCLeaf(); +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END + +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(Rule) + return tmp->IsCCLeaf() || tmp->IsKnownLive(); +NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END + /* virtual */ void Rule::SetStyleSheet(CSSStyleSheet* aSheet) { @@ -199,16 +246,22 @@ ImportRule::~ImportRule() } } -NS_IMPL_CYCLE_COLLECTING_ADDREF(ImportRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(ImportRule) +NS_IMPL_ADDREF_INHERITED(ImportRule, Rule) +NS_IMPL_RELEASE_INHERITED(ImportRule, Rule) + +bool +ImportRule::IsCCLeaf() const +{ + // We're not a leaf. + return false; +} // QueryInterface implementation for ImportRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ImportRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) IMPL_STYLE_RULE_INHERIT(ImportRule, Rule) @@ -393,11 +446,18 @@ GroupRule::~GroupRule() } } -NS_IMPL_CYCLE_COLLECTING_ADDREF(GroupRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(GroupRule) +NS_IMPL_ADDREF_INHERITED(GroupRule, Rule) +NS_IMPL_RELEASE_INHERITED(GroupRule, Rule) -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(Rule) + +bool +GroupRule::IsCCLeaf() const +{ + // Let's not worry for now about sorting out whether we're a leaf or not. + return false; +} static bool SetStyleSheetReference(Rule* aRule, void* aSheet) @@ -409,7 +469,7 @@ SetStyleSheetReference(Rule* aRule, void* aSheet) NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule) tmp->mRules.EnumerateForwards(SetParentRuleReference, nullptr); // If tmp does not have a stylesheet, neither do its descendants. In that // case, don't try to null out their stylesheet, to avoid O(N^2) behavior in @@ -427,11 +487,13 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule) } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(GroupRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule) const nsCOMArray& rules = tmp->mRules; for (int32_t i = 0, count = rules.Count(); i < count; ++i) { - NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); - cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule()); + if (!rules[i]->IsCCLeaf()) { + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]"); + cb.NoteXPCOMChild(rules[i]); + } } NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -624,22 +686,11 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) -NS_IMPL_CYCLE_COLLECTION_CLASS(MediaRule) - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(MediaRule, GroupRule) - if (tmp->mMedia) { - tmp->mMedia->SetStyleSheet(nullptr); - tmp->mMedia = nullptr; - } -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaRule, GroupRule) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMedia) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, GroupRule, + mMedia) /* virtual */ void MediaRule::SetStyleSheet(CSSStyleSheet* aSheet) @@ -1110,10 +1161,12 @@ NameSpaceRule::~NameSpaceRule() { } -NS_IMPL_ADDREF(NameSpaceRule) -NS_IMPL_RELEASE(NameSpaceRule) +NS_IMPL_ADDREF_INHERITED(NameSpaceRule, Rule) +NS_IMPL_RELEASE_INHERITED(NameSpaceRule, Rule) // QueryInterface implementation for NameSpaceRule +// If this ever gets its own cycle-collection bits, reevaluate our IsCCLeaf +// implementation. NS_INTERFACE_MAP_BEGIN(NameSpaceRule) if (aIID.Equals(NS_GET_IID(css::NameSpaceRule))) { *aInstancePtr = this; @@ -1122,9 +1175,14 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) } else NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) + +bool +NameSpaceRule::IsCCLeaf() const +{ + return Rule::IsCCLeaf(); +} IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule) @@ -1539,35 +1597,52 @@ nsCSSFontFaceRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSFontFaceRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSFontFaceRule) +NS_IMPL_ADDREF_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSFontFaceRule) -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) + // Keep this in sync with IsCCLeaf. + // Trace the wrapper for our declaration. This just expands out // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecl.TraceWrapper(aCallbacks, aClosure); NS_IMPL_CYCLE_COLLECTION_TRACE_END -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) + // Keep this in sync with IsCCLeaf. + // Unlink the wrapper for our declaraton. This just expands out // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use // directly because the wrapper is on the declaration, not on us. tmp->mDecl.ReleaseWrapper(static_cast(p)); NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSFontFaceRule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSFontFaceRule, + mozilla::css::Rule) + // Keep this in sync with IsCCLeaf. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +bool +nsCSSFontFaceRule::IsCCLeaf() const +{ + if (!Rule::IsCCLeaf()) { + return false; + } + + return !mDecl.PreservingWrapper(); +} + // QueryInterface implementation for nsCSSFontFaceRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSFontFaceRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(Rule) IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule) @@ -1702,16 +1777,23 @@ nsCSSFontFeatureValuesRule::Clone() const return clone.forget(); } -NS_IMPL_ADDREF(nsCSSFontFeatureValuesRule) -NS_IMPL_RELEASE(nsCSSFontFeatureValuesRule) +NS_IMPL_ADDREF_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSFontFeatureValuesRule +// If this ever gets its own cycle-collection bits, reevaluate our IsCCLeaf +// implementation. NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) + +bool +nsCSSFontFeatureValuesRule::IsCCLeaf() const +{ + return Rule::IsCCLeaf(); +} IMPL_STYLE_RULE_INHERIT(nsCSSFontFeatureValuesRule, Rule) @@ -2037,28 +2119,35 @@ nsCSSKeyframeRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeRule) +NS_IMPL_ADDREF_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSKeyframeRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSKeyframeRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) if (tmp->mDOMDeclaration) { tmp->mDOMDeclaration->DropReference(); tmp->mDOMDeclaration = nullptr; } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSKeyframeRule) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +bool +nsCSSKeyframeRule::IsCCLeaf() const +{ + // Let's not worry about figuring out whether we're a leaf or not. + return false; +} + // QueryInterface implementation for nsCSSKeyframeRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule) @@ -2263,7 +2352,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2594,28 +2682,35 @@ nsCSSPageRule::Clone() const return clone.forget(); } -NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSPageRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSPageRule) +NS_IMPL_ADDREF_INHERITED(nsCSSPageRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSPageRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(nsCSSPageRule) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSPageRule) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsCSSPageRule, mozilla::css::Rule) if (tmp->mDOMDeclaration) { tmp->mDOMDeclaration->DropReference(); tmp->mDOMDeclaration = nullptr; } NS_IMPL_CYCLE_COLLECTION_UNLINK_END -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSPageRule) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsCSSPageRule, mozilla::css::Rule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +bool +nsCSSPageRule::IsCCLeaf() const +{ + // Let's not worry about figuring out whether we're a leaf or not. + return false; +} + // QueryInterface implementation for nsCSSPageRule -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSPageRule) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule) @@ -2786,7 +2881,6 @@ NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2907,16 +3001,23 @@ nsCSSCounterStyleRule::kGetters[] = { #undef CSS_COUNTER_DESC }; -NS_IMPL_ADDREF(nsCSSCounterStyleRule) -NS_IMPL_RELEASE(nsCSSCounterStyleRule) +NS_IMPL_ADDREF_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) +NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // QueryInterface implementation for nsCSSCounterStyleRule +// If this ever gets its own cycle-collection bits, reevaluate our IsCCLeaf +// implementation. NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) -NS_INTERFACE_MAP_END +NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) + +bool +nsCSSCounterStyleRule::IsCCLeaf() const +{ + return Rule::IsCCLeaf(); +} IMPL_STYLE_RULE_INHERIT(nsCSSCounterStyleRule, css::Rule) diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 9c3196575c..0482603b26 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -248,9 +248,9 @@ public: // copy everything except our reference count : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {} - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSFontFaceRule, - mozilla::css::Rule) + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT @@ -315,7 +315,8 @@ public: mFamilyList(aCopy.mFamilyList), mFeatureValues(aCopy.mFeatureValues) {} - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT @@ -398,8 +399,9 @@ private: nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy); ~nsCSSKeyframeRule(); public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSKeyframeRule, mozilla::css::Rule) + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT @@ -526,8 +528,9 @@ private: nsCSSPageRule(const nsCSSPageRule& aCopy); ~nsCSSPageRule(); public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSPageRule, nsIDOMCSSPageRule) + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::css::Rule) + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT @@ -623,7 +626,8 @@ private: ~nsCSSCounterStyleRule(); public: - NS_DECL_ISUPPORTS + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; // Rule methods DECL_STYLE_RULE_INHERIT From 5bb39ec403dc26630324267238784853ac5f3e3f Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 11:27:48 +0100 Subject: [PATCH 03/22] Issue #2490 - Part 2: Remove the now-unused GetExistingDOMRule() function. --- layout/style/Rule.h | 6 +----- layout/style/StyleRule.cpp | 6 ------ layout/style/StyleRule.h | 2 -- layout/style/nsCSSRules.cpp | 3 --- layout/style/nsCSSRules.h | 16 ---------------- 5 files changed, 1 insertion(+), 32 deletions(-) diff --git a/layout/style/Rule.h b/layout/style/Rule.h index ac72297765..f3a529be5a 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -27,8 +27,7 @@ class GroupRule; #define DECL_STYLE_RULE_INHERIT \ DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - virtual nsIDOMCSSRule* GetDOMRule() override; \ - virtual nsIDOMCSSRule* GetExistingDOMRule() override; + virtual nsIDOMCSSRule* GetDOMRule() override; class Rule : public nsISupports { protected: @@ -116,9 +115,6 @@ public: // supposed to have a DOM rule representation (and our code wouldn't work). virtual nsIDOMCSSRule* GetDOMRule() = 0; - // Like GetDOMRule(), but won't create one if we don't have one yet - virtual nsIDOMCSSRule* GetExistingDOMRule() = 0; - // to implement methods on nsIDOMCSSRule nsresult GetParentRule(nsIDOMCSSRule** aParentRule); nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index df25a0c5c6..0599f3045b 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1536,12 +1536,6 @@ StyleRule::GetDOMRule() return mDOMRule; } -/* virtual */ nsIDOMCSSRule* -StyleRule::GetExistingDOMRule() -{ - return mDOMRule; -} - void StyleRule::SetDeclaration(Declaration* aDecl) { diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index ef21acc137..02879816da 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -357,8 +357,6 @@ public: virtual nsIDOMCSSRule* GetDOMRule() override; - virtual nsIDOMCSSRule* GetExistingDOMRule() override; - #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index f2fd229167..2559fd99b8 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -44,8 +44,6 @@ using namespace mozilla::dom; #define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \ /* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \ - { return this; } \ - /* virtual */ nsIDOMCSSRule* class_::GetExistingDOMRule() \ { return this; } #define IMPL_STYLE_RULE_INHERIT(class_, super_) \ @@ -905,7 +903,6 @@ NS_INTERFACE_MAP_BEGIN(DocumentRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, mozilla::css::Rule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 0482603b26..aa544efb1b 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -70,10 +70,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -125,10 +121,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -459,10 +451,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE @@ -579,10 +567,6 @@ public: { return this; } - virtual nsIDOMCSSRule* GetExistingDOMRule() override - { - return this; - } NS_DECL_ISUPPORTS_INHERITED From e510cc84afadad6708f418d8d045d9af5fea2e6b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 11:38:44 +0100 Subject: [PATCH 04/22] Issue #2490 - Part 3: Give CSS rules a PreCreate hook so we can safely wrappercache them. --- dom/base/nsDOMClassInfo.cpp | 77 +++++++++++++++++++++++++++++-------- dom/base/nsDOMClassInfo.h | 23 +++++++++++ 2 files changed, 84 insertions(+), 16 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 34e6b82476..bcba7bb66d 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -189,14 +189,18 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) + NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsCSSRuleSH, + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) // XUL classes #ifdef MOZ_XUL @@ -221,13 +225,16 @@ static nsDOMClassInfoData sClassInfoData[] = { #endif NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, nsMessageManagerSH, @@ -246,18 +253,23 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSKeyframeRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS) + DOM_DEFAULT_SCRIPTABLE_FLAGS | + nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) @@ -1982,6 +1994,39 @@ nsEventTargetSH::PreserveWrapper(nsISupports *aNative) target->PreserveWrapper(aNative); } +// CSS rule helper +NS_IMETHODIMP +nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, + JSObject *aGlobalObj, JSObject **parentObj) +{ + JS::Rooted globalObj(cx, aGlobalObj); + nsCOMPtr rule = do_QueryInterface(nativeObj); + if (!rule) { + return NS_ERROR_UNEXPECTED; + } + css::Rule* cssRule = rule->GetCSSRule(); + if (!cssRule) { + // A DOMCSSStyleRule whose actual underlying rule has gone away. There + // isn't much a caller can do with this thing anyway, and only chrome code + // can get its hands on it to start with, so just wrap in the current + // global. + *parentObj = globalObj; + return NS_OK; + } + nsIDocument* doc = cssRule->GetDocument(); + if (!doc) { + *parentObj = globalObj; + return NS_OK; + } + + nsIGlobalObject* global = doc->GetScopeObject(); + if (!global) { + return NS_ERROR_UNEXPECTED; + } + *parentObj = global->GetGlobalJSObject(); + return *parentObj ? NS_OK : NS_ERROR_FAILURE; +} + // nsIDOMEventListener::HandleEvent() 'this' converter helper NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator) diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 48f4966f0f..0d70b040bc 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -172,6 +172,29 @@ public: } }; + +// Makes sure that we always create our wrapper in the right global, so we won't +// cache one from the wrong global. +class nsCSSRuleSH : public nsDOMGenericSH +{ +protected: + explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData) + { + } + + virtual ~nsCSSRuleSH() + { + } +public: + NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, + JSObject *globalObj, JSObject **parentObj) override; + + static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) + { + return new nsCSSRuleSH(aData); + } +}; + // A place to hang some static methods that we should really consider // moving to be nsGlobalWindow member methods. See bug 1062418. class nsWindowSH From 1342838b3f650552c61a4747b97cdcdb479a7aa1 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 12:39:15 +0100 Subject: [PATCH 05/22] Issue #2490 - Part 4: Make css::Rule wrappercached. --- dom/base/nsWrapperCache.h | 32 ++++++++- dom/base/nsWrapperCacheInlines.h | 2 +- layout/style/ImportRule.h | 2 + layout/style/NameSpaceRule.h | 2 + layout/style/Rule.h | 7 +- layout/style/StyleRule.cpp | 8 +++ layout/style/StyleRule.h | 2 + layout/style/nsCSSRules.cpp | 116 +++++++++++++++++++++++++++++-- layout/style/nsCSSRules.h | 55 ++++++++++++--- 9 files changed, 208 insertions(+), 18 deletions(-) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index ef67e91ddb..772c20bbc0 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -18,10 +18,24 @@ namespace dom { class TabChildGlobal; class ProcessGlobal; } // namespace dom +namespace css { +class ImportRule; +class NameSpaceRule; +class StyleRule; +class MediaRule; +class DocumentRule; +} // namespace css +class CSSSupportsRule; } // namespace mozilla class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; +class nsCSSFontFaceRule; +class nsCSSFontFeatureValuesRule; +class nsCSSKeyframeRule; +class nsCSSKeyframesRule; +class nsCSSPageRule; +class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ { 0x6f3179a1, 0x36f7, 0x4a5c, \ @@ -163,7 +177,7 @@ public: /** * Returns true if the object has a non-gray wrapper. */ - bool IsBlack(); + bool IsBlack() const; /** * Returns true if the object has a black wrapper, @@ -271,11 +285,27 @@ protected: } private: + // Friend declarations for things that need to be able to call + // SetIsNotDOMBinding(). The goal is to get rid of all of these, and + // SetIsNotDOMBinding() too. friend class mozilla::dom::TabChildGlobal; friend class mozilla::dom::ProcessGlobal; friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; + friend class mozilla::css::ImportRule; + friend class mozilla::css::NameSpaceRule; + friend class mozilla::css::StyleRule; + friend class mozilla::css::MediaRule; + friend class mozilla::css::DocumentRule; + friend class mozilla::CSSSupportsRule; + friend class nsCSSFontFaceRule; + friend class nsCSSFontFeatureValuesRule; + friend class nsCSSKeyframeRule; + friend class nsCSSKeyframesRule; + friend class nsCSSPageRule; + friend class nsCSSCounterStyleRule; + void SetIsNotDOMBinding() { MOZ_ASSERT(!mWrapper && !(GetWrapperFlags() & ~WRAPPER_IS_NOT_DOM_BINDING), diff --git a/dom/base/nsWrapperCacheInlines.h b/dom/base/nsWrapperCacheInlines.h index 2576c02ecd..d9b0ff6b8d 100644 --- a/dom/base/nsWrapperCacheInlines.h +++ b/dom/base/nsWrapperCacheInlines.h @@ -21,7 +21,7 @@ nsWrapperCache::GetWrapper() const } inline bool -nsWrapperCache::IsBlack() +nsWrapperCache::IsBlack() const { JSObject* o = GetWrapperPreserveColor(); return o && !JS::ObjectIsMarkedGray(o); diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 4db2bdf44d..64c9aa301c 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -55,6 +55,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 2165796071..5725a017e9 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -55,6 +55,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + // nsIDOMCSSRule interface NS_DECL_NSIDOMCSSRULE diff --git a/layout/style/Rule.h b/layout/style/Rule.h index f3a529be5a..ccf44767c3 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -12,6 +12,7 @@ #include "mozilla/MemoryReporting.h" #include "nsISupports.h" #include "nsIDOMCSSRule.h" +#include "nsWrapperCache.h" class nsIDocument; struct nsRuleData; @@ -29,7 +30,9 @@ class GroupRule; DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ virtual nsIDOMCSSRule* GetDOMRule() override; -class Rule : public nsISupports { +class Rule : public nsISupports + , public nsWrapperCache +{ protected: Rule(uint32_t aLineNumber, uint32_t aColumnNumber) : mSheet(nullptr), @@ -52,7 +55,7 @@ protected: public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_CLASS(Rule) + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Rule) // Return true if this rule is known to be a cycle collection leaf, in the // sense that it doesn't have any outgoing owning edges. virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE; diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 0599f3045b..3b35c2da17 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1442,6 +1442,7 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, mSelector(aSelector), mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); NS_PRECONDITION(aDeclaration, "must have a declaration"); mDeclaration->SetOwningRule(this); @@ -1453,6 +1454,7 @@ StyleRule::StyleRule(const StyleRule& aCopy) mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr), mDeclaration(new Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); // rest is constructed lazily on existing data } @@ -1680,6 +1682,12 @@ StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +StyleRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} } // namespace css } // namespace mozilla diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 02879816da..11e05692fa 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -363,6 +363,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + private: ~StyleRule(); diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 2559fd99b8..1c0312339d 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -38,6 +38,7 @@ #include "nsIURI.h" #include "mozAutoDocUpdate.h" #include "nsCCUncollectableMarker.h" +#include "nsWrapperCacheInlines.h" using namespace mozilla; using namespace mozilla::dom; @@ -58,20 +59,25 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(Rule) NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -NS_IMPL_CYCLE_COLLECTION_0(Rule) +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(Rule) bool Rule::IsCCLeaf() const { - return true; + return !PreservingWrapper(); } bool Rule::IsKnownLive() const { + if (IsBlack()) { + return true; + } + StyleSheet* sheet = GetStyleSheet(); if (!sheet) { return false; @@ -90,10 +96,10 @@ NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Rule) NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(Rule) - // Note that we can't make use of IsKnownLive() here directly, because we may - // be subclassed by something that needs tracing. Once we have a wrapper - // cache we should be able to do better here. - return tmp->IsCCLeaf(); + // Please see documentation for nsCycleCollectionParticipant::CanSkip* for why + // we need to check HasNothingToTrace here but not in the other two CanSkip + // methods. + return tmp->IsCCLeaf() || (tmp->IsKnownLive() && tmp->HasNothingToTrace(tmp)); NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(Rule) @@ -217,6 +223,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { + SetIsNotDOMBinding(); // XXXbz This is really silly.... the mMedia here will be replaced // with itself if we manage to load a sheet. Which should really // never fail nowadays, in sane cases. @@ -226,6 +233,7 @@ ImportRule::ImportRule(const ImportRule& aCopy) : Rule(aCopy), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); // Whether or not an @import rule has a null sheet is a permanent // property of that @import rule, since it is null only if the target // sheet failed security checks. @@ -415,6 +423,14 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mChildSheet, because it is measured via CSSStyleSheetInner::mSheets } +/* virtual */ JSObject* +ImportRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) : Rule(aLineNumber, aColumnNumber) { @@ -656,11 +672,13 @@ GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } MediaRule::MediaRule(const MediaRule& aCopy) : GroupRule(aCopy) { + SetIsNotDOMBinding(); if (aCopy.mMedia) { mMedia = aCopy.mMedia->Clone(); // XXXldb This doesn't really make sense. @@ -869,6 +887,13 @@ MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +MediaRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void MediaRule::AppendConditionText(nsAString& aOutput) { @@ -882,12 +907,14 @@ MediaRule::AppendConditionText(nsAString& aOutput) DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber) : GroupRule(aLineNumber, aColumnNumber) { + SetIsNotDOMBinding(); } DocumentRule::DocumentRule(const DocumentRule& aCopy) : GroupRule(aCopy) , mURLs(new URL(*aCopy.mURLs)) { + SetIsNotDOMBinding(); } DocumentRule::~DocumentRule() @@ -1110,6 +1137,14 @@ DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +DocumentRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + void DocumentRule::AppendConditionText(nsAString& aCssText) { @@ -1145,6 +1180,7 @@ NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, mPrefix(aPrefix), mURLSpec(aURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) @@ -1152,6 +1188,7 @@ NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) mPrefix(aCopy.mPrefix), mURLSpec(aCopy.mURLSpec) { + SetIsNotDOMBinding(); } NameSpaceRule::~NameSpaceRule() @@ -1277,6 +1314,13 @@ NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mURLSpec } +/* virtual */ JSObject* +NameSpaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} } // namespace css } // namespace mozilla @@ -1762,6 +1806,13 @@ nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDecl } +/* virtual */ JSObject* +nsCSSFontFaceRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ----------------------------------- // nsCSSFontFeatureValuesRule @@ -2009,6 +2060,14 @@ nsCSSFontFeatureValuesRule::SizeOfIncludingThis( return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSFontFeatureValuesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSKeyframeStyleDeclaration // @@ -2098,6 +2157,7 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy) , mKeys(aCopy.mKeys) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2317,6 +2377,13 @@ nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const // - mDOMDeclaration } +/* virtual */ JSObject* +nsCSSKeyframeRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} // ------------------------------------------- // nsCSSKeyframesRule @@ -2329,6 +2396,7 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy) : GroupRule(aCopy), mName(aCopy.mName) { + SetIsNotDOMBinding(); } nsCSSKeyframesRule::~nsCSSKeyframesRule() @@ -2573,6 +2641,14 @@ nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +nsCSSKeyframesRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + // ------------------------------------------- // nsCSSPageStyleDeclaration // @@ -2661,6 +2737,7 @@ nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy) : Rule(aCopy) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2809,6 +2886,14 @@ nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return aMallocSizeOf(this); } +/* virtual */ JSObject* +nsCSSPageRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + namespace mozilla { CSSSupportsRule::CSSSupportsRule(bool aConditionMet, @@ -2818,6 +2903,7 @@ CSSSupportsRule::CSSSupportsRule(bool aConditionMet, , mUseGroup(aConditionMet) , mCondition(aCondition) { + SetIsNotDOMBinding(); } CSSSupportsRule::~CSSSupportsRule() @@ -2829,6 +2915,7 @@ CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy) mUseGroup(aCopy.mUseGroup), mCondition(aCopy.mCondition) { + SetIsNotDOMBinding(); } #ifdef DEBUG @@ -2964,6 +3051,14 @@ CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const return n; } +/* virtual */ JSObject* +CSSSupportsRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} + } // namespace mozilla // ------------------------------------------- @@ -2975,6 +3070,7 @@ nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy) , mName(aCopy.mName) , mGeneration(aCopy.mGeneration) { + SetIsNotDOMBinding(); for (size_t i = 0; i < ArrayLength(mValues); ++i) { mValues[i] = aCopy.mValues[i]; } @@ -3434,3 +3530,11 @@ nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { return aMallocSizeOf(this); } + +/* virtual */ JSObject* +nsCSSCounterStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); + return nullptr; +} diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index aa544efb1b..628cd07a92 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -93,6 +93,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -167,6 +170,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + protected: void AppendConditionText(nsAString& aOutput); @@ -234,11 +240,18 @@ class nsCSSFontFaceRule final : public mozilla::css::Rule, { public: nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy) // copy everything except our reference count - : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {} + : mozilla::css::Rule(aCopy) + , mDecl(aCopy.mDecl) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) @@ -263,6 +276,9 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + void GetDescriptors(mozilla::CSSFontFaceDescriptors& aDescriptors) const { aDescriptors = mDecl.mDescriptors; } @@ -299,13 +315,19 @@ class nsCSSFontFeatureValuesRule final : public mozilla::css::Rule, { public: nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : mozilla::css::Rule(aLineNumber, aColumnNumber) {} + : mozilla::css::Rule(aLineNumber, aColumnNumber) + { + SetIsNotDOMBinding(); + } nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy) // copy everything except our reference count - : mozilla::css::Rule(aCopy), - mFamilyList(aCopy.mFamilyList), - mFeatureValues(aCopy.mFeatureValues) {} + : mozilla::css::Rule(aCopy) + , mFamilyList(aCopy.mFamilyList) + , mFeatureValues(aCopy.mFeatureValues) + { + SetIsNotDOMBinding(); + } NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; @@ -337,6 +359,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + protected: ~nsCSSFontFeatureValuesRule() {} @@ -385,6 +409,7 @@ public: , mKeys(mozilla::Move(aKeys)) , mDeclaration(mozilla::Move(aDeclaration)) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -416,6 +441,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + void DoGetKeyText(nsAString &aKeyText) const; private: @@ -434,6 +461,7 @@ public: : mozilla::css::GroupRule(aLineNumber, aColumnNumber) , mName(aName) { + SetIsNotDOMBinding(); } private: nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy); @@ -466,6 +494,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + private: uint32_t FindRuleIndexForKey(const nsAString& aKey); @@ -510,6 +540,7 @@ public: : mozilla::css::Rule(aLineNumber, aColumnNumber) , mDeclaration(aDeclaration) { + SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -539,6 +570,9 @@ public: void ChangeDeclaration(mozilla::css::Declaration* aDeclaration); virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + private: RefPtr mDeclaration; // lazily created when needed: @@ -547,8 +581,8 @@ private: namespace mozilla { -class CSSSupportsRule : public css::GroupRule, - public nsIDOMCSSSupportsRule +class CSSSupportsRule final : public css::GroupRule, + public nsIDOMCSSSupportsRule { public: CSSSupportsRule(bool aConditionMet, const nsString& aCondition, @@ -584,6 +618,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + protected: virtual ~CSSSupportsRule(); @@ -603,6 +639,7 @@ public: , mName(aName) , mGeneration(0) { + SetIsNotDOMBinding(); } private: @@ -651,6 +688,8 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + private: typedef NS_STDCALL_FUNCPROTO(nsresult, Getter, nsCSSCounterStyleRule, GetSymbols, (nsAString&)); From c2ee755574a01c9b61e0f03113c6e2f72f86f91b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 13:34:31 +0100 Subject: [PATCH 06/22] Issue #2490 - Part 5: Get rid of DOMCSSStyleRule. --- layout/style/StyleRule.cpp | 285 +++++++++---------------------------- layout/style/StyleRule.h | 24 ++-- 2 files changed, 82 insertions(+), 227 deletions(-) diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 3b35c2da17..c6c63c3e37 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -19,7 +19,6 @@ #include "nsIAtom.h" #include "nsString.h" #include "nsStyleUtil.h" -#include "nsICSSStyleRuleDOMWrapper.h" #include "nsDOMCSSDeclaration.h" #include "nsNameSpaceManager.h" #include "nsXMLNameSpaceMap.h" @@ -1096,30 +1095,26 @@ nsCSSSelectorList::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) cons // -------------------------------------------------------- -namespace mozilla { -namespace css { -class DOMCSSStyleRule; -} // namespace css -} // namespace mozilla - class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration { protected: + // Needs to be protected so we can use NS_IMPL_ADDREF_USING_AGGREGATOR. virtual ~DOMCSSDeclarationImpl(void); + // But we need to allow UniquePtr to delete us. + friend class mozilla::DefaultDelete; + public: explicit DOMCSSDeclarationImpl(css::StyleRule *aRule); NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override; - void DropReference(void); virtual css::Declaration* GetCSSDeclaration(Operation aOperation) override; virtual nsresult SetCSSDeclaration(css::Declaration* aDecl) override; virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override; virtual nsIDocument* DocToUpdate() override; - // Override |AddRef| and |Release| for being a member of - // |DOMCSSStyleRule|. Also, we need to forward QI for cycle - // collection things to DOMCSSStyleRule. + // Override |AddRef| and |Release| for being owned by StyleRule. Also, we + // need to forward QI for cycle collection things to StyleRule. NS_DECL_ISUPPORTS_INHERITED virtual nsINode *GetParentObject() override @@ -1137,55 +1132,12 @@ public: return document ? document->GetDocGroup() : nullptr; } - friend class css::DOMCSSStyleRule; - protected: - // This reference is not reference-counted. The rule object tells us - // when it's about to go away. + // This reference is not reference-counted. The rule object owns us and we go + // away when it does. css::StyleRule *mRule; - - inline css::DOMCSSStyleRule* DomRule(); - -private: - // NOT TO BE IMPLEMENTED - // This object cannot be allocated on its own. It must be a member of - // DOMCSSStyleRule. - void* operator new(size_t size) CPP_THROW_NEW; }; -namespace mozilla { -namespace css { - -class DOMCSSStyleRule : public nsICSSStyleRuleDOMWrapper -{ -public: - explicit DOMCSSStyleRule(StyleRule *aRule); - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(DOMCSSStyleRule) - NS_DECL_NSIDOMCSSRULE - NS_DECL_NSIDOMCSSSTYLERULE - - // nsICSSStyleRuleDOMWrapper - NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; - - DOMCSSDeclarationImpl* DOMDeclaration() { return &mDOMDeclaration; } - - friend class ::DOMCSSDeclarationImpl; - -protected: - virtual ~DOMCSSStyleRule(); - - DOMCSSDeclarationImpl mDOMDeclaration; - - StyleRule* Rule() { - return mDOMDeclaration.mRule; - } -}; - -} // namespace css -} // namespace mozilla - DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *aRule) : mRule(aRule) { @@ -1194,52 +1146,33 @@ DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(css::StyleRule *aRule) DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl(void) { - NS_ASSERTION(!mRule, "DropReference not called."); - MOZ_COUNT_DTOR(DOMCSSDeclarationImpl); } -inline css::DOMCSSStyleRule* DOMCSSDeclarationImpl::DomRule() -{ - return reinterpret_cast - (reinterpret_cast(this) - - offsetof(css::DOMCSSStyleRule, mDOMDeclaration)); -} - -NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule()) -NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, DomRule()) +NS_IMPL_ADDREF_USING_AGGREGATOR(DOMCSSDeclarationImpl, mRule) +NS_IMPL_RELEASE_USING_AGGREGATOR(DOMCSSDeclarationImpl, mRule) NS_INTERFACE_MAP_BEGIN(DOMCSSDeclarationImpl) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY - // We forward the cycle collection interfaces to DomRule(), which is - // never null (in fact, we're part of that object!) + // We forward the cycle collection interfaces to mRule, which is + // never null. if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { - return DomRule()->QueryInterface(aIID, aInstancePtr); + return mRule->QueryInterface(aIID, aInstancePtr); } else NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration) -void -DOMCSSDeclarationImpl::DropReference(void) -{ - mRule = nullptr; -} - css::Declaration* DOMCSSDeclarationImpl::GetCSSDeclaration(Operation aOperation) { - if (mRule) { - if (aOperation != eOperation_Read) { - RefPtr sheet = mRule->GetStyleSheet(); - if (sheet) { - sheet->WillDirty(); - } + if (aOperation != eOperation_Read) { + RefPtr sheet = mRule->GetStyleSheet(); + if (sheet) { + sheet->WillDirty(); } - return mRule->GetDeclaration(); - } else { - return nullptr; } + return mRule->GetDeclaration(); } void @@ -1253,11 +1186,6 @@ DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent) { NS_ENSURE_ARG_POINTER(aParent); - if (!mRule) { - *aParent = nullptr; - return NS_OK; - } - NS_IF_ADDREF(*aParent = mRule->GetDOMRule()); return NS_OK; } @@ -1294,50 +1222,13 @@ DOMCSSDeclarationImpl::DocToUpdate() return nullptr; } +// -- StyleRule ------------------------------------ + namespace mozilla { namespace css { -DOMCSSStyleRule::DOMCSSStyleRule(StyleRule* aRule) - : mDOMDeclaration(aRule) -{ -} - -DOMCSSStyleRule::~DOMCSSStyleRule() -{ -} - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) - NS_INTERFACE_MAP_ENTRY(nsISupports) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) -NS_INTERFACE_MAP_END - -NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMCSSStyleRule) -NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMCSSStyleRule) - -NS_IMPL_CYCLE_COLLECTION_CLASS(DOMCSSStyleRule) - -NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMCSSStyleRule) - // Trace the wrapper for our declaration. This just expands out - // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->DOMDeclaration()->TraceWrapper(aCallbacks, aClosure); -NS_IMPL_CYCLE_COLLECTION_TRACE_END - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMCSSStyleRule) - // Unlink the wrapper for our declaraton. This just expands out - // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use - // directly because the wrapper is on the declaration, not on us. - tmp->DOMDeclaration()->ReleaseWrapper(static_cast(p)); -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMCSSStyleRule) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - NS_IMETHODIMP -DOMCSSStyleRule::GetType(uint16_t* aType) +StyleRule::GetType(uint16_t* aType) { *aType = nsIDOMCSSRule::STYLE_RULE; @@ -1345,95 +1236,42 @@ DOMCSSStyleRule::GetType(uint16_t* aType) } NS_IMETHODIMP -DOMCSSStyleRule::GetCssText(nsAString& aCssText) +StyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) { - if (!Rule()) { - aCssText.Truncate(); - } else { - Rule()->GetCssText(aCssText); - } - return NS_OK; + return Rule::GetParentStyleSheet(aSheet); } NS_IMETHODIMP -DOMCSSStyleRule::SetCssText(const nsAString& aCssText) +StyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) { - if (Rule()) { - Rule()->SetCssText(aCssText); - } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - if (!Rule()) { - *aSheet = nullptr; - return NS_OK; - } - return Rule()->GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - if (!Rule()) { - *aParentRule = nullptr; - return NS_OK; - } - return Rule()->GetParentRule(aParentRule); + return Rule::GetParentRule(aParentRule); } css::Rule* -DOMCSSStyleRule::GetCSSRule() +StyleRule::GetCSSRule() { - return Rule(); + return this; } NS_IMETHODIMP -DOMCSSStyleRule::GetSelectorText(nsAString& aSelectorText) +StyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { - if (!Rule()) { - aSelectorText.Truncate(); - } else { - Rule()->GetSelectorText(aSelectorText); + if (!mDOMDeclaration) { + mDOMDeclaration.reset(new DOMCSSDeclarationImpl(this)); } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::SetSelectorText(const nsAString& aSelectorText) -{ - if (Rule()) { - Rule()->SetSelectorText(aSelectorText); - } - return NS_OK; -} - -NS_IMETHODIMP -DOMCSSStyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) -{ - *aStyle = &mDOMDeclaration; + *aStyle = mDOMDeclaration.get(); NS_ADDREF(*aStyle); return NS_OK; } NS_IMETHODIMP -DOMCSSStyleRule::GetCSSStyleRule(StyleRule **aResult) +StyleRule::GetCSSStyleRule(StyleRule **aResult) { - *aResult = Rule(); - NS_IF_ADDREF(*aResult); + *aResult = this; + NS_ADDREF(*aResult); return NS_OK; } -} // namespace css -} // namespace mozilla - -// -- StyleRule ------------------------------------ - -namespace mozilla { -namespace css { - StyleRule::StyleRule(nsCSSSelectorList* aSelector, Declaration* aDeclaration, uint32_t aLineNumber, @@ -1468,11 +1306,6 @@ StyleRule::~StyleRule() void StyleRule::DropReferences() { - if (mDOMRule) { - mDOMRule->DOMDeclaration()->DropReference(); - mDOMRule = nullptr; - } - if (mDeclaration) { mDeclaration->SetOwningRule(nullptr); } @@ -1486,18 +1319,38 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) return NS_OK; } else + NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) + NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) NS_IMPL_RELEASE_INHERITED(StyleRule, Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(StyleRule) + +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(StyleRule, Rule) + // Keep this in sync with IsCCLeaf. + // Trace the wrapper for our declaration. This just expands out + // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + if (tmp->mDOMDeclaration) { + tmp->mDOMDeclaration->TraceWrapper(aCallbacks, aClosure); + } +NS_IMPL_CYCLE_COLLECTION_TRACE_END + NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(StyleRule, Rule) + // Unlink the wrapper for our declaraton. This just expands out + // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use + // directly because the wrapper is on the declaration, not on us. + if (tmp->mDOMDeclaration) { + tmp->mDOMDeclaration->ReleaseWrapper(static_cast(p)); + } tmp->DropReferences(); NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(StyleRule, Rule) // Keep this in sync with IsCCLeaf. - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMRule) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END bool @@ -1507,7 +1360,7 @@ StyleRule::IsCCLeaf() const return false; } - return !mDOMRule || !mDOMRule->DOMDeclaration()->PreservingWrapper(); + return !mDOMDeclaration || !mDOMDeclaration->PreservingWrapper(); } /* virtual */ int32_t @@ -1526,16 +1379,7 @@ StyleRule::Clone() const /* virtual */ nsIDOMCSSRule* StyleRule::GetDOMRule() { - if (!mDOMRule) { - if (!GetStyleSheet()) { - // Inline style rules aren't supposed to have a DOM rule object, only - // a declaration. But if we do have one already, from a style sheet - // rule that used to be in a document, we still want to return it. - return nullptr; - } - mDOMRule = new DOMCSSStyleRule(this); - } - return mDOMRule; + return this; } void @@ -1592,7 +1436,7 @@ StyleRule::List(FILE* out, int32_t aIndent) const } #endif -void +NS_IMETHODIMP StyleRule::GetCssText(nsAString& aCssText) { if (mSelector) { @@ -1609,24 +1453,27 @@ StyleRule::GetCssText(nsAString& aCssText) } aCssText.Append(char16_t(' ')); aCssText.Append(char16_t('}')); + return NS_OK; } -void +NS_IMETHODIMP StyleRule::SetCssText(const nsAString& aCssText) { // XXX TBI - need to re-parse rule & declaration + return NS_OK; } -void +NS_IMETHODIMP StyleRule::GetSelectorText(nsAString& aSelectorText) { if (mSelector) mSelector->ToString(aSelectorText, GetStyleSheet()); else aSelectorText.Truncate(); + return NS_OK; } -void +NS_IMETHODIMP StyleRule::SetSelectorText(const nsAString& aSelectorText) { CSSStyleSheet* sheet = GetStyleSheet(); @@ -1653,7 +1500,7 @@ StyleRule::SetSelectorText(const nsAString& aSelectorText) aSelectorText, sheet->GetSheetURI(), 0, &selectorList); if (NS_FAILED(result)) { // Ignore parsing errors and continue to use the previous value. - return; + return NS_OK; } // Replace selector. @@ -1666,6 +1513,8 @@ StyleRule::SetSelectorText(const nsAString& aSelectorText) mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true); doc->StyleRuleChanged(sheet, this); } + + return NS_OK; } /* virtual */ size_t diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 11e05692fa..68cdb25dc0 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -13,12 +13,14 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/UniquePtr.h" #include "mozilla/css/Rule.h" #include "nsString.h" #include "nsCOMPtr.h" #include "nsCSSPseudoElements.h" #include "nsIStyleRule.h" +#include "nsICSSStyleRuleDOMWrapper.h" class nsIAtom; struct nsCSSSelectorList; @@ -316,13 +318,15 @@ private: { 0x464bab7a, 0x2fce, 0x4f30, \ { 0xab, 0x44, 0xb7, 0xa5, 0xf3, 0xaa, 0xe5, 0x7d } } +class DOMCSSDeclarationImpl; + namespace mozilla { namespace css { class Declaration; -class DOMCSSStyleRule; class StyleRule final : public Rule + , public nsICSSStyleRuleDOMWrapper { public: StyleRule(nsCSSSelectorList* aSelector, @@ -335,9 +339,15 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_RULE_IMPL_CID) NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(StyleRule, Rule) + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StyleRule, Rule) virtual bool IsCCLeaf() const override; + NS_DECL_NSIDOMCSSRULE + NS_DECL_NSIDOMCSSSTYLERULE + + // nsICSSStyleRuleDOMWrapper + NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; + // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -345,12 +355,6 @@ public: void SetDeclaration(Declaration* aDecl); - // hooks for DOM rule - void GetCssText(nsAString& aCssText); - void SetCssText(const nsAString& aCssText); - void GetSelectorText(nsAString& aSelectorText); - void SetSelectorText(const nsAString& aSelectorText); - virtual int32_t GetType() const override; virtual already_AddRefed Clone() const override; @@ -375,7 +379,9 @@ private: private: nsCSSSelectorList* mSelector; // null for style attribute RefPtr mDeclaration; - RefPtr mDOMRule; + + // We own it, and it aggregates its refcount with us. + UniquePtr mDOMDeclaration; private: StyleRule& operator=(const StyleRule& aCopy) = delete; From 8c871f602ee066bceeeb5dfa8a35919a3ae647aa Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 17:30:24 +0100 Subject: [PATCH 07/22] Issue #2490 - Part 6: Make css::Rule inherit from nsIDOMCSSRule. --- dom/base/nsDOMClassInfo.cpp | 11 +++++++++++ .../css/nsIDOMCSSCounterStyleRule.idl | 4 ++-- dom/interfaces/css/nsIDOMCSSFontFaceRule.idl | 6 ++++-- .../css/nsIDOMCSSFontFeatureValuesRule.idl | 4 ++-- dom/interfaces/css/nsIDOMCSSGroupingRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSImportRule.idl | 7 +++++-- dom/interfaces/css/nsIDOMCSSKeyframeRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSKeyframesRule.idl | 7 +++++-- dom/interfaces/css/nsIDOMCSSMediaRule.idl | 2 ++ dom/interfaces/css/nsIDOMCSSPageRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSStyleRule.idl | 6 ++++-- dom/interfaces/css/nsIDOMCSSUnknownRule.idl | 4 ++-- layout/inspector/inCSSValueSearch.cpp | 1 + layout/style/NameSpaceRule.h | 3 +-- layout/style/Rule.h | 9 +++++---- layout/style/StyleRule.cpp | 1 - layout/style/nsCSSRules.cpp | 18 ++++-------------- 17 files changed, 60 insertions(+), 41 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index bcba7bb66d..578b16fc66 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -524,14 +524,17 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_END @@ -573,14 +576,17 @@ nsDOMClassInfo::Init() #endif DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_END @@ -616,22 +622,27 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSKeyframeRule, nsIDOMCSSKeyframeRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframeRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSPageRule, nsIDOMCSSPageRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSPageRule) DOM_CLASSINFO_MAP_END DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) + DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) DOM_CLASSINFO_MAP_END diff --git a/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl b/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl index d82b4dbc44..eb2c58d943 100644 --- a/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl +++ b/dom/interfaces/css/nsIDOMCSSCounterStyleRule.idl @@ -3,10 +3,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(9b5e48ce-d84c-4e31-aff5-34e9f4141313)] -interface nsIDOMCSSCounterStyleRule : nsIDOMCSSRule +interface nsIDOMCSSCounterStyleRule : nsISupports { attribute DOMString name; attribute DOMString system; diff --git a/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl b/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl index 18ca669f43..06a58bb834 100644 --- a/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl +++ b/dom/interfaces/css/nsIDOMCSSFontFaceRule.idl @@ -3,10 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(db971017-fe0c-4529-972c-8217f2fee217)] -interface nsIDOMCSSFontFaceRule : nsIDOMCSSRule +interface nsIDOMCSSFontFaceRule : nsISupports { readonly attribute nsIDOMCSSStyleDeclaration style; }; diff --git a/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl b/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl index 1b04dde86f..1e782c07db 100644 --- a/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl +++ b/dom/interfaces/css/nsIDOMCSSFontFeatureValuesRule.idl @@ -3,10 +3,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(a343d27f-1da6-4fc3-9355-d4ca434f958e)] -interface nsIDOMCSSFontFeatureValuesRule : nsIDOMCSSRule +interface nsIDOMCSSFontFeatureValuesRule : nsISupports { attribute DOMString fontFamily; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSGroupingRule.idl b/dom/interfaces/css/nsIDOMCSSGroupingRule.idl index f3580aeecc..348af52b5d 100644 --- a/dom/interfaces/css/nsIDOMCSSGroupingRule.idl +++ b/dom/interfaces/css/nsIDOMCSSGroupingRule.idl @@ -3,13 +3,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSRuleList; /** * Interface for at-rules that have child rules in the CSS OM. */ [scriptable, uuid(a0e3324a-f911-4baf-9591-5322c76cbb0d)] -interface nsIDOMCSSGroupingRule : nsIDOMCSSRule +interface nsIDOMCSSGroupingRule : nsISupports { readonly attribute nsIDOMCSSRuleList cssRules; diff --git a/dom/interfaces/css/nsIDOMCSSImportRule.idl b/dom/interfaces/css/nsIDOMCSSImportRule.idl index 0909d92212..fc96977d91 100644 --- a/dom/interfaces/css/nsIDOMCSSImportRule.idl +++ b/dom/interfaces/css/nsIDOMCSSImportRule.idl @@ -3,10 +3,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMMediaList; +interface nsIDOMCSSStyleSheet; [scriptable, uuid(d3b2b914-01ef-4663-beda-a6475a26f491)] -interface nsIDOMCSSImportRule : nsIDOMCSSRule +interface nsIDOMCSSImportRule : nsISupports { readonly attribute DOMString href; readonly attribute nsIDOMMediaList media; diff --git a/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl b/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl index 46e7ffbb10..0027be2d29 100644 --- a/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl +++ b/dom/interfaces/css/nsIDOMCSSKeyframeRule.idl @@ -3,10 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(a281a8b4-eaa2-49a8-8b97-acc2814a57c9)] -interface nsIDOMCSSKeyframeRule : nsIDOMCSSRule +interface nsIDOMCSSKeyframeRule : nsISupports { attribute DOMString keyText; readonly attribute nsIDOMCSSStyleDeclaration style; diff --git a/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl b/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl index acbb657e47..0e2d3bc4f2 100644 --- a/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl +++ b/dom/interfaces/css/nsIDOMCSSKeyframesRule.idl @@ -3,10 +3,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSRuleList; +interface nsIDOMCSSKeyframeRule; [scriptable, uuid(400f4b70-ad0a-4047-aba4-ee8019f6b907)] -interface nsIDOMCSSKeyframesRule : nsIDOMCSSRule +interface nsIDOMCSSKeyframesRule : nsISupports { attribute DOMString name; readonly attribute nsIDOMCSSRuleList cssRules; diff --git a/dom/interfaces/css/nsIDOMCSSMediaRule.idl b/dom/interfaces/css/nsIDOMCSSMediaRule.idl index 9be4ba143a..e292e2485f 100644 --- a/dom/interfaces/css/nsIDOMCSSMediaRule.idl +++ b/dom/interfaces/css/nsIDOMCSSMediaRule.idl @@ -5,6 +5,8 @@ #include "nsIDOMCSSConditionRule.idl" +interface nsIDOMMediaList; + /** * Interface for @media rules in the CSS OM. */ diff --git a/dom/interfaces/css/nsIDOMCSSPageRule.idl b/dom/interfaces/css/nsIDOMCSSPageRule.idl index e586a0dbb3..a7efb5044a 100644 --- a/dom/interfaces/css/nsIDOMCSSPageRule.idl +++ b/dom/interfaces/css/nsIDOMCSSPageRule.idl @@ -3,10 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(c119072b-7d2f-4aeb-a90d-e2d6b606c32a)] -interface nsIDOMCSSPageRule : nsIDOMCSSRule +interface nsIDOMCSSPageRule : nsISupports { //attribute DOMString selectorText; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSStyleRule.idl b/dom/interfaces/css/nsIDOMCSSStyleRule.idl index d94d22d93e..39b3efaf0c 100644 --- a/dom/interfaces/css/nsIDOMCSSStyleRule.idl +++ b/dom/interfaces/css/nsIDOMCSSStyleRule.idl @@ -3,10 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" + +interface nsIDOMCSSStyleDeclaration; [scriptable, uuid(b5e9af48-a7c2-4f88-aae3-58307af4b5a5)] -interface nsIDOMCSSStyleRule : nsIDOMCSSRule +interface nsIDOMCSSStyleRule : nsISupports { attribute DOMString selectorText; // raises(DOMException) on setting diff --git a/dom/interfaces/css/nsIDOMCSSUnknownRule.idl b/dom/interfaces/css/nsIDOMCSSUnknownRule.idl index 6dfb5ec69a..87546d63b5 100644 --- a/dom/interfaces/css/nsIDOMCSSUnknownRule.idl +++ b/dom/interfaces/css/nsIDOMCSSUnknownRule.idl @@ -3,9 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "nsIDOMCSSRule.idl" +#include "nsISupports.idl" [scriptable, uuid(98f4c27b-fb35-4355-8fd9-546c4697d71a)] -interface nsIDOMCSSUnknownRule : nsIDOMCSSRule +interface nsIDOMCSSUnknownRule : nsISupports { }; diff --git a/layout/inspector/inCSSValueSearch.cpp b/layout/inspector/inCSSValueSearch.cpp index ecde099938..5897e1b542 100644 --- a/layout/inspector/inCSSValueSearch.cpp +++ b/layout/inspector/inCSSValueSearch.cpp @@ -18,6 +18,7 @@ #include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSSupportsRule.h" +#include "nsIDOMCSSRule.h" #include "nsIURI.h" #include "nsIDocument.h" #include "nsNetUtil.h" diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 5725a017e9..383fe32b8e 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -24,8 +24,7 @@ class nsIAtom; namespace mozilla { namespace css { -class NameSpaceRule final : public Rule, - public nsIDOMCSSRule +class NameSpaceRule final : public Rule { public: NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, diff --git a/layout/style/Rule.h b/layout/style/Rule.h index ccf44767c3..61ffaa0e86 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -30,7 +30,7 @@ class GroupRule; DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ virtual nsIDOMCSSRule* GetDOMRule() override; -class Rule : public nsISupports +class Rule : public nsIDOMCSSRule , public nsWrapperCache { protected: @@ -119,9 +119,10 @@ public: virtual nsIDOMCSSRule* GetDOMRule() = 0; // to implement methods on nsIDOMCSSRule - nsresult GetParentRule(nsIDOMCSSRule** aParentRule); - nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet); - Rule* GetCSSRule(); + NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParentRule) override; + NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) override; + virtual Rule* GetCSSRule() override; + using nsIDOMCSSRule::GetType; // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index c6c63c3e37..407db13009 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1321,7 +1321,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) else NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1c0312339d..b01cd7988b 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -60,6 +60,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(Rule) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Rule) NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END @@ -115,7 +116,7 @@ Rule::SetStyleSheet(CSSStyleSheet* aSheet) mSheet = aSheet; } -nsresult +NS_IMETHODIMP Rule::GetParentRule(nsIDOMCSSRule** aParentRule) { if (mParentRule) { @@ -126,7 +127,7 @@ Rule::GetParentRule(nsIDOMCSSRule** aParentRule) return NS_OK; } -nsresult +NS_IMETHODIMP Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) { NS_ENSURE_ARG_POINTER(aSheet); @@ -135,7 +136,7 @@ Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) return NS_OK; } -css::Rule* +/* virtual */ css::Rule* Rule::GetCSSRule() { return this; @@ -264,7 +265,6 @@ ImportRule::IsCCLeaf() const // QueryInterface implementation for ImportRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -698,7 +698,6 @@ NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule) // QueryInterface implementation for MediaRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) @@ -926,7 +925,6 @@ NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule) // QueryInterface implementation for DocumentRule NS_INTERFACE_MAP_BEGIN(DocumentRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) @@ -1208,7 +1206,6 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) return NS_OK; } else - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -1681,7 +1678,6 @@ nsCSSFontFaceRule::IsCCLeaf() const // QueryInterface implementation for nsCSSFontFaceRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) @@ -1833,7 +1829,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // implementation. NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2202,7 +2197,6 @@ nsCSSKeyframeRule::IsCCLeaf() const // QueryInterface implementation for nsCSSKeyframeRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2415,7 +2409,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) // QueryInterface implementation for nsCSSKeyframesRule NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) @@ -2782,7 +2775,6 @@ nsCSSPageRule::IsCCLeaf() const // QueryInterface implementation for nsCSSPageRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) @@ -2961,7 +2953,6 @@ NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule) // QueryInterface implementation for CSSSupportsRule NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) @@ -3101,7 +3092,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // If this ever gets its own cycle-collection bits, reevaluate our IsCCLeaf // implementation. NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) - NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) From fce04b359166a26e6fbd64481106cc733e47128c Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 19:31:09 +0100 Subject: [PATCH 08/22] Issue #2490 - Part 7: Push the nsIDOMCSSRule implementation up to css::Rule. --- layout/style/GroupRule.h | 2 +- layout/style/ImportRule.h | 7 +- layout/style/NameSpaceRule.h | 8 +- layout/style/Rule.h | 13 +- layout/style/StyleRule.cpp | 38 +-- layout/style/StyleRule.h | 6 +- layout/style/nsCSSRules.cpp | 451 ++++++++--------------------------- layout/style/nsCSSRules.h | 81 ++++--- 8 files changed, 171 insertions(+), 435 deletions(-) diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index d9770dd1ec..fe348e8bad 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -83,7 +83,7 @@ public: protected: // to help implement nsIDOMCSSRule - void AppendRulesToCssText(nsAString& aCssText); + void AppendRulesToCssText(nsAString& aCssText) const; // to implement common methods on nsIDOMCSSMediaRule and // nsIDOMCSSMozDocumentRule diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 64c9aa301c..3e02f91939 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -57,12 +57,13 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSImportRule interface NS_DECL_NSIDOMCSSIMPORTRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + private: nsString mURLSpec; RefPtr mMedia; diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index 383fe32b8e..c78cb108da 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -45,20 +45,22 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; nsIAtom* GetPrefix() const { return mPrefix; } void GetURLSpec(nsString& aURLSpec) const { aURLSpec = mURLSpec; } + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - private: nsCOMPtr mPrefix; nsString mURLSpec; diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 61ffaa0e86..08589a57bd 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -60,6 +60,9 @@ public: // sense that it doesn't have any outgoing owning edges. virtual bool IsCCLeaf() const MOZ_MUST_OVERRIDE; + // nsIDOMCSSRule interface + NS_DECL_NSIDOMCSSRULE + #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0; #endif @@ -118,17 +121,15 @@ public: // supposed to have a DOM rule representation (and our code wouldn't work). virtual nsIDOMCSSRule* GetDOMRule() = 0; - // to implement methods on nsIDOMCSSRule - NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParentRule) override; - NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) override; - virtual Rule* GetCSSRule() override; - using nsIDOMCSSRule::GetType; - // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const MOZ_MUST_OVERRIDE = 0; + // WebIDL interface, aka helpers for nsIDOMCSSRule implementation. + virtual uint16_t Type() const = 0; + virtual void GetCssTextImpl(nsAString& aCssText) const = 0; + protected: // True if we're known-live for cycle collection purposes. bool IsKnownLive() const; diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index 407db13009..b04794c34b 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1227,30 +1227,10 @@ DOMCSSDeclarationImpl::DocToUpdate() namespace mozilla { namespace css { -NS_IMETHODIMP -StyleRule::GetType(uint16_t* aType) +uint16_t +StyleRule::Type() const { - *aType = nsIDOMCSSRule::STYLE_RULE; - - return NS_OK; -} - -NS_IMETHODIMP -StyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -StyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -StyleRule::GetCSSRule() -{ - return this; + return nsIDOMCSSRule::STYLE_RULE; } NS_IMETHODIMP @@ -1435,8 +1415,8 @@ StyleRule::List(FILE* out, int32_t aIndent) const } #endif -NS_IMETHODIMP -StyleRule::GetCssText(nsAString& aCssText) +void +StyleRule::GetCssTextImpl(nsAString& aCssText) const { if (mSelector) { mSelector->ToString(aCssText, GetStyleSheet()); @@ -1452,14 +1432,6 @@ StyleRule::GetCssText(nsAString& aCssText) } aCssText.Append(char16_t(' ')); aCssText.Append(char16_t('}')); - return NS_OK; -} - -NS_IMETHODIMP -StyleRule::SetCssText(const nsAString& aCssText) -{ - // XXX TBI - need to re-parse rule & declaration - return NS_OK; } NS_IMETHODIMP diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 68cdb25dc0..2e74d16e86 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -342,12 +342,15 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(StyleRule, Rule) virtual bool IsCCLeaf() const override; - NS_DECL_NSIDOMCSSRULE NS_DECL_NSIDOMCSSSTYLERULE // nsICSSStyleRuleDOMWrapper NS_IMETHOD GetCSSStyleRule(StyleRule **aResult) override; + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -356,6 +359,7 @@ public: void SetDeclaration(Declaration* aDecl); virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index b01cd7988b..7ba72623f8 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -142,6 +142,28 @@ Rule::GetCSSRule() return this; } +NS_IMETHODIMP +Rule::GetType(uint16_t* aType) +{ + *aType = Type(); + return NS_OK; +} + +NS_IMETHODIMP +Rule::SetCssText(const nsAString& aCssText) +{ + // We used to throw for some rule types, but not all. Specifically, we did + // not throw for StyleRule. Let's just always not throw. + return NS_OK; +} + +NS_IMETHODIMP +Rule::GetCssText(nsAString& aCssText) +{ + GetCssTextImpl(aCssText); + return NS_OK; +} + // ------------------------------- // Style Rule List for group rules // @@ -334,16 +356,14 @@ ImportRule::SetSheet(CSSStyleSheet* aSheet) mMedia = mChildSheet->Media(); } -NS_IMETHODIMP -ImportRule::GetType(uint16_t* aType) +uint16_t +ImportRule::Type() const { - NS_ENSURE_ARG_POINTER(aType); - *aType = nsIDOMCSSRule::IMPORT_RULE; - return NS_OK; + return nsIDOMCSSRule::IMPORT_RULE; } -NS_IMETHODIMP -ImportRule::GetCssText(nsAString& aCssText) +void +ImportRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@import url("); nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText); @@ -357,31 +377,6 @@ ImportRule::GetCssText(nsAString& aCssText) } } aCssText.Append(';'); - return NS_OK; -} - -NS_IMETHODIMP -ImportRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -ImportRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -ImportRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -589,7 +584,7 @@ GroupRule::InsertStyleRuleAt(uint32_t aIndex, Rule* aRule) } void -GroupRule::AppendRulesToCssText(nsAString& aCssText) +GroupRule::AppendRulesToCssText(nsAString& aCssText) const { aCssText.AppendLiteral(" {\n"); @@ -768,45 +763,18 @@ MediaRule::SetMedia(nsMediaList* aMedia) return NS_OK; } -// nsIDOMCSSRule methods -NS_IMETHODIMP -MediaRule::GetType(uint16_t* aType) +uint16_t +MediaRule::Type() const { - *aType = nsIDOMCSSRule::MEDIA_RULE; - return NS_OK; + return nsIDOMCSSRule::MEDIA_RULE; } -NS_IMETHODIMP -MediaRule::GetCssText(nsAString& aCssText) +void +MediaRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@media "); AppendConditionText(aCssText); GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -MediaRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -MediaRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -MediaRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -894,7 +862,7 @@ MediaRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) } void -MediaRule::AppendConditionText(nsAString& aOutput) +MediaRule::AppendConditionText(nsAString& aOutput) const { if (mMedia) { nsAutoString mediaText; @@ -984,46 +952,19 @@ DocumentRule::Clone() const return clone.forget(); } -// nsIDOMCSSRule methods -NS_IMETHODIMP -DocumentRule::GetType(uint16_t* aType) +uint16_t +DocumentRule::Type() const { // XXX What should really happen here? - *aType = nsIDOMCSSRule::UNKNOWN_RULE; - return NS_OK; + return nsIDOMCSSRule::UNKNOWN_RULE; } -NS_IMETHODIMP -DocumentRule::GetCssText(nsAString& aCssText) +void +DocumentRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@-moz-document "); AppendConditionText(aCssText); GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -DocumentRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -DocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -DocumentRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -1144,7 +1085,7 @@ DocumentRule::WrapObject(JSContext* aCx, } void -DocumentRule::AppendConditionText(nsAString& aCssText) +DocumentRule::AppendConditionText(nsAString& aCssText) const { for (URL *url = mURLs; url; url = url->next) { switch (url->func) { @@ -1256,15 +1197,14 @@ NameSpaceRule::Clone() const return clone.forget(); } -NS_IMETHODIMP -NameSpaceRule::GetType(uint16_t* aType) +uint16_t +NameSpaceRule::Type() const { - *aType = nsIDOMCSSRule::NAMESPACE_RULE; - return NS_OK; + return nsIDOMCSSRule::NAMESPACE_RULE; } -NS_IMETHODIMP -NameSpaceRule::GetCssText(nsAString& aCssText) +void +NameSpaceRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@namespace "); if (mPrefix) { @@ -1273,31 +1213,6 @@ NameSpaceRule::GetCssText(nsAString& aCssText) aCssText.AppendLiteral("url("); nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText); aCssText.AppendLiteral(");"); - return NS_OK; -} - -NS_IMETHODIMP -NameSpaceRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -NameSpaceRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -NameSpaceRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } /* virtual */ size_t @@ -1448,7 +1363,14 @@ nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, NS_IMETHODIMP -nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText) +nsCSSFontFaceStyleDecl::GetCssText(nsAString& aCssText) +{ + GetCssTextImpl(aCssText); + return NS_OK; +} + +void +nsCSSFontFaceStyleDecl::GetCssTextImpl(nsAString& aCssText) const { nsAutoString descStr; @@ -1467,7 +1389,6 @@ nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText) aCssText.AppendLiteral(";\n"); } } - return NS_OK; } NS_IMETHODIMP @@ -1719,47 +1640,21 @@ nsCSSFontFaceRule::GetType() const return Rule::FONT_FACE_RULE; } -NS_IMETHODIMP -nsCSSFontFaceRule::GetType(uint16_t* aType) +uint16_t +nsCSSFontFaceRule::Type() const { - *aType = nsIDOMCSSRule::FONT_FACE_RULE; - return NS_OK; + return nsIDOMCSSRule::FONT_FACE_RULE; } -NS_IMETHODIMP -nsCSSFontFaceRule::GetCssText(nsAString& aCssText) +void +nsCSSFontFaceRule::GetCssTextImpl(nsAString& aCssText) const { nsAutoString propText; - mDecl.GetCssText(propText); + mDecl.GetCssTextImpl(propText); aCssText.AssignLiteral("@font-face {\n"); aCssText.Append(propText); aCssText.Append('}'); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSFontFaceRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; // bug 443978 -} - -NS_IMETHODIMP -nsCSSFontFaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSFontFaceRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -1928,43 +1823,16 @@ nsCSSFontFeatureValuesRule::GetType() const return Rule::FONT_FEATURE_VALUES_RULE; } -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetType(uint16_t* aType) +uint16_t +nsCSSFontFeatureValuesRule::Type() const { - *aType = nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE; - return NS_OK; + return nsIDOMCSSRule::FONT_FEATURE_VALUES_RULE; } -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetCssText(nsAString& aCssText) +void +nsCSSFontFeatureValuesRule::GetCssTextImpl(nsAString& aCssText) const { FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, aCssText); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSFontFeatureValuesRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSFontFeatureValuesRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2228,15 +2096,14 @@ nsCSSKeyframeRule::GetType() const return Rule::KEYFRAME_RULE; } -NS_IMETHODIMP -nsCSSKeyframeRule::GetType(uint16_t* aType) +uint16_t +nsCSSKeyframeRule::Type() const { - *aType = nsIDOMCSSRule::KEYFRAME_RULE; - return NS_OK; + return nsIDOMCSSRule::KEYFRAME_RULE; } -NS_IMETHODIMP -nsCSSKeyframeRule::GetCssText(nsAString& aCssText) +void +nsCSSKeyframeRule::GetCssTextImpl(nsAString& aCssText) const { DoGetKeyText(aCssText); aCssText.AppendLiteral(" { "); @@ -2244,32 +2111,6 @@ nsCSSKeyframeRule::GetCssText(nsAString& aCssText) mDeclaration->ToString(tmp); aCssText.Append(tmp); aCssText.AppendLiteral(" }"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSKeyframeRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSKeyframeRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSKeyframeRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2437,15 +2278,14 @@ nsCSSKeyframesRule::GetType() const return Rule::KEYFRAMES_RULE; } -NS_IMETHODIMP -nsCSSKeyframesRule::GetType(uint16_t* aType) +uint16_t +nsCSSKeyframesRule::Type() const { - *aType = nsIDOMCSSRule::KEYFRAMES_RULE; - return NS_OK; + return nsIDOMCSSRule::KEYFRAMES_RULE; } -NS_IMETHODIMP -nsCSSKeyframesRule::GetCssText(nsAString& aCssText) +void +nsCSSKeyframesRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@keyframes "); aCssText.Append(mName); @@ -2457,32 +2297,6 @@ nsCSSKeyframesRule::GetCssText(nsAString& aCssText) aCssText.Append('\n'); } aCssText.Append('}'); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSKeyframesRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSKeyframesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSKeyframesRule::GetCSSRule() -{ - return GroupRule::GetCSSRule(); } NS_IMETHODIMP @@ -2804,47 +2618,20 @@ nsCSSPageRule::GetType() const return Rule::PAGE_RULE; } -NS_IMETHODIMP -nsCSSPageRule::GetType(uint16_t* aType) +uint16_t +nsCSSPageRule::Type() const { - *aType = nsIDOMCSSRule::PAGE_RULE; - return NS_OK; + return nsIDOMCSSRule::PAGE_RULE; } -NS_IMETHODIMP -nsCSSPageRule::GetCssText(nsAString& aCssText) +void +nsCSSPageRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AppendLiteral("@page { "); nsAutoString tmp; mDeclaration->ToString(tmp); aCssText.Append(tmp); aCssText.AppendLiteral(" }"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSPageRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSPageRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSPageRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSPageRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } NS_IMETHODIMP @@ -2959,45 +2746,18 @@ NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) -// nsIDOMCSSRule methods -NS_IMETHODIMP -CSSSupportsRule::GetType(uint16_t* aType) +uint16_t +CSSSupportsRule::Type() const { - *aType = nsIDOMCSSRule::SUPPORTS_RULE; - return NS_OK; + return nsIDOMCSSRule::SUPPORTS_RULE; } -NS_IMETHODIMP -CSSSupportsRule::GetCssText(nsAString& aCssText) +void +CSSSupportsRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral("@supports "); aCssText.Append(mCondition); css::GroupRule::AppendRulesToCssText(aCssText); - return NS_OK; -} - -NS_IMETHODIMP -CSSSupportsRule::SetCssText(const nsAString& aCssText) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -CSSSupportsRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return css::GroupRule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -CSSSupportsRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return css::GroupRule::GetParentRule(aParentRule); -} - -css::Rule* -CSSSupportsRule::GetCSSRule() -{ - return css::GroupRule::GetCSSRule(); } // nsIDOMCSSGroupingRule methods @@ -3129,16 +2889,14 @@ nsCSSCounterStyleRule::GetType() const return Rule::COUNTER_STYLE_RULE; } -// nsIDOMCSSRule methods -NS_IMETHODIMP -nsCSSCounterStyleRule::GetType(uint16_t* aType) +uint16_t +nsCSSCounterStyleRule::Type() const { - *aType = nsIDOMCSSRule::COUNTER_STYLE_RULE; - return NS_OK; + return nsIDOMCSSRule::COUNTER_STYLE_RULE; } -NS_IMETHODIMP -nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) +void +nsCSSCounterStyleRule::GetCssTextImpl(nsAString& aCssText) const { aCssText.AssignLiteral(u"@counter-style "); nsStyleUtil::AppendEscapedCSSIdent(mName, aCssText); @@ -3148,7 +2906,10 @@ nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) id = nsCSSCounterDesc(id + 1)) { if (mValues[id].GetUnit() != eCSSUnit_Null) { nsAutoString tmp; - (this->*kGetters[id])(tmp); + // This is annoying. We want to be a const method, but kGetters stores + // XPCOM method pointers, which aren't const methods. The thing is, + // none of those mutate "this". So it's OK to cast away const here. + (const_cast(this)->*kGetters[id])(tmp); aCssText.AppendLiteral(u" "); AppendASCIItoUTF16(nsCSSProps::GetStringValue(id), aCssText); aCssText.AppendLiteral(u": "); @@ -3157,32 +2918,6 @@ nsCSSCounterStyleRule::GetCssText(nsAString& aCssText) } } aCssText.AppendLiteral(u"}"); - return NS_OK; -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::SetCssText(const nsAString& aCssText) -{ - // FIXME: implement??? - return NS_ERROR_NOT_IMPLEMENTED; -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet) -{ - return Rule::GetParentStyleSheet(aSheet); -} - -NS_IMETHODIMP -nsCSSCounterStyleRule::GetParentRule(nsIDOMCSSRule** aParentRule) -{ - return Rule::GetParentRule(aParentRule); -} - -css::Rule* -nsCSSCounterStyleRule::GetCSSRule() -{ - return Rule::GetCSSRule(); } // nsIDOMCSSCounterStyleRule methods diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 628cd07a92..847bfe847e 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -65,15 +65,13 @@ public: #endif virtual void SetStyleSheet(mozilla::CSSStyleSheet* aSheet) override; //override GroupRule virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -89,7 +87,11 @@ public: // @media rule methods nsresult SetMedia(nsMediaList* aMedia); - + + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -97,7 +99,7 @@ public: JS::Handle aGivenProto) override; protected: - void AppendConditionText(nsAString& aOutput); + void AppendConditionText(nsAString& aOutput) const; RefPtr mMedia; }; @@ -119,15 +121,13 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -167,6 +167,10 @@ public: void SetURLs(URL *aURLs) { mURLs = aURLs; } + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -174,7 +178,7 @@ public: JS::Handle aGivenProto) override; protected: - void AppendConditionText(nsAString& aOutput); + void AppendConditionText(nsAString& aOutput) const; nsAutoPtr mURLs; // linked list of |struct URL| above. }; @@ -228,6 +232,9 @@ protected: mozilla::CSSFontFaceDescriptors mDescriptors; + // The actual implementation of GetCssText, so we can make it const. + void GetCssTextImpl(nsAString& aCssText) const; + private: // NOT TO BE IMPLEMENTED // This object cannot be allocated on its own, only as part of @@ -263,17 +270,19 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSFontFaceRule interface NS_DECL_NSIDOMCSSFONTFACERULE void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue); void GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue); + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; virtual JSObject* WrapObject(JSContext* aCx, @@ -338,14 +347,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSFontFaceRule interface NS_DECL_NSIDOMCSSFONTFEATUREVALUESRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + const mozilla::FontFamilyList& GetFamilyList() { return mFamilyList; } void SetFamilyList(const mozilla::FontFamilyList& aFamilyList); @@ -426,14 +437,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSKeyframeRule interface NS_DECL_NSIDOMCSSKEYFRAMERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + const nsTArray& GetKeys() const { return mKeys; } mozilla::css::Declaration* Declaration() { return mDeclaration; } @@ -474,18 +487,20 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual nsIDOMCSSRule* GetDOMRule() override { return this; } - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSKeyframesRule interface NS_DECL_NSIDOMCSSKEYFRAMESRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // rest of GroupRule virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; @@ -557,14 +572,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSPageRule interface NS_DECL_NSIDOMCSSPAGERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + mozilla::css::Declaration* Declaration() { return mDeclaration; } void ChangeDeclaration(mozilla::css::Declaration* aDeclaration); @@ -594,6 +611,7 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; @@ -604,9 +622,6 @@ public: NS_DECL_ISUPPORTS_INHERITED - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -616,6 +631,10 @@ public: // nsIDOMCSSSupportsRule interface NS_DECL_NSIDOMCSSSUPPORTSRULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; @@ -656,14 +675,16 @@ public: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif virtual int32_t GetType() const override; + using Rule::GetType; virtual already_AddRefed Clone() const override; - // nsIDOMCSSRule interface - NS_DECL_NSIDOMCSSRULE - // nsIDOMCSSCounterStyleRule NS_DECL_NSIDOMCSSCOUNTERSTYLERULE + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // This function is only used to check whether a non-empty value, which has // been accepted by parser, is valid for the given system and descriptor. static bool CheckDescValue(int32_t aSystem, From bb2aaeac9f046c23e0b1e0ab858a1e08cd4f9d58 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 30 Mar 2024 22:32:33 +0100 Subject: [PATCH 09/22] Issue #2490 - Part 8: Get rid of css::Rule::GetDOMRule. --- dom/base/nsDocument.cpp | 8 +++--- layout/inspector/inDOMUtils.cpp | 10 +++----- layout/style/CSSStyleSheet.cpp | 9 ++----- layout/style/GroupRule.h | 2 -- layout/style/ImportRule.h | 2 -- layout/style/NameSpaceRule.h | 2 -- layout/style/Rule.h | 11 --------- layout/style/StyleRule.cpp | 8 +----- layout/style/StyleRule.h | 2 -- layout/style/nsCSSRules.cpp | 44 ++++++--------------------------- layout/style/nsCSSRules.h | 26 ------------------- 11 files changed, 17 insertions(+), 107 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 5f1d3a30c0..0c6950e422 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -4940,7 +4940,7 @@ nsDocument::StyleRuleChanged(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleChanged", mRule, - aStyleRule ? aStyleRule->GetDOMRule() : nullptr); + aStyleRule); } } @@ -4954,8 +4954,7 @@ nsDocument::StyleRuleAdded(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleAdded", mRule, - aStyleRule ? aStyleRule->GetDOMRule() - : nullptr); + aStyleRule); } } @@ -4969,8 +4968,7 @@ nsDocument::StyleRuleRemoved(StyleSheet* aSheet, DO_STYLESHEET_NOTIFICATION(StyleRuleChangeEvent, "StyleRuleRemoved", mRule, - aStyleRule ? aStyleRule->GetDOMRule() - : nullptr); + aStyleRule); } } diff --git a/layout/inspector/inDOMUtils.cpp b/layout/inspector/inDOMUtils.cpp index 5e0cb208a8..fdae4543ed 100644 --- a/layout/inspector/inDOMUtils.cpp +++ b/layout/inspector/inDOMUtils.cpp @@ -248,13 +248,9 @@ inDOMUtils::GetCSSStyleRules(nsIDOMElement *aElement, for (nsRuleNode* ruleNode : Reversed(ruleNodes)) { RefPtr decl = do_QueryObject(ruleNode->GetRule()); if (decl) { - RefPtr styleRule = - do_QueryObject(decl->GetOwningRule()); - if (styleRule) { - nsCOMPtr domRule = styleRule->GetDOMRule(); - if (domRule) { - rules->AppendElement(domRule, /*weak =*/ false); - } + css::Rule* owningRule = decl->GetOwningRule(); + if (owningRule) { + rules->AppendElement(owningRule, /*weak =*/ false); } } } diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index bca4820e2e..1a3944fdb4 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -112,7 +112,7 @@ CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound) css::Rule* rule = mStyleSheet->GetStyleRuleAt(aIndex); if (rule) { aFound = true; - return rule->GetDOMRule(); + return rule; } } @@ -1651,7 +1651,7 @@ CSSStyleSheet::Media() nsIDOMCSSRule* CSSStyleSheet::GetDOMOwnerRule() const { - return mOwnerRule ? mOwnerRule->GetDOMRule() : nullptr; + return mOwnerRule; } CSSRuleList* @@ -1814,11 +1814,6 @@ CSSStyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) RefPtr rule = mInner->mOrderedRules.ObjectAt(aIndex); if (rule) { mInner->mOrderedRules.RemoveObjectAt(aIndex); - if (mDocument && mDocument->StyleSheetChangeEventsEnabled()) { - // Force creation of the DOM rule, so that it can be put on the - // StyleRuleRemoved event object. - rule->GetDOMRule(); - } rule->SetStyleSheet(nullptr); DidDirty(); diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index fe348e8bad..dae429d663 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -42,8 +42,6 @@ public: NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; - // implement part of Rule - DECL_STYLE_RULE_INHERIT_NO_DOMRULE #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 3e02f91939..dd12e65b3c 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -38,8 +38,6 @@ public: NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; - DECL_STYLE_RULE_INHERIT - #ifdef HAVE_CPP_AMBIGUITY_RESOLVING_USING using Rule::GetStyleSheet; // unhide since nsIDOMCSSImportRule has its own GetStyleSheet #endif diff --git a/layout/style/NameSpaceRule.h b/layout/style/NameSpaceRule.h index c78cb108da..06848b0bb1 100644 --- a/layout/style/NameSpaceRule.h +++ b/layout/style/NameSpaceRule.h @@ -39,8 +39,6 @@ public: NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 08589a57bd..00082c1e2c 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -23,13 +23,6 @@ namespace mozilla { namespace css { class GroupRule; -#define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - /* nothing */ - -#define DECL_STYLE_RULE_INHERIT \ - DECL_STYLE_RULE_INHERIT_NO_DOMRULE \ - virtual nsIDOMCSSRule* GetDOMRule() override; - class Rule : public nsIDOMCSSRule , public nsWrapperCache { @@ -117,10 +110,6 @@ public: */ virtual already_AddRefed Clone() const = 0; - // Note that this returns null for inline style rules since they aren't - // supposed to have a DOM rule representation (and our code wouldn't work). - virtual nsIDOMCSSRule* GetDOMRule() = 0; - // This is pure virtual because all of Rule's data members are non-owning and // thus measured elsewhere. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index b04794c34b..cf5952a650 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -1186,7 +1186,7 @@ DOMCSSDeclarationImpl::GetParentRule(nsIDOMCSSRule **aParent) { NS_ENSURE_ARG_POINTER(aParent); - NS_IF_ADDREF(*aParent = mRule->GetDOMRule()); + NS_IF_ADDREF(*aParent = mRule); return NS_OK; } @@ -1355,12 +1355,6 @@ StyleRule::Clone() const return clone.forget(); } -/* virtual */ nsIDOMCSSRule* -StyleRule::GetDOMRule() -{ - return this; -} - void StyleRule::SetDeclaration(Declaration* aDecl) { diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 2e74d16e86..55ec693a38 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -363,8 +363,6 @@ public: virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override; - #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 7ba72623f8..ff0b33eb25 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -43,13 +43,6 @@ using namespace mozilla; using namespace mozilla::dom; -#define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \ - /* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \ - { return this; } - -#define IMPL_STYLE_RULE_INHERIT(class_, super_) \ -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) - // base class for all rule types in a CSS style sheet namespace mozilla { @@ -119,11 +112,7 @@ Rule::SetStyleSheet(CSSStyleSheet* aSheet) NS_IMETHODIMP Rule::GetParentRule(nsIDOMCSSRule** aParentRule) { - if (mParentRule) { - NS_IF_ADDREF(*aParentRule = mParentRule->GetDOMRule()); - } else { - *aParentRule = nullptr; - } + NS_IF_ADDREF(*aParentRule = mParentRule); return NS_OK; } @@ -229,7 +218,7 @@ GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) RefPtr rule = mGroupRule->GetStyleRuleAt(aIndex); if (rule) { aFound = true; - return rule->GetDOMRule(); + return rule; } } @@ -291,8 +280,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) -IMPL_STYLE_RULE_INHERIT(ImportRule, Rule) - NS_IMPL_CYCLE_COLLECTION_CLASS(ImportRule) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ImportRule) @@ -591,14 +578,11 @@ GroupRule::AppendRulesToCssText(nsAString& aCssText) const // get all the rules for (int32_t index = 0, count = mRules.Count(); index < count; ++index) { Rule* rule = mRules.ObjectAt(index); - nsIDOMCSSRule* domRule = rule->GetDOMRule(); - if (domRule) { - nsAutoString cssText; - domRule->GetCssText(cssText); - aCssText.AppendLiteral(" "); - aCssText.Append(cssText); - aCssText.Append('\n'); - } + nsAutoString cssText; + rule->GetCssText(cssText); + aCssText.AppendLiteral(" "); + aCssText.Append(cssText); + aCssText.Append('\n'); } aCssText.Append('}'); @@ -1156,8 +1140,6 @@ NameSpaceRule::IsCCLeaf() const return Rule::IsCCLeaf(); } -IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule) - #ifdef DEBUG /* virtual */ void NameSpaceRule::List(FILE* out, int32_t aIndent) const @@ -1505,7 +1487,7 @@ nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index, bool& aFound, nsAString & NS_IMETHODIMP nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule) { - NS_IF_ADDREF(*aParentRule = ContainingRule()->GetDOMRule()); + NS_IF_ADDREF(*aParentRule = ContainingRule()); return NS_OK; } @@ -1602,8 +1584,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) -IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule) - #ifdef DEBUG void nsCSSFontFaceRule::List(FILE* out, int32_t aIndent) const @@ -1733,8 +1713,6 @@ nsCSSFontFeatureValuesRule::IsCCLeaf() const return Rule::IsCCLeaf(); } -IMPL_STYLE_RULE_INHERIT(nsCSSFontFeatureValuesRule, Rule) - static void FeatureValuesToString( const nsTArray& aFeatureValues, @@ -2068,8 +2046,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule) - #ifdef DEBUG void nsCSSKeyframeRule::List(FILE* out, int32_t aIndent) const @@ -2592,8 +2568,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) -IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule) - #ifdef DEBUG void nsCSSPageRule::List(FILE* out, int32_t aIndent) const @@ -2862,8 +2836,6 @@ nsCSSCounterStyleRule::IsCCLeaf() const return Rule::IsCCLeaf(); } -IMPL_STYLE_RULE_INHERIT(nsCSSCounterStyleRule, css::Rule) - #ifdef DEBUG void nsCSSCounterStyleRule::List(FILE* out, int32_t aIndent) const diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 847bfe847e..2aa18b1387 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -67,10 +67,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -123,10 +119,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSGroupingRule interface NS_DECL_NSIDOMCSSGROUPINGRULE @@ -264,8 +256,6 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsCSSFontFaceRule, mozilla::css::Rule) virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -341,8 +331,6 @@ public: NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -431,8 +419,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSKeyframeRule, mozilla::css::Rule) virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -489,10 +475,6 @@ public: virtual int32_t GetType() const override; using Rule::GetType; virtual already_AddRefed Clone() const override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } // nsIDOMCSSKeyframesRule interface NS_DECL_NSIDOMCSSKEYFRAMESRULE @@ -566,8 +548,6 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsCSSPageRule, mozilla::css::Rule) virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif @@ -615,10 +595,6 @@ public: virtual already_AddRefed Clone() const override; virtual bool UseForPresentation(nsPresContext* aPresContext, nsMediaQueryResultCacheKey& aKey) override; - virtual nsIDOMCSSRule* GetDOMRule() override - { - return this; - } NS_DECL_ISUPPORTS_INHERITED @@ -669,8 +645,6 @@ public: NS_DECL_ISUPPORTS_INHERITED virtual bool IsCCLeaf() const override; - // Rule methods - DECL_STYLE_RULE_INHERIT #ifdef DEBUG virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override; #endif From 5a522d91454d8214593c100d03920521f83b9a60 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 31 Mar 2024 00:47:10 +0100 Subject: [PATCH 10/22] Issue #2490 - WIP: part 9. Add a CSSRule Web IDL interface. --- dom/bindings/Bindings.conf | 6 ++- dom/webidl/CSSRule.webidl | 52 ++++++++++++++++++++++++++ dom/webidl/CSSStyleDeclaration.webidl | 2 - dom/webidl/CSSStyleSheet.webidl | 2 - dom/webidl/StyleRuleChangeEvent.webidl | 2 - dom/webidl/StyleSheet.webidl | 2 - dom/webidl/moz.build | 1 + layout/style/CSSRuleList.h | 5 ++- layout/style/CSSStyleSheet.cpp | 6 +-- layout/style/CSSStyleSheet.h | 2 +- layout/style/Rule.h | 19 ++++++++++ layout/style/StyleSheet.h | 6 ++- layout/style/nsCSSRules.cpp | 31 ++++++++++++++- 13 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 dom/webidl/CSSRule.webidl diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 26751ac8c6..33c812a542 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -205,6 +205,11 @@ DOMInterfaces = { 'nativeType': 'nsROCSSPrimitiveValue', }, +'CSSRule': { +# 'hasXPConnectImpls': True, + 'nativeType': 'mozilla::css::Rule' +}, + 'CSSStyleDeclaration': { 'nativeType': 'nsICSSDeclaration' }, @@ -1689,7 +1694,6 @@ def addExternalIface(iface, nativeType=None, headerFile=None, addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList') addExternalIface('Counter') -addExternalIface('CSSRule') addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel') addExternalIface('HitRegionOptions', nativeType='nsISupports') addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver') diff --git a/dom/webidl/CSSRule.webidl b/dom/webidl/CSSRule.webidl new file mode 100644 index 0000000000..6c4dac2e62 --- /dev/null +++ b/dom/webidl/CSSRule.webidl @@ -0,0 +1,52 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#the-cssrule-interface + * https://drafts.csswg.org/css-animations/#interface-cssrule + * https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface + * https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface + * https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues + */ + +// https://drafts.csswg.org/cssom/#the-cssrule-interface +interface CSSRule { + + const unsigned short STYLE_RULE = 1; + const unsigned short CHARSET_RULE = 2; // historical + const unsigned short IMPORT_RULE = 3; + const unsigned short MEDIA_RULE = 4; + const unsigned short FONT_FACE_RULE = 5; + const unsigned short PAGE_RULE = 6; + // FIXME: We don't support MARGIN_RULE yet. + // XXXbz Should we expose the constant anyway? + // const unsigned short MARGIN_RULE = 9; + const unsigned short NAMESPACE_RULE = 10; + readonly attribute unsigned short type; + attribute DOMString cssText; + readonly attribute CSSRule? parentRule; + readonly attribute CSSStyleSheet? parentStyleSheet; +}; + +// https://drafts.csswg.org/css-animations/#interface-cssrule +partial interface CSSRule { + const unsigned short KEYFRAMES_RULE = 7; + const unsigned short KEYFRAME_RULE = 8; +}; + +// https://drafts.csswg.org/css-counter-styles-3/#extentions-to-cssrule-interface +partial interface CSSRule { + const unsigned short COUNTER_STYLE_RULE = 11; +}; + +// https://drafts.csswg.org/css-conditional-3/#extentions-to-cssrule-interface +partial interface CSSRule { + const unsigned short SUPPORTS_RULE = 12; +}; + +// https://drafts.csswg.org/css-fonts-3/#om-fontfeaturevalues +partial interface CSSRule { + const unsigned short FONT_FEATURE_VALUES_RULE = 14; +}; diff --git a/dom/webidl/CSSStyleDeclaration.webidl b/dom/webidl/CSSStyleDeclaration.webidl index 561e5cce1b..b672c0dd31 100644 --- a/dom/webidl/CSSStyleDeclaration.webidl +++ b/dom/webidl/CSSStyleDeclaration.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - interface CSSStyleDeclaration { [CEReactions, SetterThrows] attribute DOMString cssText; diff --git a/dom/webidl/CSSStyleSheet.webidl b/dom/webidl/CSSStyleSheet.webidl index 677d3ec528..45ef840208 100644 --- a/dom/webidl/CSSStyleSheet.webidl +++ b/dom/webidl/CSSStyleSheet.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - enum CSSStyleSheetParsingMode { "author", "user", diff --git a/dom/webidl/StyleRuleChangeEvent.webidl b/dom/webidl/StyleRuleChangeEvent.webidl index 0b783366ba..ef35bae648 100644 --- a/dom/webidl/StyleRuleChangeEvent.webidl +++ b/dom/webidl/StyleRuleChangeEvent.webidl @@ -3,8 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -interface CSSRule; - [ChromeOnly, Constructor(DOMString type, optional StyleRuleChangeEventInit eventInitDict)] interface StyleRuleChangeEvent : Event { diff --git a/dom/webidl/StyleSheet.webidl b/dom/webidl/StyleSheet.webidl index 71a8ccd8f4..26c2fbb999 100644 --- a/dom/webidl/StyleSheet.webidl +++ b/dom/webidl/StyleSheet.webidl @@ -7,8 +7,6 @@ * http://dev.w3.org/csswg/cssom/ */ -interface CSSRule; - interface StyleSheet { [Constant] readonly attribute DOMString type; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index e7cc11cecc..904d299540 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -93,6 +93,7 @@ WEBIDL_FILES = [ 'CSSLexer.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', + 'CSSRule.webidl', 'CSSRuleList.webidl', 'CSSStyleDeclaration.webidl', 'CSSStyleSheet.webidl', diff --git a/layout/style/CSSRuleList.h b/layout/style/CSSRuleList.h index 786cc1b884..60ceec0db9 100644 --- a/layout/style/CSSRuleList.h +++ b/layout/style/CSSRuleList.h @@ -7,6 +7,7 @@ #define mozilla_dom_CSSRuleList_h #include "mozilla/StyleSheetInlines.h" +#include "mozilla/css/Rule.h" #include "nsIDOMCSSRule.h" #include "nsIDOMCSSRuleList.h" #include "nsWrapperCache.h" @@ -45,13 +46,13 @@ public: } // WebIDL API - nsIDOMCSSRule* Item(uint32_t aIndex) + css::Rule* Item(uint32_t aIndex) { bool unused; return IndexedGetter(aIndex, unused); } - virtual nsIDOMCSSRule* IndexedGetter(uint32_t aIndex, bool& aFound) = 0; + virtual css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) = 0; virtual uint32_t Length() = 0; protected: diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 1a3944fdb4..1307864c9d 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -61,7 +61,7 @@ public: virtual CSSStyleSheet* GetParentObject() override; - virtual nsIDOMCSSRule* + virtual css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) override; virtual uint32_t Length() override; @@ -101,7 +101,7 @@ CSSRuleListImpl::Length() return AssertedCast(mStyleSheet->StyleRuleCount()); } -nsIDOMCSSRule* +css::Rule* CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound) { aFound = false; @@ -1648,7 +1648,7 @@ CSSStyleSheet::Media() return mMedia; } -nsIDOMCSSRule* +css::Rule* CSSStyleSheet::GetDOMOwnerRule() const { return mOwnerRule; diff --git a/layout/style/CSSStyleSheet.h b/layout/style/CSSStyleSheet.h index 69028dcdc8..640a05340f 100644 --- a/layout/style/CSSStyleSheet.h +++ b/layout/style/CSSStyleSheet.h @@ -212,7 +212,7 @@ public: // Can't be inline because we can't include ImportRule here. And can't be // called GetOwnerRule because that would be ambiguous with the ImportRule // version. - nsIDOMCSSRule* GetDOMOwnerRule() const final; + css::Rule* GetDOMOwnerRule() const final; void WillDirty(); void DidDirty(); diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 00082c1e2c..ea6ca79f29 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -118,6 +118,11 @@ public: // WebIDL interface, aka helpers for nsIDOMCSSRule implementation. virtual uint16_t Type() const = 0; virtual void GetCssTextImpl(nsAString& aCssText) const = 0; + // XPCOM GetCssText is OK, since it never throws. + // XPCOM SetCssText is OK, since it never throws. + Rule* GetParentRule() const; + StyleSheet* GetParentStyleSheet() const { return GetStyleSheet(); } + nsIDocument* GetParentObject() const { return GetDocument(); } protected: // True if we're known-live for cycle collection purposes. @@ -137,4 +142,18 @@ protected: } // namespace css } // namespace mozilla +// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid +// adding an IID to css::Rule. This can go away once all css::Rule subclasses +// are on WebIDL bindings. + +#include "js/TypeDecls.h" + +namespace mozilla { +namespace dom { +template <> +nsresult +UnwrapArg(JS::Handle src, css::Rule** ppArg); +} // namepace dom +} // namespace mozilla + #endif /* mozilla_css_Rule_h___ */ diff --git a/layout/style/StyleSheet.h b/layout/style/StyleSheet.h index bbd455a02b..fd1e9b3652 100644 --- a/layout/style/StyleSheet.h +++ b/layout/style/StyleSheet.h @@ -29,6 +29,10 @@ class CSSRuleList; class SRIMetadata; } // namespace dom +namespace css { +class Rule; +} + /** * Superclass for CSSStyleSheet. */ @@ -145,7 +149,7 @@ public: // The XPCOM SetDisabled is fine for WebIDL. // WebIDL CSSStyleSheet API - virtual nsIDOMCSSRule* GetDOMOwnerRule() const = 0; + virtual css::Rule* GetDOMOwnerRule() const = 0; dom::CSSRuleList* GetCssRules(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv); uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index ff0b33eb25..e30cddc03e 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -45,6 +45,27 @@ using namespace mozilla::dom; // base class for all rule types in a CSS style sheet +// Temporary code that can go away once all css::Rules are on WebIDL bindings. +#include "xpcpublic.h" +namespace mozilla { +namespace dom { +template<> +nsresult +UnwrapArg(JS::Handle src, css::Rule** ppArg) +{ + MOZ_ASSERT(NS_IsMainThread()); + nsCOMPtr rule = + do_QueryInterface(xpc::UnwrapReflectorToISupports(src)); + if (!rule) { + return NS_NOINTERFACE; + } + *ppArg = rule->GetCSSRule(); + NS_ADDREF(*ppArg); + return NS_OK; +} +} // namespace dom +} // namespace mozilla + namespace mozilla { namespace css { @@ -153,6 +174,12 @@ Rule::GetCssText(nsAString& aCssText) return NS_OK; } +Rule* +Rule::GetParentRule() const +{ + return mParentRule; +} + // ------------------------------- // Style Rule List for group rules // @@ -164,7 +191,7 @@ public: virtual CSSStyleSheet* GetParentObject() override; - virtual nsIDOMCSSRule* + virtual Rule* IndexedGetter(uint32_t aIndex, bool& aFound) override; virtual uint32_t Length() override; @@ -209,7 +236,7 @@ GroupRuleRuleList::Length() return AssertedCast(mGroupRule->StyleRuleCount()); } -nsIDOMCSSRule* +Rule* GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) { aFound = false; From 264f152ba07ea85331000c470920e2b7bd7ad7a5 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 1 Apr 2024 14:42:27 +0200 Subject: [PATCH 11/22] Issue #2490 - Part 9b: Add a CSSRule Web IDL interface. Fix Paris bindings by providing a temporary IID for nsIDOMCSSRule (thanks FranklinDM!) --- dom/bindings/Bindings.conf | 2 +- layout/style/Rule.h | 22 ++++++++-------------- layout/style/nsCSSRules.cpp | 21 --------------------- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 33c812a542..43dfb627da 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -206,7 +206,7 @@ DOMInterfaces = { }, 'CSSRule': { -# 'hasXPConnectImpls': True, + 'hasXPConnectImpls': True, 'nativeType': 'mozilla::css::Rule' }, diff --git a/layout/style/Rule.h b/layout/style/Rule.h index ea6ca79f29..3537bad449 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -19,6 +19,11 @@ struct nsRuleData; template struct already_AddRefed; class nsHTMLCSSStyleSheet; +// Temporary IID for the nsIDOMCSSRule interface {ebb427f1-a935-480b-bd9b-bb0e3bd387a9} +#define NS_IDOM_CSSRULE_IID \ +{ 0xebb427f1, 0xa935, 0x480b, \ + { 0xbd, 0x9b, 0xbb, 0x0e, 0x3b, 0xd3, 0x87, 0xa9 } } + namespace mozilla { namespace css { class GroupRule; @@ -46,6 +51,7 @@ protected: virtual ~Rule() {} public: + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOM_CSSRULE_IID) NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Rule) @@ -139,21 +145,9 @@ protected: uint32_t mColumnNumber; }; +NS_DEFINE_STATIC_IID_ACCESSOR(Rule, NS_IDOM_CSSRULE_IID) + } // namespace css } // namespace mozilla -// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid -// adding an IID to css::Rule. This can go away once all css::Rule subclasses -// are on WebIDL bindings. - -#include "js/TypeDecls.h" - -namespace mozilla { -namespace dom { -template <> -nsresult -UnwrapArg(JS::Handle src, css::Rule** ppArg); -} // namepace dom -} // namespace mozilla - #endif /* mozilla_css_Rule_h___ */ diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index e30cddc03e..6ae33fc776 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -45,27 +45,6 @@ using namespace mozilla::dom; // base class for all rule types in a CSS style sheet -// Temporary code that can go away once all css::Rules are on WebIDL bindings. -#include "xpcpublic.h" -namespace mozilla { -namespace dom { -template<> -nsresult -UnwrapArg(JS::Handle src, css::Rule** ppArg) -{ - MOZ_ASSERT(NS_IsMainThread()); - nsCOMPtr rule = - do_QueryInterface(xpc::UnwrapReflectorToISupports(src)); - if (!rule) { - return NS_NOINTERFACE; - } - *ppArg = rule->GetCSSRule(); - NS_ADDREF(*ppArg); - return NS_OK; -} -} // namespace dom -} // namespace mozilla - namespace mozilla { namespace css { From 95642cb4e5a4fc92370d6bcb1458a0b802d87953 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 12:29:31 +0200 Subject: [PATCH 12/22] Issue #2490 - Part 10: Convert CSSNamespaceRule to WebIDL. --- dom/base/nsDOMClassInfo.cpp | 7 ------- dom/base/nsDOMClassInfoClasses.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/media/webaudio/AudioBuffer.h | 1 + dom/tests/mochitest/general/test_interfaces.html | 2 +- dom/webidl/CSSNamespaceRule.webidl | 16 ++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 7 ++----- 9 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 dom/webidl/CSSNamespaceRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 578b16fc66..f058bfa14b 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -198,9 +198,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSNameSpaceRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) // XUL classes #ifdef MOZ_XUL @@ -538,10 +535,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(CSSNameSpaceRule, nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_END - #ifdef MOZ_XUL DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index e381fb8f9b..12ae10ffc2 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -11,7 +11,6 @@ DOMCI_CLASS(DOMConstructor) DOMCI_CLASS(CSSStyleRule) DOMCI_CLASS(CSSImportRule) DOMCI_CLASS(CSSMediaRule) -DOMCI_CLASS(CSSNameSpaceRule) // XUL classes #ifdef MOZ_XUL diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 772c20bbc0..ed1cfa8650 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -20,7 +20,6 @@ class ProcessGlobal; } // namespace dom namespace css { class ImportRule; -class NameSpaceRule; class StyleRule; class MediaRule; class DocumentRule; @@ -294,7 +293,6 @@ private: friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; friend class mozilla::css::ImportRule; - friend class mozilla::css::NameSpaceRule; friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 43dfb627da..0e16cc78d9 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -201,12 +201,17 @@ DOMInterfaces = { 'wrapperCache': False }, +'CSSNamespaceRule': { + 'nativeType': 'mozilla::css::NameSpaceRule', +}, + 'CSSPrimitiveValue': { 'nativeType': 'nsROCSSPrimitiveValue', }, 'CSSRule': { 'hasXPConnectImpls': True, + 'concrete': False, 'nativeType': 'mozilla::css::Rule' }, diff --git a/dom/media/webaudio/AudioBuffer.h b/dom/media/webaudio/AudioBuffer.h index 15474b6c5c..e8722db77b 100644 --- a/dom/media/webaudio/AudioBuffer.h +++ b/dom/media/webaudio/AudioBuffer.h @@ -15,6 +15,7 @@ #include "AudioContext.h" #include "js/TypeDecls.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/dom/TypedArray.h" namespace mozilla { diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index 1354f381e9..13a76ce992 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -244,7 +244,7 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "CSSMozDocumentRule", // IMPORTANT: Do not change this list without review from a DOM peer! - "CSSNameSpaceRule", + "CSSNamespaceRule", // IMPORTANT: Do not change this list without review from a DOM peer! "CSSPageRule", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/webidl/CSSNamespaceRule.webidl b/dom/webidl/CSSNamespaceRule.webidl new file mode 100644 index 0000000000..0051c904a7 --- /dev/null +++ b/dom/webidl/CSSNamespaceRule.webidl @@ -0,0 +1,16 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#cssnamespacerule + */ + +// https://drafts.csswg.org/cssom/#cssnamespacerule +interface CSSNamespaceRule : CSSRule { + // Not implemented yet. . + // readonly attribute DOMString namespaceURI; + // readonly attribute DOMString prefix; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 904d299540..3f3ee0d50e 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -91,6 +91,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSLexer.webidl', + 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', 'CSSRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 6ae33fc776..1c746c7645 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -33,6 +33,7 @@ #include "nsCSSParser.h" #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" +#include "mozilla/dom/CSSNamespaceRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1109,7 +1110,6 @@ NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec, mPrefix(aPrefix), mURLSpec(aURLSpec) { - SetIsNotDOMBinding(); } NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) @@ -1117,7 +1117,6 @@ NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy) mPrefix(aCopy.mPrefix), mURLSpec(aCopy.mURLSpec) { - SetIsNotDOMBinding(); } NameSpaceRule::~NameSpaceRule() @@ -1137,7 +1136,6 @@ NS_INTERFACE_MAP_BEGIN(NameSpaceRule) return NS_OK; } else - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) bool @@ -1218,8 +1216,7 @@ NameSpaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const NameSpaceRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSNamespaceRuleBinding::Wrap(aCx, this, aGivenProto); } } // namespace css From 525606c15d19d11ce9286a8b37a46493a46bc319 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 13:22:41 +0200 Subject: [PATCH 13/22] Issue #2490 - Part 11: Convert CSSImportRule to WebIDL. Note that the .media PutForwards is a new feature coming along for the ride, now that we're using the spec IDL. --- dom/base/nsDOMClassInfo.cpp | 9 -------- dom/base/nsDOMClassInfoClasses.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 4 ++++ dom/webidl/CSSImportRule.webidl | 17 +++++++++++++++ dom/webidl/moz.build | 1 + js/xpconnect/tests/chrome/test_weakmaps.xul | 24 ++------------------- layout/style/ImportRule.h | 4 ++++ layout/style/nsCSSRules.cpp | 16 ++++++++------ 9 files changed, 38 insertions(+), 40 deletions(-) create mode 100644 dom/webidl/CSSImportRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index f058bfa14b..3b5a5a1f17 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSMozDocumentRule.h" @@ -192,9 +191,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSImportRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -525,11 +521,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 12ae10ffc2..90dbb32a72 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -9,7 +9,6 @@ DOMCI_CLASS(DOMConstructor) // CSS classes DOMCI_CLASS(CSSStyleRule) -DOMCI_CLASS(CSSImportRule) DOMCI_CLASS(CSSMediaRule) // XUL classes diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index ed1cfa8650..eb366e8baa 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,7 +19,6 @@ class TabChildGlobal; class ProcessGlobal; } // namespace dom namespace css { -class ImportRule; class StyleRule; class MediaRule; class DocumentRule; @@ -292,7 +291,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::ImportRule; friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 0e16cc78d9..08387439c7 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -197,6 +197,10 @@ DOMInterfaces = { 'nativeType': 'nsDOMCSSDeclaration' }, +'CSSImportRule': { + 'nativeType': 'mozilla::css::ImportRule', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSImportRule.webidl b/dom/webidl/CSSImportRule.webidl new file mode 100644 index 0000000000..7d3f17c794 --- /dev/null +++ b/dom/webidl/CSSImportRule.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#cssimportrule + */ + +// https://drafts.csswg.org/cssom/#cssimportrule +interface CSSImportRule : CSSRule { + readonly attribute DOMString href; + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; + // Per spec, the .styleSheet is never null, but in our implementation it can + // be. See . + [SameObject] readonly attribute CSSStyleSheet? styleSheet; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 3f3ee0d50e..820af99089 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,6 +90,7 @@ WEBIDL_FILES = [ 'CSPReport.webidl', 'CSS.webidl', 'CSSAnimation.webidl', + 'CSSImportRule.webidl', 'CSSLexer.webidl', 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', diff --git a/js/xpconnect/tests/chrome/test_weakmaps.xul b/js/xpconnect/tests/chrome/test_weakmaps.xul index e741a41c6c..9301b7b5d4 100644 --- a/js/xpconnect/tests/chrome/test_weakmaps.xul +++ b/js/xpconnect/tests/chrome/test_weakmaps.xul @@ -214,28 +214,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=668855 make_live_map(); - let unpreservable_native_key = function () { - // We only allow natives that support wrapper preservation to be used as weak - // map keys. We should be able to try to add unpreservable natives as keys without - // crashing (bug 711616), but we should throw an error (bug 761620). - - let dummy_test_map = new WeakMap; - - let rule_fail = false; - let got_rule = false; - try { - var rule = document.styleSheets[0].cssRules[0]; - got_rule = true; - dummy_test_map.set(rule, 1); - } catch (e) { - rule_fail = true; - } - ok(got_rule, "Got the CSS rule"); - ok(rule_fail, "Using a CSS rule as a weak map key should produce an exception because it can't be wrapper preserved."); - - } - - unpreservable_native_key(); + // We're out of ideas for unpreservable natives, now that just about + // everything is on webidl, so just don't test those. /* set up for running precise GC/CC then checking the results */ diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index dd12e65b3c..077349d017 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -20,6 +20,7 @@ class nsString; namespace mozilla { class CSSStyleSheet; +class StyleSheet; namespace css { @@ -61,6 +62,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetHref is fine, since it never fails. + nsMediaList* Media() const { return mMedia; } + StyleSheet* GetStyleSheet() const; private: nsString mURLSpec; diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 1c746c7645..a754ee48c0 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -34,6 +34,7 @@ #include "nsDOMClassInfoID.h" #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "mozilla/dom/CSSNamespaceRuleBinding.h" +#include "mozilla/dom/CSSImportRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -242,7 +243,7 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, , mURLSpec(aURLSpec) , mMedia(aMedia) { - SetIsNotDOMBinding(); + MOZ_ASSERT(aMedia); // XXXbz This is really silly.... the mMedia here will be replaced // with itself if we manage to load a sheet. Which should really // never fail nowadays, in sane cases. @@ -252,7 +253,6 @@ ImportRule::ImportRule(const ImportRule& aCopy) : Rule(aCopy), mURLSpec(aCopy.mURLSpec) { - SetIsNotDOMBinding(); // Whether or not an @import rule has a null sheet is a permanent // property of that @import rule, since it is null only if the target // sheet failed security checks. @@ -284,7 +284,6 @@ ImportRule::IsCCLeaf() const // QueryInterface implementation for ImportRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ImportRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_CYCLE_COLLECTION_CLASS(ImportRule) @@ -373,6 +372,12 @@ ImportRule::GetCssTextImpl(nsAString& aCssText) const aCssText.Append(';'); } +StyleSheet* +ImportRule::GetStyleSheet() const +{ + return mChildSheet; +} + NS_IMETHODIMP ImportRule::GetHref(nsAString & aHref) { @@ -385,7 +390,7 @@ ImportRule::GetMedia(nsIDOMMediaList * *aMedia) { NS_ENSURE_ARG_POINTER(aMedia); - NS_IF_ADDREF(*aMedia = mMedia); + NS_ADDREF(*aMedia = mMedia); return NS_OK; } @@ -416,8 +421,7 @@ ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const ImportRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSImportRuleBinding::Wrap(aCx, this, aGivenProto); } GroupRule::GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber) From 6176bd62d9b768fac966d30f5275f3fcd4b99003 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 13:59:06 +0200 Subject: [PATCH 14/22] Issue #2490 - Part 12: Convert CSSStyleRule to WebIDL. The .style PutForwards bit is coming along for the ride here, aligning us with the behavior of Blink and Gecko. --- dom/base/nsDOMClassInfo.cpp | 17 ------ dom/base/nsDOMClassInfoClasses.h | 1 - dom/base/nsWrapperCache.h | 2 - dom/bindings/Bindings.conf | 4 ++ dom/webidl/CSSStyleRule.webidl | 14 +++++ dom/webidl/LegacyQueryInterface.webidl | 1 + dom/webidl/moz.build | 1 + .../file_crosscompartment_weakmap.html | 1 - .../test_crosscompartment_weakmap.html | 8 --- layout/style/BindingStyleRule.cpp | 18 ++++++ layout/style/BindingStyleRule.h | 60 +++++++++++++++++++ layout/style/StyleRule.cpp | 35 +++++------ layout/style/StyleRule.h | 7 +-- layout/style/moz.build | 13 +++- layout/style/nsICSSStyleRuleDOMWrapper.h | 5 ++ 15 files changed, 132 insertions(+), 55 deletions(-) create mode 100644 dom/webidl/CSSStyleRule.webidl create mode 100644 layout/style/BindingStyleRule.cpp create mode 100644 layout/style/BindingStyleRule.h diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 3b5a5a1f17..18115dbba2 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -80,7 +80,6 @@ #include "nsIDOMCSSSupportsRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMCSSPageRule.h" -#include "nsIDOMCSSStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -188,9 +187,6 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSStyleRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -516,11 +512,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSStyleRule, nsIDOMCSSStyleRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSStyleRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) @@ -2000,14 +1991,6 @@ nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, return NS_ERROR_UNEXPECTED; } css::Rule* cssRule = rule->GetCSSRule(); - if (!cssRule) { - // A DOMCSSStyleRule whose actual underlying rule has gone away. There - // isn't much a caller can do with this thing anyway, and only chrome code - // can get its hands on it to start with, so just wrap in the current - // global. - *parentObj = globalObj; - return NS_OK; - } nsIDocument* doc = cssRule->GetDocument(); if (!doc) { *parentObj = globalObj; diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 90dbb32a72..ff3e57f60c 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -8,7 +8,6 @@ DOMCI_CLASS(DOMPrototype) DOMCI_CLASS(DOMConstructor) // CSS classes -DOMCI_CLASS(CSSStyleRule) DOMCI_CLASS(CSSMediaRule) // XUL classes diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index eb366e8baa..df83a8f234 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -19,7 +19,6 @@ class TabChildGlobal; class ProcessGlobal; } // namespace dom namespace css { -class StyleRule; class MediaRule; class DocumentRule; } // namespace css @@ -291,7 +290,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::StyleRule; friend class mozilla::css::MediaRule; friend class mozilla::css::DocumentRule; friend class mozilla::CSSSupportsRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 08387439c7..5c91365834 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -223,6 +223,10 @@ DOMInterfaces = { 'nativeType': 'nsICSSDeclaration' }, +'CSSStyleRule': { + 'nativeType': 'mozilla::BindingStyleRule', +}, + 'CSSStyleSheet': { 'nativeType': 'mozilla::StyleSheet', 'binaryNames': { 'ownerRule': 'DOMOwnerRule' }, diff --git a/dom/webidl/CSSStyleRule.webidl b/dom/webidl/CSSStyleRule.webidl new file mode 100644 index 0000000000..571bd6a57f --- /dev/null +++ b/dom/webidl/CSSStyleRule.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#the-cssstylerule-interface + */ + +// https://drafts.csswg.org/cssom/#the-cssstylerule-interface +interface CSSStyleRule : CSSRule { + attribute DOMString selectorText; + [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/LegacyQueryInterface.webidl b/dom/webidl/LegacyQueryInterface.webidl index 96048b03ca..41bbd025ff 100644 --- a/dom/webidl/LegacyQueryInterface.webidl +++ b/dom/webidl/LegacyQueryInterface.webidl @@ -26,6 +26,7 @@ Comment implements LegacyQueryInterface; Crypto implements LegacyQueryInterface; CSSPrimitiveValue implements LegacyQueryInterface; CSSStyleDeclaration implements LegacyQueryInterface; +CSSStyleRule implements LegacyQueryInterface; CSSValueList implements LegacyQueryInterface; DOMImplementation implements LegacyQueryInterface; DOMParser implements LegacyQueryInterface; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 820af99089..3f20beac79 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -98,6 +98,7 @@ WEBIDL_FILES = [ 'CSSRule.webidl', 'CSSRuleList.webidl', 'CSSStyleDeclaration.webidl', + 'CSSStyleRule.webidl', 'CSSStyleSheet.webidl', 'CSSTransition.webidl', 'CSSValue.webidl', diff --git a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html index b25cdb2f90..127c479ebe 100644 --- a/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/file_crosscompartment_weakmap.html @@ -1,7 +1,6 @@ - Test Cross-Compartment DOM WeakMaps diff --git a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html index e50b1f1bd8..54658d17bc 100644 --- a/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html +++ b/js/xpconnect/tests/mochitest/test_crosscompartment_weakmap.html @@ -15,14 +15,6 @@ function setup() { var item = window.frames[0].document.querySelector("body"); my_map.set(item, "success_string"); - - var rule_fail = false; - try { - my_map.set(window.frames[0].document.styleSheets[0].cssRules[0], 1); - } catch (e) { - rule_fail = true; - } - ok(rule_fail, "Using rule as a weak map key across compartments should produce an exception because it can't be wrapper preserved."); } function runTest() { diff --git a/layout/style/BindingStyleRule.cpp b/layout/style/BindingStyleRule.cpp new file mode 100644 index 0000000000..9cdbc46cdd --- /dev/null +++ b/layout/style/BindingStyleRule.cpp @@ -0,0 +1,18 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/BindingStyleRule.h" +#include "mozilla/dom/CSSStyleRuleBinding.h" + +namespace mozilla { + +/* virtual */ JSObject* +BindingStyleRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + return dom::CSSStyleRuleBinding::Wrap(aCx, this, aGivenProto); +} + +} // namespace mozilla diff --git a/layout/style/BindingStyleRule.h b/layout/style/BindingStyleRule.h new file mode 100644 index 0000000000..e371bc1149 --- /dev/null +++ b/layout/style/BindingStyleRule.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_BindingStyleRule_h__ +#define mozilla_BindingStyleRule_h__ + +#include "nscore.h" +#include "nsStringGlue.h" +#include "mozilla/css/Rule.h" + +/** + * Superclass for mozilla::css::StyleRule, for use from bindings code. + */ + +class nsICSSDeclaration; + +namespace mozilla { + +class BindingStyleRule : public css::Rule +{ +protected: + BindingStyleRule(uint32_t aLineNumber, uint32_t aColumnNumber) + : css::Rule(aLineNumber, aColumnNumber) + { + } + BindingStyleRule(const BindingStyleRule& aCopy) + : css::Rule(aCopy) + { + } + virtual ~BindingStyleRule() {} + +public: + // This is pure virtual because we have no members, and are an abstract class + // to start with. The fact that we have to have this declaration at all is + // kinda dumb. :( + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) + const override MOZ_MUST_OVERRIDE = 0; + + // Likewise for this one. We have to override our superclass, but don't + // really need to do anything in this method. + virtual bool IsCCLeaf() const override MOZ_MUST_OVERRIDE = 0; + + // WebIDL API + // For GetSelectorText/SetSelectorText, we purposefully use a signature that + // matches the nsIDOMCSSStyleRule one for now, so subclasses can just + // implement both at once. The actual implementations must never return + // anything other than NS_OK; + NS_IMETHOD GetSelectorText(nsAString& aSelectorText) = 0; + NS_IMETHOD SetSelectorText(const nsAString& aSelectorText) = 0; + virtual nsICSSDeclaration* Style() = 0; + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; +}; + +} // namespace mozilla + +#endif // mozilla_BindingStyleRule_h__ diff --git a/layout/style/StyleRule.cpp b/layout/style/StyleRule.cpp index cf5952a650..97a17d2871 100644 --- a/layout/style/StyleRule.cpp +++ b/layout/style/StyleRule.cpp @@ -15,6 +15,7 @@ #include "mozilla/MemoryReporting.h" #include "mozilla/css/GroupRule.h" #include "mozilla/css/Declaration.h" +#include "mozilla/dom/CSSStyleRuleBinding.h" #include "nsIDocument.h" #include "nsIAtom.h" #include "nsString.h" @@ -26,7 +27,6 @@ #include "nsCSSPseudoClasses.h" #include "nsCSSAnonBoxes.h" #include "nsTArray.h" -#include "nsDOMClassInfoID.h" #include "nsContentUtils.h" #include "nsError.h" #include "mozAutoDocUpdate.h" @@ -1235,13 +1235,18 @@ StyleRule::Type() const NS_IMETHODIMP StyleRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +StyleRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration.reset(new DOMCSSDeclarationImpl(this)); } - *aStyle = mDOMDeclaration.get(); - NS_ADDREF(*aStyle); - return NS_OK; + return mDOMDeclaration.get(); } NS_IMETHODIMP @@ -1256,11 +1261,10 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, Declaration* aDeclaration, uint32_t aLineNumber, uint32_t aColumnNumber) - : Rule(aLineNumber, aColumnNumber), - mSelector(aSelector), - mDeclaration(aDeclaration) + : BindingStyleRule(aLineNumber, aColumnNumber) + , mSelector(aSelector) + , mDeclaration(aDeclaration) { - SetIsNotDOMBinding(); NS_PRECONDITION(aDeclaration, "must have a declaration"); mDeclaration->SetOwningRule(this); @@ -1268,11 +1272,10 @@ StyleRule::StyleRule(nsCSSSelectorList* aSelector, // for |Clone| StyleRule::StyleRule(const StyleRule& aCopy) - : Rule(aCopy), - mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr), - mDeclaration(new Declaration(*aCopy.mDeclaration)) + : BindingStyleRule(aCopy) + , mSelector(aCopy.mSelector ? aCopy.mSelector->Clone() : nullptr) + , mDeclaration(new Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); // rest is constructed lazily on existing data } @@ -1301,7 +1304,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(StyleRule) else NS_INTERFACE_MAP_ENTRY(nsICSSStyleRuleDOMWrapper) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleRule) NS_INTERFACE_MAP_END_INHERITING(Rule) NS_IMPL_ADDREF_INHERITED(StyleRule, Rule) @@ -1496,12 +1498,5 @@ StyleRule::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const return n; } -/* virtual */ JSObject* -StyleRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) -{ - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; -} - } // namespace css } // namespace mozilla diff --git a/layout/style/StyleRule.h b/layout/style/StyleRule.h index 55ec693a38..ba10542c78 100644 --- a/layout/style/StyleRule.h +++ b/layout/style/StyleRule.h @@ -14,7 +14,7 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" #include "mozilla/UniquePtr.h" -#include "mozilla/css/Rule.h" +#include "mozilla/BindingStyleRule.h" #include "nsString.h" #include "nsCOMPtr.h" @@ -325,7 +325,7 @@ namespace css { class Declaration; -class StyleRule final : public Rule +class StyleRule final : public BindingStyleRule , public nsICSSStyleRuleDOMWrapper { public: @@ -350,6 +350,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + virtual nsICSSDeclaration* Style() override; // null for style attribute nsCSSSelectorList* Selector() { return mSelector; } @@ -369,8 +370,6 @@ public: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; - virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - private: ~StyleRule(); diff --git a/layout/style/moz.build b/layout/style/moz.build index 7239526aa8..1212a92d10 100644 --- a/layout/style/moz.build +++ b/layout/style/moz.build @@ -74,6 +74,7 @@ EXPORTS += [ EXPORTS.mozilla += [ 'AnimationCollection.h', + 'BindingStyleRule.h', 'CSSEnabledState.h', 'CSSStyleSheet.h', 'CSSVariableDeclarations.h', @@ -177,10 +178,18 @@ UNIFIED_SOURCES += [ 'SVGAttrAnimationRuleProcessor.cpp', ] -# nsCSSRuleProcessor.cpp needs to be built separately because it uses plarena.h. -# nsLayoutStylesheetCache.cpp needs to be built separately because it uses +# - BindingStyleRule.cpp doesn't necessarily need to be built separately, +# however, it may shift unified build boundaries, causing +# the Unified CPP containing it to include nsStyleCoord.cpp, which +# includes, via nsStyleCoord.h, , which ends up including +# , which fails in much the way described in +# . +# - nsCSSRuleProcessor.cpp needs to be built separately because it uses +# plarena.h. +# - nsLayoutStylesheetCache.cpp needs to be built separately because it uses # nsExceptionHandler.h, which includes windows.h. SOURCES += [ + 'BindingStyleRule.cpp', 'nsCSSRuleProcessor.cpp', 'nsLayoutStylesheetCache.cpp', ] diff --git a/layout/style/nsICSSStyleRuleDOMWrapper.h b/layout/style/nsICSSStyleRuleDOMWrapper.h index 038cca0868..f2a3b6ccc9 100644 --- a/layout/style/nsICSSStyleRuleDOMWrapper.h +++ b/layout/style/nsICSSStyleRuleDOMWrapper.h @@ -18,6 +18,11 @@ #define NS_ICSS_STYLE_RULE_DOM_WRAPPER_IID \ {0xcee1bbb6, 0x0a32, 0x4cf3, {0x8d, 0x42, 0xba, 0x39, 0x38, 0xe9, 0xec, 0xaa}} +namespace mozilla { +namespace css { +class StyleRule; +} // namespace css +} // namespace mozilla class nsICSSStyleRuleDOMWrapper : public nsIDOMCSSStyleRule { public: From d1b6a584b8a329d3e3f068345507366a49c39705 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 15:52:14 +0200 Subject: [PATCH 15/22] Issue #2490 - Part 13: Convert media, supports, and moz-document rules to WebIDL. This also converts the internal ConditionRule and GroupingRule classes. --- dom/base/nsDOMClassInfo.cpp | 31 ----- dom/base/nsDOMClassInfoClasses.h | 6 - dom/base/nsWrapperCache.h | 9 +- dom/bindings/Bindings.conf | 26 ++++ dom/webidl/CSSConditionRule.webidl | 14 ++ dom/webidl/CSSGroupingRule.webidl | 17 +++ dom/webidl/CSSMediaRule.webidl | 17 +++ dom/webidl/CSSMozDocumentRule.webidl | 10 ++ dom/webidl/CSSSupportsRule.webidl | 12 ++ dom/webidl/LegacyQueryInterface.webidl | 1 + dom/webidl/moz.build | 5 + layout/style/GroupRule.h | 29 +++++ layout/style/nsCSSRules.cpp | 172 ++++++++++++++++++------- layout/style/nsCSSRules.h | 18 ++- 14 files changed, 273 insertions(+), 94 deletions(-) create mode 100644 dom/webidl/CSSConditionRule.webidl create mode 100644 dom/webidl/CSSGroupingRule.webidl create mode 100644 dom/webidl/CSSMediaRule.webidl create mode 100644 dom/webidl/CSSMozDocumentRule.webidl create mode 100644 dom/webidl/CSSSupportsRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 18115dbba2..7659795dcb 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,10 +74,7 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSFontFaceRule.h" -#include "nsIDOMCSSMozDocumentRule.h" -#include "nsIDOMCSSSupportsRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMCSSPageRule.h" #include "nsIDOMXULCommandDispatcher.h" @@ -186,11 +183,6 @@ static nsDOMClassInfoData sClassInfoData[] = { // Misc Core related classes - // CSS classes - NS_DEFINE_CLASSINFO_DATA(CSSMediaRule, nsCSSRuleSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - // XUL classes #ifdef MOZ_XUL NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULCommandDispatcher, nsDOMGenericSH, @@ -213,14 +205,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(CSSMozDocumentRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - - NS_DEFINE_CLASSINFO_DATA(CSSSupportsRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -512,11 +496,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMDOMConstructor) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMediaRule) - DOM_CLASSINFO_MAP_END - #ifdef MOZ_XUL DOM_CLASSINFO_MAP_BEGIN(XULCommandDispatcher, nsIDOMXULCommandDispatcher) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULCommandDispatcher) @@ -550,16 +529,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END #endif - DOM_CLASSINFO_MAP_BEGIN(CSSMozDocumentRule, nsIDOMCSSMozDocumentRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - DOM_CLASSINFO_MAP_END - - DOM_CLASSINFO_MAP_BEGIN(CSSSupportsRule, nsIDOMCSSSupportsRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSSupportsRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index ff3e57f60c..1488b56b87 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -7,9 +7,6 @@ DOMCI_CLASS(DOMPrototype) DOMCI_CLASS(DOMConstructor) -// CSS classes -DOMCI_CLASS(CSSMediaRule) - // XUL classes #ifdef MOZ_XUL DOMCI_CLASS(XULCommandDispatcher) @@ -25,9 +22,6 @@ DOMCI_CLASS(XULTemplateBuilder) DOMCI_CLASS(XULTreeBuilder) #endif -DOMCI_CLASS(CSSMozDocumentRule) -DOMCI_CLASS(CSSSupportsRule) - // @font-face in CSS DOMCI_CLASS(CSSFontFaceRule) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index df83a8f234..120dfb48ba 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -18,12 +18,8 @@ namespace dom { class TabChildGlobal; class ProcessGlobal; } // namespace dom -namespace css { -class MediaRule; -class DocumentRule; -} // namespace css -class CSSSupportsRule; } // namespace mozilla + class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; @@ -290,9 +286,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class mozilla::css::MediaRule; - friend class mozilla::css::DocumentRule; - friend class mozilla::CSSSupportsRule; friend class nsCSSFontFaceRule; friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 5c91365834..17772d1751 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -197,6 +197,17 @@ DOMInterfaces = { 'nativeType': 'nsDOMCSSDeclaration' }, +'CSSConditionRule': { + 'concrete': False, + 'nativeType': 'mozilla::css::ConditionRule', + 'headerFile': 'mozilla/css/GroupRule.h', +}, + +'CSSGroupingRule': { + 'concrete': False, + 'nativeType': 'mozilla::css::GroupRule', +}, + 'CSSImportRule': { 'nativeType': 'mozilla::css::ImportRule', }, @@ -205,6 +216,16 @@ DOMInterfaces = { 'wrapperCache': False }, +'CSSMediaRule': { + 'nativeType': 'mozilla::css::MediaRule', + 'headerFile': 'nsCSSRules.h', +}, + +'CSSMozDocumentRule': { + 'nativeType': 'mozilla::css::DocumentRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSNamespaceRule': { 'nativeType': 'mozilla::css::NameSpaceRule', }, @@ -232,6 +253,11 @@ DOMInterfaces = { 'binaryNames': { 'ownerRule': 'DOMOwnerRule' }, }, +'CSSSupportsRule': { + 'nativeType': 'mozilla::CSSSupportsRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSValue': { 'concrete': False }, diff --git a/dom/webidl/CSSConditionRule.webidl b/dom/webidl/CSSConditionRule.webidl new file mode 100644 index 0000000000..24fae2343c --- /dev/null +++ b/dom/webidl/CSSConditionRule.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-conditional/#the-cssconditionrule-interface + */ + +// https://drafts.csswg.org/css-conditional/#the-cssconditionrule-interface +interface CSSConditionRule : CSSGroupingRule { + [SetterThrows] + attribute DOMString conditionText; +}; diff --git a/dom/webidl/CSSGroupingRule.webidl b/dom/webidl/CSSGroupingRule.webidl new file mode 100644 index 0000000000..bc1023fe20 --- /dev/null +++ b/dom/webidl/CSSGroupingRule.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#cssgroupingrule + */ + +// https://drafts.csswg.org/cssom/#cssgroupingrule +interface CSSGroupingRule : CSSRule { + [SameObject] readonly attribute CSSRuleList cssRules; + [Throws] + unsigned long insertRule(DOMString rule, unsigned long index); + [Throws] + void deleteRule(unsigned long index); +}; diff --git a/dom/webidl/CSSMediaRule.webidl b/dom/webidl/CSSMediaRule.webidl new file mode 100644 index 0000000000..841a1b6f6b --- /dev/null +++ b/dom/webidl/CSSMediaRule.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#the-cssmediarule-interface + * https://drafts.csswg.org/css-conditional/#the-cssmediarule-interface + */ + +// https://drafts.csswg.org/cssom/#the-cssmediarule-interface and +// https://drafts.csswg.org/css-conditional/#the-cssmediarule-interface +// except they disagree with each other. We're taking the inheritance from +// css-conditional and the PutForwards behavior from cssom. +interface CSSMediaRule : CSSConditionRule { + [SameObject, PutForwards=mediaText] readonly attribute MediaList media; +}; diff --git a/dom/webidl/CSSMozDocumentRule.webidl b/dom/webidl/CSSMozDocumentRule.webidl new file mode 100644 index 0000000000..27a22d52c7 --- /dev/null +++ b/dom/webidl/CSSMozDocumentRule.webidl @@ -0,0 +1,10 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// This is a non-standard interface for @-moz-document rules +interface CSSMozDocumentRule : CSSConditionRule { + // XXX Add access to the URL list. +}; diff --git a/dom/webidl/CSSSupportsRule.webidl b/dom/webidl/CSSSupportsRule.webidl new file mode 100644 index 0000000000..0576e90ebd --- /dev/null +++ b/dom/webidl/CSSSupportsRule.webidl @@ -0,0 +1,12 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-conditional/#the-csssupportsrule-interface + */ + +// https://drafts.csswg.org/css-conditional/#the-csssupportsrule-interface +interface CSSSupportsRule : CSSConditionRule { +}; diff --git a/dom/webidl/LegacyQueryInterface.webidl b/dom/webidl/LegacyQueryInterface.webidl index 41bbd025ff..a2f7b9dc64 100644 --- a/dom/webidl/LegacyQueryInterface.webidl +++ b/dom/webidl/LegacyQueryInterface.webidl @@ -24,6 +24,7 @@ BoxObject implements LegacyQueryInterface; CaretPosition implements LegacyQueryInterface; Comment implements LegacyQueryInterface; Crypto implements LegacyQueryInterface; +CSSMozDocumentRule implements LegacyQueryInterface; CSSPrimitiveValue implements LegacyQueryInterface; CSSStyleDeclaration implements LegacyQueryInterface; CSSStyleRule implements LegacyQueryInterface; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 3f20beac79..c5dcf1db69 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -90,8 +90,12 @@ WEBIDL_FILES = [ 'CSPReport.webidl', 'CSS.webidl', 'CSSAnimation.webidl', + 'CSSConditionRule.webidl', + 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', + 'CSSMediaRule.webidl', + 'CSSMozDocumentRule.webidl', 'CSSNamespaceRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', @@ -100,6 +104,7 @@ WEBIDL_FILES = [ 'CSSStyleDeclaration.webidl', 'CSSStyleRule.webidl', 'CSSStyleSheet.webidl', + 'CSSSupportsRule.webidl', 'CSSTransition.webidl', 'CSSValue.webidl', 'CSSValueList.webidl', diff --git a/layout/style/GroupRule.h b/layout/style/GroupRule.h index dae429d663..d153053ed4 100644 --- a/layout/style/GroupRule.h +++ b/layout/style/GroupRule.h @@ -12,6 +12,7 @@ #define mozilla_css_GroupRule_h__ #include "mozilla/Attributes.h" +#include "mozilla/ErrorResult.h" #include "mozilla/IncrementalClearCOMRuleArray.h" #include "mozilla/MemoryReporting.h" #include "mozilla/css/Rule.h" @@ -24,6 +25,10 @@ namespace mozilla { class CSSStyleSheet; +namespace dom { +class CSSRuleList; +} // namespace dom + namespace css { class GroupRuleRuleList; @@ -79,6 +84,12 @@ public: return true; } + // WebIDL API + dom::CSSRuleList* CssRules(); + uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex, + ErrorResult& aRv); + void DeleteRule(uint32_t aIndex, ErrorResult& aRv); + protected: // to help implement nsIDOMCSSRule void AppendRulesToCssText(nsAString& aCssText) const; @@ -94,6 +105,24 @@ protected: RefPtr mRuleCollection; // lazily constructed }; +// Implementation of WebIDL CSSConditionRule. +class ConditionRule : public GroupRule +{ +protected: + ConditionRule(uint32_t aLineNumber, uint32_t aColumnNumber); + ConditionRule(const ConditionRule& aCopy); + virtual ~ConditionRule(); + +public: + + // GetConditionText signature matches nsIDOMCSSConditionRule, so subclasses + // can implement this easily. The implementations should never return + // anything other than NS_OK. + NS_IMETHOD GetConditionText(nsAString& aConditionText) = 0; + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) = 0; +}; + } // namespace css } // namespace mozilla diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index a754ee48c0..3b65ab2219 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -35,6 +35,9 @@ #include "mozilla/dom/CSSStyleDeclarationBinding.h" #include "mozilla/dom/CSSNamespaceRuleBinding.h" #include "mozilla/dom/CSSImportRuleBinding.h" +#include "mozilla/dom/CSSMediaRuleBinding.h" +#include "mozilla/dom/CSSSupportsRuleBinding.h" +#include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -602,43 +605,85 @@ GroupRule::AppendRulesToCssText(nsAString& aCssText) const // nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods nsresult GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList) +{ + NS_ADDREF(*aRuleList = CssRules()); + return NS_OK; +} + +CSSRuleList* +GroupRule::CssRules() { if (!mRuleCollection) { mRuleCollection = new css::GroupRuleRuleList(this); } - NS_ADDREF(*aRuleList = mRuleCollection); - return NS_OK; + return mRuleCollection; } nsresult GroupRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval) +{ + ErrorResult rv; + *_retval = InsertRule(aRule, aIndex, rv); + return rv.StealNSResult(); +} + +uint32_t +GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex, ErrorResult& aRv) { CSSStyleSheet* sheet = GetStyleSheet(); - NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); - - if (aIndex > uint32_t(mRules.Count())) - return NS_ERROR_DOM_INDEX_SIZE_ERR; + if (NS_WARN_IF(!sheet)) { + aRv.Throw(NS_ERROR_FAILURE); + return 0; + } + + if (aIndex > uint32_t(mRules.Count())) { + aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return 0; + } NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX, "Too many style rules!"); - return sheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval); + uint32_t retval; + nsresult rv = + sheet->InsertRuleIntoGroup(aRule, this, aIndex, &retval); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + return 0; + } + return retval; } nsresult GroupRule::DeleteRule(uint32_t aIndex) { - CSSStyleSheet* sheet = GetStyleSheet(); - NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE); + ErrorResult rv; + DeleteRule(aIndex, rv); + return rv.StealNSResult(); +} - if (aIndex >= uint32_t(mRules.Count())) - return NS_ERROR_DOM_INDEX_SIZE_ERR; +void +GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) +{ + CSSStyleSheet* sheet = GetStyleSheet(); + if (NS_WARN_IF(!sheet)) { + aRv.Throw(NS_ERROR_FAILURE); + return; + } + + if (aIndex >= uint32_t(mRules.Count())) { + aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); + return; + } NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX, "Too many style rules!"); - return sheet->DeleteRuleFromGroup(this, aIndex); + nsresult rv = sheet->DeleteRuleFromGroup(this, aIndex); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } /* virtual */ size_t @@ -655,20 +700,31 @@ GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const return n; } +ConditionRule::ConditionRule(uint32_t aLineNumber, uint32_t aColumnNumber) + : GroupRule(aLineNumber, aColumnNumber) +{ +} + +ConditionRule::ConditionRule(const ConditionRule& aCopy) + : GroupRule(aCopy) +{ +} + +ConditionRule::~ConditionRule() +{ +} // ------------------------------------------- // nsICSSMediaRule // MediaRule::MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : GroupRule(aLineNumber, aColumnNumber) + : ConditionRule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } MediaRule::MediaRule(const MediaRule& aCopy) - : GroupRule(aCopy) + : ConditionRule(aCopy) { - SetIsNotDOMBinding(); if (aCopy.mMedia) { mMedia = aCopy.mMedia->Clone(); // XXXldb This doesn't really make sense. @@ -683,18 +739,17 @@ MediaRule::~MediaRule() } } -NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule) -NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule) +NS_IMPL_ADDREF_INHERITED(MediaRule, ConditionRule) +NS_IMPL_RELEASE_INHERITED(MediaRule, ConditionRule) // QueryInterface implementation for MediaRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) -NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, GroupRule, +NS_IMPL_CYCLE_COLLECTION_INHERITED(MediaRule, ConditionRule, mMedia) /* virtual */ void @@ -764,6 +819,14 @@ MediaRule::Type() const return nsIDOMCSSRule::MEDIA_RULE; } +nsMediaList* +MediaRule::Media() const +{ + // In practice, if we end up being parsed at all, we have non-null mMedia. So + // it's OK to claim we don't return null here. + return mMedia; +} + void MediaRule::GetCssTextImpl(nsAString& aCssText) const { @@ -802,6 +865,15 @@ MediaRule::GetConditionText(nsAString& aConditionText) NS_IMETHODIMP MediaRule::SetConditionText(const nsAString& aConditionText) +{ + ErrorResult rv; + SetConditionText(aConditionText, rv); + return rv.StealNSResult(); +} + +void +MediaRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) { if (!mMedia) { RefPtr media = new nsMediaList(); @@ -809,11 +881,16 @@ MediaRule::SetConditionText(const nsAString& aConditionText) nsresult rv = media->SetMediaText(aConditionText); if (NS_SUCCEEDED(rv)) { mMedia = media; + } else { + aRv.Throw(rv); } - return rv; + return; } - return mMedia->SetMediaText(aConditionText); + nsresult rv = mMedia->SetMediaText(aConditionText); + if (NS_FAILED(rv)) { + aRv.Throw(rv); + } } // nsIDOMCSSMediaRule methods @@ -852,8 +929,7 @@ MediaRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const /* virtual */ JSObject* MediaRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSMediaRuleBinding::Wrap(aCx, this, aGivenProto); } void @@ -867,32 +943,29 @@ MediaRule::AppendConditionText(nsAString& aOutput) const } DocumentRule::DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber) - : GroupRule(aLineNumber, aColumnNumber) + : ConditionRule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } DocumentRule::DocumentRule(const DocumentRule& aCopy) - : GroupRule(aCopy) + : ConditionRule(aCopy) , mURLs(new URL(*aCopy.mURLs)) { - SetIsNotDOMBinding(); } DocumentRule::~DocumentRule() { } -NS_IMPL_ADDREF_INHERITED(DocumentRule, GroupRule) -NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule) +NS_IMPL_ADDREF_INHERITED(DocumentRule, ConditionRule) +NS_IMPL_RELEASE_INHERITED(DocumentRule, ConditionRule) // QueryInterface implementation for DocumentRule NS_INTERFACE_MAP_BEGIN(DocumentRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) #ifdef DEBUG /* virtual */ void @@ -996,6 +1069,13 @@ DocumentRule::SetConditionText(const nsAString& aConditionText) return NS_ERROR_NOT_IMPLEMENTED; } +void +DocumentRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + // GroupRule interface /* virtual */ bool DocumentRule::UseForPresentation(nsPresContext* aPresContext, @@ -1075,8 +1155,7 @@ DocumentRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const DocumentRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSMozDocumentRuleBinding::Wrap(aCx, this, aGivenProto); } void @@ -2659,11 +2738,10 @@ namespace mozilla { CSSSupportsRule::CSSSupportsRule(bool aConditionMet, const nsString& aCondition, uint32_t aLineNumber, uint32_t aColumnNumber) - : css::GroupRule(aLineNumber, aColumnNumber) + : css::ConditionRule(aLineNumber, aColumnNumber) , mUseGroup(aConditionMet) , mCondition(aCondition) { - SetIsNotDOMBinding(); } CSSSupportsRule::~CSSSupportsRule() @@ -2671,11 +2749,10 @@ CSSSupportsRule::~CSSSupportsRule() } CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy) - : css::GroupRule(aCopy), + : css::ConditionRule(aCopy), mUseGroup(aCopy.mUseGroup), mCondition(aCopy.mCondition) { - SetIsNotDOMBinding(); } #ifdef DEBUG @@ -2716,16 +2793,15 @@ CSSSupportsRule::UseForPresentation(nsPresContext* aPresContext, return mUseGroup; } -NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::GroupRule) -NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule) +NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::ConditionRule) +NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::ConditionRule) // QueryInterface implementation for CSSSupportsRule NS_INTERFACE_MAP_BEGIN(CSSSupportsRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule) -NS_INTERFACE_MAP_END_INHERITING(GroupRule) +NS_INTERFACE_MAP_END_INHERITING(ConditionRule) uint16_t CSSSupportsRule::Type() const @@ -2774,6 +2850,13 @@ CSSSupportsRule::SetConditionText(const nsAString& aConditionText) return NS_ERROR_NOT_IMPLEMENTED; } +void +CSSSupportsRule::SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + /* virtual */ size_t CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { @@ -2787,8 +2870,7 @@ CSSSupportsRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const CSSSupportsRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSSupportsRuleBinding::Wrap(aCx, this, aGivenProto); } } // namespace mozilla diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 2aa18b1387..18e1dc0fd7 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -46,7 +46,7 @@ class ErrorResult; namespace css { -class MediaRule final : public GroupRule, +class MediaRule final : public ConditionRule, public nsIDOMCSSMediaRule { public: @@ -56,7 +56,7 @@ private: ~MediaRule(); public: - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, GroupRule) + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, ConditionRule) NS_DECL_ISUPPORTS_INHERITED // Rule methods @@ -87,6 +87,10 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; + nsMediaList* Media() const; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -100,7 +104,7 @@ protected: RefPtr mMedia; }; -class DocumentRule final : public GroupRule, +class DocumentRule final : public ConditionRule, public nsIDOMCSSMozDocumentRule { public: @@ -162,6 +166,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override MOZ_MUST_OVERRIDE; @@ -578,7 +585,7 @@ private: namespace mozilla { -class CSSSupportsRule final : public css::GroupRule, +class CSSSupportsRule final : public css::ConditionRule, public nsIDOMCSSSupportsRule { public: @@ -610,6 +617,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetConditionText is OK + virtual void SetConditionText(const nsAString& aConditionText, + ErrorResult& aRv) override; virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; From 74fdaed1fea57175b8060de82b6c9c983adf31a6 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 16:47:23 +0200 Subject: [PATCH 16/22] Issue #2490 - Part 14: Convert CSSPageRule to WebIDL. The .style PutForwards bit is coming along for the ride here as a new feature. --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoClasses.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSPageRule.webidl | 17 +++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 16 ++++++++++------ layout/style/nsCSSRules.h | 2 +- 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 dom/webidl/CSSPageRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 7659795dcb..080862c43f 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -76,7 +76,6 @@ #include "nsIDOMCSSKeyframesRule.h" #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSCounterStyleRule.h" -#include "nsIDOMCSSPageRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -236,10 +235,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSPageRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -580,11 +575,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSPageRule, nsIDOMCSSPageRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSPageRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index 1488b56b87..db869ce41d 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -36,8 +36,6 @@ DOMCI_CLASS(CSSKeyframesRule) // @counter-style in CSS DOMCI_CLASS(CSSCounterStyleRule) -DOMCI_CLASS(CSSPageRule) - DOMCI_CLASS(CSSFontFeatureValuesRule) DOMCI_CLASS(XULControlElement) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 120dfb48ba..c994768e35 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -27,7 +27,6 @@ class nsCSSFontFaceRule; class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; -class nsCSSPageRule; class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ @@ -290,7 +289,6 @@ private: friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; - friend class nsCSSPageRule; friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 17772d1751..96f634130b 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -230,6 +230,11 @@ DOMInterfaces = { 'nativeType': 'mozilla::css::NameSpaceRule', }, +'CSSPageRule': { + 'nativeType': 'nsCSSPageRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSPrimitiveValue': { 'nativeType': 'nsROCSSPrimitiveValue', }, diff --git a/dom/webidl/CSSPageRule.webidl b/dom/webidl/CSSPageRule.webidl new file mode 100644 index 0000000000..93e47ef02b --- /dev/null +++ b/dom/webidl/CSSPageRule.webidl @@ -0,0 +1,17 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/cssom/#the-csspagerule-interface + */ + +// https://drafts.csswg.org/cssom/#the-csspagerule-interface +// Per spec, this should inherit from CSSGroupingRule, but we don't +// implement this yet. +interface CSSPageRule : CSSRule { + // selectorText not implemented yet + // attribute DOMString selectorText; + [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index c5dcf1db69..da060f2fcf 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -97,6 +97,7 @@ WEBIDL_FILES = [ 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', 'CSSNamespaceRule.webidl', + 'CSSPageRule.webidl', 'CSSPrimitiveValue.webidl', 'CSSPseudoElement.webidl', 'CSSRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 3b65ab2219..fe76715d9c 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -38,6 +38,7 @@ #include "mozilla/dom/CSSMediaRuleBinding.h" #include "mozilla/dom/CSSSupportsRuleBinding.h" #include "mozilla/dom/CSSMozDocumentRuleBinding.h" +#include "mozilla/dom/CSSPageRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2606,7 +2607,6 @@ nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy) : Rule(aCopy) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2651,7 +2651,6 @@ nsCSSPageRule::IsCCLeaf() const // QueryInterface implementation for nsCSSPageRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSPageRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) #ifdef DEBUG @@ -2696,12 +2695,18 @@ nsCSSPageRule::GetCssTextImpl(nsAString& aCssText) const NS_IMETHODIMP nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +nsCSSPageRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration = new nsCSSPageStyleDeclaration(this); } - NS_ADDREF(*aStyle = mDOMDeclaration); - return NS_OK; + return mDOMDeclaration; } void @@ -2729,8 +2734,7 @@ nsCSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSPageRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSPageRuleBinding::Wrap(aCx, this, aGivenProto); } namespace mozilla { diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 18e1dc0fd7..01097c3f64 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -544,7 +544,6 @@ public: : mozilla::css::Rule(aLineNumber, aColumnNumber) , mDeclaration(aDeclaration) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -568,6 +567,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + nsICSSDeclaration* Style(); mozilla::css::Declaration* Declaration() { return mDeclaration; } From 50f8c187574c1bfbbb17b0d78f96129539d1568a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 10:02:17 +0200 Subject: [PATCH 17/22] Issue #2490 - Part 15: Convert CSSFontFaceRule to WebIDL. The .style PutForwards bit is coming along for the ride here as a new feature. --- dom/base/nsDOMClassInfo.cpp | 10 ---------- dom/base/nsDOMClassInfoClasses.h | 3 --- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSFontFaceRule.webidl | 15 +++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 11 ++++++++--- layout/style/nsCSSRules.h | 3 +-- 8 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 dom/webidl/CSSFontFaceRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 080862c43f..d6634f0504 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -74,7 +74,6 @@ // includes needed for the prototype chain interfaces #include "nsIDOMCSSKeyframeRule.h" #include "nsIDOMCSSKeyframesRule.h" -#include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" @@ -204,10 +203,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DEFAULT_SCRIPTABLE_FLAGS) #endif - NS_DEFINE_CLASSINFO_DATA(CSSFontFaceRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, nsMessageManagerSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | @@ -524,11 +519,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_END #endif - DOM_CLASSINFO_MAP_BEGIN(CSSFontFaceRule, nsIDOMCSSFontFaceRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFaceRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentFrameMessageManager, nsISupports) DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget) DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index db869ce41d..d280c47ce6 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -22,9 +22,6 @@ DOMCI_CLASS(XULTemplateBuilder) DOMCI_CLASS(XULTreeBuilder) #endif -// @font-face in CSS -DOMCI_CLASS(CSSFontFaceRule) - DOMCI_CLASS(ContentFrameMessageManager) DOMCI_CLASS(ContentProcessMessageManager) DOMCI_CLASS(ChromeMessageBroadcaster) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index c994768e35..cedda8ba79 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSFontFaceRule; class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; @@ -285,7 +284,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSFontFaceRule; friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 96f634130b..9b8c826cc0 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -203,6 +203,11 @@ DOMInterfaces = { 'headerFile': 'mozilla/css/GroupRule.h', }, +'CSSFontFaceRule': { + 'nativeType': 'nsCSSFontFaceRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSGroupingRule': { 'concrete': False, 'nativeType': 'mozilla::css::GroupRule', diff --git a/dom/webidl/CSSFontFaceRule.webidl b/dom/webidl/CSSFontFaceRule.webidl new file mode 100644 index 0000000000..221dd26aec --- /dev/null +++ b/dom/webidl/CSSFontFaceRule.webidl @@ -0,0 +1,15 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-fonts/#om-fontface + */ + +// https://drafts.csswg.org/css-fonts/#om-fontface +// But we implement a very old draft, apparently.... +// See bug 1058408 for implementing the current spec. +interface CSSFontFaceRule : CSSRule { + [SameObject] readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index da060f2fcf..bbadc6655a 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -91,6 +91,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSConditionRule.webidl', + 'CSSFontFaceRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index fe76715d9c..799dac42be 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -39,6 +39,7 @@ #include "mozilla/dom/CSSSupportsRuleBinding.h" #include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "mozilla/dom/CSSPageRuleBinding.h" +#include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1668,7 +1669,6 @@ nsCSSFontFaceRule::IsCCLeaf() const // QueryInterface implementation for nsCSSFontFaceRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSFontFaceRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule) NS_INTERFACE_MAP_END_INHERITING(Rule) #ifdef DEBUG @@ -1724,6 +1724,12 @@ nsCSSFontFaceRule::GetCssTextImpl(nsAString& aCssText) const aCssText.Append('}'); } +nsICSSDeclaration* +nsCSSFontFaceRule::Style() +{ + return &mDecl; +} + NS_IMETHODIMP nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { @@ -1768,8 +1774,7 @@ nsCSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSFontFaceRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSFontFaceRuleBinding::Wrap(aCx, this, aGivenProto); } // ----------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 01097c3f64..5dfe10af39 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -248,7 +248,6 @@ public: nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber) : mozilla::css::Rule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy) @@ -256,7 +255,6 @@ public: : mozilla::css::Rule(aCopy) , mDecl(aCopy.mDecl) { - SetIsNotDOMBinding(); } NS_DECL_ISUPPORTS_INHERITED @@ -279,6 +277,7 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + nsICSSDeclaration* Style(); virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; From f0de637255d6ba7cb45396fb9d6cb898eaf7248c Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 10:20:43 +0200 Subject: [PATCH 18/22] Issue #2490 - Part 16: Convert CSSFontFeatureValuesRule to WebIDL. --- dom/base/nsDOMClassInfo.cpp | 9 ------- dom/base/nsDOMClassInfoClasses.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 ++++ dom/webidl/CSSFontFeatureValuesRule.webidl | 29 ++++++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 19 +++++++++++--- layout/style/nsCSSRules.h | 6 +++-- 8 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 dom/webidl/CSSFontFeatureValuesRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index d6634f0504..2962ec2a26 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -230,10 +230,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSFontFeatureValuesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH, @@ -565,11 +561,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSFontFeatureValuesRule, nsIDOMCSSFontFeatureValuesRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement) DOM_CLASSINFO_MAP_END diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index d280c47ce6..dadebcbb76 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -33,8 +33,6 @@ DOMCI_CLASS(CSSKeyframesRule) // @counter-style in CSS DOMCI_CLASS(CSSCounterStyleRule) -DOMCI_CLASS(CSSFontFeatureValuesRule) - DOMCI_CLASS(XULControlElement) DOMCI_CLASS(XULLabeledControlElement) DOMCI_CLASS(XULButtonElement) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index cedda8ba79..78fff8fc58 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSFontFeatureValuesRule; class nsCSSKeyframeRule; class nsCSSKeyframesRule; class nsCSSCounterStyleRule; @@ -284,7 +283,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSFontFeatureValuesRule; friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 9b8c826cc0..b3e4cb4e65 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -208,6 +208,11 @@ DOMInterfaces = { 'headerFile': 'nsCSSRules.h', }, +'CSSFontFeatureValuesRule': { + 'nativeType': 'nsCSSFontFeatureValuesRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSGroupingRule': { 'concrete': False, 'nativeType': 'mozilla::css::GroupRule', diff --git a/dom/webidl/CSSFontFeatureValuesRule.webidl b/dom/webidl/CSSFontFeatureValuesRule.webidl new file mode 100644 index 0000000000..7532938141 --- /dev/null +++ b/dom/webidl/CSSFontFeatureValuesRule.webidl @@ -0,0 +1,29 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-fonts/#om-fontfeaturevalues + */ + +// https://drafts.csswg.org/css-fonts/#om-fontfeaturevalues +// but we don't implement anything remotely resembling the spec. +interface CSSFontFeatureValuesRule : CSSRule { + [SetterThrows] + attribute DOMString fontFamily; + + // Not yet implemented + // readonly attribute CSSFontFeatureValuesMap annotation; + // readonly attribute CSSFontFeatureValuesMap ornaments; + // readonly attribute CSSFontFeatureValuesMap stylistic; + // readonly attribute CSSFontFeatureValuesMap swash; + // readonly attribute CSSFontFeatureValuesMap characterVariant; + // readonly attribute CSSFontFeatureValuesMap styleset; +}; + +partial interface CSSFontFeatureValuesRule { + // Gecko addition? + [SetterThrows] + attribute DOMString valueText; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index bbadc6655a..6c51b04f0e 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -92,6 +92,7 @@ WEBIDL_FILES = [ 'CSSAnimation.webidl', 'CSSConditionRule.webidl', 'CSSFontFaceRule.webidl', + 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSLexer.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 799dac42be..ea80b6ffe2 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -40,6 +40,7 @@ #include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "mozilla/dom/CSSPageRuleBinding.h" #include "mozilla/dom/CSSFontFaceRuleBinding.h" +#include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -1796,7 +1797,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSFontFeatureValuesRule, mozilla::css::Rule) // implementation. NS_INTERFACE_MAP_BEGIN(nsCSSFontFeatureValuesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFeatureValuesRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFeatureValuesRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) bool @@ -1905,6 +1905,20 @@ nsCSSFontFeatureValuesRule::GetCssTextImpl(nsAString& aCssText) const FontFeatureValuesRuleToString(mFamilyList, mFeatureValues, aCssText); } +void +nsCSSFontFeatureValuesRule::SetFontFamily(const nsAString& aFamily, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + +void +nsCSSFontFeatureValuesRule::SetValueText(const nsAString& aFamily, + ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); +} + NS_IMETHODIMP nsCSSFontFeatureValuesRule::GetFontFamily(nsAString& aFamilyListStr) { @@ -1997,8 +2011,7 @@ nsCSSFontFeatureValuesRule::SizeOfIncludingThis( nsCSSFontFeatureValuesRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSFontFeatureValuesRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 5dfe10af39..3e7e6fe4b8 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -322,7 +322,6 @@ public: nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber) : mozilla::css::Rule(aLineNumber, aColumnNumber) { - SetIsNotDOMBinding(); } nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy) @@ -331,7 +330,6 @@ public: , mFamilyList(aCopy.mFamilyList) , mFeatureValues(aCopy.mFeatureValues) { - SetIsNotDOMBinding(); } NS_DECL_ISUPPORTS_INHERITED @@ -350,6 +348,10 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetFontFamily is OK + void SetFontFamily(const nsAString& aFamily, mozilla::ErrorResult& aRv); + // Our XPCOM GetValueText is OK + void SetValueText(const nsAString& aFamily, mozilla::ErrorResult& aRv); const mozilla::FontFamilyList& GetFamilyList() { return mFamilyList; } void SetFamilyList(const mozilla::FontFamilyList& aFamilyList); From 89d96e02265f00e959aa04939fd4458a7dfd1ac4 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 14:00:59 +0200 Subject: [PATCH 19/22] Issue #2490 - Part 17: Convert CSSKeyframeRule to WebIDL. --- dom/base/nsDOMClassInfo.cpp | 8 -------- dom/base/nsDOMClassInfoClasses.h | 1 - dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSKeyframeRule.webidl | 14 ++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 16 ++++++++++------ layout/style/nsCSSRules.h | 4 +++- 8 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 dom/webidl/CSSKeyframeRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 2962ec2a26..d74cc63d93 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -219,9 +219,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframeRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -546,11 +543,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframeRule, nsIDOMCSSKeyframeRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframeRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index dadebcbb76..d6423723b6 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -27,7 +27,6 @@ DOMCI_CLASS(ContentProcessMessageManager) DOMCI_CLASS(ChromeMessageBroadcaster) DOMCI_CLASS(ChromeMessageSender) -DOMCI_CLASS(CSSKeyframeRule) DOMCI_CLASS(CSSKeyframesRule) // @counter-style in CSS diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 78fff8fc58..65fddff476 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSKeyframeRule; class nsCSSKeyframesRule; class nsCSSCounterStyleRule; @@ -283,7 +282,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSKeyframeRule; friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index b3e4cb4e65..4a527ca97a 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -222,6 +222,11 @@ DOMInterfaces = { 'nativeType': 'mozilla::css::ImportRule', }, +'CSSKeyframeRule': { + 'nativeType': 'nsCSSKeyframeRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSKeyframeRule.webidl b/dom/webidl/CSSKeyframeRule.webidl new file mode 100644 index 0000000000..25d8965f2a --- /dev/null +++ b/dom/webidl/CSSKeyframeRule.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-animations/#interface-csskeyframerule + */ + +// https://drafts.csswg.org/css-animations/#interface-csskeyframerule +interface CSSKeyframeRule : CSSRule { + attribute DOMString keyText; + readonly attribute CSSStyleDeclaration style; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 6c51b04f0e..0b0c421135 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -95,6 +95,7 @@ WEBIDL_FILES = [ 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', + 'CSSKeyframeRule.webidl', 'CSSLexer.webidl', 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index ea80b6ffe2..ecec902de5 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -41,6 +41,7 @@ #include "mozilla/dom/CSSPageRuleBinding.h" #include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" +#include "mozilla/dom/CSSKeyframeRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2103,7 +2104,6 @@ nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy) , mKeys(aCopy.mKeys) , mDeclaration(new css::Declaration(*aCopy.mDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } @@ -2148,7 +2148,6 @@ nsCSSKeyframeRule::IsCCLeaf() const // QueryInterface implementation for nsCSSKeyframeRule NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsCSSKeyframeRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframeRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframeRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) #ifdef DEBUG @@ -2248,12 +2247,18 @@ nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText) NS_IMETHODIMP nsCSSKeyframeRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle) +{ + NS_ADDREF(*aStyle = Style()); + return NS_OK; +} + +nsICSSDeclaration* +nsCSSKeyframeRule::Style() { if (!mDOMDeclaration) { mDOMDeclaration = new nsCSSKeyframeStyleDeclaration(this); } - NS_ADDREF(*aStyle = mDOMDeclaration); - return NS_OK; + return mDOMDeclaration; } void @@ -2297,8 +2302,7 @@ nsCSSKeyframeRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSKeyframeRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSKeyframeRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 3e7e6fe4b8..ceb20e5a1d 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -416,7 +416,6 @@ public: , mKeys(mozilla::Move(aKeys)) , mDeclaration(mozilla::Move(aDeclaration)) { - SetIsNotDOMBinding(); mDeclaration->SetOwningRule(this); } private: @@ -440,6 +439,9 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetKeyText is OK. + // Our XPCOM SetKeyText is OK. + nsICSSDeclaration* Style(); const nsTArray& GetKeys() const { return mKeys; } mozilla::css::Declaration* Declaration() { return mDeclaration; } From b984856d8f8da89ad60010c0f50d7620ef93d56e Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 14:13:43 +0200 Subject: [PATCH 20/22] Issue #2490 - Part 18: Convert CSSKeyframesRule to WebIDL. --- dom/base/nsDOMClassInfo.cpp | 11 ----------- dom/base/nsDOMClassInfoClasses.h | 2 -- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSKeyframesRule.webidl | 18 ++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 19 +++++++++++-------- layout/style/nsCSSRules.h | 7 ++++++- 8 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 dom/webidl/CSSKeyframesRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index d74cc63d93..f1c0ca43ec 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -72,8 +72,6 @@ #include "nsMemory.h" // includes needed for the prototype chain interfaces -#include "nsIDOMCSSKeyframeRule.h" -#include "nsIDOMCSSKeyframesRule.h" #include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" @@ -219,10 +217,6 @@ static nsDOMClassInfoData sClassInfoData[] = { DOM_DEFAULT_SCRIPTABLE_FLAGS) - NS_DEFINE_CLASSINFO_DATA(CSSKeyframesRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS | nsIXPCScriptable::WANT_PRECREATE) @@ -543,11 +537,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSKeyframesRule, nsIDOMCSSKeyframesRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSKeyframesRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index d6423723b6..ad96206cdb 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -27,8 +27,6 @@ DOMCI_CLASS(ContentProcessMessageManager) DOMCI_CLASS(ChromeMessageBroadcaster) DOMCI_CLASS(ChromeMessageSender) -DOMCI_CLASS(CSSKeyframesRule) - // @counter-style in CSS DOMCI_CLASS(CSSCounterStyleRule) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 65fddff476..3adaaa25e8 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSKeyframesRule; class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ @@ -282,7 +281,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSKeyframesRule; friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 4a527ca97a..fcc2727220 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -227,6 +227,11 @@ DOMInterfaces = { 'headerFile': 'nsCSSRules.h', }, +'CSSKeyframesRule': { + 'nativeType': 'nsCSSKeyframesRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/webidl/CSSKeyframesRule.webidl b/dom/webidl/CSSKeyframesRule.webidl new file mode 100644 index 0000000000..d0ea978d03 --- /dev/null +++ b/dom/webidl/CSSKeyframesRule.webidl @@ -0,0 +1,18 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-animations/#interface-csskeyframesrule + */ + +// https://drafts.csswg.org/css-animations/#interface-csskeyframesrule +interface CSSKeyframesRule : CSSRule { + attribute DOMString name; + readonly attribute CSSRuleList cssRules; + + void appendRule(DOMString rule); + void deleteRule(DOMString select); + CSSKeyframeRule? findRule(DOMString select); +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 0b0c421135..18d4fdc2b5 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -96,6 +96,7 @@ WEBIDL_FILES = [ 'CSSGroupingRule.webidl', 'CSSImportRule.webidl', 'CSSKeyframeRule.webidl', + 'CSSKeyframesRule.webidl', 'CSSLexer.webidl', 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index ecec902de5..5c99fbd37c 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -42,6 +42,7 @@ #include "mozilla/dom/CSSFontFaceRuleBinding.h" #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "mozilla/dom/CSSKeyframeRuleBinding.h" +#include "mozilla/dom/CSSKeyframesRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2316,7 +2317,6 @@ nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy) : GroupRule(aCopy), mName(aCopy.mName) { - SetIsNotDOMBinding(); } nsCSSKeyframesRule::~nsCSSKeyframesRule() @@ -2336,7 +2336,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule) // QueryInterface implementation for nsCSSKeyframesRule NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSKeyframesRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSKeyframesRule) NS_INTERFACE_MAP_END_INHERITING(GroupRule) #ifdef DEBUG @@ -2501,14 +2500,19 @@ nsCSSKeyframesRule::DeleteRule(const nsAString& aKey) NS_IMETHODIMP nsCSSKeyframesRule::FindRule(const nsAString& aKey, nsIDOMCSSKeyframeRule** aResult) +{ + NS_IF_ADDREF(*aResult = FindRule(aKey)); + return NS_OK; +} + +nsCSSKeyframeRule* +nsCSSKeyframesRule::FindRule(const nsAString& aKey) { uint32_t index = FindRuleIndexForKey(aKey); if (index == RULE_NOT_FOUND) { - *aResult = nullptr; - } else { - NS_ADDREF(*aResult = static_cast(mRules[index])); + return nullptr; } - return NS_OK; + return static_cast(mRules[index]); } // GroupRule interface @@ -2537,8 +2541,7 @@ nsCSSKeyframesRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSKeyframesRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSKeyframesRuleBinding::Wrap(aCx, this, aGivenProto); } // ------------------------------------------- diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index ceb20e5a1d..81e4f04cfb 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -470,7 +470,6 @@ public: : mozilla::css::GroupRule(aLineNumber, aColumnNumber) , mName(aName) { - SetIsNotDOMBinding(); } private: nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy); @@ -492,6 +491,12 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetName is OK + // The XPCOM SetName is OK + using mozilla::css::GroupRule::CssRules; + // The XPCOM appendRule is OK, since it never throws + // The XPCOM deleteRule is OK, since it never throws + nsCSSKeyframeRule* FindRule(const nsAString& aKey); // rest of GroupRule virtual bool UseForPresentation(nsPresContext* aPresContext, From 7fb5d53a791a4e308e2857410567b5005b3f0f62 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 19:52:36 +0200 Subject: [PATCH 21/22] Issue #2490 - Part 19: Convert CSSCounterStyleRule to WebIDL. --- dom/base/nsDOMClassInfo.cpp | 11 ----------- dom/base/nsDOMClassInfoClasses.h | 3 --- dom/base/nsWrapperCache.h | 2 -- dom/bindings/Bindings.conf | 5 +++++ dom/webidl/CSSCounterStyleRule.webidl | 23 +++++++++++++++++++++++ dom/webidl/moz.build | 1 + layout/style/nsCSSRules.cpp | 6 ++---- layout/style/nsCSSRules.h | 23 ++++++++++++++++++++++- 8 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 dom/webidl/CSSCounterStyleRule.webidl diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index f1c0ca43ec..bc3a6fefaa 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -72,7 +72,6 @@ #include "nsMemory.h" // includes needed for the prototype chain interfaces -#include "nsIDOMCSSCounterStyleRule.h" #include "nsIDOMXULCommandDispatcher.h" #include "nsIControllers.h" #ifdef MOZ_XUL @@ -216,11 +215,6 @@ static nsDOMClassInfoData sClassInfoData[] = { NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) - - NS_DEFINE_CLASSINFO_DATA(CSSCounterStyleRule, nsDOMGenericSH, - DOM_DEFAULT_SCRIPTABLE_FLAGS | - nsIXPCScriptable::WANT_PRECREATE) - NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULControlElement, nsDOMGenericSH, DOM_DEFAULT_SCRIPTABLE_FLAGS) NS_DEFINE_CHROME_XBL_CLASSINFO_DATA(XULLabeledControlElement, nsDOMGenericSH, @@ -537,11 +531,6 @@ nsDOMClassInfo::Init() DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender) DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN(CSSCounterStyleRule, nsIDOMCSSCounterStyleRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule) - DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - DOM_CLASSINFO_MAP_END - DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(XULControlElement, nsIDOMXULControlElement) DOM_CLASSINFO_MAP_ENTRY(nsIDOMXULControlElement) DOM_CLASSINFO_MAP_END diff --git a/dom/base/nsDOMClassInfoClasses.h b/dom/base/nsDOMClassInfoClasses.h index ad96206cdb..843cdc85bf 100644 --- a/dom/base/nsDOMClassInfoClasses.h +++ b/dom/base/nsDOMClassInfoClasses.h @@ -27,9 +27,6 @@ DOMCI_CLASS(ContentProcessMessageManager) DOMCI_CLASS(ChromeMessageBroadcaster) DOMCI_CLASS(ChromeMessageSender) -// @counter-style in CSS -DOMCI_CLASS(CSSCounterStyleRule) - DOMCI_CLASS(XULControlElement) DOMCI_CLASS(XULLabeledControlElement) DOMCI_CLASS(XULButtonElement) diff --git a/dom/base/nsWrapperCache.h b/dom/base/nsWrapperCache.h index 3adaaa25e8..8368581c96 100644 --- a/dom/base/nsWrapperCache.h +++ b/dom/base/nsWrapperCache.h @@ -23,7 +23,6 @@ class ProcessGlobal; class SandboxPrivate; class nsInProcessTabChildGlobal; class nsWindowRoot; -class nsCSSCounterStyleRule; #define NS_WRAPPERCACHE_IID \ { 0x6f3179a1, 0x36f7, 0x4a5c, \ @@ -281,7 +280,6 @@ private: friend class SandboxPrivate; friend class nsInProcessTabChildGlobal; friend class nsWindowRoot; - friend class nsCSSCounterStyleRule; void SetIsNotDOMBinding() { diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index fcc2727220..ffb4edbf5d 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -203,6 +203,11 @@ DOMInterfaces = { 'headerFile': 'mozilla/css/GroupRule.h', }, +'CSSCounterStyleRule': { + 'nativeType': 'nsCSSCounterStyleRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSFontFaceRule': { 'nativeType': 'nsCSSFontFaceRule', 'headerFile': 'nsCSSRules.h', diff --git a/dom/webidl/CSSCounterStyleRule.webidl b/dom/webidl/CSSCounterStyleRule.webidl new file mode 100644 index 0000000000..bb6f7e0e1b --- /dev/null +++ b/dom/webidl/CSSCounterStyleRule.webidl @@ -0,0 +1,23 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is + * https://drafts.csswg.org/css-counter-styles-3/#the-csscounterstylerule-interface + */ + +// https://drafts.csswg.org/css-counter-styles-3/#the-csscounterstylerule-interface +interface CSSCounterStyleRule : CSSRule { + attribute DOMString name; + attribute DOMString system; + attribute DOMString symbols; + attribute DOMString additiveSymbols; + attribute DOMString negative; + attribute DOMString prefix; + attribute DOMString suffix; + attribute DOMString range; + attribute DOMString pad; + attribute DOMString speakAs; + attribute DOMString fallback; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 18d4fdc2b5..f821b3ce4e 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -91,6 +91,7 @@ WEBIDL_FILES = [ 'CSS.webidl', 'CSSAnimation.webidl', 'CSSConditionRule.webidl', + 'CSSCounterStyleRule.webidl', 'CSSFontFaceRule.webidl', 'CSSFontFeatureValuesRule.webidl', 'CSSGroupingRule.webidl', diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 5c99fbd37c..08d2deb7f0 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -43,6 +43,7 @@ #include "mozilla/dom/CSSFontFeatureValuesRuleBinding.h" #include "mozilla/dom/CSSKeyframeRuleBinding.h" #include "mozilla/dom/CSSKeyframesRuleBinding.h" +#include "mozilla/dom/CSSCounterStyleRuleBinding.h" #include "StyleRule.h" #include "nsFont.h" #include "nsIURI.h" @@ -2913,7 +2914,6 @@ nsCSSCounterStyleRule::nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy) , mName(aCopy.mName) , mGeneration(aCopy.mGeneration) { - SetIsNotDOMBinding(); for (size_t i = 0; i < ArrayLength(mValues); ++i) { mValues[i] = aCopy.mValues[i]; } @@ -2945,7 +2945,6 @@ NS_IMPL_RELEASE_INHERITED(nsCSSCounterStyleRule, mozilla::css::Rule) // implementation. NS_INTERFACE_MAP_BEGIN(nsCSSCounterStyleRule) NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCounterStyleRule) - NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCounterStyleRule) NS_INTERFACE_MAP_END_INHERITING(mozilla::css::Rule) bool @@ -3350,6 +3349,5 @@ nsCSSCounterStyleRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const nsCSSCounterStyleRule::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { - NS_NOTREACHED("We called SetIsNotDOMBinding() in our constructor"); - return nullptr; + return CSSCounterStyleRuleBinding::Wrap(aCx, this, aGivenProto); } diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 81e4f04cfb..6dc9b141cc 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -652,7 +652,6 @@ public: , mName(aName) , mGeneration(0) { - SetIsNotDOMBinding(); } private: @@ -676,6 +675,28 @@ public: // WebIDL interface uint16_t Type() const override; void GetCssTextImpl(nsAString& aCssText) const override; + // The XPCOM GetName is OK + // The XPCOM SetName is OK + // The XPCOM GetSystem is OK + // The XPCOM SetSystem is OK + // The XPCOM GetSymbols is OK + // The XPCOM SetSymbols is OK + // The XPCOM GetAdditiveSymbols is OK + // The XPCOM SetAdditiveSymbols is OK + // The XPCOM GetNegative is OK + // The XPCOM SetNegative is OK + // The XPCOM GetPrefix is OK + // The XPCOM SetPrefix is OK + // The XPCOM GetSuffix is OK + // The XPCOM SetSuffix is OK + // The XPCOM GetRange is OK + // The XPCOM SetRange is OK + // The XPCOM GetPad is OK + // The XPCOM SetPad is OK + // The XPCOM GetSpeakAs is OK + // The XPCOM SetSpeakAs is OK + // The XPCOM GetFallback is OK + // The XPCOM SetFallback is OK // This function is only used to check whether a non-empty value, which has // been accepted by parser, is valid for the given system and descriptor. From 641b556c53defbb35a2bda85b68be2b9d833af6c Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 4 Apr 2024 20:07:33 +0200 Subject: [PATCH 22/22] Issue #2490 - Part 20: Remove the stuff that was added temporarily to deal with a mix of WebIDL and non-WebIDL rules. --- dom/base/nsDOMClassInfo.cpp | 26 -------------------------- dom/base/nsDOMClassInfo.h | 23 ----------------------- dom/bindings/Bindings.conf | 1 - layout/style/Rule.h | 9 --------- 4 files changed, 59 deletions(-) diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index bc3a6fefaa..1ea93ed4ce 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -67,7 +67,6 @@ #include "nsIDOMEventTarget.h" // CSS related includes -#include "nsCSSRules.h" #include "nsIDOMCSSRule.h" #include "nsMemory.h" @@ -1890,31 +1889,6 @@ nsEventTargetSH::PreserveWrapper(nsISupports *aNative) target->PreserveWrapper(aNative); } -// CSS rule helper -NS_IMETHODIMP -nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *aGlobalObj, JSObject **parentObj) -{ - JS::Rooted globalObj(cx, aGlobalObj); - nsCOMPtr rule = do_QueryInterface(nativeObj); - if (!rule) { - return NS_ERROR_UNEXPECTED; - } - css::Rule* cssRule = rule->GetCSSRule(); - nsIDocument* doc = cssRule->GetDocument(); - if (!doc) { - *parentObj = globalObj; - return NS_OK; - } - - nsIGlobalObject* global = doc->GetScopeObject(); - if (!global) { - return NS_ERROR_UNEXPECTED; - } - *parentObj = global->GetGlobalJSObject(); - return *parentObj ? NS_OK : NS_ERROR_FAILURE; -} - // nsIDOMEventListener::HandleEvent() 'this' converter helper NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator) diff --git a/dom/base/nsDOMClassInfo.h b/dom/base/nsDOMClassInfo.h index 0d70b040bc..48f4966f0f 100644 --- a/dom/base/nsDOMClassInfo.h +++ b/dom/base/nsDOMClassInfo.h @@ -172,29 +172,6 @@ public: } }; - -// Makes sure that we always create our wrapper in the right global, so we won't -// cache one from the wrong global. -class nsCSSRuleSH : public nsDOMGenericSH -{ -protected: - explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData) - { - } - - virtual ~nsCSSRuleSH() - { - } -public: - NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx, - JSObject *globalObj, JSObject **parentObj) override; - - static nsIClassInfo *doCreate(nsDOMClassInfoData* aData) - { - return new nsCSSRuleSH(aData); - } -}; - // A place to hang some static methods that we should really consider // moving to be nsGlobalWindow member methods. See bug 1062418. class nsWindowSH diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index ffb4edbf5d..f484c59e53 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -265,7 +265,6 @@ DOMInterfaces = { }, 'CSSRule': { - 'hasXPConnectImpls': True, 'concrete': False, 'nativeType': 'mozilla::css::Rule' }, diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 3537bad449..9586edffd4 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -19,11 +19,6 @@ struct nsRuleData; template struct already_AddRefed; class nsHTMLCSSStyleSheet; -// Temporary IID for the nsIDOMCSSRule interface {ebb427f1-a935-480b-bd9b-bb0e3bd387a9} -#define NS_IDOM_CSSRULE_IID \ -{ 0xebb427f1, 0xa935, 0x480b, \ - { 0xbd, 0x9b, 0xbb, 0x0e, 0x3b, 0xd3, 0x87, 0xa9 } } - namespace mozilla { namespace css { class GroupRule; @@ -51,8 +46,6 @@ protected: virtual ~Rule() {} public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOM_CSSRULE_IID) - NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Rule) // Return true if this rule is known to be a cycle collection leaf, in the @@ -145,8 +138,6 @@ protected: uint32_t mColumnNumber; }; -NS_DEFINE_STATIC_IID_ACCESSOR(Rule, NS_IDOM_CSSRULE_IID) - } // namespace css } // namespace mozilla