Bug 1174003 part 6: [css-flexbox] Replace ComputedCrossSize() helper with a new API that uses logical axes internally. r?mats draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 27 Feb 2018 15:46:55 -0800
changeset 760690 4f9e912b1903a92c9fa1d4e42e6d180cf57cbdb5
parent 760683 fb87314e2c86924c78de50440fd97686ebc043b3
child 760691 1dfcc0e4f87d8a89e2bff6eb54c2e02ada41cfd6
child 760699 3e05d3091220f592b6d7e202792ace6130204bca
push id100719
push userdholbert@mozilla.com
push dateTue, 27 Feb 2018 23:47:13 +0000
reviewersmats
bugs1174003
milestone60.0a1
Bug 1174003 part 6: [css-flexbox] Replace ComputedCrossSize() helper with a new API that uses logical axes internally. r?mats This patch doesn't affect behavior. It removes a helper-function that simply returned nsStylePosition::mWidth or mHeight -- whichever was in the flex container's cross axis. This helper was only used to answer the question "is the cross size 'auto'", at a single callsite. So, this patch replaces the helper with a new helper that more directly answers that question. The new helper's implementation uses logical axes for its reasoning, too, whereas the removed one used physical axes (and in particular, it relied on AxisOrientationTracker::IsCrossAxisHorizontal(), which I'll be getting rid of later in this patch series). MozReview-Commit-ID: EJ8MObTauZH
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -352,27 +352,16 @@ public:
   }
   nscoord GetMarginSizeInCrossAxis(const LogicalMargin& aMargin) const {
     // If we're row-oriented, our cross axis is the block axis.
     return IsRowOriented()
       ? aMargin.BStartEnd(mWM)
       : aMargin.IStartEnd(mWM);
   }
 
-  // Returns aFrame's computed value for 'height' or 'width' -- whichever is in
-  // the cross-axis. (NOTE: This is cross-axis-specific for now. If we need a
-  // main-axis version as well, we could generalize or clone this function.)
-  const nsStyleCoord& ComputedCrossSize(const nsIFrame* aFrame) const {
-    const nsStylePosition* stylePos = aFrame->StylePosition();
-
-    return IsCrossAxisHorizontal() ?
-      stylePos->mWidth :
-      stylePos->mHeight;
-  }
-
   /**
    * Converts a "flex-relative" point (a main-axis & cross-axis coordinate)
    * into a LogicalPoint, using the flex container's writing mode.
    *
    *  @arg aMainCoord  The main-axis coordinate -- i.e an offset from the
    *                   main-start edge of the flex container's content box.
    *  @arg aCrossCoord The cross-axis coordinate -- i.e an offset from the
    *                   cross-start edge of the flex container's content box.
@@ -551,16 +540,19 @@ public:
 
   bool HadMinViolation() const     { return mHadMinViolation; }
   bool HadMaxViolation() const     { return mHadMaxViolation; }
 
   // Indicates whether this item received a preliminary "measuring" reflow
   // before its actual reflow.
   bool HadMeasuringReflow() const  { return mHadMeasuringReflow; }
 
+  // Indicates whether this item's computed cross-size property is 'auto'.
+  bool IsCrossSizeAuto() const;
+
   // Indicates whether this item's cross-size has been stretched (from having
   // "align-self: stretch" with an auto cross-size and no auto margins in the
   // cross axis).
   bool IsStretched() const         { return mIsStretched; }
 
   // Indicates whether we need to resolve an 'auto' value for the main-axis
   // min-[width|height] property.
   bool NeedsMinSizeAutoResolution() const
@@ -1995,16 +1987,28 @@ FlexItem::GetBaselineOffsetFromOuterCros
              "we're not using the top side, so that only leaves the bottom...");
 
   // Measuring from bottom: The distance from the margin-box bottom edge to the
   // baseline is just the margin-box cross size (i.e. outer cross size), minus
   // the already-computed distance from margin-top to baseline.
   return GetOuterCrossSize(crossAxis) - marginTopToBaseline;
 }
 
+bool
+FlexItem::IsCrossSizeAuto() const
+{
+  const nsStylePosition* stylePos = mFrame->StylePosition();
+  // Check whichever component is in the flex container's cross axis.
+  // (IsInlineAxisCrossAxis() tells us whether that's our ISize or BSize, in
+  // terms of our own WritingMode, mWM.)
+  return eStyleUnit_Auto == (IsInlineAxisCrossAxis()
+                             ? stylePos->ISize(mWM).GetUnit()
+                             : stylePos->BSize(mWM).GetUnit());
+}
+
 uint32_t
 FlexItem::GetNumAutoMarginsInAxis(AxisOrientationType aAxis) const
 {
   uint32_t numAutoMargins = 0;
   const nsStyleSides& styleMargin = mFrame->StyleMargin()->mMargin;
   for (uint32_t i = 0; i < eNumAxisEdges; i++) {
     mozilla::Side side = kAxisOrientationToSidesMap[aAxis][i];
     if (styleMargin.GetUnit(side) == eStyleUnit_Auto) {
@@ -3275,17 +3279,17 @@ FlexItem::ResolveStretchedCrossSize(nsco
                                     const FlexboxAxisTracker& aAxisTracker)
 {
   AxisOrientationType crossAxis = aAxisTracker.GetCrossAxis();
   // We stretch IFF we are align-self:stretch, have no auto margins in
   // cross axis, and have cross-axis size property == "auto". If any of those
   // conditions don't hold up, we won't stretch.
   if (mAlignSelf != NS_STYLE_ALIGN_STRETCH ||
       GetNumAutoMarginsInAxis(crossAxis) != 0 ||
-      eStyleUnit_Auto != aAxisTracker.ComputedCrossSize(mFrame).GetUnit()) {
+      !IsCrossSizeAuto()) {
     return;
   }
 
   // If we've already been stretched, we can bail out early, too.
   // No need to redo the calculation.
   if (mIsStretched) {
     return;
   }