Bug 1304636 Part 1: Make GetComputedStyle report 'auto' for min-width:auto flex/grid items.
MozReview-Commit-ID: 3snktoHTohq
--- 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)
+{
+ // A {flex,grid} item's min-{width|height} "auto" value gets special
+ // treatment 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|height}: auto" is mapped to "0px", unless
+ // we're a flex item (and the min-size is in the flex container's main
+ // axis), or we're a grid item, AND we also have overflow:visible.
+
+ // Note: We only need to bother checking one "overflow" subproperty for
+ // "visible", because a non-"visible" value in either axis would force the
+ // other axis to also be non-"visible" as well.
+
+ if (mOuterFrame) {
+ nsIFrame* containerFrame = mOuterFrame->GetParent();
+ if (containerFrame &&
+ StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) {
+ auto containerType = containerFrame->GetType();
+ if (containerType == nsGkAtoms::flexContainerFrame &&
+ (static_cast<nsFlexContainerFrame*>(containerFrame)->IsHorizontal() ==
+ (aAxis == eAxisHorizontal))) {
+ return true;
+ }
+ if (containerType == nsGkAtoms::gridContainerFrame) {
+ 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
@@ -18,16 +18,17 @@
#include "nsDOMCSSDeclaration.h"
#include "nsStyleContext.h"
#include "nsIWeakReferenceUtils.h"
#include "mozilla/gfx/Types.h"
#include "nsCoord.h"
#include "nsColor.h"
#include "nsIContent.h"
#include "nsStyleStruct.h"
+#include "mozilla/WritingModes.h"
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
struct ComputedGridTrackInfo;
} // namespace mozilla
@@ -211,16 +212,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(mozilla::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 */