diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index c467b5d65268..01e1718532b4 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -180,38 +180,6 @@ nsIContent::GetAssignedSlotByMode() const return slot; } -nsINode* -nsIContent::GetFlattenedTreeParentForDocumentElementNAC() const -{ - MOZ_ASSERT(IsRootOfNativeAnonymousSubtree()); - MOZ_ASSERT(GetParent()); - MOZ_ASSERT(GetParent() == OwnerDoc()->GetRootElement()); - MOZ_ASSERT(!IsGeneratedContentContainerForAfter()); - MOZ_ASSERT(!IsGeneratedContentContainerForBefore()); - - nsIContent* parent = GetParent(); - AutoTArray rootElementNAC; - nsContentUtils::AppendNativeAnonymousChildren( - parent, rootElementNAC, nsIContent::eSkipDocumentLevelNativeAnonymousContent); - const bool isDocLevelNAC = !rootElementNAC.Contains(this); - -#ifdef DEBUG - { - // The code below would be slightly more direct, but it gets the wrong - // answer when the root scrollframe is being bootstrapped and we're - // trying to style the scrollbars (since GetRootScrollFrame() still returns - // null at that point). Verify that the results match otherwise. - AutoTArray docLevelNAC; - nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(OwnerDoc(), docLevelNAC); - nsIPresShell* shell = OwnerDoc()->GetShell(); - MOZ_ASSERT_IF(shell && shell->GetRootScrollFrame(), - isDocLevelNAC == docLevelNAC.Contains(this)); - } -#endif - - return isDocLevelNAC ? OwnerDocAsNode() : parent; -} - nsIContent::IMEState nsIContent::GetDesiredIMEState() { diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 8714f4b3607e..fd7c7f6587fb 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -10490,6 +10490,9 @@ nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo( nsTArray& aElements) { MOZ_ASSERT(aDocument); +#ifdef DEBUG + size_t oldLength = aElements.Length(); +#endif if (nsIPresShell* presShell = aDocument->GetShell()) { if (nsIFrame* scrollFrame = presShell->GetRootScrollFrame()) { @@ -10505,6 +10508,14 @@ nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo( } } } + +#ifdef DEBUG + for (size_t i = oldLength; i < aElements.Length(); i++) { + MOZ_ASSERT( + aElements[i]->GetProperty(nsGkAtoms::docLevelNativeAnonymousContent), + "Someone here has lied, or missed to flag the node"); + } +#endif } static void diff --git a/dom/base/nsGkAtomList.h b/dom/base/nsGkAtomList.h index f3dfea2b8cfa..c9e93e726ecf 100644 --- a/dom/base/nsGkAtomList.h +++ b/dom/base/nsGkAtomList.h @@ -2182,7 +2182,8 @@ GK_ATOM(genConInitializerProperty, "QuoteNodeProperty") GK_ATOM(labelMouseDownPtProperty, "LabelMouseDownPtProperty") GK_ATOM(lockedStyleStates, "lockedStyleStates") GK_ATOM(apzCallbackTransform, "apzCallbackTransform") -GK_ATOM(restylableAnonymousNode, "restylableAnonymousNode") +GK_ATOM(restylableAnonymousNode, "restylableAnonymousNode") // bool +GK_ATOM(docLevelNativeAnonymousContent, "docLevelNativeAnonymousContent") // bool GK_ATOM(paintRequestTime, "PaintRequestTime") GK_ATOM(pseudoProperty, "PseudoProperty") // CSSPseudoElementType GK_ATOM(manualNACProperty, "ManualNACProperty") // ManualNAC* diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h index aad60a593f68..e0117bf5ef8f 100644 --- a/dom/base/nsIContent.h +++ b/dom/base/nsIContent.h @@ -616,16 +616,6 @@ public: */ inline nsIContent* GetFlattenedTreeParent() const; - /** - * Get the flattened tree parent for NAC holding from the document element, - * from the point of view of the style system. - * - * Document-level anonymous content holds from the document element, even - * though they should not be treated as such (they should be parented to the - * document instead, and shouldn't inherit from the document element). - */ - nsINode* GetFlattenedTreeParentForDocumentElementNAC() const; - /** * API to check if this is a link that's traversed in response to user input * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for diff --git a/dom/base/nsIContentInlines.h b/dom/base/nsIContentInlines.h index 8fc5136d76e4..f724a578b00f 100644 --- a/dom/base/nsIContentInlines.h +++ b/dom/base/nsIContentInlines.h @@ -78,10 +78,10 @@ GetFlattenedTreeParentNode(const nsINode* aNode) if (aType == nsINode::eForStyle && content->IsRootOfNativeAnonymousSubtree() && - parentAsContent == content->OwnerDoc()->GetRootElement() && - !content->IsGeneratedContentContainerForAfter() && - !content->IsGeneratedContentContainerForBefore()) { - return content->GetFlattenedTreeParentForDocumentElementNAC(); + parentAsContent == content->OwnerDoc()->GetRootElement()) { + const bool docLevel = + content->GetProperty(nsGkAtoms::docLevelNativeAnonymousContent); + return docLevel ? content->OwnerDocAsNode() : parent; } if (content->IsRootOfAnonymousSubtree()) { diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 528db52a6879..9fc55c67053c 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -557,7 +557,7 @@ public: * * For all other cases OwnerDoc and GetOwnerDocument behave identically. */ - nsIDocument *OwnerDoc() const + nsIDocument* OwnerDoc() const { return mNodeInfo->GetDocument(); } @@ -566,7 +566,7 @@ public: * Return the "owner document" of this node as an nsINode*. Implemented * in nsIDocument.h. */ - nsINode *OwnerDocAsNode() const; + inline nsINode* OwnerDocAsNode() const; /** * Returns true if the content has an ancestor that is a document. diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index ec23f4894dcd..2aac22e3e030 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -93,6 +93,9 @@ nsCanvasFrame::CreateAnonymousContent(nsTArray& aElements) reinterpret_cast(true)); #endif // DEBUG + mCustomContentContainer->SetProperty(nsGkAtoms::docLevelNativeAnonymousContent, + reinterpret_cast(true)); + aElements.AppendElement(mCustomContentContainer); // Do not create an accessible object for the container. diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 7b4884df33ee..694c1d663088 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -4612,12 +4612,11 @@ ScrollFrameHelper::CreateAnonymousContent( } } - nsNodeInfoManager *nodeInfoManager = - presContext->Document()->NodeInfoManager(); - RefPtr nodeInfo; - nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbar, nullptr, - kNameSpaceID_XUL, - nsINode::ELEMENT_NODE); + nsNodeInfoManager* nodeInfoManager = presContext->Document()->NodeInfoManager(); + RefPtr nodeInfo = + nodeInfoManager->GetNodeInfo(nsGkAtoms::scrollbar, nullptr, + kNameSpaceID_XUL, + nsINode::ELEMENT_NODE); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); if (canHaveHorizontal) { @@ -4636,6 +4635,9 @@ ScrollFrameHelper::CreateAnonymousContent( mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough, NS_LITERAL_STRING("always"), false); if (mIsRoot) { + mHScrollbarContent->SetProperty(nsGkAtoms::docLevelNativeAnonymousContent, + reinterpret_cast(true)); + mHScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::root_, NS_LITERAL_STRING("true"), false); } @@ -4659,6 +4661,8 @@ ScrollFrameHelper::CreateAnonymousContent( mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::clickthrough, NS_LITERAL_STRING("always"), false); if (mIsRoot) { + mVScrollbarContent->SetProperty(nsGkAtoms::docLevelNativeAnonymousContent, + reinterpret_cast(true)); mVScrollbarContent->SetAttr(kNameSpaceID_None, nsGkAtoms::root_, NS_LITERAL_STRING("true"), false); } @@ -4697,11 +4701,13 @@ ScrollFrameHelper::CreateAnonymousContent( mResizerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::dir, dir, false); if (mIsRoot) { + mResizerContent->SetProperty(nsGkAtoms::docLevelNativeAnonymousContent, + reinterpret_cast(true)); + Element* browserRoot = GetBrowserRoot(mOuter->GetContent()); mCollapsedResizer = !(browserRoot && browserRoot->HasAttr(kNameSpaceID_None, nsGkAtoms::showresizer)); - } - else { + } else { mResizerContent->SetAttr(kNameSpaceID_None, nsGkAtoms::element, NS_LITERAL_STRING("_parent"), false); } @@ -4718,6 +4724,10 @@ ScrollFrameHelper::CreateAnonymousContent( kNameSpaceID_XUL, nsINode::ELEMENT_NODE); NS_TrustedNewXULElement(getter_AddRefs(mScrollCornerContent), nodeInfo.forget()); + if (mIsRoot) { + mScrollCornerContent->SetProperty(nsGkAtoms::docLevelNativeAnonymousContent, + reinterpret_cast(true)); + } if (!aElements.AppendElement(mScrollCornerContent)) return NS_ERROR_OUT_OF_MEMORY; }