diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index c13e775a94..3edcb39020 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2802,20 +2802,9 @@ nsDocument::GetPrincipal() return NodePrincipal(); } -extern bool sDisablePrefetchHTTPSPref; - void nsDocument::SetPrincipal(nsIPrincipal *aNewPrincipal) { - if (aNewPrincipal && mAllowDNSPrefetch && sDisablePrefetchHTTPSPref) { - nsCOMPtr uri; - aNewPrincipal->GetURI(getter_AddRefs(uri)); - bool isHTTPS; - if (!uri || NS_FAILED(uri->SchemeIs("https", &isHTTPS)) || - isHTTPS) { - mAllowDNSPrefetch = false; - } - } mNodeInfoManager->SetDocumentPrincipal(aNewPrincipal); #ifdef DEBUG diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 6658db318c..f3bfc1db9e 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -237,6 +237,16 @@ DOMInterfaces = { 'headerFile': 'nsCSSRules.h', }, +'CSSLayerBlockRule': { + 'nativeType': 'mozilla::CSSLayerBlockRule', + 'headerFile': 'nsCSSRules.h', +}, + +'CSSLayerStatementRule': { + 'nativeType': 'mozilla::CSSLayerStatementRule', + 'headerFile': 'nsCSSRules.h', +}, + 'CSSLexer': { 'wrapperCache': False }, diff --git a/dom/html/nsHTMLDNSPrefetch.cpp b/dom/html/nsHTMLDNSPrefetch.cpp index 6a7217021f..1b91d8041d 100644 --- a/dom/html/nsHTMLDNSPrefetch.cpp +++ b/dom/html/nsHTMLDNSPrefetch.cpp @@ -37,7 +37,6 @@ using namespace mozilla::dom; using namespace mozilla::net; static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID); -bool sDisablePrefetchHTTPSPref; static bool sInitialized = false; static nsIDNSService *sDNSService = nullptr; static nsHTMLDNSPrefetch::nsDeferrals *sPrefetches = nullptr; @@ -59,13 +58,6 @@ nsHTMLDNSPrefetch::Initialize() sPrefetches->Activate(); - Preferences::AddBoolVarCache(&sDisablePrefetchHTTPSPref, - "network.dns.disablePrefetchFromHTTPS"); - - // Default is false, so we need an explicit call to prime the cache. - sDisablePrefetchHTTPSPref = - Preferences::GetBool("network.dns.disablePrefetchFromHTTPS", true); - NS_IF_RELEASE(sDNSService); nsresult rv; rv = CallGetService(kDNSServiceCID, &sDNSService); diff --git a/dom/interfaces/css/moz.build b/dom/interfaces/css/moz.build index 83b50eb5e7..51f225e155 100644 --- a/dom/interfaces/css/moz.build +++ b/dom/interfaces/css/moz.build @@ -13,6 +13,8 @@ XPIDL_SOURCES += [ 'nsIDOMCSSImportRule.idl', 'nsIDOMCSSKeyframeRule.idl', 'nsIDOMCSSKeyframesRule.idl', + 'nsIDOMCSSLayerBlockRule.idl', + 'nsIDOMCSSLayerStatementRule.idl', 'nsIDOMCSSMediaRule.idl', 'nsIDOMCSSMozDocumentRule.idl', 'nsIDOMCSSPageRule.idl', diff --git a/dom/interfaces/css/nsIDOMCSSImportRule.idl b/dom/interfaces/css/nsIDOMCSSImportRule.idl index fc96977d91..9f2a5405ad 100644 --- a/dom/interfaces/css/nsIDOMCSSImportRule.idl +++ b/dom/interfaces/css/nsIDOMCSSImportRule.idl @@ -14,4 +14,5 @@ interface nsIDOMCSSImportRule : nsISupports readonly attribute DOMString href; readonly attribute nsIDOMMediaList media; readonly attribute nsIDOMCSSStyleSheet styleSheet; + readonly attribute DOMString layerName; }; diff --git a/dom/interfaces/css/nsIDOMCSSLayerBlockRule.idl b/dom/interfaces/css/nsIDOMCSSLayerBlockRule.idl new file mode 100644 index 0000000000..dbd909ccd8 --- /dev/null +++ b/dom/interfaces/css/nsIDOMCSSLayerBlockRule.idl @@ -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/. */ + +#include "nsIDOMCSSGroupingRule.idl" + +[scriptable, uuid(2865c2ba-ae78-4282-8eff-9b7a2d71f9eb)] +interface nsIDOMCSSLayerBlockRule : nsIDOMCSSGroupingRule +{ + readonly attribute DOMString name; +}; diff --git a/dom/interfaces/css/nsIDOMCSSLayerStatementRule.idl b/dom/interfaces/css/nsIDOMCSSLayerStatementRule.idl new file mode 100644 index 0000000000..bfbcb05d3c --- /dev/null +++ b/dom/interfaces/css/nsIDOMCSSLayerStatementRule.idl @@ -0,0 +1,11 @@ +/* -*- 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/. */ + +#include "nsISupports.idl" + +[scriptable, uuid(ec215b70-417e-41fa-8d48-8edd6d30aac3)] +interface nsIDOMCSSLayerStatementRule : nsISupports +{ +}; diff --git a/dom/interfaces/css/nsIDOMCSSRule.idl b/dom/interfaces/css/nsIDOMCSSRule.idl index f4cc557730..06dc813f6f 100644 --- a/dom/interfaces/css/nsIDOMCSSRule.idl +++ b/dom/interfaces/css/nsIDOMCSSRule.idl @@ -44,6 +44,9 @@ interface nsIDOMCSSRule : nsISupports const unsigned short COUNTER_STYLE_RULE = 11; const unsigned short SUPPORTS_RULE = 12; const unsigned short FONT_FEATURE_VALUES_RULE = 14; + const unsigned short RESERVED1_RULE = 15; + const unsigned short LAYER_BLOCK_RULE = 16; + const unsigned short LAYER_STATEMENT_RULE = 17; readonly attribute unsigned short type; attribute DOMString cssText; diff --git a/dom/webidl/CSSImportRule.webidl b/dom/webidl/CSSImportRule.webidl index 7d3f17c794..efd6da7689 100644 --- a/dom/webidl/CSSImportRule.webidl +++ b/dom/webidl/CSSImportRule.webidl @@ -15,3 +15,9 @@ interface CSSImportRule : CSSRule { // be. See . [SameObject] readonly attribute CSSStyleSheet? styleSheet; }; + +// https://drafts.csswg.org/css-cascade-5/#extensions-to-cssimportrule-interface +partial interface CSSImportRule { + [Pref="layout.css.cascade-layers.enabled"] + readonly attribute DOMString? layerName; +}; diff --git a/dom/webidl/CSSLayerBlockRule.webidl b/dom/webidl/CSSLayerBlockRule.webidl new file mode 100644 index 0000000000..2fece73a37 --- /dev/null +++ b/dom/webidl/CSSLayerBlockRule.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-cascade-5/#the-csslayerblockrule-interface + */ +[Exposed=Window, Pref="layout.css.cascade-layers.enabled"] +interface CSSLayerBlockRule : CSSGroupingRule { + readonly attribute DOMString name; +}; diff --git a/dom/webidl/CSSLayerStatementRule.webidl b/dom/webidl/CSSLayerStatementRule.webidl new file mode 100644 index 0000000000..d91e32436c --- /dev/null +++ b/dom/webidl/CSSLayerStatementRule.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-cascade-5/#the-csslayerstatementrule-interface + */ +[Exposed=Window, Pref="layout.css.cascade-layers.enabled"] +interface CSSLayerStatementRule : CSSRule { + // readonly attribute FrozenArray nameList; + [Frozen, Cached, Pure] + readonly attribute sequence nameList; +}; diff --git a/dom/webidl/moz.build b/dom/webidl/moz.build index 1d354fa3ed..366366ac31 100644 --- a/dom/webidl/moz.build +++ b/dom/webidl/moz.build @@ -98,6 +98,8 @@ WEBIDL_FILES = [ 'CSSImportRule.webidl', 'CSSKeyframeRule.webidl', 'CSSKeyframesRule.webidl', + 'CSSLayerBlockRule.webidl', + 'CSSLayerStatementRule.webidl', 'CSSLexer.webidl', 'CSSMediaRule.webidl', 'CSSMozDocumentRule.webidl', diff --git a/layout/inspector/inCSSValueSearch.cpp b/layout/inspector/inCSSValueSearch.cpp index 5897e1b542..82697508ed 100644 --- a/layout/inspector/inCSSValueSearch.cpp +++ b/layout/inspector/inCSSValueSearch.cpp @@ -18,6 +18,8 @@ #include "nsIDOMCSSImportRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSSupportsRule.h" +#include "nsIDOMCSSLayerBlockRule.h" +#include "nsIDOMCSSLayerStatementRule.h" #include "nsIDOMCSSRule.h" #include "nsIURI.h" #include "nsIDocument.h" @@ -322,6 +324,12 @@ inCSSValueSearch::SearchRuleList(nsIDOMCSSRuleList* aRuleList, nsIURI* aBaseURL) supportsRule->GetCssRules(getter_AddRefs(childRules)); SearchRuleList(childRules, aBaseURL); } break; + case nsIDOMCSSRule::LAYER_BLOCK_RULE: { + nsCOMPtr layerBlockRule = do_QueryInterface(rule); + nsCOMPtr childRules; + layerBlockRule->GetCssRules(getter_AddRefs(childRules)); + SearchRuleList(childRules, aBaseURL); + } break; default: // XXX handle nsIDOMCSSRule::PAGE_RULE if we ever support it break; diff --git a/layout/style/CSSStyleSheet.cpp b/layout/style/CSSStyleSheet.cpp index 1307864c9d..1ed14259db 100644 --- a/layout/style/CSSStyleSheet.cpp +++ b/layout/style/CSSStyleSheet.cpp @@ -1896,6 +1896,8 @@ CSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule, case css::Rule::COUNTER_STYLE_RULE: case css::Rule::DOCUMENT_RULE: case css::Rule::SUPPORTS_RULE: + case css::Rule::LAYER_BLOCK_RULE: + case css::Rule::LAYER_STATEMENT_RULE: // these types are OK to insert into a group break; case css::Rule::CHARSET_RULE: diff --git a/layout/style/ImportRule.h b/layout/style/ImportRule.h index 077349d017..bfa58d8a6e 100644 --- a/layout/style/ImportRule.h +++ b/layout/style/ImportRule.h @@ -29,6 +29,7 @@ class ImportRule final : public Rule, { public: ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, + const nsString& aLayerName, uint32_t aLineNumber, uint32_t aColumnNumber); private: // for |Clone| @@ -65,9 +66,11 @@ public: // The XPCOM GetHref is fine, since it never fails. nsMediaList* Media() const { return mMedia; } StyleSheet* GetStyleSheet() const; + // The XPCOM GetLayerName is OK private: nsString mURLSpec; + nsString mLayerName; RefPtr mMedia; RefPtr mChildSheet; }; diff --git a/layout/style/Rule.h b/layout/style/Rule.h index 9586edffd4..9ff8c0cc4b 100644 --- a/layout/style/Rule.h +++ b/layout/style/Rule.h @@ -78,7 +78,10 @@ public: DOCUMENT_RULE, SUPPORTS_RULE, FONT_FEATURE_VALUES_RULE, - COUNTER_STYLE_RULE + COUNTER_STYLE_RULE, + RESERVED1_RULE, + LAYER_BLOCK_RULE, + LAYER_STATEMENT_RULE }; virtual int32_t GetType() const = 0; diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index c08a774328..8a84445a07 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -68,6 +68,7 @@ static bool sWebkitDevicePixelRatioEnabled; static bool sMozGradientsEnabled; static bool sControlCharVisibility; static bool sLegacyNegationPseudoClassEnabled; +static bool sCascadeLayersEnabled; const uint32_t nsCSSProps::kParserVariantTable[eCSSProperty_COUNT_no_shorthands] = { @@ -705,6 +706,7 @@ protected: bool ParseMediaQueryExpression(nsMediaQuery* aQuery); void ProcessImport(const nsString& aURLSpec, nsMediaList* aMedia, + const nsString& aLayerName, RuleAppendFunc aAppendFunc, void* aProcessData, uint32_t aLineNumber, @@ -752,6 +754,8 @@ protected: nsCSSValue& aValue); bool ParseCounterRange(nsCSSValuePair& aPair); + bool ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData); + /** * Parses the current input stream for a CSS token stream value and resolves * any variable references using the variables in aVariables. @@ -3452,6 +3456,11 @@ CSSParserImpl::ParseAtRule(RuleAppendFunc aAppendFunc, parseFunc = &CSSParserImpl::ParseSupportsRule; newSection = eCSSSection_General; + } else if (mToken.mIdent.LowerCaseEqualsLiteral("layer") && + sCascadeLayersEnabled) { + parseFunc = &CSSParserImpl::ParseLayerRule; + newSection = eCSSSection_General; + } else if (mToken.mIdent.LowerCaseEqualsLiteral("counter-style")) { parseFunc = &CSSParserImpl::ParseCounterStyleRule; newSection = eCSSSection_General; @@ -3885,19 +3894,24 @@ CSSParserImpl::ParseImportRule(RuleAppendFunc aAppendFunc, void* aData) NS_ASSERTION(media->Length() != 0, "media list must be nonempty"); } - ProcessImport(url, media, aAppendFunc, aData, linenum, colnum); + // FIXME: Layer functions inside @import declarations are treated as an error. + nsAutoString layerName; + + ProcessImport(url, media, layerName, aAppendFunc, aData, linenum, colnum); return true; } void CSSParserImpl::ProcessImport(const nsString& aURLSpec, nsMediaList* aMedia, + const nsString& aLayerName, RuleAppendFunc aAppendFunc, void* aData, uint32_t aLineNumber, uint32_t aColumnNumber) { RefPtr rule = new css::ImportRule(aMedia, aURLSpec, + aLayerName, aLineNumber, aColumnNumber); (*aAppendFunc)(rule, aData); @@ -4929,6 +4943,113 @@ CSSParserImpl::ParseSupportsConditionTermsAfterOperator( } } +bool +CSSParserImpl::ParseLayerRule(RuleAppendFunc aAppendFunc, void* aProcessData) +{ + nsString layerName; + nsTArray* nameList = new nsTArray(); + + uint32_t linenum, colnum; + if (!GetNextTokenLocation(true, &linenum, &colnum)) { + return false; + } + + nsCSSToken* tk = &mToken; + if (!GetToken(true)) { + return false; + } + + // Parse the layer name or name list if we aren't immediately + // followed by a "{", which indicates an anonymous layer. + bool isStatement = false; + if (tk->mType == eCSSToken_Ident) { + nsString* currentName = new nsString(); + currentName->Assign(tk->mIdent); + + bool parsing = true; + bool expectIdent = false; + while (parsing) { + if (!GetToken(true)) { + return false; + } + + switch (tk->mType) { + case eCSSToken_Symbol: { + if ('.' == tk->mSymbol) { + expectIdent = true; + if (!currentName->IsEmpty()) { + currentName->Append(tk->mSymbol); + continue; + } + parsing = false; + break; + } else if (',' == tk->mSymbol) { + if (expectIdent) { + parsing = false; + break; + } + nameList->AppendElement(*currentName); + currentName = new nsString(); + expectIdent = true; + continue; + } else if (';' == tk->mSymbol) { + if (expectIdent) { + parsing = false; + break; + } + nameList->AppendElement(*currentName); + currentName = new nsString(); + isStatement = true; + parsing = false; + break; + } else if ('{' == tk->mSymbol) { + if (expectIdent) { + parsing = false; + break; + } + nameList->AppendElement(*currentName); + uint32_t nameListLength = nameList->Length(); + if (nameListLength == 0 || nameListLength > 1) { + return false; + } + layerName.Assign(nameList->ElementAt(0)); + parsing = false; + break; + } + } + case eCSSToken_Ident: { + expectIdent = false; + currentName->Append(tk->mIdent); + break; + } + default: { + return false; + } + } + } + + if (expectIdent) { + UngetToken(); + return false; + } + } else if (tk->mType == eCSSToken_Symbol && '{' != tk->mSymbol) { + UngetToken(); + return false; + } + + if (isStatement) { + RefPtr rule = + new CSSLayerStatementRule(*nameList, linenum, colnum); + (*aAppendFunc)(rule, aProcessData); + return true; + } + + UngetToken(); + RefPtr rule = + new CSSLayerBlockRule(layerName, linenum, colnum); + return ParseGroupRule(rule, aAppendFunc, aProcessData); +} + bool CSSParserImpl::ParseCounterStyleRule(RuleAppendFunc aAppendFunc, void* aData) { @@ -18179,6 +18300,8 @@ nsCSSParser::Startup() "layout.css.control-characters.visible"); Preferences::AddBoolVarCache(&sLegacyNegationPseudoClassEnabled, "layout.css.legacy-negation-pseudo.enabled"); + Preferences::AddBoolVarCache(&sCascadeLayersEnabled, + "layout.css.cascade-layers.enabled"); } nsCSSParser::nsCSSParser(mozilla::css::Loader* aLoader, diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index ff3661c73d..0a9c55fc17 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -3932,7 +3932,8 @@ GatherDocRuleEnumFunc(css::Rule* aRule, void* aData) "mMustGatherDocumentRules is true"); if (css::Rule::MEDIA_RULE == type || - css::Rule::SUPPORTS_RULE == type) { + css::Rule::SUPPORTS_RULE == type || + css::Rule::LAYER_BLOCK_RULE == type) { css::GroupRule* groupRule = static_cast(aRule); if (!groupRule->EnumerateRulesForwards(GatherDocRuleEnumFunc, aData)) { return false; @@ -4011,7 +4012,8 @@ CascadeRuleEnumFunc(css::Rule* aRule, void* aData) } } else if (css::Rule::MEDIA_RULE == type || - css::Rule::SUPPORTS_RULE == type) { + css::Rule::SUPPORTS_RULE == type || + css::Rule::LAYER_BLOCK_RULE == type) { css::GroupRule* groupRule = static_cast(aRule); const bool use = groupRule->UseForPresentation(data->mPresContext, data->mCacheKey); diff --git a/layout/style/nsCSSRules.cpp b/layout/style/nsCSSRules.cpp index 08d2deb7f0..f31a813e07 100644 --- a/layout/style/nsCSSRules.cpp +++ b/layout/style/nsCSSRules.cpp @@ -36,6 +36,8 @@ #include "mozilla/dom/CSSNamespaceRuleBinding.h" #include "mozilla/dom/CSSImportRuleBinding.h" #include "mozilla/dom/CSSMediaRuleBinding.h" +#include "mozilla/dom/CSSLayerBlockRuleBinding.h" +#include "mozilla/dom/CSSLayerStatementRuleBinding.h" #include "mozilla/dom/CSSSupportsRuleBinding.h" #include "mozilla/dom/CSSMozDocumentRuleBinding.h" #include "mozilla/dom/CSSPageRuleBinding.h" @@ -247,10 +249,12 @@ GroupRuleRuleList::IndexedGetter(uint32_t aIndex, bool& aFound) // ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, + const nsString& aLayerName, uint32_t aLineNumber, uint32_t aColumnNumber) : Rule(aLineNumber, aColumnNumber) , mURLSpec(aURLSpec) , mMedia(aMedia) + , mLayerName(aLayerName) { MOZ_ASSERT(aMedia); // XXXbz This is really silly.... the mMedia here will be replaced @@ -259,8 +263,9 @@ ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec, } ImportRule::ImportRule(const ImportRule& aCopy) - : Rule(aCopy), - mURLSpec(aCopy.mURLSpec) + : Rule(aCopy) + , mURLSpec(aCopy.mURLSpec) + , mLayerName(aCopy.mLayerName) { // 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 @@ -412,6 +417,13 @@ ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet) return NS_OK; } +NS_IMETHODIMP +ImportRule::GetLayerName(nsAString & aLayerName) +{ + aLayerName = mLayerName; + return NS_OK; +} + /* virtual */ size_t ImportRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const { @@ -3351,3 +3363,229 @@ nsCSSCounterStyleRule::WrapObject(JSContext* aCx, { return CSSCounterStyleRuleBinding::Wrap(aCx, this, aGivenProto); } + +namespace mozilla { + +// ------------------------------------------- +// LayerStatementRule +// + +CSSLayerStatementRule::CSSLayerStatementRule( + const nsTArray& aNameList, + uint32_t aLineNumber, uint32_t aColumnNumber) + : Rule(aLineNumber, aColumnNumber) + , mNameList(aNameList) +{ +} + +CSSLayerStatementRule::CSSLayerStatementRule(const CSSLayerStatementRule& aCopy) + : Rule(aCopy) + , mNameList(aCopy.mNameList) +{ +} + +CSSLayerStatementRule::~CSSLayerStatementRule() +{ +} + +NS_IMPL_ADDREF_INHERITED(CSSLayerStatementRule, Rule) +NS_IMPL_RELEASE_INHERITED(CSSLayerStatementRule, Rule) + +bool +CSSLayerStatementRule::IsCCLeaf() const +{ + // We're not a leaf. + return false; +} + +// QueryInterface implementation for CSSLayerStatementRule +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(CSSLayerStatementRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSLayerStatementRule) +NS_INTERFACE_MAP_END_INHERITING(Rule) + +NS_IMPL_CYCLE_COLLECTION_CLASS(CSSLayerStatementRule) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSLayerStatementRule) + tmp->mNameList.Clear(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSLayerStatementRule, mozilla::css::Rule) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +#ifdef DEBUG +/* virtual */ void +CSSLayerStatementRule::List(FILE* out, int32_t aIndent) const +{ + // TODO +} +#endif + +/* virtual */ int32_t +CSSLayerStatementRule::GetType() const +{ + return Rule::LAYER_STATEMENT_RULE; +} + +/* virtual */ already_AddRefed +CSSLayerStatementRule::Clone() const +{ + RefPtr clone = new CSSLayerStatementRule(*this); + return clone.forget(); +} + +uint16_t +CSSLayerStatementRule::Type() const +{ + return nsIDOMCSSRule::LAYER_STATEMENT_RULE; +} + +void +CSSLayerStatementRule::GetCssTextImpl(nsAString& aCssText) const +{ + aCssText.AssignLiteral("@layer "); + for (uint32_t i = 0, i_end = mNameList.Length(); i != i_end; ++i) { + aCssText.Append(mNameList[i]); + if (i != i_end - 1) { + aCssText.AppendLiteral(", "); + } + } + aCssText.Append(';'); +} + +void +CSSLayerStatementRule::GetNameList(nsTArray& aResult) +{ + aResult = mNameList; +} + +/* virtual */ size_t +CSSLayerStatementRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + return aMallocSizeOf(this); +} + +/* virtual */ JSObject* +CSSLayerStatementRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + return CSSLayerStatementRuleBinding::Wrap(aCx, this, aGivenProto); +} + + +// ------------------------------------------- +// LayerBlockRule +// + +CSSLayerBlockRule::CSSLayerBlockRule(const nsString& aName, + uint32_t aLineNumber, uint32_t aColumnNumber) + : css::GroupRule(aLineNumber, aColumnNumber) + , mName(aName) +{ +} + +CSSLayerBlockRule::~CSSLayerBlockRule() +{ +} + +CSSLayerBlockRule::CSSLayerBlockRule(const CSSLayerBlockRule& aCopy) + : css::GroupRule(aCopy) + , mName(aCopy.mName) +{ +} + +#ifdef DEBUG +/* virtual */ void +CSSLayerBlockRule::List(FILE* out, int32_t aIndent) const +{ + // TODO +} +#endif + +/* virtual */ int32_t +CSSLayerBlockRule::GetType() const +{ + return Rule::LAYER_BLOCK_RULE; +} + +/* virtual */ already_AddRefed +CSSLayerBlockRule::Clone() const +{ + RefPtr clone = new CSSLayerBlockRule(*this); + return clone.forget(); +} + +/* virtual */ bool +CSSLayerBlockRule::UseForPresentation(nsPresContext* aPresContext, + nsMediaQueryResultCacheKey& aKey) +{ + // This will never be reached. + return true; +} + +NS_IMPL_ADDREF_INHERITED(CSSLayerBlockRule, css::GroupRule) +NS_IMPL_RELEASE_INHERITED(CSSLayerBlockRule, css::GroupRule) + +// QueryInterface implementation for CSSLayerBlockRule +NS_INTERFACE_MAP_BEGIN(CSSLayerBlockRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule) + NS_INTERFACE_MAP_ENTRY(nsIDOMCSSLayerBlockRule) +NS_INTERFACE_MAP_END_INHERITING(GroupRule) + +uint16_t +CSSLayerBlockRule::Type() const +{ + return nsIDOMCSSRule::LAYER_BLOCK_RULE; +} + +void +CSSLayerBlockRule::GetCssTextImpl(nsAString& aCssText) const +{ + aCssText.AssignLiteral("@layer "); + aCssText.Append(mName); + css::GroupRule::AppendRulesToCssText(aCssText); +} + +// nsIDOMCSSGroupingRule methods +NS_IMETHODIMP +CSSLayerBlockRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList) +{ + return css::GroupRule::GetCssRules(aRuleList); +} + +NS_IMETHODIMP +CSSLayerBlockRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval) +{ + return css::GroupRule::InsertRule(aRule, aIndex, _retval); +} + +NS_IMETHODIMP +CSSLayerBlockRule::DeleteRule(uint32_t aIndex) +{ + return css::GroupRule::DeleteRule(aIndex); +} + +// nsIDOMCSSLayerBlockRule methods +NS_IMETHODIMP +CSSLayerBlockRule::GetName(nsAString& aConditionText) +{ + aConditionText.Assign(mName); + return NS_OK; +} + +/* virtual */ size_t +CSSLayerBlockRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const +{ + size_t n = aMallocSizeOf(this); + n += css::GroupRule::SizeOfExcludingThis(aMallocSizeOf); + n += mName.SizeOfExcludingThisIfUnshared(aMallocSizeOf); + return n; +} + +/* virtual */ JSObject* +CSSLayerBlockRule::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) +{ + return CSSLayerBlockRuleBinding::Wrap(aCx, this, aGivenProto); +} + +} // namespace mozilla diff --git a/layout/style/nsCSSRules.h b/layout/style/nsCSSRules.h index 6dc9b141cc..1f66ef16ee 100644 --- a/layout/style/nsCSSRules.h +++ b/layout/style/nsCSSRules.h @@ -26,6 +26,8 @@ #include "nsIDOMCSSFontFaceRule.h" #include "nsIDOMCSSFontFeatureValuesRule.h" #include "nsIDOMCSSGroupingRule.h" +#include "nsIDOMCSSLayerBlockRule.h" +#include "nsIDOMCSSLayerStatementRule.h" #include "nsIDOMCSSMediaRule.h" #include "nsIDOMCSSMozDocumentRule.h" #include "nsIDOMCSSPageRule.h" @@ -737,4 +739,87 @@ private: uint32_t mGeneration; }; +namespace mozilla { + +class CSSLayerStatementRule final : public css::Rule, + public nsIDOMCSSLayerStatementRule +{ +public: + CSSLayerStatementRule(const nsTArray& aNameList, + uint32_t aLineNumber, uint32_t aColumnNumber); + CSSLayerStatementRule(const CSSLayerStatementRule& aCopy); + + // Rule methods +#ifdef DEBUG + 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; + + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSLayerStatementRule, Rule) + NS_DECL_ISUPPORTS_INHERITED + virtual bool IsCCLeaf() const override; + + // nsIDOMCSSLayerStatementRule interface + NS_DECL_NSIDOMCSSLAYERSTATEMENTRULE + + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + void GetNameList(nsTArray& aResult); + + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + +protected: + virtual ~CSSLayerStatementRule(); + + nsTArray mNameList; +}; + +class CSSLayerBlockRule final : public css::GroupRule, + public nsIDOMCSSLayerBlockRule +{ +public: + CSSLayerBlockRule(const nsString& aName, + uint32_t aLineNumber, uint32_t aColumnNumber); + CSSLayerBlockRule(const CSSLayerBlockRule& aCopy); + + // Rule methods +#ifdef DEBUG + 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; + + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMCSSGroupingRule interface + NS_DECL_NSIDOMCSSGROUPINGRULE + + // nsIDOMCSSLayerBlockRule interface + NS_DECL_NSIDOMCSSLAYERBLOCKRULE + + // WebIDL interface + uint16_t Type() const override; + void GetCssTextImpl(nsAString& aCssText) const override; + // Our XPCOM GetName is OK + + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override; + + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + +protected: + virtual ~CSSLayerBlockRule(); + + nsString mName; +}; + +} // namespace mozilla + #endif /* !defined(nsCSSRules_h_) */ diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 225e79cb44..d36d6a87ca 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -2684,6 +2684,9 @@ pref("layout.css.control-characters.visible", false); // Is support for ResizeObservers enabled? pref("layout.css.resizeobserver.enabled", true); +// Is support for cascade layers enabled? +pref("layout.css.cascade-layers.enabled", true); + // pref for which side vertical scrollbars should be on // 0 = end-side in UI direction // 1 = end-side in document/content direction