mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 13:25:37 +00:00
Bug 1463589 - Add contain:size and contain:content parsing functionality. r=emilio
MozReview-Commit-ID: 4fOqln3oOpC --HG-- extra : rebase_source : 3b2ac1116ea9399a8fbbaab158e7dda5fec3930d
This commit is contained in:
parent
61f3a20ced
commit
0403087901
@ -525,6 +525,7 @@ CSS_KEY(sideways-lr, sideways_lr)
|
||||
CSS_KEY(sideways-right, sideways_right) /* alias for 'sideways' */
|
||||
CSS_KEY(sideways-rl, sideways_rl)
|
||||
CSS_KEY(simplified, simplified)
|
||||
CSS_KEY(size, size)
|
||||
CSS_KEY(skew, skew)
|
||||
CSS_KEY(skewx, skewx)
|
||||
CSS_KEY(skewy, skewy)
|
||||
|
@ -1048,9 +1048,11 @@ const KTableEntry nsCSSProps::kListStylePositionKTable[] = {
|
||||
const KTableEntry nsCSSProps::kContainKTable[] = {
|
||||
{ eCSSKeyword_none, NS_STYLE_CONTAIN_NONE },
|
||||
{ eCSSKeyword_strict, NS_STYLE_CONTAIN_STRICT },
|
||||
{ eCSSKeyword_content, NS_STYLE_CONTAIN_CONTENT },
|
||||
{ eCSSKeyword_layout, NS_STYLE_CONTAIN_LAYOUT },
|
||||
{ eCSSKeyword_style, NS_STYLE_CONTAIN_STYLE },
|
||||
{ eCSSKeyword_paint, NS_STYLE_CONTAIN_PAINT },
|
||||
{ eCSSKeyword_size, NS_STYLE_CONTAIN_SIZE },
|
||||
{ eCSSKeyword_UNKNOWN, -1 }
|
||||
};
|
||||
|
||||
|
@ -5081,14 +5081,18 @@ nsComputedDOMStyle::DoGetContain()
|
||||
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");
|
||||
"contain: strict should imply contain: size layout style paint");
|
||||
val->SetIdent(eCSSKeyword_strict);
|
||||
} else {
|
||||
} else if (mask & NS_STYLE_CONTAIN_CONTENT) {
|
||||
NS_ASSERTION(mask == (NS_STYLE_CONTAIN_CONTENT | NS_STYLE_CONTAIN_CONTENT_BITS),
|
||||
"contain: content should imply contain: layout style paint");
|
||||
val->SetIdent(eCSSKeyword_content);
|
||||
} else {
|
||||
nsAutoString valueStr;
|
||||
|
||||
nsStyleUtil::AppendBitmaskCSSValue(nsCSSProps::kContainKTable,
|
||||
mask, NS_STYLE_CONTAIN_LAYOUT,
|
||||
NS_STYLE_CONTAIN_PAINT, valueStr);
|
||||
mask,
|
||||
NS_STYLE_CONTAIN_SIZE, NS_STYLE_CONTAIN_PAINT,
|
||||
valueStr);
|
||||
val->SetString(valueStr);
|
||||
}
|
||||
|
||||
|
@ -455,15 +455,21 @@ enum class StyleDisplay : uint8_t {
|
||||
};
|
||||
|
||||
// See nsStyleDisplay
|
||||
// If these are re-ordered, nsComputedDOMStyle::DoGetContain() and
|
||||
// nsCSSValue::AppendToString() must be updated.
|
||||
// If these are re-ordered, nsComputedDOMStyle::DoGetContain() 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
|
||||
#define NS_STYLE_CONTAIN_SIZE 0x01
|
||||
#define NS_STYLE_CONTAIN_LAYOUT 0x02
|
||||
#define NS_STYLE_CONTAIN_STYLE 0x04
|
||||
#define NS_STYLE_CONTAIN_PAINT 0x08
|
||||
#define NS_STYLE_CONTAIN_STRICT 0x10
|
||||
#define NS_STYLE_CONTAIN_CONTENT 0x20
|
||||
// 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 | \
|
||||
NS_STYLE_CONTAIN_SIZE)
|
||||
// NS_STYLE_CONTAIN_CONTENT_BITS does not correspond to a keyword.
|
||||
#define NS_STYLE_CONTAIN_CONTENT_BITS (NS_STYLE_CONTAIN_LAYOUT | \
|
||||
NS_STYLE_CONTAIN_STYLE | \
|
||||
NS_STYLE_CONTAIN_PAINT)
|
||||
|
||||
|
@ -7239,6 +7239,8 @@ if (IsCSSPropertyPrefEnabled("layout.css.contain.enabled")) {
|
||||
"strict",
|
||||
"layout",
|
||||
"style",
|
||||
"size",
|
||||
"content",
|
||||
"layout style",
|
||||
"style layout",
|
||||
"paint",
|
||||
@ -7246,6 +7248,9 @@ if (IsCSSPropertyPrefEnabled("layout.css.contain.enabled")) {
|
||||
"paint layout",
|
||||
"style paint",
|
||||
"paint style",
|
||||
"size layout",
|
||||
"style size",
|
||||
"paint size",
|
||||
"layout style paint",
|
||||
"layout paint style",
|
||||
"style paint layout",
|
||||
@ -7256,11 +7261,18 @@ if (IsCSSPropertyPrefEnabled("layout.css.contain.enabled")) {
|
||||
"strict layout",
|
||||
"strict layout style",
|
||||
"layout strict",
|
||||
"layout content",
|
||||
"strict content",
|
||||
"layout style strict",
|
||||
"layout style paint strict",
|
||||
"paint strict",
|
||||
"style strict",
|
||||
"paint paint",
|
||||
"content content",
|
||||
"size content",
|
||||
"content strict size",
|
||||
"paint layout content",
|
||||
"layout size content",
|
||||
"strict strict",
|
||||
"auto",
|
||||
"10px",
|
||||
|
@ -3626,10 +3626,13 @@ fn static_assert() {
|
||||
pub fn set_contain(&mut self, v: longhands::contain::computed_value::T) {
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_NONE;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_STRICT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_SIZE;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_LAYOUT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_STYLE;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT_BITS;
|
||||
use properties::longhands::contain::SpecifiedValue;
|
||||
|
||||
if v.is_empty() {
|
||||
@ -3641,6 +3644,10 @@ fn static_assert() {
|
||||
self.gecko.mContain = (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS) as u8;
|
||||
return;
|
||||
}
|
||||
if v.contains(SpecifiedValue::CONTENT) {
|
||||
self.gecko.mContain = (NS_STYLE_CONTAIN_CONTENT | NS_STYLE_CONTAIN_CONTENT_BITS) as u8;
|
||||
return;
|
||||
}
|
||||
|
||||
let mut bitfield = 0;
|
||||
if v.contains(SpecifiedValue::LAYOUT) {
|
||||
@ -3652,36 +3659,57 @@ fn static_assert() {
|
||||
if v.contains(SpecifiedValue::PAINT) {
|
||||
bitfield |= NS_STYLE_CONTAIN_PAINT;
|
||||
}
|
||||
if v.contains(SpecifiedValue::SIZE) {
|
||||
bitfield |= NS_STYLE_CONTAIN_SIZE;
|
||||
}
|
||||
|
||||
self.gecko.mContain = bitfield as u8;
|
||||
}
|
||||
|
||||
pub fn clone_contain(&self) -> longhands::contain::computed_value::T {
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_STRICT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_SIZE;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_LAYOUT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_STYLE;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS;
|
||||
use gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT_BITS;
|
||||
use properties::longhands::contain::{self, SpecifiedValue};
|
||||
|
||||
let mut servo_flags = contain::computed_value::T::empty();
|
||||
let gecko_flags = self.gecko.mContain;
|
||||
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_STRICT as u8) != 0 &&
|
||||
gecko_flags & (NS_STYLE_CONTAIN_ALL_BITS as u8) != 0 {
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_STRICT as u8) != 0 {
|
||||
debug_assert_eq!(
|
||||
gecko_flags & (NS_STYLE_CONTAIN_ALL_BITS as u8),
|
||||
NS_STYLE_CONTAIN_ALL_BITS as u8,
|
||||
"When strict is specified, ALL_BITS should be specified as well"
|
||||
);
|
||||
servo_flags.insert(SpecifiedValue::STRICT | SpecifiedValue::STRICT_BITS);
|
||||
return servo_flags;
|
||||
}
|
||||
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_CONTENT as u8) != 0 {
|
||||
debug_assert_eq!(
|
||||
gecko_flags & (NS_STYLE_CONTAIN_CONTENT_BITS as u8),
|
||||
NS_STYLE_CONTAIN_CONTENT_BITS as u8,
|
||||
"When content is specified, CONTENT_BITS should be specified as well"
|
||||
);
|
||||
servo_flags.insert(SpecifiedValue::CONTENT | SpecifiedValue::CONTENT_BITS);
|
||||
return servo_flags;
|
||||
}
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_LAYOUT as u8) != 0 {
|
||||
servo_flags.insert(SpecifiedValue::LAYOUT);
|
||||
}
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_STYLE as u8) != 0{
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_STYLE as u8) != 0 {
|
||||
servo_flags.insert(SpecifiedValue::STYLE);
|
||||
}
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_PAINT as u8) != 0 {
|
||||
servo_flags.insert(SpecifiedValue::PAINT);
|
||||
}
|
||||
if gecko_flags & (NS_STYLE_CONTAIN_SIZE as u8) != 0 {
|
||||
servo_flags.insert(SpecifiedValue::SIZE);
|
||||
}
|
||||
|
||||
return servo_flags;
|
||||
}
|
||||
|
@ -525,19 +525,25 @@ pub fn assert_touch_action_matches() {
|
||||
|
||||
bitflags! {
|
||||
#[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)]
|
||||
#[value_info(other_values = "none,strict,layout,style,paint")]
|
||||
#[value_info(other_values = "none,strict,content,size,layout,style,paint")]
|
||||
/// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property
|
||||
pub struct Contain: u8 {
|
||||
/// 'size' variant, turns on size containment
|
||||
const SIZE = 0x01;
|
||||
/// `layout` variant, turns on layout containment
|
||||
const LAYOUT = 0x01;
|
||||
const LAYOUT = 0x02;
|
||||
/// `style` variant, turns on style containment
|
||||
const STYLE = 0x02;
|
||||
const STYLE = 0x04;
|
||||
/// `paint` variant, turns on paint containment
|
||||
const PAINT = 0x04;
|
||||
const PAINT = 0x08;
|
||||
/// `strict` variant, turns on all types of containment
|
||||
const STRICT = 0x8;
|
||||
const STRICT = 0x10;
|
||||
/// 'content' variant, turns on style, layout, and paint containment
|
||||
const CONTENT = 0x20;
|
||||
/// variant with all the bits that contain: strict turns on
|
||||
const STRICT_BITS = Contain::LAYOUT.bits | Contain::STYLE.bits | Contain::PAINT.bits;
|
||||
const STRICT_BITS = Contain::LAYOUT.bits | Contain::STYLE.bits | Contain::PAINT.bits | Contain::SIZE.bits;
|
||||
/// variant with all the bits that contain: content turns on
|
||||
const CONTENT_BITS = Contain::STYLE.bits | Contain::LAYOUT.bits | Contain::PAINT.bits;
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,6 +558,9 @@ impl ToCss for Contain {
|
||||
if self.contains(Contain::STRICT) {
|
||||
return dest.write_str("strict");
|
||||
}
|
||||
if self.contains(Contain::CONTENT) {
|
||||
return dest.write_str("content");
|
||||
}
|
||||
|
||||
let mut has_any = false;
|
||||
macro_rules! maybe_write_value {
|
||||
@ -565,6 +574,7 @@ impl ToCss for Contain {
|
||||
}
|
||||
};
|
||||
}
|
||||
maybe_write_value!(Contain::SIZE => "size");
|
||||
maybe_write_value!(Contain::LAYOUT => "layout");
|
||||
maybe_write_value!(Contain::STYLE => "style");
|
||||
maybe_write_value!(Contain::PAINT => "paint");
|
||||
@ -583,10 +593,12 @@ impl Parse for Contain {
|
||||
let mut result = Contain::empty();
|
||||
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
|
||||
let flag = match_ignore_ascii_case! { &name,
|
||||
"size" => Some(Contain::SIZE),
|
||||
"layout" => Some(Contain::LAYOUT),
|
||||
"style" => Some(Contain::STYLE),
|
||||
"paint" => Some(Contain::PAINT),
|
||||
"strict" if result.is_empty() => return Ok(Contain::STRICT | Contain::STRICT_BITS),
|
||||
"content" if result.is_empty() => return Ok(Contain::CONTENT | Contain::CONTENT_BITS),
|
||||
"none" if result.is_empty() => return Ok(result),
|
||||
_ => None
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user