Bug 1008969 - part 1, Initialize the nsHTMLReflowState "frame type" correctly for display:grid/inline-grid. Add nsIFrame::IsFlexOrGridItem(), and use it to share some flexbox code in nsHTMLReflowState. r=dholbert
authorMats Palmgren <matspal@gmail.com>
Mon, 12 May 2014 21:16:05 +0000
changeset 182755 7048bc41993fc4e70898ad3623043260fec3255e
parent 182754 6ad82809e623f11381ca1835431f69264491374f
child 182756 46cf8e7066203430fc3c158ae81d0961157c2089
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdholbert
bugs1008969
milestone32.0a1
Bug 1008969 - part 1, Initialize the nsHTMLReflowState "frame type" correctly for display:grid/inline-grid. Add nsIFrame::IsFlexOrGridItem(), and use it to share some flexbox code in nsHTMLReflowState. r=dholbert
layout/base/nsDisplayList.cpp
layout/generic/nsHTMLReflowState.cpp
layout/generic/nsIFrame.h
layout/generic/nsIFrameInlines.h
--- a/layout/base/nsDisplayList.cpp
+++ b/layout/base/nsDisplayList.cpp
@@ -1684,17 +1684,17 @@ nsDisplayItem::MaxActiveLayers()
   }
 
   return sMaxLayers;
 }
 
 int32_t
 nsDisplayItem::ZIndex() const
 {
-  if (!mFrame->IsPositioned() && !mFrame->IsFlexItem())
+  if (!mFrame->IsPositioned() && !mFrame->IsFlexOrGridItem())
     return 0;
 
   const nsStylePosition* position = mFrame->StylePosition();
   if (position->mZIndex.GetUnit() == eStyleUnit_Integer)
     return position->mZIndex.GetIntValue();
 
   // sort the auto and 0 elements together
   return 0;
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -136,19 +136,19 @@ FontSizeInflationListMarginAdjustment(co
 // and padding against the containing-block height, rather than its width.
 nsCSSOffsetState::nsCSSOffsetState(nsIFrame *aFrame,
                                    nsRenderingContext *aRenderingContext,
                                    nscoord aContainingBlockWidth)
   : frame(aFrame)
   , rendContext(aRenderingContext)
   , mWritingMode(aFrame->GetWritingMode())
 {
-  MOZ_ASSERT(!aFrame->IsFlexItem(),
+  MOZ_ASSERT(!aFrame->IsFlexOrGridItem(),
              "We're about to resolve vertical percent margin & padding "
-             "values against CB width, which is incorrect for flex items");
+             "values against CB width, which is incorrect for flex/grid items");
   InitOffsets(aContainingBlockWidth, aContainingBlockWidth, frame->GetType());
 }
 
 // Initialize a reflow state for a child frame's reflow. Some state
 // is copied from the parent reflow state; the remaining state is
 // computed.
 nsHTMLReflowState::nsHTMLReflowState(nsPresContext*           aPresContext,
                                      const nsHTMLReflowState& aParentReflowState,
@@ -712,26 +712,28 @@ nsHTMLReflowState::InitFrameType(nsIAtom
   }
   else {
     switch (GetDisplay()) {
     case NS_STYLE_DISPLAY_BLOCK:
     case NS_STYLE_DISPLAY_LIST_ITEM:
     case NS_STYLE_DISPLAY_TABLE:
     case NS_STYLE_DISPLAY_TABLE_CAPTION:
     case NS_STYLE_DISPLAY_FLEX:
+    case NS_STYLE_DISPLAY_GRID:
       frameType = NS_CSS_FRAME_TYPE_BLOCK;
       break;
 
     case NS_STYLE_DISPLAY_INLINE:
     case NS_STYLE_DISPLAY_INLINE_BLOCK:
     case NS_STYLE_DISPLAY_INLINE_TABLE:
     case NS_STYLE_DISPLAY_INLINE_BOX:
     case NS_STYLE_DISPLAY_INLINE_XUL_GRID:
     case NS_STYLE_DISPLAY_INLINE_STACK:
     case NS_STYLE_DISPLAY_INLINE_FLEX:
+    case NS_STYLE_DISPLAY_INLINE_GRID:
       frameType = NS_CSS_FRAME_TYPE_INLINE;
       break;
 
     case NS_STYLE_DISPLAY_TABLE_CELL:
     case NS_STYLE_DISPLAY_TABLE_ROW_GROUP:
     case NS_STYLE_DISPLAY_TABLE_COLUMN:
     case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP:
     case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP:
@@ -1868,17 +1870,17 @@ GetFlexContainer(nsIFrame* aFrame)
 // For everything else: the CSS21 spec requires that margin and padding
 // percentage values are calculated with respect to the *width* of the
 // containing block, even for margin & padding in the vertical axis.
 static nscoord
 VerticalOffsetPercentBasis(const nsIFrame* aFrame,
                            nscoord aContainingBlockWidth,
                            nscoord aContainingBlockHeight)
 {
-  if (!aFrame->IsFlexItem()) {
+  if (!aFrame->IsFlexOrGridItem()) {
     return aContainingBlockWidth;
   }
 
   if (aContainingBlockHeight == NS_AUTOHEIGHT) {
     return 0;
   }
 
   return aContainingBlockHeight;
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -2926,16 +2926,20 @@ NS_PTR_TO_INT32(frame->Properties().Get(
    */
   virtual void FindCloserFrameForSelection(nsPoint aPoint,
                                            FrameWithDistance* aCurrentBestFrame);
 
   /**
    * Is this a flex item? (i.e. a non-abs-pos child of a flex container)
    */
   inline bool IsFlexItem() const;
+  /**
+   * Is this a flex or grid item? (i.e. a non-abs-pos child of a flex/grid container)
+   */
+  inline bool IsFlexOrGridItem() const;
 
   inline bool IsBlockInside() const;
   inline bool IsBlockOutside() const;
   inline bool IsInlineOutside() const;
   inline uint8_t GetDisplay() const;
   inline bool IsFloating() const;
   inline bool IsPositioned() const;
   inline bool IsRelativelyPositioned() const;
--- a/layout/generic/nsIFrameInlines.h
+++ b/layout/generic/nsIFrameInlines.h
@@ -14,16 +14,28 @@ bool
 nsIFrame::IsFlexItem() const
 {
   return mParent &&
     mParent->GetType() == nsGkAtoms::flexContainerFrame &&
     !(GetStateBits() & NS_FRAME_OUT_OF_FLOW);
 }
 
 bool
+nsIFrame::IsFlexOrGridItem() const
+{
+  if (mParent) {
+    nsIAtom* t = mParent->GetType();
+    return (t == nsGkAtoms::flexContainerFrame ||
+            t == nsGkAtoms::gridContainerFrame) &&
+      !(GetStateBits() & NS_FRAME_OUT_OF_FLOW);
+  }
+  return false;
+}
+
+bool
 nsIFrame::IsFloating() const
 {
   return StyleDisplay()->IsFloating(this);
 }
 
 bool
 nsIFrame::IsPositioned() const
 {