Bug 1032922 part 1: Give "flex-basis" its own keyword table, instead of having it co-opt kWidthKTable. r=heycam

This commit is contained in:
Daniel Holbert 2014-08-07 22:11:47 -07:00
parent 39bd7337db
commit cb313ca766
7 changed files with 97 additions and 4 deletions

View File

@ -7451,7 +7451,7 @@ CSSParserImpl::ParseFlex()
// "a unitless zero that is not already preceded by two flex factors must be
// interpreted as a flex factor.
if (!ParseNonNegativeVariant(tmpVal, flexBasisVariantMask | VARIANT_NUMBER,
nsCSSProps::kWidthKTable)) {
nsCSSProps::kFlexBasisKTable)) {
// First component was not a valid flex-basis or flex-grow value. Fail.
return false;
}
@ -7499,7 +7499,7 @@ CSSParserImpl::ParseFlex()
// unitless 0 encountered here *must* have been preceded by 2 flex factors.
if (!wasFirstComponentFlexBasis &&
ParseNonNegativeVariant(tmpVal, flexBasisVariantMask,
nsCSSProps::kWidthKTable)) {
nsCSSProps::kFlexBasisKTable)) {
flexBasis = tmpVal;
}
}

View File

@ -1657,7 +1657,7 @@ CSS_PROP_POSITION(
// its own code to parse each subproperty. It does not depend on the
// longhand parsing defined here.
VARIANT_AHKLP | VARIANT_CALC,
kWidthKTable,
kFlexBasisKTable,
offsetof(nsStylePosition, mFlexBasis),
eStyleAnimType_Coord)
CSS_PROP_POSITION(

View File

@ -1125,6 +1125,14 @@ const KTableValue nsCSSProps::kAlignSelfKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const KTableValue nsCSSProps::kFlexBasisKTable[] = {
eCSSKeyword__moz_max_content, NS_STYLE_WIDTH_MAX_CONTENT,
eCSSKeyword__moz_min_content, NS_STYLE_WIDTH_MIN_CONTENT,
eCSSKeyword__moz_fit_content, NS_STYLE_WIDTH_FIT_CONTENT,
eCSSKeyword__moz_available, NS_STYLE_WIDTH_AVAILABLE,
eCSSKeyword_UNKNOWN,-1
};
const KTableValue nsCSSProps::kFlexDirectionKTable[] = {
eCSSKeyword_row, NS_STYLE_FLEX_DIRECTION_ROW,
eCSSKeyword_row_reverse, NS_STYLE_FLEX_DIRECTION_ROW_REVERSE,

View File

@ -566,6 +566,7 @@ public:
static const KTableValue kAlignContentKTable[];
static const KTableValue kAlignItemsKTable[];
static const KTableValue kAlignSelfKTable[];
static const KTableValue kFlexBasisKTable[];
static const KTableValue kFlexDirectionKTable[];
static const KTableValue kFlexWrapKTable[];
static const KTableValue kJustifyContentKTable[];

View File

@ -3649,7 +3649,7 @@ nsComputedDOMStyle::DoGetFlexBasis()
// }
SetValueToCoord(val, StylePosition()->mFlexBasis, true,
nullptr, nsCSSProps::kWidthKTable);
nullptr, nsCSSProps::kFlexBasisKTable);
return val;
}

View File

@ -124,6 +124,7 @@ skip-if = toolkit == 'android' #bug 536603
[test_extra_inherit_initial.html]
[test_flexbox_align_self_auto.html]
[test_flexbox_child_display_values.xhtml]
[test_flexbox_flex_basis_values.html]
[test_flexbox_flex_grow_and_shrink.html]
[test_flexbox_flex_shorthand.html]
[test_flexbox_layout.html]

View File

@ -0,0 +1,83 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1032922
-->
<head>
<meta charset="utf-8">
<title>
Test that 'flex-basis' accepts all valid values for 'width' and 'height'
(helper for Bug 1032922)
</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="property_database.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<div id="testnode"></div>
</div>
<pre id="test">
<script type="text/javascript;version=1.7">
"use strict";
/**
* Test that 'flex-basis' accepts all valid values for 'width' and 'height'
* (helper for Bug 1032922)
*
* PEDANTIC NOTE: Technically, the flexbox spec's "value" definition for
* "flex-basis" only says it accepts "main-size | <'width'>" -- there's no
* mention of <'height'>.
*
* However, the prose later on is clear that all valid "height" values are
* supposed to be accepted as well:
* # The flex-basis property [...] accepts the same values
* # as the 'width' and 'height' property.
* http://dev.w3.org/csswg/css-flexbox/#propdef-flex-basis
*
* Presumably the spec's value-definition omits <'height'> just for brevity's
* sake, since <'width'> already covers the full range of valid "height"
* values (for now at least; and probably forever).
*
* In any case: in this test, we ensure that flex-basis really does accept all
* of property_database's valid sample-values for both "width" *and* "height",
* to be on the safe side.
*/
function check_accepted(decl, origPropName, val)
{
decl.setProperty("flex-basis", val, "");
// Note: decl.getPropertyValue() will return something non-empty here if the
// value was parsed successfully. Otherwise (i.e. if the value is rejected),
// it'll return the empty string.
isnot(decl.getPropertyValue("flex-basis"), "",
"value '" + val + "' which is valid for '" + origPropName +
"' should also be valid for 'flex-basis' ");
decl.removeProperty("flex-basis");
}
function main()
{
let decl = document.getElementById("testnode").style;
let props = [ "width", "height" ];
props.forEach(function(prop) {
let info = gCSSProperties[prop];
let all_values = info.initial_values.concat(info.other_values);
all_values.forEach(function(value) {
check_accepted(decl, prop, value);
});
});
}
main();
</script>
</pre>
</body>
</html>