Bug 958714 part 2: Simplify percent-margin/padding resolution code to pass around a single length as the percent basis. r=mats a=IanN DONTBUILD CLOSED TREE SEAMONKEY_2_49_ESR_RELBRANCH
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 30 Jan 2018 22:24:55 -0500
branchSEAMONKEY_2_49_ESR_RELBRANCH
changeset 357575 c90c92c68b2120d7c8382d6d5d60cfc0892e7107
parent 357574 831b454b9038a9fc8b1cdb235cdde640e398f774
child 357576 3a4afe7ecac570decfb1d388eee2682d5d15dbc8
push id7836
push userfrgrahl@gmx.net
push dateMon, 15 Jul 2019 16:17:02 +0000
treeherdermozilla-esr52@3a4afe7ecac5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats, IanN
bugs958714
milestone52.9.1
Bug 958714 part 2: Simplify percent-margin/padding resolution code to pass around a single length as the percent basis. r=mats a=IanN DONTBUILD CLOSED TREE SeaMonkey ESR52 release branch only. MozReview-Commit-ID: J1EPYMQ5lP4
layout/generic/ReflowInput.cpp
layout/generic/ReflowInput.h
layout/generic/nsFrame.cpp
layout/generic/nsFrame.h
--- a/layout/generic/ReflowInput.cpp
+++ b/layout/generic/ReflowInput.cpp
@@ -165,20 +165,19 @@ SizeComputationInput::SizeComputationInp
   , mWritingMode(aFrame->GetWritingMode())
 {
   MOZ_ASSERT(!aFrame->IsFlexOrGridItem(),
              "We're about to resolve percent margin & padding "
              "values against CB inline size, which is incorrect for "
              "flex/grid items. "
              "Additionally for grid items, this path doesn't handle baseline "
              "padding contribution - see SizeComputationInput::InitOffsets");
-  LogicalSize cbSize(aContainingBlockWritingMode, aContainingBlockISize,
-                     aContainingBlockISize);
   ReflowInputFlags flags;
-  InitOffsets(aContainingBlockWritingMode, cbSize, mFrame->GetType(), flags);
+  InitOffsets(aContainingBlockWritingMode, aContainingBlockISize,
+              mFrame->GetType(), flags);
 }
 
 // Initialize a reflow state for a child frame's reflow. Some state
 // is copied from the parent reflow state; the remaining state is
 // computed.
 ReflowInput::ReflowInput(
                      nsPresContext*           aPresContext,
                      const ReflowInput& aParentReflowInput,
@@ -2119,34 +2118,16 @@ IsSideCaption(nsIFrame* aFrame, const ns
   if (aStyleDisplay->mDisplay != StyleDisplay::TableCaption) {
     return false;
   }
   uint8_t captionSide = aFrame->StyleTableBorder()->mCaptionSide;
   return captionSide == NS_STYLE_CAPTION_SIDE_LEFT ||
          captionSide == NS_STYLE_CAPTION_SIDE_RIGHT;
 }
 
-// Flex/grid items resolve block-axis percentage margin & padding against the
-// containing block block-size (also for abs/fixed-pos child frames).
-// For everything else: the CSS21 spec requires that margin and padding
-// percentage values are calculated with respect to the inline-size of the
-// containing block, even for margin & padding in the block axis.
-static LogicalSize
-OffsetPercentBasis(const nsIFrame*    aFrame,
-                   WritingMode        aWM,
-                   const LogicalSize& aContainingBlockSize)
-{
-  // XXX The next patch in this series will get rid of this function and have
-  // the upstream/downstream code just work with the one nscoord value that
-  // we'll be dealing with now (which is aContainingBlockSize.ISize(aWM)).
-  LogicalSize offsetPercentBasis = aContainingBlockSize;
-  offsetPercentBasis.BSize(aWM) = offsetPercentBasis.ISize(aWM);
-  return offsetPercentBasis;
-}
-
 // XXX refactor this code to have methods for each set of properties
 // we are computing: width,height,line-height; margin; offsets
 
 void
 ReflowInput::InitConstraints(nsPresContext*     aPresContext,
                                    const LogicalSize& aContainingBlockSize,
                                    const nsMargin*    aBorder,
                                    const nsMargin*    aPadding,
@@ -2157,17 +2138,17 @@ ReflowInput::InitConstraints(nsPresConte
                            aContainingBlockSize.ISize(wm),
                            aContainingBlockSize.BSize(wm),
                            aBorder, aPadding);
 
   // If this is a reflow root, then set the computed width and
   // height equal to the available space
   if (nullptr == mParentReflowInput || mFlags.mDummyParentReflowInput) {
     // XXXldb This doesn't mean what it used to!
-    InitOffsets(wm, OffsetPercentBasis(mFrame, wm, aContainingBlockSize),
+    InitOffsets(wm, aContainingBlockSize.ISize(wm),
                 aFrameType, mFlags, aBorder, aPadding);
     // Override mComputedMargin since reflow roots start from the
     // frame's boundary, which is inside the margin.
     ComputedPhysicalMargin().SizeTo(0, 0, 0, 0);
     ComputedPhysicalOffsets().SizeTo(0, 0, 0, 0);
 
     ComputedISize() =
       AvailableISize() - ComputedLogicalBorderPadding().IStartEnd(wm);
@@ -2214,18 +2195,17 @@ ReflowInput::InitConstraints(nsPresConte
     }
 
     // XXX Might need to also pass the CB height (not width) for page boxes,
     // too, if we implement them.
 
     // For calculating positioning offsets, margins, borders and
     // padding, we use the writing mode of the containing block
     WritingMode cbwm = cbrs->GetWritingMode();
-    InitOffsets(cbwm, OffsetPercentBasis(mFrame, cbwm,
-                                         cbSize.ConvertTo(cbwm, wm)),
+    InitOffsets(cbwm, cbSize.ConvertTo(cbwm, wm).ISize(cbwm),
                 aFrameType, mFlags, aBorder, aPadding);
 
     // For calculating the size of this box, we use its own writing mode
     const nsStyleCoord &blockSize = mStylePosition->BSize(wm);
     nsStyleUnit blockSizeUnit = blockSize.GetUnit();
 
     // Check for a percentage based block size and a containing block
     // block size that depends on the content block size
@@ -2485,17 +2465,17 @@ UpdateProp(FrameProperties& aProps,
     }
   } else {
     aProps.Delete(aProperty);
   }
 }
 
 void
 SizeComputationInput::InitOffsets(WritingMode aWM,
-                              const LogicalSize& aPercentBasis,
+                                  nscoord aPercentBasis,
                               nsIAtom* aFrameType,
                               ReflowInputFlags aFlags,
                               const nsMargin* aBorder,
                               const nsMargin* aPadding)
 {
   DISPLAY_INIT_OFFSETS(mFrame, this, aPercentBasis, aBorder, aPadding);
 
   // Since we are in reflow, we don't need to store these properties anymore
@@ -2856,44 +2836,44 @@ ReflowInput::CalcLineHeight(nsIContent* 
     }
   }
 
   return lineHeight;
 }
 
 bool
 SizeComputationInput::ComputeMargin(WritingMode aWM,
-                                const LogicalSize& aPercentBasis)
+                                    nscoord aPercentBasis)
 {
   // SVG text frames have no margin.
   if (mFrame->IsSVGText()) {
     return false;
   }
 
   // If style style can provide us the margin directly, then use it.
   const nsStyleMargin *styleMargin = mFrame->StyleMargin();
 
   bool isCBDependent = !styleMargin->GetMargin(ComputedPhysicalMargin());
   if (isCBDependent) {
     // We have to compute the value. Note that this calculation is
     // performed according to the writing mode of the containing block
     // (http://dev.w3.org/csswg/css-writing-modes-3/#orthogonal-flows)
     LogicalMargin m(aWM);
     m.IStart(aWM) = nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               styleMargin->mMargin.GetIStart(aWM));
     m.IEnd(aWM) = nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               styleMargin->mMargin.GetIEnd(aWM));
 
     m.BStart(aWM) = nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               styleMargin->mMargin.GetBStart(aWM));
     m.BEnd(aWM) = nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               styleMargin->mMargin.GetBEnd(aWM));
 
     SetComputedLogicalMargin(aWM, m);
   }
 
   // ... but font-size-inflation-based margin adjustment uses the
   // frame's writing mode
   nscoord marginAdjustment = FontSizeInflationListMarginAdjustment(mFrame);
@@ -2904,17 +2884,17 @@ SizeComputationInput::ComputeMargin(Writ
     SetComputedLogicalMargin(m);
   }
 
   return isCBDependent;
 }
 
 bool
 SizeComputationInput::ComputePadding(WritingMode aWM,
-                                 const LogicalSize& aPercentBasis,
+                                     nscoord aPercentBasis,
                                  nsIAtom* aFrameType)
 {
   // If style can provide us the padding directly, then use it.
   const nsStylePadding *stylePadding = mFrame->StylePadding();
   bool isCBDependent = !stylePadding->GetPadding(ComputedPhysicalPadding());
   // a table row/col group, row/col doesn't have padding
   // XXXldb Neither do border-collapse tables.
   if (nsGkAtoms::tableRowGroupFrame == aFrameType ||
@@ -2925,27 +2905,27 @@ SizeComputationInput::ComputePadding(Wri
   }
   else if (isCBDependent) {
     // We have to compute the value. This calculation is performed
     // according to the writing mode of the containing block
     // (http://dev.w3.org/csswg/css-writing-modes-3/#orthogonal-flows)
     // clamp negative calc() results to 0
     LogicalMargin p(aWM);
     p.IStart(aWM) = std::max(0, nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               stylePadding->mPadding.GetIStart(aWM)));
     p.IEnd(aWM) = std::max(0, nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.ISize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               stylePadding->mPadding.GetIEnd(aWM)));
 
     p.BStart(aWM) = std::max(0, nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               stylePadding->mPadding.GetBStart(aWM)));
     p.BEnd(aWM) = std::max(0, nsLayoutUtils::
-      ComputeCBDependentValue(aPercentBasis.BSize(aWM),
+      ComputeCBDependentValue(aPercentBasis,
                               stylePadding->mPadding.GetBEnd(aWM)));
 
     SetComputedLogicalPadding(aWM, p);
   }
   return isCBDependent;
 }
 
 void
--- a/layout/generic/ReflowInput.h
+++ b/layout/generic/ReflowInput.h
@@ -239,70 +239,56 @@ public:
   };
 
 #ifdef DEBUG
   // Reflow trace methods.  Defined in nsFrame.cpp so they have access
   // to the display-reflow infrastructure.
   static void* DisplayInitOffsetsEnter(
                                      nsIFrame* aFrame,
                                      SizeComputationInput* aState,
-                                     const mozilla::LogicalSize& aPercentBasis,
+                                     nscoord aPercentBasis,
                                      const nsMargin* aBorder,
                                      const nsMargin* aPadding);
   static void DisplayInitOffsetsExit(nsIFrame* aFrame,
                                      SizeComputationInput* aState,
                                      void* aValue);
 #endif
 
 private:
   /**
    * Computes margin values from the specified margin style information, and
    * fills in the mComputedMargin member.
    *
    * @param aWM Writing mode of the containing block
    * @param aPercentBasis
-   *    Logical size in the writing mode of the containing block to use
-   *    for resolving percentage margin values in the inline and block
-   *    axes.
-   *    The inline size is usually the containing block inline-size
-   *    (width if writing mode is horizontal, and height if vertical).
-   *    The block size is usually the containing block inline-size, per
-   *    CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec
-   *    7.2), but may be the containing block block-size, e.g. in CSS3
-   *    Flexbox and Grid.
+   *    Inline size of the containing block (in its own writing mode), to use
+   *    for resolving percentage margin values in the inline and block axes.
    * @return true if the margin is dependent on the containing block size.
    */
   bool ComputeMargin(mozilla::WritingMode aWM,
-                     const mozilla::LogicalSize& aPercentBasis);
+                     nscoord aPercentBasis);
   
   /**
    * Computes padding values from the specified padding style information, and
    * fills in the mComputedPadding member.
    *
    * @param aWM Writing mode of the containing block
    * @param aPercentBasis
-   *    Logical size in the writing mode of the containing block to use
-   *    for resolving percentage padding values in the inline and block
-   *    axes.
-   *    The inline size is usually the containing block inline-size
-   *    (width if writing mode is horizontal, and height if vertical).
-   *    The block size is usually the containing block inline-size, per
-   *    CSS21 sec 8.3 (read in conjunction with CSS Writing Modes sec
-   *    7.2), but may be the containing block block-size, e.g. in CSS3
-   *    Flexbox and Grid.
+   *    Inline size of the containing block (in its own writing mode), to use
+   *    for resolving percentage padding values in the inline and block axes.
    * @return true if the padding is dependent on the containing block size.
    */
   bool ComputePadding(mozilla::WritingMode aWM,
-                      const mozilla::LogicalSize& aPercentBasis,
+                      nscoord aPercentBasis,
                       nsIAtom* aFrameType);
 
 protected:
 
   void InitOffsets(mozilla::WritingMode aWM,
-                   const mozilla::LogicalSize& aPercentBasis,
+                   nscoord aPercentBasis,
                    nsIAtom* aFrameType,
                    ReflowInputFlags aFlags,
                    const nsMargin* aBorder = nullptr,
                    const nsMargin* aPadding = nullptr);
 
   /*
    * Convert nsStyleCoord to nscoord when percentages depend on the
    * inline size of the containing block, and enumerated values are for
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -10284,18 +10284,18 @@ DR_init_constraints_cookie::DR_init_cons
 DR_init_constraints_cookie::~DR_init_constraints_cookie()
 {
   MOZ_COUNT_DTOR(DR_init_constraints_cookie);
   ReflowInput::DisplayInitConstraintsExit(mFrame, mState, mValue);
 }
 
 DR_init_offsets_cookie::DR_init_offsets_cookie(
                      nsIFrame*                aFrame,
-                     SizeComputationInput*        aState,
-                     const LogicalSize&       aPercentBasis,
+                     SizeComputationInput*    aState,
+                     nscoord                  aPercentBasis,
                      const nsMargin*          aMargin,
                      const nsMargin*          aPadding)
   : mFrame(aFrame)
   , mState(aState)
 {
   MOZ_COUNT_CTOR(DR_init_offsets_cookie);
   mValue = SizeComputationInput::DisplayInitOffsetsEnter(mFrame, mState,
                                                      aPercentBasis,
@@ -11238,37 +11238,34 @@ ReflowInput::DisplayInitConstraintsExit(
   }
   DR_state->DeleteTreeNode(*treeNode);
 }
 
 
 /* static */ void*
 SizeComputationInput::DisplayInitOffsetsEnter(nsIFrame* aFrame,
                                           SizeComputationInput* aState,
-                                          const LogicalSize& aPercentBasis,
+                                          nscoord aPercentBasis,
                                           const nsMargin* aBorder,
                                           const nsMargin* aPadding)
 {
   NS_PRECONDITION(aFrame, "non-null frame required");
   NS_PRECONDITION(aState, "non-null state required");
 
   if (!DR_state->mInited) DR_state->Init();
   if (!DR_state->mActive) return nullptr;
 
   // aState is not necessarily a ReflowInput
   DR_FrameTreeNode* treeNode = DR_state->CreateTreeNode(aFrame, nullptr);
   if (treeNode && treeNode->mDisplay) {
     DR_state->DisplayFrameTypeInfo(aFrame, treeNode->mIndent);
 
-    char horizPctBasisStr[16];
-    char vertPctBasisStr[16];
-    WritingMode wm = aState->GetWritingMode();
-    DR_state->PrettyUC(aPercentBasis.ISize(wm), horizPctBasisStr, 16);
-    DR_state->PrettyUC(aPercentBasis.BSize(wm), vertPctBasisStr, 16);
-    printf("InitOffsets pct_basis=%s,%s", horizPctBasisStr, vertPctBasisStr);
+    char pctBasisStr[16];
+    DR_state->PrettyUC(aPercentBasis, pctBasisStr, 16);
+    printf("InitOffsets pct_basis=%s", pctBasisStr);
 
     DR_state->PrintMargin("b", aBorder);
     DR_state->PrintMargin("p", aPadding);
     putchar('\n');
   }
   return treeNode;
 }
 
--- a/layout/generic/nsFrame.h
+++ b/layout/generic/nsFrame.h
@@ -840,17 +840,17 @@ public:
 
     nsIFrame* mFrame;
     mozilla::ReflowInput* mState;
     void* mValue;
   };
 
   struct DR_init_offsets_cookie {
     DR_init_offsets_cookie(nsIFrame* aFrame, mozilla::SizeComputationInput* aState,
-                           const mozilla::LogicalSize& aPercentBasis,
+                           nscoord aPercentBasis,
                            const nsMargin* aBorder,
                            const nsMargin* aPadding);
     ~DR_init_offsets_cookie();
 
     nsIFrame* mFrame;
     mozilla::SizeComputationInput* mState;
     void* mValue;
   };