Bug 1343879. Be consistent about the parent style context the document-level anonymous content container should get: it should get no parent style context. r=bholley a=gchang
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 08 Mar 2017 03:14:10 -0500
changeset 375170 50c32a3075f835a528491d651e4b23f6fbdba268
parent 375169 1f56b8617108ddd27b36f18bdf169ef20da1bcc4
child 375171 dfda7df6b72ed25b253df488e54b79a0edf5256c
push id10887
push usercbook@mozilla.com
push dateMon, 13 Mar 2017 10:24:22 +0000
treeherdermozilla-aurora@e8fdbc7507a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, gchang
bugs1343879
milestone54.0a2
Bug 1343879. Be consistent about the parent style context the document-level anonymous content container should get: it should get no parent style context. r=bholley a=gchang MozReview-Commit-ID: 8cVsXhVWBgS
layout/base/nsCSSFrameConstructor.cpp
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -10874,26 +10874,32 @@ nsCSSFrameConstructor::AddFCItemsForAnon
     // for us.
     nsIFrame* inheritFrame = aFrame;
     if (!content->IsNativeScrollbarContent()) {
       while (inheritFrame->GetContent()->IsNativeAnonymous()) {
         inheritFrame = inheritFrame->GetInFlowParent();
       }
     }
 
-    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<nsIAnonymousContentCreator::ContentInfo>* anonChildren = nullptr;
     if (!aAnonymousItems[i].mChildren.IsEmpty()) {
       anonChildren = &aAnonymousItems[i].mChildren;
     }
 
     uint32_t flags = ITEM_ALLOW_XBL_BASE | ITEM_ALLOW_PAGE_BREAK |
                      ITEM_IS_ANONYMOUSCONTENTCREATOR_CONTENT | aExtraFlags;