Bug 1624514 Part 2 - Generalize nsIFrame::ContentBSize() to be ContentSize(). r=AlaskanEmily
authorTing-Yu Lin <tlin@mozilla.com>
Wed, 25 Mar 2020 18:12:25 +0000
changeset 520420 d2cd2c812a9559058ed5c66e966856c1dd1562d7
parent 520419 d4477b1bcc43337ff7d8f2f3348046f6acda89a5
child 520421 59b5013d907ea710b07fb409a24d34fbac7eb060
push id37249
push userdvarga@mozilla.com
push dateWed, 25 Mar 2020 21:39:06 +0000
treeherdermozilla-central@b3c3f7d0f044 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAlaskanEmily
bugs1624514
milestone76.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 1624514 Part 2 - Generalize nsIFrame::ContentBSize() to be ContentSize(). r=AlaskanEmily To get the logical content size of a frame, some callers use GetContentRectRelativeToSelf().Size() and then convert it to LogicalRect. We really should generalize ContentBSize(), and provide ContentSize() for such purpose. Differential Revision: https://phabricator.services.mozilla.com/D68065
layout/base/RestyleManager.cpp
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsGridContainerFrame.cpp
layout/generic/nsIFrame.h
layout/generic/nsSplittableFrame.cpp
--- a/layout/base/RestyleManager.cpp
+++ b/layout/base/RestyleManager.cpp
@@ -740,17 +740,17 @@ static bool RecomputePosition(nsIFrame* 
     } else {
       MOZ_ASSERT(StylePositionProperty::Relative == display->mPosition,
                  "Unexpected type of positioning");
       for (nsIFrame* cont = aFrame; cont;
            cont = nsLayoutUtils::GetNextContinuationOrIBSplitSibling(cont)) {
         nsIFrame* cb = cont->GetContainingBlock();
         nsMargin newOffsets;
         WritingMode wm = cb->GetWritingMode();
-        const LogicalSize size(wm, cb->GetContentRectRelativeToSelf().Size());
+        const LogicalSize size = cb->ContentSize();
 
         ReflowInput::ComputeRelativeOffsets(wm, cont, size, newOffsets);
         NS_ASSERTION(newOffsets.left == -newOffsets.right &&
                          newOffsets.top == -newOffsets.bottom,
                      "ComputeRelativeOffsets should return valid results");
 
         // ReflowInput::ApplyRelativePositioning would work here, but
         // since we've already checked mPosition and aren't changing the frame's
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -2193,18 +2193,17 @@ bool FlexItem::NeedsFinalReflow() const 
   const LogicalSize finalSize = mIsInlineAxisMainAxis
                                     ? LogicalSize(mWM, mMainSize, mCrossSize)
                                     : LogicalSize(mWM, mCrossSize, mMainSize);
 
   if (HadMeasuringReflow()) {
     // We've already reflowed this flex item once, to measure it. In that
     // reflow, did its frame happen to end up with the correct final size
     // that the flex container would like it to have?
-    if (finalSize !=
-        LogicalSize(mWM, mFrame->GetContentRectRelativeToSelf().Size())) {
+    if (finalSize != mFrame->ContentSize(mWM)) {
       // The measuring reflow left the item with a different size than its
       // final flexed size. So, we need to reflow to give it the correct size.
       FLEX_LOG(
           "[perf] Flex item needed both a measuring reflow and a final "
           "reflow due to measured size disagreeing with final size");
       return true;
     }
 
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -4965,17 +4965,17 @@ static nscoord ContentContribution(
       size += childRI.ComputedLogicalMargin().BStartEnd(childWM);
     } else {
       size = ::MeasuringReflow(child, aState.mReflowInput, aRC, availableSize,
                                cbSize, iMinSizeClamp, bMinSizeClamp);
       size += child->GetLogicalUsedMargin(childWM).BStartEnd(childWM);
     }
     nscoord overflow = size - aMinSizeClamp;
     if (MOZ_UNLIKELY(overflow > 0)) {
-      nscoord contentSize = child->ContentBSize(childWM);
+      nscoord contentSize = child->ContentSize(childWM).BSize(childWM);
       nscoord newContentSize = std::max(nscoord(0), contentSize - overflow);
       // XXXmats deal with percentages better, see bug 1300369 comment 27.
       size -= contentSize - newContentSize;
     }
   }
   MOZ_ASSERT(aGridItem.mBaselineOffset[aAxis] >= 0,
              "baseline offset should be non-negative at this point");
   MOZ_ASSERT((aGridItem.mState[aAxis] & ItemState::eIsBaselineAligned) ||
--- a/layout/generic/nsIFrame.h
+++ b/layout/generic/nsIFrame.h
@@ -1009,21 +1009,23 @@ class nsIFrame : public nsQueryFrame {
   nscoord ISize() const { return ISize(GetWritingMode()); }
   nscoord ISize(mozilla::WritingMode aWritingMode) const {
     return GetLogicalSize(aWritingMode).ISize(aWritingMode);
   }
   nscoord BSize() const { return BSize(GetWritingMode()); }
   nscoord BSize(mozilla::WritingMode aWritingMode) const {
     return GetLogicalSize(aWritingMode).BSize(aWritingMode);
   }
-  nscoord ContentBSize() const { return ContentBSize(GetWritingMode()); }
-  nscoord ContentBSize(mozilla::WritingMode aWritingMode) const {
+  mozilla::LogicalSize ContentSize() const {
+    return ContentSize(GetWritingMode());
+  }
+  mozilla::LogicalSize ContentSize(mozilla::WritingMode aWritingMode) const {
     auto bp = GetLogicalUsedBorderAndPadding(aWritingMode);
     bp.ApplySkipSides(GetLogicalSkipSides());
-    return std::max(0, BSize(aWritingMode) - bp.BStartEnd(aWritingMode));
+    return GetLogicalSize(aWritingMode) - bp.Size(aWritingMode);
   }
 
   /**
    * When we change the size of the frame's border-box rect, we may need to
    * reset the overflow rect if it was previously stored as deltas.
    * (If it is currently a "large" overflow and could be re-packed as deltas,
    * we don't bother as the cost of the allocation has already been paid.)
    * @param aRebuildDisplayItems If true, then adds this frame to the
--- a/layout/generic/nsSplittableFrame.cpp
+++ b/layout/generic/nsSplittableFrame.cpp
@@ -184,17 +184,17 @@ void nsSplittableFrame::RemoveFromFlow(n
   aFrame->SetNextInFlow(nullptr);
 }
 
 nscoord nsSplittableFrame::ConsumedBSize(WritingMode aWM) const {
   nscoord bSize = 0;
 
   for (nsIFrame* prev = GetPrevContinuation(); prev;
        prev = prev->GetPrevContinuation()) {
-    bSize += prev->ContentBSize(aWM);
+    bSize += prev->ContentSize(aWM).BSize(aWM);
   }
   return bSize;
 }
 
 nscoord nsSplittableFrame::GetEffectiveComputedBSize(
     const ReflowInput& aReflowInput, nscoord aConsumedBSize) const {
   nscoord bSize = aReflowInput.ComputedBSize();
   if (bSize == NS_UNCONSTRAINEDSIZE) {