Bug 1267462 part 6: Add FlexItem methods to test whether its inline axis is in container's main vs. cross axis. r=mats
authorDaniel Holbert <dholbert@cs.stanford.edu>
Thu, 08 Feb 2018 15:01:09 -0800
changeset 752934 ceef95f707fe6926cc7419495e61d1fe4223d52c
parent 752933 60666668cf81676e5917e94c9a5ac34c73f944b7
child 752935 1c67959201d286cb2a76906a240b88a15c737071
push id98429
push usermak77@bonardo.net
push dateFri, 09 Feb 2018 10:14:12 +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(),