diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 2ca775ed345..e0003ceae30 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -4,7 +4,6 @@ //! Element nodes. -use app_units::Au; use cssparser::Color; use devtools_traits::AttrInfo; use dom::activation::Activatable; @@ -476,7 +475,7 @@ impl LayoutElementHelpers for LayoutJS { }; if let Some(cellspacing) = cellspacing { - let width_value = specified::Length::Absolute(Au::from_px(cellspacing as i32)); + let width_value = specified::Length::from_px(cellspacing as f32); hints.push(from_declaration( PropertyDeclaration::BorderSpacing(DeclaredValue::Value( border_spacing::SpecifiedValue { @@ -509,7 +508,8 @@ impl LayoutElementHelpers for LayoutJS { }; if let Some(size) = size { - let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(size)); + let value = specified::Length::NoCalc( + specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(size))); hints.push(from_declaration( PropertyDeclaration::Width(DeclaredValue::Value( specified::LengthOrPercentageOrAuto::Length(value))))); @@ -541,7 +541,7 @@ impl LayoutElementHelpers for LayoutJS { } LengthOrPercentageOrAuto::Length(length) => { let width_value = specified::LengthOrPercentageOrAuto::Length( - specified::Length::Absolute(length)); + specified::Length::NoCalc(specified::NoCalcLength::Absolute(length))); hints.push(from_declaration( PropertyDeclaration::Width(DeclaredValue::Value(width_value)))); } @@ -566,7 +566,7 @@ impl LayoutElementHelpers for LayoutJS { } LengthOrPercentageOrAuto::Length(length) => { let height_value = specified::LengthOrPercentageOrAuto::Length( - specified::Length::Absolute(length)); + specified::Length::NoCalc(specified::NoCalcLength::Absolute(length))); hints.push(from_declaration( PropertyDeclaration::Height(DeclaredValue::Value(height_value)))); } @@ -588,7 +588,8 @@ impl LayoutElementHelpers for LayoutJS { // scrollbar size into consideration (but we don't have a scrollbar yet!) // // https://html.spec.whatwg.org/multipage/#textarea-effective-width - let value = specified::Length::ServoCharacterWidth(specified::CharacterWidth(cols)); + let value = specified::Length::NoCalc( + specified::NoCalcLength::ServoCharacterWidth(specified::CharacterWidth(cols))); hints.push(from_declaration( PropertyDeclaration::Width(DeclaredValue::Value( specified::LengthOrPercentageOrAuto::Length(value))))); @@ -608,7 +609,8 @@ impl LayoutElementHelpers for LayoutJS { // TODO(mttr) This should take scrollbar size into consideration. // // https://html.spec.whatwg.org/multipage/#textarea-effective-height - let value = specified::Length::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat)); + let value = specified::Length::NoCalc( + specified::NoCalcLength::FontRelative(specified::FontRelativeLength::Em(rows as CSSFloat))); hints.push(from_declaration( PropertyDeclaration::Height(DeclaredValue::Value( specified::LengthOrPercentageOrAuto::Length(value))))); @@ -622,8 +624,7 @@ impl LayoutElementHelpers for LayoutJS { }; if let Some(border) = border { - let width_value = specified::BorderWidth::from_length( - specified::Length::Absolute(Au::from_px(border as i32))); + let width_value = specified::BorderWidth::from_length(specified::Length::from_px(border as f32)); hints.push(from_declaration( PropertyDeclaration::BorderTopWidth(DeclaredValue::Value(width_value.clone())))); hints.push(from_declaration( diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index 754afaf164d..9bec8f87b21 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -1328,7 +1328,7 @@ ${helpers.single_keyword("animation-fill-mode", result.push(SpecifiedOperation::Translate(TranslateKind::Translate, tx, ty, - specified::Length::Absolute(Au(0)))); + specified::Length::zero())); Ok(()) })) }, @@ -1339,7 +1339,7 @@ ${helpers.single_keyword("animation-fill-mode", TranslateKind::TranslateX, tx, specified::LengthOrPercentage::zero(), - specified::Length::Absolute(Au(0)))); + specified::Length::zero())); Ok(()) })) }, @@ -1350,7 +1350,7 @@ ${helpers.single_keyword("animation-fill-mode", TranslateKind::TranslateY, specified::LengthOrPercentage::zero(), ty, - specified::Length::Absolute(Au(0)))); + specified::Length::zero())); Ok(()) })) }, @@ -1836,7 +1836,7 @@ ${helpers.single_keyword("transform-style", Ok(SpecifiedValue { horizontal: result.horizontal.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))), vertical: result.vertical.unwrap_or(LengthOrPercentage::Percentage(Percentage(0.5))), - depth: result.depth.unwrap_or(Length::Absolute(Au(0))), + depth: result.depth.unwrap_or(Length::zero()), }) } diff --git a/components/style/properties/longhand/effects.mako.rs b/components/style/properties/longhand/effects.mako.rs index 3da52aa3db2..01771f36315 100644 --- a/components/style/properties/longhand/effects.mako.rs +++ b/components/style/properties/longhand/effects.mako.rs @@ -280,10 +280,10 @@ ${helpers.predefined_type("opacity", left = try!(parse_argument(context, input)); } Ok(SpecifiedValue(Some(SpecifiedClipRect { - top: top.unwrap_or(Length::Absolute(Au(0))), + top: top.unwrap_or(Length::zero()), right: right, bottom: bottom, - left: left.unwrap_or(Length::Absolute(Au(0))), + left: left.unwrap_or(Length::zero()), }))) }) } diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs index d143398b2d8..3bb3a09db89 100644 --- a/components/style/properties/longhand/font.mako.rs +++ b/components/style/properties/longhand/font.mako.rs @@ -329,7 +329,7 @@ ${helpers.single_keyword("font-variant-caps", use std::fmt; use style_traits::ToCss; use values::{FONT_MEDIUM_PX, HasViewportPercentage}; - use values::specified::{LengthOrPercentage, Length, Percentage}; + use values::specified::{LengthOrPercentage, Length, NoCalcLength, Percentage}; impl ToCss for SpecifiedValue { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { @@ -363,10 +363,10 @@ ${helpers.single_keyword("font-variant-caps", #[inline] fn to_computed_value(&self, context: &Context) -> computed_value::T { match self.0 { - LengthOrPercentage::Length(Length::FontRelative(value)) => { + LengthOrPercentage::Length(Length::NoCalc(NoCalcLength::FontRelative(value))) => { value.to_computed_value(context, /* use inherited */ true) } - LengthOrPercentage::Length(Length::ServoCharacterWidth(value)) => { + LengthOrPercentage::Length(Length::NoCalc(NoCalcLength::ServoCharacterWidth(value))) => { value.to_computed_value(context.inherited_style().get_font().clone_font_size()) } LengthOrPercentage::Length(ref l) => { diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index db83c7308df..9c63fd45686 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -113,13 +113,14 @@ specified::LengthOrPercentage::Length(ref value) => computed_value::T::Length(value.to_computed_value(context)), specified::LengthOrPercentage::Percentage(specified::Percentage(value)) => { - let fr = specified::Length::FontRelative(specified::FontRelativeLength::Em(value)); + let fr = specified::Length::NoCalc(specified::NoCalcLength::FontRelative( + specified::FontRelativeLength::Em(value))); computed_value::T::Length(fr.to_computed_value(context)) }, specified::LengthOrPercentage::Calc(ref calc) => { let calc = calc.to_computed_value(context); let fr = specified::FontRelativeLength::Em(calc.percentage()); - let fr = specified::Length::FontRelative(fr); + let fr = specified::Length::NoCalc(specified::NoCalcLength::FontRelative(fr)); computed_value::T::Length(calc.length() + fr.to_computed_value(context)) } } @@ -681,9 +682,7 @@ ${helpers.single_keyword("text-align-last", fn parse_one_text_shadow(context: &ParserContext, input: &mut Parser) -> Result { use app_units::Au; - let mut lengths = [specified::Length::Absolute(Au(0)), - specified::Length::Absolute(Au(0)), - specified::Length::Absolute(Au(0))]; + let mut lengths = [specified::Length::zero(), specified::Length::zero(), specified::Length::zero()]; let mut lengths_parsed = false; let mut color = None; diff --git a/components/style/properties/shorthand/inherited_text.mako.rs b/components/style/properties/shorthand/inherited_text.mako.rs index a75e6d8925d..d2b0bce7d76 100644 --- a/components/style/properties/shorthand/inherited_text.mako.rs +++ b/components/style/properties/shorthand/inherited_text.mako.rs @@ -99,7 +99,7 @@ Ok(Longhands { _webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor, authored: None })), - _webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))), + _webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::zero()))), }) } else { Err(()) diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 807bcadb5df..f9347ef33a1 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -57,7 +57,6 @@ <%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis" extra_prefixes="webkit" spec="https://drafts.csswg.org/css-flexbox/#flex-property"> use parser::Parse; - use app_units::Au; use values::specified::{Number, Length, LengthOrPercentageOrAutoOrContent}; pub fn parse_flexibility(input: &mut Parser) @@ -102,7 +101,7 @@ Ok(Longhands { flex_grow: grow.or(Some(Number(1.0))), flex_shrink: shrink.or(Some(Number(1.0))), - flex_basis: basis.or(Some(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0))))) + flex_basis: basis.or(Some(LengthOrPercentageOrAutoOrContent::Length(Length::zero()))) }) } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index d89f926dee4..c7175b5352d 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -327,7 +327,7 @@ fn serialize_basicshape_position(position: &Position, dest: &mut W) // 0 length should be replaced with 0% fn replace_with_percent(input: LengthOrPercentage) -> LengthOrPercentage { match input { - LengthOrPercentage::Length(Length::Absolute(au)) if au.0 == 0 => { + LengthOrPercentage::Length(ref l) if l == &Length::zero() => { LengthOrPercentage::Percentage(Percentage(0.0)) } _ => { diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index f6d30655064..8e9a96067d6 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -316,6 +316,18 @@ impl NoCalcLength { _ => Err(()) } } + + #[inline] + /// Returns a `zero` length. + pub fn zero() -> NoCalcLength { + NoCalcLength::Absolute(Au(0)) + } + + /// Get an absolute length from a px values. + #[inline] + pub fn from_px(px_value: CSSFloat) -> NoCalcLength { + NoCalcLength::Absolute(Au((px_value * AU_PER_PX) as i32)) + } } /// An extension to `NoCalcLength` to parse `calc` expressions. @@ -395,6 +407,12 @@ impl Mul for ViewportPercentageLength { } impl Length { + #[inline] + /// Returns a `zero` length. + pub fn zero() -> Length { + Length::NoCalc(NoCalcLength::zero()) + } + /// https://drafts.csswg.org/css-fonts-3/#font-size-prop pub fn from_str(s: &str) -> Option { NoCalcLength::from_str(s).map(Length::NoCalc) @@ -411,7 +429,7 @@ impl Length { Token::Dimension(ref value, ref unit) if context.is_ok(value.value) => Length::parse_dimension(value.value, unit), Token::Number(ref value) if value.value == 0. => - Ok(Length::Absolute(Au(0))), + Ok(Length::zero()), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => input.parse_nested_block(|input| { CalcLengthOrPercentage::parse_length(input, context) @@ -428,7 +446,7 @@ impl Length { /// Get an absolute length from a px values. #[inline] pub fn from_px(px_value: CSSFloat) -> Length { - Length::NoCalc(NoCalcLength::Absolute(Au((px_value * AU_PER_PX) as i32))) + Length::NoCalc(NoCalcLength::from_px(px_value)) } /// Extract inner length without a clone, replacing it with a 0 Au @@ -436,8 +454,7 @@ impl Length { /// Use when you need to move out of a length array without cloning #[inline] pub fn take(&mut self) -> Self { - let new = Length::Absolute(Au(0)); - mem::replace(self, new) + mem::replace(self, Length::zero()) } } @@ -473,7 +490,7 @@ pub struct CalcProductNode { #[derive(Clone, Debug)] #[allow(missing_docs)] pub enum CalcValueNode { - Length(Length), + Length(LengthInternal), Angle(Angle), Time(Time), Percentage(CSSFloat), @@ -566,7 +583,7 @@ impl CalcLengthOrPercentage { (Token::Number(ref value), _) => Ok(CalcValueNode::Number(value.value)), (Token::Dimension(ref value, ref unit), CalcUnit::Length) | (Token::Dimension(ref value, ref unit), CalcUnit::LengthOrPercentage) => { - Length::parse_dimension(value.value, unit).map(CalcValueNode::Length) + LengthInternal::parse_dimension(value.value, unit).map(CalcValueNode::Length) } (Token::Dimension(ref value, ref unit), CalcUnit::Angle) => { Angle::parse_dimension(value.value, unit).map(CalcValueNode::Angle) @@ -907,9 +924,10 @@ impl ToCss for LengthOrPercentage { } } impl LengthOrPercentage { + #[inline] /// Returns a `zero` length. pub fn zero() -> LengthOrPercentage { - LengthOrPercentage::Length(Length::Absolute(Au(0))) + LengthOrPercentage::Length(Length::zero()) } fn parse_internal(input: &mut Parser, context: AllowedNumericType) @@ -921,7 +939,7 @@ impl LengthOrPercentage { Token::Percentage(ref value) if context.is_ok(value.unit_value) => Ok(LengthOrPercentage::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => - Ok(LengthOrPercentage::Length(Length::Absolute(Au(0)))), + Ok(LengthOrPercentage::Length(Length::zero())), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); Ok(LengthOrPercentage::Calc(Box::new(calc))) @@ -941,8 +959,7 @@ impl LengthOrPercentage { /// Use when you need to move out of a length array without cloning #[inline] pub fn take(&mut self) -> Self { - let new = LengthOrPercentage::Length(Length::Absolute(Au(0))); - mem::replace(self, new) + mem::replace(self, LengthOrPercentage::zero()) } } @@ -996,7 +1013,7 @@ impl LengthOrPercentageOrAuto { Token::Percentage(ref value) if context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrAuto::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => - Ok(LengthOrPercentageOrAuto::Length(Length::Absolute(Au(0)))), + Ok(LengthOrPercentageOrAuto::Length(Length::zero())), Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(LengthOrPercentageOrAuto::Auto), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { @@ -1063,7 +1080,7 @@ impl LengthOrPercentageOrNone { Token::Percentage(ref value) if context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrNone::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => - Ok(LengthOrPercentageOrNone::Length(Length::Absolute(Au(0)))), + Ok(LengthOrPercentageOrNone::Length(Length::zero())), Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => { let calc = try!(input.parse_nested_block(CalcLengthOrPercentage::parse_length_or_percentage)); Ok(LengthOrPercentageOrNone::Calc(Box::new(calc))) @@ -1146,7 +1163,7 @@ impl Parse for LengthOrPercentageOrAutoOrContent { Token::Percentage(ref value) if context.is_ok(value.unit_value) => Ok(LengthOrPercentageOrAutoOrContent::Percentage(Percentage(value.unit_value))), Token::Number(ref value) if value.value == 0. => - Ok(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0)))), + Ok(LengthOrPercentageOrAutoOrContent::Length(Length::zero())), Token::Ident(ref value) if value.eq_ignore_ascii_case("auto") => Ok(LengthOrPercentageOrAutoOrContent::Auto), Token::Ident(ref value) if value.eq_ignore_ascii_case("content") => diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 253237528bc..8a57f52d99a 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -198,7 +198,7 @@ impl NoViewportPercentage for BorderRadiusSize {} impl BorderRadiusSize { #[allow(missing_docs)] pub fn zero() -> BorderRadiusSize { - let zero = LengthOrPercentage::Length(Length::Absolute(Au(0))); + let zero = LengthOrPercentage::Length(Length::default()); BorderRadiusSize(Size2D::new(zero.clone(), zero)) } @@ -605,12 +605,11 @@ impl Shadow { // disable_spread_and_inset is for filter: drop-shadow(...) #[allow(missing_docs)] pub fn parse(context: &ParserContext, input: &mut Parser, disable_spread_and_inset: bool) -> Result { - use app_units::Au; let length_count = if disable_spread_and_inset { 3 } else { 4 }; - let mut lengths = [Length::Absolute(Au(0)), - Length::Absolute(Au(0)), - Length::Absolute(Au(0)), - Length::Absolute(Au(0))]; + let mut lengths = [Length::default(), + Length::default(), + Length::default(), + Length::default()]; let mut lengths_parsed = false; let mut color = None; let mut inset = false; @@ -662,7 +661,7 @@ impl Shadow { offset_x: lengths[0].take(), offset_y: lengths[1].take(), blur_radius: lengths[2].take(), - spread_radius: if disable_spread_and_inset { Length::Absolute(Au(0)) } else { lengths[3].take() }, + spread_radius: if disable_spread_and_inset { Length::default() } else { lengths[3].take() }, color: color, inset: inset, }) diff --git a/components/style/viewport.rs b/components/style/viewport.rs index 7e98b7e2460..eb2d0e99f4e 100644 --- a/components/style/viewport.rs +++ b/components/style/viewport.rs @@ -25,7 +25,7 @@ use style_traits::ToCss; use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom}; use stylesheets::{Stylesheet, Origin}; use values::computed::{Context, ToComputedValue}; -use values::specified::{Length, LengthOrPercentageOrAuto, ViewportPercentageLength}; +use values::specified::{Length, NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength}; macro_rules! declare_viewport_descriptor { ( $( $variant_name: expr => $variant: ident($data: ident), )+ ) => { @@ -150,9 +150,11 @@ impl FromMeta for ViewportLength { Some(match value { v if v.eq_ignore_ascii_case("device-width") => - specified!(Length::ViewportPercentage(ViewportPercentageLength::Vw(100.))), + specified!(Length::NoCalc( + NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.)))), v if v.eq_ignore_ascii_case("device-height") => - specified!(Length::ViewportPercentage(ViewportPercentageLength::Vh(100.))), + specified!(Length::NoCalc( + NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(100.)))), _ => { match value.parse::() { Ok(n) if n >= 0. => specified!(Length::from_px(n.max(1.).min(10000.))), diff --git a/tests/unit/style/media_queries.rs b/tests/unit/style/media_queries.rs index d6e32a9e5a5..11e1987928a 100644 --- a/tests/unit/style/media_queries.rs +++ b/tests/unit/style/media_queries.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use app_units::Au; use cssparser::{Parser, SourcePosition}; use euclid::size::TypedSize2D; use servo_url::ServoUrl; @@ -207,7 +206,7 @@ fn test_mq_default_expressions() { assert!(q.media_type == MediaQueryType::All, css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(100))), + ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::from_px(100.)), _ => panic!("wrong expression type"), } }); @@ -219,7 +218,7 @@ fn test_mq_default_expressions() { assert!(q.media_type == MediaQueryType::All, css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(43))), + ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::from_px(43.)), _ => panic!("wrong expression type"), } }); @@ -234,7 +233,7 @@ fn test_mq_expressions() { assert!(q.media_type == MediaQueryType::Known(MediaType::Screen), css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(100))), + ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::from_px(100.)), _ => panic!("wrong expression type"), } }); @@ -246,7 +245,7 @@ fn test_mq_expressions() { assert!(q.media_type == MediaQueryType::Known(MediaType::Print), css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(43))), + ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::from_px(43.)), _ => panic!("wrong expression type"), } }); @@ -258,7 +257,7 @@ fn test_mq_expressions() { assert!(q.media_type == MediaQueryType::Known(MediaType::Print), css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Eq(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(43))), + ExpressionKind::Width(Range::Eq(ref w)) => assert!(*w == specified::Length::from_px(43.)), _ => panic!("wrong expression type"), } }); @@ -270,7 +269,7 @@ fn test_mq_expressions() { assert!(q.media_type == MediaQueryType::Unknown(Atom::from("fridge")), css.to_owned()); assert!(q.expressions.len() == 1, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(52))), + ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::from_px(52.)), _ => panic!("wrong expression type"), } }); @@ -295,11 +294,11 @@ fn test_mq_multiple_expressions() { assert!(q.media_type == MediaQueryType::All, css.to_owned()); assert!(q.expressions.len() == 2, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(100))), + ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::from_px(100.)), _ => panic!("wrong expression type"), } match *q.expressions[1].kind_for_testing() { - ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(200))), + ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::from_px(200.)), _ => panic!("wrong expression type"), } }); @@ -311,11 +310,11 @@ fn test_mq_multiple_expressions() { assert!(q.media_type == MediaQueryType::Known(MediaType::Screen), css.to_owned()); assert!(q.expressions.len() == 2, css.to_owned()); match *q.expressions[0].kind_for_testing() { - ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(100))), + ExpressionKind::Width(Range::Min(ref w)) => assert!(*w == specified::Length::from_px(100.)), _ => panic!("wrong expression type"), } match *q.expressions[1].kind_for_testing() { - ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::Absolute(Au::from_px(200))), + ExpressionKind::Width(Range::Max(ref w)) => assert!(*w == specified::Length::from_px(200.)), _ => panic!("wrong expression type"), } }); diff --git a/tests/unit/style/properties/viewport.rs b/tests/unit/style/properties/viewport.rs index 221e7d568bb..7e036a6e95d 100644 --- a/tests/unit/style/properties/viewport.rs +++ b/tests/unit/style/properties/viewport.rs @@ -6,21 +6,21 @@ use app_units::Au; use style::properties::{DeclaredValue, PropertyDeclaration}; use style::properties::longhands::border_top_width; use style::values::HasViewportPercentage; -use style::values::specified::{Length, ViewportPercentageLength}; +use style::values::specified::{Length, NoCalcLength, ViewportPercentageLength}; #[test] fn has_viewport_percentage_for_specified_value() { //TODO: test all specified value with a HasViewportPercentage impl let pvw = PropertyDeclaration::BorderTopWidth( DeclaredValue::Value(border_top_width::SpecifiedValue::from_length( - Length::ViewportPercentage(ViewportPercentageLength::Vw(100.)) + Length::NoCalc(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.))) )) ); assert!(pvw.has_viewport_percentage()); let pabs = PropertyDeclaration::BorderTopWidth( DeclaredValue::Value(border_top_width::SpecifiedValue::from_length( - Length::Absolute(Au(100)) + Length::NoCalc(NoCalcLength::Absolute(Au(100))) )) ); assert!(!pabs.has_viewport_percentage()); diff --git a/tests/unit/style/value.rs b/tests/unit/style/value.rs index 4f9944e324d..472a5177d30 100644 --- a/tests/unit/style/value.rs +++ b/tests/unit/style/value.rs @@ -5,14 +5,14 @@ use app_units::Au; use cssparser::Parser; use style::values::HasViewportPercentage; -use style::values::specified::{ViewportPercentageLength, Length}; +use style::values::specified::{ViewportPercentageLength, NoCalcLength}; use style::values::specified::length::{CalcLengthOrPercentage, CalcUnit}; #[test] fn length_has_viewport_percentage() { - let l = Length::ViewportPercentage(ViewportPercentageLength::Vw(100.)); + let l = NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.)); assert!(l.has_viewport_percentage()); - let l = Length::Absolute(Au(100)); + let l = NoCalcLength::Absolute(Au(100)); assert!(!l.has_viewport_percentage()); }