From 74fdaed1fea57175b8060de82b6c9c983adf31a6 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 16:47:23 +0200 Subject: [PATCH] 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; }