Bug 1177614 - Provide a utility method on nsHTMLReflowState to return the computed size including border-padding, for use as a container for logical coordinate conversions, or zero if unconstrained. r=dholbert
authorJonathan Kew <jkew@mozilla.com>
Thu, 16 Jul 2015 10:07:46 +0100
changeset 253151 b0f47defe8106f673aea5fdd4f91e64aaa5e6ff5
parent 253150 18e90871e991d576051a72d3b55166ead19a23b2
child 253152 28673cc5e68b48d6a397b027a6ef5321703dea4a
push id29061
push userryanvm@gmail.com
push dateThu, 16 Jul 2015 18:53:45 +0000
treeherdermozilla-central@a0f4a688433d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1177614
milestone42.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 1177614 - Provide a utility method on nsHTMLReflowState to return the computed size including border-padding, for use as a container for logical coordinate conversions, or zero if unconstrained. r=dholbert
layout/forms/nsComboboxControlFrame.cpp
layout/generic/nsHTMLReflowState.cpp
layout/generic/nsHTMLReflowState.h
layout/tables/nsTableCellFrame.cpp
layout/tables/nsTableFrame.cpp
layout/tables/nsTableRowFrame.cpp
layout/tables/nsTableRowGroupFrame.cpp
--- a/layout/forms/nsComboboxControlFrame.cpp
+++ b/layout/forms/nsComboboxControlFrame.cpp
@@ -861,18 +861,18 @@ nsComboboxControlFrame::Reflow(nsPresCon
   }
 
   mDisplayISize = aReflowState.ComputedISize() - buttonISize;
 
   nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
 
   // The button should occupy the same space as a scrollbar
   WritingMode wm = aReflowState.GetWritingMode();
-  nscoord containerWidth = aReflowState.ComputedWidth() +
-    aReflowState.ComputedPhysicalBorderPadding().LeftRight();
+  nscoord containerWidth =
+    aReflowState.ComputedSizeAsContainerIfConstrained().width;
   LogicalRect buttonRect = mButtonFrame->GetLogicalRect(containerWidth);
 
   buttonRect.IStart(wm) =
     aReflowState.ComputedLogicalBorderPadding().IStartEnd(wm) +
     mDisplayISize -
     (aReflowState.ComputedLogicalBorderPadding().IEnd(wm) -
      aReflowState.ComputedLogicalPadding().IEnd(wm));
   buttonRect.ISize(wm) = buttonISize;
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -1261,18 +1261,17 @@ nsHTMLReflowState::CalculateHypothetical
   }
 
   // Get the placeholder x-offset and y-offset in the coordinate
   // space of its containing block
   // XXXbz the placeholder is not fully reflowed yet if our containing block is
   // relatively positioned...
   WritingMode cbwm = cbrs->GetWritingMode();
   nscoord containerWidth = containingBlock->GetStateBits() & NS_FRAME_IN_REFLOW
-    ? cbrs->ComputedWidth() +
-      cbrs->ComputedLogicalBorderPadding().LeftRight(cbwm)
+    ? cbrs->ComputedSizeAsContainerIfConstrained().width
     : containingBlock->GetSize().width;
   LogicalPoint placeholderOffset(wm, aPlaceholderFrame->GetOffsetTo(containingBlock),
                                  containerWidth);
 
   // XXX hack to correct for lack of LogicalPoint bidi support in vertical mode
   if (wm.IsVertical() && !wm.IsBidiLTR()) {
     placeholderOffset.I(wm) = cbrs->ComputedHeight() +
       cbrs->ComputedLogicalBorderPadding().TopBottom(cbwm) -
--- a/layout/generic/nsHTMLReflowState.h
+++ b/layout/generic/nsHTMLReflowState.h
@@ -442,16 +442,27 @@ struct nsHTMLReflowState : public nsCSSO
   nsMargin& ComputedPhysicalOffsets() { return mComputedOffsets; }
 
   const LogicalMargin ComputedLogicalOffsets() const
     { return LogicalMargin(mWritingMode, mComputedOffsets); }
 
   void SetComputedLogicalOffsets(const LogicalMargin& aOffsets)
     { mComputedOffsets = aOffsets.GetPhysicalMargin(mWritingMode); }
 
+  // Return the state's computed size including border-padding, with
+  // unconstrained dimensions replaced by zero.
+  nsSize ComputedSizeAsContainerIfConstrained() const {
+    const nscoord wd = ComputedWidth();
+    const nscoord ht = ComputedHeight();
+    return nsSize(wd == NS_UNCONSTRAINEDSIZE
+                  ? 0 : wd + ComputedPhysicalBorderPadding().LeftRight(),
+                  ht == NS_UNCONSTRAINEDSIZE
+                  ? 0 : ht + ComputedPhysicalBorderPadding().TopBottom());
+  }
+
 private:
   // the available width in which to reflow the frame. The space
   // represents the amount of room for the frame's margin, border,
   // padding, and content area. The frame size you choose should fit
   // within the available width.
   nscoord              mAvailableWidth;
 
   // A value of NS_UNCONSTRAINEDSIZE for the available height means
--- a/layout/tables/nsTableCellFrame.cpp
+++ b/layout/tables/nsTableCellFrame.cpp
@@ -939,24 +939,19 @@ nsTableCellFrame::Reflow(nsPresContext* 
   if (aReflowState.mFlags.mSpecialBSizeReflow ||
       FirstInFlow()->HasAnyStateBits(NS_TABLE_CELL_HAD_SPECIAL_REFLOW)) {
     // We need to force the kid to have mBResize set if we've had a
     // special reflow in the past, since the non-special reflow needs to
     // resize back to what it was without the special bsize reflow.
     kidReflowState.SetBResize(true);
   }
 
-  nscoord containerWidth;
-  if (aReflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE) {
-    containerWidth = 0; // avoid passing unconstrained container width to
-                        // ReflowChild; but position will not be valid
-  } else {
-    containerWidth = aReflowState.ComputedWidth() +
-      aReflowState.ComputedPhysicalBorderPadding().LeftRight();
-  }
+  nscoord containerWidth =
+    aReflowState.ComputedSizeAsContainerIfConstrained().width;
+
   LogicalPoint kidOrigin(wm, borderPadding.IStart(wm),
                          borderPadding.BStart(wm));
   nsRect origRect = firstKid->GetRect();
   nsRect origVisualOverflow = firstKid->GetVisualOverflowRect();
   bool firstReflow = firstKid->HasAnyStateBits(NS_FRAME_FIRST_REFLOW);
 
   ReflowChild(firstKid, aPresContext, kidSize, kidReflowState,
               wm, kidOrigin, containerWidth, 0, aStatus);
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -2968,29 +2968,21 @@ nsTableFrame::ReflowChildren(nsTableRefl
                              nsIFrame*&          aLastChildReflowed,
                              nsOverflowAreas&    aOverflowAreas)
 {
   aStatus = NS_FRAME_COMPLETE;
   aLastChildReflowed = nullptr;
 
   nsIFrame* prevKidFrame = nullptr;
   WritingMode wm = aReflowState.reflowState.GetWritingMode();
-  nscoord containerWidth = aReflowState.reflowState.ComputedWidth();
-  if (containerWidth == NS_UNCONSTRAINEDSIZE) {
-    NS_WARN_IF_FALSE(wm.IsVertical(),
-                     "shouldn't have unconstrained width in horizontal mode");
-    // We won't know the containerWidth until we've reflowed our contents,
-    // so use zero for now; in vertical-rl mode, this will mean the children
-    // are misplaced in the block-direction, and will need to be moved
-    // rightwards by the true containerWidth once we know it.
-    containerWidth = 0;
-  } else {
-    containerWidth +=
-      aReflowState.reflowState.ComputedPhysicalBorderPadding().LeftRight();
-  }
+  NS_WARN_IF_FALSE(wm.IsVertical() || NS_UNCONSTRAINEDSIZE !=
+                                      aReflowState.reflowState.ComputedWidth(),
+                   "shouldn't have unconstrained width in horizontal mode");
+  nscoord containerWidth =
+    aReflowState.reflowState.ComputedSizeAsContainerIfConstrained().width;
 
   nsPresContext* presContext = PresContext();
   // XXXldb Should we be checking constrained height instead?
   // tables are not able to pull back children from its next inflow, so even
   // under paginated contexts tables are should not paginate if they are inside
   // column set
   bool isPaginated = presContext->IsPaginated() &&
                        NS_UNCONSTRAINEDSIZE != aReflowState.availSize.BSize(wm) &&
@@ -3383,22 +3375,18 @@ void ResizeCells(nsTableFrame& aTableFra
 
 void
 nsTableFrame::DistributeBSizeToRows(const nsHTMLReflowState& aReflowState,
                                     nscoord                  aAmount)
 {
   WritingMode wm = aReflowState.GetWritingMode();
   LogicalMargin borderPadding = GetChildAreaOffset(wm, &aReflowState);
 
-  nscoord containerWidth = aReflowState.ComputedWidth();
-  if (containerWidth == NS_UNCONSTRAINEDSIZE) {
-    containerWidth = 0;
-  } else {
-    containerWidth += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
-  }
+  nscoord containerWidth =
+    aReflowState.ComputedSizeAsContainerIfConstrained().width;
 
   RowGroupArray rowGroups;
   OrderRowGroups(rowGroups);
 
   nscoord amountUsed = 0;
   // distribute space to each pct bsize row whose row group doesn't have a computed
   // bsize, and base the pct on the table bsize. If the row group had a computed
   // bsize, then this was already done in nsTableRowGroupFrame::CalculateRowBSizes
--- a/layout/tables/nsTableRowFrame.cpp
+++ b/layout/tables/nsTableRowFrame.cpp
@@ -812,22 +812,18 @@ nsTableRowFrame::ReflowChildren(nsPresCo
   int32_t prevColIndex = -1;
   nscoord iCoord = 0; // running total of children inline-coord offset
 
   // This computes the max of all cell bsizes
   nscoord cellMaxBSize = 0;
 
   // Reflow each of our existing cell frames
   WritingMode wm = aReflowState.GetWritingMode();
-  nscoord containerWidth = aReflowState.ComputedWidth();
-  if (containerWidth == NS_UNCONSTRAINEDSIZE) {
-    containerWidth = 0; // cell positions will not yet be correct
-  } else {
-    containerWidth += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
-  }
+  nscoord containerWidth =
+    aReflowState.ComputedSizeAsContainerIfConstrained().width;
 
   for (nsIFrame* kidFrame : mFrames) {
     nsTableCellFrame *cellFrame = do_QueryFrame(kidFrame);
     if (!cellFrame) {
       // XXXldb nsCSSFrameConstructor needs to enforce this!
       NS_NOTREACHED("yikes, a non-row child");
 
       // it's an unknown frame type, give it a generic reflow and ignore the results
--- a/layout/tables/nsTableRowGroupFrame.cpp
+++ b/layout/tables/nsTableRowGroupFrame.cpp
@@ -341,24 +341,18 @@ nsTableRowGroupFrame::ReflowChildren(nsP
   bool haveRow = false;
   bool reflowAllKids = aReflowState.reflowState.ShouldReflowAllKids() ||
                          tableFrame->IsGeometryDirty();
 
   // in vertical-rl mode, we always need the row bsizes in order to
   // get the necessary containerWidth for placing our kids
   bool needToCalcRowBSizes = reflowAllKids || wm.IsVerticalRL();
 
-  nscoord containerWidth = aReflowState.reflowState.ComputedWidth();
-  if (containerWidth == NS_UNCONSTRAINEDSIZE) {
-    containerWidth = 0; // we can't position frames correctly in RTL yet,
-                        // so they will need to be adjusted later
-  } else {
-    containerWidth +=
-      aReflowState.reflowState.ComputedPhysicalBorderPadding().LeftRight();
-  }
+  nscoord containerWidth =
+    aReflowState.reflowState.ComputedSizeAsContainerIfConstrained().width;
 
   nsIFrame *prevKidFrame = nullptr;
   for (nsIFrame* kidFrame = mFrames.FirstChild(); kidFrame;
        prevKidFrame = kidFrame, kidFrame = kidFrame->GetNextSibling()) {
     nsTableRowFrame *rowFrame = do_QueryFrame(kidFrame);
     if (!rowFrame) {
       // XXXldb nsCSSFrameConstructor needs to enforce this!
       NS_NOTREACHED("yikes, a non-row child");