From ca503b4908cb45c20cc6777f9d01253057a86a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 6 Jan 2019 23:01:00 +0100 Subject: [PATCH 1/6] style: Simplify computed::LengthOrPercentage and friends. This is a first step to share LengthOrPercentage representation between Rust and Gecko. We need to preserve whether the value came from a calc() expression, for now at least, since we do different things depending on whether we're calc or not right now. See https://github.com/w3c/csswg-drafts/issues/3482 and dependent bugs for example. That means that the gecko conversion code needs to handle calc() in a bit of an awkward way until I change it to not be needed (patches for that incoming in the next few weeks I hope). I need to add a hack to exclude other things from the PartialEq implementation because the new conversion code is less lossy than the old one, and we relied on the lousiness in AnimationValue comparison (in order to start transitions and such, in [1] for example). I expect to remove that manual PartialEq implementation as soon as I'm done with the conversion. The less lossy conversion does fix a few serialization bugs for animation values though, like not loosing 0% values in calc() when interpolating lengths and percentages, see the two modified tests: * property-types.js * test_animation_properties.html Differential Revision: https://phabricator.services.mozilla.com/D15793 --- components/style/gecko/conversions.rs | 97 +--- components/style/gecko/values.rs | 56 +-- .../gecko_bindings/sugar/ns_css_value.rs | 20 +- components/style/properties/gecko.mako.rs | 15 +- .../longhands/inherited_text.mako.rs | 2 +- .../style/properties/longhands/margin.mako.rs | 2 +- components/style/stylesheets/viewport_rule.rs | 16 +- components/style/values/animated/length.rs | 63 +-- components/style/values/animated/mod.rs | 4 +- components/style/values/animated/svg.rs | 16 +- components/style/values/animated/transform.rs | 25 +- components/style/values/computed/image.rs | 13 +- components/style/values/computed/length.rs | 465 +++++++----------- components/style/values/computed/mod.rs | 2 +- components/style/values/computed/position.rs | 4 +- components/style/values/computed/transform.rs | 4 +- components/style/values/generics/text.rs | 5 +- components/style/values/generics/transform.rs | 10 +- components/style/values/specified/font.rs | 4 +- components/style/values/specified/length.rs | 128 +---- components/style/values/specified/position.rs | 27 +- .../style/values/specified/transform.rs | 4 +- 22 files changed, 338 insertions(+), 644 deletions(-) diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 266ebbd750a..08d0557f896 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -20,7 +20,7 @@ use crate::stylesheets::{Origin, RulesMutateError}; use crate::values::computed::image::LineDirection; use crate::values::computed::transform::Matrix3D; use crate::values::computed::url::ComputedImageUrl; -use crate::values::computed::{Angle, CalcLengthOrPercentage, Gradient, Image}; +use crate::values::computed::{Angle, Gradient, Image}; use crate::values::computed::{Integer, LengthOrPercentage}; use crate::values::computed::{LengthOrPercentageOrAuto, NonNegativeLengthOrPercentageOrAuto}; use crate::values::computed::{Percentage, TextAlign}; @@ -31,9 +31,10 @@ use crate::values::generics::rect::Rect; use crate::values::generics::NonNegative; use app_units::Au; use std::f32::consts::PI; +use style_traits::values::specified::AllowedNumericType; -impl From for nsStyleCoord_CalcValue { - fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { +impl From for nsStyleCoord_CalcValue { + fn from(other: LengthOrPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { mLength: other.unclamped_length().to_i32_au(), @@ -43,32 +44,19 @@ impl From for nsStyleCoord_CalcValue { } } -impl From for CalcLengthOrPercentage { - fn from(other: nsStyleCoord_CalcValue) -> CalcLengthOrPercentage { +impl From for LengthOrPercentage { + fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentage { let percentage = if other.mHasPercent { Some(Percentage(other.mPercent)) } else { None }; - Self::new(Au(other.mLength).into(), percentage) - } -} - -impl From for nsStyleCoord_CalcValue { - fn from(other: LengthOrPercentage) -> nsStyleCoord_CalcValue { - match other { - LengthOrPercentage::Length(px) => nsStyleCoord_CalcValue { - mLength: px.to_i32_au(), - mPercent: 0.0, - mHasPercent: false, - }, - LengthOrPercentage::Percentage(pc) => nsStyleCoord_CalcValue { - mLength: 0, - mPercent: pc.0, - mHasPercent: true, - }, - LengthOrPercentage::Calc(calc) => calc.into(), - } + Self::with_clamping_mode( + Au(other.mLength).into(), + percentage, + AllowedNumericType::All, + /* was_calc = */ true, + ) } } @@ -76,39 +64,15 @@ impl LengthOrPercentageOrAuto { /// Convert this value in an appropriate `nsStyleCoord::CalcValue`. pub fn to_calc_value(&self) -> Option { match *self { - LengthOrPercentageOrAuto::Length(px) => Some(nsStyleCoord_CalcValue { - mLength: px.to_i32_au(), - mPercent: 0.0, - mHasPercent: false, - }), - LengthOrPercentageOrAuto::Percentage(pc) => Some(nsStyleCoord_CalcValue { - mLength: 0, - mPercent: pc.0, - mHasPercent: true, - }), - LengthOrPercentageOrAuto::Calc(calc) => Some(calc.into()), + LengthOrPercentageOrAuto::LengthOrPercentage(len) => Some(From::from(len)), LengthOrPercentageOrAuto::Auto => None, } } } -impl From for LengthOrPercentage { - fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentage { - match (other.mHasPercent, other.mLength) { - (false, _) => LengthOrPercentage::Length(Au(other.mLength).into()), - (true, 0) => LengthOrPercentage::Percentage(Percentage(other.mPercent)), - _ => LengthOrPercentage::Calc(other.into()), - } - } -} - impl From for LengthOrPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentageOrAuto { - match (other.mHasPercent, other.mLength) { - (false, _) => LengthOrPercentageOrAuto::Length(Au(other.mLength).into()), - (true, 0) => LengthOrPercentageOrAuto::Percentage(Percentage(other.mPercent)), - _ => LengthOrPercentageOrAuto::Calc(other.into()), - } + LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::from(other)) } } @@ -116,9 +80,8 @@ impl From for LengthOrPercentageOrAuto { // disappear as we move more stuff to cbindgen. impl From for NonNegativeLengthOrPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> Self { - use style_traits::values::specified::AllowedNumericType; - NonNegative(if other.mLength < 0 || other.mPercent < 0. { - LengthOrPercentageOrAuto::Calc(CalcLengthOrPercentage::with_clamping_mode( + NonNegative( + LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::with_clamping_mode( Au(other.mLength).into(), if other.mHasPercent { Some(Percentage(other.mPercent)) @@ -126,10 +89,9 @@ impl From for NonNegativeLengthOrPercentageOrAuto { None }, AllowedNumericType::NonNegative, + /* was_calc = */ true, )) - } else { - other.into() - }) + ) } } @@ -143,20 +105,13 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) use crate::values::computed::position::Position; use crate::values::specified::position::{X, Y}; - let horizontal_percentage = match horizontal { - LengthOrPercentage::Percentage(percentage) => Some(percentage.0), - _ => None, - }; - - let vertical_percentage = match vertical { - LengthOrPercentage::Percentage(percentage) => Some(percentage.0), - _ => None, - }; + let horizontal_percentage = horizontal.as_percentage(); + let vertical_percentage = vertical.as_percentage(); let horizontal_as_corner = horizontal_percentage.and_then(|percentage| { - if percentage == 0.0 { + if percentage.0 == 0.0 { Some(X::Left) - } else if percentage == 1.0 { + } else if percentage.0 == 1.0 { Some(X::Right) } else { None @@ -164,9 +119,9 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) }); let vertical_as_corner = vertical_percentage.and_then(|percentage| { - if percentage == 0.0 { + if percentage.0 == 0.0 { Some(Y::Top) - } else if percentage == 1.0 { + } else if percentage.0 == 1.0 { Some(Y::Bottom) } else { None @@ -178,13 +133,13 @@ fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) } if let Some(hc) = horizontal_as_corner { - if vertical_percentage == Some(0.5) { + if vertical_percentage == Some(Percentage(0.5)) { return LineDirection::Horizontal(hc); } } if let Some(vc) = vertical_as_corner { - if horizontal_percentage == Some(0.5) { + if horizontal_percentage == Some(Percentage(0.5)) { return LineDirection::Vertical(vc); } } diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 39a5ac2de89..3c11d11e311 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -148,19 +148,21 @@ impl GeckoStyleCoordConvertible for NumberOrPercentage { impl GeckoStyleCoordConvertible for LengthOrPercentage { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentage::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentage::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentage::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + if self.was_calc { + return coord.set_value(CoordDataValue::Calc((*self).into())) + } + debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); + if let Some(p) = self.percentage { + return coord.set_value(CoordDataValue::Percent(p.0)); + } + coord.set_value(CoordDataValue::Coord(self.unclamped_length().to_i32_au())) } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => Some(LengthOrPercentage::Length(Au(coord).into())), - CoordDataValue::Percent(p) => Some(LengthOrPercentage::Percentage(Percentage(p))), - CoordDataValue::Calc(calc) => Some(LengthOrPercentage::Calc(calc.into())), + CoordDataValue::Coord(coord) => Some(LengthOrPercentage::new(Au(coord).into(), None)), + CoordDataValue::Percent(p) => Some(LengthOrPercentage::new(Au(0).into(), Some(Percentage(p)))), + CoordDataValue::Calc(calc) => Some(calc.into()), _ => None, } } @@ -181,48 +183,32 @@ impl GeckoStyleCoordConvertible for Length { impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentageOrAuto::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentageOrAuto::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentageOrAuto::Auto => CoordDataValue::Auto, - LengthOrPercentageOrAuto::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + match *self { + LengthOrPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto), + LengthOrPercentageOrAuto::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), + } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => { - Some(LengthOrPercentageOrAuto::Length(Au(coord).into())) - }, - CoordDataValue::Percent(p) => Some(LengthOrPercentageOrAuto::Percentage(Percentage(p))), CoordDataValue::Auto => Some(LengthOrPercentageOrAuto::Auto), - CoordDataValue::Calc(calc) => Some(LengthOrPercentageOrAuto::Calc(calc.into())), - _ => None, + _ => LengthOrPercentage::from_gecko_style_coord(coord).map(LengthOrPercentageOrAuto::LengthOrPercentage), } } } impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { fn to_gecko_style_coord(&self, coord: &mut T) { - let value = match *self { - LengthOrPercentageOrNone::Length(px) => CoordDataValue::Coord(px.to_i32_au()), - LengthOrPercentageOrNone::Percentage(p) => CoordDataValue::Percent(p.0), - LengthOrPercentageOrNone::None => CoordDataValue::None, - LengthOrPercentageOrNone::Calc(calc) => CoordDataValue::Calc(calc.into()), - }; - coord.set_value(value); + match *self { + LengthOrPercentageOrNone::None => coord.set_value(CoordDataValue::None), + LengthOrPercentageOrNone::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), + } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => { - Some(LengthOrPercentageOrNone::Length(Au(coord).into())) - }, - CoordDataValue::Percent(p) => Some(LengthOrPercentageOrNone::Percentage(Percentage(p))), CoordDataValue::None => Some(LengthOrPercentageOrNone::None), - CoordDataValue::Calc(calc) => Some(LengthOrPercentageOrNone::Calc(calc.into())), - _ => None, + _ => LengthOrPercentage::from_gecko_style_coord(coord).map(LengthOrPercentageOrNone::LengthOrPercentage), } } } diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index aa4f9947cd2..f9ed43f7a3d 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -69,11 +69,14 @@ impl nsCSSValue { /// Sets LengthOrPercentage value to this nsCSSValue. pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) { - match lop { - LengthOrPercentage::Length(px) => self.set_px(px.px()), - LengthOrPercentage::Percentage(pc) => self.set_percentage(pc.0), - LengthOrPercentage::Calc(calc) => bindings::Gecko_CSSValue_SetCalc(self, calc.into()), + if lop.was_calc { + return bindings::Gecko_CSSValue_SetCalc(self, lop.into()) } + debug_assert!(lop.percentage.is_none() || lop.unclamped_length() == Length::zero()); + if let Some(p) = lop.percentage { + return self.set_percentage(p.0); + } + self.set_px(lop.unclamped_length().px()); } /// Sets a px value to this nsCSSValue. @@ -90,13 +93,16 @@ impl nsCSSValue { pub unsafe fn get_lop(&self) -> LengthOrPercentage { match self.mUnit { nsCSSUnit::eCSSUnit_Pixel => { - LengthOrPercentage::Length(Length::new(bindings::Gecko_CSSValue_GetNumber(self))) + LengthOrPercentage::new( + Length::new(bindings::Gecko_CSSValue_GetNumber(self)), + None, + ) }, - nsCSSUnit::eCSSUnit_Percent => LengthOrPercentage::Percentage(Percentage( + nsCSSUnit::eCSSUnit_Percent => LengthOrPercentage::new_percent(Percentage( bindings::Gecko_CSSValue_GetPercentage(self), )), nsCSSUnit::eCSSUnit_Calc => { - LengthOrPercentage::Calc(bindings::Gecko_CSSValue_GetCalc(self).into()) + bindings::Gecko_CSSValue_GetCalc(self).into() }, _ => panic!("Unexpected unit"), } diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index d969f14f54a..036653d218e 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -558,18 +558,16 @@ def set_gecko_property(ffi_name, expr): }, CoordDataValue::Coord(coord) => { SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Length(Au(coord).into()) + LengthOrPercentage::new(Au(coord).into(), None) ) }, CoordDataValue::Percent(p) => { SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(Percentage(p)) + LengthOrPercentage::new(Au(0).into(), Some(Percentage(p))) ) }, CoordDataValue::Calc(calc) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Calc(calc.into()) - ) + SvgLengthOrPercentageOrNumber::LengthOrPercentage(calc.into()) }, _ => unreachable!("Unexpected coordinate in ${ident}"), }; @@ -5062,6 +5060,7 @@ clip-path pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T { use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE; use crate::values::computed::LengthOrPercentage; + use crate::values::generics::NonNegative; use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthOrPercentageOrNumber}; if self.gecko.mContextFlags & CONTEXT_VALUE != 0 { @@ -5075,13 +5074,13 @@ clip-path vec.push(SvgLengthOrPercentageOrNumber::Number(number.into())), CoordDataValue::Coord(coord) => vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Length(Au(coord).into()).into())), + NonNegative(LengthOrPercentage::new(Au(coord).into(), None).into()))), CoordDataValue::Percent(p) => vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(Percentage(p)).into())), + NonNegative(LengthOrPercentage::new_percent(Percentage(p)).into()))), CoordDataValue::Calc(calc) => vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Calc(calc.into()).into())), + NonNegative(LengthOrPercentage::from(calc).clamp_to_non_negative()))), _ => unreachable!(), } } diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 5a7b88e3823..3eded4ea7ac 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -54,7 +54,7 @@ ${helpers.single_keyword( ${helpers.predefined_type( "text-indent", "LengthOrPercentage", - "computed::LengthOrPercentage::Length(computed::Length::new(0.))", + "computed::LengthOrPercentage::zero()", animation_value_type="ComputedValue", spec="https://drafts.csswg.org/css-text/#propdef-text-indent", allow_quirks=True, diff --git a/components/style/properties/longhands/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs index 822fbf798a7..7762be1a23a 100644 --- a/components/style/properties/longhands/margin.mako.rs +++ b/components/style/properties/longhands/margin.mako.rs @@ -15,7 +15,7 @@ ${helpers.predefined_type( "margin-%s" % side[0], "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Length(computed::Length::new(0.))", + "computed::LengthOrPercentageOrAuto::zero()", alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), allow_quirks=not side[1], animation_value_type="ComputedValue", diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index 4df576a15ab..209243228df 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -18,7 +18,7 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard use crate::str::CssStringWriter; use crate::stylesheets::{Origin, StylesheetInDocument}; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::specified::{LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; +use crate::values::specified::{self, LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; use app_units::Au; use cssparser::CowRcStr; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; @@ -157,7 +157,9 @@ impl FromMeta for ViewportLength { fn from_meta(value: &str) -> Option { macro_rules! specified { ($value:expr) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length($value)) + ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length($value) + )) }; } @@ -752,16 +754,10 @@ impl MaybeNew for ViewportConstraints { if let Some($value) = $value { match *$value { ViewportLength::Specified(ref length) => match *length { - LengthOrPercentageOrAuto::Length(ref value) => { - Some(Au::from(value.to_computed_value(&context))) - }, - LengthOrPercentageOrAuto::Percentage(value) => { - Some(initial_viewport.$dimension.scale_by(value.0)) - }, LengthOrPercentageOrAuto::Auto => None, - LengthOrPercentageOrAuto::Calc(ref calc) => calc + LengthOrPercentageOrAuto::LengthOrPercentage(ref lop) => Some(lop .to_computed_value(&context) - .to_used_value(Some(initial_viewport.$dimension)), + .to_used_value(initial_viewport.$dimension)), }, ViewportLength::ExtendToZoom => { // $extend_to will be 'None' if 'extend-to-zoom' is 'auto' diff --git a/components/style/values/animated/length.rs b/components/style/values/animated/length.rs index e303d2fcfce..b0d717b0e49 100644 --- a/components/style/values/animated/length.rs +++ b/components/style/values/animated/length.rs @@ -4,15 +4,14 @@ //! Animation implementation for various length-related types. -use super::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; -use crate::values::computed::length::{CalcLengthOrPercentage, Length}; -use crate::values::computed::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +use super::{Animate, Procedure, ToAnimatedValue}; +use crate::values::computed::length::LengthOrPercentage; use crate::values::computed::MaxLength as ComputedMaxLength; use crate::values::computed::MozLength as ComputedMozLength; use crate::values::computed::Percentage; /// -impl Animate for CalcLengthOrPercentage { +impl Animate for LengthOrPercentage { #[inline] fn animate(&self, other: &Self, procedure: Procedure) -> Result { let animate_percentage_half = |this: Option, other: Option| { @@ -28,42 +27,17 @@ impl Animate for CalcLengthOrPercentage { .unclamped_length() .animate(&other.unclamped_length(), procedure)?; let percentage = animate_percentage_half(self.percentage, other.percentage)?; - Ok(CalcLengthOrPercentage::with_clamping_mode( + let is_calc = self.was_calc || other.was_calc || self.percentage.is_some() != other.percentage.is_some(); + Ok(Self::with_clamping_mode( length, percentage, self.clamping_mode, + is_calc, )) } } -impl ToAnimatedZero for LengthOrPercentageOrAuto { - #[inline] - fn to_animated_zero(&self) -> Result { - match *self { - LengthOrPercentageOrAuto::Length(_) | - LengthOrPercentageOrAuto::Percentage(_) | - LengthOrPercentageOrAuto::Calc(_) => { - Ok(LengthOrPercentageOrAuto::Length(Length::new(0.))) - }, - LengthOrPercentageOrAuto::Auto => Err(()), - } - } -} - -impl ToAnimatedZero for LengthOrPercentageOrNone { - #[inline] - fn to_animated_zero(&self) -> Result { - match *self { - LengthOrPercentageOrNone::Length(_) | - LengthOrPercentageOrNone::Percentage(_) | - LengthOrPercentageOrNone::Calc(_) => { - Ok(LengthOrPercentageOrNone::Length(Length::new(0.))) - }, - LengthOrPercentageOrNone::None => Err(()), - } - } -} - +// FIXME(emilio): These should use NonNegative<> instead. impl ToAnimatedValue for ComputedMaxLength { type AnimatedValue = Self; @@ -74,18 +48,15 @@ impl ToAnimatedValue for ComputedMaxLength { #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::{Length, LengthOrPercentageOrNone, Percentage}; + use crate::values::computed::LengthOrPercentageOrNone; use crate::values::generics::length::MaxLength as GenericMaxLength; match animated { GenericMaxLength::LengthOrPercentageOrNone(lopn) => { let result = match lopn { - LengthOrPercentageOrNone::Length(px) => { - LengthOrPercentageOrNone::Length(Length::new(px.px().max(0.))) + LengthOrPercentageOrNone::LengthOrPercentage(len) => { + LengthOrPercentageOrNone::LengthOrPercentage(len.clamp_to_non_negative()) }, - LengthOrPercentageOrNone::Percentage(percentage) => { - LengthOrPercentageOrNone::Percentage(Percentage(percentage.0.max(0.))) - }, - _ => lopn, + LengthOrPercentageOrNone::None => lopn, }; GenericMaxLength::LengthOrPercentageOrNone(result) }, @@ -104,20 +75,10 @@ impl ToAnimatedValue for ComputedMozLength { #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::{Length, LengthOrPercentageOrAuto, Percentage}; use crate::values::generics::length::MozLength as GenericMozLength; match animated { GenericMozLength::LengthOrPercentageOrAuto(lopa) => { - let result = match lopa { - LengthOrPercentageOrAuto::Length(px) => { - LengthOrPercentageOrAuto::Length(Length::new(px.px().max(0.))) - }, - LengthOrPercentageOrAuto::Percentage(percentage) => { - LengthOrPercentageOrAuto::Percentage(Percentage(percentage.0.max(0.))) - }, - _ => lopa, - }; - GenericMozLength::LengthOrPercentageOrAuto(result) + GenericMozLength::LengthOrPercentageOrAuto(lopa.clamp_to_non_negative()) }, _ => animated, } diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index a7c947f810a..1655f2eaa26 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -9,7 +9,7 @@ //! module's raison d'être is to ultimately contain all these types. use crate::properties::PropertyId; -use crate::values::computed::length::CalcLengthOrPercentage; +use crate::values::computed::length::LengthOrPercentage; use crate::values::computed::url::ComputedUrl; use crate::values::computed::Angle as ComputedAngle; use crate::values::computed::Image; @@ -335,7 +335,7 @@ macro_rules! trivial_to_animated_value { } trivial_to_animated_value!(Au); -trivial_to_animated_value!(CalcLengthOrPercentage); +trivial_to_animated_value!(LengthOrPercentage); trivial_to_animated_value!(ComputedAngle); trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); diff --git a/components/style/values/animated/svg.rs b/components/style/values/animated/svg.rs index 1d8be90fb6e..7123542aef8 100644 --- a/components/style/values/animated/svg.rs +++ b/components/style/values/animated/svg.rs @@ -32,10 +32,16 @@ fn to_number_or_percentage( value: &SvgLengthOrPercentageOrNumber, ) -> Result { Ok(match *value { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref l) => match *l { - LengthOrPercentage::Length(ref l) => NumberOrPercentage::Number(l.px()), - LengthOrPercentage::Percentage(ref p) => NumberOrPercentage::Percentage(*p), - LengthOrPercentage::Calc(..) => return Err(()), + SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref l) => { + match l.percentage { + Some(p) => { + if l.unclamped_length().px() != 0. { + return Err(()); + } + NumberOrPercentage::Percentage(p) + } + None => NumberOrPercentage::Number(l.length().px()) + } }, SvgLengthOrPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), }) @@ -55,7 +61,7 @@ impl Animate for SvgLengthOrPercentageOrNumber { NumberOrPercentage::Percentage(ref this), NumberOrPercentage::Percentage(ref other), ) => Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::Percentage(this.animate(other, procedure)?), + LengthOrPercentage::new_percent(this.animate(other, procedure)?), )), _ => Err(()), } diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index 5223a195075..2804f4c0890 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -1167,17 +1167,6 @@ impl Animate for ComputedTransformOperation { // See https://bugzilla.mozilla.org/show_bug.cgi?id=1318591#c0. impl ComputeSquaredDistance for ComputedTransformOperation { fn compute_squared_distance(&self, other: &Self) -> Result { - // For translate, We don't want to require doing layout in order to calculate the result, so - // drop the percentage part. However, dropping percentage makes us impossible to - // compute the distance for the percentage-percentage case, but Gecko uses the - // same formula, so it's fine for now. - // Note: We use pixel value to compute the distance for translate, so we have to - // convert Au into px. - let extract_pixel_length = |lop: &LengthOrPercentage| match *lop { - LengthOrPercentage::Length(px) => px.px(), - LengthOrPercentage::Percentage(_) => 0., - LengthOrPercentage::Calc(calc) => calc.length().px(), - }; match (self, other) { (&TransformOperation::Matrix3D(ref this), &TransformOperation::Matrix3D(ref other)) => { this.compute_squared_distance(other) @@ -1199,10 +1188,16 @@ impl ComputeSquaredDistance for ComputedTransformOperation { &TransformOperation::Translate3D(ref fx, ref fy, ref fz), &TransformOperation::Translate3D(ref tx, ref ty, ref tz), ) => { - let fx = extract_pixel_length(&fx); - let fy = extract_pixel_length(&fy); - let tx = extract_pixel_length(&tx); - let ty = extract_pixel_length(&ty); + // For translate, We don't want to require doing layout in order + // to calculate the result, so drop the percentage part. + // + // However, dropping percentage makes us impossible to compute + // the distance for the percentage-percentage case, but Gecko + // uses the same formula, so it's fine for now. + let fx = fx.length_component().px(); + let fy = fy.length_component().px(); + let tx = tx.length_component().px(); + let ty = ty.length_component().px(); Ok(fx.compute_squared_distance(&tx)? + fy.compute_squared_distance(&ty)? + diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index ba18e4b30c8..1c573ac3a2b 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -9,8 +9,6 @@ use crate::values::computed::position::Position; use crate::values::computed::url::ComputedImageUrl; -#[cfg(feature = "gecko")] -use crate::values::computed::Percentage; use crate::values::computed::{Angle, Color, Context}; use crate::values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue}; use crate::values::generics::image::{self as generic, CompatMode}; @@ -73,15 +71,10 @@ impl generic::LineDirection for LineDirection { LineDirection::Vertical(Y::Top) if compat_mode != CompatMode::Modern => true, LineDirection::Corner(..) => false, #[cfg(feature = "gecko")] - LineDirection::MozPosition( - Some(Position { - horizontal: LengthOrPercentage::Percentage(Percentage(x)), - vertical: LengthOrPercentage::Percentage(Percentage(y)), - }), - None, - ) => { + LineDirection::MozPosition(Some(Position { ref vertical, ref horizontal }), None) => { // `50% 0%` is the default value for line direction. - x == 0.5 && y == 0.0 + horizontal.as_percentage().map_or(false, |p| p.0 == 0.5) && + vertical.as_percentage().map_or(false, |p| p.0 == 0.0) }, _ => false, } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 240b5ceb1ee..8a9425ee631 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -5,7 +5,7 @@ //! `` computed values, and related ones. use super::{Context, Number, Percentage, ToComputedValue}; -use crate::values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; +use crate::values::animated::{ToAnimatedValue}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::length::MaxLength as GenericMaxLength; use crate::values::generics::length::MozLength as GenericMozLength; @@ -68,15 +68,38 @@ impl ToComputedValue for specified::Length { } #[allow(missing_docs)] -#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToAnimatedZero)] -pub struct CalcLengthOrPercentage { +#[derive(Clone, Copy, Debug, MallocSizeOf, ToAnimatedZero)] +pub struct LengthOrPercentage { #[animation(constant)] pub clamping_mode: AllowedNumericType, length: Length, pub percentage: Option, + /// Whether this was from a calc() expression. This is needed because right + /// now we don't treat calc() the same way as non-calc everywhere, but + /// that's a bug in most cases. + /// + /// Please don't add new uses of this that aren't for converting to Gecko's + /// representation, or to interpolate values. + /// + /// See https://github.com/w3c/csswg-drafts/issues/3482. + #[animation(constant)] + pub was_calc: bool, } -impl ComputeSquaredDistance for CalcLengthOrPercentage { +// FIXME(emilio): This is a bit of a hack that can disappear as soon as we share +// representation of LengthOrPercentage with Gecko. The issue here is that Gecko +// uses CalcValue to represent position components, so they always come back as +// was_calc == true, and we mess up in the transitions code. +// +// This was a pre-existing bug, though arguably so only in pretty obscure cases +// like calc(0px + 5%) and such. +impl PartialEq for LengthOrPercentage { + fn eq(&self, other: &Self) -> bool { + self.length == other.length && self.percentage == other.percentage + } +} + +impl ComputeSquaredDistance for LengthOrPercentage { #[inline] fn compute_squared_distance(&self, other: &Self) -> Result { // FIXME(nox): This looks incorrect to me, to add a distance between lengths @@ -89,24 +112,36 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage { } } -impl CalcLengthOrPercentage { - /// Returns a new `CalcLengthOrPercentage`. +impl LengthOrPercentage { + /// Returns a new `LengthOrPercentage`. #[inline] pub fn new(length: Length, percentage: Option) -> Self { - Self::with_clamping_mode(length, percentage, AllowedNumericType::All) + Self::with_clamping_mode( + length, + percentage, + AllowedNumericType::All, + /* was_calc = */ false, + ) } - /// Returns a new `CalcLengthOrPercentage` with a specific clamping mode. + /// Returns a new `LengthOrPercentage` with zero length and some percentage. + pub fn new_percent(percentage: Percentage) -> Self { + Self::new(Length::zero(), Some(percentage)) + } + + /// Returns a new `LengthOrPercentage` with a specific clamping mode. #[inline] pub fn with_clamping_mode( length: Length, percentage: Option, clamping_mode: AllowedNumericType, + was_calc: bool, ) -> Self { Self { clamping_mode, length, percentage, + was_calc, } } @@ -131,22 +166,38 @@ impl CalcLengthOrPercentage { self.length } + /// Return the percentage value as CSSFloat. #[inline] pub fn percentage(&self) -> CSSFloat { self.percentage.map_or(0., |p| p.0) } + /// Returns the percentage component if this could be represented as a + /// non-calc percentage. + pub fn as_percentage(&self) -> Option { + if self.length.px() != 0. { + return None; + } + + let p = self.percentage?; + if self.clamping_mode.clamp(p.0) != p.0 { + return None; + } + + Some(p) + } + /// Convert the computed value into used value. #[inline] - pub fn to_used_value(&self, container_len: Option) -> Option { - self.to_pixel_length(container_len).map(Au::from) + pub fn maybe_to_used_value(&self, container_len: Option) -> Option { + self.maybe_to_pixel_length(container_len).map(Au::from) } /// If there are special rules for computing percentages in a value (e.g. /// the height property), they apply whenever a calc() expression contains /// percentages. - pub fn to_pixel_length(&self, container_len: Option) -> Option { + pub fn maybe_to_pixel_length(&self, container_len: Option) -> Option { match (container_len, self.percentage) { (Some(len), Some(percent)) => { let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px(); @@ -158,81 +209,12 @@ impl CalcLengthOrPercentage { } } -impl From for CalcLengthOrPercentage { - fn from(len: LengthOrPercentage) -> CalcLengthOrPercentage { - match len { - LengthOrPercentage::Percentage(this) => { - CalcLengthOrPercentage::new(Length::new(0.), Some(this)) - }, - LengthOrPercentage::Length(this) => CalcLengthOrPercentage::new(this, None), - LengthOrPercentage::Calc(this) => this, - } - } -} - -impl From for Option { - fn from(len: LengthOrPercentageOrAuto) -> Option { - match len { - LengthOrPercentageOrAuto::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) - }, - LengthOrPercentageOrAuto::Length(this) => Some(CalcLengthOrPercentage::new(this, None)), - LengthOrPercentageOrAuto::Calc(this) => Some(this), - LengthOrPercentageOrAuto::Auto => None, - } - } -} - -impl From for Option { - fn from(len: LengthOrPercentageOrNone) -> Option { - match len { - LengthOrPercentageOrNone::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) - }, - LengthOrPercentageOrNone::Length(this) => Some(CalcLengthOrPercentage::new(this, None)), - LengthOrPercentageOrNone::Calc(this) => Some(this), - LengthOrPercentageOrNone::None => None, - } - } -} - -impl ToCss for CalcLengthOrPercentage { +impl ToCss for LengthOrPercentage { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, { - use num_traits::Zero; - - let length = self.unclamped_length(); - match self.percentage { - Some(p) => { - if length.px() == 0. && self.clamping_mode.clamp(p.0) == p.0 { - return p.to_css(dest); - } - }, - None => { - if self.clamping_mode.clamp(length.px()) == length.px() { - return length.to_css(dest); - } - }, - } - - dest.write_str("calc(")?; - if let Some(percentage) = self.percentage { - percentage.to_css(dest)?; - if length.px() != 0. { - dest.write_str(if length.px() < Zero::zero() { - " - " - } else { - " + " - })?; - length.abs().to_css(dest)?; - } - } else { - length.to_css(dest)?; - } - - dest.write_str(")") + specified::LengthOrPercentage::from_computed_value(self).to_css(dest) } } @@ -243,7 +225,7 @@ impl specified::CalcLengthOrPercentage { context: &Context, zoom_fn: F, base_size: FontBaseSize, - ) -> CalcLengthOrPercentage + ) -> LengthOrPercentage where F: Fn(Length) -> Length, { @@ -277,10 +259,11 @@ impl specified::CalcLengthOrPercentage { } } - CalcLengthOrPercentage { + LengthOrPercentage { clamping_mode: self.clamping_mode, length: Length::new(length.min(f32::MAX).max(f32::MIN)), percentage: self.percentage, + was_calc: true, } } @@ -289,7 +272,7 @@ impl specified::CalcLengthOrPercentage { &self, context: &Context, base_size: FontBaseSize, - ) -> CalcLengthOrPercentage { + ) -> LengthOrPercentage { self.to_computed_value_with_zoom( context, |abs| context.maybe_zoom_text(abs.into()).0, @@ -324,15 +307,15 @@ impl specified::CalcLengthOrPercentage { } impl ToComputedValue for specified::CalcLengthOrPercentage { - type ComputedValue = CalcLengthOrPercentage; + type ComputedValue = LengthOrPercentage; - fn to_computed_value(&self, context: &Context) -> CalcLengthOrPercentage { + fn to_computed_value(&self, context: &Context) -> LengthOrPercentage { // normal properties don't zoom, and compute em units against the current style's font-size self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle) } #[inline] - fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self { + fn from_computed_value(computed: &LengthOrPercentage) -> Self { specified::CalcLengthOrPercentage { clamping_mode: computed.clamping_mode, absolute: Some(AbsoluteLength::from_computed_value(&computed.length)), @@ -342,95 +325,33 @@ impl ToComputedValue for specified::CalcLengthOrPercentage { } } -#[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] -#[css(derive_debug)] -#[derive( - Animate, - Clone, - ComputeSquaredDistance, - Copy, - MallocSizeOf, - PartialEq, - ToAnimatedValue, - ToAnimatedZero, - ToCss, -)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] -pub enum LengthOrPercentage { - Length(Length), - Percentage(Percentage), - Calc(CalcLengthOrPercentage), -} - -impl LengthOrPercentage { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - // Special handling for zero values since these should not require calc(). - if self.is_definitely_zero() { - return other.to_animated_zero()?.animate(other, procedure); - } - if other.is_definitely_zero() { - return self.animate(&self.to_animated_zero()?, procedure); - } - - let this = CalcLengthOrPercentage::from(*self); - let other = CalcLengthOrPercentage::from(*other); - Ok(LengthOrPercentage::Calc(this.animate(&other, procedure)?)) - } - - #[inline] - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - CalcLengthOrPercentage::compute_squared_distance(&(*self).into(), &(*other).into()) - } -} - -impl From for LengthOrPercentage { - #[inline] - fn from(length: Au) -> Self { - LengthOrPercentage::Length(length.into()) - } -} - impl LengthOrPercentage { #[inline] #[allow(missing_docs)] pub fn zero() -> LengthOrPercentage { - LengthOrPercentage::Length(Length::new(0.)) + LengthOrPercentage::new(Length::new(0.), None) } - #[inline] /// 1px length value for SVG defaults + #[inline] pub fn one() -> LengthOrPercentage { - LengthOrPercentage::Length(Length::new(1.)) + LengthOrPercentage::new(Length::new(1.), None) } /// Returns true if the computed value is absolute 0 or 0%. - /// - /// (Returns false for calc() values, even if ones that may resolve to zero.) #[inline] pub fn is_definitely_zero(&self) -> bool { - use self::LengthOrPercentage::*; - match *self { - Length(l) => l.px() == 0.0, - Percentage(p) => p.0 == 0.0, - Calc(_) => false, - } + self.unclamped_length().px() == 0.0 && self.percentage.map_or(true, |p| p.0 == 0.0) } // CSSFloat doesn't implement Hash, so does CSSPixelLength. Therefore, we still use Au as the // hash key. #[allow(missing_docs)] pub fn to_hash_key(&self) -> (Au, NotNan) { - use self::LengthOrPercentage::*; - match *self { - Length(l) => (Au::from(l), NotNan::new(0.0).unwrap()), - Percentage(p) => (Au(0), NotNan::new(p.0).unwrap()), - Calc(c) => ( - Au::from(c.unclamped_length()), - NotNan::new(c.percentage()).unwrap(), - ), - } + ( + Au::from(self.unclamped_length()), + NotNan::new(self.percentage()).unwrap(), + ) } /// Returns the used value. @@ -440,27 +361,40 @@ impl LengthOrPercentage { /// Returns the used value as CSSPixelLength. pub fn to_pixel_length(&self, containing_length: Au) -> Length { - match *self { - LengthOrPercentage::Length(length) => length, - LengthOrPercentage::Percentage(p) => containing_length.scale_by(p.0).into(), - LengthOrPercentage::Calc(ref calc) => { - calc.to_pixel_length(Some(containing_length)).unwrap() - }, - } + self.maybe_to_pixel_length(Some(containing_length)).unwrap() } /// Returns the clamped non-negative values. + /// + /// TODO(emilio): It's a bit unfortunate that this depends on whether the + /// value was a `calc()` value or not. Should it? #[inline] pub fn clamp_to_non_negative(self) -> Self { - match self { - LengthOrPercentage::Length(length) => { - LengthOrPercentage::Length(length.clamp_to_non_negative()) - }, - LengthOrPercentage::Percentage(percentage) => { - LengthOrPercentage::Percentage(percentage.clamp_to_non_negative()) - }, - _ => self, + if self.was_calc { + return Self::with_clamping_mode( + self.length, + self.percentage, + AllowedNumericType::NonNegative, + self.was_calc, + ) } + + debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero()); + if let Some(p) = self.percentage { + return Self::with_clamping_mode( + Length::zero(), + Some(p.clamp_to_non_negative()), + AllowedNumericType::NonNegative, + self.was_calc, + ); + } + + Self::with_clamping_mode( + self.length.clamp_to_non_negative(), + None, + AllowedNumericType::NonNegative, + self.was_calc, + ) } } @@ -470,71 +404,57 @@ impl ToComputedValue for specified::LengthOrPercentage { fn to_computed_value(&self, context: &Context) -> LengthOrPercentage { match *self { specified::LengthOrPercentage::Length(ref value) => { - LengthOrPercentage::Length(value.to_computed_value(context)) + LengthOrPercentage::new(value.to_computed_value(context), None) }, specified::LengthOrPercentage::Percentage(value) => { - LengthOrPercentage::Percentage(value) + LengthOrPercentage::new_percent(value) }, specified::LengthOrPercentage::Calc(ref calc) => { - LengthOrPercentage::Calc((**calc).to_computed_value(context)) + (**calc).to_computed_value(context) }, } } fn from_computed_value(computed: &LengthOrPercentage) -> Self { - match *computed { - LengthOrPercentage::Length(value) => { - specified::LengthOrPercentage::Length(ToComputedValue::from_computed_value(&value)) - }, - LengthOrPercentage::Percentage(value) => { - specified::LengthOrPercentage::Percentage(value) - }, - LengthOrPercentage::Calc(ref calc) => specified::LengthOrPercentage::Calc(Box::new( - ToComputedValue::from_computed_value(calc), - )), + let length = computed.unclamped_length(); + if let Some(p) = computed.as_percentage() { + return specified::LengthOrPercentage::Percentage(p) } + + let percentage = computed.percentage; + if percentage.is_none() && + computed.clamping_mode.clamp(length.px()) == length.px() { + return specified::LengthOrPercentage::Length( + ToComputedValue::from_computed_value(&length) + ) + } + + specified::LengthOrPercentage::Calc(Box::new( + ToComputedValue::from_computed_value(computed), + )) } } impl IsZeroLength for LengthOrPercentage { #[inline] fn is_zero_length(&self) -> bool { - match *self { - LengthOrPercentage::Length(l) => l.0 == 0.0, - LengthOrPercentage::Percentage(p) => p.0 == 0.0, - LengthOrPercentage::Calc(c) => c.unclamped_length().0 == 0.0 && c.percentage() == 0.0, - } + self.is_definitely_zero() } } #[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] #[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToCss)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] pub enum LengthOrPercentageOrAuto { - Length(Length), - Percentage(Percentage), + LengthOrPercentage(LengthOrPercentage), Auto, - Calc(CalcLengthOrPercentage), } impl LengthOrPercentageOrAuto { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - let this = >::from(*self); - let other = >::from(*other); - Ok(LengthOrPercentageOrAuto::Calc( - this.animate(&other, procedure)?.ok_or(())?, - )) - } - + /// Returns the `0` value. #[inline] - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - >::compute_squared_distance( - &(*self).into(), - &(*other).into(), - ) + pub fn zero() -> Self { + LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero()) } } @@ -572,24 +492,21 @@ impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto { /// Returns true if the computed value is absolute 0 or 0%. - /// - /// (Returns false for calc() values, even if ones that may resolve to zero.) #[inline] pub fn is_definitely_zero(&self) -> bool { use self::LengthOrPercentageOrAuto::*; match *self { - Length(l) => l.px() == 0.0, - Percentage(p) => p.0 == 0.0, - Calc(_) | Auto => false, + LengthOrPercentage(ref l) => l.is_definitely_zero(), + Auto => false, } } - fn clamp_to_non_negative(self) -> Self { + /// Clamps the value to a non-negative value. + pub fn clamp_to_non_negative(self) -> Self { use self::LengthOrPercentageOrAuto::*; match self { - Length(l) => Length(l.clamp_to_non_negative()), - Percentage(p) => Percentage(p.clamp_to_non_negative()), - _ => self, + LengthOrPercentage(l) => LengthOrPercentage(l.clamp_to_non_negative()), + Auto => Auto, } } } @@ -600,16 +517,12 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto { #[inline] fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrAuto { match *self { - specified::LengthOrPercentageOrAuto::Length(ref value) => { - LengthOrPercentageOrAuto::Length(value.to_computed_value(context)) - }, - specified::LengthOrPercentageOrAuto::Percentage(value) => { - LengthOrPercentageOrAuto::Percentage(value) + specified::LengthOrPercentageOrAuto::LengthOrPercentage(ref value) => { + LengthOrPercentageOrAuto::LengthOrPercentage( + value.to_computed_value(context), + ) }, specified::LengthOrPercentageOrAuto::Auto => LengthOrPercentageOrAuto::Auto, - specified::LengthOrPercentageOrAuto::Calc(ref calc) => { - LengthOrPercentageOrAuto::Calc((**calc).to_computed_value(context)) - }, } } @@ -617,78 +530,44 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto { fn from_computed_value(computed: &LengthOrPercentageOrAuto) -> Self { match *computed { LengthOrPercentageOrAuto::Auto => specified::LengthOrPercentageOrAuto::Auto, - LengthOrPercentageOrAuto::Length(value) => specified::LengthOrPercentageOrAuto::Length( - ToComputedValue::from_computed_value(&value), - ), - LengthOrPercentageOrAuto::Percentage(value) => { - specified::LengthOrPercentageOrAuto::Percentage(value) + LengthOrPercentageOrAuto::LengthOrPercentage(ref value) => { + specified::LengthOrPercentageOrAuto::LengthOrPercentage( + ToComputedValue::from_computed_value(value), + ) }, - LengthOrPercentageOrAuto::Calc(calc) => specified::LengthOrPercentageOrAuto::Calc( - Box::new(ToComputedValue::from_computed_value(&calc)), - ), } } } #[allow(missing_docs)] -#[animate(fallback = "Self::animate_fallback")] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[css(derive_debug)] -#[derive(Animate, Clone, ComputeSquaredDistance, Copy, PartialEq, ToCss)] -#[distance(fallback = "Self::compute_squared_distance_fallback")] +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] pub enum LengthOrPercentageOrNone { - Length(Length), - Percentage(Percentage), - Calc(CalcLengthOrPercentage), + LengthOrPercentage(LengthOrPercentage), None, } -impl LengthOrPercentageOrNone { - /// - fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result { - let this = >::from(*self); - let other = >::from(*other); - Ok(LengthOrPercentageOrNone::Calc( - this.animate(&other, procedure)?.ok_or(())?, - )) - } - - fn compute_squared_distance_fallback(&self, other: &Self) -> Result { - >::compute_squared_distance( - &(*self).into(), - &(*other).into(), - ) - } -} - impl LengthOrPercentageOrNone { /// Returns the used value. pub fn to_used_value(&self, containing_length: Au) -> Option { match *self { LengthOrPercentageOrNone::None => None, - LengthOrPercentageOrNone::Length(length) => Some(Au::from(length)), - LengthOrPercentageOrNone::Percentage(percent) => { - Some(containing_length.scale_by(percent.0)) + LengthOrPercentageOrNone::LengthOrPercentage(ref lop) => { + Some(lop.to_used_value(containing_length)) }, - LengthOrPercentageOrNone::Calc(ref calc) => calc.to_used_value(Some(containing_length)), } } } +// FIXME(emilio): Derive this. impl ToComputedValue for specified::LengthOrPercentageOrNone { type ComputedValue = LengthOrPercentageOrNone; #[inline] fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrNone { match *self { - specified::LengthOrPercentageOrNone::Length(ref value) => { - LengthOrPercentageOrNone::Length(value.to_computed_value(context)) - }, - specified::LengthOrPercentageOrNone::Percentage(value) => { - LengthOrPercentageOrNone::Percentage(value) - }, - specified::LengthOrPercentageOrNone::Calc(ref calc) => { - LengthOrPercentageOrNone::Calc((**calc).to_computed_value(context)) + specified::LengthOrPercentageOrNone::LengthOrPercentage(ref value) => { + LengthOrPercentageOrNone::LengthOrPercentage(value.to_computed_value(context)) }, specified::LengthOrPercentageOrNone::None => LengthOrPercentageOrNone::None, } @@ -698,15 +577,11 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone { fn from_computed_value(computed: &LengthOrPercentageOrNone) -> Self { match *computed { LengthOrPercentageOrNone::None => specified::LengthOrPercentageOrNone::None, - LengthOrPercentageOrNone::Length(value) => specified::LengthOrPercentageOrNone::Length( - ToComputedValue::from_computed_value(&value), - ), - LengthOrPercentageOrNone::Percentage(value) => { - specified::LengthOrPercentageOrNone::Percentage(value) + LengthOrPercentageOrNone::LengthOrPercentage(value) => { + specified::LengthOrPercentageOrNone::LengthOrPercentage( + ToComputedValue::from_computed_value(&value), + ) }, - LengthOrPercentageOrNone::Calc(calc) => specified::LengthOrPercentageOrNone::Calc( - Box::new(ToComputedValue::from_computed_value(&calc)), - ), } } } @@ -719,19 +594,19 @@ impl ToAnimatedValue for NonNegativeLengthOrPercentage { #[inline] fn to_animated_value(self) -> Self::AnimatedValue { - self.into() + self.0 } #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - animated.clamp_to_non_negative().into() + NonNegative(animated.clamp_to_non_negative()) } } impl From for NonNegativeLengthOrPercentage { #[inline] fn from(length: NonNegativeLength) -> Self { - LengthOrPercentage::Length(length.0).into() + LengthOrPercentage::new(length.0, None).into() } } @@ -749,6 +624,15 @@ impl From for LengthOrPercentage { } } +// TODO(emilio): This is a really generic impl which is only needed to implement +// Animated and co for Spacing<>. Get rid of this, probably? +impl From for LengthOrPercentage { + #[inline] + fn from(length: Au) -> Self { + LengthOrPercentage::new(length.into(), None) + } +} + impl NonNegativeLengthOrPercentage { /// Get zero value. #[inline] @@ -798,11 +682,6 @@ impl CSSPixelLength { self.0 } - #[inline] - fn clamp_to_non_negative(self) -> Self { - Self::new(self.px().max(0.)) - } - /// Return the length with app_unit i32 type. #[inline] pub fn to_i32_au(&self) -> i32 { @@ -810,11 +689,19 @@ impl CSSPixelLength { } /// Return the absolute value of this length. + #[inline] pub fn abs(self) -> Self { CSSPixelLength::new(self.0.abs()) } + /// Return the clamped value of this length. + #[inline] + pub fn clamp_to_non_negative(self) -> Self { + CSSPixelLength::new(self.0.max(0.)) + } + /// Zero value + #[inline] pub fn zero() -> Self { CSSPixelLength::new(0.) } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 4051511e28e..7877fddc192 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -62,7 +62,7 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, pub use self::gecko::ScrollSnapPoint; pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; -pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage}; +pub use self::length::{Length, LengthOrNumber, LengthOrPercentage}; pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto}; #[cfg(feature = "gecko")] diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index 8c7976886d8..7bcdb59f89e 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -28,8 +28,8 @@ impl Position { #[inline] pub fn center() -> Self { Self::new( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(0.5)), + LengthOrPercentage::new_percent(Percentage(0.5)), + LengthOrPercentage::new_percent(Percentage(0.5)), ) } diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index e3493131544..14115295213 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -31,8 +31,8 @@ impl TransformOrigin { #[inline] pub fn initial_value() -> Self { Self::new( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(0.5)), + LengthOrPercentage::new_percent(Percentage(0.5)), + LengthOrPercentage::new_percent(Percentage(0.5)), Length::new(0.), ) } diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 090c3c1f687..2ee92513cf9 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -103,10 +103,7 @@ where } } -impl ToAnimatedZero for Spacing -where - V: From, -{ +impl ToAnimatedZero for Spacing { #[inline] fn to_animated_zero(&self) -> Result { Err(()) diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index 158b7456c76..d4b69b02e72 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -288,18 +288,14 @@ impl ToAbsoluteLength for ComputedLength { impl ToAbsoluteLength for ComputedLengthOrPercentage { #[inline] fn to_pixel_length(&self, containing_len: Option) -> Result { - let extract_pixel_length = |lop: &ComputedLengthOrPercentage| match *lop { - ComputedLengthOrPercentage::Length(px) => px.px(), - ComputedLengthOrPercentage::Percentage(_) => 0., - ComputedLengthOrPercentage::Calc(calc) => calc.length().px(), - }; - match containing_len { Some(relative_len) => Ok(self.to_pixel_length(relative_len).px()), // If we don't have reference box, we cannot resolve the used value, // so only retrieve the length part. This will be used for computing // distance without any layout info. - None => Ok(extract_pixel_length(self)), + // + // FIXME(emilio): This looks wrong. + None => Ok(self.length_component().px()), } } } diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index e5699742b14..57d7835e416 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -916,9 +916,7 @@ impl FontSize { info = parent.keyword_info.map(|i| i.compose(ratio, abs.into())); } let calc = calc.to_computed_value_zoomed(context, base_size); - calc.to_used_value(Some(base_size.resolve(context))) - .unwrap() - .into() + calc.to_used_value(base_size.resolve(context)).into() }, FontSize::Keyword(i) => { // As a specified keyword, this is keyword derived diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index e64385472a0..4be179212c8 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -789,6 +789,12 @@ impl LengthOrPercentage { LengthOrPercentage::Length(NoCalcLength::zero()) } + #[inline] + /// Returns a `0%` value. + pub fn zero_percent() -> LengthOrPercentage { + LengthOrPercentage::Percentage(computed::Percentage::zero()) + } + fn parse_internal<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, @@ -898,24 +904,8 @@ impl IsZeroLength for LengthOrPercentage { #[allow(missing_docs)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)] pub enum LengthOrPercentageOrAuto { - Length(NoCalcLength), - Percentage(computed::Percentage), + LengthOrPercentage(LengthOrPercentage), Auto, - Calc(Box), -} - -impl From for LengthOrPercentageOrAuto { - #[inline] - fn from(len: NoCalcLength) -> Self { - LengthOrPercentageOrAuto::Length(len) - } -} - -impl From for LengthOrPercentageOrAuto { - #[inline] - fn from(pc: computed::Percentage) -> Self { - LengthOrPercentageOrAuto::Percentage(pc) - } } impl LengthOrPercentageOrAuto { @@ -925,48 +915,16 @@ impl LengthOrPercentageOrAuto { num_context: AllowedNumericType, allow_quirks: AllowQuirks, ) -> Result> { - // FIXME: remove early returns when lifetimes are non-lexical - { - let location = input.current_source_location(); - let token = input.next()?; - match *token { - Token::Dimension { - value, ref unit, .. - } if num_context.is_ok(context.parsing_mode, value) => { - return NoCalcLength::parse_dimension(context, value, unit) - .map(LengthOrPercentageOrAuto::Length) - .map_err(|()| location.new_unexpected_token_error(token.clone())); - }, - Token::Percentage { unit_value, .. } - if num_context.is_ok(context.parsing_mode, unit_value) => - { - return Ok(LengthOrPercentageOrAuto::Percentage(computed::Percentage( - unit_value, - ))); - } - Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => { - if value != 0. && - !context.parsing_mode.allows_unitless_lengths() && - !allow_quirks.allowed(context.quirks_mode) - { - return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); - } - return Ok(LengthOrPercentageOrAuto::Length(NoCalcLength::Absolute( - AbsoluteLength::Px(value), - ))); - }, - Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => { - return Ok(LengthOrPercentageOrAuto::Auto); - }, - Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}, - _ => return Err(location.new_unexpected_token_error(token.clone())), - } + if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + return Ok(LengthOrPercentageOrAuto::Auto); } - let calc = input.parse_nested_block(|i| { - CalcNode::parse_length_or_percentage(context, i, num_context) - })?; - Ok(LengthOrPercentageOrAuto::Calc(Box::new(calc))) + Ok(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::parse_internal( + context, + input, + num_context, + allow_quirks, + )?)) } /// Parse a non-negative length, percentage, or auto. @@ -1000,13 +958,13 @@ impl LengthOrPercentageOrAuto { /// Returns a value representing a `0` length. pub fn zero() -> Self { - LengthOrPercentageOrAuto::Length(NoCalcLength::zero()) + LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero()) } /// Returns a value representing `0%`. #[inline] pub fn zero_percent() -> Self { - LengthOrPercentageOrAuto::Percentage(computed::Percentage::zero()) + LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero_percent()) } /// Parses, with quirks. @@ -1076,9 +1034,7 @@ impl Parse for NonNegativeLengthOrPercentageOrAuto { #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss)] #[allow(missing_docs)] pub enum LengthOrPercentageOrNone { - Length(NoCalcLength), - Percentage(computed::Percentage), - Calc(Box), + LengthOrPercentage(LengthOrPercentage), None, } @@ -1089,48 +1045,16 @@ impl LengthOrPercentageOrNone { num_context: AllowedNumericType, allow_quirks: AllowQuirks, ) -> Result> { - // FIXME: remove early returns when lifetimes are non-lexical - { - let location = input.current_source_location(); - let token = input.next()?; - match *token { - Token::Dimension { - value, ref unit, .. - } if num_context.is_ok(context.parsing_mode, value) => { - return NoCalcLength::parse_dimension(context, value, unit) - .map(LengthOrPercentageOrNone::Length) - .map_err(|()| location.new_unexpected_token_error(token.clone())); - }, - Token::Percentage { unit_value, .. } - if num_context.is_ok(context.parsing_mode, unit_value) => - { - return Ok(LengthOrPercentageOrNone::Percentage(computed::Percentage( - unit_value, - ))); - } - Token::Number { value, .. } if num_context.is_ok(context.parsing_mode, value) => { - if value != 0. && - !context.parsing_mode.allows_unitless_lengths() && - !allow_quirks.allowed(context.quirks_mode) - { - return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); - } - return Ok(LengthOrPercentageOrNone::Length(NoCalcLength::Absolute( - AbsoluteLength::Px(value), - ))); - }, - Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {}, - Token::Ident(ref value) if value.eq_ignore_ascii_case("none") => { - return Ok(LengthOrPercentageOrNone::None); - }, - _ => return Err(location.new_unexpected_token_error(token.clone())), - } + if input.try(|i| i.expect_ident_matching("none")).is_ok() { + return Ok(LengthOrPercentageOrNone::None); } - let calc = input.parse_nested_block(|i| { - CalcNode::parse_length_or_percentage(context, i, num_context) - })?; - Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) + Ok(LengthOrPercentageOrNone::LengthOrPercentage(LengthOrPercentage::parse_internal( + context, + input, + num_context, + allow_quirks, + )?)) } /// Parse a non-negative LengthOrPercentageOrNone. diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index e2865071eeb..a7c6c9f41d6 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -10,7 +10,6 @@ use crate::hash::FxHashMap; use crate::parser::{Parse, ParserContext}; use crate::str::HTML_SPACE_CHARACTERS; -use crate::values::computed::CalcLengthOrPercentage; use crate::values::computed::LengthOrPercentage as ComputedLengthOrPercentage; use crate::values::computed::{Context, Percentage, ToComputedValue}; use crate::values::generics::position::Position as GenericPosition; @@ -255,25 +254,21 @@ impl ToComputedValue for PositionComponent { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { - PositionComponent::Center => ComputedLengthOrPercentage::Percentage(Percentage(0.5)), + PositionComponent::Center => ComputedLengthOrPercentage::new_percent(Percentage(0.5)), PositionComponent::Side(ref keyword, None) => { let p = Percentage(if keyword.is_start() { 0. } else { 1. }); - ComputedLengthOrPercentage::Percentage(p) + ComputedLengthOrPercentage::new_percent(p) }, PositionComponent::Side(ref keyword, Some(ref length)) if !keyword.is_start() => { - match length.to_computed_value(context) { - ComputedLengthOrPercentage::Length(length) => ComputedLengthOrPercentage::Calc( - CalcLengthOrPercentage::new(-length, Some(Percentage::hundred())), - ), - ComputedLengthOrPercentage::Percentage(p) => { - ComputedLengthOrPercentage::Percentage(Percentage(1.0 - p.0)) - }, - ComputedLengthOrPercentage::Calc(calc) => { - let p = Percentage(1. - calc.percentage.map_or(0., |p| p.0)); - let l = -calc.unclamped_length(); - ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(l, Some(p))) - }, - } + let length = length.to_computed_value(context); + let p = Percentage(1. - length.percentage()); + let l = -length.unclamped_length(); + ComputedLengthOrPercentage::with_clamping_mode( + l, + Some(p), + length.clamping_mode, + length.was_calc, + ) }, PositionComponent::Side(_, Some(ref length)) | PositionComponent::Length(ref length) => length.to_computed_value(context), diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index a5b36a24db5..bc8737ca95b 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -323,12 +323,12 @@ where fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { OriginComponent::Center => { - ComputedLengthOrPercentage::Percentage(ComputedPercentage(0.5)) + ComputedLengthOrPercentage::new_percent(ComputedPercentage(0.5)) }, OriginComponent::Length(ref length) => length.to_computed_value(context), OriginComponent::Side(ref keyword) => { let p = ComputedPercentage(if keyword.is_start() { 0. } else { 1. }); - ComputedLengthOrPercentage::Percentage(p) + ComputedLengthOrPercentage::new_percent(p) }, } } From 4a31509215c70c8810019880b83025182a80b6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 7 Jan 2019 16:43:10 +0100 Subject: [PATCH 2/6] style: Fix servo build. This also fixes a bunch of calc handling issues and such. Also remove tests that no longer compile and are covered by WPT. --- components/layout/block.rs | 66 +++++--------- components/layout/display_list/gradient.rs | 12 +-- components/layout/flex.rs | 36 ++++---- components/layout/floats.rs | 21 +++-- components/layout/fragment.rs | 71 +++++++-------- components/layout/model.rs | 86 +++++++------------ components/layout/multicol.rs | 23 +++-- components/layout/table.rs | 16 ++-- components/layout/table_row.rs | 27 +++--- components/script/dom/element.rs | 44 +++++++--- .../properties/longhands/position.mako.rs | 2 +- tests/unit/style/animated_properties.rs | 81 ----------------- tests/unit/style/attr.rs | 13 --- tests/unit/style/properties/serialization.rs | 51 +---------- tests/unit/style/stylesheets.rs | 68 +-------------- tests/unit/style/viewport.rs | 13 +-- ...riable-substitution-replaced-size.html.ini | 5 -- 17 files changed, 199 insertions(+), 436 deletions(-) diff --git a/components/layout/block.rs b/components/layout/block.rs index 823d5226ea1..5cf6597654f 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -66,8 +66,7 @@ use style::context::SharedStyleContext; use style::logical_geometry::{LogicalMargin, LogicalPoint, LogicalRect, LogicalSize, WritingMode}; use style::properties::ComputedValues; use style::servo::restyle_damage::ServoRestyleDamage; -use style::values::computed::LengthOrPercentageOrAuto; -use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrNone}; +use style::values::computed::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; /// Information specific to floated blocks. #[derive(Clone, Serialize)] @@ -418,42 +417,23 @@ impl CandidateBSizeIterator { // If that is not determined yet by the time we need to resolve // `min-height` and `max-height`, percentage values are ignored. - let block_size = match ( - fragment.style.content_block_size(), - block_container_block_size, - ) { - (LengthOrPercentageOrAuto::Percentage(percent), Some(block_container_block_size)) => { - MaybeAuto::Specified(block_container_block_size.scale_by(percent.0)) + let block_size = match fragment.style.content_block_size() { + LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_to_used_value(block_container_block_size)) }, - (LengthOrPercentageOrAuto::Calc(calc), _) => { - MaybeAuto::from_option(calc.to_used_value(block_container_block_size)) - }, - (LengthOrPercentageOrAuto::Percentage(_), None) | - (LengthOrPercentageOrAuto::Auto, _) => MaybeAuto::Auto, - (LengthOrPercentageOrAuto::Length(length), _) => MaybeAuto::Specified(Au::from(length)), }; - let max_block_size = match (fragment.style.max_block_size(), block_container_block_size) { - (LengthOrPercentageOrNone::Percentage(percent), Some(block_container_block_size)) => { - Some(block_container_block_size.scale_by(percent.0)) + + let max_block_size = match fragment.style.max_block_size() { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(block_container_block_size) }, - (LengthOrPercentageOrNone::Calc(calc), _) => { - calc.to_used_value(block_container_block_size) - }, - (LengthOrPercentageOrNone::Percentage(_), None) | - (LengthOrPercentageOrNone::None, _) => None, - (LengthOrPercentageOrNone::Length(length), _) => Some(Au::from(length)), - }; - let min_block_size = match (fragment.style.min_block_size(), block_container_block_size) { - (LengthOrPercentage::Percentage(percent), Some(block_container_block_size)) => { - block_container_block_size.scale_by(percent.0) - }, - (LengthOrPercentage::Calc(calc), _) => calc - .to_used_value(block_container_block_size) - .unwrap_or(Au(0)), - (LengthOrPercentage::Percentage(_), None) => Au(0), - (LengthOrPercentage::Length(length), _) => Au::from(length), }; + let min_block_size = + fragment.style.min_block_size().maybe_to_used_value(block_container_block_size).unwrap_or(Au(0)); + // If the style includes `box-sizing: border-box`, subtract the border and padding. let adjustment_for_box_sizing = match fragment.style.get_position().box_sizing { BoxSizing::BorderBox => fragment.border_padding.block_start_end(), @@ -1415,15 +1395,9 @@ impl BlockFlow { pub fn explicit_block_size(&self, containing_block_size: Option) -> Option { let content_block_size = self.fragment.style().content_block_size(); - match (content_block_size, containing_block_size) { - (LengthOrPercentageOrAuto::Calc(calc), _) => calc.to_used_value(containing_block_size), - (LengthOrPercentageOrAuto::Length(length), _) => Some(Au::from(length)), - (LengthOrPercentageOrAuto::Percentage(percent), Some(container_size)) => { - Some(container_size.scale_by(percent.0)) - }, - (LengthOrPercentageOrAuto::Percentage(_), None) | - (LengthOrPercentageOrAuto::Auto, None) => None, - (LengthOrPercentageOrAuto::Auto, Some(container_size)) => { + match content_block_size { + LengthOrPercentageOrAuto::Auto => { + let container_size = containing_block_size?; let (block_start, block_end) = { let position = self.fragment.style().logical_position(); ( @@ -1454,10 +1428,12 @@ impl BlockFlow { let sum = block_start + block_end + margin_block_start + margin_block_end; Some(available_block_size - sum) }, - (_, _) => None, } }, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(containing_block_size) + }, } } @@ -2177,8 +2153,8 @@ impl Flow for BlockFlow { // If this block has a fixed width, just use that for the minimum and preferred width, // rather than bubbling up children inline width. let consult_children = match self.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => false, - _ => true, + LengthOrPercentageOrAuto::Auto => true, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => lp.maybe_to_used_value(None).is_none(), }; self.bubble_inline_sizes_for_block(consult_children); self.fragment diff --git a/components/layout/display_list/gradient.rs b/components/layout/display_list/gradient.rs index 6cdee3d6df8..f7fc834e8d8 100644 --- a/components/layout/display_list/gradient.rs +++ b/components/layout/display_list/gradient.rs @@ -107,14 +107,14 @@ fn convert_gradient_stops( { let first = stop_items.first_mut().unwrap(); if first.position.is_none() { - first.position = Some(LengthOrPercentage::Percentage(Percentage(0.0))); + first.position = Some(LengthOrPercentage::new_percent(Percentage(0.))); } } // If the last color stop does not have a position, set its position to 100%. { let last = stop_items.last_mut().unwrap(); if last.position.is_none() { - last.position = Some(LengthOrPercentage::Percentage(Percentage(1.0))); + last.position = Some(LengthOrPercentage::new_percent(Percentage(1.0))); } } @@ -214,13 +214,7 @@ fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 { if total_length == Au(0) { return 0.0; } - match position { - LengthOrPercentage::Length(l) => l.to_i32_au() as f32 / total_length.0 as f32, - LengthOrPercentage::Percentage(percentage) => percentage.0 as f32, - LengthOrPercentage::Calc(calc) => { - calc.to_used_value(Some(total_length)).unwrap().0 as f32 / total_length.0 as f32 - }, - } + position.to_used_value(total_length).0 as f32 / total_length.0 as f32 } pub fn linear( diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 1848cdf2e81..fbd01c14dca 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -12,7 +12,7 @@ use crate::floats::FloatKind; use crate::flow::{Flow, FlowClass, FlowFlags, GetBaseFlow, ImmutableFlowUtils, OpaqueFlow}; use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow}; use crate::layout_debug; -use crate::model::{AdjoiningMargins, CollapsibleMargins}; +use crate::model::{self, AdjoiningMargins, CollapsibleMargins}; use crate::model::{IntrinsicISizes, MaybeAuto, SizeConstraint}; use crate::traversal::PreorderFlowTraversal; use app_units::{Au, MAX_AU}; @@ -52,18 +52,15 @@ impl AxisSize { max: LengthOrPercentageOrNone, ) -> AxisSize { match size { - LengthOrPercentageOrAuto::Length(length) => AxisSize::Definite(Au::from(length)), - LengthOrPercentageOrAuto::Percentage(percent) => match content_size { - Some(size) => AxisSize::Definite(size.scale_by(percent.0)), - None => AxisSize::Infinite, - }, - LengthOrPercentageOrAuto::Calc(calc) => match calc.to_used_value(content_size) { - Some(length) => AxisSize::Definite(length), - None => AxisSize::Infinite, - }, LengthOrPercentageOrAuto::Auto => { AxisSize::MinMax(SizeConstraint::new(content_size, min, max, None)) - }, + } + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + match lp.maybe_to_used_value(content_size) { + Some(length) => AxisSize::Definite(length), + None => AxisSize::Infinite, + } + } } } } @@ -461,10 +458,11 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out, and max replaced with union_nonbreaking_inline. fn inline_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => true, - _ => false, - }; + // FIXME(emilio): This doesn't handle at all writing-modes. + let fixed_width = !model::style_length( + self.block_flow.fragment.style().get_position().width, + None, + ).is_auto(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { @@ -488,10 +486,10 @@ impl FlexFlow { // Currently, this is the core of BlockFlow::bubble_inline_sizes() with all float logic // stripped out. fn block_mode_bubble_inline_sizes(&mut self) { - let fixed_width = match self.block_flow.fragment.style().get_position().width { - LengthOrPercentageOrAuto::Length(_) => true, - _ => false, - }; + let fixed_width = !model::style_length( + self.block_flow.fragment.style().get_position().width, + None, + ).is_auto(); let mut computation = self.block_flow.fragment.compute_intrinsic_inline_sizes(); if !fixed_width { diff --git a/components/layout/floats.rs b/components/layout/floats.rs index 5e9ee3ae886..9aa25f4e9b6 100644 --- a/components/layout/floats.rs +++ b/components/layout/floats.rs @@ -542,16 +542,21 @@ impl SpeculatedFloatPlacement { let mut float_inline_size = base_flow.intrinsic_inline_sizes.preferred_inline_size; if float_inline_size == Au(0) { if flow.is_block_like() { - // Hack: If the size of the float is a percentage, then there's no way we can guess - // at its size now. So just pick an arbitrary nonzero value (in this case, 1px) so - // that the layout traversal logic will know that objects later in the document + // Hack: If the size of the float is not fixed, then there's no + // way we can guess at its size now. So just pick an arbitrary + // nonzero value (in this case, 1px) so that the layout + // traversal logic will know that objects later in the document // might flow around this float. - if let LengthOrPercentageOrAuto::Percentage(percentage) = - flow.as_block().fragment.style.content_inline_size() - { - if percentage.0 > 0.0 { - float_inline_size = Au::from_px(1) + let inline_size = + flow.as_block().fragment.style.content_inline_size(); + let fixed = match inline_size { + LengthOrPercentageOrAuto::Auto => false, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.is_definitely_zero() || lp.maybe_to_used_value(None).is_some() } + }; + if !fixed { + float_inline_size = Au::from_px(1) } } } diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 3e84a36c595..5560941aaa8 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -61,7 +61,7 @@ use style::selector_parser::RestyleDamage; use style::servo::restyle_damage::ServoRestyleDamage; use style::str::char_is_whitespace; use style::values::computed::counters::ContentItem; -use style::values::computed::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto}; use style::values::generics::box_::{Perspective, VerticalAlign}; use style::values::generics::transform; use webrender_api::{self, LayoutTransform}; @@ -1610,33 +1610,32 @@ impl Fragment { SpecificFragmentInfo::Canvas(_) | SpecificFragmentInfo::Iframe(_) | SpecificFragmentInfo::Svg(_) => { - let mut inline_size = match self.style.content_inline_size() { - LengthOrPercentageOrAuto::Auto | LengthOrPercentageOrAuto::Percentage(_) => { - // We have to initialize the `border_padding` field first to make - // the size constraints work properly. - // TODO(stshine): Find a cleaner way to do this. - let padding = self.style.logical_padding(); - self.border_padding.inline_start = - padding.inline_start.to_used_value(Au(0)); - self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0)); - self.border_padding.block_start = padding.block_start.to_used_value(Au(0)); - self.border_padding.block_end = padding.block_end.to_used_value(Au(0)); - let border = self.border_width(); - self.border_padding.inline_start += border.inline_start; - self.border_padding.inline_end += border.inline_end; - self.border_padding.block_start += border.block_start; - self.border_padding.block_end += border.block_end; - let (result_inline, _) = self.calculate_replaced_sizes(None, None); - result_inline - }, - LengthOrPercentageOrAuto::Length(length) => Au::from(length), - LengthOrPercentageOrAuto::Calc(calc) => { - // TODO(nox): This is probably wrong, because it accounts neither for - // clamping (not sure if necessary here) nor percentage. - Au::from(calc.unclamped_length()) - }, + let inline_size = match self.style.content_inline_size() { + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None) + } }; + let mut inline_size = inline_size.unwrap_or_else(|| { + // We have to initialize the `border_padding` field first to make + // the size constraints work properly. + // TODO(stshine): Find a cleaner way to do this. + let padding = self.style.logical_padding(); + self.border_padding.inline_start = + padding.inline_start.to_used_value(Au(0)); + self.border_padding.inline_end = padding.inline_end.to_used_value(Au(0)); + self.border_padding.block_start = padding.block_start.to_used_value(Au(0)); + self.border_padding.block_end = padding.block_end.to_used_value(Au(0)); + let border = self.border_width(); + self.border_padding.inline_start += border.inline_start; + self.border_padding.inline_end += border.inline_end; + self.border_padding.block_start += border.block_start; + self.border_padding.block_end += border.block_end; + let (result_inline, _) = self.calculate_replaced_sizes(None, None); + result_inline + }); + let size_constraint = self.size_constraint(None, Direction::Inline); inline_size = size_constraint.clamp(inline_size); @@ -2432,16 +2431,8 @@ impl Fragment { content_inline_metrics.space_below_baseline } }, - VerticalAlign::Length(LengthOrPercentage::Length(length)) => { - offset -= Au::from(length) - }, - VerticalAlign::Length(LengthOrPercentage::Percentage(percentage)) => { - offset -= minimum_line_metrics.space_needed().scale_by(percentage.0) - }, - VerticalAlign::Length(LengthOrPercentage::Calc(formula)) => { - offset -= formula - .to_used_value(Some(minimum_line_metrics.space_needed())) - .unwrap() + VerticalAlign::Length(ref lp) => { + offset -= lp.to_used_value(minimum_line_metrics.space_needed()); }, } } @@ -2519,12 +2510,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_end != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthOrPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_end != - LengthOrPercentage::Length(Length::new(0.)) + LengthOrPercentage::zero() { return false; } @@ -2545,12 +2536,12 @@ impl Fragment { continue; } if inline_context_node.style.logical_margin().inline_start != - LengthOrPercentageOrAuto::Length(Length::new(0.)) + LengthOrPercentageOrAuto::zero() { return false; } if inline_context_node.style.logical_padding().inline_start != - LengthOrPercentage::Length(Length::new(0.)) + LengthOrPercentage::zero() { return false; } diff --git a/components/layout/model.rs b/components/layout/model.rs index 4db60d05a4b..a54e3a9b76e 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -136,26 +136,19 @@ impl MarginCollapseInfo { may_collapse_through = may_collapse_through && match fragment.style().content_block_size() { LengthOrPercentageOrAuto::Auto => true, - LengthOrPercentageOrAuto::Length(l) => l.px() == 0., - LengthOrPercentageOrAuto::Percentage(v) => { - v.0 == 0. || containing_block_size.is_none() + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.is_definitely_zero() || + lp.maybe_to_used_value(containing_block_size).is_none() }, - LengthOrPercentageOrAuto::Calc(_) => false, }; if may_collapse_through { - match fragment.style().min_block_size() { - LengthOrPercentage::Length(l) if l.px() == 0. => { - FinalMarginState::MarginsCollapseThrough - }, - LengthOrPercentage::Percentage(v) if v.0 == 0. => { - FinalMarginState::MarginsCollapseThrough - }, - _ => { - // If the fragment has non-zero min-block-size, margins may not - // collapse through it. - FinalMarginState::BottomMarginCollapses - }, + if fragment.style().min_block_size().is_definitely_zero() { + FinalMarginState::MarginsCollapseThrough + } else { + // If the fragment has non-zero min-block-size, margins may not + // collapse through it. + FinalMarginState::BottomMarginCollapses } } else { // If the fragment has an explicitly specified block-size, margins may not @@ -445,13 +438,9 @@ impl MaybeAuto { pub fn from_style(length: LengthOrPercentageOrAuto, containing_length: Au) -> MaybeAuto { match length { LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, - LengthOrPercentageOrAuto::Percentage(percent) => { - MaybeAuto::Specified(containing_length.scale_by(percent.0)) + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + MaybeAuto::Specified(lp.to_used_value(containing_length)) }, - LengthOrPercentageOrAuto::Calc(calc) => { - MaybeAuto::from_option(calc.to_used_value(Some(containing_length))) - }, - LengthOrPercentageOrAuto::Length(length) => MaybeAuto::Specified(Au::from(length)), } } @@ -484,6 +473,15 @@ impl MaybeAuto { self.specified_or_default(Au::new(0)) } + #[inline] + pub fn is_auto(&self) -> bool { + match *self { + MaybeAuto::Auto => true, + MaybeAuto::Specified(..) => false, + } + } + + #[inline] pub fn map(&self, mapper: F) -> MaybeAuto where @@ -503,15 +501,11 @@ pub fn style_length( style_length: LengthOrPercentageOrAuto, container_size: Option, ) -> MaybeAuto { - match container_size { - Some(length) => MaybeAuto::from_style(style_length, length), - None => { - if let LengthOrPercentageOrAuto::Length(length) = style_length { - MaybeAuto::Specified(Au::from(length)) - } else { - MaybeAuto::Auto - } - }, + match style_length { + LengthOrPercentageOrAuto::Auto => MaybeAuto::Auto, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + MaybeAuto::from_option(lp.maybe_to_used_value(container_size)) + } } } @@ -580,27 +574,16 @@ impl SizeConstraint { max_size: LengthOrPercentageOrNone, border: Option, ) -> SizeConstraint { - let mut min_size = match container_size { - Some(container_size) => min_size.to_used_value(container_size), - None => { - if let LengthOrPercentage::Length(length) = min_size { - Au::from(length) - } else { - Au(0) - } + let mut min_size = + min_size.maybe_to_used_value(container_size).unwrap_or(Au(0)); + + let mut max_size = match max_size { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(container_size) }, }; - let mut max_size = match container_size { - Some(container_size) => max_size.to_used_value(container_size), - None => { - if let LengthOrPercentageOrNone::Length(length) = max_size { - Some(Au::from(length)) - } else { - None - } - }, - }; // Make sure max size is not smaller than min size. max_size = max_size.map(|x| max(x, min_size)); @@ -609,10 +592,7 @@ impl SizeConstraint { max_size = max_size.map(|x| max(x - border, Au(0))); } - SizeConstraint { - min_size: min_size, - max_size: max_size, - } + SizeConstraint { min_size, max_size } } /// Clamp the given size by the given min size and max size constraint. diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 294670f0a1e..e0234454b27 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -154,11 +154,22 @@ impl Flow for MulticolFlow { this_fragment_is_empty: true, available_block_size: { let style = &self.block_flow.fragment.style; - if let LengthOrPercentageOrAuto::Length(length) = style.content_block_size() { - Au::from(length) - } else if let LengthOrPercentageOrNone::Length(length) = style.max_block_size() { - Au::from(length) - } else { + let size = match style.content_block_size() { + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None) + } + }; + let size = size.or_else(|| { + match style.max_block_size() { + LengthOrPercentageOrNone::None => None, + LengthOrPercentageOrNone::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None) + } + } + }); + + size.unwrap_or_else(|| { // FIXME: do column balancing instead // FIXME: (until column balancing) substract margins/borders/padding LogicalSize::from_physical( @@ -166,7 +177,7 @@ impl Flow for MulticolFlow { ctx.shared_context().viewport_size(), ) .block - } + }) }, }); diff --git a/components/layout/table.rs b/components/layout/table.rs index 5f08b107b31..f492e9056ff 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -301,16 +301,16 @@ impl Flow for TableFlow { self.column_intrinsic_inline_sizes .push(ColumnIntrinsicInlineSize { minimum_length: match *specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => Au(0), - LengthOrPercentageOrAuto::Length(length) => Au::from(length), + LengthOrPercentageOrAuto::Auto => Au(0), + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None).unwrap_or(Au(0)) + }, }, percentage: match *specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Length(_) => 0.0, - LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, + LengthOrPercentageOrAuto::Auto => 0.0, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.as_percentage().map_or(0.0, |p| p.0) + }, }, preferred: Au(0), constrained: false, diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 90c3c812f1c..52412d9a2d1 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -430,25 +430,24 @@ impl Flow for TableRowFlow { let child_base = kid.mut_base(); let child_column_inline_size = ColumnIntrinsicInlineSize { minimum_length: match child_specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => { - child_base.intrinsic_inline_sizes.minimum_inline_size + LengthOrPercentageOrAuto::Auto => None, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None) }, - LengthOrPercentageOrAuto::Length(length) => Au::from(length), - }, + } + .unwrap_or(child_base.intrinsic_inline_sizes.minimum_inline_size), percentage: match child_specified_inline_size { - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Length(_) => 0.0, - LengthOrPercentageOrAuto::Percentage(percentage) => percentage.0, + LengthOrPercentageOrAuto::Auto => 0.0, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.as_percentage().map_or(0.0, |p| p.0) + }, }, preferred: child_base.intrinsic_inline_sizes.preferred_inline_size, constrained: match child_specified_inline_size { - LengthOrPercentageOrAuto::Length(_) => true, - LengthOrPercentageOrAuto::Auto | - LengthOrPercentageOrAuto::Calc(_) | - LengthOrPercentageOrAuto::Percentage(_) => false, + LengthOrPercentageOrAuto::Auto => false, + LengthOrPercentageOrAuto::LengthOrPercentage(ref lp) => { + lp.maybe_to_used_value(None).is_some() + }, }, }; min_inline_size = min_inline_size + child_column_inline_size.minimum_length; diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 233d4a01bb3..6feb6381b77 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -718,7 +718,9 @@ impl LayoutElementHelpers for LayoutDom { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } @@ -743,8 +745,10 @@ impl LayoutElementHelpers for LayoutDom { match width { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let width_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let width_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Percentage( + computed::Percentage(percentage), + ), ); hints.push(from_declaration( shared_lock, @@ -753,9 +757,13 @@ impl LayoutElementHelpers for LayoutDom { }, LengthOrPercentageOrAuto::Length(length) => { let width_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( - specified::AbsoluteLength::Px(length.to_f32_px()), - )); + specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length( + specified::NoCalcLength::Absolute( + specified::AbsoluteLength::Px(length.to_f32_px()), + ), + ), + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Width(width_value), @@ -776,8 +784,10 @@ impl LayoutElementHelpers for LayoutDom { match height { LengthOrPercentageOrAuto::Auto => {}, LengthOrPercentageOrAuto::Percentage(percentage) => { - let height_value = specified::LengthOrPercentageOrAuto::Percentage( - computed::Percentage(percentage), + let height_value = specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Percentage( + computed::Percentage(percentage), + ) ); hints.push(from_declaration( shared_lock, @@ -786,9 +796,13 @@ impl LayoutElementHelpers for LayoutDom { }, LengthOrPercentageOrAuto::Length(length) => { let height_value = - specified::LengthOrPercentageOrAuto::Length(specified::NoCalcLength::Absolute( - specified::AbsoluteLength::Px(length.to_f32_px()), - )); + specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length( + specified::NoCalcLength::Absolute( + specified::AbsoluteLength::Px(length.to_f32_px()), + ) + ) + ); hints.push(from_declaration( shared_lock, PropertyDeclaration::Height(height_value), @@ -815,7 +829,9 @@ impl LayoutElementHelpers for LayoutDom { specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols)); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Width(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } @@ -837,7 +853,9 @@ impl LayoutElementHelpers for LayoutDom { )); hints.push(from_declaration( shared_lock, - PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::Length(value)), + PropertyDeclaration::Height(specified::LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthOrPercentage::Length(value) + )), )); } diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index 53a3acf81ec..ddba7255008 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -297,7 +297,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "min-%s" % size, "LengthOrPercentage", - "computed::LengthOrPercentage::Length(computed::Length::new(0.))", + "computed::LengthOrPercentage::zero()", "parse_non_negative", spec=spec % ("min-%s" % size), logical_group="min-size", diff --git a/tests/unit/style/animated_properties.rs b/tests/unit/style/animated_properties.rs index 06102bc840e..8fa45a6305f 100644 --- a/tests/unit/style/animated_properties.rs +++ b/tests/unit/style/animated_properties.rs @@ -4,7 +4,6 @@ use cssparser::RGBA; use style::values::animated::{Animate, Procedure, ToAnimatedValue}; -use style::values::computed::Percentage; use style::values::generics::transform::{Transform, TransformOperation}; fn interpolate_rgba(from: RGBA, to: RGBA, progress: f64) -> RGBA { @@ -83,60 +82,6 @@ fn test_rgba_color_interepolation_out_of_range_clamped_2() { ); } -// Transform -#[test] -fn test_transform_interpolation_on_translate() { - use style::values::computed::{CalcLengthOrPercentage, Length, LengthOrPercentage}; - - let from = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(0.)), - LengthOrPercentage::Length(Length::new(100.)), - Length::new(25.), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(0.)), - Length::new(75.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(50.)), - LengthOrPercentage::Length(Length::new(50.)), - Length::new(50.), - )]) - ); - - let from = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Percentage(Percentage(0.5)), - LengthOrPercentage::Percentage(Percentage(1.0)), - Length::new(25.), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(50.)), - Length::new(75.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::Translate3D( - // calc(50px + 25%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new( - Length::new(50.), - Some(Percentage(0.25)) - )), - // calc(25px + 50%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new( - Length::new(25.), - Some(Percentage(0.5)) - )), - Length::new(50.), - )]) - ); -} - #[test] fn test_transform_interpolation_on_scale() { let from = Transform(vec![TransformOperation::Scale3D(1.0, 2.0, 1.0)]); @@ -197,29 +142,3 @@ fn test_transform_interpolation_on_skew() { )]) ); } - -#[test] -fn test_transform_interpolation_on_mismatched_lists() { - use style::values::computed::{Angle, Length, LengthOrPercentage}; - - let from = Transform(vec![TransformOperation::Rotate3D( - 0.0, - 0.0, - 1.0, - Angle::from_radians(100.0), - )]); - let to = Transform(vec![TransformOperation::Translate3D( - LengthOrPercentage::Length(Length::new(100.)), - LengthOrPercentage::Length(Length::new(0.)), - Length::new(0.), - )]); - assert_eq!( - from.animate(&to, Procedure::Interpolate { progress: 0.5 }) - .unwrap(), - Transform(vec![TransformOperation::InterpolateMatrix { - from_list: from.clone(), - to_list: to.clone(), - progress: Percentage(0.5), - }]) - ); -} diff --git a/tests/unit/style/attr.rs b/tests/unit/style/attr.rs index 4521d83239a..261d6d8f98b 100644 --- a/tests/unit/style/attr.rs +++ b/tests/unit/style/attr.rs @@ -4,19 +4,6 @@ use app_units::Au; use style::attr::{parse_length, AttrValue, LengthOrPercentageOrAuto}; -use style::values::computed::{CalcLengthOrPercentage, Percentage}; - -#[test] -fn test_length_calc() { - let calc = CalcLengthOrPercentage::new(Au(10).into(), Some(Percentage(0.2))); - assert_eq!(calc.to_used_value(Some(Au(10))), Some(Au(12))); - assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10))); - assert_eq!(calc.to_used_value(None), None); - - let calc = CalcLengthOrPercentage::new(Au(10).into(), None); - assert_eq!(calc.to_used_value(Some(Au(0))), Some(Au(10))); - assert_eq!(calc.to_used_value(None), Some(Au(10))); -} #[test] fn test_parse_double() { diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 035f9a9385c..8853ab010dd 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -4,13 +4,11 @@ use crate::properties::{parse, parse_input}; use crate::stylesheets::block_from; -use style::computed_values::display::T as Display; use style::properties::declaration_block::PropertyDeclarationBlock; use style::properties::parse_property_declaration_list; use style::properties::{Importance, PropertyDeclaration}; use style::values::specified::url::SpecifiedUrl; -use style::values::specified::NoCalcLength; -use style::values::specified::{Length, LengthOrPercentage, LengthOrPercentageOrAuto}; +use style::values::specified::Length; use style_traits::ToCss; trait ToCssString { @@ -25,53 +23,6 @@ impl ToCssString for PropertyDeclarationBlock { } } -#[test] -fn property_declaration_block_should_serialize_correctly() { - use style::properties::longhands::overflow_x::SpecifiedValue as OverflowValue; - - let declarations = vec![ - ( - PropertyDeclaration::Width(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( - 70f32, - ))), - Importance::Normal, - ), - ( - PropertyDeclaration::MinHeight(LengthOrPercentage::Length(NoCalcLength::from_px( - 20f32, - ))), - Importance::Normal, - ), - ( - PropertyDeclaration::Height(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( - 20f32, - ))), - Importance::Important, - ), - ( - PropertyDeclaration::Display(Display::InlineBlock), - Importance::Normal, - ), - ( - PropertyDeclaration::OverflowX(OverflowValue::Auto), - Importance::Normal, - ), - ( - PropertyDeclaration::OverflowY(OverflowValue::Auto), - Importance::Normal, - ), - ]; - - let block = block_from(declarations); - - let css_string = block.to_css_string(); - - assert_eq!( - css_string, - "width: 70px; min-height: 20px; height: 20px !important; display: inline-block; overflow: auto;" - ); -} - mod shorthand_serialization { pub use super::*; diff --git a/tests/unit/style/stylesheets.rs b/tests/unit/style/stylesheets.rs index a0557ad8795..68bbff46f9f 100644 --- a/tests/unit/style/stylesheets.rs +++ b/tests/unit/style/stylesheets.rs @@ -17,20 +17,16 @@ use std::sync::atomic::AtomicBool; use style::context::QuirksMode; use style::error_reporting::{ContextualParseError, ParseErrorReporter}; use style::media_queries::MediaList; -use style::properties::longhands::{self, animation_timing_function}; +use style::properties::longhands; use style::properties::{CSSWideKeyword, CustomDeclaration}; use style::properties::{CustomDeclarationValue, Importance}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::shared_lock::SharedRwLock; -use style::stylesheets::keyframes_rule::{Keyframe, KeyframePercentage, KeyframeSelector}; use style::stylesheets::{ - CssRule, CssRules, KeyframesRule, NamespaceRule, StyleRule, Stylesheet, StylesheetContents, + CssRule, CssRules, NamespaceRule, StyleRule, Stylesheet, StylesheetContents, }; use style::stylesheets::{Namespaces, Origin}; -use style::values::computed::Percentage; -use style::values::specified::TimingFunction; -use style::values::specified::{LengthOrPercentageOrAuto, PositionComponent}; -use style::values::{CustomIdent, KeyframesName}; +use style::values::specified::PositionComponent; pub fn block_from(iterable: I) -> PropertyDeclarationBlock where @@ -61,14 +57,6 @@ fn test_parse_stylesheet() { display: block; } #d1 > .ok { background: blue; } - @keyframes foo { - from { width: 0% } - to { - width: 100%; - width: 50% !important; /* !important not allowed here */ - animation-name: 'foo'; /* animation properties not allowed here */ - animation-timing-function: ease; /* … except animation-timing-function */ - } }"; let url = ServoUrl::parse("about::test").unwrap(); let lock = SharedRwLock::new(); @@ -278,56 +266,6 @@ fn test_parse_stylesheet() { column: 9, }, }))), - CssRule::Keyframes(Arc::new(stylesheet.shared_lock.wrap(KeyframesRule { - name: KeyframesName::Ident(CustomIdent("foo".into())), - keyframes: vec![ - Arc::new(stylesheet.shared_lock.wrap(Keyframe { - selector: KeyframeSelector::new_for_unit_testing(vec![ - KeyframePercentage::new(0.), - ]), - block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![( - PropertyDeclaration::Width( - LengthOrPercentageOrAuto::Percentage(Percentage(0.)), - ), - Importance::Normal, - )]))), - source_location: SourceLocation { - line: 17, - column: 13, - }, - })), - Arc::new(stylesheet.shared_lock.wrap(Keyframe { - selector: KeyframeSelector::new_for_unit_testing(vec![ - KeyframePercentage::new(1.), - ]), - block: Arc::new(stylesheet.shared_lock.wrap(block_from(vec![ - ( - PropertyDeclaration::Width( - LengthOrPercentageOrAuto::Percentage(Percentage(1.)), - ), - Importance::Normal, - ), - ( - PropertyDeclaration::AnimationTimingFunction( - animation_timing_function::SpecifiedValue(vec![ - TimingFunction::ease(), - ]), - ), - Importance::Normal, - ), - ]))), - source_location: SourceLocation { - line: 18, - column: 13, - }, - })), - ], - vendor_prefix: None, - source_location: SourceLocation { - line: 16, - column: 19, - }, - }))), ], &stylesheet.shared_lock, ), diff --git a/tests/unit/style/viewport.rs b/tests/unit/style/viewport.rs index 5855b11e114..41fc2539f39 100644 --- a/tests/unit/style/viewport.rs +++ b/tests/unit/style/viewport.rs @@ -17,6 +17,7 @@ use style::stylesheets::{CssRuleType, Origin, Stylesheet, StylesheetInDocument}; use style::values::specified::LengthOrPercentageOrAuto::{self, Auto}; use style::values::specified::NoCalcLength::{self, ViewportPercentage}; use style::values::specified::ViewportPercentageLength::Vw; +use style::values::specified::LengthOrPercentage; use style_traits::viewport::*; use style_traits::{ParsingMode, PinchZoomFactor}; @@ -96,15 +97,15 @@ macro_rules! assert_decl_len { macro_rules! viewport_length { ($value:expr, px) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length(NoCalcLength::from_px( - $value, - ))) - }; - ($value:expr, vw) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::Length(ViewportPercentage(Vw( + ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(NoCalcLength::from_px( $value, )))) }; + ($value:expr, vw) => { + ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::Length(ViewportPercentage(Vw( + $value, + ))))) + }; } #[test] diff --git a/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini b/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini index d9922a6482f..07ba6517e69 100644 --- a/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini +++ b/tests/wpt/metadata/css/css-variables/variable-substitution-replaced-size.html.ini @@ -1,6 +1,4 @@ [variable-substitution-replaced-size.html] - [height on IFRAME] - expected: FAIL [width on INPUT] expected: FAIL @@ -8,6 +6,3 @@ [height on INPUT] expected: FAIL - [height on CANVAS] - expected: FAIL - From daf1f02febc3a02d19fbfc85cd74c862e804a435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 7 Jan 2019 12:20:30 +0100 Subject: [PATCH 3/6] style: Rename LengthOrPercentage to LengthPercentage. It does not represent ` | `, but ``, so `LengthOrPercentage` is not the right name. This patch is totally autogenerated using: rg 'LengthOrPercentage' servo | cut -d : -f 1 | sort | uniq > files for file in $(cat files); do sed -i "s#LengthOrPercentage#LengthPercentage#g" $file; done Differential Revision: https://phabricator.services.mozilla.com/D15812 --- components/style/attr.rs | 2 +- components/style/gecko/conversions.rs | 84 ++++---- components/style/gecko/values.rs | 50 ++--- .../gecko_bindings/sugar/ns_css_value.rs | 14 +- components/style/properties/gecko.mako.rs | 86 ++++---- .../properties/longhands/background.mako.rs | 2 +- .../style/properties/longhands/border.mako.rs | 8 +- .../style/properties/longhands/box.mako.rs | 6 +- .../longhands/inherited_text.mako.rs | 4 +- .../style/properties/longhands/margin.mako.rs | 4 +- .../properties/longhands/padding.mako.rs | 6 +- .../properties/longhands/position.mako.rs | 28 +-- .../style/properties/longhands/svg.mako.rs | 2 +- .../style/properties/properties.mako.rs | 18 +- .../properties/shorthands/margin.mako.rs | 2 +- .../properties/shorthands/padding.mako.rs | 2 +- components/style/stylesheets/viewport_rule.rs | 18 +- components/style/values/animated/length.rs | 20 +- components/style/values/animated/mod.rs | 4 +- components/style/values/animated/svg.rs | 20 +- components/style/values/animated/transform.rs | 12 +- .../style/values/computed/background.rs | 8 +- .../style/values/computed/basic_shape.rs | 18 +- components/style/values/computed/border.rs | 16 +- components/style/values/computed/box.rs | 4 +- components/style/values/computed/flex.rs | 2 +- components/style/values/computed/gecko.rs | 4 +- components/style/values/computed/image.rs | 12 +- components/style/values/computed/length.rs | 202 +++++++++--------- components/style/values/computed/mod.rs | 14 +- components/style/values/computed/position.rs | 12 +- components/style/values/computed/svg.rs | 36 ++-- components/style/values/computed/text.rs | 4 +- components/style/values/computed/transform.rs | 20 +- .../style/values/generics/background.rs | 10 +- .../style/values/generics/basic_shape.rs | 36 ++-- components/style/values/generics/border.rs | 14 +- components/style/values/generics/box.rs | 4 +- components/style/values/generics/gecko.rs | 4 +- components/style/values/generics/grid.rs | 12 +- components/style/values/generics/image.rs | 28 +-- components/style/values/generics/length.rs | 8 +- components/style/values/generics/svg.rs | 16 +- components/style/values/generics/text.rs | 4 +- components/style/values/generics/transform.rs | 40 ++-- .../style/values/specified/background.rs | 14 +- .../style/values/specified/basic_shape.rs | 24 +-- components/style/values/specified/border.rs | 16 +- components/style/values/specified/box.rs | 6 +- components/style/values/specified/calc.rs | 24 +-- components/style/values/specified/flex.rs | 2 +- components/style/values/specified/font.rs | 24 +-- components/style/values/specified/gecko.rs | 6 +- components/style/values/specified/grid.rs | 26 +-- components/style/values/specified/image.rs | 44 ++-- components/style/values/specified/length.rs | 165 +++++++------- components/style/values/specified/mod.rs | 16 +- components/style/values/specified/position.rs | 34 +-- components/style/values/specified/svg.rs | 32 +-- components/style/values/specified/text.rs | 20 +- .../style/values/specified/transform.rs | 38 ++-- 61 files changed, 709 insertions(+), 702 deletions(-) diff --git a/components/style/attr.rs b/components/style/attr.rs index 16173d64057..926d52cd5f8 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -543,7 +543,7 @@ pub fn parse_legacy_color(mut input: &str) -> Result { /// Parses a [dimension value][dim]. If unparseable, `Auto` is returned. /// /// [dim]: https://html.spec.whatwg.org/multipage/#rules-for-parsing-dimension-values -// TODO: this function can be rewritten to return Result +// TODO: this function can be rewritten to return Result pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto { // Steps 1 & 2 are not relevant diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index 08d0557f896..7e896b37569 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -21,8 +21,8 @@ use crate::values::computed::image::LineDirection; use crate::values::computed::transform::Matrix3D; use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::{Angle, Gradient, Image}; -use crate::values::computed::{Integer, LengthOrPercentage}; -use crate::values::computed::{LengthOrPercentageOrAuto, NonNegativeLengthOrPercentageOrAuto}; +use crate::values::computed::{Integer, LengthPercentage}; +use crate::values::computed::{LengthPercentageOrAuto, NonNegativeLengthPercentageOrAuto}; use crate::values::computed::{Percentage, TextAlign}; use crate::values::generics::box_::VerticalAlign; use crate::values::generics::grid::{TrackListValue, TrackSize}; @@ -33,8 +33,8 @@ use app_units::Au; use std::f32::consts::PI; use style_traits::values::specified::AllowedNumericType; -impl From for nsStyleCoord_CalcValue { - fn from(other: LengthOrPercentage) -> nsStyleCoord_CalcValue { +impl From for nsStyleCoord_CalcValue { + fn from(other: LengthPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { mLength: other.unclamped_length().to_i32_au(), @@ -44,8 +44,8 @@ impl From for nsStyleCoord_CalcValue { } } -impl From for LengthOrPercentage { - fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentage { +impl From for LengthPercentage { + fn from(other: nsStyleCoord_CalcValue) -> LengthPercentage { let percentage = if other.mHasPercent { Some(Percentage(other.mPercent)) } else { @@ -60,28 +60,28 @@ impl From for LengthOrPercentage { } } -impl LengthOrPercentageOrAuto { +impl LengthPercentageOrAuto { /// Convert this value in an appropriate `nsStyleCoord::CalcValue`. pub fn to_calc_value(&self) -> Option { match *self { - LengthOrPercentageOrAuto::LengthOrPercentage(len) => Some(From::from(len)), - LengthOrPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(len) => Some(From::from(len)), + LengthPercentageOrAuto::Auto => None, } } } -impl From for LengthOrPercentageOrAuto { - fn from(other: nsStyleCoord_CalcValue) -> LengthOrPercentageOrAuto { - LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::from(other)) +impl From for LengthPercentageOrAuto { + fn from(other: nsStyleCoord_CalcValue) -> LengthPercentageOrAuto { + LengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other)) } } // FIXME(emilio): A lot of these impl From should probably become explicit or // disappear as we move more stuff to cbindgen. -impl From for NonNegativeLengthOrPercentageOrAuto { +impl From for NonNegativeLengthPercentageOrAuto { fn from(other: nsStyleCoord_CalcValue) -> Self { NonNegative( - LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::with_clamping_mode( + LengthPercentageOrAuto::LengthPercentage(LengthPercentage::with_clamping_mode( Au(other.mLength).into(), if other.mHasPercent { Some(Percentage(other.mPercent)) @@ -101,7 +101,7 @@ impl From for CoordDataValue { } } -fn line_direction(horizontal: LengthOrPercentage, vertical: LengthOrPercentage) -> LineDirection { +fn line_direction(horizontal: LengthPercentage, vertical: LengthPercentage) -> LineDirection { use crate::values::computed::position::Position; use crate::values::specified::position::{X, Y}; @@ -467,8 +467,8 @@ impl nsStyleImage { .as_ref() .unwrap(); let angle = Angle::from_gecko_style_coord(&gecko_gradient.mAngle); - let horizontal_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosX); - let vertical_style = LengthOrPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosY); + let horizontal_style = LengthPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosX); + let vertical_style = LengthPercentage::from_gecko_style_coord(&gecko_gradient.mBgPosY); let kind = match gecko_gradient.mShape as u32 { structs::NS_STYLE_GRADIENT_SHAPE_LINEAR => { @@ -529,20 +529,20 @@ impl nsStyleImage { structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => { let length_percentage_keyword = match gecko_gradient.mSize as u32 { structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => match ( - LengthOrPercentage::from_gecko_style_coord( + LengthPercentage::from_gecko_style_coord( &gecko_gradient.mRadiusX, ), - LengthOrPercentage::from_gecko_style_coord( + LengthPercentage::from_gecko_style_coord( &gecko_gradient.mRadiusY, ), ) { (Some(x), Some(y)) => Ellipse::Radii(x, y), _ => { debug_assert!(false, - "mRadiusX, mRadiusY could not convert to LengthOrPercentage"); + "mRadiusX, mRadiusY could not convert to LengthPercentage"); Ellipse::Radii( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), ) }, }, @@ -561,11 +561,11 @@ impl nsStyleImage { _ => { debug_assert!( false, - "mRadiusX, mRadiusY could not convert to LengthOrPercentage" + "mRadiusX, mRadiusY could not convert to LengthPercentage" ); Position { - horizontal: LengthOrPercentage::zero(), - vertical: LengthOrPercentage::zero(), + horizontal: LengthPercentage::zero(), + vertical: LengthPercentage::zero(), } }, }; @@ -580,13 +580,13 @@ impl nsStyleImage { .map(|ref stop| { if stop.mIsInterpolationHint { GradientItem::InterpolationHint( - LengthOrPercentage::from_gecko_style_coord(&stop.mLocation) - .expect("mLocation could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(&stop.mLocation) + .expect("mLocation could not convert to LengthPercentage"), ) } else { GradientItem::ColorStop(ColorStop { color: stop.mColor.into(), - position: LengthOrPercentage::from_gecko_style_coord(&stop.mLocation), + position: LengthPercentage::from_gecko_style_coord(&stop.mLocation), }) } }) @@ -625,7 +625,7 @@ pub mod basic_shape { BasicShape, ClippingShape, FloatAreaShape, ShapeRadius, }; use crate::values::computed::border::{BorderCornerRadius, BorderRadius}; - use crate::values::computed::length::LengthOrPercentage; + use crate::values::computed::length::LengthPercentage; use crate::values::computed::motion::OffsetPath; use crate::values::computed::position; use crate::values::computed::url::ComputedUrl; @@ -742,10 +742,10 @@ pub mod basic_shape { fn from(other: &'a StyleBasicShape) -> Self { match other.mType { StyleBasicShapeType::Inset => { - let t = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[0]); - let r = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[1]); - let b = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[2]); - let l = LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[3]); + let t = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[0]); + let r = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[1]); + let b = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[2]); + let l = LengthPercentage::from_gecko_style_coord(&other.mCoordinates[3]); let round: BorderRadius = (&other.mRadius).into(); let round = if round.all_zero() { None } else { Some(round) }; let rect = Rect::new( @@ -771,12 +771,12 @@ pub mod basic_shape { let x = 2 * i; let y = x + 1; coords.push(PolygonCoord( - LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[x]) + LengthPercentage::from_gecko_style_coord(&other.mCoordinates[x]) .expect( "polygon() coordinate should be a length, percentage, \ or calc value", ), - LengthOrPercentage::from_gecko_style_coord(&other.mCoordinates[y]) + LengthPercentage::from_gecko_style_coord(&other.mCoordinates[y]) .expect( "polygon() coordinate should be a length, percentage, \ or calc value", @@ -797,12 +797,12 @@ pub mod basic_shape { let get_corner = |index| { BorderCornerRadius::new( NonNegative( - LengthOrPercentage::from_gecko_style_coord(&other.data_at(index)).expect( + LengthPercentage::from_gecko_style_coord(&other.data_at(index)).expect( " should be a length, percentage, or calc value", ), ), NonNegative( - LengthOrPercentage::from_gecko_style_coord(&other.data_at(index + 1)) + LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1)) .expect( " should be a length, percentage, or calc value", ), @@ -958,11 +958,11 @@ impl From for SheetType { } } -impl TrackSize { +impl TrackSize { /// Return TrackSize from given two nsStyleCoord pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { use crate::gecko_bindings::structs::root::nsStyleUnit; - use crate::values::computed::length::LengthOrPercentage; + use crate::values::computed::length::LengthPercentage; use crate::values::generics::grid::{TrackBreadth, TrackSize}; if gecko_min.unit() == nsStyleUnit::eStyleUnit_None { @@ -972,8 +972,8 @@ impl TrackSize { gecko_max.unit() == nsStyleUnit::eStyleUnit_Calc ); return TrackSize::FitContent( - LengthOrPercentage::from_gecko_style_coord(gecko_max) - .expect("gecko_max could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(gecko_max) + .expect("gecko_max could not convert to LengthPercentage"), ); } @@ -1013,7 +1013,7 @@ impl TrackSize { } } -impl TrackListValue { +impl TrackListValue { /// Return TrackSize from given two nsStyleCoord pub fn from_gecko_style_coords(gecko_min: &T, gecko_max: &T) -> Self { TrackListValue::TrackSize(TrackSize::from_gecko_style_coords(gecko_min, gecko_max)) diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 3c11d11e311..b4c26bc7dd8 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -13,9 +13,9 @@ use crate::gecko_bindings::sugar::ns_style_coord::{CoordData, CoordDataMut, Coor use crate::media_queries::Device; use crate::values::computed::basic_shape::ShapeRadius as ComputedShapeRadius; use crate::values::computed::FlexBasis as ComputedFlexBasis; -use crate::values::computed::{Angle, ExtremumLength, Length, LengthOrPercentage}; -use crate::values::computed::{LengthOrPercentageOrAuto, Percentage}; -use crate::values::computed::{LengthOrPercentageOrNone, Number, NumberOrPercentage}; +use crate::values::computed::{Angle, ExtremumLength, Length, LengthPercentage}; +use crate::values::computed::{LengthPercentageOrAuto, Percentage}; +use crate::values::computed::{LengthPercentageOrNone, Number, NumberOrPercentage}; use crate::values::computed::{MaxLength as ComputedMaxLength, MozLength as ComputedMozLength}; use crate::values::generics::basic_shape::ShapeRadius; use crate::values::generics::box_::Perspective; @@ -146,7 +146,7 @@ impl GeckoStyleCoordConvertible for NumberOrPercentage { } } -impl GeckoStyleCoordConvertible for LengthOrPercentage { +impl GeckoStyleCoordConvertible for LengthPercentage { fn to_gecko_style_coord(&self, coord: &mut T) { if self.was_calc { return coord.set_value(CoordDataValue::Calc((*self).into())) @@ -160,8 +160,8 @@ impl GeckoStyleCoordConvertible for LengthOrPercentage { fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Coord(coord) => Some(LengthOrPercentage::new(Au(coord).into(), None)), - CoordDataValue::Percent(p) => Some(LengthOrPercentage::new(Au(0).into(), Some(Percentage(p)))), + CoordDataValue::Coord(coord) => Some(LengthPercentage::new(Au(coord).into(), None)), + CoordDataValue::Percent(p) => Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p)))), CoordDataValue::Calc(calc) => Some(calc.into()), _ => None, } @@ -181,34 +181,34 @@ impl GeckoStyleCoordConvertible for Length { } } -impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { +impl GeckoStyleCoordConvertible for LengthPercentageOrAuto { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - LengthOrPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto), - LengthOrPercentageOrAuto::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), + LengthPercentageOrAuto::Auto => coord.set_value(CoordDataValue::Auto), + LengthPercentageOrAuto::LengthPercentage(ref lop) => lop.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::Auto => Some(LengthOrPercentageOrAuto::Auto), - _ => LengthOrPercentage::from_gecko_style_coord(coord).map(LengthOrPercentageOrAuto::LengthOrPercentage), + CoordDataValue::Auto => Some(LengthPercentageOrAuto::Auto), + _ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrAuto::LengthPercentage), } } } -impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { +impl GeckoStyleCoordConvertible for LengthPercentageOrNone { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - LengthOrPercentageOrNone::None => coord.set_value(CoordDataValue::None), - LengthOrPercentageOrNone::LengthOrPercentage(ref lop) => lop.to_gecko_style_coord(coord), + LengthPercentageOrNone::None => coord.set_value(CoordDataValue::None), + LengthPercentageOrNone::LengthPercentage(ref lop) => lop.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { match coord.as_value() { - CoordDataValue::None => Some(LengthOrPercentageOrNone::None), - _ => LengthOrPercentage::from_gecko_style_coord(coord).map(LengthOrPercentageOrNone::LengthOrPercentage), + CoordDataValue::None => Some(LengthPercentageOrNone::None), + _ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrNone::LengthPercentage), } } } @@ -363,14 +363,14 @@ impl GeckoStyleCoordConvertible for ExtremumLength { impl GeckoStyleCoordConvertible for ComputedMozLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MozLength::LengthOrPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord), + MozLength::LengthPercentageOrAuto(ref lopoa) => lopoa.to_gecko_style_coord(coord), MozLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthOrPercentageOrAuto::from_gecko_style_coord(coord) - .map(MozLength::LengthOrPercentageOrAuto) + LengthPercentageOrAuto::from_gecko_style_coord(coord) + .map(MozLength::LengthPercentageOrAuto) .or_else(|| { ExtremumLength::from_gecko_style_coord(coord).map(MozLength::ExtremumLength) }) @@ -380,21 +380,21 @@ impl GeckoStyleCoordConvertible for ComputedMozLength { impl GeckoStyleCoordConvertible for ComputedMaxLength { fn to_gecko_style_coord(&self, coord: &mut T) { match *self { - MaxLength::LengthOrPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord), + MaxLength::LengthPercentageOrNone(ref lopon) => lopon.to_gecko_style_coord(coord), MaxLength::ExtremumLength(ref e) => e.to_gecko_style_coord(coord), } } fn from_gecko_style_coord(coord: &T) -> Option { - LengthOrPercentageOrNone::from_gecko_style_coord(coord) - .map(MaxLength::LengthOrPercentageOrNone) + LengthPercentageOrNone::from_gecko_style_coord(coord) + .map(MaxLength::LengthPercentageOrNone) .or_else(|| { ExtremumLength::from_gecko_style_coord(coord).map(MaxLength::ExtremumLength) }) } } -impl GeckoStyleCoordConvertible for ScrollSnapPoint { +impl GeckoStyleCoordConvertible for ScrollSnapPoint { fn to_gecko_style_coord(&self, coord: &mut T) { match self.repeated() { None => coord.set_value(CoordDataValue::None), @@ -409,8 +409,8 @@ impl GeckoStyleCoordConvertible for ScrollSnapPoint { Some(match coord.unit() { nsStyleUnit::eStyleUnit_None => ScrollSnapPoint::None, _ => ScrollSnapPoint::Repeat( - LengthOrPercentage::from_gecko_style_coord(coord) - .expect("coord could not convert to LengthOrPercentage"), + LengthPercentage::from_gecko_style_coord(coord) + .expect("coord could not convert to LengthPercentage"), ), }) } diff --git a/components/style/gecko_bindings/sugar/ns_css_value.rs b/components/style/gecko_bindings/sugar/ns_css_value.rs index f9ed43f7a3d..b3fb82f041f 100644 --- a/components/style/gecko_bindings/sugar/ns_css_value.rs +++ b/components/style/gecko_bindings/sugar/ns_css_value.rs @@ -9,7 +9,7 @@ use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::{nsCSSUnit, nsCSSValue}; use crate::gecko_bindings::structs::{nsCSSValueList, nsCSSValue_Array}; use crate::gecko_string_cache::Atom; -use crate::values::computed::{Angle, Length, LengthOrPercentage, Percentage}; +use crate::values::computed::{Angle, Length, LengthPercentage, Percentage}; use std::marker::PhantomData; use std::mem; use std::ops::{Index, IndexMut}; @@ -67,8 +67,8 @@ impl nsCSSValue { &*array } - /// Sets LengthOrPercentage value to this nsCSSValue. - pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) { + /// Sets LengthPercentage value to this nsCSSValue. + pub unsafe fn set_lop(&mut self, lop: LengthPercentage) { if lop.was_calc { return bindings::Gecko_CSSValue_SetCalc(self, lop.into()) } @@ -89,16 +89,16 @@ impl nsCSSValue { bindings::Gecko_CSSValue_SetPercentage(self, unit_value) } - /// Returns LengthOrPercentage value. - pub unsafe fn get_lop(&self) -> LengthOrPercentage { + /// Returns LengthPercentage value. + pub unsafe fn get_lop(&self) -> LengthPercentage { match self.mUnit { nsCSSUnit::eCSSUnit_Pixel => { - LengthOrPercentage::new( + LengthPercentage::new( Length::new(bindings::Gecko_CSSValue_GetNumber(self)), None, ) }, - nsCSSUnit::eCSSUnit_Percent => LengthOrPercentage::new_percent(Percentage( + nsCSSUnit::eCSSUnit_Percent => LengthPercentage::new_percent(Percentage( bindings::Gecko_CSSValue_GetPercentage(self), )), nsCSSUnit::eCSSUnit_Calc => { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 036653d218e..673de55681f 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -510,7 +510,7 @@ def set_gecko_property(ffi_name, expr): // set on mContextFlags, and the length field is set to the initial value. pub fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) { - use crate::values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber}; + use crate::values::generics::svg::{SVGLength, SvgLengthPercentageOrNumber}; use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; let length = match v { SVGLength::Length(length) => { @@ -526,9 +526,9 @@ def set_gecko_property(ffi_name, expr): } }; match length { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => + SvgLengthPercentageOrNumber::LengthPercentage(lop) => self.gecko.${gecko_ffi_name}.set(lop), - SvgLengthOrPercentageOrNumber::Number(num) => + SvgLengthPercentageOrNumber::Number(num) => self.gecko.${gecko_ffi_name}.set_value(CoordDataValue::Factor(num.into())), } } @@ -546,28 +546,28 @@ def set_gecko_property(ffi_name, expr): } pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use crate::values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber}; - use crate::values::computed::LengthOrPercentage; + use crate::values::generics::svg::{SVGLength, SvgLengthPercentageOrNumber}; + use crate::values::computed::LengthPercentage; use crate::gecko_bindings::structs::nsStyleSVG_${ident.upper()}_CONTEXT as CONTEXT_VALUE; if (self.gecko.mContextFlags & CONTEXT_VALUE) != 0 { return SVGLength::ContextValue; } let length = match self.gecko.${gecko_ffi_name}.as_value() { CoordDataValue::Factor(number) => { - SvgLengthOrPercentageOrNumber::Number(number) + SvgLengthPercentageOrNumber::Number(number) }, CoordDataValue::Coord(coord) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::new(Au(coord).into(), None) + SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new(Au(coord).into(), None) ) }, CoordDataValue::Percent(p) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::new(Au(0).into(), Some(Percentage(p))) + SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new(Au(0).into(), Some(Percentage(p))) ) }, CoordDataValue::Calc(calc) => { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(calc.into()) + SvgLengthPercentageOrNumber::LengthPercentage(calc.into()) }, _ => unreachable!("Unexpected coordinate in ${ident}"), }; @@ -1269,12 +1269,12 @@ pub fn clone_transform_from_list( #[allow(non_snake_case)] pub fn clone_${ident}(&self) -> values::computed::TransformOrigin { - use crate::values::computed::{Length, LengthOrPercentage, TransformOrigin}; + use crate::values::computed::{Length, LengthPercentage, TransformOrigin}; TransformOrigin { - horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0]) - .expect("clone for LengthOrPercentage failed"), - vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) - .expect("clone for LengthOrPercentage failed"), + horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[0]) + .expect("clone for LengthPercentage failed"), + vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.${gecko_ffi_name}[1]) + .expect("clone for LengthPercentage failed"), depth: if let Some(third) = self.gecko.${gecko_ffi_name}.get(2) { Length::from_gecko_style_coord(third) .expect("clone for Length failed") @@ -1402,19 +1402,19 @@ impl Clone for ${style_struct.gecko_struct_name} { "length::LengthOrAuto": impl_style_coord, "length::LengthOrNormal": impl_style_coord, "length::NonNegativeLengthOrAuto": impl_style_coord, - "length::NonNegativeLengthOrPercentageOrNormal": impl_style_coord, + "length::NonNegativeLengthPercentageOrNormal": impl_style_coord, "FillRule": impl_simple, "FlexBasis": impl_style_coord, "Length": impl_absolute_length, "LengthOrNormal": impl_style_coord, - "LengthOrPercentage": impl_style_coord, - "LengthOrPercentageOrAuto": impl_style_coord, - "LengthOrPercentageOrNone": impl_style_coord, + "LengthPercentage": impl_style_coord, + "LengthPercentageOrAuto": impl_style_coord, + "LengthPercentageOrNone": impl_style_coord, "MaxLength": impl_style_coord, "MozLength": impl_style_coord, "MozScriptMinSize": impl_absolute_length, "MozScriptSizeMultiplier": impl_simple, - "NonNegativeLengthOrPercentage": impl_style_coord, + "NonNegativeLengthPercentage": impl_style_coord, "NonNegativeNumber": impl_simple, "Number": impl_simple, "Opacity": impl_simple, @@ -3084,7 +3084,7 @@ fn static_assert() { } pub fn clone_vertical_align(&self) -> longhands::vertical_align::computed_value::T { - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; use crate::values::generics::box_::VerticalAlign; let gecko = &self.gecko.mVerticalAlign; @@ -3092,7 +3092,7 @@ fn static_assert() { CoordDataValue::Enumerated(value) => VerticalAlign::from_gecko_keyword(value), _ => { VerticalAlign::Length( - LengthOrPercentage::from_gecko_style_coord(gecko).expect( + LengthPercentage::from_gecko_style_coord(gecko).expect( "expected for vertical-align", ), ) @@ -3386,11 +3386,11 @@ fn static_assert() { pub fn clone_perspective_origin(&self) -> longhands::perspective_origin::computed_value::T { use crate::properties::longhands::perspective_origin::computed_value::T; - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; T { - horizontal: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0]) + horizontal: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[0]) .expect("Expected length or percentage for horizontal value of perspective-origin"), - vertical: LengthOrPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1]) + vertical: LengthPercentage::from_gecko_style_coord(&self.gecko.mPerspectiveOrigin[1]) .expect("Expected length or percentage for vertical value of perspective-origin"), } } @@ -3879,12 +3879,12 @@ fn static_assert() { pub fn clone_${shorthand}_size(&self) -> longhands::${shorthand}_size::computed_value::T { use crate::gecko_bindings::structs::nsStyleCoord_CalcValue as CalcValue; use crate::gecko_bindings::structs::nsStyleImageLayers_Size_DimensionType as DimensionType; - use crate::values::computed::NonNegativeLengthOrPercentageOrAuto; + use crate::values::computed::NonNegativeLengthPercentageOrAuto; use crate::values::generics::background::BackgroundSize; - fn to_servo(value: CalcValue, ty: u8) -> NonNegativeLengthOrPercentageOrAuto { + fn to_servo(value: CalcValue, ty: u8) -> NonNegativeLengthPercentageOrAuto { if ty == DimensionType::eAuto as u8 { - NonNegativeLengthOrPercentageOrAuto::auto() + NonNegativeLengthPercentageOrAuto::auto() } else { debug_assert_eq!(ty, DimensionType::eLengthPercentage as u8); value.into() @@ -4575,7 +4575,7 @@ fn static_assert() { } pub fn clone_word_spacing(&self) -> longhands::word_spacing::computed_value::T { - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; use crate::values::generics::text::Spacing; debug_assert!( matches!(self.gecko.mWordSpacing.as_value(), @@ -4584,7 +4584,7 @@ fn static_assert() { CoordDataValue::Percent(_) | CoordDataValue::Calc(_)), "Unexpected computed value for word-spacing"); - LengthOrPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing).map_or(Spacing::Normal, Spacing::Value) + LengthPercentage::from_gecko_style_coord(&self.gecko.mWordSpacing).map_or(Spacing::Normal, Spacing::Value) } <%call expr="impl_coord_copy('word_spacing', 'mWordSpacing')"> @@ -5016,7 +5016,7 @@ clip-path pub fn set_stroke_dasharray(&mut self, v: longhands::stroke_dasharray::computed_value::T) { use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE; - use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthOrPercentageOrNumber}; + use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthPercentageOrNumber}; match v { SVGStrokeDashArray::Values(v) => { @@ -5027,9 +5027,9 @@ clip-path } for (gecko, servo) in self.gecko.mStrokeDasharray.iter_mut().zip(v) { match servo { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => + SvgLengthPercentageOrNumber::LengthPercentage(lop) => gecko.set(lop), - SvgLengthOrPercentageOrNumber::Number(num) => + SvgLengthPercentageOrNumber::Number(num) => gecko.set_value(CoordDataValue::Factor(num.into())), } } @@ -5059,9 +5059,9 @@ clip-path pub fn clone_stroke_dasharray(&self) -> longhands::stroke_dasharray::computed_value::T { use crate::gecko_bindings::structs::nsStyleSVG_STROKE_DASHARRAY_CONTEXT as CONTEXT_VALUE; - use crate::values::computed::LengthOrPercentage; + use crate::values::computed::LengthPercentage; use crate::values::generics::NonNegative; - use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthOrPercentageOrNumber}; + use crate::values::generics::svg::{SVGStrokeDashArray, SvgLengthPercentageOrNumber}; if self.gecko.mContextFlags & CONTEXT_VALUE != 0 { debug_assert_eq!(self.gecko.mStrokeDasharray.len(), 0); @@ -5071,16 +5071,16 @@ clip-path for gecko in self.gecko.mStrokeDasharray.iter() { match gecko.as_value() { CoordDataValue::Factor(number) => - vec.push(SvgLengthOrPercentageOrNumber::Number(number.into())), + vec.push(SvgLengthPercentageOrNumber::Number(number.into())), CoordDataValue::Coord(coord) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - NonNegative(LengthOrPercentage::new(Au(coord).into(), None).into()))), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::new(Au(coord).into(), None).into()))), CoordDataValue::Percent(p) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - NonNegative(LengthOrPercentage::new_percent(Percentage(p)).into()))), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::new_percent(Percentage(p)).into()))), CoordDataValue::Calc(calc) => - vec.push(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - NonNegative(LengthOrPercentage::from(calc).clamp_to_non_negative()))), + vec.push(SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::from(calc).clamp_to_non_negative()))), _ => unreachable!(), } } diff --git a/components/style/properties/longhands/background.mako.rs b/components/style/properties/longhands/background.mako.rs index b97545898c2..c6a25be53c1 100644 --- a/components/style/properties/longhands/background.mako.rs +++ b/components/style/properties/longhands/background.mako.rs @@ -35,7 +35,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "background-position-" + axis, "position::" + direction + "Position", - initial_value="computed::LengthOrPercentage::zero()", + initial_value="computed::LengthPercentage::zero()", initial_specified_value="SpecifiedValue::initial_specified_value()", spec="https://drafts.csswg.org/css-backgrounds-4/#propdef-background-position-" + axis, animation_value_type="ComputedValue", diff --git a/components/style/properties/longhands/border.mako.rs b/components/style/properties/longhands/border.mako.rs index 3fcf73bf2f4..79df20d7812 100644 --- a/components/style/properties/longhands/border.mako.rs +++ b/components/style/properties/longhands/border.mako.rs @@ -69,7 +69,7 @@ ${helpers.gecko_keyword_conversion( type="crate::values::specified::BorderStyle", )} -// FIXME(#4126): when gfx supports painting it, make this Size2D +// FIXME(#4126): when gfx supports painting it, make this Size2D % for corner in ["top-left", "top-right", "bottom-right", "bottom-left"]: ${helpers.predefined_type( "border-" + corner + "-radius", @@ -189,7 +189,7 @@ impl crate::values::computed::BorderImageWidth { use crate::gecko_bindings::structs::nsStyleUnit::{eStyleUnit_Factor, eStyleUnit_Auto}; use crate::gecko_bindings::sugar::ns_style_coord::CoordData; use crate::gecko::values::GeckoStyleCoordConvertible; - use crate::values::computed::{LengthOrPercentage, Number}; + use crate::values::computed::{LengthPercentage, Number}; use crate::values::generics::border::BorderImageSideWidth; use crate::values::generics::NonNegative; @@ -207,8 +207,8 @@ impl crate::values::computed::BorderImageWidth { }, _ => { BorderImageSideWidth::Length( - NonNegative(LengthOrPercentage::from_gecko_style_coord(&sides.data_at(${i})) - .expect("sides[${i}] could not convert to LengthOrPercentage"))) + NonNegative(LengthPercentage::from_gecko_style_coord(&sides.data_at(${i})) + .expect("sides[${i}] could not convert to LengthPercentage"))) }, }, % endfor diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index 48b83271d9b..1818179a442 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -611,10 +611,10 @@ ${helpers.predefined_type( ${helpers.predefined_type( "shape-margin", - "NonNegativeLengthOrPercentage", - "computed::NonNegativeLengthOrPercentage::zero()", + "NonNegativeLengthPercentage", + "computed::NonNegativeLengthPercentage::zero()", products="gecko", - animation_value_type="NonNegativeLengthOrPercentage", + animation_value_type="NonNegativeLengthPercentage", flags="APPLIES_TO_FIRST_LETTER", spec="https://drafts.csswg.org/css-shapes/#shape-margin-property", )} diff --git a/components/style/properties/longhands/inherited_text.mako.rs b/components/style/properties/longhands/inherited_text.mako.rs index 3eded4ea7ac..b1ed79379ca 100644 --- a/components/style/properties/longhands/inherited_text.mako.rs +++ b/components/style/properties/longhands/inherited_text.mako.rs @@ -53,8 +53,8 @@ ${helpers.single_keyword( ${helpers.predefined_type( "text-indent", - "LengthOrPercentage", - "computed::LengthOrPercentage::zero()", + "LengthPercentage", + "computed::LengthPercentage::zero()", animation_value_type="ComputedValue", spec="https://drafts.csswg.org/css-text/#propdef-text-indent", allow_quirks=True, diff --git a/components/style/properties/longhands/margin.mako.rs b/components/style/properties/longhands/margin.mako.rs index 7762be1a23a..e5eac633c96 100644 --- a/components/style/properties/longhands/margin.mako.rs +++ b/components/style/properties/longhands/margin.mako.rs @@ -14,8 +14,8 @@ %> ${helpers.predefined_type( "margin-%s" % side[0], - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::zero()", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::zero()", alias=maybe_moz_logical_alias(product, side, "-moz-margin-%s"), allow_quirks=not side[1], animation_value_type="ComputedValue", diff --git a/components/style/properties/longhands/padding.mako.rs b/components/style/properties/longhands/padding.mako.rs index edfc37d31e6..5fa51863629 100644 --- a/components/style/properties/longhands/padding.mako.rs +++ b/components/style/properties/longhands/padding.mako.rs @@ -16,10 +16,10 @@ %> ${helpers.predefined_type( "padding-%s" % side[0], - "NonNegativeLengthOrPercentage", - "computed::NonNegativeLengthOrPercentage::zero()", + "NonNegativeLengthPercentage", + "computed::NonNegativeLengthPercentage::zero()", alias=maybe_moz_logical_alias(product, side, "-moz-padding-%s"), - animation_value_type="NonNegativeLengthOrPercentage", + animation_value_type="NonNegativeLengthPercentage", logical=side[1], logical_group="padding", spec=spec, diff --git a/components/style/properties/longhands/position.mako.rs b/components/style/properties/longhands/position.mako.rs index ddba7255008..a7a6910f954 100644 --- a/components/style/properties/longhands/position.mako.rs +++ b/components/style/properties/longhands/position.mako.rs @@ -12,8 +12,8 @@ % for side in PHYSICAL_SIDES: ${helpers.predefined_type( side, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", spec="https://www.w3.org/TR/CSS2/visuren.html#propdef-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", animation_value_type="ComputedValue", @@ -26,8 +26,8 @@ % for side in LOGICAL_SIDES: ${helpers.predefined_type( "inset-%s" % side, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", spec="https://drafts.csswg.org/css-logical-props/#propdef-inset-%s" % side, flags="GETCS_NEEDS_LAYOUT_FLUSH", alias="offset-%s:layout.css.offset-logical-properties.enabled" % side, @@ -285,8 +285,8 @@ ${helpers.predefined_type( // servo versions (no keyword support) ${helpers.predefined_type( size, - "LengthOrPercentageOrAuto", - "computed::LengthOrPercentageOrAuto::Auto", + "LengthPercentageOrAuto", + "computed::LengthPercentageOrAuto::Auto", "parse_non_negative", spec=spec % size, logical_group="size", @@ -296,8 +296,8 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( "min-%s" % size, - "LengthOrPercentage", - "computed::LengthOrPercentage::zero()", + "LengthPercentage", + "computed::LengthPercentage::zero()", "parse_non_negative", spec=spec % ("min-%s" % size), logical_group="min-size", @@ -308,8 +308,8 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( "max-%s" % size, - "LengthOrPercentageOrNone", - "computed::LengthOrPercentageOrNone::None", + "LengthPercentageOrNone", + "computed::LengthPercentageOrNone::None", "parse_non_negative", spec=spec % ("max-%s" % size), logical_group="max-size", @@ -408,24 +408,24 @@ ${helpers.predefined_type( ${helpers.predefined_type( "column-gap", - "length::NonNegativeLengthOrPercentageOrNormal", + "length::NonNegativeLengthPercentageOrNormal", "Either::Second(Normal)", alias="grid-column-gap" if product == "gecko" else "", extra_prefixes="moz", servo_pref="layout.columns.enabled", spec="https://drafts.csswg.org/css-align-3/#propdef-column-gap", - animation_value_type="NonNegativeLengthOrPercentageOrNormal", + animation_value_type="NonNegativeLengthPercentageOrNormal", servo_restyle_damage="reflow", )} // no need for -moz- prefixed alias for this property ${helpers.predefined_type( "row-gap", - "length::NonNegativeLengthOrPercentageOrNormal", + "length::NonNegativeLengthPercentageOrNormal", "Either::Second(Normal)", alias="grid-row-gap", products="gecko", spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap", - animation_value_type="NonNegativeLengthOrPercentageOrNormal", + animation_value_type="NonNegativeLengthPercentageOrNormal", servo_restyle_damage="reflow", )} diff --git a/components/style/properties/longhands/svg.mako.rs b/components/style/properties/longhands/svg.mako.rs index 43a8952d86e..f003fa5222e 100644 --- a/components/style/properties/longhands/svg.mako.rs +++ b/components/style/properties/longhands/svg.mako.rs @@ -118,7 +118,7 @@ ${helpers.predefined_type( ${helpers.predefined_type( "mask-position-" + axis, "position::" + direction + "Position", - "computed::LengthOrPercentage::zero()", + "computed::LengthPercentage::zero()", products="gecko", extra_prefixes="webkit", initial_specified_value="specified::PositionComponent::Center", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 494bdc7706d..2d91273be15 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -3017,7 +3017,7 @@ impl ComputedValuesInner { /// Get the logical computed inline size. #[inline] - pub fn content_inline_size(&self) -> computed::LengthOrPercentageOrAuto { + pub fn content_inline_size(&self) -> computed::LengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.height @@ -3028,42 +3028,42 @@ impl ComputedValuesInner { /// Get the logical computed block size. #[inline] - pub fn content_block_size(&self) -> computed::LengthOrPercentageOrAuto { + pub fn content_block_size(&self) -> computed::LengthPercentageOrAuto { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.width } else { position_style.height } } /// Get the logical computed min inline size. #[inline] - pub fn min_inline_size(&self) -> computed::LengthOrPercentage { + pub fn min_inline_size(&self) -> computed::LengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_height } else { position_style.min_width } } /// Get the logical computed min block size. #[inline] - pub fn min_block_size(&self) -> computed::LengthOrPercentage { + pub fn min_block_size(&self) -> computed::LengthPercentage { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.min_width } else { position_style.min_height } } /// Get the logical computed max inline size. #[inline] - pub fn max_inline_size(&self) -> computed::LengthOrPercentageOrNone { + pub fn max_inline_size(&self) -> computed::LengthPercentageOrNone { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_height } else { position_style.max_width } } /// Get the logical computed max block size. #[inline] - pub fn max_block_size(&self) -> computed::LengthOrPercentageOrNone { + pub fn max_block_size(&self) -> computed::LengthPercentageOrNone { let position_style = self.get_position(); if self.writing_mode.is_vertical() { position_style.max_width } else { position_style.max_height } } /// Get the logical computed padding for this writing mode. #[inline] - pub fn logical_padding(&self) -> LogicalMargin { + pub fn logical_padding(&self) -> LogicalMargin { let padding_style = self.get_padding(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( padding_style.padding_top.0, @@ -3093,7 +3093,7 @@ impl ComputedValuesInner { /// Gets the logical computed margin from this style. #[inline] - pub fn logical_margin(&self) -> LogicalMargin { + pub fn logical_margin(&self) -> LogicalMargin { let margin_style = self.get_margin(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( margin_style.margin_top, @@ -3105,7 +3105,7 @@ impl ComputedValuesInner { /// Gets the logical position from this style. #[inline] - pub fn logical_position(&self) -> LogicalMargin { + pub fn logical_position(&self) -> LogicalMargin { // FIXME(SimonSapin): should be the writing mode of the containing block, maybe? let position_style = self.get_position(); LogicalMargin::from_physical(self.writing_mode, SideOffsets2D::new( diff --git a/components/style/properties/shorthands/margin.mako.rs b/components/style/properties/shorthands/margin.mako.rs index 944d4a3e6a1..86e3b56a226 100644 --- a/components/style/properties/shorthands/margin.mako.rs +++ b/components/style/properties/shorthands/margin.mako.rs @@ -4,7 +4,7 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthOrPercentageOrAuto::parse", +${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthPercentageOrAuto::parse", spec="https://drafts.csswg.org/css-box/#propdef-margin", allowed_in_page_rule=True, allow_quirks=True)} diff --git a/components/style/properties/shorthands/padding.mako.rs b/components/style/properties/shorthands/padding.mako.rs index 41db5d3a0fe..0314a46938d 100644 --- a/components/style/properties/shorthands/padding.mako.rs +++ b/components/style/properties/shorthands/padding.mako.rs @@ -4,6 +4,6 @@ <%namespace name="helpers" file="/helpers.mako.rs" /> -${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthOrPercentage::parse", +${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthPercentage::parse", spec="https://drafts.csswg.org/css-box-3/#propdef-padding", allow_quirks=True)} diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index 209243228df..ce63ffbfc47 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -18,7 +18,7 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard use crate::str::CssStringWriter; use crate::stylesheets::{Origin, StylesheetInDocument}; use crate::values::computed::{Context, ToComputedValue}; -use crate::values::specified::{self, LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; +use crate::values::specified::{self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength}; use app_units::Au; use cssparser::CowRcStr; use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser}; @@ -149,7 +149,7 @@ trait FromMeta: Sized { #[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive(Clone, Debug, PartialEq, ToCss)] pub enum ViewportLength { - Specified(LengthOrPercentageOrAuto), + Specified(LengthPercentageOrAuto), ExtendToZoom, } @@ -157,8 +157,8 @@ impl FromMeta for ViewportLength { fn from_meta(value: &str) -> Option { macro_rules! specified { ($value:expr) => { - ViewportLength::Specified(LengthOrPercentageOrAuto::LengthOrPercentage( - specified::LengthOrPercentage::Length($value) + ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage( + specified::LengthPercentage::Length($value) )) }; } @@ -186,7 +186,7 @@ impl ViewportLength { ) -> Result> { // we explicitly do not accept 'extend-to-zoom', since it is a UA // internal value for viewport translation - LengthOrPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) + LengthPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified) } } @@ -468,10 +468,10 @@ impl ViewportRule { if !has_width && has_zoom { if has_height { push_descriptor!(MinWidth(ViewportLength::Specified( - LengthOrPercentageOrAuto::Auto + LengthPercentageOrAuto::Auto ))); push_descriptor!(MaxWidth(ViewportLength::Specified( - LengthOrPercentageOrAuto::Auto + LengthPercentageOrAuto::Auto ))); } else { push_descriptor!(MinWidth(ViewportLength::ExtendToZoom)); @@ -754,8 +754,8 @@ impl MaybeNew for ViewportConstraints { if let Some($value) = $value { match *$value { ViewportLength::Specified(ref length) => match *length { - LengthOrPercentageOrAuto::Auto => None, - LengthOrPercentageOrAuto::LengthOrPercentage(ref lop) => Some(lop + LengthPercentageOrAuto::Auto => None, + LengthPercentageOrAuto::LengthPercentage(ref lop) => Some(lop .to_computed_value(&context) .to_used_value(initial_viewport.$dimension)), }, diff --git a/components/style/values/animated/length.rs b/components/style/values/animated/length.rs index b0d717b0e49..f3d002b4fd0 100644 --- a/components/style/values/animated/length.rs +++ b/components/style/values/animated/length.rs @@ -5,13 +5,13 @@ //! Animation implementation for various length-related types. use super::{Animate, Procedure, ToAnimatedValue}; -use crate::values::computed::length::LengthOrPercentage; +use crate::values::computed::length::LengthPercentage; use crate::values::computed::MaxLength as ComputedMaxLength; use crate::values::computed::MozLength as ComputedMozLength; use crate::values::computed::Percentage; /// -impl Animate for LengthOrPercentage { +impl Animate for LengthPercentage { #[inline] fn animate(&self, other: &Self, procedure: Procedure) -> Result { let animate_percentage_half = |this: Option, other: Option| { @@ -48,17 +48,17 @@ impl ToAnimatedValue for ComputedMaxLength { #[inline] fn from_animated_value(animated: Self::AnimatedValue) -> Self { - use crate::values::computed::LengthOrPercentageOrNone; + use crate::values::computed::LengthPercentageOrNone; use crate::values::generics::length::MaxLength as GenericMaxLength; match animated { - GenericMaxLength::LengthOrPercentageOrNone(lopn) => { + GenericMaxLength::LengthPercentageOrNone(lopn) => { let result = match lopn { - LengthOrPercentageOrNone::LengthOrPercentage(len) => { - LengthOrPercentageOrNone::LengthOrPercentage(len.clamp_to_non_negative()) + LengthPercentageOrNone::LengthPercentage(len) => { + LengthPercentageOrNone::LengthPercentage(len.clamp_to_non_negative()) }, - LengthOrPercentageOrNone::None => lopn, + LengthPercentageOrNone::None => lopn, }; - GenericMaxLength::LengthOrPercentageOrNone(result) + GenericMaxLength::LengthPercentageOrNone(result) }, _ => animated, } @@ -77,8 +77,8 @@ impl ToAnimatedValue for ComputedMozLength { fn from_animated_value(animated: Self::AnimatedValue) -> Self { use crate::values::generics::length::MozLength as GenericMozLength; match animated { - GenericMozLength::LengthOrPercentageOrAuto(lopa) => { - GenericMozLength::LengthOrPercentageOrAuto(lopa.clamp_to_non_negative()) + GenericMozLength::LengthPercentageOrAuto(lopa) => { + GenericMozLength::LengthPercentageOrAuto(lopa.clamp_to_non_negative()) }, _ => animated, } diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 1655f2eaa26..a4e79074ef6 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -9,7 +9,7 @@ //! module's raison d'être is to ultimately contain all these types. use crate::properties::PropertyId; -use crate::values::computed::length::LengthOrPercentage; +use crate::values::computed::length::LengthPercentage; use crate::values::computed::url::ComputedUrl; use crate::values::computed::Angle as ComputedAngle; use crate::values::computed::Image; @@ -335,7 +335,7 @@ macro_rules! trivial_to_animated_value { } trivial_to_animated_value!(Au); -trivial_to_animated_value!(LengthOrPercentage); +trivial_to_animated_value!(LengthPercentage); trivial_to_animated_value!(ComputedAngle); trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); diff --git a/components/style/values/animated/svg.rs b/components/style/values/animated/svg.rs index 7123542aef8..4f181981d91 100644 --- a/components/style/values/animated/svg.rs +++ b/components/style/values/animated/svg.rs @@ -8,9 +8,9 @@ use super::{Animate, Procedure, ToAnimatedZero}; use crate::properties::animated_properties::ListAnimation; use crate::values::animated::color::Color as AnimatedColor; use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{LengthOrPercentage, Number, NumberOrPercentage}; +use crate::values::computed::{LengthPercentage, Number, NumberOrPercentage}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; -use crate::values::generics::svg::{SVGLength, SVGPaint, SvgLengthOrPercentageOrNumber}; +use crate::values::generics::svg::{SVGLength, SVGPaint, SvgLengthPercentageOrNumber}; use crate::values::generics::svg::{SVGOpacity, SVGStrokeDashArray}; /// Animated SVGPaint. @@ -29,10 +29,10 @@ impl ToAnimatedZero for IntermediateSVGPaint { // FIXME: We need to handle calc here properly, see // https://bugzilla.mozilla.org/show_bug.cgi?id=1386967 fn to_number_or_percentage( - value: &SvgLengthOrPercentageOrNumber, + value: &SvgLengthPercentageOrNumber, ) -> Result { Ok(match *value { - SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref l) => { + SvgLengthPercentageOrNumber::LengthPercentage(ref l) => { match l.percentage { Some(p) => { if l.unclamped_length().px() != 0. { @@ -43,11 +43,11 @@ fn to_number_or_percentage( None => NumberOrPercentage::Number(l.length().px()) } }, - SvgLengthOrPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), + SvgLengthPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n), }) } -impl Animate for SvgLengthOrPercentageOrNumber { +impl Animate for SvgLengthPercentageOrNumber { #[inline] fn animate(&self, other: &Self, procedure: Procedure) -> Result { let this = to_number_or_percentage(self)?; @@ -55,20 +55,20 @@ impl Animate for SvgLengthOrPercentageOrNumber { match (this, other) { (NumberOrPercentage::Number(ref this), NumberOrPercentage::Number(ref other)) => Ok( - SvgLengthOrPercentageOrNumber::Number(this.animate(other, procedure)?), + SvgLengthPercentageOrNumber::Number(this.animate(other, procedure)?), ), ( NumberOrPercentage::Percentage(ref this), NumberOrPercentage::Percentage(ref other), - ) => Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::new_percent(this.animate(other, procedure)?), + ) => Ok(SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::new_percent(this.animate(other, procedure)?), )), _ => Err(()), } } } -impl ComputeSquaredDistance for SvgLengthOrPercentageOrNumber { +impl ComputeSquaredDistance for SvgLengthPercentageOrNumber { fn compute_squared_distance(&self, other: &Self) -> Result { to_number_or_percentage(self)?.compute_squared_distance(&to_number_or_percentage(other)?) } diff --git a/components/style/values/animated/transform.rs b/components/style/values/animated/transform.rs index 2804f4c0890..c341ca770ed 100644 --- a/components/style/values/animated/transform.rs +++ b/components/style/values/animated/transform.rs @@ -16,7 +16,7 @@ use crate::values::computed::transform::TransformOperation as ComputedTransformO use crate::values::computed::transform::Translate as ComputedTranslate; use crate::values::computed::transform::{DirectionVector, Matrix, Matrix3D}; use crate::values::computed::Angle; -use crate::values::computed::{Length, LengthOrPercentage}; +use crate::values::computed::{Length, LengthPercentage}; use crate::values::computed::{Number, Percentage}; use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; use crate::values::generics::transform::{self, Transform, TransformOperation}; @@ -1043,8 +1043,8 @@ impl Animate for ComputedTransformOperation { ) => Ok(TransformOperation::Translate( fx.animate(tx, procedure)?, Some( - fy.unwrap_or(LengthOrPercentage::zero()) - .animate(&ty.unwrap_or(LengthOrPercentage::zero()), procedure)?, + fy.unwrap_or(LengthPercentage::zero()) + .animate(&ty.unwrap_or(LengthPercentage::zero()), procedure)?, ), )), (&TransformOperation::TranslateX(ref f), &TransformOperation::TranslateX(ref t)) => { @@ -1383,15 +1383,15 @@ impl ComputeSquaredDistance for ComputedRotate { /// impl ComputedTranslate { - fn resolve(&self) -> (LengthOrPercentage, LengthOrPercentage, Length) { + fn resolve(&self) -> (LengthPercentage, LengthPercentage, Length) { // According to the spec: // https://drafts.csswg.org/css-transforms-2/#individual-transforms // // Unspecified translations default to 0px match *self { Translate::None => ( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), Length::zero(), ), Translate::Translate3D(tx, ty, tz) => (tx, ty, tz), diff --git a/components/style/values/computed/background.rs b/components/style/values/computed/background.rs index 82db7e0fdeb..08f10c9c1ec 100644 --- a/components/style/values/computed/background.rs +++ b/components/style/values/computed/background.rs @@ -4,20 +4,20 @@ //! Computed types for CSS values related to backgrounds. -use crate::values::computed::length::NonNegativeLengthOrPercentageOrAuto; +use crate::values::computed::length::NonNegativeLengthPercentageOrAuto; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; pub use crate::values::specified::background::BackgroundRepeat; /// A computed value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl BackgroundSize { /// Returns `auto auto`. pub fn auto() -> Self { GenericBackgroundSize::Explicit { - width: NonNegativeLengthOrPercentageOrAuto::auto(), - height: NonNegativeLengthOrPercentageOrAuto::auto(), + width: NonNegativeLengthPercentageOrAuto::auto(), + height: NonNegativeLengthPercentageOrAuto::auto(), } } } diff --git a/components/style/values/computed/basic_shape.rs b/components/style/values/computed/basic_shape.rs index f808e0bf9f5..9b4be538854 100644 --- a/components/style/values/computed/basic_shape.rs +++ b/components/style/values/computed/basic_shape.rs @@ -8,7 +8,7 @@ //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{Image, LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage}; use crate::values::generics::basic_shape as generic; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; @@ -24,25 +24,25 @@ pub type FloatAreaShape = generic::FloatAreaShape; /// A computed basic shape. pub type BasicShape = generic::BasicShape< - LengthOrPercentage, - LengthOrPercentage, - LengthOrPercentage, - NonNegativeLengthOrPercentage, + LengthPercentage, + LengthPercentage, + LengthPercentage, + NonNegativeLengthPercentage, >; /// The computed value of `inset()` -pub type InsetRect = generic::InsetRect; +pub type InsetRect = generic::InsetRect; /// A computed circle. pub type Circle = - generic::Circle; + generic::Circle; /// A computed ellipse. pub type Ellipse = - generic::Ellipse; + generic::Ellipse; /// The computed value of `ShapeRadius` -pub type ShapeRadius = generic::ShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; impl ToCss for Circle { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result diff --git a/components/style/values/computed/border.rs b/components/style/values/computed/border.rs index c6ab4abc5a5..e85b5a3e5d6 100644 --- a/components/style/values/computed/border.rs +++ b/components/style/values/computed/border.rs @@ -4,7 +4,7 @@ //! Computed types for CSS values related to borders. -use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; +use crate::values::computed::length::{NonNegativeLength, NonNegativeLengthPercentage}; use crate::values::computed::{NonNegativeNumber, NonNegativeNumberOrPercentage}; use crate::values::generics::border::BorderCornerRadius as GenericBorderCornerRadius; use crate::values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth; @@ -23,16 +23,16 @@ pub type BorderImageWidth = Rect; /// A computed value for a single side of a `border-image-width` property. pub type BorderImageSideWidth = - GenericBorderImageSideWidth; + GenericBorderImageSideWidth; /// A computed value for the `border-image-slice` property. pub type BorderImageSlice = GenericBorderImageSlice; /// A computed value for the `border-radius` property. -pub type BorderRadius = GenericBorderRadius; +pub type BorderRadius = GenericBorderRadius; /// A computed value for the `border-*-radius` longhand properties. -pub type BorderCornerRadius = GenericBorderCornerRadius; +pub type BorderCornerRadius = GenericBorderCornerRadius; /// A computed value for the `border-spacing` longhand property. pub type BorderSpacing = GenericBorderSpacing; @@ -80,8 +80,8 @@ impl BorderCornerRadius { /// Returns `0 0`. pub fn zero() -> Self { GenericBorderCornerRadius(Size::new( - NonNegativeLengthOrPercentage::zero(), - NonNegativeLengthOrPercentage::zero(), + NonNegativeLengthPercentage::zero(), + NonNegativeLengthPercentage::zero(), )) } } @@ -90,8 +90,8 @@ impl BorderRadius { /// Returns whether all the values are `0px`. pub fn all_zero(&self) -> bool { fn all(corner: &BorderCornerRadius) -> bool { - fn is_zero(l: &NonNegativeLengthOrPercentage) -> bool { - *l == NonNegativeLengthOrPercentage::zero() + fn is_zero(l: &NonNegativeLengthPercentage) -> bool { + *l == NonNegativeLengthPercentage::zero() } is_zero(corner.0.width()) && is_zero(corner.0.height()) } diff --git a/components/style/values/computed/box.rs b/components/style/values/computed/box.rs index 32ac16fb574..381ae7b364e 100644 --- a/components/style/values/computed/box.rs +++ b/components/style/values/computed/box.rs @@ -4,7 +4,7 @@ //! Computed types for box properties. -use crate::values::computed::length::{LengthOrPercentage, NonNegativeLength}; +use crate::values::computed::length::{LengthPercentage, NonNegativeLength}; use crate::values::computed::{Context, Number, ToComputedValue}; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::Perspective as GenericPerspective; @@ -18,7 +18,7 @@ pub use crate::values::specified::box_::{OverscrollBehavior, ScrollSnapType}; pub use crate::values::specified::box_::{TouchAction, TransitionProperty, WillChange}; /// A computed value for the `vertical-align` property. -pub type VerticalAlign = GenericVerticalAlign; +pub type VerticalAlign = GenericVerticalAlign; /// A computed value for the `animation-iteration-count` property. pub type AnimationIterationCount = GenericAnimationIterationCount; diff --git a/components/style/values/computed/flex.rs b/components/style/values/computed/flex.rs index fb65aaeae87..a48d7800752 100644 --- a/components/style/values/computed/flex.rs +++ b/components/style/values/computed/flex.rs @@ -8,7 +8,7 @@ use crate::values::generics::flex::FlexBasis as GenericFlexBasis; /// The `width` value type. #[cfg(feature = "servo")] -pub type Width = crate::values::computed::NonNegativeLengthOrPercentageOrAuto; +pub type Width = crate::values::computed::NonNegativeLengthPercentageOrAuto; /// The `width` value type. #[cfg(feature = "gecko")] diff --git a/components/style/values/computed/gecko.rs b/components/style/values/computed/gecko.rs index bf0e24f67ae..cbe0802eab8 100644 --- a/components/style/values/computed/gecko.rs +++ b/components/style/values/computed/gecko.rs @@ -4,8 +4,8 @@ //! Computed types for legacy Gecko-only properties. -use crate::values::computed::length::LengthOrPercentage; +use crate::values::computed::length::LengthPercentage; use crate::values::generics::gecko::ScrollSnapPoint as GenericScrollSnapPoint; /// A computed type for scroll snap points. -pub type ScrollSnapPoint = GenericScrollSnapPoint; +pub type ScrollSnapPoint = GenericScrollSnapPoint; diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 1c573ac3a2b..749c2e44e3a 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -10,7 +10,7 @@ use crate::values::computed::position::Position; use crate::values::computed::url::ComputedImageUrl; use crate::values::computed::{Angle, Color, Context}; -use crate::values::computed::{Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue}; +use crate::values::computed::{Length, LengthPercentage, NumberOrPercentage, ToComputedValue}; use crate::values::generics::image::{self as generic, CompatMode}; use crate::values::specified::image::LineDirection as SpecifiedLineDirection; use crate::values::specified::position::{X, Y}; @@ -29,11 +29,11 @@ pub type Image = generic::Image; /// Computed values for a CSS gradient. /// pub type Gradient = - generic::Gradient; + generic::Gradient; /// A computed gradient kind. pub type GradientKind = - generic::GradientKind; + generic::GradientKind; /// A computed gradient line direction. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)] @@ -52,13 +52,13 @@ pub enum LineDirection { } /// A computed radial gradient ending shape. -pub type EndingShape = generic::EndingShape; +pub type EndingShape = generic::EndingShape; /// A computed gradient item. -pub type GradientItem = generic::GradientItem; +pub type GradientItem = generic::GradientItem; /// A computed color stop. -pub type ColorStop = generic::ColorStop; +pub type ColorStop = generic::ColorStop; /// Computed values for `-moz-image-rect(...)`. pub type MozImageRect = generic::MozImageRect; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 8a9425ee631..3030efa825d 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -67,9 +67,13 @@ impl ToComputedValue for specified::Length { } } +/// A `` value. This can be either a ``, a +/// ``, or a combination of both via `calc()`. +/// +/// https://drafts.csswg.org/css-values-4/#typedef-length-percentage #[allow(missing_docs)] #[derive(Clone, Copy, Debug, MallocSizeOf, ToAnimatedZero)] -pub struct LengthOrPercentage { +pub struct LengthPercentage { #[animation(constant)] pub clamping_mode: AllowedNumericType, length: Length, @@ -87,19 +91,19 @@ pub struct LengthOrPercentage { } // FIXME(emilio): This is a bit of a hack that can disappear as soon as we share -// representation of LengthOrPercentage with Gecko. The issue here is that Gecko +// representation of LengthPercentage with Gecko. The issue here is that Gecko // uses CalcValue to represent position components, so they always come back as // was_calc == true, and we mess up in the transitions code. // // This was a pre-existing bug, though arguably so only in pretty obscure cases // like calc(0px + 5%) and such. -impl PartialEq for LengthOrPercentage { +impl PartialEq for LengthPercentage { fn eq(&self, other: &Self) -> bool { self.length == other.length && self.percentage == other.percentage } } -impl ComputeSquaredDistance for LengthOrPercentage { +impl ComputeSquaredDistance for LengthPercentage { #[inline] fn compute_squared_distance(&self, other: &Self) -> Result { // FIXME(nox): This looks incorrect to me, to add a distance between lengths @@ -112,8 +116,8 @@ impl ComputeSquaredDistance for LengthOrPercentage { } } -impl LengthOrPercentage { - /// Returns a new `LengthOrPercentage`. +impl LengthPercentage { + /// Returns a new `LengthPercentage`. #[inline] pub fn new(length: Length, percentage: Option) -> Self { Self::with_clamping_mode( @@ -124,12 +128,12 @@ impl LengthOrPercentage { ) } - /// Returns a new `LengthOrPercentage` with zero length and some percentage. + /// Returns a new `LengthPercentage` with zero length and some percentage. pub fn new_percent(percentage: Percentage) -> Self { Self::new(Length::zero(), Some(percentage)) } - /// Returns a new `LengthOrPercentage` with a specific clamping mode. + /// Returns a new `LengthPercentage` with a specific clamping mode. #[inline] pub fn with_clamping_mode( length: Length, @@ -209,23 +213,23 @@ impl LengthOrPercentage { } } -impl ToCss for LengthOrPercentage { +impl ToCss for LengthPercentage { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: Write, { - specified::LengthOrPercentage::from_computed_value(self).to_css(dest) + specified::LengthPercentage::from_computed_value(self).to_css(dest) } } -impl specified::CalcLengthOrPercentage { +impl specified::CalcLengthPercentage { /// Compute the value, zooming any absolute units by the zoom function. fn to_computed_value_with_zoom( &self, context: &Context, zoom_fn: F, base_size: FontBaseSize, - ) -> LengthOrPercentage + ) -> LengthPercentage where F: Fn(Length) -> Length, { @@ -259,7 +263,7 @@ impl specified::CalcLengthOrPercentage { } } - LengthOrPercentage { + LengthPercentage { clamping_mode: self.clamping_mode, length: Length::new(length.min(f32::MAX).max(f32::MIN)), percentage: self.percentage, @@ -272,7 +276,7 @@ impl specified::CalcLengthOrPercentage { &self, context: &Context, base_size: FontBaseSize, - ) -> LengthOrPercentage { + ) -> LengthPercentage { self.to_computed_value_with_zoom( context, |abs| context.maybe_zoom_text(abs.into()).0, @@ -306,17 +310,17 @@ impl specified::CalcLengthOrPercentage { } } -impl ToComputedValue for specified::CalcLengthOrPercentage { - type ComputedValue = LengthOrPercentage; +impl ToComputedValue for specified::CalcLengthPercentage { + type ComputedValue = LengthPercentage; - fn to_computed_value(&self, context: &Context) -> LengthOrPercentage { + fn to_computed_value(&self, context: &Context) -> LengthPercentage { // normal properties don't zoom, and compute em units against the current style's font-size self.to_computed_value_with_zoom(context, |abs| abs, FontBaseSize::CurrentStyle) } #[inline] - fn from_computed_value(computed: &LengthOrPercentage) -> Self { - specified::CalcLengthOrPercentage { + fn from_computed_value(computed: &LengthPercentage) -> Self { + specified::CalcLengthPercentage { clamping_mode: computed.clamping_mode, absolute: Some(AbsoluteLength::from_computed_value(&computed.length)), percentage: computed.percentage, @@ -325,17 +329,17 @@ impl ToComputedValue for specified::CalcLengthOrPercentage { } } -impl LengthOrPercentage { +impl LengthPercentage { #[inline] #[allow(missing_docs)] - pub fn zero() -> LengthOrPercentage { - LengthOrPercentage::new(Length::new(0.), None) + pub fn zero() -> LengthPercentage { + LengthPercentage::new(Length::new(0.), None) } /// 1px length value for SVG defaults #[inline] - pub fn one() -> LengthOrPercentage { - LengthOrPercentage::new(Length::new(1.), None) + pub fn one() -> LengthPercentage { + LengthPercentage::new(Length::new(1.), None) } /// Returns true if the computed value is absolute 0 or 0%. @@ -398,44 +402,44 @@ impl LengthOrPercentage { } } -impl ToComputedValue for specified::LengthOrPercentage { - type ComputedValue = LengthOrPercentage; +impl ToComputedValue for specified::LengthPercentage { + type ComputedValue = LengthPercentage; - fn to_computed_value(&self, context: &Context) -> LengthOrPercentage { + fn to_computed_value(&self, context: &Context) -> LengthPercentage { match *self { - specified::LengthOrPercentage::Length(ref value) => { - LengthOrPercentage::new(value.to_computed_value(context), None) + specified::LengthPercentage::Length(ref value) => { + LengthPercentage::new(value.to_computed_value(context), None) }, - specified::LengthOrPercentage::Percentage(value) => { - LengthOrPercentage::new_percent(value) + specified::LengthPercentage::Percentage(value) => { + LengthPercentage::new_percent(value) }, - specified::LengthOrPercentage::Calc(ref calc) => { + specified::LengthPercentage::Calc(ref calc) => { (**calc).to_computed_value(context) }, } } - fn from_computed_value(computed: &LengthOrPercentage) -> Self { + fn from_computed_value(computed: &LengthPercentage) -> Self { let length = computed.unclamped_length(); if let Some(p) = computed.as_percentage() { - return specified::LengthOrPercentage::Percentage(p) + return specified::LengthPercentage::Percentage(p) } let percentage = computed.percentage; if percentage.is_none() && computed.clamping_mode.clamp(length.px()) == length.px() { - return specified::LengthOrPercentage::Length( + return specified::LengthPercentage::Length( ToComputedValue::from_computed_value(&length) ) } - specified::LengthOrPercentage::Calc(Box::new( + specified::LengthPercentage::Calc(Box::new( ToComputedValue::from_computed_value(computed), )) } } -impl IsZeroLength for LengthOrPercentage { +impl IsZeroLength for LengthPercentage { #[inline] fn is_zero_length(&self) -> bool { self.is_definitely_zero() @@ -445,39 +449,39 @@ impl IsZeroLength for LengthOrPercentage { #[allow(missing_docs)] #[css(derive_debug)] #[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] -pub enum LengthOrPercentageOrAuto { - LengthOrPercentage(LengthOrPercentage), +pub enum LengthPercentageOrAuto { + LengthPercentage(LengthPercentage), Auto, } -impl LengthOrPercentageOrAuto { +impl LengthPercentageOrAuto { /// Returns the `0` value. #[inline] pub fn zero() -> Self { - LengthOrPercentageOrAuto::LengthOrPercentage(LengthOrPercentage::zero()) + LengthPercentageOrAuto::LengthPercentage(LengthPercentage::zero()) } } -/// A wrapper of LengthOrPercentageOrAuto, whose value must be >= 0. -pub type NonNegativeLengthOrPercentageOrAuto = NonNegative; +/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. +pub type NonNegativeLengthPercentageOrAuto = NonNegative; -impl IsAuto for NonNegativeLengthOrPercentageOrAuto { +impl IsAuto for NonNegativeLengthPercentageOrAuto { #[inline] fn is_auto(&self) -> bool { *self == Self::auto() } } -impl NonNegativeLengthOrPercentageOrAuto { +impl NonNegativeLengthPercentageOrAuto { /// `auto` #[inline] pub fn auto() -> Self { - NonNegative(LengthOrPercentageOrAuto::Auto) + NonNegative(LengthPercentageOrAuto::Auto) } } -impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto { - type AnimatedValue = LengthOrPercentageOrAuto; +impl ToAnimatedValue for NonNegativeLengthPercentageOrAuto { + type AnimatedValue = LengthPercentageOrAuto; #[inline] fn to_animated_value(self) -> Self::AnimatedValue { @@ -490,48 +494,48 @@ impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto { } } -impl LengthOrPercentageOrAuto { +impl LengthPercentageOrAuto { /// Returns true if the computed value is absolute 0 or 0%. #[inline] pub fn is_definitely_zero(&self) -> bool { - use self::LengthOrPercentageOrAuto::*; + use self::LengthPercentageOrAuto::*; match *self { - LengthOrPercentage(ref l) => l.is_definitely_zero(), + LengthPercentage(ref l) => l.is_definitely_zero(), Auto => false, } } /// Clamps the value to a non-negative value. pub fn clamp_to_non_negative(self) -> Self { - use self::LengthOrPercentageOrAuto::*; + use self::LengthPercentageOrAuto::*; match self { - LengthOrPercentage(l) => LengthOrPercentage(l.clamp_to_non_negative()), + LengthPercentage(l) => LengthPercentage(l.clamp_to_non_negative()), Auto => Auto, } } } -impl ToComputedValue for specified::LengthOrPercentageOrAuto { - type ComputedValue = LengthOrPercentageOrAuto; +impl ToComputedValue for specified::LengthPercentageOrAuto { + type ComputedValue = LengthPercentageOrAuto; #[inline] - fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrAuto { + fn to_computed_value(&self, context: &Context) -> LengthPercentageOrAuto { match *self { - specified::LengthOrPercentageOrAuto::LengthOrPercentage(ref value) => { - LengthOrPercentageOrAuto::LengthOrPercentage( + specified::LengthPercentageOrAuto::LengthPercentage(ref value) => { + LengthPercentageOrAuto::LengthPercentage( value.to_computed_value(context), ) }, - specified::LengthOrPercentageOrAuto::Auto => LengthOrPercentageOrAuto::Auto, + specified::LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto, } } #[inline] - fn from_computed_value(computed: &LengthOrPercentageOrAuto) -> Self { + fn from_computed_value(computed: &LengthPercentageOrAuto) -> Self { match *computed { - LengthOrPercentageOrAuto::Auto => specified::LengthOrPercentageOrAuto::Auto, - LengthOrPercentageOrAuto::LengthOrPercentage(ref value) => { - specified::LengthOrPercentageOrAuto::LengthOrPercentage( + LengthPercentageOrAuto::Auto => specified::LengthPercentageOrAuto::Auto, + LengthPercentageOrAuto::LengthPercentage(ref value) => { + specified::LengthPercentageOrAuto::LengthPercentage( ToComputedValue::from_computed_value(value), ) }, @@ -542,17 +546,17 @@ impl ToComputedValue for specified::LengthOrPercentageOrAuto { #[allow(missing_docs)] #[css(derive_debug)] #[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)] -pub enum LengthOrPercentageOrNone { - LengthOrPercentage(LengthOrPercentage), +pub enum LengthPercentageOrNone { + LengthPercentage(LengthPercentage), None, } -impl LengthOrPercentageOrNone { +impl LengthPercentageOrNone { /// Returns the used value. pub fn to_used_value(&self, containing_length: Au) -> Option { match *self { - LengthOrPercentageOrNone::None => None, - LengthOrPercentageOrNone::LengthOrPercentage(ref lop) => { + LengthPercentageOrNone::None => None, + LengthPercentageOrNone::LengthPercentage(ref lop) => { Some(lop.to_used_value(containing_length)) }, } @@ -560,25 +564,25 @@ impl LengthOrPercentageOrNone { } // FIXME(emilio): Derive this. -impl ToComputedValue for specified::LengthOrPercentageOrNone { - type ComputedValue = LengthOrPercentageOrNone; +impl ToComputedValue for specified::LengthPercentageOrNone { + type ComputedValue = LengthPercentageOrNone; #[inline] - fn to_computed_value(&self, context: &Context) -> LengthOrPercentageOrNone { + fn to_computed_value(&self, context: &Context) -> LengthPercentageOrNone { match *self { - specified::LengthOrPercentageOrNone::LengthOrPercentage(ref value) => { - LengthOrPercentageOrNone::LengthOrPercentage(value.to_computed_value(context)) + specified::LengthPercentageOrNone::LengthPercentage(ref value) => { + LengthPercentageOrNone::LengthPercentage(value.to_computed_value(context)) }, - specified::LengthOrPercentageOrNone::None => LengthOrPercentageOrNone::None, + specified::LengthPercentageOrNone::None => LengthPercentageOrNone::None, } } #[inline] - fn from_computed_value(computed: &LengthOrPercentageOrNone) -> Self { + fn from_computed_value(computed: &LengthPercentageOrNone) -> Self { match *computed { - LengthOrPercentageOrNone::None => specified::LengthOrPercentageOrNone::None, - LengthOrPercentageOrNone::LengthOrPercentage(value) => { - specified::LengthOrPercentageOrNone::LengthOrPercentage( + LengthPercentageOrNone::None => specified::LengthPercentageOrNone::None, + LengthPercentageOrNone::LengthPercentage(value) => { + specified::LengthPercentageOrNone::LengthPercentage( ToComputedValue::from_computed_value(&value), ) }, @@ -586,11 +590,11 @@ impl ToComputedValue for specified::LengthOrPercentageOrNone { } } -/// A wrapper of LengthOrPercentage, whose value must be >= 0. -pub type NonNegativeLengthOrPercentage = NonNegative; +/// A wrapper of LengthPercentage, whose value must be >= 0. +pub type NonNegativeLengthPercentage = NonNegative; -impl ToAnimatedValue for NonNegativeLengthOrPercentage { - type AnimatedValue = LengthOrPercentage; +impl ToAnimatedValue for NonNegativeLengthPercentage { + type AnimatedValue = LengthPercentage; #[inline] fn to_animated_value(self) -> Self::AnimatedValue { @@ -603,41 +607,41 @@ impl ToAnimatedValue for NonNegativeLengthOrPercentage { } } -impl From for NonNegativeLengthOrPercentage { +impl From for NonNegativeLengthPercentage { #[inline] fn from(length: NonNegativeLength) -> Self { - LengthOrPercentage::new(length.0, None).into() + LengthPercentage::new(length.0, None).into() } } -impl From for NonNegativeLengthOrPercentage { +impl From for NonNegativeLengthPercentage { #[inline] - fn from(lop: LengthOrPercentage) -> Self { - NonNegative::(lop) + fn from(lop: LengthPercentage) -> Self { + NonNegative::(lop) } } -impl From for LengthOrPercentage { +impl From for LengthPercentage { #[inline] - fn from(lop: NonNegativeLengthOrPercentage) -> LengthOrPercentage { + fn from(lop: NonNegativeLengthPercentage) -> LengthPercentage { lop.0 } } // TODO(emilio): This is a really generic impl which is only needed to implement // Animated and co for Spacing<>. Get rid of this, probably? -impl From for LengthOrPercentage { +impl From for LengthPercentage { #[inline] fn from(length: Au) -> Self { - LengthOrPercentage::new(length.into(), None) + LengthPercentage::new(length.into(), None) } } -impl NonNegativeLengthOrPercentage { +impl NonNegativeLengthPercentage { /// Get zero value. #[inline] pub fn zero() -> Self { - NonNegative::(LengthOrPercentage::zero()) + NonNegative::(LengthPercentage::zero()) } /// Returns true if the computed value is absolute 0 or 0%. @@ -850,8 +854,8 @@ pub type NonNegativeLengthOrAuto = Either; /// Either a computed NonNegativeLength or the `normal` keyword. pub type NonNegativeLengthOrNormal = Either; -/// Either a computed NonNegativeLengthOrPercentage or the `normal` keyword. -pub type NonNegativeLengthOrPercentageOrNormal = Either; +/// Either a computed NonNegativeLengthPercentage or the `normal` keyword. +pub type NonNegativeLengthPercentageOrNormal = Either; /// A type for possible values for min- and max- flavors of width, height, /// block-size, and inline-size. @@ -881,23 +885,23 @@ pub enum ExtremumLength { } /// A computed value for `min-width`, `min-height`, `width` or `height` property. -pub type MozLength = GenericMozLength; +pub type MozLength = GenericMozLength; impl MozLength { /// Returns the `auto` value. #[inline] pub fn auto() -> Self { - GenericMozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::Auto) + GenericMozLength::LengthPercentageOrAuto(LengthPercentageOrAuto::Auto) } } /// A computed value for `max-width` or `min-height` property. -pub type MaxLength = GenericMaxLength; +pub type MaxLength = GenericMaxLength; impl MaxLength { /// Returns the `none` value. #[inline] pub fn none() -> Self { - GenericMaxLength::LengthOrPercentageOrNone(LengthOrPercentageOrNone::None) + GenericMaxLength::LengthPercentageOrNone(LengthPercentageOrNone::None) } } diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 7877fddc192..c389e1d1267 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -62,9 +62,9 @@ pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, pub use self::gecko::ScrollSnapPoint; pub use self::image::{Gradient, GradientItem, Image, ImageLayer, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; -pub use self::length::{Length, LengthOrNumber, LengthOrPercentage}; -pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength}; -pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto}; +pub use self::length::{Length, LengthOrNumber, LengthPercentage}; +pub use self::length::{LengthPercentageOrAuto, LengthPercentageOrNone, MaxLength, MozLength}; +pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto}; #[cfg(feature = "gecko")] pub use self::list::ListStyleType; pub use self::list::{QuotePair, Quotes}; @@ -689,20 +689,20 @@ impl ToCss for ClipRect { pub type ClipRectOrAuto = Either; /// The computed value of a grid `` -pub type TrackBreadth = GenericTrackBreadth; +pub type TrackBreadth = GenericTrackBreadth; /// The computed value of a grid `` -pub type TrackSize = GenericTrackSize; +pub type TrackSize = GenericTrackSize; /// The computed value of a grid `` /// (could also be `` or ``) -pub type TrackList = GenericTrackList; +pub type TrackList = GenericTrackList; /// The computed value of a ``. pub type GridLine = GenericGridLine; /// ` | ` -pub type GridTemplateComponent = GenericGridTemplateComponent; +pub type GridTemplateComponent = GenericGridTemplateComponent; impl ClipRectOrAuto { /// Return an auto (default for clip-rect and image-region) value diff --git a/components/style/values/computed/position.rs b/components/style/values/computed/position.rs index 7bcdb59f89e..d6f9161903b 100644 --- a/components/style/values/computed/position.rs +++ b/components/style/values/computed/position.rs @@ -7,7 +7,7 @@ //! //! [position]: https://drafts.csswg.org/css-backgrounds-3/#position -use crate::values::computed::{Integer, LengthOrPercentage, Percentage}; +use crate::values::computed::{Integer, LengthPercentage, Percentage}; use crate::values::generics::position::Position as GenericPosition; use crate::values::generics::position::ZIndex as GenericZIndex; pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas}; @@ -18,25 +18,25 @@ use style_traits::{CssWriter, ToCss}; pub type Position = GenericPosition; /// The computed value of a CSS horizontal position. -pub type HorizontalPosition = LengthOrPercentage; +pub type HorizontalPosition = LengthPercentage; /// The computed value of a CSS vertical position. -pub type VerticalPosition = LengthOrPercentage; +pub type VerticalPosition = LengthPercentage; impl Position { /// `50% 50%` #[inline] pub fn center() -> Self { Self::new( - LengthOrPercentage::new_percent(Percentage(0.5)), - LengthOrPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), ) } /// `0% 0%` #[inline] pub fn zero() -> Self { - Self::new(LengthOrPercentage::zero(), LengthOrPercentage::zero()) + Self::new(LengthPercentage::zero(), LengthPercentage::zero()) } } diff --git a/components/style/values/computed/svg.rs b/components/style/values/computed/svg.rs index 02583189e4f..f3ca86aa5b0 100644 --- a/components/style/values/computed/svg.rs +++ b/components/style/values/computed/svg.rs @@ -6,7 +6,7 @@ use crate::values::computed::color::Color; use crate::values::computed::url::ComputedUrl; -use crate::values::computed::{LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::computed::{LengthPercentage, NonNegativeLengthPercentage}; use crate::values::computed::{NonNegativeNumber, Number, Opacity}; use crate::values::generics::svg as generic; use crate::values::RGBA; @@ -42,56 +42,56 @@ impl SVGPaint { /// A value of | | for stroke-dashoffset. /// -pub type SvgLengthOrPercentageOrNumber = - generic::SvgLengthOrPercentageOrNumber; +pub type SvgLengthPercentageOrNumber = + generic::SvgLengthPercentageOrNumber; /// | | | context-value -pub type SVGLength = generic::SVGLength; +pub type SVGLength = generic::SVGLength; impl SVGLength { /// `0px` pub fn zero() -> Self { - generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( - LengthOrPercentage::zero(), + generic::SVGLength::Length(generic::SvgLengthPercentageOrNumber::LengthPercentage( + LengthPercentage::zero(), )) } } /// A value of | | for stroke-width/stroke-dasharray. /// -pub type NonNegativeSvgLengthOrPercentageOrNumber = - generic::SvgLengthOrPercentageOrNumber; +pub type NonNegativeSvgLengthPercentageOrNumber = + generic::SvgLengthPercentageOrNumber; // FIXME(emilio): This is really hacky, and can go away with a bit of work on // the clone_stroke_width code in gecko.mako.rs. -impl Into for SvgLengthOrPercentageOrNumber { - fn into(self) -> NonNegativeSvgLengthOrPercentageOrNumber { +impl Into for SvgLengthPercentageOrNumber { + fn into(self) -> NonNegativeSvgLengthPercentageOrNumber { match self { - generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => { - generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop.into()) + generic::SvgLengthPercentageOrNumber::LengthPercentage(lop) => { + generic::SvgLengthPercentageOrNumber::LengthPercentage(lop.into()) }, - generic::SvgLengthOrPercentageOrNumber::Number(num) => { - generic::SvgLengthOrPercentageOrNumber::Number(num.into()) + generic::SvgLengthPercentageOrNumber::Number(num) => { + generic::SvgLengthPercentageOrNumber::Number(num.into()) }, } } } /// An non-negative wrapper of SVGLength. -pub type SVGWidth = generic::SVGLength; +pub type SVGWidth = generic::SVGLength; impl SVGWidth { /// `1px`. pub fn one() -> Self { use crate::values::generics::NonNegative; - generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( - NonNegative(LengthOrPercentage::one()), + generic::SVGLength::Length(generic::SvgLengthPercentageOrNumber::LengthPercentage( + NonNegative(LengthPercentage::one()), )) } } /// [ | | ]# | context-value -pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; +pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; impl Default for SVGStrokeDashArray { fn default() -> Self { diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index ce5545308b0..030a6df6cff 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -6,7 +6,7 @@ #[cfg(feature = "servo")] use crate::properties::StyleBuilder; -use crate::values::computed::length::{Length, LengthOrPercentage}; +use crate::values::computed::length::{Length, LengthPercentage}; use crate::values::computed::{NonNegativeLength, NonNegativeNumber}; use crate::values::generics::text::InitialLetter as GenericInitialLetter; use crate::values::generics::text::LineHeight as GenericLineHeight; @@ -29,7 +29,7 @@ pub type InitialLetter = GenericInitialLetter; pub type LetterSpacing = Spacing; /// A computed value for the `word-spacing` property. -pub type WordSpacing = Spacing; +pub type WordSpacing = Spacing; /// A computed value for the `line-height` property. pub type LineHeight = GenericLineHeight; diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 14115295213..979886aa996 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -7,7 +7,7 @@ use super::CSSFloat; use crate::values::animated::transform::{Perspective, Scale3D, Translate3D}; use crate::values::animated::ToAnimatedZero; -use crate::values::computed::{Angle, Integer, Length, LengthOrPercentage, Number, Percentage}; +use crate::values::computed::{Angle, Integer, Length, LengthPercentage, Number, Percentage}; use crate::values::generics::transform as generic; use euclid::{Transform3D, Vector3D}; use num_traits::Zero; @@ -16,12 +16,12 @@ pub use crate::values::generics::transform::TransformStyle; /// A single operation in a computed CSS `transform` pub type TransformOperation = - generic::TransformOperation; + generic::TransformOperation; /// A computed CSS `transform` pub type Transform = generic::Transform; /// The computed value of a CSS `` -pub type TransformOrigin = generic::TransformOrigin; +pub type TransformOrigin = generic::TransformOrigin; /// A vector to represent the direction vector (rotate axis) for Rotate3D. pub type DirectionVector = Vector3D; @@ -31,8 +31,8 @@ impl TransformOrigin { #[inline] pub fn initial_value() -> Self { Self::new( - LengthOrPercentage::new_percent(Percentage(0.5)), - LengthOrPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), + LengthPercentage::new_percent(Percentage(0.5)), Length::new(0.), ) } @@ -374,7 +374,7 @@ impl TransformOperation { generic::TransformOperation::Translate(ref x, None) => { generic::TransformOperation::Translate3D( x.clone(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), Length::zero(), ) }, @@ -383,15 +383,15 @@ impl TransformOperation { }, generic::TransformOperation::TranslateY(ref y) => { generic::TransformOperation::Translate3D( - LengthOrPercentage::zero(), + LengthPercentage::zero(), y.clone(), Length::zero(), ) }, generic::TransformOperation::TranslateZ(ref z) => { generic::TransformOperation::Translate3D( - LengthOrPercentage::zero(), - LengthOrPercentage::zero(), + LengthPercentage::zero(), + LengthPercentage::zero(), z.clone(), ) }, @@ -576,7 +576,7 @@ impl Rotate { } /// A computed CSS `translate` -pub type Translate = generic::Translate; +pub type Translate = generic::Translate; impl Translate { /// Convert TransformOperation to Translate. diff --git a/components/style/values/generics/background.rs b/components/style/values/generics/background.rs index 68bd08b29dd..4a7ee4b9b95 100644 --- a/components/style/values/generics/background.rs +++ b/components/style/values/generics/background.rs @@ -22,13 +22,13 @@ use style_traits::{CssWriter, ToCss}; ToAnimatedZero, ToComputedValue, )] -pub enum BackgroundSize { +pub enum BackgroundSize { /// ` ` Explicit { /// Explicit width. - width: LengthOrPercentageOrAuto, + width: LengthPercentageOrAuto, /// Explicit height. - height: LengthOrPercentageOrAuto, + height: LengthPercentageOrAuto, }, /// `cover` #[animation(error)] @@ -38,9 +38,9 @@ pub enum BackgroundSize { Contain, } -impl ToCss for BackgroundSize +impl ToCss for BackgroundSize where - LengthOrPercentageOrAuto: ToCss + IsAuto, + LengthPercentageOrAuto: ToCss + IsAuto, { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs index bfe709ceb4b..f224f936ccb 100644 --- a/components/style/values/generics/basic_shape.rs +++ b/components/style/values/generics/basic_shape.rs @@ -104,11 +104,11 @@ pub enum ShapeSource { ToComputedValue, ToCss, )] -pub enum BasicShape { - Inset(#[css(field_bound)] InsetRect), - Circle(#[css(field_bound)] Circle), - Ellipse(#[css(field_bound)] Ellipse), - Polygon(Polygon), +pub enum BasicShape { + Inset(#[css(field_bound)] InsetRect), + Circle(#[css(field_bound)] Circle), + Ellipse(#[css(field_bound)] Ellipse), + Polygon(Polygon), } /// @@ -125,9 +125,9 @@ pub enum BasicShape { ToAnimatedValue, ToComputedValue, )] -pub struct InsetRect { - pub rect: Rect, - pub round: Option>, +pub struct InsetRect { + pub rect: Rect, + pub round: Option>, } /// @@ -145,9 +145,9 @@ pub struct InsetRect { ToAnimatedValue, ToComputedValue, )] -pub struct Circle { +pub struct Circle { pub position: Position, - pub radius: ShapeRadius, + pub radius: ShapeRadius, } /// @@ -165,10 +165,10 @@ pub struct Circle { ToAnimatedValue, ToComputedValue, )] -pub struct Ellipse { +pub struct Ellipse { pub position: Position, - pub semiaxis_x: ShapeRadius, - pub semiaxis_y: ShapeRadius, + pub semiaxis_x: ShapeRadius, + pub semiaxis_y: ShapeRadius, } /// @@ -186,8 +186,8 @@ pub struct Ellipse { ToComputedValue, ToCss, )] -pub enum ShapeRadius { - Length(NonNegativeLengthOrPercentage), +pub enum ShapeRadius { + Length(NonNegativeLengthPercentage), #[animation(error)] ClosestSide, #[animation(error)] @@ -208,13 +208,13 @@ pub enum ShapeRadius { ToComputedValue, ToCss, )] -pub struct Polygon { +pub struct Polygon { /// The filling rule for a polygon. #[css(skip_if = "fill_is_default")] pub fill: FillRule, /// A collection of (x, y) coordinates to draw the polygon. #[css(iterable)] - pub coordinates: Vec>, + pub coordinates: Vec>, } /// Coordinates for Polygon. @@ -228,7 +228,7 @@ pub struct Polygon { ToComputedValue, ToCss, )] -pub struct PolygonCoord(pub LengthOrPercentage, pub LengthOrPercentage); +pub struct PolygonCoord(pub LengthPercentage, pub LengthPercentage); // https://drafts.csswg.org/css-shapes/#typedef-fill-rule // NOTE: Basic shapes spec says that these are the only two values, however diff --git a/components/style/values/generics/border.rs b/components/style/values/generics/border.rs index 20274816615..0a1cef3b4bb 100644 --- a/components/style/values/generics/border.rs +++ b/components/style/values/generics/border.rs @@ -13,9 +13,9 @@ use style_traits::{CssWriter, ToCss}; #[derive( Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, )] -pub enum BorderImageSideWidth { +pub enum BorderImageSideWidth { /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), /// `` Number(Number), /// `auto` @@ -98,15 +98,15 @@ impl BorderSpacing { ToAnimatedValue, ToComputedValue, )] -pub struct BorderRadius { +pub struct BorderRadius { /// The top left radius. - pub top_left: BorderCornerRadius, + pub top_left: BorderCornerRadius, /// The top right radius. - pub top_right: BorderCornerRadius, + pub top_right: BorderCornerRadius, /// The bottom right radius. - pub bottom_right: BorderCornerRadius, + pub bottom_right: BorderCornerRadius, /// The bottom left radius. - pub bottom_left: BorderCornerRadius, + pub bottom_left: BorderCornerRadius, } impl BorderRadius { diff --git a/components/style/values/generics/box.rs b/components/style/values/generics/box.rs index 1c40702dd6c..8a8dc58fd92 100644 --- a/components/style/values/generics/box.rs +++ b/components/style/values/generics/box.rs @@ -19,7 +19,7 @@ use crate::values::animated::ToAnimatedZero; ToComputedValue, ToCss, )] -pub enum VerticalAlign { +pub enum VerticalAlign { /// `baseline` Baseline, /// `sub` @@ -40,7 +40,7 @@ pub enum VerticalAlign { #[cfg(feature = "gecko")] MozMiddleWithBaseline, /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), } impl VerticalAlign { diff --git a/components/style/values/generics/gecko.rs b/components/style/values/generics/gecko.rs index e8bddc871f9..fb84fdf4acc 100644 --- a/components/style/values/generics/gecko.rs +++ b/components/style/values/generics/gecko.rs @@ -8,12 +8,12 @@ /// A generic value for scroll snap points. #[cfg_attr(feature = "gecko", derive(MallocSizeOf))] #[derive(Clone, Copy, Debug, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] -pub enum ScrollSnapPoint { +pub enum ScrollSnapPoint { /// `none` None, /// `repeat()` #[css(function)] - Repeat(LengthOrPercentage), + Repeat(LengthPercentage), } impl ScrollSnapPoint { diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index 9944ef6a212..400b04cae61 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -482,11 +482,11 @@ impl TrackRepeat { /// Track list values. Can be or #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] -pub enum TrackListValue { +pub enum TrackListValue { /// A value. - TrackSize(TrackSize), + TrackSize(TrackSize), /// A value. - TrackRepeat(TrackRepeat), + TrackRepeat(TrackRepeat), } /// The type of a `` as determined during parsing. @@ -515,7 +515,7 @@ pub enum TrackListType { /// /// #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo)] -pub struct TrackList { +pub struct TrackList { /// The type of this `` (auto, explicit or general). /// /// In order to avoid parsing the same value multiple times, this does a single traversal @@ -523,7 +523,7 @@ pub struct TrackList { #[css(skip)] pub list_type: TrackListType, /// A vector of ` | ` values. - pub values: Vec>, + pub values: Vec>, /// `` accompanying ` | ` values. /// /// If there's no ``, then it's represented by an empty vector. @@ -531,7 +531,7 @@ pub struct TrackList { /// length is always one value more than that of the ``. pub line_names: Box<[Box<[CustomIdent]>]>, /// `` value. There can only be one `` in a TrackList. - pub auto_repeat: Option>, + pub auto_repeat: Option>, } impl ToCss for TrackList { diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index a4bbc2b44d2..44ff903b4f4 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -37,11 +37,11 @@ pub enum Image { /// A CSS gradient. /// #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)] -pub struct Gradient { +pub struct Gradient { /// Gradients can be linear or radial. - pub kind: GradientKind, + pub kind: GradientKind, /// The color stops and interpolation hints. - pub items: Vec>, + pub items: Vec>, /// True if this is a repeating gradient. pub repeating: bool, /// Compatibility mode. @@ -61,12 +61,12 @@ pub enum CompatMode { /// A gradient kind. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue)] -pub enum GradientKind { +pub enum GradientKind { /// A linear gradient. Linear(LineDirection), /// A radial gradient. Radial( - EndingShape, + EndingShape, Position, Option, ), @@ -74,11 +74,11 @@ pub enum GradientKind { +pub enum EndingShape { /// A circular gradient. Circle(Circle), /// An elliptic gradient. - Ellipse(Ellipse), + Ellipse(Ellipse), } /// A circle shape. @@ -92,9 +92,9 @@ pub enum Circle { /// An ellipse shape. #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub enum Ellipse { +pub enum Ellipse { /// An ellipse pair of radii. - Radii(LengthOrPercentage, LengthOrPercentage), + Radii(LengthPercentage, LengthPercentage), /// An ellipse extent. Extent(ShapeExtent), } @@ -115,21 +115,21 @@ pub enum ShapeExtent { /// A gradient item. /// #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub enum GradientItem { +pub enum GradientItem { /// A color stop. - ColorStop(ColorStop), + ColorStop(ColorStop), /// An interpolation hint. - InterpolationHint(LengthOrPercentage), + InterpolationHint(LengthPercentage), } /// A color stop. /// #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)] -pub struct ColorStop { +pub struct ColorStop { /// The color of this stop. pub color: Color, /// The position of this stop. - pub position: Option, + pub position: Option, } /// Specified values for a paint worklet. diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index ade1e4bb3a9..006739462aa 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -26,8 +26,8 @@ use crate::values::computed::ExtremumLength; ToComputedValue, ToCss, )] -pub enum MozLength { - LengthOrPercentageOrAuto(LengthOrPercentageOrAuto), +pub enum MozLength { + LengthPercentageOrAuto(LengthPercentageOrAuto), #[animation(error)] ExtremumLength(ExtremumLength), } @@ -47,8 +47,8 @@ pub enum MozLength { ToComputedValue, ToCss, )] -pub enum MaxLength { - LengthOrPercentageOrNone(LengthOrPercentageOrNone), +pub enum MaxLength { + LengthPercentageOrNone(LengthPercentageOrNone), #[animation(error)] ExtremumLength(ExtremumLength), } diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 0559f8f1514..a96d5221c93 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -142,28 +142,28 @@ impl Parse for SVGPaint { +pub enum SvgLengthPercentageOrNumber { /// | - LengthOrPercentage(LengthOrPercentage), + LengthPercentage(LengthPercentage), /// Number(Number), } -/// Parsing the SvgLengthOrPercentageOrNumber. At first, we need to parse number +/// Parsing the SvgLengthPercentageOrNumber. At first, we need to parse number /// since prevent converting to the length. -impl Parse - for SvgLengthOrPercentageOrNumber +impl Parse + for SvgLengthPercentageOrNumber { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(num) = input.try(|i| NumberType::parse(context, i)) { - return Ok(SvgLengthOrPercentageOrNumber::Number(num)); + return Ok(SvgLengthPercentageOrNumber::Number(num)); } - let lop = LengthOrPercentageType::parse(context, input)?; - Ok(SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop)) + let lop = LengthPercentageType::parse(context, input)?; + Ok(SvgLengthPercentageOrNumber::LengthPercentage(lop)) } } diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 2ee92513cf9..5a4f9213908 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -123,7 +123,7 @@ impl ToAnimatedZero for Spacing { ToAnimatedValue, ToCss, )] -pub enum LineHeight { +pub enum LineHeight { /// `normal` Normal, /// `-moz-block-height` @@ -132,7 +132,7 @@ pub enum LineHeight { /// `` Number(Number), /// `` - Length(LengthOrPercentage), + Length(LengthPercentage), } impl ToAnimatedZero for LineHeight { diff --git a/components/style/values/generics/transform.rs b/components/style/values/generics/transform.rs index d4b69b02e72..87f26efa0d9 100644 --- a/components/style/values/generics/transform.rs +++ b/components/style/values/generics/transform.rs @@ -5,10 +5,10 @@ //! Generic types for CSS values that are related to transformations. use crate::values::computed::length::Length as ComputedLength; -use crate::values::computed::length::LengthOrPercentage as ComputedLengthOrPercentage; +use crate::values::computed::length::LengthPercentage as ComputedLengthPercentage; use crate::values::specified::angle::Angle as SpecifiedAngle; use crate::values::specified::length::Length as SpecifiedLength; -use crate::values::specified::length::LengthOrPercentage as SpecifiedLengthOrPercentage; +use crate::values::specified::length::LengthPercentage as SpecifiedLengthPercentage; use crate::values::{computed, CSSFloat}; use app_units::Au; use euclid::{self, Rect, Transform3D}; @@ -105,7 +105,7 @@ impl TransformOrigin { #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss)] /// A single operation in the list of a `transform` value -pub enum TransformOperation { +pub enum TransformOperation { /// Represents a 2D 2x3 matrix. Matrix(Matrix), /// Represents a 3D 4x4 matrix. @@ -125,19 +125,19 @@ pub enum TransformOperation SkewY(Angle), /// translate(x, y) or translate(x) #[css(comma, function)] - Translate(LengthOrPercentage, Option), + Translate(LengthPercentage, Option), /// translateX(x) #[css(function = "translateX")] - TranslateX(LengthOrPercentage), + TranslateX(LengthPercentage), /// translateY(y) #[css(function = "translateY")] - TranslateY(LengthOrPercentage), + TranslateY(LengthPercentage), /// translateZ(z) #[css(function = "translateZ")] TranslateZ(Length), /// translate3d(x, y, z) #[css(comma, function = "translate3d")] - Translate3D(LengthOrPercentage, LengthOrPercentage, Length), + Translate3D(LengthPercentage, LengthPercentage, Length), /// A 2D scaling factor. /// /// `scale(2)` is parsed as `Scale(Number::new(2.0), None)` and is equivalent to @@ -192,8 +192,8 @@ pub enum TransformOperation #[css(comma, function = "interpolatematrix")] InterpolateMatrix { from_list: - Transform>, - to_list: Transform>, + Transform>, + to_list: Transform>, progress: computed::Percentage, }, /// A intermediate type for accumulation of mismatched transform lists. @@ -201,8 +201,8 @@ pub enum TransformOperation #[css(comma, function = "accumulatematrix")] AccumulateMatrix { from_list: - Transform>, - to_list: Transform>, + Transform>, + to_list: Transform>, count: Integer, }, } @@ -211,8 +211,8 @@ pub enum TransformOperation /// A value of the `transform` property pub struct Transform(#[css(if_empty = "none", iterable)] pub Vec); -impl - TransformOperation +impl + TransformOperation { /// Check if it is any rotate function. pub fn is_rotate(&self) -> bool { @@ -263,13 +263,13 @@ impl ToAbsoluteLength for SpecifiedLength { } } -impl ToAbsoluteLength for SpecifiedLengthOrPercentage { +impl ToAbsoluteLength for SpecifiedLengthPercentage { // This returns Err(()) if there is any relative length or percentage. We use this when // parsing a transform list of DOMMatrix because we want to return a DOM Exception // if there is relative length. #[inline] fn to_pixel_length(&self, _containing_len: Option) -> Result { - use self::SpecifiedLengthOrPercentage::*; + use self::SpecifiedLengthPercentage::*; match *self { Length(len) => len.to_computed_pixel_length_without_context(), Calc(ref calc) => calc.to_computed_pixel_length_without_context(), @@ -285,7 +285,7 @@ impl ToAbsoluteLength for ComputedLength { } } -impl ToAbsoluteLength for ComputedLengthOrPercentage { +impl ToAbsoluteLength for ComputedLengthPercentage { #[inline] fn to_pixel_length(&self, containing_len: Option) -> Result { match containing_len { @@ -633,18 +633,18 @@ impl ToCss for Scale { /// A value of the `Translate` property /// /// -pub enum Translate { +pub enum Translate { /// 'none' None, /// '' or ' ' - Translate(LengthOrPercentage, LengthOrPercentage), + Translate(LengthPercentage, LengthPercentage), /// ' ' - Translate3D(LengthOrPercentage, LengthOrPercentage, Length), + Translate3D(LengthPercentage, LengthPercentage, Length), } /// A trait to check if this is a zero length. /// An alternative way is use num_traits::Zero. However, in order to implement num_traits::Zero, -/// we also have to implement Add, which may be complicated for LengthOrPercentage::Calc. +/// we also have to implement Add, which may be complicated for LengthPercentage::Calc. /// We could do this if other types also need it. If so, we could drop this trait. pub trait IsZeroLength { /// Returns true if this is a zero length. diff --git a/components/style/values/specified/background.rs b/components/style/values/specified/background.rs index d3c1b2c0d14..47c66feaef6 100644 --- a/components/style/values/specified/background.rs +++ b/components/style/values/specified/background.rs @@ -6,24 +6,24 @@ use crate::parser::{Parse, ParserContext}; use crate::values::generics::background::BackgroundSize as GenericBackgroundSize; -use crate::values::specified::length::NonNegativeLengthOrPercentageOrAuto; +use crate::values::specified::length::NonNegativeLengthPercentageOrAuto; use cssparser::Parser; use selectors::parser::SelectorParseErrorKind; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, ToCss}; /// A specified value for the `background-size` property. -pub type BackgroundSize = GenericBackgroundSize; +pub type BackgroundSize = GenericBackgroundSize; impl Parse for BackgroundSize { fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(width) = input.try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) { + if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) { let height = input - .try(|i| NonNegativeLengthOrPercentageOrAuto::parse(context, i)) - .unwrap_or(NonNegativeLengthOrPercentageOrAuto::auto()); + .try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + .unwrap_or(NonNegativeLengthPercentageOrAuto::auto()); return Ok(GenericBackgroundSize::Explicit { width, height }); } Ok(try_match_ident_ignore_ascii_case! { input, @@ -37,8 +37,8 @@ impl BackgroundSize { /// Returns `auto auto`. pub fn auto() -> Self { GenericBackgroundSize::Explicit { - width: NonNegativeLengthOrPercentageOrAuto::auto(), - height: NonNegativeLengthOrPercentageOrAuto::auto(), + width: NonNegativeLengthPercentageOrAuto::auto(), + height: NonNegativeLengthPercentageOrAuto::auto(), } } } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 84624671ffe..88c7b384d41 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -17,7 +17,7 @@ use crate::values::specified::image::Image; use crate::values::specified::position::{HorizontalPosition, Position, VerticalPosition}; use crate::values::specified::url::SpecifiedUrl; use crate::values::specified::SVGPathData; -use crate::values::specified::{LengthOrPercentage, NonNegativeLengthOrPercentage}; +use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage}; use cssparser::Parser; use std::fmt::{self, Write}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; @@ -35,26 +35,26 @@ pub type FloatAreaShape = generic::FloatAreaShape; pub type BasicShape = generic::BasicShape< HorizontalPosition, VerticalPosition, - LengthOrPercentage, - NonNegativeLengthOrPercentage, + LengthPercentage, + NonNegativeLengthPercentage, >; /// The specified value of `inset()` -pub type InsetRect = generic::InsetRect; +pub type InsetRect = generic::InsetRect; /// A specified circle. pub type Circle = - generic::Circle; + generic::Circle; /// A specified ellipse. pub type Ellipse = - generic::Ellipse; + generic::Ellipse; /// The specified value of `ShapeRadius` -pub type ShapeRadius = generic::ShapeRadius; +pub type ShapeRadius = generic::ShapeRadius; /// The specified value of `Polygon` -pub type Polygon = generic::Polygon; +pub type Polygon = generic::Polygon; #[cfg(feature = "gecko")] fn is_clip_path_path_enabled(context: &ParserContext) -> bool { @@ -200,7 +200,7 @@ impl InsetRect { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let rect = Rect::parse_with(context, input, LengthOrPercentage::parse)?; + let rect = Rect::parse_with(context, input, LengthPercentage::parse)?; let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() { Some(BorderRadius::parse(context, input)?) } else { @@ -316,7 +316,7 @@ impl Parse for ShapeRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { + if let Ok(lop) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { return Ok(generic::ShapeRadius::Length(lop)); } @@ -353,8 +353,8 @@ impl Polygon { let buf = input.parse_comma_separated(|i| { Ok(PolygonCoord( - LengthOrPercentage::parse(context, i)?, - LengthOrPercentage::parse(context, i)?, + LengthPercentage::parse(context, i)?, + LengthPercentage::parse(context, i)?, )) })?; diff --git a/components/style/values/specified/border.rs b/components/style/values/specified/border.rs index acd38ea5ba4..c3f1dd6f4af 100644 --- a/components/style/values/specified/border.rs +++ b/components/style/values/specified/border.rs @@ -13,7 +13,7 @@ use crate::values::generics::border::BorderRadius as GenericBorderRadius; use crate::values::generics::border::BorderSpacing as GenericBorderSpacing; use crate::values::generics::rect::Rect; use crate::values::generics::size::Size; -use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; +use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage}; use crate::values::specified::{AllowQuirks, NonNegativeNumber, NonNegativeNumberOrPercentage}; use cssparser::Parser; use std::fmt::{self, Write}; @@ -79,16 +79,16 @@ pub type BorderImageWidth = Rect; /// A specified value for a single side of a `border-image-width` property. pub type BorderImageSideWidth = - GenericBorderImageSideWidth; + GenericBorderImageSideWidth; /// A specified value for the `border-image-slice` property. pub type BorderImageSlice = GenericBorderImageSlice; /// A specified value for the `border-radius` property. -pub type BorderRadius = GenericBorderRadius; +pub type BorderRadius = GenericBorderRadius; /// A specified value for the `border-*-radius` longhand properties. -pub type BorderCornerRadius = GenericBorderCornerRadius; +pub type BorderCornerRadius = GenericBorderCornerRadius; /// A specified value for the `border-spacing` longhand properties. pub type BorderSpacing = GenericBorderSpacing; @@ -178,7 +178,7 @@ impl Parse for BorderImageSideWidth { return Ok(GenericBorderImageSideWidth::Auto); } - if let Ok(len) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) { + if let Ok(len) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { return Ok(GenericBorderImageSideWidth::Length(len)); } @@ -206,9 +206,9 @@ impl Parse for BorderRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let widths = Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)?; + let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?; let heights = if input.try(|i| i.expect_delim('/')).is_ok() { - Rect::parse_with(context, input, NonNegativeLengthOrPercentage::parse)? + Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)? } else { widths.clone() }; @@ -227,7 +227,7 @@ impl Parse for BorderCornerRadius { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Size::parse_with(context, input, NonNegativeLengthOrPercentage::parse) + Size::parse_with(context, input, NonNegativeLengthPercentage::parse) .map(GenericBorderCornerRadius) } } diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index c785fb0c0db..65f66de8129 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -11,7 +11,7 @@ use crate::properties::{PropertyId, ShorthandId}; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::Perspective as GenericPerspective; use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign; -use crate::values::specified::length::{LengthOrPercentage, NonNegativeLength}; +use crate::values::specified::length::{LengthPercentage, NonNegativeLength}; use crate::values::specified::{AllowQuirks, Number}; use crate::values::{CustomIdent, KeyframesName}; use crate::Atom; @@ -271,7 +271,7 @@ impl Display { } /// A specified value for the `vertical-align` property. -pub type VerticalAlign = GenericVerticalAlign; +pub type VerticalAlign = GenericVerticalAlign; impl Parse for VerticalAlign { fn parse<'i, 't>( @@ -279,7 +279,7 @@ impl Parse for VerticalAlign { input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(lop) = - input.try(|i| LengthOrPercentage::parse_quirky(context, i, AllowQuirks::Yes)) + input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) { return Ok(GenericVerticalAlign::Length(lop)); } diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index 2fe00ff8799..9e66edd9a9e 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -52,7 +52,7 @@ pub enum CalcUnit { /// `` Percentage, /// ` | ` - LengthOrPercentage, + LengthPercentage, /// `` Angle, /// `