From d245f8b5791c63eb7bb9e735659b1425ac94bee0 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Thu, 19 Jul 2018 10:11:04 +1000 Subject: [PATCH] style: Introduce a concept of logical group. Bug: 1473180 Reviewed-by: emilio MozReview-Commit-ID: GXlf8JNML4N --- components/style/properties/data.py | 5 ++- .../style/properties/longhands/border.mako.rs | 3 ++ .../style/properties/longhands/margin.mako.rs | 1 + .../properties/longhands/padding.mako.rs | 1 + .../properties/longhands/position.mako.rs | 7 ++- .../style/properties/properties.mako.rs | 44 +++++++++++++++++++ 6 files changed, 59 insertions(+), 2 deletions(-) diff --git a/components/style/properties/data.py b/components/style/properties/data.py index ea0516d803e..007a659dca1 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -168,7 +168,7 @@ class Longhand(object): enabled_in="content", need_index=False, gecko_ffi_name=None, allowed_in_keyframe_block=True, cast_type='u8', - logical=False, alias=None, extra_prefixes=None, boxed=False, + logical=False, logical_group=None, alias=None, extra_prefixes=None, boxed=False, flags=None, allowed_in_page_rule=False, allow_quirks=False, ignored_when_colors_disabled=False, vector=False, servo_restyle_damage="repaint"): @@ -196,6 +196,9 @@ class Longhand(object): self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case self.cast_type = cast_type self.logical = arg_to_bool(logical) + self.logical_group = logical_group + if self.logical: + assert logical_group, "Property " + name + " must have a logical group" self.alias = parse_property_aliases(alias) self.extra_prefixes = parse_property_aliases(extra_prefixes) self.boxed = arg_to_bool(boxed) diff --git a/components/style/properties/longhands/border.mako.rs b/components/style/properties/longhands/border.mako.rs index 9bb3dbcec28..901d29728b1 100644 --- a/components/style/properties/longhands/border.mako.rs +++ b/components/style/properties/longhands/border.mako.rs @@ -27,6 +27,7 @@ spec=maybe_logical_spec(side, "color"), animation_value_type="AnimatedColor", logical=is_logical, + logical_group="border-color", allow_quirks=not is_logical, flags="APPLIES_TO_FIRST_LETTER", ignored_when_colors_disabled=True, @@ -40,6 +41,7 @@ flags="APPLIES_TO_FIRST_LETTER", animation_value_type="discrete" if not is_logical else "none", logical=is_logical, + logical_group="border-style", needs_context=False, )} @@ -52,6 +54,7 @@ spec=maybe_logical_spec(side, "width"), animation_value_type="NonNegativeLength", logical=is_logical, + logical_group="border-width", flags="APPLIES_TO_FIRST_LETTER GETCS_NEEDS_LAYOUT_FLUSH", allow_quirks=not is_logical, servo_restyle_damage="reflow rebuild_and_reflow_inline" diff --git a/components/style/properties/longhands/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs index 1a964bcbb74..5627e27bf82 100644 --- a/components/style/properties/longhands/margin.mako.rs +++ b/components/style/properties/longhands/margin.mako.rs @@ -20,6 +20,7 @@ allow_quirks=not side[1], animation_value_type="ComputedValue", logical=side[1], + logical_group="margin", spec=spec, flags="APPLIES_TO_FIRST_LETTER GETCS_NEEDS_LAYOUT_FLUSH", allowed_in_page_rule=True, diff --git a/components/style/properties/longhands/padding.mako.rs b/components/style/properties/longhands/padding.mako.rs index 3d2467c0ca0..876f4be92c0 100644 --- a/components/style/properties/longhands/padding.mako.rs +++ b/components/style/properties/longhands/padding.mako.rs @@ -21,6 +21,7 @@ alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"), animation_value_type="NonNegativeLengthOrPercentage", logical=side[1], + logical_group="padding", spec=spec, flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_PLACEHOLDER GETCS_NEEDS_LAYOUT_FLUSH", allow_quirks=not side[1], diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 3b34047fc5a..81cf3d3782a 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -18,7 +18,8 @@ flags="GETCS_NEEDS_LAYOUT_FLUSH", animation_value_type="ComputedValue", allow_quirks=True, - servo_restyle_damage="reflow_out_of_flow" + servo_restyle_damage="reflow_out_of_flow", + logical_group="inset", )} % endfor // inset-* logical properties, map to "top" / "left" / "bottom" / "right" @@ -32,6 +33,7 @@ alias="offset-%s:layout.css.offset-logical-properties.enabled" % side, animation_value_type="ComputedValue", logical=True, + logical_group="inset", )} % endfor @@ -221,6 +223,7 @@ ${helpers.predefined_type( "computed::MozLength::auto()", parse_function, logical=logical, + logical_group="size", allow_quirks=not logical, spec=spec % size, animation_value_type="MozLength", @@ -234,6 +237,7 @@ ${helpers.predefined_type( "computed::MozLength::auto()", parse_function, logical=logical, + logical_group="min-size", allow_quirks=not logical, spec=spec % size, animation_value_type="MozLength", @@ -245,6 +249,7 @@ ${helpers.predefined_type( "computed::MaxLength::none()", parse_function, logical=logical, + logical_group="max-size", allow_quirks=not logical, spec=spec % size, animation_value_type="MaxLength", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 64cde6fe793..6a94fbd6a64 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -56,6 +56,7 @@ use style_adjuster::StyleAdjuster; pub use self::declaration_block::*; <%! + from collections import defaultdict from data import Method, Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS import os.path %> @@ -841,6 +842,29 @@ bitflags! { } } +<% + logical_groups = defaultdict(list) + for prop in data.longhands: + if prop.logical_group: + logical_groups[prop.logical_group].append(prop) + + for group, props in logical_groups.iteritems(): + logical_count = sum(1 for p in props if p.logical) + if logical_count * 2 != len(props): + raise RuntimeError("Logical group {} has ".format(group) + + "unbalanced logical / physical properties") +%> + +/// A group for properties which may override each other +/// via logical resolution. +#[derive(Clone, Copy, Eq, Hash, PartialEq)] +pub enum LogicalGroup { + % for group in logical_groups.iterkeys(): + /// ${group} + ${to_camel_case(group)}, + % endfor +} + /// An identifier for a given longhand property. #[derive(Clone, Copy, Eq, Hash, MallocSizeOf, PartialEq)] #[repr(u16)] @@ -993,9 +1017,15 @@ impl LonghandId { match *self { % for property in data.longhands: % if property.logical: + <% logical_group = property.logical_group %> LonghandId::${property.camel_case} => { <%helpers:logical_setter_helper name="${property.name}"> <%def name="inner(physical_ident)"> + <% + physical_name = physical_ident.replace("_", "-") + physical_property = data.longhands_by_name[physical_name] + assert logical_group == physical_property.logical_group + %> LonghandId::${to_camel_case(physical_ident)} @@ -1006,6 +1036,20 @@ impl LonghandId { } } + /// Return the logical group of this longhand property. + pub fn logical_group(&self) -> Option { + const LOGICAL_GROUPS: [Option; ${len(data.longhands)}] = [ + % for prop in data.longhands: + % if prop.logical_group: + Some(LogicalGroup::${to_camel_case(prop.logical_group)}), + % else: + None, + % endif + % endfor + ]; + LOGICAL_GROUPS[*self as usize] + } + /// Returns PropertyFlags for given longhand property. pub fn flags(&self) -> PropertyFlags { match *self {