From 67799f9445f7e09a61b6ae42c1a85ad32c6c6884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Sat, 1 Apr 2017 01:57:47 +0300 Subject: [PATCH] Create a generic flag system for properties --- components/style/properties/data.py | 10 +++--- .../style/properties/longhand/box.mako.rs | 14 +++----- .../style/properties/longhand/effects.mako.rs | 7 ++-- .../properties/longhand/position.mako.rs | 3 +- .../style/properties/longhand/svg.mako.rs | 4 +-- .../style/properties/properties.mako.rs | 33 +++++++++++-------- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index ec982a1cbe1..b0d704970c7 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -128,8 +128,7 @@ class Longhand(object): need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, allowed_in_keyframe_block=True, complex_color=False, cast_type='u8', has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False, - creates_stacking_context=False, fixpos_cb=False, abspos_cb=False, - allowed_in_page_rule=False): + flags=None, allowed_in_page_rule=False): self.name = name if not spec: raise TypeError("Spec should be specified for %s" % name) @@ -153,9 +152,7 @@ class Longhand(object): self.alias = alias.split() if alias else [] self.extra_prefixes = extra_prefixes.split() if extra_prefixes else [] self.boxed = arg_to_bool(boxed) - self.creates_stacking_context = arg_to_bool(creates_stacking_context) - self.fixpos_cb = arg_to_bool(fixpos_cb) - self.abspos_cb = arg_to_bool(abspos_cb) + self.flags = flags.split() if flags else [] self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) # https://drafts.csswg.org/css-animations/#keyframes @@ -190,7 +187,7 @@ class Longhand(object): class Shorthand(object): def __init__(self, name, sub_properties, spec=None, experimental=False, internal=False, allowed_in_keyframe_block=True, alias=None, extra_prefixes=None, - allowed_in_page_rule=False): + allowed_in_page_rule=False, flags=None): self.name = name if not spec: raise TypeError("Spec should be specified for %s" % name) @@ -204,6 +201,7 @@ class Shorthand(object): self.alias = alias.split() if alias else [] self.extra_prefixes = extra_prefixes.split() if extra_prefixes else [] self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) + self.flags = flags.split() if flags else [] # https://drafts.csswg.org/css-animations/#keyframes # > The inside of accepts any CSS property diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 851beb6267c..c167349c4df 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -107,8 +107,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed", need_clone="True", extra_gecko_values="sticky", animation_type="none", - creates_stacking_context="True", - abspos_cb="True", + flags="CREATES_STACKING_CONTEXT ABSPOS_CB", spec="https://drafts.csswg.org/css-position/#position-property")} <%helpers:single_keyword_computed name="float" @@ -1111,8 +1110,7 @@ ${helpers.predefined_type("scroll-snap-coordinate", <%helpers:longhand name="transform" products="gecko servo" extra_prefixes="webkit" animation_type="normal" - creates_stacking_context="True" - fixpos_cb="True" + flags="CREATES_STACKING_CONTEXT FIXPOS_CB" spec="https://drafts.csswg.org/css-transforms/#propdef-transform"> use app_units::Au; use values::specified::{Angle, Length, LengthOrPercentage, Number}; @@ -1825,7 +1823,7 @@ ${helpers.single_keyword("isolation", "auto isolate", products="gecko", spec="https://drafts.fxtf.org/compositing/#isolation", - creates_stacking_context=True, + flags="CREATES_STACKING_CONTEXT", animation_type="none")} // TODO add support for logical values recto and verso @@ -1864,8 +1862,7 @@ ${helpers.predefined_type("perspective", gecko_ffi_name="mChildPerspective", spec="https://drafts.csswg.org/css-transforms/#perspective", extra_prefixes="moz webkit", - creates_stacking_context=True, - fixpos_cb=True, + flags="CREATES_STACKING_CONTEXT FIXPOS_CB", animation_type="normal")} <%helpers:longhand name="perspective-origin" boxed="True" animation_type="normal" extra_prefixes="moz webkit" @@ -1963,8 +1960,7 @@ ${helpers.single_keyword("transform-style", "flat preserve-3d", spec="https://drafts.csswg.org/css-transforms/#transform-style-property", extra_prefixes="moz webkit", - creates_stacking_context=True, - fixpos_cb=True, + flags="CREATES_STACKING_CONTEXT FIXPOS_CB", animation_type="none")} <%helpers:longhand name="transform-origin" animation_type="normal" extra_prefixes="moz webkit" boxed="True" diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 93d1100d4a0..efc7b48088e 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -11,7 +11,7 @@ ${helpers.predefined_type("opacity", "Opacity", "1.0", animation_type="normal", - creates_stacking_context=True, + flags="CREATES_STACKING_CONTEXT", spec="https://drafts.csswg.org/css-color/#opacity")} <%helpers:vector_longhand name="box-shadow" allow_empty="True" @@ -87,8 +87,7 @@ ${helpers.predefined_type("clip", // FIXME: This prop should be animatable <%helpers:longhand name="filter" animation_type="none" extra_prefixes="webkit" - creates_stacking_context="True" - fixpos_cb="True" + flags="CREATES_STACKING_CONTEXT FIXPOS_CB" spec="https://drafts.fxtf.org/filters/#propdef-filter"> //pub use self::computed_value::T as SpecifiedValue; use cssparser; @@ -526,5 +525,5 @@ ${helpers.single_keyword("mix-blend-mode", color-burn hard-light soft-light difference exclusion hue saturation color luminosity""", gecko_constant_prefix="NS_STYLE_BLEND", animation_type="none", - creates_stacking_context=True, + flags="CREATES_STACKING_CONTEXT", spec="https://drafts.fxtf.org/compositing/#propdef-mix-blend-mode")} diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index ed41a227de8..eedab26f452 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -26,9 +26,10 @@ ${helpers.predefined_type("z-index", "IntegerOrAuto", "Either::Second(Auto)", spec="https://www.w3.org/TR/CSS2/visuren.html#z-index", - creates_stacking_context=True, + flags="CREATES_STACKING_CONTEXT", animation_type="normal")} + // CSS Flexible Box Layout Module Level 1 // http://www.w3.org/TR/css3-flexbox/ diff --git a/components/style/properties/longhand/svg.mako.rs b/components/style/properties/longhand/svg.mako.rs index 7de3b078690..dea04984cf1 100644 --- a/components/style/properties/longhand/svg.mako.rs +++ b/components/style/properties/longhand/svg.mako.rs @@ -59,7 +59,7 @@ ${helpers.single_keyword("mask-type", "luminance alpha", spec="https://drafts.fxtf.org/css-masking/#propdef-mask-type")} <%helpers:longhand name="clip-path" animation_type="none" products="gecko" boxed="True" - creates_stacking_context="True" + flags="CREATES_STACKING_CONTEXT" spec="https://drafts.fxtf.org/css-masking/#propdef-clip-path"> use std::fmt; use style_traits::ToCss; @@ -200,7 +200,7 @@ ${helpers.single_keyword("mask-composite", <%helpers:vector_longhand name="mask-image" products="gecko" animation_type="none" extra_prefixes="webkit" has_uncacheable_values="${product == 'gecko'}" - creates_stacking_context="True" + flags="CREATES_STACKING_CONTEXT", spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image"> use std::fmt; use style_traits::ToCss; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 767bb39385c..b0ab39c2505 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -469,13 +469,13 @@ bitflags! { /// A set of flags for properties. pub flags PropertyFlags: u8 { /// This property requires a stacking context. - const CREATES_STACKING_CONTEXT = 0x01, + const CREATES_STACKING_CONTEXT = 1 << 0, /// This property has values that can establish a containing block for /// fixed positioned and absolutely positioned elements. - const FIXPOS_CB = 0x02, + const FIXPOS_CB = 1 << 1, /// This property has values that can establish a containing block for /// absolutely positioned elements. - const ABSPOS_CB = 0x04, + const ABSPOS_CB = 1 << 2, } } @@ -518,20 +518,14 @@ impl LonghandId { } } - /// Returns PropertyFlags for given property. + /// Returns PropertyFlags for given longhand property. pub fn flags(&self) -> PropertyFlags { match *self { % for property in data.longhands: LonghandId::${property.camel_case} => - %if property.creates_stacking_context: - CREATES_STACKING_CONTEXT | - %endif - %if property.fixpos_cb: - FIXPOS_CB | - %endif - %if property.abspos_cb: - ABSPOS_CB | - %endif + % for flag in property.flags: + ${flag} | + % endfor PropertyFlags::empty(), % endfor } @@ -658,6 +652,19 @@ impl ShorthandId { None } + + /// Returns PropertyFlags for given shorthand property. + pub fn flags(&self) -> PropertyFlags { + match *self { + % for property in data.shorthands: + ShorthandId::${property.camel_case} => + % for flag in property.flags: + ${flag} | + % endfor + PropertyFlags::empty(), + % endfor + } + } } /// Servo's representation of a declared value for a given `T`, which is the