Bug 1304636 Part 1: Make GetComputedStyle report 'auto' for min-width:auto items. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 17 Nov 2016 15:38:57 -0800
changeset 440678 9ecd59c57ee8bf632c3d3be84558f264f1771d12
parent 440454 05e5b12f41df270b31955ff7e6d09245c1f83a7a
child 440679 25eda2940a993cf97ac7c66499301562d465c752
push id36295
push userbwerth@mozilla.com
push dateFri, 18 Nov 2016 00:24:00 +0000
bugs1304636
milestone53.0a1
Bug 1304636 Part 1: Make GetComputedStyle report 'auto' for min-width:auto items. MozReview-Commit-ID: 3snktoHTohq
layout/style/nsComputedDOMStyle.cpp
layout/style/nsComputedDOMStyle.h
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -4875,16 +4875,49 @@ already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetMaxWidth()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   SetValueToCoord(val, StylePosition()->mMaxWidth, true,
                   nullptr, nsCSSProps::kWidthKTable);
   return val.forget();
 }
 
+bool
+nsComputedDOMStyle::ShouldHonorMinSizeAutoInAxis(PhysicalAxis aAxis)
+{
+  // Bug 1304636 - A {flex,grid} item's min-{width,height} "auto" value
+  // should be reported as "auto" in getComputedStyle().
+  // https://drafts.csswg.org/css-flexbox-1/#valdef-min-width-auto
+  // https://drafts.csswg.org/css-grid/#min-size-auto
+  // In most cases, "min-width: auto" is mapped to "0px", unless we're a
+  // flex item or a grid item with visible overflow in the horizontal axis,
+  // in which case it remains "auto".
+
+  if (mOuterFrame) {
+    nsIFrame* containerFrame = mOuterFrame->GetParent();
+    if (containerFrame) {
+      auto containerType = containerFrame->GetType();
+      if (containerType == nsGkAtoms::flexContainerFrame &&
+          (static_cast<nsFlexContainerFrame*>(containerFrame)->IsHorizontal() ==
+           (aAxis == eAxisHorizontal)) &&
+          (aAxis == eAxisHorizontal ?
+            StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE :
+            StyleDisplay()->mOverflowY == NS_STYLE_OVERFLOW_VISIBLE)) {
+        return true;
+      } else if (containerType == nsGkAtoms::gridContainerFrame &&
+                 (aAxis == eAxisHorizontal ?
+                   StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE :
+                   StyleDisplay()->mOverflowY == NS_STYLE_OVERFLOW_VISIBLE)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetMinHeight()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
   nsStyleCoord minHeight = StylePosition()->mMinHeight;
 
   if (eStyleUnit_Auto == minHeight.GetUnit()) {
     // In non-flexbox contexts, "min-height: auto" means "min-height: 0"
@@ -4900,30 +4933,19 @@ nsComputedDOMStyle::DoGetMinHeight()
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetMinWidth()
 {
   RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
 
   nsStyleCoord minWidth = StylePosition()->mMinWidth;
 
-  if (eStyleUnit_Auto == minWidth.GetUnit()) {
-    // "min-width: auto" means "0", unless we're a flex item in a horizontal
-    // flex container, in which case it means "min-content"
+  if (eStyleUnit_Auto == minWidth.GetUnit() &&
+      !ShouldHonorMinSizeAutoInAxis(eAxisHorizontal)) {
     minWidth.SetCoordValue(0);
-    if (mOuterFrame && mOuterFrame->IsFlexItem()) {
-      nsIFrame* flexContainer = mOuterFrame->GetParent();
-      MOZ_ASSERT(flexContainer &&
-                 flexContainer->GetType() == nsGkAtoms::flexContainerFrame,
-                 "IsFlexItem() lied...?");
-
-      if (static_cast<nsFlexContainerFrame*>(flexContainer)->IsHorizontal()) {
-        minWidth.SetIntValue(NS_STYLE_WIDTH_MIN_CONTENT, eStyleUnit_Enumerated);
-      }
-    }
   }
 
   SetValueToCoord(val, minWidth, true, nullptr, nsCSSProps::kWidthKTable);
   return val.forget();
 }
 
 already_AddRefed<CSSValue>
 nsComputedDOMStyle::DoGetMixBlendMode()
--- a/layout/style/nsComputedDOMStyle.h
+++ b/layout/style/nsComputedDOMStyle.h
@@ -211,16 +211,18 @@ private:
                             nsAString& aString);
   void GetImageRectString(nsIURI* aURI,
                           const nsStyleSides& aCropRect,
                           nsString& aString);
   already_AddRefed<CSSValue> GetScrollSnapPoints(const nsStyleCoord& aCoord);
   void AppendTimingFunction(nsDOMCSSValueList *aValueList,
                             const nsTimingFunction& aTimingFunction);
 
+  bool ShouldHonorMinSizeAutoInAxis(PhysicalAxis aAxis);
+
   /* Properties queryable as CSSValues.
    * To avoid a name conflict with nsIDOM*CSS2Properties, these are all
    * DoGetXXX instead of GetXXX.
    */
 
   already_AddRefed<CSSValue> DoGetAppearance();
 
   /* Box properties */