diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp
index a1d6cc41da9..d22d63beff6 100644
--- a/layout/generic/nsHTMLReflowState.cpp
+++ b/layout/generic/nsHTMLReflowState.cpp
@@ -2597,8 +2597,16 @@ nsHTMLReflowState::ComputeMinMaxValues(nscoord aContainingBlockWidth,
{
// Handle "min-width: auto"
if (eStyleUnit_Auto == mStylePosition->mMinWidth.GetUnit()) {
- // XXXdholbert For flex items, this needs to behave like -moz-min-content.
- ComputedMinWidth() = 0;
+ nsFlexContainerFrame* flexContainerFrame = GetFlexContainer(frame);
+ if (flexContainerFrame && flexContainerFrame->IsHorizontal()) {
+ ComputedMinWidth() =
+ ComputeWidthValue(aContainingBlockWidth,
+ mStylePosition->mBoxSizing,
+ nsStyleCoord(NS_STYLE_WIDTH_MIN_CONTENT,
+ eStyleUnit_Enumerated));
+ } else {
+ ComputedMinWidth() = 0;
+ }
} else {
ComputedMinWidth() = ComputeWidthValue(aContainingBlockWidth,
mStylePosition->mBoxSizing,
diff --git a/layout/style/nsComputedDOMStyle.cpp b/layout/style/nsComputedDOMStyle.cpp
index 6d9e4bb7b36..d4c5f7a4112 100644
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -14,6 +14,8 @@
#include "nsError.h"
#include "nsDOMString.h"
#include "nsIDOMCSSPrimitiveValue.h"
+#include "nsIFrame.h"
+#include "nsIFrameInlines.h"
#include "nsStyleContext.h"
#include "nsIScrollableFrame.h"
#include "nsContentUtils.h"
@@ -22,6 +24,7 @@
#include "nsDOMCSSRect.h"
#include "nsDOMCSSRGBColor.h"
#include "nsDOMCSSValueList.h"
+#include "nsFlexContainerFrame.h"
#include "nsGkAtoms.h"
#include "nsHTMLReflowState.h"
#include "nsStyleUtil.h"
@@ -4126,12 +4129,20 @@ nsComputedDOMStyle::DoGetMinWidth()
nsStyleCoord minWidth = StylePosition()->mMinWidth;
if (eStyleUnit_Auto == minWidth.GetUnit()) {
- // In non-flexbox contexts, "min-width: auto" means "min-width: 0".
- // XXXdholbert For flex items, we should set |minWidth| to the
- // -moz-min-content keyword, instead of 0.
+ // "min-width: auto" means "0", unless we're a flex item in a horizontal
+ // flex container, in which case it means "min-content"
minWidth.SetCoordValue(0);
- }
+ if (mOuterFrame && mOuterFrame->IsFlexItem()) {
+ nsIFrame* flexContainer = mOuterFrame->GetParent();
+ MOZ_ASSERT(flexContainer &&
+ flexContainer->GetType() == nsGkAtoms::flexContainerFrame,
+ "IsFlexItem() lied...?");
+ if (static_cast(flexContainer)->IsHorizontal()) {
+ minWidth.SetIntValue(NS_STYLE_WIDTH_MIN_CONTENT, eStyleUnit_Enumerated);
+ }
+ }
+ }
SetValueToCoord(val, minWidth, true,
&nsComputedDOMStyle::GetCBContentWidth,
nsCSSProps::kWidthKTable);