Bug 907396 - Flex/Grid container changes for display:contents. r=dholbert
authorMats Palmgren <matspal@gmail.com>
Thu, 20 Nov 2014 18:24:09 +0000
changeset 216687 39bd6adc47edf1014ab5d066f3293fe4e7640375
parent 216686 ff8c07f86822e54335838081fb728ffb32e12192
child 216688 07fe7c94219fa05645ad96b4529a8ab8ca4e3e80
push id27858
push userkwierso@gmail.com
push dateFri, 21 Nov 2014 01:35:46 +0000
treeherdermozilla-central@6309710dd71d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs907396
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 907396 - Flex/Grid container changes for display:contents. r=dholbert
layout/style/nsStyleContext.cpp
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -504,18 +504,31 @@ nsStyleContext::ApplyStyleFixups(bool aS
   // Adjust the "display" values of flex and grid items (but not for raw text,
   // placeholders, or table-parts). CSS3 Flexbox section 4 says:
   //   # The computed 'display' of a flex item is determined
   //   # by applying the table in CSS 2.1 Chapter 9.7.
   // ...which converts inline-level elements to their block-level equivalents.
   // Any direct children of elements with Ruby display values which are
   // block-level are converted to their inline-level equivalents.
   if (!aSkipParentDisplayBasedStyleFixup && mParent) {
-    const nsStyleDisplay* parentDisp = mParent->StyleDisplay();
-    if (parentDisp->IsFlexOrGridDisplayType() &&
+    // Skip display:contents ancestors to reach the potential container.
+    // (If there are only display:contents ancestors between this node and
+    // a flex/grid container ancestor, then this node is a flex/grid item, since
+    // its parent *in the frame tree* will be the flex/grid container. So we treat
+    // it like a flex/grid item here.)
+    nsStyleContext* containerContext = mParent;
+    const nsStyleDisplay* containerDisp = containerContext->StyleDisplay();
+    while (containerDisp->mDisplay == NS_STYLE_DISPLAY_CONTENTS) {
+      if (!containerContext->GetParent()) {
+        break;
+      }
+      containerContext = containerContext->GetParent();
+      containerDisp = containerContext->StyleDisplay();
+    }
+    if (containerDisp->IsFlexOrGridDisplayType() &&
         GetPseudo() != nsCSSAnonBoxes::mozNonElement) {
       uint8_t displayVal = disp->mDisplay;
       // Skip table parts.
       // NOTE: This list needs to be kept in sync with
       // nsCSSFrameConstructor.cpp's "sDisplayData" array -- specifically,
       // this should be the list of display-values that have
       // FCDATA_DESIRED_PARENT_TYPE_TO_BITS specified in that array.
       if (NS_STYLE_DISPLAY_TABLE_CAPTION      != displayVal &&
@@ -538,18 +551,18 @@ nsStyleContext::ApplyStyleFixups(bool aS
           NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle(),
                        "We shouldn't be changing the display value of "
                        "positioned content (and we should have already "
                        "converted its display value to be block-level...)");
           nsStyleDisplay *mutable_display =
             static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
           mutable_display->mDisplay = displayVal;
         }
-      } 
-    } else if (parentDisp->IsRubyDisplayType()) {
+      }
+    } else if (containerDisp->IsRubyDisplayType()) {
       uint8_t displayVal = disp->mDisplay;
       nsRuleNode::EnsureInlineDisplay(displayVal);
       // The display change should only occur for "in-flow" children
       if (displayVal != disp->mDisplay && 
           !disp->IsOutOfFlowStyle()) {
         nsStyleDisplay *mutable_display =
           static_cast<nsStyleDisplay*>(GetUniqueStyleData(eStyleStruct_Display));
         mutable_display->mDisplay = displayVal;