diff --git a/components/style/properties/data.py b/components/style/properties/data.py index c363aa782cc..8113c402581 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -10,11 +10,14 @@ PHYSICAL_SIZES = ["width", "height"] LOGICAL_SIZES = ["block-size", "inline-size"] PHYSICAL_CORNERS = ["top-left", "top-right", "bottom-right", "bottom-left"] LOGICAL_CORNERS = ["start-start", "start-end", "end-start", "end-end"] +PHYSICAL_AXES = ["x", "y"] +LOGICAL_AXES = ["inline", "block"] # bool is True when logical ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES] ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size in LOGICAL_SIZES] ALL_CORNERS = [(corner, False) for corner in PHYSICAL_CORNERS] + [(corner, True) for corner in LOGICAL_CORNERS] +ALL_AXES = [(axis, False) for axis in PHYSICAL_AXES] + [(axis, True) for axis in LOGICAL_AXES] SYSTEM_FONT_LONGHANDS = """font_family font_size font_style font_variant_caps font_stretch font_kerning @@ -162,6 +165,8 @@ def parse_property_aliases(alias_list): result.append((name, pref)) return result +def to_phys(name, logical, physical): + return name.replace(logical, physical).replace("inset-", "") class Longhand(object): def __init__(self, style_struct, name, spec=None, animation_value_type=None, keyword=None, @@ -241,16 +246,16 @@ class Longhand(object): # property names corresponding to it. def all_physical_mapped_properties(self): assert self.logical - logical_side = None - for s in LOGICAL_SIDES + LOGICAL_SIZES + LOGICAL_CORNERS: - if s in self.name: - assert not logical_side - logical_side = s - assert logical_side + candidates = [s for s in LOGICAL_SIDES + LOGICAL_SIZES + LOGICAL_CORNERS + if s in self.name] + [s for s in LOGICAL_AXES if self.name.endswith(s)] + assert(len(candidates) == 1) + logical_side = candidates[0] + physical = PHYSICAL_SIDES if logical_side in LOGICAL_SIDES \ else PHYSICAL_SIZES if logical_side in LOGICAL_SIZES \ + else PHYSICAL_AXES if logical_side in LOGICAL_AXES \ else LOGICAL_CORNERS - return [self.name.replace(logical_side, physical_side).replace("inset-", "") + return [to_phys(self.name, logical_side, physical_side) for physical_side in physical] def experimental(self, product): diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 800d50c6220..b29c323cf92 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -3,8 +3,9 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ <%! - from data import Keyword, to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS - from data import LOGICAL_CORNERS, PHYSICAL_CORNERS, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES + from data import Keyword, to_rust_ident, to_phys, to_camel_case, SYSTEM_FONT_LONGHANDS + from data import (LOGICAL_CORNERS, PHYSICAL_CORNERS, LOGICAL_SIDES, + PHYSICAL_SIDES, LOGICAL_SIZES, LOGICAL_AXES) %> <%def name="predefined_type(name, type, initial_value, parse_method='parse', @@ -1038,17 +1039,21 @@ side = None size = None corner = None + axis = None maybe_side = [s for s in LOGICAL_SIDES if s in name] maybe_size = [s for s in LOGICAL_SIZES if s in name] maybe_corner = [s for s in LOGICAL_CORNERS if s in name] + maybe_axis = [s for s in LOGICAL_AXES if name.endswith(s)] if len(maybe_side) == 1: side = maybe_side[0] elif len(maybe_size) == 1: size = maybe_size[0] elif len(maybe_corner) == 1: corner = maybe_corner[0] + elif len(maybe_axis) == 1: + axis = maybe_axis[0] def phys_ident(side, phy_side): - return to_rust_ident(name.replace(side, phy_side).replace("inset-", "")) + return to_rust_ident(to_phys(name, side, phy_side)) %> % if side is not None: use crate::logical_geometry::PhysicalSide; @@ -1080,6 +1085,19 @@ } else { ${caller.inner(physical_ident=phys_ident(size, physical_size[0]))} } + % elif axis is not None: + <% + if axis == "inline": + me, other = "x", "y" + else: + assert(axis == "block") + me, other = "y", "x" + %> + if wm.is_vertical() { + ${caller.inner(physical_ident=phys_ident(axis, other))} + } else { + ${caller.inner(physical_ident=phys_ident(axis, me))} + } % else: <% raise Exception("Don't know what to do with logical property %s" % name) %> % endif diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index f37d5968b24..0a15047038a 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -3,7 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ <%namespace name="helpers" file="/helpers.mako.rs" /> -<% from data import Keyword, Method, to_rust_ident, to_camel_case%> +<% from data import ALL_AXES, Keyword, Method, to_rust_ident, to_camel_case%> <% data.new_style_struct("Box", inherited=False, @@ -114,27 +114,22 @@ ${helpers.single_keyword("-servo-overflow-clip-box", "padding-box content-box", // FIXME(pcwalton, #2742): Implement scrolling for `scroll` and `auto`. // // We allow it to apply to placeholders for UA sheets, which set it !important. -${helpers.predefined_type( - "overflow-x", - "Overflow", - "computed::Overflow::Visible", - animation_value_type="discrete", - flags="APPLIES_TO_PLACEHOLDER", - spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-x", - needs_context=False, - servo_restyle_damage = "reflow", -)} - -${helpers.predefined_type( - "overflow-y", - "Overflow", - "computed::Overflow::Visible", - animation_value_type="discrete", - flags="APPLIES_TO_PLACEHOLDER", - spec="https://drafts.csswg.org/css-overflow/#propdef-overflow-y", - needs_context=False, - servo_restyle_damage = "reflow", -)} +% for (axis, logical) in ALL_AXES: + <% full_name = "overflow-{}".format(axis) %> + ${helpers.predefined_type( + full_name, + "Overflow", + "computed::Overflow::Visible", + logical_group="overflow", + logical=logical, + animation_value_type="discrete", + flags="APPLIES_TO_PLACEHOLDER", + spec="https://drafts.csswg.org/css-overflow-3/#propdef-{}".format(full_name), + needs_context=False, + servo_restyle_damage = "reflow", + gecko_pref="layout.css.overflow-logical.enabled" if logical else None, + )} +% endfor ${helpers.predefined_type( "overflow-anchor",