Bug 1468416 Part 1: Make nsGridContainerFrame::GetGridFrameWithComputedInfo use the same code to find the grid container frame as used by the layout algorithm itself. r=mats
authorBrad Werth <bwerth@mozilla.com>
Thu, 14 Jun 2018 16:35:42 -0700
changeset 480137 ad40d4b300a6d0b152d7ca7db2eae4bda2b352c0
parent 480136 0d4eda5546ddd0317e305d42280c58fb8773a66d
child 480138 f63604ec72d12f32ba0691c3f05ba40bdf533b82
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1468416
milestone62.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 1468416 Part 1: Make nsGridContainerFrame::GetGridFrameWithComputedInfo use the same code to find the grid container frame as used by the layout algorithm itself. r=mats 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;