Bug 1170781 - Patch 1: Implement CSS 'contain: paint'. r=dholbert

This commit is contained in:
Kyle Zentner 2015-11-09 13:32:00 +01:00
parent 550385997f
commit a6d63fb33b
5 changed files with 42 additions and 7 deletions

View File

@ -6759,8 +6759,11 @@ nsBlockFrame::Init(nsIContent* aContent,
// If the box is a block container, then it establishes a new block
// formatting context.
// (http://dev.w3.org/csswg/css-writing-modes/#block-flow)
if (GetParent() && StyleVisibility()->mWritingMode !=
GetParent()->StyleVisibility()->mWritingMode) {
// If the box has contain: paint (or contain: strict), then it should also
// establish a formatting context.
if ((GetParent() && StyleVisibility()->mWritingMode !=
GetParent()->StyleVisibility()->mWritingMode) ||
StyleDisplay()->IsContainPaint()) {
AddStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
}

View File

@ -5705,6 +5705,21 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
display->mOverflowY = NS_STYLE_OVERFLOW_AUTO;
}
// When 'contain: paint', update overflow from 'visible' to 'clip'.
if (display->IsContainPaint()) {
// XXX This actually sets overflow-[x|y] to -moz-hidden-unscrollable.
if (display->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) {
// This uncacheability (and the one below) could be fixed by adding
// mOriginalOverflowX and mOriginalOverflowY fields, if necessary.
display->mOverflowX = NS_STYLE_OVERFLOW_CLIP;
conditions.SetUncacheable();
}
if (display->mOverflowY == NS_STYLE_OVERFLOW_VISIBLE) {
display->mOverflowY = NS_STYLE_OVERFLOW_CLIP;
conditions.SetUncacheable();
}
}
SetDiscrete(*aRuleData->ValueForOverflowClipBox(), display->mOverflowClipBox,
conditions,
SETDSC_ENUMERATED | SETDSC_UNSET_INITIAL,
@ -5846,6 +5861,18 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
// mOriginalDisplay, which we have carefully not changed.
}
if (display->IsContainPaint()) {
// An element with contain:paint or contain:layout needs to "be a
// formatting context". For the purposes of the "display" property, that
// just means we need to promote "display:inline" to "inline-block".
// XXX We may also need to promote ruby display vals; see bug 1179349.
// It's okay to cache this change in the rule tree for the same
// reasons as floats in the previous condition.
if (display->mDisplay == NS_STYLE_DISPLAY_INLINE) {
display->mDisplay = NS_STYLE_DISPLAY_INLINE_BLOCK;
}
}
}
/* Convert the nsCSSValueList into an nsTArray<nsTransformFunction *>. */

View File

@ -2374,6 +2374,10 @@ struct nsStyleDisplay {
mOverflowX != NS_STYLE_OVERFLOW_CLIP;
}
bool IsContainPaint() const {
return NS_STYLE_CONTAIN_PAINT & mContain;
}
/* Returns whether the element has the -moz-transform property
* or a related property. */
bool HasTransformStyle() const {

View File

@ -140,7 +140,8 @@ nsStyleDisplay::IsFixedPosContainingBlock(const nsIFrame* aContextFrame) const
{
NS_ASSERTION(aContextFrame->StyleDisplay() == this,
"unexpected aContextFrame");
return (HasTransform(aContextFrame) || HasPerspectiveStyle() ||
return (IsContainPaint() || HasTransform(aContextFrame) ||
HasPerspectiveStyle() ||
aContextFrame->StyleSVGReset()->HasFilters()) &&
!aContextFrame->IsSVGText();
}

View File

@ -2568,7 +2568,7 @@ var gCSSProperties = {
type: CSS_TYPE_LONGHAND,
initial_values: [ "inline" ],
/* XXX none will really mess with other properties */
prerequisites: { "float": "none", "position": "static" },
prerequisites: { "float": "none", "position": "static", "contain": "none" },
other_values: [
"block",
"flex",
@ -3226,7 +3226,7 @@ var gCSSProperties = {
domProp: "overflow",
inherited: false,
type: CSS_TYPE_SHORTHAND_AND_LONGHAND,
prerequisites: { "display": "block" },
prerequisites: { "display": "block", "contain": "none" },
subproperties: [ "overflow-x", "overflow-y" ],
initial_values: [ "visible" ],
other_values: [ "auto", "scroll", "hidden", "-moz-hidden-unscrollable", "-moz-scrollbars-none" ],
@ -3236,7 +3236,7 @@ var gCSSProperties = {
domProp: "overflowX",
inherited: false,
type: CSS_TYPE_LONGHAND,
prerequisites: { "display": "block", "overflow-y": "visible" },
prerequisites: { "display": "block", "overflow-y": "visible", "contain": "none" },
initial_values: [ "visible" ],
other_values: [ "auto", "scroll", "hidden", "-moz-hidden-unscrollable" ],
invalid_values: []
@ -3245,7 +3245,7 @@ var gCSSProperties = {
domProp: "overflowY",
inherited: false,
type: CSS_TYPE_LONGHAND,
prerequisites: { "display": "block", "overflow-x": "visible" },
prerequisites: { "display": "block", "overflow-x": "visible", "contain": "none" },
initial_values: [ "visible" ],
other_values: [ "auto", "scroll", "hidden", "-moz-hidden-unscrollable" ],
invalid_values: []