From 6a887234096900246cfab98a424c68fb140e5ab3 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 2 Jan 2017 14:55:52 -0800 Subject: [PATCH] Support logical values for float/clear --- components/style/properties/helpers.mako.rs | 17 +++-- .../style/properties/longhand/box.mako.rs | 65 ++++++++++++++++--- .../style/properties/properties.mako.rs | 2 +- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 689a179df3f..13e727c3168 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -338,7 +338,7 @@ -<%def name="single_keyword_computed(name, values, vector=False, **kwargs)"> +<%def name="single_keyword_computed(name, values, vector=False, extra_specified=None, **kwargs)"> <% keyword_kwargs = {a: kwargs.pop(a, None) for a in [ 'gecko_constant_prefix', 'gecko_enum_prefix', @@ -348,7 +348,16 @@ %> <%def name="inner_body()"> - pub use self::computed_value::T as SpecifiedValue; + % if extra_specified: + use style_traits::ToCss; + define_css_keyword_enum! { SpecifiedValue: + % for value in data.longhands_by_name[name].keyword.values_for(product) + extra_specified.split(): + "${value}" => ${to_rust_ident(value)}, + % endfor + } + % else: + pub use self::computed_value::T as SpecifiedValue; + % endif pub mod computed_value { use style_traits::ToCss; define_css_keyword_enum! { T: @@ -363,12 +372,12 @@ } #[inline] pub fn get_initial_specified_value() -> SpecifiedValue { - get_initial_value() + SpecifiedValue::${to_rust_ident(values.split()[0])} } #[inline] pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result { - computed_value::T::parse(input) + SpecifiedValue::parse(input) } % if vector: diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 8064f31e851..6819368502e 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -98,9 +98,10 @@ ${helpers.single_keyword("position", "static absolute relative fixed", need_clone=True, extra_gecko_values="sticky", animatable=False, spec="https://drafts.csswg.org/css-position/#position-property")} -// TODO add support for logical values inline-start and inline-end (https://drafts.csswg.org/css-logical-props/#float-clear) <%helpers:single_keyword_computed name="float" values="none left right" + // https://drafts.csswg.org/css-logical-props/#float-clear + extra_specified="inline-start inline-end" animatable="False" need_clone="True" gecko_enum_prefix="StyleFloat" @@ -118,23 +119,69 @@ ${helpers.single_keyword("position", "static absolute relative fixed", longhands::position::SpecifiedValue::absolute | longhands::position::SpecifiedValue::fixed); if positioned { - SpecifiedValue::none + computed_value::T::none } else { - *self + let ltr = context.style().writing_mode.is_bidi_ltr(); + // https://drafts.csswg.org/css-logical-props/#float-clear + match *self { + SpecifiedValue::inline_start if ltr => computed_value::T::left, + SpecifiedValue::inline_start => computed_value::T::right, + SpecifiedValue::inline_end if ltr => computed_value::T::right, + SpecifiedValue::inline_end => computed_value::T::left, + % for value in "none left right".split(): + SpecifiedValue::${value} => computed_value::T::${value}, + % endfor + } } } #[inline] fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue { - *computed + match *computed { + % for value in "none left right".split(): + computed_value::T::${value} => SpecifiedValue::${value}, + % endfor + } } } - -${helpers.single_keyword("clear", "none left right both", - animatable=False, gecko_ffi_name="mBreakType", - gecko_enum_prefix="StyleClear", - spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control")} +<%helpers:single_keyword_computed name="clear" + values="none left right both" + // https://drafts.csswg.org/css-logical-props/#float-clear + extra_specified="inline-start inline-end" + animatable="False" + gecko_enum_prefix="StyleClear" + gecko_ffi_name="mBreakType" + spec="https://www.w3.org/TR/CSS2/visuren.html#flow-control"> + use values::NoViewportPercentage; + impl NoViewportPercentage for SpecifiedValue {} + impl ToComputedValue for SpecifiedValue { + type ComputedValue = computed_value::T; + + #[inline] + fn to_computed_value(&self, context: &Context) -> computed_value::T { + let ltr = context.style().writing_mode.is_bidi_ltr(); + // https://drafts.csswg.org/css-logical-props/#float-clear + match *self { + SpecifiedValue::inline_start if ltr => computed_value::T::left, + SpecifiedValue::inline_start => computed_value::T::right, + SpecifiedValue::inline_end if ltr => computed_value::T::right, + SpecifiedValue::inline_end => computed_value::T::left, + % for value in "none left right both".split(): + SpecifiedValue::${value} => computed_value::T::${value}, + % endfor + } + } + #[inline] + fn from_computed_value(computed: &computed_value::T) -> SpecifiedValue { + match *computed { + % for value in "none left right both".split(): + computed_value::T::${value} => SpecifiedValue::${value}, + % endfor + } + } + } + <%helpers:longhand name="-servo-display-for-hypothetical-box" animatable="False" diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 75ea5dff3d5..647a5e7539d 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1891,7 +1891,7 @@ pub fn apply_declarations<'a, F, I>(viewport_size: Size2D, let positioned = matches!(style.get_box().clone_position(), longhands::position::SpecifiedValue::absolute | longhands::position::SpecifiedValue::fixed); - let floated = style.get_box().clone_float() != longhands::float::SpecifiedValue::none; + let floated = style.get_box().clone_float() != longhands::float::computed_value::T::none; // FIXME(heycam): We should look past any display:contents ancestors to // determine if we are a flex or grid item, but we don't have access to // grandparent or higher style here.