Bug 1225376 part 1 - [css-align] Don't compute left/right to start in the style system anymore (due to pending spec change). Map the used value instead (in layout). r=dholbert
authorMats Palmgren <mats@mozilla.com>
Sat, 28 Nov 2015 21:37:44 +0100
changeset 308704 d15205791d9bce5c067bad9ecc92e7181e34edb3
parent 308703 c33072613b5e7f60db7c324bdb79b558a0a1d50e
child 308705 ff70bbc58b6c9b5f354002cc9921364b7ff58657
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1225376
milestone45.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 1225376 part 1 - [css-align] Don't compute left/right to start in the style system anymore (due to pending spec change). Map the used value instead (in layout). r=dholbert For background, see this www-style thread: https://lists.w3.org/Archives/Public/www-style/2015Nov/0280.html
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsGridContainerFrame.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -3792,18 +3792,17 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
   const nscoord contentBoxCrossSize =
     ComputeCrossSize(aReflowState, aAxisTracker, sumLineCrossSizes,
                      aAvailableBSizeForContent, &isCrossSizeDefinite, aStatus);
 
   // Set up state for cross-axis alignment, at a high level (outside the
   // scope of a particular flex line)
   CrossAxisPositionTracker
     crossAxisPosnTracker(lines.getFirst(),
-                         aReflowState.mStylePosition->ComputedAlignContent(
-                           aReflowState.mStyleDisplay),
+                         aReflowState.mStylePosition->ComputedAlignContent(),
                          contentBoxCrossSize, isCrossSizeDefinite,
                          aAxisTracker);
 
   // Now that we know the cross size of each line (including
   // "align-content:stretch" adjustments, from the CrossAxisPositionTracker
   // constructor), we can create struts for any flex items with
   // "visibility: collapse" (and restart flex layout).
   if (aStruts.IsEmpty()) { // (Don't make struts if we already did)
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -1015,20 +1015,20 @@ static Maybe<LogicalAxis>
 AlignSelf(uint8_t aAlignSelf, const LogicalRect& aCB, const WritingMode aCBWM,
           const nsHTMLReflowState& aRS, const LogicalSize& aSize,
           LogicalSize* aContentSize, LogicalPoint* aPos)
 {
   Maybe<LogicalAxis> resizedAxis;
   auto alignSelf = aAlignSelf;
   bool overflowSafe = alignSelf & NS_STYLE_ALIGN_SAFE;
   alignSelf &= ~NS_STYLE_ALIGN_FLAG_BITS;
-  MOZ_ASSERT(alignSelf != NS_STYLE_ALIGN_LEFT &&
-             alignSelf != NS_STYLE_ALIGN_RIGHT,
-             "Grid's 'align-self' axis is never parallel to the container's "
-             "inline axis, so these should've computed to 'start' already");
+  // Grid's 'align-self' axis is never parallel to the container's inline axis.
+  if (alignSelf == NS_STYLE_ALIGN_LEFT || alignSelf == NS_STYLE_ALIGN_RIGHT) {
+    alignSelf = NS_STYLE_ALIGN_START;
+  }
   if (MOZ_UNLIKELY(alignSelf == NS_STYLE_ALIGN_AUTO)) {
     // Happens in rare edge cases when 'position' was ignored by the frame
     // constructor (and the style system computed 'auto' based on 'position').
     alignSelf = NS_STYLE_ALIGN_STRETCH;
   }
   WritingMode childWM = aRS.GetWritingMode();
   bool isOrthogonal = aCBWM.IsOrthogonalTo(childWM);
   // |sameSide| is true if the container's start side in this axis is the same
@@ -1092,19 +1092,20 @@ GetAlignJustifyValue(uint16_t aAlignment
 {
   *aOverflowSafe = aAlignment & NS_STYLE_ALIGN_SAFE;
   aAlignment &= (NS_STYLE_ALIGN_ALL_BITS & ~NS_STYLE_ALIGN_FLAG_BITS);
 
   // Map some alignment values to 'start' / 'end'.
   switch (aAlignment) {
     case NS_STYLE_ALIGN_LEFT:
     case NS_STYLE_ALIGN_RIGHT: {
-      MOZ_ASSERT(!aIsAlign, "Grid container's 'align-contents' axis is never "
-                 "parallel to its inline axis, so these should've computed to "
-                 "'start' already");
+      if (aIsAlign) {
+        // Grid's 'align-content' axis is never parallel to the inline axis.
+        return NS_STYLE_ALIGN_START;
+      }
       bool isStart = aWM.IsBidiLTR() == (aAlignment == NS_STYLE_ALIGN_LEFT);
       return isStart ? NS_STYLE_ALIGN_START : NS_STYLE_ALIGN_END;
     }
     case NS_STYLE_ALIGN_FLEX_START: // same as 'start' for Grid
       return NS_STYLE_ALIGN_START;
     case NS_STYLE_ALIGN_FLEX_END: // same as 'end' for Grid
       return NS_STYLE_ALIGN_END;
   }
@@ -2595,17 +2596,17 @@ nsGridContainerFrame::Tracks::AlignJusti
 {
   if (mSizes.IsEmpty()) {
     return;
   }
 
   const bool isAlign = mAxis == eLogicalAxisBlock;
   auto stylePos = aReflowState.mStylePosition;
   const auto valueAndFallback = isAlign ?
-    stylePos->ComputedAlignContent(aReflowState.mStyleDisplay) :
+    stylePos->ComputedAlignContent() :
     stylePos->ComputedJustifyContent(aReflowState.mStyleDisplay);
   WritingMode wm = aReflowState.GetWritingMode();
   bool overflowSafe;
   auto alignment = ::GetAlignJustifyValue(valueAndFallback, wm, isAlign,
                                           &overflowSafe);
   if (alignment == NS_STYLE_ALIGN_AUTO) {
     alignment = NS_STYLE_ALIGN_START;
   }
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -4017,17 +4017,17 @@ nsComputedDOMStyle::DoGetOrder()
   return val;
 }
 
 CSSValue*
 nsComputedDOMStyle::DoGetAlignContent()
 {
   nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
   nsAutoString str;
-  auto align = StylePosition()->ComputedAlignContent(StyleDisplay());
+  auto align = StylePosition()->ComputedAlignContent();
   nsCSSValue::AppendAlignJustifyValueToString(align & NS_STYLE_ALIGN_ALL_BITS, str);
   auto fallback = align >> NS_STYLE_ALIGN_ALL_SHIFT;
   if (fallback) {
     str.Append(' ');
     nsCSSValue::AppendAlignJustifyValueToString(fallback, str);
   }
   val->SetString(str);
   return val;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -8006,32 +8006,21 @@ nsRuleNode::ComputePositionData(void* aS
               parentPos->mBoxSizing,
               StyleBoxSizing::Content,
               StyleBoxSizing::Content /* ignored */,
               StyleBoxSizing::Content /* ignored */,
               StyleBoxSizing::Content /* ignored */,
               StyleBoxSizing::Content /* ignored */);
 
   // align-content: enum, inherit, initial
-  const auto& alignContentValue = *aRuleData->ValueForAlignContent();
-  if (MOZ_UNLIKELY(alignContentValue.GetUnit() == eCSSUnit_Inherit)) {
-    if (MOZ_LIKELY(parentContext)) {
-      pos->mAlignContent =
-        parentPos->ComputedAlignContent(parentContext->StyleDisplay());
-    } else {
-      pos->mAlignContent = NS_STYLE_ALIGN_AUTO;
-    }
-    conditions.SetUncacheable();
-  } else {
-    SetDiscrete(alignContentValue,
-                pos->mAlignContent, conditions,
-                SETDSC_ENUMERATED | SETDSC_UNSET_INITIAL,
-                parentPos->mAlignContent, // unused, we handle 'inherit' above
-                NS_STYLE_ALIGN_AUTO, 0, 0, 0, 0);
-  }
+  SetDiscrete(*aRuleData->ValueForAlignContent(),
+              pos->mAlignContent, conditions,
+              SETDSC_ENUMERATED | SETDSC_UNSET_INITIAL,
+              parentPos->mAlignContent,
+              NS_STYLE_ALIGN_AUTO, 0, 0, 0, 0);
 
   // align-items: enum, inherit, initial
   const auto& alignItemsValue = *aRuleData->ValueForAlignItems();
   if (MOZ_UNLIKELY(alignItemsValue.GetUnit() == eCSSUnit_Inherit)) {
     if (MOZ_LIKELY(parentContext)) {
       pos->mAlignItems =
         parentPos->ComputedAlignItems(parentContext->StyleDisplay());
     } else {
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1674,72 +1674,41 @@ nsStylePosition::WidthCoordDependsOnCont
 {
   return aCoord.HasPercent() ||
          (aCoord.GetUnit() == eStyleUnit_Enumerated &&
           (aCoord.GetIntValue() == NS_STYLE_WIDTH_FIT_CONTENT ||
            aCoord.GetIntValue() == NS_STYLE_WIDTH_AVAILABLE));
 }
 
 uint8_t
-nsStylePosition::MapLeftRightToStart(uint8_t aAlign, LogicalAxis aAxis,
-                                     const nsStyleDisplay* aDisplay) const
-{
-  auto val = aAlign & ~NS_STYLE_ALIGN_FLAG_BITS;
-  if (val == NS_STYLE_ALIGN_LEFT || val == NS_STYLE_ALIGN_RIGHT) {
-    switch (aDisplay->mDisplay) {
-    case NS_STYLE_DISPLAY_FLEX:
-    case NS_STYLE_DISPLAY_INLINE_FLEX:
-      // XXX TODO
-      // NOTE: make sure to strip off 'legacy' bit when mapping to 'start'
-      break;
-    default:
-      if (aAxis == eLogicalAxisBlock) {
-        return NS_STYLE_ALIGN_START | (aAlign & NS_STYLE_ALIGN_FLAG_BITS);
-      }
-    }
-  }
-  return aAlign;
-}
-
-uint16_t
-nsStylePosition::ComputedAlignContent(const nsStyleDisplay* aDisplay) const
-{
-  uint8_t val = mAlignContent & NS_STYLE_ALIGN_ALL_BITS;
-  val = MapLeftRightToStart(val, eLogicalAxisBlock, aDisplay);
-  uint8_t fallback = mAlignContent >> NS_STYLE_ALIGN_ALL_SHIFT;
-  fallback = MapLeftRightToStart(fallback, eLogicalAxisBlock, aDisplay);
-  return (uint16_t(fallback) << NS_STYLE_ALIGN_ALL_SHIFT) | uint16_t(val);
-}
-
-uint8_t
 nsStylePosition::ComputedAlignItems(const nsStyleDisplay* aDisplay) const
 {
   if (mAlignItems != NS_STYLE_ALIGN_AUTO) {
-    return MapLeftRightToStart(mAlignItems, eLogicalAxisBlock, aDisplay);
+    return mAlignItems;
   }
   return aDisplay->IsFlexOrGridDisplayType() ? NS_STYLE_ALIGN_STRETCH
                                              : NS_STYLE_ALIGN_START;
 }
 
 uint8_t
 nsStylePosition::ComputedAlignSelf(const nsStyleDisplay* aDisplay,
-                                   nsStyleContext* aParent) const
+                                   nsStyleContext*       aParent) const
 {
   if (mAlignSelf != NS_STYLE_ALIGN_AUTO) {
-    return MapLeftRightToStart(mAlignSelf, eLogicalAxisBlock, aDisplay);
+    return mAlignSelf;
   }
   if (MOZ_UNLIKELY(aDisplay->IsAbsolutelyPositionedStyle())) {
     return NS_STYLE_ALIGN_AUTO;
   }
   if (MOZ_LIKELY(aParent)) {
     auto parentAlignItems = aParent->StylePosition()->
       ComputedAlignItems(aParent->StyleDisplay());
     MOZ_ASSERT(!(parentAlignItems & NS_STYLE_ALIGN_LEGACY),
                "align-items can't have 'legacy'");
-    return MapLeftRightToStart(parentAlignItems, eLogicalAxisBlock, aDisplay);
+    return parentAlignItems;
   }
   return NS_STYLE_ALIGN_START;
 }
 
 uint16_t
 nsStylePosition::ComputedJustifyContent(const nsStyleDisplay* aDisplay) const
 {
   switch (aDisplay->mDisplay) {
@@ -1751,58 +1720,52 @@ nsStylePosition::ComputedJustifyContent(
       // XXX maybe map 'auto' too? (ISSUE 8 in the spec)
       // https://drafts.csswg.org/css-align-3/#content-distribution
       if ((mJustifyContent & NS_STYLE_ALIGN_ALL_BITS) ==
           NS_STYLE_JUSTIFY_STRETCH) {
         return NS_STYLE_JUSTIFY_FLEX_START;
       }
       break;
   }
-  uint8_t val = mJustifyContent & NS_STYLE_JUSTIFY_ALL_BITS;
-  val = MapLeftRightToStart(val, eLogicalAxisInline, aDisplay);
-  uint8_t fallback = mJustifyContent >> NS_STYLE_JUSTIFY_ALL_SHIFT;
-  fallback = MapLeftRightToStart(fallback, eLogicalAxisInline, aDisplay);
-  return (uint16_t(fallback) << NS_STYLE_JUSTIFY_ALL_SHIFT) | uint16_t(val);
+  return mJustifyContent;
 }
 
 uint8_t
 nsStylePosition::ComputedJustifyItems(const nsStyleDisplay* aDisplay,
-                                      nsStyleContext* aParent) const
+                                      nsStyleContext*       aParent) const
 {
   if (mJustifyItems != NS_STYLE_JUSTIFY_AUTO) {
-    return MapLeftRightToStart(mJustifyItems, eLogicalAxisInline, aDisplay);
+    return mJustifyItems;
   }
   if (MOZ_LIKELY(aParent)) {
     auto inheritedJustifyItems =
       aParent->StylePosition()->ComputedJustifyItems(aParent->StyleDisplay(),
                                                      aParent->GetParent());
     if (inheritedJustifyItems & NS_STYLE_JUSTIFY_LEGACY) {
       return inheritedJustifyItems;
     }
   }
   return aDisplay->IsFlexOrGridDisplayType() ? NS_STYLE_JUSTIFY_STRETCH
                                              : NS_STYLE_JUSTIFY_START;
 }
 
 uint8_t
 nsStylePosition::ComputedJustifySelf(const nsStyleDisplay* aDisplay,
-                                     nsStyleContext* aParent) const
+                                     nsStyleContext*       aParent) const
 {
   if (mJustifySelf != NS_STYLE_JUSTIFY_AUTO) {
-    return MapLeftRightToStart(mJustifySelf, eLogicalAxisInline, aDisplay);
+    return mJustifySelf;
   }
   if (MOZ_UNLIKELY(aDisplay->IsAbsolutelyPositionedStyle())) {
     return NS_STYLE_JUSTIFY_AUTO;
   }
   if (MOZ_LIKELY(aParent)) {
     auto inheritedJustifyItems = aParent->StylePosition()->
       ComputedJustifyItems(aParent->StyleDisplay(), aParent->GetParent());
-    inheritedJustifyItems &= ~NS_STYLE_JUSTIFY_LEGACY;
-    return MapLeftRightToStart(inheritedJustifyItems, eLogicalAxisInline,
-                               aDisplay);
+    return inheritedJustifyItems & ~NS_STYLE_JUSTIFY_LEGACY;
   }
   return NS_STYLE_JUSTIFY_START;
 }
 
 // --------------------
 // nsStyleTable
 //
 
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -1402,20 +1402,19 @@ struct nsStylePosition {
     return nsChangeHint(0);
   }
 
   // XXXdholbert nsStyleBackground::Position should probably be moved to a
   // different scope, since we're now using it in multiple style structs.
   typedef nsStyleBackground::Position Position;
 
   /**
-   * Return the computed value for 'align-content' given our 'display' value in
-   * aDisplay.
+   * Return the computed value for 'align-content'.
    */
-  uint16_t ComputedAlignContent(const nsStyleDisplay* aDisplay) const;
+  uint16_t ComputedAlignContent() const { return mAlignContent; }
 
   /**
    * Return the computed value for 'align-items' given our 'display' value in
    * aDisplay.
    */
   uint8_t ComputedAlignItems(const nsStyleDisplay* aDisplay) const;
 
   /**
@@ -1457,19 +1456,16 @@ struct nsStylePosition {
   nsStyleCoord  mGridAutoColumnsMin;    // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoColumnsMax;    // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoRowsMin;       // [reset] coord, percent, enum, calc, flex
   nsStyleCoord  mGridAutoRowsMax;       // [reset] coord, percent, enum, calc, flex
   uint8_t       mGridAutoFlow;          // [reset] enumerated. See nsStyleConsts.h
   mozilla::StyleBoxSizing mBoxSizing;   // [reset] see nsStyleConsts.h
 private:
   friend class nsRuleNode;
-  // Helper for the ComputedAlign/Justify* methods.
-  uint8_t MapLeftRightToStart(uint8_t aAlign, mozilla::LogicalAxis aAxis,
-                              const nsStyleDisplay* aDisplay) const;
 
   uint16_t      mAlignContent;          // [reset] fallback value in the high byte
   uint8_t       mAlignItems;            // [reset] see nsStyleConsts.h
   uint8_t       mAlignSelf;             // [reset] see nsStyleConsts.h
   uint16_t      mJustifyContent;        // [reset] fallback value in the high byte
   uint8_t       mJustifyItems;          // [reset] see nsStyleConsts.h
   uint8_t       mJustifySelf;           // [reset] see nsStyleConsts.h
 public: