Bug 1267462 part 6: Add FlexItem methods to test whether its inline axis is in container's main vs. cross axis. r?mats draft
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 08 Feb 2018 15:01:09 -0800
changeset 752863 235b06096f649d709e5a9cf74f192648fe31bb32
parent 752862 5a2cf8262a98844c5beeb63b853ca934f578aaa2
child 752864 f464b3b3471f4ab25dd9b41614efaf66eefc6be8
push id98402
push userdholbert@mozilla.com
push dateFri, 09 Feb 2018 01:40:46 +0000
reviewersmats
bugs1267462
milestone60.0a1
Bug 1267462 part 6: Add FlexItem methods to test whether its inline axis is in container's main vs. cross axis. r?mats This patch doesn't affect behavior -- it's just adding a new member-var & accessor with no usages. The next patch in the series will add some usages. MozReview-Commit-ID: NKBvKnb7Jw
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -562,16 +562,25 @@ public:
   // min-[width|height] property.
   bool NeedsMinSizeAutoResolution() const
     { return mNeedsMinSizeAutoResolution; }
 
   // Indicates whether this item is a "strut" left behind by an element with
   // visibility:collapse.
   bool IsStrut() const             { return mIsStrut; }
 
+  // Returns true if this item's inline axis is parallel (or antiparallel)
+  // to the container's main axis. Otherwise (i.e. if this item's inline axis
+  // is orthogonal to the container's main axis), this function returns false.
+  bool IsInlineAxisMainAxis() const { return mIsInlineAxisMainAxis; }
+
+  // Same as above, but for cross axis. Equivalent to !IsInlineAxisMainAxis().
+  // This just exists for convenience/readability at callsites.
+  bool IsInlineAxisCrossAxis() const { return !mIsInlineAxisMainAxis; }
+
   WritingMode GetWritingMode() const { return mWM; }
   uint8_t GetAlignSelf() const     { return mAlignSelf; }
 
   // Returns the flex factor (flex-grow or flex-shrink), depending on
   // 'aIsUsingFlexGrow'.
   //
   // Asserts fatally if called on a frozen item (since frozen items are not
   // flexible).
@@ -844,16 +853,17 @@ protected:
   bool mHadMaxViolation;
 
   // Misc:
   bool mHadMeasuringReflow; // Did this item get a preliminary reflow,
                             // to measure its desired height?
   bool mIsStretched; // See IsStretched() documentation
   bool mIsStrut;     // Is this item a "strut" left behind by an element
                      // with visibility:collapse?
+  const bool mIsInlineAxisMainAxis; // See IsInlineAxisMainAxis() documentation
 
   // Does this item need to resolve a min-[width|height]:auto (in main-axis).
   bool mNeedsMinSizeAutoResolution;
 
   uint8_t mAlignSelf; // My "align-self" computed value (with "auto"
                       // swapped out for parent"s "align-items" value,
                       // in our constructor).
 };
@@ -1796,17 +1806,19 @@ FlexItem::FlexItem(ReflowInput& aFlexIte
     mAscent(0),
     mShareOfWeightSoFar(0.0f),
     mWM(aFlexItemReflowInput.GetWritingMode()),
     mIsFrozen(false),
     mHadMinViolation(false),
     mHadMaxViolation(false),
     mHadMeasuringReflow(false),
     mIsStretched(false),
-    mIsStrut(false)
+    mIsStrut(false),
+    mIsInlineAxisMainAxis(aAxisTracker.IsRowOriented() !=
+                          aAxisTracker.GetWritingMode().IsOrthogonalTo(mWM))
     // mNeedsMinSizeAutoResolution is initialized in CheckForMinSizeAuto()
     // mAlignSelf, see below
 {
   MOZ_ASSERT(mFrame, "expecting a non-null child frame");
   MOZ_ASSERT(!mFrame->IsPlaceholderFrame(),
              "placeholder frames should not be treated as flex items");
   MOZ_ASSERT(!(mFrame->GetStateBits() & NS_FRAME_OUT_OF_FLOW),
              "out-of-flow frames should not be treated as flex items");
@@ -1894,16 +1906,17 @@ FlexItem::FlexItem(nsIFrame* aChildFrame
     // just share container's WM for simplicity:
     mWM(aContainerWM),
     mIsFrozen(true),
     mHadMinViolation(false),
     mHadMaxViolation(false),
     mHadMeasuringReflow(false),
     mIsStretched(false),
     mIsStrut(true), // (this is the constructor for making struts, after all)
+    mIsInlineAxisMainAxis(true), // (doesn't matter b/c we're not doing layout)
     mNeedsMinSizeAutoResolution(false),
     mAlignSelf(NS_STYLE_ALIGN_FLEX_START)
 {
   MOZ_ASSERT(mFrame, "expecting a non-null child frame");
   MOZ_ASSERT(NS_STYLE_VISIBILITY_COLLAPSE ==
              mFrame->StyleVisibility()->mVisible,
              "Should only make struts for children with 'visibility:collapse'");
   MOZ_ASSERT(!mFrame->IsPlaceholderFrame(),