Bug 1634911 - Simplify loops over lines in block layout to use ranged for. r=emilio
☠☠ backed out by 144027682685 ☠ ☠
authorShishir Jaiswal <shishirlearnz@hotmail.com>
Tue, 19 May 2020 16:54:02 +0000
changeset 530853 39dff7adfc302a9fd6cbcfa93d53acc481823828
parent 530852 a9eaeeec414894e9968976cdf58ae390d0244970
child 530854 c28b24aa7cec851c34e51af9a8f323acdd8bfd73
push id116411
push userealvarez@mozilla.com
push dateTue, 19 May 2020 16:54:54 +0000
treeherderautoland@39dff7adfc30 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1634911
milestone78.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 1634911 - Simplify loops over lines in block layout to use ranged for. r=emilio - Fixed clang-tidy warning - Addressed the final review comments. - Fixed the build failures happening in DEBUG mode. Had to revert the range based for loop usage at one place. Differential Revision: https://phabricator.services.mozilla.com/D75673
layout/base/nsLayoutUtils.cpp
layout/generic/nsBlockFrame.cpp
layout/generic/nsBlockFrame.h
layout/generic/nsLineBox.h
layout/generic/nsTextFrame.cpp
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -6396,39 +6396,37 @@ bool nsLayoutUtils::GetFirstLinePosition
       }
       return false;
     }
 
     // No baseline.
     return false;
   }
 
-  for (nsBlockFrame::ConstLineIterator line = block->LinesBegin(),
-                                       line_end = block->LinesEnd();
-       line != line_end; ++line) {
-    if (line->IsBlock()) {
-      nsIFrame* kid = line->mFirstChild;
+  for (const auto& line : block->Lines()) {
+    if (line.IsBlock()) {
+      const nsIFrame* kid = line.mFirstChild;
       LinePosition kidPosition;
       if (GetFirstLinePosition(aWM, kid, &kidPosition)) {
         // XXX Not sure if this is the correct value to use for container
         //    width here. It will only be used in vertical-rl layout,
         //    which we don't have full support and testing for yet.
-        const nsSize& containerSize = line->mContainerSize;
+        const auto& containerSize = line.mContainerSize;
         *aResult = kidPosition +
                    kid->GetLogicalNormalPosition(aWM, containerSize).B(aWM);
         return true;
       }
     } else {
       // XXX Is this the right test?  We have some bogus empty lines
       // floating around, but IsEmpty is perhaps too weak.
-      if (line->BSize() != 0 || !line->IsEmpty()) {
-        nscoord bStart = line->BStart();
+      if (0 != line.BSize() || !line.IsEmpty()) {
+        nscoord bStart = line.BStart();
         aResult->mBStart = bStart;
-        aResult->mBaseline = bStart + line->GetLogicalAscent();
-        aResult->mBEnd = bStart + line->BSize();
+        aResult->mBaseline = bStart + line.GetLogicalAscent();
+        aResult->mBEnd = bStart + line.BSize();
         return true;
       }
     }
   }
   return false;
 }
 
 /* static */
@@ -6476,29 +6474,27 @@ bool nsLayoutUtils::GetLastLineBaseline(
 }
 
 static nscoord CalculateBlockContentBEnd(WritingMode aWM,
                                          nsBlockFrame* aFrame) {
   MOZ_ASSERT(aFrame, "null ptr");
 
   nscoord contentBEnd = 0;
 
-  for (nsBlockFrame::LineIterator line = aFrame->LinesBegin(),
-                                  line_end = aFrame->LinesEnd();
-       line != line_end; ++line) {
-    if (line->IsBlock()) {
-      nsIFrame* child = line->mFirstChild;
-      const nsSize& containerSize = line->mContainerSize;
+  for (const auto& line : aFrame->Lines()) {
+    if (line.IsBlock()) {
+      nsIFrame* child = line.mFirstChild;
+      const auto& containerSize = line.mContainerSize;
       nscoord offset =
           child->GetLogicalNormalPosition(aWM, containerSize).B(aWM);
       contentBEnd =
           std::max(contentBEnd,
                    nsLayoutUtils::CalculateContentBEnd(aWM, child) + offset);
     } else {
-      contentBEnd = std::max(contentBEnd, line->BEnd());
+      contentBEnd = std::max(contentBEnd, line.BEnd());
     }
   }
   return contentBEnd;
 }
 
 /* static */
 nscoord nsLayoutUtils::CalculateContentBEnd(WritingMode aWM, nsIFrame* aFrame) {
   MOZ_ASSERT(aFrame, "null ptr");
--- a/layout/generic/nsBlockFrame.cpp
+++ b/layout/generic/nsBlockFrame.cpp
@@ -70,28 +70,24 @@ static const int MIN_LINES_NEEDING_CURSO
 using namespace mozilla;
 using namespace mozilla::css;
 using namespace mozilla::dom;
 using namespace mozilla::layout;
 using ShapeType = nsFloatManager::ShapeType;
 typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags;
 
 static void MarkAllDescendantLinesDirty(nsBlockFrame* aBlock) {
-  nsLineList::iterator line = aBlock->LinesBegin();
-  nsLineList::iterator endLine = aBlock->LinesEnd();
-  while (line != endLine) {
-    if (line->IsBlock()) {
-      nsIFrame* f = line->mFirstChild;
-      nsBlockFrame* bf = do_QueryFrame(f);
+  for (auto& line : aBlock->Lines()) {
+    if (line.IsBlock()) {
+      nsBlockFrame* bf = do_QueryFrame(line.mFirstChild);
       if (bf) {
         MarkAllDescendantLinesDirty(bf);
       }
     }
-    line->MarkDirty();
-    ++line;
+    line.MarkDirty();
   }
 }
 
 static void MarkSameFloatManagerLinesDirty(nsBlockFrame* aBlock) {
   nsBlockFrame* blockWithFloatMgr = aBlock;
   while (!(blockWithFloatMgr->GetStateBits() & NS_BLOCK_FLOAT_MGR)) {
     nsBlockFrame* bf = do_QueryFrame(blockWithFloatMgr->GetParent());
     if (!bf) {
@@ -110,21 +106,20 @@ static void MarkSameFloatManagerLinesDir
 /**
  * Returns true if aFrame is a block that has one or more float children.
  */
 static bool BlockHasAnyFloats(nsIFrame* aFrame) {
   nsBlockFrame* block = do_QueryFrame(aFrame);
   if (!block) return false;
   if (block->GetChildList(nsIFrame::kFloatList).FirstChild()) return true;
 
-  nsLineList::iterator line = block->LinesBegin();
-  nsLineList::iterator endLine = block->LinesEnd();
-  while (line != endLine) {
-    if (line->IsBlock() && BlockHasAnyFloats(line->mFirstChild)) return true;
-    ++line;
+  for (const auto& line : block->Lines()) {
+    if (line.IsBlock() && BlockHasAnyFloats(line.mFirstChild)) {
+      return true;
+    }
   }
   return false;
 }
 
 /**
  * Determines whether the given frame is visible or has
  * visible children that participate in the same line. Frames
  * that are not line participants do not have their
@@ -413,19 +408,18 @@ NS_IMPL_FRAMEARENA_HELPERS(nsBlockFrame)
 
 nsBlockFrame::~nsBlockFrame() = default;
 
 void nsBlockFrame::AddSizeOfExcludingThisForTree(
     nsWindowSizes& aWindowSizes) const {
   nsContainerFrame::AddSizeOfExcludingThisForTree(aWindowSizes);
 
   // Add the size of any nsLineBox::mFrames hashtables we might have:
-  for (ConstLineIterator line = LinesBegin(), line_end = LinesEnd();
-       line != line_end; ++line) {
-    line->AddSizeOfExcludingThis(aWindowSizes);
+  for (const auto& line : Lines()) {
+    line.AddSizeOfExcludingThis(aWindowSizes);
   }
   const FrameLines* overflowLines = GetOverflowLines();
   if (overflowLines) {
     ConstLineIterator line = overflowLines->mLines.begin(),
                       line_end = overflowLines->mLines.end();
     for (; line != line_end; ++line) {
       line->AddSizeOfExcludingThis(aWindowSizes);
     }
@@ -1206,24 +1200,21 @@ static bool ClearLineClampEllipsis(nsBlo
         }
       }
     }
     return false;
   }
 
   aFrame->RemoveStateBits(NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS);
 
-  nsBlockFrame::LineIterator line = aFrame->LinesBegin();
-  nsBlockFrame::LineIterator end = aFrame->LinesEnd();
-  while (line != end) {
-    if (line->HasLineClampEllipsis()) {
-      line->ClearHasLineClampEllipsis();
+  for (auto& line : aFrame->Lines()) {
+    if (line.HasLineClampEllipsis()) {
+      line.ClearHasLineClampEllipsis();
       return true;
     }
-    ++line;
   }
 
   // We didn't find a line with the ellipsis; it must have been deleted already.
   return true;
 }
 
 void nsBlockFrame::ClearLineClampEllipsis() { ::ClearLineClampEllipsis(this); }
 
@@ -1506,19 +1497,18 @@ void nsBlockFrame::Reflow(nsPresContext*
   // logical direction progresses in a negative physical direction, and
   // therefore block-dir coordinate conversion depends on knowing the width
   // of the coordinate space in order to translate between the logical and
   // physical origins.
   if (wm.IsVerticalRL()) {
     nsSize containerSize = aMetrics.PhysicalSize();
     nscoord deltaX = containerSize.width - state.ContainerSize().width;
     if (deltaX != 0) {
-      for (LineIterator line = LinesBegin(), end = LinesEnd(); line != end;
-           line++) {
-        UpdateLineContainerSize(line, containerSize);
+      for (auto& line : Lines()) {
+        UpdateLineContainerSize(&line, containerSize);
       }
       for (nsIFrame* f : mFloats) {
         nsPoint physicalDelta(deltaX, 0);
         f->MovePositionBy(physicalDelta);
       }
       nsFrameList* markerList = GetOutsideMarkerList();
       if (markerList) {
         nsPoint physicalDelta(deltaX, 0);
@@ -1678,32 +1668,25 @@ void nsBlockFrame::Reflow(nsPresContext*
     printf("%s\n", buf);
   }
 #endif
 
   NS_FRAME_SET_TRUNCATION(aStatus, (*reflowInput), aMetrics);
 }
 
 bool nsBlockFrame::CheckForCollapsedBEndMarginFromClearanceLine() {
-  LineIterator begin = LinesBegin();
-  LineIterator line = LinesEnd();
-
-  while (true) {
-    if (begin == line) {
+  for (auto& line : Reversed(Lines())) {
+    if (0 != line.BSize() || !line.CachedIsEmpty()) {
       return false;
     }
-    --line;
-    if (line->BSize() != 0 || !line->CachedIsEmpty()) {
-      return false;
-    }
-    if (line->HasClearance()) {
+    if (line.HasClearance()) {
       return true;
     }
   }
-  // not reached
+  return false;
 }
 
 static nsLineBox* FindLineClampTarget(nsBlockFrame*& aFrame,
                                       uint32_t aLineNumber) {
   MOZ_ASSERT(aLineNumber > 0);
   MOZ_ASSERT(!aFrame->HasAnyStateBits(NS_BLOCK_HAS_LINE_CLAMP_ELLIPSIS),
              "Should have been removed earlier in nsBlockReflow::Reflow");
 
@@ -2069,31 +2052,30 @@ void nsBlockFrame::ComputeOverflowAreas(
                                         const nsStyleDisplay* aDisplay,
                                         nscoord aBEndEdgeOfChildren,
                                         nsOverflowAreas& aOverflowAreas) {
   // Compute the overflow areas of our children
   // XXX_perf: This can be done incrementally.  It is currently one of
   // the things that makes incremental reflow O(N^2).
   nsOverflowAreas areas(aBounds, aBounds);
   if (!ShouldApplyOverflowClipping(this, aDisplay)) {
-    for (LineIterator line = LinesBegin(), line_end = LinesEnd();
-         line != line_end; ++line) {
+    for (const auto& line : Lines()) {
       if (aDisplay->IsContainLayout()) {
         // If we have layout containment, we should only consider our child's
         // visual overflow, leaving the scrollable regions of the parent
         // unaffected.
         // Note: scrollable overflow is a subset of visual overflow,
         // so this has the same affect as unioning the child's visual and
         // scrollable overflow with its parent's visual overflow.
-        nsRect childVisualRect = line->GetVisualOverflowArea();
+        nsRect childVisualRect = line.GetVisualOverflowArea();
         nsOverflowAreas childVisualArea =
             nsOverflowAreas(childVisualRect, nsRect());
         areas.UnionWith(childVisualArea);
       } else {
-        areas.UnionWith(line->GetOverflowAreas());
+        areas.UnionWith(line.GetOverflowAreas());
       }
     }
 
     // Factor an outside ::marker in; normally the ::marker will be factored
     // into the line-box's overflow areas. However, if the line is a block
     // line then it won't; if there are no lines, it won't. So just
     // factor it in anyway (it can't hurt if it was already done).
     // XXXldb Can we just fix GetOverflowArea instead?
@@ -2118,35 +2100,34 @@ void nsBlockFrame::ComputeOverflowAreas(
   aOverflowAreas = areas;
 }
 
 void nsBlockFrame::UnionChildOverflow(nsOverflowAreas& aOverflowAreas) {
   // We need to update the overflow areas of lines manually, as they
   // get cached and re-used otherwise. Lines aren't exposed as normal
   // frame children, so calling UnionChildOverflow alone will end up
   // using the old cached values.
-  for (LineIterator line = LinesBegin(), line_end = LinesEnd();
-       line != line_end; ++line) {
-    nsRect bounds = line->GetPhysicalBounds();
+  for (auto& line : Lines()) {
+    nsRect bounds = line.GetPhysicalBounds();
     nsOverflowAreas lineAreas(bounds, bounds);
 
-    int32_t n = line->GetChildCount();
-    for (nsIFrame* lineFrame = line->mFirstChild; n > 0;
+    int32_t n = line.GetChildCount();
+    for (nsIFrame* lineFrame = line.mFirstChild; n > 0;
          lineFrame = lineFrame->GetNextSibling(), --n) {
       ConsiderChildOverflow(lineAreas, lineFrame);
     }
 
     // Consider the overflow areas of the floats attached to the line as well
-    if (line->HasFloats()) {
-      for (nsFloatCache* fc = line->GetFirstFloat(); fc; fc = fc->Next()) {
+    if (line.HasFloats()) {
+      for (nsFloatCache* fc = line.GetFirstFloat(); fc; fc = fc->Next()) {
         ConsiderChildOverflow(lineAreas, fc->mFloat);
       }
     }
 
-    line->SetOverflowAreas(lineAreas);
+    line.SetOverflowAreas(lineAreas);
     aOverflowAreas.UnionWith(lineAreas);
   }
 
   // Union with child frames, skipping the principal and float lists
   // since we already handled those using the line boxes.
   nsLayoutUtils::UnionChildOverflow(this, aOverflowAreas,
                                     {kPrincipalList, kFloatList});
 }
@@ -2301,19 +2282,18 @@ void nsBlockFrame::PrepareResizeReflow(B
             line->IsImpactedByFloat() ? "impacted " : "",
             line->BreakTypeToString(line->GetBreakTypeBefore()),
             line->BreakTypeToString(line->GetBreakTypeAfter()), line->IEnd());
       }
 #endif
     }
   } else {
     // Mark everything dirty
-    for (LineIterator line = LinesBegin(), line_end = LinesEnd();
-         line != line_end; ++line) {
-      line->MarkDirty();
+    for (auto& line : Lines()) {
+      line.MarkDirty();
     }
   }
 }
 
 //----------------------------------------
 
 /**
  * Propagate reflow "damage" from from earlier lines to the current
@@ -3999,21 +3979,19 @@ void nsBlockFrame::ReflowBlockFrame(Bloc
               // else one of our own overflow lines. In the latter case
               // the line is already marked dirty, so just handle the
               // first case.
               if (!madeContinuation) {
                 nsBlockFrame* nifBlock = do_QueryFrame(nextFrame->GetParent());
                 NS_ASSERTION(
                     nifBlock,
                     "A block's child's next in flow's parent must be a block!");
-                for (LineIterator line = nifBlock->LinesBegin(),
-                                  line_end = nifBlock->LinesEnd();
-                     line != line_end; ++line) {
-                  if (line->Contains(nextFrame)) {
-                    line->MarkDirty();
+                for (auto& line : nifBlock->Lines()) {
+                  if (line.Contains(nextFrame)) {
+                    line.MarkDirty();
                     break;
                   }
                 }
               }
             }
             *aKeepReflowGoing = false;
 
             // The block-end margin for a block is only applied on the last
@@ -4750,20 +4728,20 @@ bool nsBlockFrame::IsLastLine(BlockReflo
     }
     // The next line is empty, try the next one
   }
 
   // XXX Not sure about this part
   // Try our next-in-flows lines to answer the question
   nsBlockFrame* nextInFlow = (nsBlockFrame*)GetNextInFlow();
   while (nullptr != nextInFlow) {
-    for (LineIterator line = nextInFlow->LinesBegin(),
-                      line_end = nextInFlow->LinesEnd();
-         line != line_end; ++line) {
-      if (0 != line->GetChildCount()) return line->IsBlock();
+    for (const auto& line : nextInFlow->Lines()) {
+      if (0 != line.GetChildCount()) {
+        return line.IsBlock();
+      }
     }
     nextInFlow = (nsBlockFrame*)nextInFlow->GetNextInFlow();
   }
 
   // This is the last line - so don't allow justification
   return true;
 }
 
@@ -5788,19 +5766,18 @@ void nsBlockFrame::AppendDirectlyOwnedAn
   if (auto* rubyContentPseudoFrame = GetRubyContentPseudoFrame()) {
     aResult.AppendElement(OwnedAnonBox(rubyContentPseudoFrame));
   }
 }
 
 void nsBlockFrame::RemoveFloatFromFloatCache(nsIFrame* aFloat) {
   // Find which line contains the float, so we can update
   // the float cache.
-  LineIterator line = LinesBegin(), line_end = LinesEnd();
-  for (; line != line_end; ++line) {
-    if (line->IsInline() && line->RemoveFloat(aFloat)) {
+  for (auto& line : Lines()) {
+    if (line.IsInline() && line.RemoveFloat(aFloat)) {
       break;
     }
   }
 }
 
 void nsBlockFrame::RemoveFloat(nsIFrame* aFloat) {
 #ifdef DEBUG
   // Floats live in mFloats, or in the PushedFloat or OverflowOutOfFlows
@@ -6744,20 +6721,19 @@ void nsBlockFrame::RecoverFloats(nsFloat
 
   // Recurse into our overflow container children
   for (nsIFrame* oc = GetChildList(kOverflowContainersList).FirstChild(); oc;
        oc = oc->GetNextSibling()) {
     RecoverFloatsFor(oc, aFloatManager, aWM, aContainerSize);
   }
 
   // Recurse into our normal children
-  for (nsBlockFrame::LineIterator line = LinesBegin(); line != LinesEnd();
-       ++line) {
-    if (line->IsBlock()) {
-      RecoverFloatsFor(line->mFirstChild, aFloatManager, aWM, aContainerSize);
+  for (const auto& line : Lines()) {
+    if (line.IsBlock()) {
+      RecoverFloatsFor(line.mFirstChild, aFloatManager, aWM, aContainerSize);
     }
   }
 }
 
 void nsBlockFrame::RecoverFloatsFor(nsIFrame* aFrame,
                                     nsFloatManager& aFloatManager,
                                     WritingMode aWM,
                                     const nsSize& aContainerSize) {
@@ -7464,26 +7440,25 @@ void nsBlockFrame::CheckFloats(BlockRefl
 #ifdef DEBUG
   // If any line is still dirty, that must mean we're going to reflow this
   // block again soon (e.g. because we bailed out after noticing that
   // clearance was imposed), so don't worry if the floats are out of sync.
   bool anyLineDirty = false;
 
   // Check that the float list is what we would have built
   AutoTArray<nsIFrame*, 8> lineFloats;
-  for (LineIterator line = LinesBegin(), line_end = LinesEnd();
-       line != line_end; ++line) {
-    if (line->HasFloats()) {
-      nsFloatCache* fc = line->GetFirstFloat();
+  for (auto& line : Lines()) {
+    if (line.HasFloats()) {
+      nsFloatCache* fc = line.GetFirstFloat();
       while (fc) {
         lineFloats.AppendElement(fc->mFloat);
         fc = fc->Next();
       }
     }
-    if (line->IsDirty()) {
+    if (line.IsDirty()) {
       anyLineDirty = true;
     }
   }
 
   AutoTArray<nsIFrame*, 8> storedFloats;
   bool equal = true;
   uint32_t i = 0;
   for (nsIFrame* f : mFloats) {
@@ -7786,41 +7761,41 @@ void nsBlockFrame::VerifyLines(bool aFin
     return;
   }
 
   nsLineBox* cursor = GetLineCursor();
 
   // Add up the counts on each line. Also validate that IsFirstLine is
   // set properly.
   int32_t count = 0;
-  LineIterator line, line_end;
-  for (line = LinesBegin(), line_end = LinesEnd(); line != line_end; ++line) {
+  for (const auto& line : Lines()) {
     if (line == cursor) {
       cursor = nullptr;
     }
     if (aFinalCheckOK) {
-      MOZ_ASSERT(line->GetChildCount(), "empty line");
-      if (line->IsBlock()) {
-        NS_ASSERTION(1 == line->GetChildCount(), "bad first line");
-      }
-    }
-    count += line->GetChildCount();
+      MOZ_ASSERT(line.GetChildCount(), "empty line");
+      if (line.IsBlock()) {
+        NS_ASSERTION(1 == line.GetChildCount(), "bad first line");
+      }
+    }
+    count += line.GetChildCount();
   }
 
   // Then count the frames
   int32_t frameCount = 0;
   nsIFrame* frame = mLines.front()->mFirstChild;
   while (frame) {
     frameCount++;
     frame = frame->GetNextSibling();
   }
   NS_ASSERTION(count == frameCount, "bad line list");
 
   // Next: test that each line has right number of frames on it
-  for (line = LinesBegin(), line_end = LinesEnd(); line != line_end;) {
+  for (LineIterator line = LinesBegin(), line_end = LinesEnd();
+       line != line_end;) {
     count = line->GetChildCount();
     frame = line->mFirstChild;
     while (--count >= 0) {
       frame = frame->GetNextSibling();
     }
     ++line;
     if ((line != line_end) && (0 != line->GetChildCount())) {
       NS_ASSERTION(frame == line->mFirstChild, "bad line list");
--- a/layout/generic/nsBlockFrame.h
+++ b/layout/generic/nsBlockFrame.h
@@ -97,16 +97,20 @@ class nsBlockFrame : public nsContainerF
   ReverseLineIterator LinesREnd() { return mLines.rend(); }
   ConstReverseLineIterator LinesRBegin() const { return mLines.rbegin(); }
   ConstReverseLineIterator LinesREnd() const { return mLines.rend(); }
   LineIterator LinesBeginFrom(nsLineBox* aList) { return mLines.begin(aList); }
   ReverseLineIterator LinesRBeginFrom(nsLineBox* aList) {
     return mLines.rbegin(aList);
   }
 
+  // Methods declared to be used in 'range-based-for-loop'
+  nsLineList& Lines() { return mLines; }
+  const nsLineList& Lines() const { return mLines; }
+
   friend nsBlockFrame* NS_NewBlockFrame(mozilla::PresShell* aPresShell,
                                         ComputedStyle* aStyle);
 
   // nsQueryFrame
   NS_DECL_QUERYFRAME
 
   // nsIFrame
   void Init(nsIContent* aContent, nsContainerFrame* aParent,
--- a/layout/generic/nsLineBox.h
+++ b/layout/generic/nsLineBox.h
@@ -405,27 +405,29 @@ class nsLineBox final : public nsLineLin
   // used for painting-related things, but should never be used for
   // layout (except for handling of 'overflow').
   void SetOverflowAreas(const nsOverflowAreas& aOverflowAreas);
   mozilla::LogicalRect GetOverflowArea(nsOverflowType aType,
                                        mozilla::WritingMode aWM,
                                        const nsSize& aContainerSize) {
     return mozilla::LogicalRect(aWM, GetOverflowArea(aType), aContainerSize);
   }
-  nsRect GetOverflowArea(nsOverflowType aType) {
+  nsRect GetOverflowArea(nsOverflowType aType) const {
     return mData ? mData->mOverflowAreas.Overflow(aType) : GetPhysicalBounds();
   }
-  nsOverflowAreas GetOverflowAreas() {
+  nsOverflowAreas GetOverflowAreas() const {
     if (mData) {
       return mData->mOverflowAreas;
     }
     nsRect bounds = GetPhysicalBounds();
     return nsOverflowAreas(bounds, bounds);
   }
-  nsRect GetVisualOverflowArea() { return GetOverflowArea(eVisualOverflow); }
+  nsRect GetVisualOverflowArea() const {
+    return GetOverflowArea(eVisualOverflow);
+  }
   nsRect GetScrollableOverflowArea() {
     return GetOverflowArea(eScrollableOverflow);
   }
 
   void SlideBy(nscoord aDBCoord, const nsSize& aContainerSize) {
     NS_ASSERTION(
         aContainerSize == mContainerSize || mContainerSize == nsSize(-1, -1),
         "container size doesn't match");
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -4908,23 +4908,21 @@ static void PaintSelectionBackground(
 // If not set, calculate this value for all child frames of aBlockFrame
 static nscoord LazyGetLineBaselineOffset(nsIFrame* aChildFrame,
                                          nsBlockFrame* aBlockFrame) {
   bool offsetFound;
   nscoord offset =
       aChildFrame->GetProperty(nsIFrame::LineBaselineOffset(), &offsetFound);
 
   if (!offsetFound) {
-    for (nsBlockFrame::LineIterator line = aBlockFrame->LinesBegin(),
-                                    line_end = aBlockFrame->LinesEnd();
-         line != line_end; line++) {
-      if (line->IsInline()) {
-        int32_t n = line->GetChildCount();
-        nscoord lineBaseline = line->BStart() + line->GetLogicalAscent();
-        for (nsIFrame* lineFrame = line->mFirstChild; n > 0;
+    for (const auto& line : aBlockFrame->Lines()) {
+      if (line.IsInline()) {
+        int32_t n = line.GetChildCount();
+        nscoord lineBaseline = line.BStart() + line.GetLogicalAscent();
+        for (auto* lineFrame = line.mFirstChild; n > 0;
              lineFrame = lineFrame->GetNextSibling(), --n) {
           offset = lineBaseline - lineFrame->GetNormalPosition().y;
           lineFrame->SetProperty(nsIFrame::LineBaselineOffset(), offset);
         }
       }
     }
     return aChildFrame->GetProperty(nsIFrame::LineBaselineOffset(),
                                     &offsetFound);