Create a generic flag system for properties

This commit is contained in:
Nazım Can Altınova 2017-04-01 01:57:47 +03:00
parent 355d5f89da
commit 67799f9445
No known key found for this signature in database
GPG key ID: AF9BCD7CE6449954
6 changed files with 36 additions and 35 deletions

View file

@ -128,8 +128,7 @@ class Longhand(object):
need_clone=False, need_index=False, gecko_ffi_name=None, depend_on_viewport_size=False, 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', allowed_in_keyframe_block=True, complex_color=False, cast_type='u8',
has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False, has_uncacheable_values=False, logical=False, alias=None, extra_prefixes=None, boxed=False,
creates_stacking_context=False, fixpos_cb=False, abspos_cb=False, flags=None, allowed_in_page_rule=False):
allowed_in_page_rule=False):
self.name = name self.name = name
if not spec: if not spec:
raise TypeError("Spec should be specified for %s" % name) raise TypeError("Spec should be specified for %s" % name)
@ -153,9 +152,7 @@ class Longhand(object):
self.alias = alias.split() if alias else [] self.alias = alias.split() if alias else []
self.extra_prefixes = extra_prefixes.split() if extra_prefixes else [] self.extra_prefixes = extra_prefixes.split() if extra_prefixes else []
self.boxed = arg_to_bool(boxed) self.boxed = arg_to_bool(boxed)
self.creates_stacking_context = arg_to_bool(creates_stacking_context) self.flags = flags.split() if flags else []
self.fixpos_cb = arg_to_bool(fixpos_cb)
self.abspos_cb = arg_to_bool(abspos_cb)
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule)
# https://drafts.csswg.org/css-animations/#keyframes # https://drafts.csswg.org/css-animations/#keyframes
@ -190,7 +187,7 @@ class Longhand(object):
class Shorthand(object): class Shorthand(object):
def __init__(self, name, sub_properties, spec=None, experimental=False, internal=False, def __init__(self, name, sub_properties, spec=None, experimental=False, internal=False,
allowed_in_keyframe_block=True, alias=None, extra_prefixes=None, 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 self.name = name
if not spec: if not spec:
raise TypeError("Spec should be specified for %s" % name) raise TypeError("Spec should be specified for %s" % name)
@ -204,6 +201,7 @@ class Shorthand(object):
self.alias = alias.split() if alias else [] self.alias = alias.split() if alias else []
self.extra_prefixes = extra_prefixes.split() if extra_prefixes else [] self.extra_prefixes = extra_prefixes.split() if extra_prefixes else []
self.allowed_in_page_rule = arg_to_bool(allowed_in_page_rule) 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 # https://drafts.csswg.org/css-animations/#keyframes
# > The <declaration-list> inside of <keyframe-block> accepts any CSS property # > The <declaration-list> inside of <keyframe-block> accepts any CSS property

View file

@ -107,8 +107,7 @@ ${helpers.single_keyword("position", "static absolute relative fixed",
need_clone="True", need_clone="True",
extra_gecko_values="sticky", extra_gecko_values="sticky",
animation_type="none", animation_type="none",
creates_stacking_context="True", flags="CREATES_STACKING_CONTEXT ABSPOS_CB",
abspos_cb="True",
spec="https://drafts.csswg.org/css-position/#position-property")} spec="https://drafts.csswg.org/css-position/#position-property")}
<%helpers:single_keyword_computed name="float" <%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" <%helpers:longhand name="transform" products="gecko servo" extra_prefixes="webkit"
animation_type="normal" animation_type="normal"
creates_stacking_context="True" flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
fixpos_cb="True"
spec="https://drafts.csswg.org/css-transforms/#propdef-transform"> spec="https://drafts.csswg.org/css-transforms/#propdef-transform">
use app_units::Au; use app_units::Au;
use values::specified::{Angle, Length, LengthOrPercentage, Number}; use values::specified::{Angle, Length, LengthOrPercentage, Number};
@ -1825,7 +1823,7 @@ ${helpers.single_keyword("isolation",
"auto isolate", "auto isolate",
products="gecko", products="gecko",
spec="https://drafts.fxtf.org/compositing/#isolation", spec="https://drafts.fxtf.org/compositing/#isolation",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT",
animation_type="none")} animation_type="none")}
// TODO add support for logical values recto and verso // TODO add support for logical values recto and verso
@ -1864,8 +1862,7 @@ ${helpers.predefined_type("perspective",
gecko_ffi_name="mChildPerspective", gecko_ffi_name="mChildPerspective",
spec="https://drafts.csswg.org/css-transforms/#perspective", spec="https://drafts.csswg.org/css-transforms/#perspective",
extra_prefixes="moz webkit", extra_prefixes="moz webkit",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
fixpos_cb=True,
animation_type="normal")} animation_type="normal")}
<%helpers:longhand name="perspective-origin" boxed="True" animation_type="normal" extra_prefixes="moz webkit" <%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", "flat preserve-3d",
spec="https://drafts.csswg.org/css-transforms/#transform-style-property", spec="https://drafts.csswg.org/css-transforms/#transform-style-property",
extra_prefixes="moz webkit", extra_prefixes="moz webkit",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT FIXPOS_CB",
fixpos_cb=True,
animation_type="none")} animation_type="none")}
<%helpers:longhand name="transform-origin" animation_type="normal" extra_prefixes="moz webkit" boxed="True" <%helpers:longhand name="transform-origin" animation_type="normal" extra_prefixes="moz webkit" boxed="True"

View file

@ -11,7 +11,7 @@ ${helpers.predefined_type("opacity",
"Opacity", "Opacity",
"1.0", "1.0",
animation_type="normal", animation_type="normal",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT",
spec="https://drafts.csswg.org/css-color/#opacity")} spec="https://drafts.csswg.org/css-color/#opacity")}
<%helpers:vector_longhand name="box-shadow" allow_empty="True" <%helpers:vector_longhand name="box-shadow" allow_empty="True"
@ -87,8 +87,7 @@ ${helpers.predefined_type("clip",
// FIXME: This prop should be animatable // FIXME: This prop should be animatable
<%helpers:longhand name="filter" animation_type="none" extra_prefixes="webkit" <%helpers:longhand name="filter" animation_type="none" extra_prefixes="webkit"
creates_stacking_context="True" flags="CREATES_STACKING_CONTEXT FIXPOS_CB"
fixpos_cb="True"
spec="https://drafts.fxtf.org/filters/#propdef-filter"> spec="https://drafts.fxtf.org/filters/#propdef-filter">
//pub use self::computed_value::T as SpecifiedValue; //pub use self::computed_value::T as SpecifiedValue;
use cssparser; use cssparser;
@ -526,5 +525,5 @@ ${helpers.single_keyword("mix-blend-mode",
color-burn hard-light soft-light difference exclusion hue color-burn hard-light soft-light difference exclusion hue
saturation color luminosity""", gecko_constant_prefix="NS_STYLE_BLEND", saturation color luminosity""", gecko_constant_prefix="NS_STYLE_BLEND",
animation_type="none", animation_type="none",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT",
spec="https://drafts.fxtf.org/compositing/#propdef-mix-blend-mode")} spec="https://drafts.fxtf.org/compositing/#propdef-mix-blend-mode")}

View file

@ -26,9 +26,10 @@
${helpers.predefined_type("z-index", "IntegerOrAuto", ${helpers.predefined_type("z-index", "IntegerOrAuto",
"Either::Second(Auto)", "Either::Second(Auto)",
spec="https://www.w3.org/TR/CSS2/visuren.html#z-index", spec="https://www.w3.org/TR/CSS2/visuren.html#z-index",
creates_stacking_context=True, flags="CREATES_STACKING_CONTEXT",
animation_type="normal")} animation_type="normal")}
// CSS Flexible Box Layout Module Level 1 // CSS Flexible Box Layout Module Level 1
// http://www.w3.org/TR/css3-flexbox/ // http://www.w3.org/TR/css3-flexbox/

View file

@ -59,7 +59,7 @@ ${helpers.single_keyword("mask-type", "luminance alpha",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-type")} spec="https://drafts.fxtf.org/css-masking/#propdef-mask-type")}
<%helpers:longhand name="clip-path" animation_type="none" products="gecko" boxed="True" <%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"> spec="https://drafts.fxtf.org/css-masking/#propdef-clip-path">
use std::fmt; use std::fmt;
use style_traits::ToCss; 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" <%helpers:vector_longhand name="mask-image" products="gecko" animation_type="none" extra_prefixes="webkit"
has_uncacheable_values="${product == 'gecko'}" has_uncacheable_values="${product == 'gecko'}"
creates_stacking_context="True" flags="CREATES_STACKING_CONTEXT",
spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image"> spec="https://drafts.fxtf.org/css-masking/#propdef-mask-image">
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;

View file

@ -469,13 +469,13 @@ bitflags! {
/// A set of flags for properties. /// A set of flags for properties.
pub flags PropertyFlags: u8 { pub flags PropertyFlags: u8 {
/// This property requires a stacking context. /// 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 /// This property has values that can establish a containing block for
/// fixed positioned and absolutely positioned elements. /// 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 /// This property has values that can establish a containing block for
/// absolutely positioned elements. /// 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 { pub fn flags(&self) -> PropertyFlags {
match *self { match *self {
% for property in data.longhands: % for property in data.longhands:
LonghandId::${property.camel_case} => LonghandId::${property.camel_case} =>
%if property.creates_stacking_context: % for flag in property.flags:
CREATES_STACKING_CONTEXT | ${flag} |
%endif % endfor
%if property.fixpos_cb:
FIXPOS_CB |
%endif
%if property.abspos_cb:
ABSPOS_CB |
%endif
PropertyFlags::empty(), PropertyFlags::empty(),
% endfor % endfor
} }
@ -658,6 +652,19 @@ impl ShorthandId {
None 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 /// Servo's representation of a declared value for a given `T`, which is the