From d1b6a584b8a329d3e3f068345507366a49c39705 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 3 Apr 2024 15:52:14 +0200 Subject: [PATCH] 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;