Bug 1468416 Part 1: Make nsGridContainerFrame::GetGridFrameWithComputedInfo use the same code to find the grid container frame as used by the layout algorithm itself. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 14 Jun 2018 16:35:42 -0700
changeset 809706 20f82e85cf729fe46285f3d840d045bdc4b8c681
parent 809559 6b6f3f6ecf142908b3e437d3bc3fac75540a9bcb
child 809707 4a64149e78bd62598a7f8a7980220fd4ba2e389e
push id113776
push userbwerth@mozilla.com
push dateFri, 22 Jun 2018 19:20:15 +0000
bugs1468416
milestone62.0a1
Bug 1468416 Part 1: Make nsGridContainerFrame::GetGridFrameWithComputedInfo use the same code to find the grid container frame as used by the layout algorithm itself. MozReview-Commit-ID: 85GeT1MOApS
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsGridContainerFrame.h
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -551,26 +551,25 @@ struct nsGridContainerFrame::GridItemInf
 
   explicit GridItemInfo(nsIFrame* aFrame,
                         const GridArea& aArea)
     : mFrame(aFrame)
     , mArea(aArea)
   {
     mState[eLogicalAxisBlock] = StateBits(0);
     mState[eLogicalAxisInline] = StateBits(0);
-    nsIFrame* innerFrame = InnerFrame(mFrame);
-    if (innerFrame->IsGridContainerFrame()) {
-      const auto* f = static_cast<nsGridContainerFrame*>(innerFrame);
+    nsGridContainerFrame* gridFrame = GetGridContainerFrame(mFrame);
+    if (gridFrame) {
       auto parentWM = aFrame->GetParent()->GetWritingMode();
-      bool isOrthogonal = parentWM.IsOrthogonalTo(f->GetWritingMode());
-      if (f->IsColSubgrid()) {
+      bool isOrthogonal = parentWM.IsOrthogonalTo(gridFrame->GetWritingMode());
+      if (gridFrame->IsColSubgrid()) {
         mState[isOrthogonal ? eLogicalAxisBlock : eLogicalAxisInline] =
           StateBits::eIsSubgrid;
       }
-      if (f->IsRowSubgrid()) {
+      if (gridFrame->IsRowSubgrid()) {
         mState[isOrthogonal ? eLogicalAxisInline : eLogicalAxisBlock] =
           StateBits::eIsSubgrid;
       }
     }
     mBaselineOffset[eLogicalAxisBlock] = nscoord(0);
     mBaselineOffset[eLogicalAxisInline] = nscoord(0);
   }
 
@@ -632,28 +631,16 @@ struct nsGridContainerFrame::GridItemInf
   void Dump() const;
 #endif
 
   static bool IsStartRowLessThan(const GridItemInfo* a, const GridItemInfo* b)
   {
     return a->mArea.mRows.mStart < b->mArea.mRows.mStart;
   }
 
-  // Return the inner frame of aFrame that might be a grid container.
-  // This drills down through scroll frames and such.
-  static nsIFrame* InnerFrame(nsIFrame* aFrame)
-  {
-    nsIFrame* inner = aFrame;
-    if (MOZ_UNLIKELY(aFrame->IsFieldSetFrame())) {
-      inner = static_cast<nsFieldSetFrame*>(aFrame)->GetInner();
-    }
-    inner = inner->GetContentInsertionFrame();
-    return inner ? inner : aFrame;
-  }
-
   nsIFrame* const mFrame;
   GridArea mArea;
   // Offset from the margin edge to the baseline (LogicalAxis index).  It's from
   // the start edge when eFirstBaseline is set, end edge otherwise. It's mutable
   // since we update the value fairly late (just before reflowing the item).
   mutable nscoord mBaselineOffset[2];
   mutable StateBits mState[2]; // state bits per axis (LogicalAxis index)
   static_assert(mozilla::eLogicalAxisBlock == 0, "unexpected index value");
@@ -7003,33 +6990,36 @@ nsGridContainerFrame::TrackSize::Dump() 
   if (mState & eBreakBefore) {
     printf("break-before ");
   }
 }
 
 #endif // DEBUG
 
 nsGridContainerFrame*
+nsGridContainerFrame::GetGridContainerFrame(nsIFrame* aFrame)
+{
+  nsGridContainerFrame* gridFrame = nullptr;
+
+  if (aFrame) {
+    nsIFrame* inner = aFrame;
+    if (MOZ_UNLIKELY(aFrame->IsFieldSetFrame())) {
+      inner = static_cast<nsFieldSetFrame*>(aFrame)->GetInner();
+    }
+    inner = inner->GetContentInsertionFrame();
+    nsIFrame* possibleGridFrame = inner ? inner : aFrame;
+    gridFrame = possibleGridFrame->IsGridContainerFrame() ?
+      static_cast<nsGridContainerFrame*>(possibleGridFrame) : nullptr;
+  }
+  return gridFrame;
+}
+
+nsGridContainerFrame*
 nsGridContainerFrame::GetGridFrameWithComputedInfo(nsIFrame* aFrame)
 {
-  // Prepare a lambda function that we may need to call multiple times.
-  auto GetGridContainerFrame = [](nsIFrame *aFrame) {
-    // Return the aFrame's content insertion frame, iff it is
-    // a grid container.
-    nsGridContainerFrame* gridFrame = nullptr;
-
-    if (aFrame) {
-      nsIFrame* contentFrame = aFrame->GetContentInsertionFrame();
-      if (contentFrame && (contentFrame->IsGridContainerFrame())) {
-        gridFrame = static_cast<nsGridContainerFrame*>(contentFrame);
-      }
-    }
-    return gridFrame;
-  };
-
   nsGridContainerFrame* gridFrame = GetGridContainerFrame(aFrame);
   if (gridFrame) {
     // if any of our properties are missing, generate them
     bool reflowNeeded = (!gridFrame->HasProperty(GridColTrackInfo()) ||
                          !gridFrame->HasProperty(GridRowTrackInfo()) ||
                          !gridFrame->HasProperty(GridColumnLineInfo()) ||
                          !gridFrame->HasProperty(GridRowLineInfo()));
 
--- a/layout/generic/nsGridContainerFrame.h
+++ b/layout/generic/nsGridContainerFrame.h
@@ -241,17 +241,23 @@ public:
   }
   /** Return true if this frame has any subgrid items. */
   bool HasSubgridItems() const {
     return HasAnyStateBits(NS_STATE_GRID_HAS_ROW_SUBGRID_ITEM |
                            NS_STATE_GRID_HAS_COL_SUBGRID_ITEM);
   }
 
   /**
-   * Return a containing grid frame, and ensure it has computed grid info
+   * Return a container grid frame for the supplied frame, if available.
+   * @return nullptr if aFrame has no grid container.
+   */
+  static nsGridContainerFrame* GetGridContainerFrame(nsIFrame* aFrame);
+
+  /**
+   * Return a container grid frame, and ensure it has computed grid info
    * @return nullptr if aFrame has no grid container, or frame was destroyed
    * @note this might destroy layout/style data since it may flush layout
    */
   static nsGridContainerFrame* GetGridFrameWithComputedInfo(nsIFrame* aFrame);
 
   struct TrackSize;
   struct GridItemInfo;
   struct GridReflowInput;