From 65b6a899780d800cd40093357c2f8ad33639b9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Sat, 15 Apr 2017 00:31:33 +0300 Subject: [PATCH] stylo: Add glue for contain property --- components/style/properties/gecko.mako.rs | 67 ++++++++++++++++++- .../style/properties/longhand/box.mako.rs | 27 +++----- tests/unit/style/parsing/containment.rs | 6 -- 3 files changed, 75 insertions(+), 25 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 23daca26c86..f8b1d00df8e 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1641,7 +1641,7 @@ fn static_assert() { scroll-snap-points-x scroll-snap-points-y transform scroll-snap-type-y scroll-snap-coordinate perspective-origin transform-origin -moz-binding will-change - shape-outside""" %> + shape-outside contain""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> // We manually-implement the |display| property until we get general @@ -2257,6 +2257,71 @@ fn static_assert() { } <% impl_shape_source("shape_outside", "mShapeOutside") %> + + 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_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 properties::longhands::contain; + + if v.is_empty() { + self.gecko.mContain = NS_STYLE_CONTAIN_NONE as u8; + return; + } + + if v.contains(contain::STRICT) { + self.gecko.mContain = (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS) as u8; + return; + } + + let mut bitfield = 0; + if v.contains(contain::LAYOUT) { + bitfield |= NS_STYLE_CONTAIN_LAYOUT; + } + if v.contains(contain::STYLE) { + bitfield |= NS_STYLE_CONTAIN_STYLE; + } + if v.contains(contain::PAINT) { + bitfield |= NS_STYLE_CONTAIN_PAINT; + } + + 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_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 properties::longhands::contain; + + 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 { + servo_flags.insert(contain::STRICT | contain::STRICT_BITS); + return servo_flags; + } + + if gecko_flags & (NS_STYLE_CONTAIN_LAYOUT as u8) != 0 { + servo_flags.insert(contain::LAYOUT); + } + if gecko_flags & (NS_STYLE_CONTAIN_STYLE as u8) != 0{ + servo_flags.insert(contain::STYLE); + } + if gecko_flags & (NS_STYLE_CONTAIN_PAINT as u8) != 0 { + servo_flags.insert(contain::PAINT); + } + + return servo_flags; + } + + ${impl_simple_copy("contain", "mContain")} <%def name="simple_image_array_property(name, shorthand, field_name)"> diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index b7e516907a9..a187f09ce99 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -2076,7 +2076,10 @@ ${helpers.single_keyword("transform-style", } -<%helpers:longhand name="contain" animation_type="none" products="none" need_clone="True" +// FIXME: `size` and `content` values are not implemented and `strict` is implemented +// like `content`(layout style paint) in gecko. We should implement `size` and `content`, +// also update the glue once they are implemented in gecko. +<%helpers:longhand name="contain" animation_type="none" products="gecko" need_clone="True" spec="https://drafts.csswg.org/css-contain/#contain-property"> use std::fmt; use style_traits::ToCss; @@ -2093,14 +2096,11 @@ ${helpers.single_keyword("transform-style", bitflags! { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub flags SpecifiedValue: u8 { - const SIZE = 0x01, - const LAYOUT = 0x02, - const STYLE = 0x04, - const PAINT = 0x08, - const STRICT = 0x10, - const STRICT_BITS = SIZE.bits | LAYOUT.bits | STYLE.bits | PAINT.bits, - const CONTENT = 0x20, - const CONTENT_BITS = LAYOUT.bits | STYLE.bits | PAINT.bits, + const LAYOUT = 0x01, + const STYLE = 0x02, + const PAINT = 0x04, + const STRICT = 0x8, + const STRICT_BITS = LAYOUT.bits | STYLE.bits | PAINT.bits, } } @@ -2112,9 +2112,6 @@ ${helpers.single_keyword("transform-style", if self.contains(STRICT) { return dest.write_str("strict") } - if self.contains(CONTENT) { - return dest.write_str("content") - } let mut has_any = false; macro_rules! maybe_write_value { @@ -2128,7 +2125,6 @@ ${helpers.single_keyword("transform-style", } } } - maybe_write_value!(SIZE => "size"); maybe_write_value!(LAYOUT => "layout"); maybe_write_value!(STYLE => "style"); maybe_write_value!(PAINT => "paint"); @@ -2154,14 +2150,9 @@ ${helpers.single_keyword("transform-style", result.insert(STRICT | STRICT_BITS); return Ok(result) } - if input.try(|input| input.expect_ident_matching("content")).is_ok() { - result.insert(CONTENT | CONTENT_BITS); - return Ok(result) - } while let Ok(name) = input.try(|input| input.expect_ident()) { let flag = match_ignore_ascii_case! { &name, - "size" => SIZE, "layout" => LAYOUT, "style" => STYLE, "paint" => PAINT, diff --git a/tests/unit/style/parsing/containment.rs b/tests/unit/style/parsing/containment.rs index 2ef6a08659e..dbd02fd7067 100644 --- a/tests/unit/style/parsing/containment.rs +++ b/tests/unit/style/parsing/containment.rs @@ -16,16 +16,10 @@ fn contain_longhand_should_parse_correctly() { let strict = parse_longhand!(contain, "strict"); assert_eq!(strict, contain::STRICT | contain::STRICT_BITS); - let strict = parse_longhand!(contain, "content"); - assert_eq!(strict, contain::CONTENT | contain::CONTENT_BITS); - let style_paint = parse_longhand!(contain, "style paint"); assert_eq!(style_paint, contain::STYLE | contain::PAINT); assert_roundtrip_with_context!(contain::parse, "strict"); - assert_roundtrip_with_context!(contain::parse, "size layout style paint"); - - assert_roundtrip_with_context!(contain::parse, "content"); assert_roundtrip_with_context!(contain::parse, "layout style paint"); // Assert that the `2px` is not consumed, which would trigger parsing failure in real use