From 87bc2cab4e6007c4d129ed0b97b54b7f47bd987b Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Thu, 16 Apr 2020 17:54:38 -0400 Subject: [PATCH] Bug 1343879 - Be consistent about the parent style context the document-level anonymous content container should get: it should get no parent style context. Tag #1375 --- layout/base/nsCSSFrameConstructor.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index e88b2d62c5..3747642034 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -10751,16 +10751,22 @@ nsCSSFrameConstructor::AddFCItemsForAnonymousContent( } } - if (inheritFrame->GetType() == nsGkAtoms::canvasFrame) { - // CorrectStyleParentFrame returns nullptr if the prospective parent is - // the canvas frame, so avoid calling it in that situation. - } else { - inheritFrame = nsFrame::CorrectStyleParentFrame(inheritFrame, pseudo); - } - Element* originating = pseudo ? inheritFrame->GetContent()->AsElement() : nullptr; + nsIFrame* styleParentFrame = + nsFrame::CorrectStyleParentFrame(inheritFrame, pseudo); + // The only way we can not have a style parent now is if inheritFrame is the + // canvas frame and we're the NAC parent for all the things added via + // nsIDocument::InsertAnonymousContent. + MOZ_ASSERT_IF(!styleParentFrame, + inheritFrame->GetType() == nsGkAtoms::canvasFrame); + // And that anonymous div has no pseudo. + MOZ_ASSERT_IF(!styleParentFrame, !pseudo); + Element* originating = + pseudo ? styleParentFrame->GetContent()->AsElement() : nullptr; + nsStyleContext* parentStyle = + styleParentFrame ? styleParentFrame->StyleContext() : nullptr; styleContext = - ResolveStyleContext(inheritFrame->StyleContext(), content, &aState, originating); + ResolveStyleContext(parentStyle, content, &aState, originating); nsTArray* anonChildren = nullptr; if (!aAnonymousItems[i].mChildren.IsEmpty()) {