Bug 1497589 Part 4: Set ComputedFlexContainerInfo physical axis values, and expose them through the Flex API. r=dholbert
authorBrad Werth <bwerth@mozilla.com>
Wed, 17 Oct 2018 20:23:09 +0000
changeset 490306 d8e73cf6952fd03c118b8cdd3cc97a8f59045f95
parent 490305 082aaca611f9f0e13cd82d6cc708b687cfd35b7c
child 490307 49e1cc5fdf49b102fa27980622087fc550ed93bb
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdholbert
bugs1497589
milestone64.0a1
Bug 1497589 Part 4: Set ComputedFlexContainerInfo physical axis values, and expose them through the Flex API. r=dholbert Depends on D8616 Differential Revision: https://phabricator.services.mozilla.com/D8617
dom/flex/Flex.cpp
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsFlexContainerFrame.h
--- a/dom/flex/Flex.cpp
+++ b/dom/flex/Flex.cpp
@@ -36,16 +36,19 @@ Flex::Flex(Element* aParent,
 
   mLines.SetLength(containerInfo->mLines.Length());
   uint32_t index = 0;
   for (auto&& l : containerInfo->mLines) {
     FlexLineValues* line = new FlexLineValues(this, &l);
     mLines.ElementAt(index) = line;
     index++;
   }
+
+  mMainAxisDirection = containerInfo->mMainAxisDirection;
+  mCrossAxisDirection = containerInfo->mCrossAxisDirection;
 }
 
 JSObject*
 Flex::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return Flex_Binding::Wrap(aCx, this, aGivenProto);
 }
 
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -298,16 +298,18 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(Ax
 class MOZ_STACK_CLASS nsFlexContainerFrame::FlexboxAxisTracker {
 public:
   FlexboxAxisTracker(const nsFlexContainerFrame* aFlexContainer,
                      const WritingMode& aWM,
                      AxisTrackerFlags aFlags = eNoFlags);
 
   // Accessors:
   // XXXdholbert [BEGIN DEPRECATED]
+  // These should not be used in layout, but they are useful for devtools API
+  // which reports physical axis direction.
   AxisOrientationType GetMainAxis() const  { return mMainAxis;  }
   AxisOrientationType GetCrossAxis() const { return mCrossAxis; }
   // XXXdholbert [END DEPRECATED]
 
   // Returns the flex container's writing mode.
   WritingMode GetWritingMode() const { return mWM; }
 
   // Returns true if our main axis is in the reverse direction of our
@@ -4664,16 +4666,31 @@ nsFlexContainerFrame::IsUsedFlexBasisCon
   // See https://drafts.csswg.org/css-flexbox-1/#valdef-flex-basis-auto
   return
     (aFlexBasis->GetUnit() == eStyleUnit_Enumerated &&
      aFlexBasis->GetIntValue() == NS_STYLE_FLEX_BASIS_CONTENT) ||
     (aFlexBasis->GetUnit() == eStyleUnit_Auto &&
      aMainSize->GetUnit() == eStyleUnit_Auto);
 }
 
+static mozilla::dom::FlexPhysicalDirection
+ConvertAxisOrientationTypeToAPIEnum(AxisOrientationType aAxisOrientation)
+{
+  switch (aAxisOrientation) {
+    case eAxis_LR:
+      return mozilla::dom::FlexPhysicalDirection::Horizontal_lr;
+    case eAxis_RL:
+      return mozilla::dom::FlexPhysicalDirection::Horizontal_rl;
+    case eAxis_TB:
+      return mozilla::dom::FlexPhysicalDirection::Vertical_tb;
+    default:
+      return mozilla::dom::FlexPhysicalDirection::Vertical_bt;
+  }
+}
+
 void
 nsFlexContainerFrame::DoFlexLayout(nsPresContext*           aPresContext,
                                    ReflowOutput&     aDesiredSize,
                                    const ReflowInput& aReflowInput,
                                    nsReflowStatus&          aStatus,
                                    nscoord aContentBoxMainSize,
                                    nscoord aAvailableBSizeForContent,
                                    nsTArray<StrutInfo>& aStruts,
@@ -4718,16 +4735,29 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
     if (!aStruts.IsEmpty()) {
       // We restarted DoFlexLayout, and may have stale mLines to clear:
       containerInfo->mLines.Clear();
     } else {
       MOZ_ASSERT(containerInfo->mLines.IsEmpty(),
                  "Shouldn't have lines yet.");
     }
 
+    // Set the axis physical directions.
+    AxisOrientationType mainAxis = aAxisTracker.GetMainAxis();
+    AxisOrientationType crossAxis = aAxisTracker.GetCrossAxis();
+    if (aAxisTracker.AreAxesInternallyReversed()) {
+      mainAxis = GetReverseAxis(mainAxis);
+      crossAxis = GetReverseAxis(crossAxis);
+    }
+
+    containerInfo->mMainAxisDirection =
+      ConvertAxisOrientationTypeToAPIEnum(mainAxis);
+    containerInfo->mCrossAxisDirection =
+      ConvertAxisOrientationTypeToAPIEnum(crossAxis);
+
     for (const FlexLine* line = lines.getFirst(); line;
          line = line->getNext()) {
       ComputedFlexLineInfo* lineInfo =
         containerInfo->mLines.AppendElement();
       // Most lineInfo properties will be set later, but we set
       // mGrowthState to UNCHANGED here because it may be later
       // modified by ResolveFlexibleLengths().
       lineInfo->mGrowthState =
--- a/layout/generic/nsFlexContainerFrame.h
+++ b/layout/generic/nsFlexContainerFrame.h
@@ -6,16 +6,17 @@
 
 /* rendering object for CSS "display: flex" and "display: -webkit-box" */
 
 #ifndef nsFlexContainerFrame_h___
 #define nsFlexContainerFrame_h___
 
 #include "nsContainerFrame.h"
 #include "mozilla/UniquePtr.h"
+#include "mozilla/dom/FlexBinding.h"
 
 class nsStyleCoord;
 
 namespace mozilla {
 template <class T> class LinkedList;
 class LogicalPoint;
 } // namespace mozilla
 
@@ -67,16 +68,18 @@ struct ComputedFlexLineInfo
     SHRINKING,
     GROWING,
   } mGrowthState;
 };
 
 struct ComputedFlexContainerInfo
 {
   nsTArray<ComputedFlexLineInfo> mLines;
+  mozilla::dom::FlexPhysicalDirection mMainAxisDirection;
+  mozilla::dom::FlexPhysicalDirection mCrossAxisDirection;
 };
 
 /**
  * This is the rendering object used for laying out elements with
  * "display: flex" or "display: inline-flex".
  *
  * We also use this class for elements with "display: -webkit-box" or
  * "display: -webkit-inline-box" (but not "-moz-box" / "-moz-inline-box" --