diff options
author | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 05:01:17 -0400 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2020-04-17 05:01:17 -0400 |
commit | 0d362ca50335d964a78dbba7e7d32574ee67899a (patch) | |
tree | 8b5de5f34019b97ad0b3c155c270a810608cd775 /layout/base | |
parent | de45820b64ab03768336c7242622ef9f499347cf (diff) | |
download | UXP-0d362ca50335d964a78dbba7e7d32574ee67899a.tar UXP-0d362ca50335d964a78dbba7e7d32574ee67899a.tar.gz UXP-0d362ca50335d964a78dbba7e7d32574ee67899a.tar.lz UXP-0d362ca50335d964a78dbba7e7d32574ee67899a.tar.xz UXP-0d362ca50335d964a78dbba7e7d32574ee67899a.zip |
Bug 1330843 - Allow JS to create NAC pseudo-elements
Tag #1375
Diffstat (limited to 'layout/base')
-rw-r--r-- | layout/base/RestyleManager.cpp | 19 | ||||
-rw-r--r-- | layout/base/nsCSSFrameConstructor.cpp | 13 |
2 files changed, 31 insertions, 1 deletions
diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index c3eeb8c71..16db4c18b 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -1062,6 +1062,25 @@ ElementForStyleContext(nsIContent* aParentContent, return f->GetContent()->AsElement(); } + Element* frameElement = aFrame->GetContent()->AsElement(); + if (frameElement->IsNativeAnonymous() && + nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(aPseudoType)) { + // NAC-implemented pseudos use the closest non-NAC element as their + // element to inherit from. + // + // FIXME(heycam): In theory we shouldn't need to limit this only to + // JS-created pseudo-implementing NAC, as all pseudo-implementing + // should use the closest non-native anonymous ancestor element as + // its originating element. But removing that part of the condition + // reveals some bugs in style resultion with display:contents and + // XBL. See bug 1345809. + Element* originatingElement = + nsContentUtils::GetClosestNonNativeAnonymousAncestor(frameElement); + if (originatingElement) { + return originatingElement; + } + } + if (aParentContent) { return aParentContent->AsElement(); } diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index 3be7c2a0b..b574e7690 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -5041,8 +5041,19 @@ nsCSSFrameConstructor::ResolveStyleContext(nsStyleContext* aParentStyleContext, aParentStyleContext); } } else { - MOZ_ASSERT(aOriginatingElementOrNull); MOZ_ASSERT(aContent->IsInNativeAnonymousSubtree()); + if (!aOriginatingElementOrNull) { + // For pseudo-implementing NAC created by JS using the ChromeOnly + // document.createElement(..., { pseudo: ... }) API, we find the + // originating element by lookup the tree until we find a non-NAC + // ancestor. (These are the correct semantics for C++-generated pseudo- + // implementing NAC as well, but for those cases we already have a + // correct originating element passed in.) + MOZ_ASSERT(nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(pseudoType)); + aOriginatingElementOrNull = + nsContentUtils::GetClosestNonNativeAnonymousAncestor(aContent->AsElement()); + } + MOZ_ASSERT(aOriginatingElementOrNull); result = styleSet->ResolvePseudoElementStyle(aOriginatingElementOrNull, pseudoType, aParentStyleContext, |