Bug 1477856: In flexbox devtools API, report max-width:none as +infinity. r=bradwerth

Previously we were just directly converting this nscoord sentinel-value representation (NS_UNCONSTRAINEDSIZE) into CSS pixels and producing a particular bogus number of pixels.

Differential Revision: https://phabricator.services.mozilla.com/D2432
This commit is contained in:
Daniel Holbert
2018-07-27 21:38:46 +00:00
parent 31d9ca4434
commit 7b1c036ad3
2 changed files with 30 additions and 4 deletions

View File

@@ -20,6 +20,24 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItem)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
/**
* Utility function to convert a nscoord size to CSS pixel values, with
* graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to
* the double "positive infinity" value).
*
* This function is suitable for converting quantities that are expected to
* sometimes legitimately (rather than arbitrarily/accidentally) contain the
* sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none".
*/
static double
ToPossiblyUnconstrainedPixels(nscoord aSize)
{
if (aSize == NS_UNCONSTRAINEDSIZE) {
return std::numeric_limits<double>::infinity();
}
return nsPresContext::AppUnitsToDoubleCSSPixels(aSize);
}
FlexItem::FlexItem(FlexLine* aParent,
const ComputedFlexItemInfo* aItem)
: mParent(aParent)
@@ -38,12 +56,10 @@ FlexItem::FlexItem(FlexLine* aParent,
aItem->mMainDeltaSize);
mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(
aItem->mMainMinSize);
mMainMaxSize = nsPresContext::AppUnitsToDoubleCSSPixels(
aItem->mMainMaxSize);
mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize);
mCrossMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(
aItem->mCrossMinSize);
mCrossMaxSize = nsPresContext::AppUnitsToDoubleCSSPixels(
aItem->mCrossMaxSize);
mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize);
}
JSObject*

View File

@@ -66,6 +66,12 @@ function testItemMatchesExpectedValues(item, values, index) {
if (typeof(values.mainMaxSize) != "undefined") {
is(item.mainMaxSize, values.mainMaxSize, "Item index " + index + " has expected mainMaxSize.");
} else {
// If we didn't specify an expected mainMaxSize, then it's implied
// that the max main-size property (max-width/max-height) is at its
// default "none" value, which our FlexItem API represents as +infinity.
is(item.mainMaxSize, Number.POSITIVE_INFINITY,
"Item index " + index + " has expected (default) mainMaxSize.");
}
if (typeof(values.crossMinSize) != "undefined") {
@@ -74,6 +80,10 @@ function testItemMatchesExpectedValues(item, values, index) {
if (typeof(values.crossMaxSize) != "undefined") {
is(item.crossMaxSize, values.crossMaxSize, "Item index " + index + " has expected crossMaxSize.");
} else {
// As above for mainMaxSize, no-expected-value implies we expect +infinity.
is(item.crossMaxSize, Number.POSITIVE_INFINITY,
"Item index " + index + " has expected (default) crossMaxSize.");
}
}