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;