From aea66a9fb6e5e2c367a65cbb7a2160715d0526d1 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 15 Feb 2018 10:00:51 +0100 Subject: [PATCH 1/4] Move FontTag to the generic module --- components/style/gecko/rules.rs | 3 +- components/style/properties/gecko.mako.rs | 3 +- .../helpers/animated_properties.mako.rs | 4 +- components/style/values/generics/font.rs | 46 ++++++++++++++++++- components/style/values/specified/font.rs | 46 +------------------ 5 files changed, 49 insertions(+), 53 deletions(-) diff --git a/components/style/gecko/rules.rs b/components/style/gecko/rules.rs index 599cdf81e25..ce448cddfd7 100644 --- a/components/style/gecko/rules.rs +++ b/components/style/gecko/rules.rs @@ -21,7 +21,8 @@ use std::fmt::{self, Write}; use std::str; use str::CssStringWriter; use values::computed::font::FamilyName; -use values::specified::font::{FontTag, FontVariationSettings, SpecifiedFontFeatureSettings}; +use values::generics::font::FontTag; +use values::specified::font::{FontVariationSettings, SpecifiedFontFeatureSettings}; /// A @font-face rule pub type FontFaceRule = RefPtr; diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index cded662230e..b33c63b50d2 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -1452,8 +1452,7 @@ impl Clone for ${style_struct.gecko_struct_name} { } pub fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { - use values::generics::font::{FontSettings, ${tag_type}}; - use values::specified::font::FontTag; + use values::generics::font::{FontSettings, FontTag, ${tag_type}}; FontSettings( self.gecko.mFont.${gecko_ffi_name}.iter().map(|gecko_font_setting| { diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 0d6fa24af2c..f0eb0113c95 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -52,14 +52,12 @@ use values::computed::transform::Translate as ComputedTranslate; use values::computed::transform::Scale as ComputedScale; use values::generics::transform::{self, Rotate, Translate, Scale, Transform, TransformOperation}; use values::distance::{ComputeSquaredDistance, SquaredDistance}; -use values::generics::font::FontSettings as GenericFontSettings; +use values::generics::font::{FontSettings as GenericFontSettings, FontTag, VariationValue}; use values::computed::font::FontVariationSettings; -use values::generics::font::VariationValue; use values::generics::effects::Filter; use values::generics::position as generic_position; use values::generics::svg::{SVGLength, SvgLengthOrPercentageOrNumber, SVGPaint}; use values::generics::svg::{SVGPaintKind, SVGStrokeDashArray, SVGOpacity}; -use values::specified::font::FontTag; use void::{self, Void}; /// diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index ddd3fc0ac3c..9a8374274ea 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -4,13 +4,14 @@ //! Generic types for font stuff. +use byteorder::{ReadBytesExt, BigEndian}; use cssparser::Parser; use num_traits::One; use parser::{Parse, ParserContext}; use std::fmt::{self, Write}; -use style_traits::{CssWriter, ParseError, ToCss}; +use std::io::Cursor; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::distance::{ComputeSquaredDistance, SquaredDistance}; -use values::specified::font::FontTag; /// https://drafts.csswg.org/css-fonts-4/#feature-tag-value #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)] @@ -117,3 +118,44 @@ impl ToCss for FontSettings { Ok(()) } } + +/// A font four-character tag, represented as a u32 for convenience. +/// +/// See: +/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def +/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-feature-settings +/// +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)] +pub struct FontTag(pub u32); + +impl ToCss for FontTag { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + use byteorder::{BigEndian, ByteOrder}; + use std::str; + + let mut raw = [0u8; 4]; + BigEndian::write_u32(&mut raw, self.0); + str::from_utf8(&raw).unwrap_or_default().to_css(dest) + } +} + +impl Parse for FontTag { + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + let location = input.current_source_location(); + let tag = input.expect_string()?; + + // allowed strings of length 4 containing chars: + if tag.len() != 4 || tag.as_bytes().iter().any(|c| *c < b' ' || *c > b'~') { + return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) + } + + let mut raw = Cursor::new(tag.as_bytes()); + Ok(FontTag(raw.read_u32::().unwrap())) + } +} diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index a9309267ad4..5443bdba2d0 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -21,7 +21,7 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::CustomIdent; use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue}; use values::computed::font::{SingleFontFamily, FontFamilyList, FamilyName}; -use values::generics::font::{FontSettings, FeatureTagValue, VariationValue}; +use values::generics::font::{FontSettings, FeatureTagValue, FontTag, VariationValue}; use values::specified::{AllowQuirks, Integer, LengthOrPercentage, NoCalcLength, Number}; use values::specified::length::{AU_PER_PT, AU_PER_PX, FontBaseSize}; @@ -1945,50 +1945,6 @@ impl Parse for FontLanguageOverride { } } -/// A font four-character tag, represented as a u32 for convenience. -/// -/// See: -/// https://drafts.csswg.org/css-fonts-4/#font-variation-settings-def -/// https://drafts.csswg.org/css-fonts-4/#descdef-font-face-font-feature-settings -/// -#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue)] -pub struct FontTag(pub u32); - -impl Parse for FontTag { - fn parse<'i, 't>( - _context: &ParserContext, - input: &mut Parser<'i, 't>, - ) -> Result> { - use byteorder::{ReadBytesExt, BigEndian}; - use std::io::Cursor; - - let location = input.current_source_location(); - let tag = input.expect_string()?; - - // allowed strings of length 4 containing chars: - if tag.len() != 4 || tag.as_bytes().iter().any(|c| *c < b' ' || *c > b'~') { - return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)) - } - - let mut raw = Cursor::new(tag.as_bytes()); - Ok(FontTag(raw.read_u32::().unwrap())) - } -} - -impl ToCss for FontTag { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - use byteorder::{BigEndian, ByteOrder}; - use std::str; - - let mut raw = [0u8; 4]; - BigEndian::write_u32(&mut raw, self.0); - str::from_utf8(&raw).unwrap_or_default().to_css(dest) - } -} - /// This property provides low-level control over OpenType or TrueType font /// variations. pub type FontVariationSettings = FontSettings>; From b17fea1d7fe4c3a0d186328d9b07cc8b767ed941 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 15 Feb 2018 10:26:36 +0100 Subject: [PATCH 2/4] Make KeywordInfo generic --- components/style/properties/gecko.mako.rs | 5 +- components/style/values/computed/font.rs | 49 +---------- components/style/values/generics/font.rs | 101 ++++++++++++++++++++++ components/style/values/specified/font.rs | 85 +++++------------- 4 files changed, 131 insertions(+), 109 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index b33c63b50d2..e06b724afaa 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2389,7 +2389,7 @@ fn static_assert() { } pub fn set_font_size(&mut self, v: FontSize) { - use values::specified::font::KeywordSize; + use values::generics::font::KeywordSize; self.gecko.mSize = v.size().0; self.gecko.mScriptUnconstrainedSize = v.size().0; if let Some(info) = v.keyword_info { @@ -2601,8 +2601,7 @@ fn static_assert() { } pub fn clone_font_size(&self) -> FontSize { - use values::computed::font::KeywordInfo; - use values::specified::font::KeywordSize; + use values::generics::font::{KeywordInfo, KeywordSize}; let size = Au(self.gecko.mSize).into(); let kw = match self.gecko.mFontSizeKeyword as u32 { structs::NS_STYLE_FONT_SIZE_XXSMALL => KeywordSize::XXSmall, diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 63b18bb3512..b8d2873a113 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -23,7 +23,8 @@ use style_traits::{CssWriter, ParseError, ToCss}; use values::CSSFloat; use values::animated::{ToAnimatedValue, ToAnimatedZero}; use values::computed::{Context, NonNegativeLength, ToComputedValue, Integer, Number}; -use values::generics::font::{FontSettings, FeatureTagValue, VariationValue}; +use values::generics::font::{FontSettings, FeatureTagValue}; +use values::generics::font::{KeywordInfo as GenericKeywordInfo, VariationValue}; use values::specified::font as specified; use values::specified::length::{FontBaseSize, NoCalcLength}; @@ -49,50 +50,8 @@ pub struct FontSize { pub keyword_info: Option, } -#[derive(Animate, ComputeSquaredDistance, MallocSizeOf, ToAnimatedValue, ToAnimatedZero)] -#[derive(Clone, Copy, Debug, PartialEq)] -/// Additional information for keyword-derived font sizes. -pub struct KeywordInfo { - /// The keyword used - pub kw: specified::KeywordSize, - /// A factor to be multiplied by the computed size of the keyword - pub factor: f32, - /// An additional Au offset to add to the kw*factor in the case of calcs - pub offset: NonNegativeLength, -} - -impl KeywordInfo { - /// Computes the final size for this font-size keyword, accounting for - /// text-zoom. - pub fn to_computed_value(&self, context: &Context) -> NonNegativeLength { - let base = context.maybe_zoom_text(self.kw.to_computed_value(context)); - base.scale_by(self.factor) + context.maybe_zoom_text(self.offset) - } - - /// Given a parent keyword info (self), apply an additional factor/offset to it - pub fn compose(self, factor: f32, offset: NonNegativeLength) -> Self { - KeywordInfo { - kw: self.kw, - factor: self.factor * factor, - offset: self.offset.scale_by(factor) + offset, - } - } - - /// KeywordInfo value for font-size: medium - pub fn medium() -> Self { - specified::KeywordSize::Medium.into() - } -} - -impl From for KeywordInfo { - fn from(x: specified::KeywordSize) -> Self { - KeywordInfo { - kw: x, - factor: 1., - offset: Au(0).into(), - } - } -} +/// Additional information for computed keyword-derived font sizes. +pub type KeywordInfo = GenericKeywordInfo; impl FontWeight { /// Value for normal diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index 9a8374274ea..828e7345d7a 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -4,6 +4,7 @@ //! Generic types for font stuff. +use app_units::Au; use byteorder::{ReadBytesExt, BigEndian}; use cssparser::Parser; use num_traits::One; @@ -159,3 +160,103 @@ impl Parse for FontTag { Ok(FontTag(raw.read_u32::().unwrap())) } } + +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero)] +/// Additional information for keyword-derived font sizes. +pub struct KeywordInfo { + /// The keyword used + pub kw: KeywordSize, + /// A factor to be multiplied by the computed size of the keyword + pub factor: f32, + /// An additional Au offset to add to the kw*factor in the case of calcs + pub offset: Length, +} + +impl KeywordInfo +where + Au: Into, +{ + /// KeywordInfo value for font-size: medium + pub fn medium() -> Self { + KeywordSize::Medium.into() + } +} + +impl From for KeywordInfo +where + Au: Into, +{ + fn from(x: KeywordSize) -> Self { + KeywordInfo { + kw: x, + factor: 1., + offset: Au(0).into(), + } + } +} + +/// CSS font keywords +#[derive(Animate, ComputeSquaredDistance, MallocSizeOf, ToAnimatedValue, ToAnimatedZero)] +#[derive(Clone, Copy, Debug, PartialEq)] +#[allow(missing_docs)] +pub enum KeywordSize { + XXSmall = 1, // This is to enable the NonZero optimization + // which simplifies the representation of Option + // in bindgen + XSmall, + Small, + Medium, + Large, + XLarge, + XXLarge, + // This is not a real font keyword and will not parse + // HTML font-size 7 corresponds to this value + XXXLarge, +} + +impl KeywordSize { + /// Convert to an HTML value + pub fn html_size(&self) -> u8 { + match *self { + KeywordSize::XXSmall => 0, + KeywordSize::XSmall => 1, + KeywordSize::Small => 2, + KeywordSize::Medium => 3, + KeywordSize::Large => 4, + KeywordSize::XLarge => 5, + KeywordSize::XXLarge => 6, + KeywordSize::XXXLarge => 7, + } + } +} + +impl Default for KeywordSize { + fn default() -> Self { + KeywordSize::Medium + } +} + +impl ToCss for KeywordSize { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + dest.write_str(match *self { + KeywordSize::XXSmall => "xx-small", + KeywordSize::XSmall => "x-small", + KeywordSize::Small => "small", + KeywordSize::Medium => "medium", + KeywordSize::Large => "large", + KeywordSize::XLarge => "x-large", + KeywordSize::XXLarge => "xx-large", + KeywordSize::XXXLarge => { + debug_assert!( + false, + "We should never serialize specified values set via HTML presentation attributes" + ); + "-servo-xxx-large" + }, + }) + } +} diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 5443bdba2d0..36d0ae7c698 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -21,7 +21,8 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use values::CustomIdent; use values::computed::{font as computed, Context, Length, NonNegativeLength, ToComputedValue}; use values::computed::font::{SingleFontFamily, FontFamilyList, FamilyName}; -use values::generics::font::{FontSettings, FeatureTagValue, FontTag, VariationValue}; +use values::generics::font::{FontSettings, FontTag, FeatureTagValue}; +use values::generics::font::{KeywordInfo as GenericKeywordInfo, KeywordSize, VariationValue}; use values::specified::{AllowQuirks, Integer, LengthOrPercentage, NoCalcLength, Number}; use values::specified::length::{AU_PER_PT, AU_PER_PX, FontBaseSize}; @@ -134,7 +135,7 @@ pub enum FontSize { /// go into the ratio, and the remaining units all computed together /// will go into the offset. /// See bug 1355707. - Keyword(computed::KeywordInfo), + Keyword(KeywordInfo), /// font-size: smaller Smaller, /// font-size: larger @@ -340,27 +341,29 @@ impl Parse for FontSizeAdjust { } } -/// CSS font keywords -#[derive(Animate, ComputeSquaredDistance, MallocSizeOf, ToAnimatedValue, ToAnimatedZero)] -#[derive(Clone, Copy, Debug, PartialEq)] -#[allow(missing_docs)] -pub enum KeywordSize { - XXSmall = 1, // This is to enable the NonZero optimization - // which simplifies the representation of Option - // in bindgen - XSmall, - Small, - Medium, - Large, - XLarge, - XXLarge, - // This is not a real font keyword and will not parse - // HTML font-size 7 corresponds to this value - XXXLarge, +/// Additional information for specified keyword-derived font sizes. +pub type KeywordInfo = GenericKeywordInfo; + +impl KeywordInfo { + /// Computes the final size for this font-size keyword, accounting for + /// text-zoom. + pub fn to_computed_value(&self, context: &Context) -> NonNegativeLength { + let base = context.maybe_zoom_text(self.kw.to_computed_value(context)); + base.scale_by(self.factor) + context.maybe_zoom_text(self.offset) + } + + /// Given a parent keyword info (self), apply an additional factor/offset to it + pub fn compose(self, factor: f32, offset: NonNegativeLength) -> Self { + KeywordInfo { + kw: self.kw, + factor: self.factor * factor, + offset: self.offset.scale_by(factor) + offset, + } + } } impl KeywordSize { - /// Parse a keyword size + /// Parses a keyword size. pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { try_match_ident_ignore_ascii_case! { input, "xx-small" => Ok(KeywordSize::XXSmall), @@ -372,46 +375,6 @@ impl KeywordSize { "xx-large" => Ok(KeywordSize::XXLarge), } } - - /// Convert to an HTML value - pub fn html_size(&self) -> u8 { - match *self { - KeywordSize::XXSmall => 0, - KeywordSize::XSmall => 1, - KeywordSize::Small => 2, - KeywordSize::Medium => 3, - KeywordSize::Large => 4, - KeywordSize::XLarge => 5, - KeywordSize::XXLarge => 6, - KeywordSize::XXXLarge => 7, - } - } -} - -impl Default for KeywordSize { - fn default() -> Self { - KeywordSize::Medium - } -} - -impl ToCss for KeywordSize { - fn to_css(&self, dest: &mut CssWriter) -> fmt::Result - where - W: Write, - { - dest.write_str(match *self { - KeywordSize::XXSmall => "xx-small", - KeywordSize::XSmall => "x-small", - KeywordSize::Small => "small", - KeywordSize::Medium => "medium", - KeywordSize::Large => "large", - KeywordSize::XLarge => "x-large", - KeywordSize::XXLarge => "xx-large", - KeywordSize::XXXLarge => unreachable!("We should never serialize \ - specified values set via - HTML presentation attributes"), - }) - } } /// This is the ratio applied for font-size: larger @@ -672,7 +635,7 @@ impl FontSize { #[inline] /// Get initial value for specified font size. pub fn medium() -> Self { - FontSize::Keyword(computed::KeywordInfo::medium()) + FontSize::Keyword(KeywordInfo::medium()) } /// Parses a font-size, with quirks. From 52f0fcabad785e0cf1e4dfe9fab716469265e0b5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 15 Feb 2018 10:53:41 +0100 Subject: [PATCH 3/4] Properly implement ToAnimatedZero for BorderSpacing --- components/style/values/animated/mod.rs | 13 +++++++++++++ components/style/values/computed/border.rs | 8 -------- components/style/values/generics/border.rs | 2 +- components/style/values/generics/size.rs | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 5946168f52f..a118292dd98 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -380,3 +380,16 @@ where } } } + +impl ToAnimatedZero for Size2D +where + T: ToAnimatedZero, +{ + #[inline] + fn to_animated_zero(&self) -> Result { + Ok(Size2D::new( + self.width.to_animated_zero()?, + self.height.to_animated_zero()?, + )) + } +} diff --git a/components/style/values/computed/border.rs b/components/style/values/computed/border.rs index cfef89a62e1..49b9eeda791 100644 --- a/components/style/values/computed/border.rs +++ b/components/style/values/computed/border.rs @@ -69,14 +69,6 @@ impl BorderCornerRadius { } } -impl ToAnimatedZero for BorderSpacing { - #[inline] - fn to_animated_zero(&self) -> Result { - // FIXME(emilio): Why? - Err(()) - } -} - impl ToAnimatedZero for BorderCornerRadius { #[inline] fn to_animated_zero(&self) -> Result { diff --git a/components/style/values/generics/border.rs b/components/style/values/generics/border.rs index 00cfe33ab62..4423d4c50d3 100644 --- a/components/style/values/generics/border.rs +++ b/components/style/values/generics/border.rs @@ -43,7 +43,7 @@ impl BorderCornerRadius { /// A generic value for the `border-spacing` property. #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] -#[derive(PartialEq, ToAnimatedValue, ToComputedValue, ToCss)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] pub struct BorderSpacing(pub Size); impl BorderSpacing { diff --git a/components/style/values/generics/size.rs b/components/style/values/generics/size.rs index f8c691a9a23..6d0904403ab 100644 --- a/components/style/values/generics/size.rs +++ b/components/style/values/generics/size.rs @@ -14,7 +14,7 @@ use values::animated::ToAnimatedValue; /// A generic size, for `border-*-radius` longhand properties, or /// `border-spacing`. #[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug)] -#[derive(MallocSizeOf, PartialEq, ToComputedValue)] +#[derive(MallocSizeOf, PartialEq, ToAnimatedZero, ToComputedValue)] pub struct Size(pub Size2D); impl Size { From d8c43ac8553c12cb6db2bdaf2b2ff74b86bb2aa9 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 15 Feb 2018 10:54:03 +0100 Subject: [PATCH 4/4] Animate NonNegativeLength as its inner type --- components/style/values/animated/effects.rs | 10 +++++----- components/style/values/animated/mod.rs | 15 --------------- components/style/values/computed/length.rs | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/components/style/values/animated/effects.rs b/components/style/values/animated/effects.rs index 4e3aeb4fde8..c1ce7fd6bed 100644 --- a/components/style/values/animated/effects.rs +++ b/components/style/values/animated/effects.rs @@ -13,7 +13,7 @@ use values::Impossible; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; use values::animated::color::RGBA; use values::computed::{Angle, Number}; -use values::computed::length::{Length, NonNegativeLength}; +use values::computed::length::Length; use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::effects::BoxShadow as GenericBoxShadow; use values::generics::effects::Filter as GenericFilter; @@ -33,7 +33,7 @@ pub type TextShadowList = ShadowList; pub struct ShadowList(Vec); /// An animated value for a single `box-shadow`. -pub type BoxShadow = GenericBoxShadow, Length, NonNegativeLength, Length>; +pub type BoxShadow = GenericBoxShadow, Length, Length, Length>; /// An animated value for the `filter` property. #[cfg_attr(feature = "servo", derive(MallocSizeOf))] @@ -42,14 +42,14 @@ pub struct FilterList(pub Vec); /// An animated value for a single `filter`. #[cfg(feature = "gecko")] -pub type Filter = GenericFilter; +pub type Filter = GenericFilter; /// An animated value for a single `filter`. #[cfg(not(feature = "gecko"))] -pub type Filter = GenericFilter; +pub type Filter = GenericFilter; /// An animated value for the `drop-shadow()` filter. -pub type SimpleShadow = GenericSimpleShadow, Length, NonNegativeLength>; +pub type SimpleShadow = GenericSimpleShadow, Length, Length>; impl ToAnimatedValue for ComputedBoxShadowList { type AnimatedValue = BoxShadowList; diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index a118292dd98..04bab7375f1 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -17,7 +17,6 @@ use values::computed::BorderCornerRadius as ComputedBorderCornerRadius; use values::computed::ComputedUrl; use values::computed::MaxLength as ComputedMaxLength; use values::computed::MozLength as ComputedMozLength; -use values::computed::NonNegativeLength as ComputedNonNegativeLength; use values::specified::url::SpecifiedUrl; pub mod color; @@ -261,20 +260,6 @@ trivial_to_animated_value!(ComputedUrl); trivial_to_animated_value!(bool); trivial_to_animated_value!(f32); -impl ToAnimatedValue for ComputedNonNegativeLength { - type AnimatedValue = Self; - - #[inline] - fn to_animated_value(self) -> Self { - self - } - - #[inline] - fn from_animated_value(animated: Self::AnimatedValue) -> Self { - ComputedNonNegativeLength::new(animated.px().max(0.)) - } -} - impl ToAnimatedValue for ComputedBorderCornerRadius { type AnimatedValue = Self; diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 8c00d330222..b482c8aeb17 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -815,6 +815,20 @@ pub type LengthOrNormal = Either; /// A wrapper of Length, whose value must be >= 0. pub type NonNegativeLength = NonNegative; +impl ToAnimatedValue for NonNegativeLength { + type AnimatedValue = Length; + + #[inline] + fn to_animated_value(self) -> Self::AnimatedValue { + self.0 + } + + #[inline] + fn from_animated_value(animated: Self::AnimatedValue) -> Self { + NonNegativeLength::new(animated.px().max(0.)) + } +} + impl NonNegativeLength { /// Create a NonNegativeLength. #[inline]