Bug 1170173 - Parse CSS 'contain' property. r=dholbert

This commit is contained in:
Kyle Zentner 2015-06-04 16:38:00 +02:00
parent 091382662c
commit 030592649e
17 changed files with 162 additions and 1 deletions

View File

@ -25,7 +25,7 @@ let testData = [
["VK_TAB", {shiftKey: true}, "display", -1, 0],
["VK_BACK_SPACE", {}, "", -1, 0],
["c", {}, "caption-side", 0, 10],
["o", {}, "color", 0, 6],
["o", {}, "color", 0, 7],
["VK_TAB", {}, "none", -1, 0],
["r", {}, "rebeccapurple", 0, 6],
["VK_DOWN", {}, "red", 1, 6],

View File

@ -330,6 +330,7 @@ CSS_KEY(korean-hanja-informal, korean_hanja_informal)
CSS_KEY(landscape, landscape)
CSS_KEY(large, large)
CSS_KEY(larger, larger)
CSS_KEY(layout, layout)
CSS_KEY(left, left)
CSS_KEY(lighten, lighten)
CSS_KEY(lighter, lighter)
@ -399,6 +400,7 @@ CSS_KEY(outside, outside)
CSS_KEY(over, over)
CSS_KEY(overlay, overlay)
CSS_KEY(overline, overline)
CSS_KEY(paint, paint)
CSS_KEY(padding-box, padding_box)
CSS_KEY(painted, painted)
CSS_KEY(pan-x, pan_x)
@ -509,6 +511,7 @@ CSS_KEY(sticky, sticky)
CSS_KEY(stretch, stretch)
CSS_KEY(stretch-to-fit, stretch_to_fit)
CSS_KEY(stretched, stretched)
CSS_KEY(strict, strict)
CSS_KEY(stroke, stroke)
CSS_KEY(stroke-box, stroke_box)
CSS_KEY(style, style)

View File

@ -887,6 +887,7 @@ protected:
// for 'clip' and '-moz-image-region'
bool ParseRect(nsCSSProperty aPropID);
bool ParseColumns();
bool ParseContain(nsCSSValue& aValue);
bool ParseContent();
bool ParseCounterData(nsCSSProperty aPropID);
bool ParseCursor();
@ -10290,6 +10291,8 @@ CSSParserImpl::ParseSingleValueProperty(nsCSSValue& aValue,
return ParseTextOverflow(aValue);
case eCSSProperty_touch_action:
return ParseTouchAction(aValue);
case eCSSProperty_contain:
return ParseContain(aValue);
default:
MOZ_ASSERT(false, "should not reach here");
return false;
@ -12397,6 +12400,29 @@ CSSParserImpl::ParseFontVariantEastAsian(nsCSSValue& aValue)
maskEastAsian);
}
bool
CSSParserImpl::ParseContain(nsCSSValue& aValue)
{
if (ParseVariant(aValue, VARIANT_INHERIT | VARIANT_NONE, nullptr)) {
return true;
}
static const int32_t maskContain[] = { MASK_END_VALUE };
if (!ParseBitmaskValues(aValue, nsCSSProps::kContainKTable, maskContain)) {
return false;
}
if (aValue.GetIntValue() & NS_STYLE_CONTAIN_STRICT) {
if (aValue.GetIntValue() != NS_STYLE_CONTAIN_STRICT) {
// Disallow any other keywords in combination with 'strict'.
return false;
}
// Strict implies layout, style, and paint.
// However, for serialization purposes, we keep the strict bit around.
aValue.SetIntValue(NS_STYLE_CONTAIN_STRICT |
NS_STYLE_CONTAIN_ALL_BITS, eCSSUnit_Enumerated);
}
return true;
}
static const int32_t maskLigatures[] = {
NS_FONT_VARIANT_LIGATURES_COMMON_MASK,
NS_FONT_VARIANT_LIGATURES_DISCRETIONARY_MASK,

View File

@ -1487,6 +1487,18 @@ CSS_PROP_COLUMN(
kBorderWidthKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_Custom)
CSS_PROP_DISPLAY(
contain,
contain,
Contain,
CSS_PROPERTY_PARSE_VALUE |
CSS_PROPERTY_VALUE_PARSER_FUNCTION,
"layout.css.contain.enabled",
// Does not affect parsing, but is needed for tab completion in devtools:
VARIANT_HK | VARIANT_NONE,
kContainKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
CSS_PROP_CONTENT(
content,
content,

View File

@ -1469,6 +1469,15 @@ const KTableValue nsCSSProps::kMathDisplayKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const KTableValue nsCSSProps::kContainKTable[] = {
eCSSKeyword_none, NS_STYLE_CONTAIN_NONE,
eCSSKeyword_strict, NS_STYLE_CONTAIN_STRICT,
eCSSKeyword_layout, NS_STYLE_CONTAIN_LAYOUT,
eCSSKeyword_style, NS_STYLE_CONTAIN_STYLE,
eCSSKeyword_paint, NS_STYLE_CONTAIN_PAINT,
eCSSKeyword_UNKNOWN,-1
};
const KTableValue nsCSSProps::kContextOpacityKTable[] = {
eCSSKeyword_context_fill_opacity, NS_STYLE_CONTEXT_FILL_OPACITY,
eCSSKeyword_context_stroke_opacity, NS_STYLE_CONTEXT_STROKE_OPACITY,

View File

@ -648,6 +648,7 @@ public:
static const KTableValue kMaskTypeKTable[];
static const KTableValue kMathVariantKTable[];
static const KTableValue kMathDisplayKTable[];
static const KTableValue kContainKTable[];
static const KTableValue kContextOpacityKTable[];
static const KTableValue kContextPatternKTable[];
static const KTableValue kObjectFitKTable[];

View File

@ -1292,6 +1292,20 @@ nsCSSValue::AppendToString(nsCSSProperty aProperty, nsAString& aResult,
aResult);
break;
case eCSSProperty_contain:
if (intValue & NS_STYLE_CONTAIN_STRICT) {
NS_ASSERTION(intValue == (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS),
"contain: strict should imply contain: layout style paint");
// Only output strict.
intValue = NS_STYLE_CONTAIN_STRICT;
}
nsStyleUtil::AppendBitmaskCSSValue(aProperty,
intValue,
NS_STYLE_CONTAIN_STRICT,
NS_STYLE_CONTAIN_PAINT,
aResult);
break;
default:
const nsAFlatCString& name = nsCSSProps::LookupPropertyValue(aProperty, intValue);
AppendASCIItoUTF16(name, aResult);

View File

@ -4005,6 +4005,31 @@ nsComputedDOMStyle::DoGetDisplay()
return val;
}
CSSValue*
nsComputedDOMStyle::DoGetContain()
{
nsROCSSPrimitiveValue* val = new nsROCSSPrimitiveValue;
int32_t mask = StyleDisplay()->mContain;
if (mask == 0) {
val->SetIdent(eCSSKeyword_none);
} else if (mask & NS_STYLE_CONTAIN_STRICT) {
NS_ASSERTION(mask == (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS),
"contain: strict should imply contain: layout style paint");
val->SetIdent(eCSSKeyword_strict);
} else {
nsAutoString valueStr;
nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_contain,
mask, NS_STYLE_CONTAIN_LAYOUT,
NS_STYLE_CONTAIN_PAINT, valueStr);
val->SetString(valueStr);
}
return val;
}
CSSValue*
nsComputedDOMStyle::DoGetPosition()
{

View File

@ -392,6 +392,7 @@ private:
mozilla::dom::CSSValue* DoGetClear();
mozilla::dom::CSSValue* DoGetFloat();
mozilla::dom::CSSValue* DoGetDisplay();
mozilla::dom::CSSValue* DoGetContain();
mozilla::dom::CSSValue* DoGetPosition();
mozilla::dom::CSSValue* DoGetClip();
mozilla::dom::CSSValue* DoGetImageOrientation();

View File

@ -102,6 +102,7 @@ COMPUTED_STYLE_PROP(caption_side, CaptionSide)
COMPUTED_STYLE_PROP(clear, Clear)
COMPUTED_STYLE_PROP(clip, Clip)
COMPUTED_STYLE_PROP(color, Color)
COMPUTED_STYLE_PROP(contain, Contain)
COMPUTED_STYLE_PROP(content, Content)
COMPUTED_STYLE_PROP(counter_increment, CounterIncrement)
COMPUTED_STYLE_PROP(counter_reset, CounterReset)

View File

@ -5266,6 +5266,12 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
parentDisplay->mDisplay,
NS_STYLE_DISPLAY_INLINE, 0, 0, 0, 0);
// contain: none, enum, inherit, initial
SetDiscrete(*aRuleData->ValueForContain(), display->mContain, canStoreInRuleTree,
SETDSC_ENUMERATED | SETDSC_NONE | SETDSC_UNSET_INITIAL,
parentDisplay->mContain,
NS_STYLE_CONTAIN_NONE, 0, NS_STYLE_CONTAIN_NONE, 0, 0);
// mix-blend-mode: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForMixBlendMode(), display->mMixBlendMode,
canStoreInRuleTree,

View File

@ -444,6 +444,19 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_DISPLAY_RUBY_TEXT_CONTAINER 37
#define NS_STYLE_DISPLAY_CONTENTS 38
// See nsStyleDisplay
// If these are re-ordered, nsComputedDOMStyle::DoGetContain() and
// nsCSSValue::AppendToString() must be updated.
#define NS_STYLE_CONTAIN_NONE 0
#define NS_STYLE_CONTAIN_STRICT 0x1
#define NS_STYLE_CONTAIN_LAYOUT 0x2
#define NS_STYLE_CONTAIN_STYLE 0x4
#define NS_STYLE_CONTAIN_PAINT 0x8
// NS_STYLE_CONTAIN_ALL_BITS does not correspond to a keyword.
#define NS_STYLE_CONTAIN_ALL_BITS (NS_STYLE_CONTAIN_LAYOUT | \
NS_STYLE_CONTAIN_STYLE | \
NS_STYLE_CONTAIN_PAINT)
// See nsStylePosition
#define NS_STYLE_ALIGN_CONTENT_FLEX_START 0
#define NS_STYLE_ALIGN_CONTENT_FLEX_END 1

View File

@ -2582,6 +2582,7 @@ nsStyleDisplay::nsStyleDisplay()
mAppearance = NS_THEME_NONE;
mDisplay = NS_STYLE_DISPLAY_INLINE;
mOriginalDisplay = mDisplay;
mContain = NS_STYLE_CONTAIN_NONE;
mPosition = NS_STYLE_POSITION_STATIC;
mFloats = NS_STYLE_FLOAT_NONE;
mOriginalFloats = mFloats;
@ -2647,6 +2648,7 @@ nsStyleDisplay::nsStyleDisplay(const nsStyleDisplay& aSource)
, mOpacity(aSource.mOpacity)
, mDisplay(aSource.mDisplay)
, mOriginalDisplay(aSource.mOriginalDisplay)
, mContain(aSource.mContain)
, mAppearance(aSource.mAppearance)
, mPosition(aSource.mPosition)
, mFloats(aSource.mFloats)
@ -2710,6 +2712,7 @@ nsChangeHint nsStyleDisplay::CalcDifference(const nsStyleDisplay& aOther) const
if (!EqualURIs(mBinding, aOther.mBinding)
|| mPosition != aOther.mPosition
|| mDisplay != aOther.mDisplay
|| mContain != aOther.mContain
|| (mFloats == NS_STYLE_FLOAT_NONE) != (aOther.mFloats == NS_STYLE_FLOAT_NONE)
|| mOverflowX != aOther.mOverflowX
|| mOverflowY != aOther.mOverflowY

View File

@ -2069,6 +2069,7 @@ struct nsStyleDisplay {
uint8_t mOriginalDisplay; // [reset] saved mDisplay for position:absolute/fixed
// and float:left/right; otherwise equal
// to mDisplay
uint8_t mContain; // [reset] see nsStyleConsts.h NS_STYLE_CONTAIN_*
uint8_t mAppearance; // [reset]
uint8_t mPosition; // [reset] see nsStyleConsts.h
uint8_t mFloats; // [reset] see nsStyleConsts.h NS_STYLE_FLOAT_*

View File

@ -6159,6 +6159,46 @@ if (SpecialPowers.getBoolPref("layout.css.display-contents.enabled")) {
gCSSProperties["display"].other_values.push("contents");
}
if (SpecialPowers.getBoolPref("layout.css.contain.enabled")) {
gCSSProperties["contain"] = {
domProp: "contain",
inherited: false,
type: CSS_TYPE_LONGHAND,
initial_values: [ "none" ],
other_values: [
"strict",
"layout",
"style",
"layout style",
"style layout",
"paint",
"layout paint",
"paint layout",
"style paint",
"paint style",
"layout style paint",
"layout paint style",
"style paint layout",
"paint style layout",
],
invalid_values: [
"none strict",
"strict layout",
"strict layout style",
"layout strict",
"layout style strict",
"layout style paint strict",
"paint strict",
"style strict",
"paint paint",
"strict strict",
"auto",
"10px",
"0",
]
};
}
if (SpecialPowers.getBoolPref("layout.css.image-orientation.enabled")) {
gCSSProperties["image-orientation"] = {
domProp: "imageOrientation",

View File

@ -2259,6 +2259,9 @@ pref("layout.css.overflow-clip-box.enabled", false);
// Is support for CSS grid enabled?
pref("layout.css.grid.enabled", false);
// Is support for CSS contain enabled?
pref("layout.css.contain.enabled", false);
// Is support for CSS Ruby enabled?
//
// When this pref is removed, make sure that the pref callback registration

View File

@ -148,6 +148,9 @@ user_pref("layout.css.report_errors", true);
// Enable CSS Grid for testing
user_pref("layout.css.grid.enabled", true);
// Enable CSS 'contain' for testing
user_pref("layout.css.contain.enabled", true);
// Enable CSS object-fit & object-position for testing
user_pref("layout.css.object-fit-and-position.enabled", true);