diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-22 01:46:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 01:46:01 -0500 |
commit | b428a94326322c88da4c32e56ee753ceeffca7d1 (patch) | |
tree | 0ada03d8ed4d26bcf50e39e54df439986e3e8f97 /components/style/properties | |
parent | 8cd4330b2afdaf6f5a1724539a25a27850d41e29 (diff) | |
parent | d06af8971dd9954c7c3217778b8d73f51a658d57 (diff) | |
download | servo-selectors-v0.18.0.tar.gz servo-selectors-v0.18.0.zip |
Auto merge of #16962 - hiikezoe:prefixed-intrinsic-size-value, r=Manishearthselectors-v0.18.0
Prefixed intrinsic size value
<!-- Please describe your changes on the following line: -->
This is a PR for https://bugzilla.mozilla.org/show_bug.cgi?id=1355402
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #16788
- [X] These changes do not require tests because it's for stylo
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16962)
<!-- Reviewable:end -->
Diffstat (limited to 'components/style/properties')
-rw-r--r-- | components/style/properties/gecko.mako.rs | 2 | ||||
-rw-r--r-- | components/style/properties/helpers.mako.rs | 101 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 24 | ||||
-rw-r--r-- | components/style/properties/longhand/position.mako.rs | 149 | ||||
-rw-r--r-- | components/style/properties/shorthand/position.mako.rs | 2 |
5 files changed, 154 insertions, 124 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 0fb75af9d31..7eb66c2fe49 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -675,7 +675,7 @@ impl Debug for ${style_struct.gecko_struct_name} { "LengthOrNone": impl_style_coord, "LengthOrNormal": impl_style_coord, "MaxLength": impl_style_coord, - "MinLength": impl_style_coord, + "MozLength": impl_style_coord, "Number": impl_simple, "Integer": impl_simple, "Opacity": impl_simple, diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 20da42ab58c..b93f7b89413 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -1067,3 +1067,104 @@ } } </%def> + +// Define property that supports prefixed intrinsic size keyword values for gecko. +// E.g. -moz-max-content, -moz-min-content, etc. +<%def name="gecko_size_type(name, length_type, initial_value, logical, **kwargs)"> + <%call expr="longhand(name, + predefined_type=length_type, + logical=logical, + **kwargs)"> + use std::fmt; + use style_traits::ToCss; + % if not logical: + use values::specified::AllowQuirks; + % endif + use values::specified::${length_type}; + + pub mod computed_value { + pub type T = ::values::computed::${length_type}; + } + + #[derive(Clone, Debug, HasViewportPercentage, PartialEq)] + #[cfg_attr(feature = "servo", derive(HeapSizeOf))] + pub struct SpecifiedValue(pub ${length_type}); + + % if length_type == "MozLength": + impl SpecifiedValue { + /// Returns the `auto` value. + pub fn auto() -> Self { + use values::specified::length::LengthOrPercentageOrAuto; + SpecifiedValue(MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto)) + } + + /// Returns a value representing a `0` length. + pub fn zero() -> Self { + use values::specified::length::{LengthOrPercentageOrAuto, NoCalcLength}; + SpecifiedValue(MozLength::LengthOrPercentageOrAuto( + LengthOrPercentageOrAuto::Length(NoCalcLength::zero()))) + } + } + % endif + + #[inline] + pub fn get_initial_value() -> computed_value::T { + use values::computed::${length_type}; + ${length_type}::${initial_value} + } + fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { + % if logical: + let ret = ${length_type}::parse(context, input); + % else: + let ret = ${length_type}::parse_quirky(context, input, AllowQuirks::Yes); + % endif + // Keyword values don't make sense in the block direction; don't parse them + % if "block" in name: + if let Ok(${length_type}::ExtremumLength(..)) = ret { + return Err(()) + } + % endif + ret.map(SpecifiedValue) + } + + impl ToCss for SpecifiedValue { + fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + self.0.to_css(dest) + } + } + + impl ToComputedValue for SpecifiedValue { + type ComputedValue = computed_value::T; + #[inline] + fn to_computed_value(&self, context: &Context) -> computed_value::T { + % if not logical or "block" in name: + use values::computed::${length_type}; + % endif + let computed = self.0.to_computed_value(context); + + // filter out keyword values in the block direction + % if logical: + % if "block" in name: + if let ${length_type}::ExtremumLength(..) = computed { + return get_initial_value() + } + % endif + % else: + if let ${length_type}::ExtremumLength(..) = computed { + <% is_height = "true" if "height" in name else "false" %> + if ${is_height} != context.style().writing_mode.is_vertical() { + return get_initial_value() + } + } + % endif + computed + } + + #[inline] + fn from_computed_value(computed: &computed_value::T) -> Self { + SpecifiedValue(ToComputedValue::from_computed_value(computed)) + } + } + </%call> +</%def> + diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 11fa3956a8a..6ea63347b60 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -41,7 +41,7 @@ use values::{Auto, Either, generics}; use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; use values::computed::{BorderRadiusSize, ClipRect}; use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage}; -use values::computed::{MaxLength, MinLength}; +use values::computed::{MaxLength, MozLength}; use values::computed::ToComputedValue; use values::generics::position as generic_position; @@ -1237,14 +1237,14 @@ impl Animatable for LengthOrPercentageOrNone { } /// https://drafts.csswg.org/css-transitions/#animtype-lpcalc -impl Animatable for MinLength { +impl Animatable for MozLength { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { match (*self, *other) { - (MinLength::LengthOrPercentage(ref this), - MinLength::LengthOrPercentage(ref other)) => { + (MozLength::LengthOrPercentageOrAuto(ref this), + MozLength::LengthOrPercentageOrAuto(ref other)) => { this.add_weighted(other, self_portion, other_portion) - .map(MinLength::LengthOrPercentage) + .map(MozLength::LengthOrPercentageOrAuto) } _ => Err(()), } @@ -1253,8 +1253,8 @@ impl Animatable for MinLength { #[inline] fn compute_distance(&self, other: &Self) -> Result<f64, ()> { match (*self, *other) { - (MinLength::LengthOrPercentage(ref this), - MinLength::LengthOrPercentage(ref other)) => { + (MozLength::LengthOrPercentageOrAuto(ref this), + MozLength::LengthOrPercentageOrAuto(ref other)) => { this.compute_distance(other) }, _ => Err(()), @@ -1267,10 +1267,10 @@ impl Animatable for MaxLength { #[inline] fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> { match (*self, *other) { - (MaxLength::LengthOrPercentage(ref this), - MaxLength::LengthOrPercentage(ref other)) => { + (MaxLength::LengthOrPercentageOrNone(ref this), + MaxLength::LengthOrPercentageOrNone(ref other)) => { this.add_weighted(other, self_portion, other_portion) - .map(MaxLength::LengthOrPercentage) + .map(MaxLength::LengthOrPercentageOrNone) } _ => Err(()), } @@ -1279,8 +1279,8 @@ impl Animatable for MaxLength { #[inline] fn compute_distance(&self, other: &Self) -> Result<f64, ()> { match (*self, *other) { - (MaxLength::LengthOrPercentage(ref this), - MaxLength::LengthOrPercentage(ref other)) => { + (MaxLength::LengthOrPercentageOrNone(ref this), + MaxLength::LengthOrPercentageOrNone(ref other)) => { this.compute_distance(other) }, _ => Err(()), diff --git a/components/style/properties/longhand/position.mako.rs b/components/style/properties/longhand/position.mako.rs index da7fe080604..324b0112f02 100644 --- a/components/style/properties/longhand/position.mako.rs +++ b/components/style/properties/longhand/position.mako.rs @@ -134,125 +134,54 @@ ${helpers.predefined_type("order", "Integer", "0", animation_value_type="ComputedValue", spec="https://drafts.csswg.org/css-flexbox/#order-property")} -// FIXME: Gecko doesn't support content value yet. -// FIXME: This property should be animatable. -${helpers.predefined_type("flex-basis", - "LengthOrPercentageOrAuto" if product == "gecko" else - "LengthOrPercentageOrAutoOrContent", - "computed::LengthOrPercentageOrAuto::Auto" if product == "gecko" else - "computed::LengthOrPercentageOrAutoOrContent::Auto", - "parse_non_negative", - spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", - extra_prefixes="webkit", - animation_value_type="ComputedValue" if product == "gecko" else "none")} - +% if product == "gecko": + // FIXME: Gecko doesn't support content value yet. + ${helpers.gecko_size_type("flex-basis", "MozLength", "auto()", + logical=False, + spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", + extra_prefixes="webkit", + animation_value_type="ComputedValue")} +% else: + // FIXME: This property should be animatable. + ${helpers.predefined_type("flex-basis", + "LengthOrPercentageOrAutoOrContent", + "computed::LengthOrPercentageOrAutoOrContent::Auto", + "parse_non_negative", + spec="https://drafts.csswg.org/css-flexbox/#flex-basis-property", + extra_prefixes="webkit", + animation_value_type="none")} +% endif % for (size, logical) in ALL_SIZES: <% spec = "https://drafts.csswg.org/css-box/#propdef-%s" if logical: spec = "https://drafts.csswg.org/css-logical-props/#propdef-%s" %> - // width, height, block-size, inline-size - ${helpers.predefined_type("%s" % size, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", - "parse_non_negative", - spec=spec % size, - allow_quirks=not logical, - animation_value_type="ComputedValue", logical = logical)} % if product == "gecko": - % for min_max in ["min", "max"]: - <% - MinMax = min_max.title() - initial = "None" if "max" == min_max else "Auto" - %> - - // min-width, min-height, min-block-size, min-inline-size, - // max-width, max-height, max-block-size, max-inline-size - // - // Keyword values are only valid in the inline direction; they must - // be replaced with auto/none in block. - <%helpers:longhand name="${min_max}-${size}" spec="${spec % ('%s-%s' % (min_max, size))}" - animation_value_type="ComputedValue" - logical="${logical}" predefined_type="${MinMax}Length"> - - use std::fmt; - use style_traits::ToCss; - % if not logical: - use values::specified::AllowQuirks; - % endif - use values::specified::${MinMax}Length; - - pub mod computed_value { - pub type T = ::values::computed::${MinMax}Length; - } - - #[derive(Clone, Debug, HasViewportPercentage, PartialEq)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct SpecifiedValue(${MinMax}Length); - - #[inline] - pub fn get_initial_value() -> computed_value::T { - use values::computed::${MinMax}Length; - ${MinMax}Length::${initial} - } - fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> { - % if logical: - let ret = ${MinMax}Length::parse(context, input); - % else: - let ret = ${MinMax}Length::parse_quirky(context, input, AllowQuirks::Yes); - % endif - // Keyword values don't make sense in the block direction; don't parse them - % if "block" in size: - if let Ok(${MinMax}Length::ExtremumLength(..)) = ret { - return Err(()) - } - % endif - ret.map(SpecifiedValue) - } - - impl ToCss for SpecifiedValue { - fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.0.to_css(dest) - } - } - - impl ToComputedValue for SpecifiedValue { - type ComputedValue = computed_value::T; - #[inline] - fn to_computed_value(&self, context: &Context) -> computed_value::T { - % if not logical or "block" in size: - use values::computed::${MinMax}Length; - % endif - let computed = self.0.to_computed_value(context); - - // filter out keyword values in the block direction - % if logical: - % if "block" in size: - if let ${MinMax}Length::ExtremumLength(..) = computed { - return get_initial_value() - } - % endif - % else: - if let ${MinMax}Length::ExtremumLength(..) = computed { - <% is_height = "true" if "height" in size else "false" %> - if ${is_height} != context.style().writing_mode.is_vertical() { - return get_initial_value() - } - } - % endif - computed - } - - #[inline] - fn from_computed_value(computed: &computed_value::T) -> Self { - SpecifiedValue(ToComputedValue::from_computed_value(computed)) - } - } - </%helpers:longhand> - % endfor + // width, height, block-size, inline-size + ${helpers.gecko_size_type("%s" % size, "MozLength", "auto()", + logical, + spec=spec % size, + animation_value_type="ComputedValue")} + // min-width, min-height, min-block-size, min-inline-size, + // max-width, max-height, max-block-size, max-inline-size + ${helpers.gecko_size_type("min-%s" % size, "MozLength", "auto()", + logical, + spec=spec % size, + animation_value_type="ComputedValue")} + ${helpers.gecko_size_type("max-%s" % size, "MaxLength", "none()", + logical, + spec=spec % size, + animation_value_type="ComputedValue")} % else: // servo versions (no keyword support) + ${helpers.predefined_type("%s" % size, + "LengthOrPercentageOrAuto", + "computed::LengthOrPercentageOrAuto::Auto", + "parse_non_negative", + spec=spec % size, + allow_quirks=not logical, + animation_value_type="ComputedValue", logical = logical)} ${helpers.predefined_type("min-%s" % size, "LengthOrPercentage", "computed::LengthOrPercentage::Length(Au(0))", diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 423e1657d9b..11b2cd41b0b 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -78,7 +78,7 @@ } } if basis.is_none() { - if let Ok(value) = input.try(|input| longhands::flex_basis::parse(context, input)) { + if let Ok(value) = input.try(|input| longhands::flex_basis::parse_specified(context, input)) { basis = Some(value); continue } |