Bug 1494332 - Avoid setting the has-first-letter child bit on a first-line. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 27 Sep 2018 13:16:00 +0000
changeset 486901 31d61c73ab751904374d1bdc81c594add80b4cde
parent 486900 126ffa5ecf7af5d432e0df94e474db53b1756d02
child 486902 f3bfb76e088a2cbdd944bda1fc4724d18eca2ae4
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersbzbarsky
bugs1494332
milestone64.0a1
Bug 1494332 - Avoid setting the has-first-letter child bit on a first-line. r=bzbarsky We rely on the bit being on the block to restyle them in the right order. Differential Revision: https://phabricator.services.mozilla.com/D7086
layout/base/crashtests/1494332.html
layout/base/crashtests/crashtests.list
layout/base/nsCSSFrameConstructor.cpp
new file mode 100644
--- /dev/null
+++ b/layout/base/crashtests/1494332.html
@@ -0,0 +1,6 @@
+  <style>
+    body::first-letter,
+    body::first-line {
+  </style>
+  XXX {
+  <img id="h" srcset="B"></img>
--- a/layout/base/crashtests/crashtests.list
+++ b/layout/base/crashtests/crashtests.list
@@ -539,9 +539,10 @@ load 1464737.html
 load 1466638.html
 load 1467688.html
 load 1467964.html
 load 1469354.html
 pref(layout.accessiblecaret.enabled,true) load 1472020.html
 load 1472027.html
 load 1489149.html
 load 1490037.html
+load 1494332.html
 load 1494030.html
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -10577,16 +10577,19 @@ nsCSSFrameConstructor::CreateLetterFrame
       aResult.AddChild(letterFrame);
       NS_ASSERTION(!aBlockFrame->GetPrevContinuation(),
                    "should have the first continuation here");
       aBlockFrame->AddStateBits(NS_BLOCK_HAS_FIRST_LETTER_CHILD);
     }
     MOZ_ASSERT(!aBlockFrame->GetPrevContinuation(),
                "Setting up a first-letter frame on a non-first block continuation?");
     auto parent = static_cast<nsContainerFrame*>(aParentFrame->FirstContinuation());
+    if (MOZ_UNLIKELY(parent->IsLineFrame())) {
+      parent = parent->GetParent();
+    }
     parent->SetHasFirstLetterChild();
     aBlockFrame->SetProperty(nsContainerFrame::FirstLetterProperty(),
                              letterFrame);
     aTextContent->SetPrimaryFrame(textFrame);
   }
 }
 
 void
@@ -10695,16 +10698,17 @@ FindFirstLetterFrame(nsIFrame* aFrame, n
 }
 
 static void ClearHasFirstLetterChildFrom(nsContainerFrame* aParentFrame)
 {
   MOZ_ASSERT(aParentFrame);
   auto* parent =
     static_cast<nsContainerFrame*>(aParentFrame->FirstContinuation());
   if (MOZ_UNLIKELY(parent->IsLineFrame())) {
+    MOZ_ASSERT(!parent->HasFirstLetterChild());
     parent = parent->GetParent();
   }
   MOZ_ASSERT(parent->HasFirstLetterChild());
   parent->ClearHasFirstLetterChild();
 }
 
 void
 nsCSSFrameConstructor::RemoveFloatingFirstLetterFrames(