diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 471548214b3..02b74807ba5 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -1520,7 +1520,7 @@ impl Fragment { LengthOrPercentageOrAuto::Calc(calc) => { // TODO(nox): This is probably wrong, because it accounts neither for // clamping (not sure if necessary here) nor percentage. - calc.unclamped_length() + Au::from(calc.unclamped_length()) }, }; diff --git a/components/style/gecko/conversions.rs b/components/style/gecko/conversions.rs index af3ee5978e2..ac0300fd7d8 100644 --- a/components/style/gecko/conversions.rs +++ b/components/style/gecko/conversions.rs @@ -29,7 +29,7 @@ impl From for nsStyleCoord_CalcValue { fn from(other: CalcLengthOrPercentage) -> nsStyleCoord_CalcValue { let has_percentage = other.percentage.is_some(); nsStyleCoord_CalcValue { - mLength: other.unclamped_length().0, + mLength: other.unclamped_length().to_i32_au(), mPercent: other.percentage.map_or(0., |p| p.0), mHasPercent: has_percentage, } @@ -43,7 +43,7 @@ impl From for CalcLengthOrPercentage { } else { None }; - Self::new(Au(other.mLength), percentage) + Self::new(Au(other.mLength).into(), percentage) } } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 585774da3b7..780047ebf8c 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -2316,7 +2316,7 @@ impl ComputeSquaredDistance for TransformOperation { match *lop { LengthOrPercentage::Length(au) => au.to_f64_px(), LengthOrPercentage::Percentage(_) => 0., - LengthOrPercentage::Calc(calc) => calc.length().to_f64_px(), + LengthOrPercentage::Calc(calc) => calc.length().px() as f64, } }; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 5b4b4784de1..696a89ccc9c 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -7,9 +7,9 @@ use app_units::{Au, AU_PER_PX}; use ordered_float::NotNaN; use std::fmt; -use std::ops::Add; +use std::ops::{Add, Neg}; use style_traits::ToCss; -use style_traits::values::specified::AllowedLengthType; +use style_traits::values::specified::AllowedNumericType; use super::{Number, ToComputedValue, Context, Percentage}; use values::{Auto, CSSFloat, Either, ExtremumLength, None_, Normal, specified}; use values::animated::{Animate, Procedure, ToAnimatedZero}; @@ -55,7 +55,7 @@ impl ToComputedValue for specified::Length { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { specified::Length::NoCalc(l) => l.to_computed_value(context), - specified::Length::Calc(ref calc) => calc.to_computed_value(context).length().into(), + specified::Length::Calc(ref calc) => calc.to_computed_value(context).length(), } } @@ -70,8 +70,8 @@ impl ToComputedValue for specified::Length { #[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)] pub struct CalcLengthOrPercentage { #[animation(constant)] - pub clamping_mode: AllowedLengthType, - length: Au, + pub clamping_mode: AllowedNumericType, + length: Length, pub percentage: Option, } @@ -81,8 +81,7 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage { // FIXME(nox): This looks incorrect to me, to add a distance between lengths // with a distance between percentages. Ok( - self.unclamped_length().to_f64_px().compute_squared_distance( - &other.unclamped_length().to_f64_px())? + + self.unclamped_length().compute_squared_distance(&other.unclamped_length())? + self.percentage().compute_squared_distance(&other.percentage())?, ) } @@ -91,15 +90,15 @@ impl ComputeSquaredDistance for CalcLengthOrPercentage { impl CalcLengthOrPercentage { /// Returns a new `CalcLengthOrPercentage`. #[inline] - pub fn new(length: Au, percentage: Option) -> Self { - Self::with_clamping_mode(length, percentage, AllowedLengthType::All) + pub fn new(length: Length, percentage: Option) -> Self { + Self::with_clamping_mode(length, percentage, AllowedNumericType::All) } /// Returns a new `CalcLengthOrPercentage` with a specific clamping mode. #[inline] - pub fn with_clamping_mode(length: Au, + pub fn with_clamping_mode(length: Length, percentage: Option, - clamping_mode: AllowedLengthType) + clamping_mode: AllowedNumericType) -> Self { Self { clamping_mode: clamping_mode, @@ -112,20 +111,20 @@ impl CalcLengthOrPercentage { /// /// Panics in debug mode if a percentage is present in the expression. #[inline] - pub fn length(&self) -> Au { + pub fn length(&self) -> CSSPixelLength { debug_assert!(self.percentage.is_none()); self.length_component() } /// Returns the length component of this `calc()` #[inline] - pub fn length_component(&self) -> Au { - self.clamping_mode.clamp(self.length) + pub fn length_component(&self) -> CSSPixelLength { + CSSPixelLength::new(self.clamping_mode.clamp(self.length.px())) } /// Returns the `` component of this `calc()`, unclamped. #[inline] - pub fn unclamped_length(&self) -> Au { + pub fn unclamped_length(&self) -> CSSPixelLength { self.length } @@ -140,9 +139,10 @@ impl CalcLengthOrPercentage { pub fn to_used_value(&self, container_len: Option) -> Option { match (container_len, self.percentage) { (Some(len), Some(percent)) => { - Some(self.clamping_mode.clamp(self.length + len.scale_by(percent.0))) + let pixel = self.length.px() + len.scale_by(percent.0).to_f32_px(); + Some(Au::from_f32_px(self.clamping_mode.clamp(pixel))) }, - (_, None) => Some(self.length()), + (_, None) => Some(Au::from(self.length())), _ => None, } } @@ -152,10 +152,10 @@ impl From for CalcLengthOrPercentage { fn from(len: LengthOrPercentage) -> CalcLengthOrPercentage { match len { LengthOrPercentage::Percentage(this) => { - CalcLengthOrPercentage::new(Au(0), Some(this)) + CalcLengthOrPercentage::new(Length::new(0.), Some(this)) } LengthOrPercentage::Length(this) => { - CalcLengthOrPercentage::new(this, None) + CalcLengthOrPercentage::new(this.into(), None) } LengthOrPercentage::Calc(this) => { this @@ -168,10 +168,10 @@ impl From for Option { fn from(len: LengthOrPercentageOrAuto) -> Option { match len { LengthOrPercentageOrAuto::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Au(0), Some(this))) + Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) } LengthOrPercentageOrAuto::Length(this) => { - Some(CalcLengthOrPercentage::new(this, None)) + Some(CalcLengthOrPercentage::new(this.into(), None)) } LengthOrPercentageOrAuto::Calc(this) => { Some(this) @@ -187,10 +187,10 @@ impl From for Option { fn from(len: LengthOrPercentageOrNone) -> Option { match len { LengthOrPercentageOrNone::Percentage(this) => { - Some(CalcLengthOrPercentage::new(Au(0), Some(this))) + Some(CalcLengthOrPercentage::new(Length::new(0.), Some(this))) } LengthOrPercentageOrNone::Length(this) => { - Some(CalcLengthOrPercentage::new(this, None)) + Some(CalcLengthOrPercentage::new(this.into(), None)) } LengthOrPercentageOrNone::Calc(this) => { Some(this) @@ -208,14 +208,14 @@ impl ToCss for CalcLengthOrPercentage { let (length, percentage) = match (self.length, self.percentage) { (l, None) => return l.to_css(dest), - (l, Some(p)) if l == Au(0) => return p.to_css(dest), + (l, Some(p)) if l.px() == 0. => return p.to_css(dest), (l, Some(p)) => (l, p), }; dest.write_str("calc(")?; percentage.to_css(dest)?; - dest.write_str(if length < Zero::zero() { " - " } else { " + " })?; + dest.write_str(if length.px() < Zero::zero() { " - " } else { " + " })?; length.abs().to_css(dest)?; dest.write_str(")") @@ -226,11 +226,12 @@ impl specified::CalcLengthOrPercentage { /// 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) -> CalcLengthOrPercentage - where F: Fn(Au) -> Au { - let mut length = Au(0); + where F: Fn(Length) -> Length { + use std::f32; + let mut length = 0.; if let Some(absolute) = self.absolute { - length += zoom_fn(Au::from(absolute.to_computed_value(context))); + length += zoom_fn(absolute.to_computed_value(context)).px(); } for val in &[self.vw.map(ViewportPercentageLength::Vw), @@ -239,7 +240,7 @@ impl specified::CalcLengthOrPercentage { self.vmax.map(ViewportPercentageLength::Vmax)] { if let Some(val) = *val { let viewport_size = context.viewport_size_for_viewport_unit_resolution(); - length += Au::from(val.to_computed_value(viewport_size)); + length += val.to_computed_value(viewport_size).px(); } } @@ -248,20 +249,20 @@ impl specified::CalcLengthOrPercentage { self.ex.map(FontRelativeLength::Ex), self.rem.map(FontRelativeLength::Rem)] { if let Some(val) = *val { - length += Au::from(val.to_computed_value(context, base_size)); + length += val.to_computed_value(context, base_size).px(); } } CalcLengthOrPercentage { clamping_mode: self.clamping_mode, - length: length, + length: Length::new(length.min(f32::MAX).max(f32::MIN)), percentage: self.percentage, } } /// Compute font-size or line-height taking into account text-zoom if necessary. pub fn to_computed_value_zoomed(&self, context: &Context, base_size: FontBaseSize) -> CalcLengthOrPercentage { - self.to_computed_value_with_zoom(context, |abs| Au::from(context.maybe_zoom_text(abs.into())), base_size) + self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs), base_size) } } @@ -277,7 +278,7 @@ impl ToComputedValue for specified::CalcLengthOrPercentage { fn from_computed_value(computed: &CalcLengthOrPercentage) -> Self { specified::CalcLengthOrPercentage { clamping_mode: computed.clamping_mode, - absolute: Some(AbsoluteLength::from_computed_value(&computed.length.into())), + absolute: Some(AbsoluteLength::from_computed_value(&computed.length)), percentage: computed.percentage, ..Default::default() } @@ -368,7 +369,7 @@ impl LengthOrPercentage { match *self { Length(l) => (l, NotNaN::new(0.0).unwrap()), Percentage(p) => (Au(0), NotNaN::new(p.0).unwrap()), - Calc(c) => (c.unclamped_length(), NotNaN::new(c.percentage()).unwrap()), + Calc(c) => (Au::from(c.unclamped_length()), NotNaN::new(c.percentage()).unwrap()), } } @@ -690,6 +691,11 @@ impl CSSPixelLength { pub fn to_i32_au(&self) -> i32 { Au::from(*self).0 } + + /// Return the absolute value of this length. + pub fn abs(self) -> Self { + CSSPixelLength::new(self.0.abs()) + } } impl ToCss for CSSPixelLength { @@ -700,6 +706,15 @@ impl ToCss for CSSPixelLength { } } +impl Neg for CSSPixelLength { + type Output = Self; + + #[inline] + fn neg(self) -> Self { + CSSPixelLength::new(-self.0) + } +} + impl From for Au { #[inline] fn from(len: CSSPixelLength) -> Self { diff --git a/components/style/values/computed/transform.rs b/components/style/values/computed/transform.rs index 48ba575b8a2..8f68be3406f 100644 --- a/components/style/values/computed/transform.rs +++ b/components/style/values/computed/transform.rs @@ -74,7 +74,7 @@ impl TransformList { match *lop { LengthOrPercentage::Length(au) => au.to_f32_px(), LengthOrPercentage::Percentage(_) => 0., - LengthOrPercentage::Calc(calc) => calc.length().to_f32_px(), + LengthOrPercentage::Calc(calc) => calc.length().px(), } }; diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index 408a5f4ab5b..32fcadf7d6f 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -11,7 +11,7 @@ use parser::ParserContext; use std::ascii::AsciiExt; use std::fmt; use style_traits::{ToCss, ParseError, StyleParseError}; -use style_traits::values::specified::AllowedLengthType; +use style_traits::values::specified::AllowedNumericType; use values::{CSSInteger, CSSFloat}; use values::computed; use values::specified::{Angle, Time}; @@ -67,7 +67,7 @@ pub enum CalcUnit { #[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[allow(missing_docs)] pub struct CalcLengthOrPercentage { - pub clamping_mode: AllowedLengthType, + pub clamping_mode: AllowedNumericType, pub absolute: Option, pub vw: Option, pub vh: Option, @@ -291,7 +291,7 @@ impl CalcNode { /// Tries to simplify this expression into a `` or ` /// value. - fn to_length_or_percentage(&self, clamping_mode: AllowedLengthType) + fn to_length_or_percentage(&self, clamping_mode: AllowedNumericType) -> Result { let mut ret = CalcLengthOrPercentage { clamping_mode: clamping_mode, @@ -565,7 +565,7 @@ impl CalcNode { pub fn parse_length_or_percentage<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, - clamping_mode: AllowedLengthType + clamping_mode: AllowedNumericType ) -> Result> { Self::parse(context, input, CalcUnit::LengthOrPercentage)? .to_length_or_percentage(clamping_mode) @@ -586,7 +586,7 @@ impl CalcNode { pub fn parse_length<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, - clamping_mode: AllowedLengthType + clamping_mode: AllowedNumericType ) -> Result> { Self::parse(context, input, CalcUnit::Length)? .to_length_or_percentage(clamping_mode) diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 8f190fdd072..33bad5d90cc 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -15,7 +15,7 @@ use std::{cmp, fmt, mem}; use std::ascii::AsciiExt; use std::ops::{Add, Mul}; use style_traits::{ToCss, ParseError, StyleParseError}; -use style_traits::values::specified::AllowedLengthType; +use style_traits::values::specified::AllowedNumericType; use stylesheets::CssRuleType; use super::{AllowQuirks, Number, ToComputedValue, Percentage}; use values::{Auto, CSSFloat, Either, FONT_MEDIUM_PX, None_, Normal}; @@ -642,7 +642,7 @@ impl Length { #[inline] fn parse_internal<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, - num_context: AllowedLengthType, + num_context: AllowedNumericType, allow_quirks: AllowQuirks) -> Result> { // FIXME: remove early returns when lifetimes are non-lexical @@ -683,7 +683,7 @@ impl Length { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks) } /// Get an absolute length from a px value. @@ -713,7 +713,7 @@ impl Length { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) } } @@ -725,7 +725,7 @@ impl Either { if let Ok(v) = input.try(|input| T::parse(context, input)) { return Ok(Either::Second(v)); } - Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No).map(Either::First) + Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First) } } @@ -752,7 +752,7 @@ impl Parse for Either { if let Ok(v) = input.try(|input| T::parse(context, input)) { return Ok(Either::Second(v)); } - Length::parse_internal(context, input, AllowedLengthType::NonNegative, AllowQuirks::No) + Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No) .map(NonNegative::).map(Either::First) } } @@ -836,7 +836,7 @@ impl LengthOrPercentage { fn parse_internal<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, - num_context: AllowedLengthType, + num_context: AllowedNumericType, allow_quirks: AllowQuirks) -> Result> { @@ -885,7 +885,7 @@ impl LengthOrPercentage { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks) } /// Parse a length, treating dimensionless numbers as pixels @@ -946,7 +946,7 @@ impl LengthOrPercentage { pub fn parse_quirky<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) } } @@ -978,7 +978,7 @@ impl From for LengthOrPercentageOrAuto { impl LengthOrPercentageOrAuto { fn parse_internal<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, - num_context: AllowedLengthType, + num_context: AllowedNumericType, allow_quirks: AllowQuirks) -> Result> { // FIXME: remove early returns when lifetimes are non-lexical @@ -1030,7 +1030,7 @@ impl LengthOrPercentageOrAuto { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks) } /// Returns the `auto` value. @@ -1063,7 +1063,7 @@ impl LengthOrPercentageOrAuto { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::All, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::All, allow_quirks) } } @@ -1081,7 +1081,7 @@ pub enum LengthOrPercentageOrNone { impl LengthOrPercentageOrNone { fn parse_internal<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>, - num_context: AllowedLengthType, + num_context: AllowedNumericType, allow_quirks: AllowQuirks) -> Result> { @@ -1133,14 +1133,14 @@ impl LengthOrPercentageOrNone { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::NonNegative, allow_quirks) + Self::parse_internal(context, input, AllowedNumericType::NonNegative, allow_quirks) } } impl Parse for LengthOrPercentageOrNone { #[inline] fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - Self::parse_internal(context, input, AllowedLengthType::All, AllowQuirks::No) + Self::parse_internal(context, input, AllowedNumericType::All, AllowQuirks::No) } } diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index fb5e22347e8..942263b2285 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -203,14 +203,15 @@ impl ToComputedValue for PositionComponent { match length.to_computed_value(context) { ComputedLengthOrPercentage::Length(length) => { ComputedLengthOrPercentage::Calc( - CalcLengthOrPercentage::new(-length, Some(Percentage::hundred()))) + CalcLengthOrPercentage::new((-length).into(), 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)); - ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(-calc.unclamped_length(), Some(p))) + let l = -calc.unclamped_length(); + ComputedLengthOrPercentage::Calc(CalcLengthOrPercentage::new(l, Some(p))) }, } }, diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 3e766fb6f67..ec4e779903e 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -84,7 +84,7 @@ impl ToComputedValue for LineHeight { #[inline] fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { - use app_units::Au; + use values::computed::NonNegativeLength; use values::specified::length::FontBaseSize; match *self { GenericLineHeight::Normal => { @@ -119,13 +119,13 @@ impl ToComputedValue for LineHeight { .to_computed_value( context, FontBaseSize::CurrentStyle, - ); + ).px(); - let absolute_length = computed_calc.unclamped_length(); - computed_calc + let absolute_length = computed_calc.unclamped_length().px(); + let pixel = computed_calc .clamping_mode - .clamp(absolute_length + Au::from(font_relative_length)) - .into() + .clamp(absolute_length + font_relative_length); + NonNegativeLength::new(pixel) } }; GenericLineHeight::Length(result) diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 8d669d3496a..6e2d2856901 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -469,49 +469,6 @@ macro_rules! __define_css_keyword_enum__actual { /// Helper types for the handling of specified values. pub mod specified { use ParsingMode; - use app_units::Au; - use std::cmp; - - /// Whether to allow negative lengths or not. - #[repr(u8)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - #[derive(Clone, Copy, Debug, Eq, PartialEq)] - pub enum AllowedLengthType { - /// Allow all kind of lengths. - All, - /// Allow only non-negative lengths. - NonNegative - } - - impl Default for AllowedLengthType { - #[inline] - fn default() -> Self { - AllowedLengthType::All - } - } - - impl AllowedLengthType { - /// Whether value is valid for this allowed length type. - #[inline] - pub fn is_ok(&self, parsing_mode: ParsingMode, value: f32) -> bool { - if parsing_mode.allows_all_numeric_values() { - return true; - } - match *self { - AllowedLengthType::All => true, - AllowedLengthType::NonNegative => value >= 0., - } - } - - /// Clamp the value following the rules of this numeric type. - #[inline] - pub fn clamp(&self, val: Au) -> Au { - match *self { - AllowedLengthType::All => val, - AllowedLengthType::NonNegative => cmp::max(Au(0), val), - } - } - } /// Whether to allow negative lengths or not. #[repr(u8)] @@ -526,6 +483,13 @@ pub mod specified { AtLeastOne, } + impl Default for AllowedNumericType { + #[inline] + fn default() -> Self { + AllowedNumericType::All + } + } + impl AllowedNumericType { /// Whether the value fits the rules of this numeric type. #[inline] diff --git a/components/style_traits/viewport.rs b/components/style_traits/viewport.rs index d688f131ccf..fc34209af8a 100644 --- a/components/style_traits/viewport.rs +++ b/components/style_traits/viewport.rs @@ -107,7 +107,7 @@ impl Zoom { pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { use PARSING_MODE_DEFAULT; use cssparser::Token; - use values::specified::AllowedLengthType::NonNegative; + use values::specified::AllowedNumericType::NonNegative; match *input.next()? { // TODO: This parse() method should take ParserContext as an diff --git a/tests/unit/style/animated_properties.rs b/tests/unit/style/animated_properties.rs index f08c3c81c56..2ed9612faeb 100644 --- a/tests/unit/style/animated_properties.rs +++ b/tests/unit/style/animated_properties.rs @@ -90,16 +90,18 @@ fn test_transform_interpolation_on_translate() { Length::new(25.), )])); let to = TransformList(Some(vec![ - TransformOperation::Translate(LengthOrPercentage::Length(Au(100)), - LengthOrPercentage::Length(Au(50)), + TransformOperation::Translate(LengthOrPercentage::Length(Au::from_px(100)), + LengthOrPercentage::Length(Au::from_px(50)), Length::new(75.))])); assert_eq!( from.animate(&to, Procedure::Interpolate { progress: 0.5 }).unwrap(), TransformList(Some(vec![TransformOperation::Translate( // calc(50px + 25%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Au(50), Some(Percentage(0.25)))), + LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Length::new(50.), + Some(Percentage(0.25)))), // calc(25px + 50%) - LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Au(25), Some(Percentage(0.5)))), + LengthOrPercentage::Calc(CalcLengthOrPercentage::new(Length::new(25.), + Some(Percentage(0.5)))), Length::new(50.), )])) ); diff --git a/tests/unit/style/attr.rs b/tests/unit/style/attr.rs index 8c04de5caa0..9fc56ff82bb 100644 --- a/tests/unit/style/attr.rs +++ b/tests/unit/style/attr.rs @@ -8,12 +8,12 @@ use style::values::computed::{CalcLengthOrPercentage, Percentage}; #[test] fn test_length_calc() { - let calc = CalcLengthOrPercentage::new(Au(10), Some(Percentage(0.2))); + 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), 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))); }