From 8dbf9b1da98478905169f0af887b6aa6b705a5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 13 Mar 2019 19:55:54 +0000 Subject: [PATCH] Bug 1535084 - Cleanup contain property. r=dholbert Now that cbindgen supports bitflags, this is trivial. Differential Revision: https://phabricator.services.mozilla.com/D23371 --- components/style/cbindgen.toml | 1 + components/style/properties/gecko.mako.rs | 87 +---------------------- components/style/values/specified/box.rs | 13 ++-- 3 files changed, 10 insertions(+), 91 deletions(-) diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 5de390cc8a6..0a0db7d1615 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -103,6 +103,7 @@ include = [ "ZIndex", "TransformOrigin", "WordBreak", + "Contain", ] item_types = ["enums", "structs", "typedefs"] diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 6a4d4d87a99..258c23a7ebf 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2751,7 +2751,7 @@ fn static_assert() { transform-style rotate scroll-snap-points-x scroll-snap-points-y scroll-snap-coordinate -moz-binding will-change - offset-path shape-outside contain touch-action + offset-path shape-outside touch-action translate scale""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> #[inline] @@ -3171,91 +3171,6 @@ fn static_assert() { <% impl_shape_source("shape_outside", "mShapeOutside") %> - pub fn set_contain(&mut self, v: longhands::contain::computed_value::T) { - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_NONE; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_STRICT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_SIZE; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_LAYOUT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT_BITS; - use crate::properties::longhands::contain::SpecifiedValue; - - if v.is_empty() { - self.gecko.mContain = NS_STYLE_CONTAIN_NONE as u8; - return; - } - - if v.contains(SpecifiedValue::STRICT) { - 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) { - bitfield |= NS_STYLE_CONTAIN_LAYOUT; - } - 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 crate::gecko_bindings::structs::NS_STYLE_CONTAIN_STRICT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_SIZE; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_LAYOUT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_PAINT; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_ALL_BITS; - use crate::gecko_bindings::structs::NS_STYLE_CONTAIN_CONTENT_BITS; - use crate::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 { - 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_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; - } - - ${impl_simple_copy("contain", "mContain")} - ${impl_simple_type_with_conversion("touch_action")} pub fn set_offset_path(&mut self, v: longhands::offset_path::computed_value::T) { diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index d4b66e42ab9..39917659cc9 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -753,18 +753,21 @@ pub fn assert_touch_action_matches() { bitflags! { #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue)] #[value_info(other_values = "none,strict,content,size,layout,paint")] + #[repr(C)] /// Constants for contain: https://drafts.csswg.org/css-contain/#contain-property pub struct Contain: u8 { + /// `none` variant, just for convenience. + const NONE = 0; /// 'size' variant, turns on size containment - const SIZE = 0x01; + const SIZE = 1 << 0; /// `layout` variant, turns on layout containment - const LAYOUT = 0x02; + const LAYOUT = 1 << 1; /// `paint` variant, turns on paint containment - const PAINT = 0x04; + const PAINT = 1 << 2; /// `strict` variant, turns on all types of containment - const STRICT = 0x08; + const STRICT = 1 << 3; /// 'content' variant, turns on layout and paint containment - const CONTENT = 0x10; + const CONTENT = 1 << 4; /// variant with all the bits that contain: strict turns on const STRICT_BITS = Contain::LAYOUT.bits | Contain::PAINT.bits | Contain::SIZE.bits; /// variant with all the bits that contain: content turns on