Bug 1148078: Replace the word "Logical" with "Flex-Relative" in some vars & functions in flexbox layout. r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 26 Mar 2015 14:37:48 -0700
changeset 236048 638492d777fca9f6e7bbefc1de2c5c40137a4414
parent 236047 fc15fab6d75b56101672ca8480fbf99e60398377
child 236049 1652874e2d978dab14dd56b39342ccb93ddee650
push id28488
push userryanvm@gmail.com
push dateFri, 27 Mar 2015 16:19:11 +0000
treeherdermozilla-central@44e454b5e93b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1148078
milestone39.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 1148078: Replace the word "Logical" with "Flex-Relative" in some vars & functions in flexbox layout. r=mats
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -39,18 +39,18 @@ GetFlexContainerLog()
   static PRLogModuleInfo *sLog;
   if (!sLog)
     sLog = PR_NewLogModule("nsFlexContainerFrame");
   return sLog;
 }
 #endif /* PR_LOGGING */
 
 // XXXdholbert Some of this helper-stuff should be separated out into a general
-// "LogicalAxisUtils.h" helper.  Should that be a class, or a namespace (under
-// what super-namespace?), or what?
+// "main/cross-axis utils" header, shared by grid & flexbox?
+// (Particularly when grid gets support for align-*/justify-* properties.)
 
 // Helper enums
 // ============
 
 // Represents a physical orientation for an axis.
 // The directional suffix indicates the direction in which the axis *grows*.
 // So e.g. eAxis_LR means a horizontal left-to-right axis, whereas eAxis_BT
 // means a vertical bottom-to-top axis.
@@ -132,32 +132,34 @@ GetSizePropertyForAxis(const nsIFrame* a
   const nsStylePosition* stylePos = aFrame->StylePosition();
 
   return IsAxisHorizontal(aAxis) ?
     stylePos->mWidth :
     stylePos->mHeight;
 }
 
 /**
- * Converts a logical position in a given axis into a position in the
- * corresponding physical (x or y) axis. If the logical axis already maps
- * directly onto one of our physical axes (i.e. LTR or TTB), then the logical
- * and physical positions are equal; otherwise, we subtract the logical
- * position from the container-size in that axis, to flip the polarity.
- * (so e.g. a logical position of 2px in a RTL 20px-wide container
- * would correspond to a physical position of 18px.)
+ * Converts a "flex-relative" coordinate in a single axis (a main- or cross-axis
+ * coordinate) into a coordinate in the corresponding physical (x or y) axis. If
+ * the flex-relative axis in question already maps *directly* to a physical
+ * axis (i.e. if it's LTR or TTB), then the physical coordinate has the same
+ * numeric value as the provided flex-relative coordinate. Otherwise, we have to
+ * subtract the flex-relative coordinate from the flex container's size in that
+ * axis, to flip the polarity. (So e.g. a main-axis position of 2px in a RTL
+ * 20px-wide container would correspond to a physical coordinate (x-value) of
+ * 18px.)
  */
 static nscoord
-PhysicalPosFromLogicalPos(nscoord aLogicalPosn,
-                          nscoord aLogicalContainerSize,
-                          AxisOrientationType aAxis) {
+PhysicalCoordFromFlexRelativeCoord(nscoord aFlexRelativeCoord,
+                                   nscoord aContainerSize,
+                                   AxisOrientationType aAxis) {
   if (AxisGrowsInPositiveDirection(aAxis)) {
-    return aLogicalPosn;
+    return aFlexRelativeCoord;
   }
-  return aLogicalContainerSize - aLogicalPosn;
+  return aContainerSize - aFlexRelativeCoord;
 }
 
 // Helper-macro to let us pick one of two expressions to evaluate
 // (a width expression vs. a height expression), to get a main-axis or
 // cross-axis component.
 // For code that has e.g. a nsSize object, FlexboxAxisTracker::GetMainComponent
 // and GetCrossComponent are cleaner; but in cases where we simply have
 // two separate expressions for width and height (which may be expensive to
@@ -199,44 +201,49 @@ public:
   }
   nscoord GetMarginSizeInCrossAxis(const nsMargin& aMargin) const {
     return IsAxisHorizontal(mCrossAxis) ?
       aMargin.LeftRight() :
       aMargin.TopBottom();
   }
 
   /**
-   * Converts a logical point into a "physical" x,y point.
+   * Converts a "flex-relative" point (a main-axis & cross-axis coordinate)
+   * into a "physical" x,y point.
    *
    * In the simplest case where the main-axis is left-to-right and the
    * cross-axis is top-to-bottom, this just returns
-   * nsPoint(aMainPosn, aCrossPosn).
+   * nsPoint(aMainCoord, aCrossCoord).
    *
-   *  @arg aMainPosn  The main-axis position -- i.e an offset from the
-   *                  main-start edge of the container's content box.
-   *  @arg aCrossPosn The cross-axis position -- i.e an offset from the
-   *                  cross-start edge of the container's content box.
+   *  @arg aMainCoord  The main-axis coordinate -- i.e an offset from the
+   *                   main-start edge of the container's content box.
+   *  @arg aCrossCoord The cross-axis coordinate -- i.e an offset from the
+   *                   cross-start edge of the container's content box.
    *  @return A nsPoint representing the same position (in coordinates
    *          relative to the container's content box).
    */
-  nsPoint PhysicalPointFromLogicalPoint(nscoord aMainPosn,
-                                        nscoord aCrossPosn,
-                                        nscoord aContainerMainSize,
-                                        nscoord aContainerCrossSize) const {
-    nscoord physicalPosnInMainAxis =
-      PhysicalPosFromLogicalPos(aMainPosn, aContainerMainSize, mMainAxis);
-    nscoord physicalPosnInCrossAxis =
-      PhysicalPosFromLogicalPos(aCrossPosn, aContainerCrossSize, mCrossAxis);
+  nsPoint PhysicalPointFromFlexRelativePoint(nscoord aMainCoord,
+                                             nscoord aCrossCoord,
+                                             nscoord aContainerMainSize,
+                                             nscoord aContainerCrossSize) const {
+    nscoord physicalCoordInMainAxis =
+      PhysicalCoordFromFlexRelativeCoord(aMainCoord, aContainerMainSize,
+                                         mMainAxis);
+    nscoord physicalCoordInCrossAxis =
+      PhysicalCoordFromFlexRelativeCoord(aCrossCoord, aContainerCrossSize,
+                                         mCrossAxis);
 
     return IsAxisHorizontal(mMainAxis) ?
-      nsPoint(physicalPosnInMainAxis, physicalPosnInCrossAxis) :
-      nsPoint(physicalPosnInCrossAxis, physicalPosnInMainAxis);
+      nsPoint(physicalCoordInMainAxis, physicalCoordInCrossAxis) :
+      nsPoint(physicalCoordInCrossAxis, physicalCoordInMainAxis);
   }
-  nsSize PhysicalSizeFromLogicalSizes(nscoord aMainSize,
-                                      nscoord aCrossSize) const {
+
+
+  nsSize PhysicalSizeFromFlexRelativeSizes(nscoord aMainSize,
+                                           nscoord aCrossSize) const {
     return IsAxisHorizontal(mMainAxis) ?
       nsSize(aMainSize, aCrossSize) :
       nsSize(aCrossSize, aMainSize);
   }
 
   // Are my axes reversed with respect to what the author asked for?
   // (We may reverse the axes in the FlexboxAxisTracker constructor and set
   // this flag, to avoid reflowing our children in bottom-to-top order.)
@@ -3247,30 +3254,32 @@ FlexLine::PositionItemsInMainAxis(uint8_
 
     mainAxisPosnTracker.ExitChildFrame(itemMainBorderBoxSize);
     mainAxisPosnTracker.ExitMargin(item->GetMargin());
     mainAxisPosnTracker.TraversePackingSpace();
   }
 }
 
 /**
- * Given the flex container's "logical ascent" (i.e. distance from the
+ * Given the flex container's "flex-relative ascent" (i.e. distance from the
  * flex container's content-box cross-start edge to its baseline), returns
  * its actual physical ascent value (the distance from the *border-box* top
  * edge to its baseline).
  */
 static nscoord
-ComputePhysicalAscentFromLogicalAscent(nscoord aLogicalAscent,
-                                       nscoord aContentBoxCrossSize,
-                                       const nsHTMLReflowState& aReflowState,
-                                       const FlexboxAxisTracker& aAxisTracker)
+ComputePhysicalAscentFromFlexRelativeAscent(
+  nscoord aFlexRelativeAscent,
+  nscoord aContentBoxCrossSize,
+  const nsHTMLReflowState& aReflowState,
+  const FlexboxAxisTracker& aAxisTracker)
 {
   return aReflowState.ComputedPhysicalBorderPadding().top +
-    PhysicalPosFromLogicalPos(aLogicalAscent, aContentBoxCrossSize,
-                              aAxisTracker.GetCrossAxis());
+    PhysicalCoordFromFlexRelativeCoord(aFlexRelativeAscent,
+                                       aContentBoxCrossSize,
+                                       aAxisTracker.GetCrossAxis());
 }
 
 void
 nsFlexContainerFrame::SizeItemInCrossAxis(
   nsPresContext* aPresContext,
   const FlexboxAxisTracker& aAxisTracker,
   nsHTMLReflowState& aChildReflowState,
   FlexItem& aItem)
@@ -3604,17 +3613,17 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
   if (!aAxisTracker.AreAxesInternallyReversed()) {
     nscoord firstLineBaselineOffset = lines.getFirst()->GetBaselineOffset();
     if (firstLineBaselineOffset == nscoord_MIN) {
       // No baseline-aligned items in line. Use sentinel value to prompt us to
       // get baseline from the first FlexItem after we've reflowed it.
       flexContainerAscent = nscoord_MIN;
     } else  {
       flexContainerAscent =
-        ComputePhysicalAscentFromLogicalAscent(
+        ComputePhysicalAscentFromFlexRelativeAscent(
           crossAxisPosnTracker.GetPosition() + firstLineBaselineOffset,
           contentBoxCrossSize, aReflowState, aAxisTracker);
     }
   }
 
   for (FlexLine* line = lines.getFirst(); line; line = line->getNext()) {
 
     // Main-Axis Alignment - Flexbox spec section 9.5
@@ -3638,17 +3647,17 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
   if (aAxisTracker.AreAxesInternallyReversed()) {
     nscoord lastLineBaselineOffset = lines.getLast()->GetBaselineOffset();
     if (lastLineBaselineOffset == nscoord_MIN) {
       // No baseline-aligned items in line. Use sentinel value to prompt us to
       // get baseline from the last FlexItem after we've reflowed it.
       flexContainerAscent = nscoord_MIN;
     } else {
       flexContainerAscent =
-        ComputePhysicalAscentFromLogicalAscent(
+        ComputePhysicalAscentFromFlexRelativeAscent(
           crossAxisPosnTracker.GetPosition() - lastLineBaselineOffset,
           contentBoxCrossSize, aReflowState, aAxisTracker);
     }
   }
 
   // Before giving each child a final reflow, calculate the origin of the
   // flex container's content box (with respect to its border-box), so that
   // we can compute our flex item's final positions.
@@ -3660,30 +3669,30 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
   nscoord containerWidth = IsAxisHorizontal(aAxisTracker.GetMainAxis()) ?
                              aContentBoxMainSize : contentBoxCrossSize;
 
   // FINAL REFLOW: Give each child frame another chance to reflow, now that
   // we know its final size and position.
   for (const FlexLine* line = lines.getFirst(); line; line = line->getNext()) {
     for (const FlexItem* item = line->GetFirstItem(); item;
          item = item->getNext()) {
-      nsPoint physicalPosn = aAxisTracker.PhysicalPointFromLogicalPoint(
+      nsPoint physicalPosn = aAxisTracker.PhysicalPointFromFlexRelativePoint(
                                item->GetMainPosition(),
                                item->GetCrossPosition(),
                                aContentBoxMainSize,
                                contentBoxCrossSize);
       // Adjust physicalPosn to be relative to the container's border-box
       // (i.e. its frame rect), instead of the container's content-box:
       physicalPosn += containerContentBoxOrigin;
 
       //XXX Can we calculate the logical position more directly instead
       //    of this double conversion?
       nsSize finalFlexedPhysicalSize =
-        aAxisTracker.PhysicalSizeFromLogicalSizes(item->GetMainSize(),
-                                                  item->GetCrossSize());
+        aAxisTracker.PhysicalSizeFromFlexRelativeSizes(item->GetMainSize(),
+                                                       item->GetCrossSize());
       LogicalPoint framePos(outerWM, physicalPosn,
                             containerWidth - finalFlexedPhysicalSize.width -
                               item->GetBorderPadding().LeftRight());
 
       // (Intentionally snapshotting this before ApplyRelativePositioning, to
       // maybe use for setting the flex container's baseline.)
       const nscoord itemNormalBPos = framePos.B(outerWM);
 
@@ -3721,18 +3730,18 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
       if (item->Frame() == mFrames.FirstChild() &&
           flexContainerAscent == nscoord_MIN) {
         flexContainerAscent = itemNormalBPos + item->ResolvedAscent();
       }
     }
   }
 
   nsSize desiredContentBoxSize =
-    aAxisTracker.PhysicalSizeFromLogicalSizes(aContentBoxMainSize,
-                                              contentBoxCrossSize);
+    aAxisTracker.PhysicalSizeFromFlexRelativeSizes(aContentBoxMainSize,
+                                                   contentBoxCrossSize);
 
   aDesiredSize.Width() = desiredContentBoxSize.width +
     containerBorderPadding.LeftRight();
   // Does *NOT* include bottom border/padding yet (we add that a bit lower down)
   aDesiredSize.Height() = desiredContentBoxSize.height +
     containerBorderPadding.top;
 
   if (flexContainerAscent == nscoord_MIN) {