Bug 1384266: Generalize FlexItem::GetBaselineOffsetFromOuterCrossEdge to allow horizontal cross axis with rotated writing modes. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 09 Oct 2017 16:17:36 -0700
changeset 677073 6a7232dfba4a6817d73b071782d921915375b2fb
parent 676713 613f64109bdef590b9748355441b3c620efa7be5
child 735105 ff9cabcccabbd11b788ec03b9d6a4037033d9b04
push id83680
push userbwerth@mozilla.com
push dateMon, 09 Oct 2017 23:22:10 +0000
bugs1384266
milestone58.0a1
Bug 1384266: Generalize FlexItem::GetBaselineOffsetFromOuterCrossEdge to allow horizontal cross axis with rotated writing modes. MozReview-Commit-ID: 4dCJuMWlTUC
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -1892,45 +1892,44 @@ 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(),
-             "Only expecting to be doing baseline computations when the "
-             "cross axis is vertical");
-
   AxisOrientationType crossAxis = aAxisTracker.GetCrossAxis();
   mozilla::Side sideToMeasureFrom = kAxisOrientationToSidesMap[crossAxis][aEdge];
 
-  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;
+  // Measuring from start (normal case): the distance from the margin-box start
+  // edge to the baseline is just ascent + margin.
+
+  // Measuring from end: The distance from the margin-box end edge to the
+  // baseline is just the margin-box cross size (i.e. outer cross size), minus
+  // the already-computed distance from margin to baseline.
+
+  // Determine the margin from the start edge.
+  nscoord marginToUse;
+  if ((sideToMeasureFrom == eSideTop) ||
+      (sideToMeasureFrom == eSideBottom)) {
+    marginToUse = mMargin.top;
+  } else {
+    marginToUse = mMargin.left;
   }
-
-  MOZ_ASSERT(sideToMeasureFrom == eSideBottom,
-             "We already checked that we're dealing with a vertical axis, and "
-             "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;
+    
+  nscoord startSideBaseline = ResolvedAscent(aUseFirstLineBaseline) +
+                              marginToUse;
+
+  // Determine if we're aligning from the start.
+  bool isStart = ((sideToMeasureFrom == eSideTop) ||
+                  (sideToMeasureFrom == eSideLeft));
+
+  return (isStart ? startSideBaseline :
+                    GetOuterCrossSize(crossAxis) - startSideBaseline);
 }
 
 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++) {