Bug 1174003 part 7: [css-flexbox] Logicalize IsCrossAxisHorizontal() check in GetBaselineOffsetFromOuterCrossSize (and simplify a condition for baseline fallback). r?mats draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Tue, 27 Feb 2018 15:50:30 -0800
changeset 760699 3e05d3091220f592b6d7e202792ace6130204bca
parent 760690 4f9e912b1903a92c9fa1d4e42e6d180cf57cbdb5
child 760700 bba149de618706eeebdc88af968ef92979fbeda0
child 760713 4dc60ed24b500cf4635018ff522def510a91a212
child 760720 69780811f58b21177071441c56b55ab7f916cc17
push id100724
push userdholbert@mozilla.com
push dateTue, 27 Feb 2018 23:50:42 +0000
reviewersmats
bugs1174003, 1384266
milestone60.0a1
Bug 1174003 part 7: [css-flexbox] Logicalize IsCrossAxisHorizontal() check in GetBaselineOffsetFromOuterCrossSize (and simplify a condition for baseline fallback). r?mats This patch doesn't change our behavior -- not in opt builds, at least. In debug builds, this patch does change an assertion condition, to remove a usage of IsCrossAxisHorizontal(). This means debug builds may proceed a bit further when loading e.g. bug 1384266's testcase (which up until now was tripping this assertion). Now that testcase fails a slighlty later assertion (which I'll sort out on that bug). The first hunk of this patch is just a simplification -- replacing a complicated condition (IsRowOriented==IsOrthogonalTo) with a simpler formulation of the same condition. I'm making that simplification in this patch so that we're more clearly consistent about what condition we depend on for baseline alignment. After this patch, that (simplified) condition matches the condition that we assert inside of GetBaselineOffsetFromOuterCrossEdge(). Note: I'm adding two XXXdholbert comments in this patch, for outstanding issues that I ran across which are out-of-scope for this patch series. MozReview-Commit-ID: 5x5xqWWilQZ
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -1865,24 +1865,25 @@ FlexItem::FlexItem(ReflowInput& aFlexIte
         MOZ_ASSERT(GetMarginComponentForSide(side) == 0,
                    "Someone else tried to resolve our auto margin");
       }
     }
   }
 #endif // DEBUG
 
   // Map align-self 'baseline' value to 'start' when baseline alignment
-  // is not possible because the FlexItem's writing mode is orthogonal to
-  // the main axis of the container. If that's the case, we just directly
+  // is not possible because the FlexItem's block axis is orthogonal to
+  // the cross axis of the container. If that's the case, we just directly
   // convert our align-self value here, so that we don't have to handle this
   // with special cases elsewhere.
   // We are treating this case as one where it is appropriate to use the
-  // fallback values defined at https://www.w3.org/TR/css-align-3/#baseline
-  if (aAxisTracker.IsRowOriented() ==
-      aAxisTracker.GetWritingMode().IsOrthogonalTo(mWM)) {
+  // fallback values defined at https://www.w3.org/TR/css-align/#baseline-values
+  // XXXdholbert That spec text actually says to fall back to 'start'/'end',
+  // not 'flex-start'/'flex-end'... Probably sort this out in bug 1207698.
+  if (!IsBlockAxisCrossAxis()) {
     if (mAlignSelf == NS_STYLE_ALIGN_BASELINE) {
       mAlignSelf = NS_STYLE_ALIGN_FLEX_START;
     } else if (mAlignSelf == NS_STYLE_ALIGN_LAST_BASELINE) {
       mAlignSelf = NS_STYLE_ALIGN_FLEX_END;
     }
   }
 }
 
@@ -1956,28 +1957,32 @@ FlexItem::CheckForMinSizeAuto(const Refl
 }
 
 nscoord
 FlexItem::GetBaselineOffsetFromOuterCrossEdge(
   AxisEdgeType aEdge,
   const FlexboxAxisTracker& aAxisTracker,
   bool aUseFirstLineBaseline) const
 {
-  // NOTE: Currently, 'mAscent' (taken from reflow) is an inherently vertical
-  // measurement -- it's the distance from the border-top edge of this FlexItem
-  // to its baseline. So, we can really only do baseline alignment when the
-  // cross axis is vertical. (The FlexItem constructor enforces this when
-  // resolving the item's "mAlignSelf" value).
-  MOZ_ASSERT(!aAxisTracker.IsCrossAxisHorizontal(),
+  // NOTE:
+  //  * We only use baselines for aligning in the flex container's cross axis.
+  //  * Baselines are a measurement in the item's block axis.
+  // ...so we only expect to get here if the item's block axis is parallel (or
+  // antiparallel) to the container's cross axis.  (Otherwise, the FlexItem
+  // constructor should've resolved mAlignSelf with a fallback value, which
+  // would prevent this function from being called.)
+  MOZ_ASSERT(IsBlockAxisCrossAxis(),
              "Only expecting to be doing baseline computations when the "
-             "cross axis is vertical");
+             "cross axis is the block axis");
 
   AxisOrientationType crossAxis = aAxisTracker.GetCrossAxis();
   mozilla::Side sideToMeasureFrom = kAxisOrientationToSidesMap[crossAxis][aEdge];
 
+  // XXXdholbert The "top"/"bottom" physical-axis dependencies below need to be
+  // logicalized -- see bug 1384266.
   nscoord marginTopToBaseline = ResolvedAscent(aUseFirstLineBaseline) +
                                 mMargin.top;
 
   if (sideToMeasureFrom == eSideTop) {
     // Measuring from top (normal case): the distance from the margin-box top
     // edge to the baseline is just ascent + margin-top.
     return marginTopToBaseline;
   }