Bug 1516454 - Make the generic size not use euclid under the hood. r=firefox-style-system-reviewers,boris
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 25 Feb 2019 03:05:39 +0000
changeset 460950 ec3876470b164a2879a7a60d791e513772ad6659
parent 460949 96e8b4cb4561b5db7783d5fcfec7ed4d64509391
child 460951 7733f36c6e38cf684cf612e81f6b89cad4df3566
push id78921
push userealvarez@mozilla.com
push dateMon, 25 Feb 2019 17:58:35 +0000
treeherderautoland@ec3876470b16 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfirefox-style-system-reviewers, boris
bugs1516454
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516454 - Make the generic size not use euclid under the hood. r=firefox-style-system-reviewers,boris The euclid size is not really used for anything. Also rename it to Size2D to avoid cbindgen conflicts with values::length::Size. Depends on D20958 Differential Revision: https://phabricator.services.mozilla.com/D20959
servo/components/style/values/computed/border.rs
servo/components/style/values/generics/border.rs
servo/components/style/values/generics/size.rs
servo/components/style/values/specified/border.rs
--- a/servo/components/style/values/computed/border.rs
+++ b/servo/components/style/values/computed/border.rs
@@ -7,17 +7,17 @@
 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;
 use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice;
 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::generics::size::Size2D;
 use crate::values::generics::NonNegative;
 use app_units::Au;
 
 pub use crate::values::specified::border::BorderImageRepeat;
 
 /// A computed value for the `border-image-width` property.
 pub type BorderImageWidth = Rect<BorderImageSideWidth>;
 
@@ -54,17 +54,17 @@ impl BorderImageSlice {
             fill: false,
         }
     }
 }
 
 impl BorderSpacing {
     /// Returns `0 0`.
     pub fn zero() -> Self {
-        GenericBorderSpacing(Size::new(
+        GenericBorderSpacing(Size2D::new(
             NonNegativeLength::zero(),
             NonNegativeLength::zero(),
         ))
     }
 
     /// Returns the horizontal spacing.
     pub fn horizontal(&self) -> Au {
         Au::from(*self.0.width())
@@ -74,17 +74,17 @@ impl BorderSpacing {
     pub fn vertical(&self) -> Au {
         Au::from(*self.0.height())
     }
 }
 
 impl BorderCornerRadius {
     /// Returns `0 0`.
     pub fn zero() -> Self {
-        GenericBorderCornerRadius(Size::new(
+        GenericBorderCornerRadius(Size2D::new(
             NonNegativeLengthPercentage::zero(),
             NonNegativeLengthPercentage::zero(),
         ))
     }
 }
 
 impl BorderRadius {
     /// Returns whether all the values are `0px`.
--- a/servo/components/style/values/generics/border.rs
+++ b/servo/components/style/values/generics/border.rs
@@ -1,16 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
 
 //! Generic types for CSS values related to borders.
 
 use crate::values::generics::rect::Rect;
-use crate::values::generics::size::Size;
+use crate::values::generics::size::Size2D;
 use std::fmt::{self, Write};
 use style_traits::{CssWriter, ToCss};
 
 /// A generic value for a single side of a `border-image-width` property.
 #[derive(
     Clone, Copy, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss,
 )]
 pub enum BorderImageSideWidth<LengthPercentage, Number> {
@@ -48,22 +48,22 @@ pub use self::GenericBorderImageSlice as
     MallocSizeOf,
     PartialEq,
     SpecifiedValueInfo,
     ToAnimatedValue,
     ToAnimatedZero,
     ToComputedValue,
     ToCss,
 )]
-pub struct BorderCornerRadius<L>(#[css(field_bound)] pub Size<L>);
+pub struct BorderCornerRadius<L>(#[css(field_bound)] pub Size2D<L>);
 
 impl<L> BorderCornerRadius<L> {
     /// Trivially create a `BorderCornerRadius`.
     pub fn new(w: L, h: L) -> Self {
-        BorderCornerRadius(Size::new(w, h))
+        BorderCornerRadius(Size2D::new(w, h))
     }
 }
 
 /// A generic value for the `border-spacing` property.
 #[derive(
     Animate,
     Clone,
     ComputeSquaredDistance,
@@ -72,22 +72,22 @@ impl<L> BorderCornerRadius<L> {
     MallocSizeOf,
     PartialEq,
     SpecifiedValueInfo,
     ToAnimatedValue,
     ToAnimatedZero,
     ToComputedValue,
     ToCss,
 )]
-pub struct BorderSpacing<L>(#[css(field_bound)] pub Size<L>);
+pub struct BorderSpacing<L>(#[css(field_bound)] pub Size2D<L>);
 
 impl<L> BorderSpacing<L> {
     /// Trivially create a `BorderCornerRadius`.
     pub fn new(w: L, h: L) -> Self {
-        BorderSpacing(Size::new(w, h))
+        BorderSpacing(Size2D::new(w, h))
     }
 }
 
 /// A generic value for `border-radius`, `outline-radius` and `inset()`.
 ///
 /// <https://drafts.csswg.org/css-backgrounds-3/#border-radius>
 #[derive(
     Animate,
@@ -163,14 +163,14 @@ where
     {
         let BorderRadius {
             top_left: BorderCornerRadius(ref tl),
             top_right: BorderCornerRadius(ref tr),
             bottom_right: BorderCornerRadius(ref br),
             bottom_left: BorderCornerRadius(ref bl),
         } = *self;
 
-        let widths = Rect::new(&tl.0.width, &tr.0.width, &br.0.width, &bl.0.width);
-        let heights = Rect::new(&tl.0.height, &tr.0.height, &br.0.height, &bl.0.height);
+        let widths = Rect::new(&tl.width, &tr.width, &br.width, &bl.width);
+        let heights = Rect::new(&tl.height, &tr.height, &br.height, &bl.height);
 
         Self::serialize_rects(widths, heights, dest)
     }
 }
--- a/servo/components/style/values/generics/size.rs
+++ b/servo/components/style/values/generics/size.rs
@@ -1,54 +1,58 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
 
 //! Generic type for CSS properties that are composed by two dimensions.
 
 use crate::parser::ParserContext;
-use crate::values::animated::ToAnimatedValue;
 use cssparser::Parser;
-use euclid::Size2D;
 use std::fmt::{self, Write};
-use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, ToCss};
+use style_traits::{CssWriter, ParseError, ToCss};
 
 /// A generic size, for `border-*-radius` longhand properties, or
 /// `border-spacing`.
 #[derive(
     Animate,
     Clone,
     ComputeSquaredDistance,
     Copy,
     Debug,
     MallocSizeOf,
     PartialEq,
+    SpecifiedValueInfo,
     ToAnimatedZero,
+    ToAnimatedValue,
     ToComputedValue,
 )]
-pub struct Size<L>(pub Size2D<L>);
+#[allow(missing_docs)]
+pub struct Size2D<L> {
+    pub width: L,
+    pub height: L,
+}
 
-impl<L> Size<L> {
+impl<L> Size2D<L> {
     #[inline]
-    /// Create a new `Size` for an area of given width and height.
-    pub fn new(width: L, height: L) -> Size<L> {
-        Size(Size2D::new(width, height))
+    /// Create a new `Size2D` for an area of given width and height.
+    pub fn new(width: L, height: L) -> Self {
+        Self { width, height }
     }
 
     /// Returns the width component.
     pub fn width(&self) -> &L {
-        &self.0.width
+        &self.width
     }
 
     /// Returns the height component.
     pub fn height(&self) -> &L {
-        &self.0.height
+        &self.height
     }
 
-    /// Parse a `Size` with a given parsing function.
+    /// Parse a `Size2D` with a given parsing function.
     pub fn parse_with<'i, 't, F>(
         context: &ParserContext,
         input: &mut Parser<'i, 't>,
         parse_one: F,
     ) -> Result<Self, ParseError<'i>>
     where
         L: Clone,
         F: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result<L, ParseError<'i>>,
@@ -56,53 +60,26 @@ impl<L> Size<L> {
         let first = parse_one(context, input)?;
         let second = input
             .try(|i| parse_one(context, i))
             .unwrap_or_else(|_| first.clone());
         Ok(Self::new(first, second))
     }
 }
 
-impl<L> ToCss for Size<L>
+impl<L> ToCss for Size2D<L>
 where
     L: ToCss + PartialEq,
 {
     fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
     where
         W: Write,
     {
-        self.0.width.to_css(dest)?;
+        self.width.to_css(dest)?;
 
-        if self.0.height != self.0.width {
+        if self.height != self.width {
             dest.write_str(" ")?;
-            self.0.height.to_css(dest)?;
+            self.height.to_css(dest)?;
         }
 
         Ok(())
     }
 }
-
-impl<L> ToAnimatedValue for Size<L>
-where
-    L: ToAnimatedValue,
-{
-    type AnimatedValue = Size<L::AnimatedValue>;
-
-    #[inline]
-    fn to_animated_value(self) -> Self::AnimatedValue {
-        Size(Size2D::new(
-            self.0.width.to_animated_value(),
-            self.0.height.to_animated_value(),
-        ))
-    }
-
-    #[inline]
-    fn from_animated_value(animated: Self::AnimatedValue) -> Self {
-        Size(Size2D::new(
-            L::from_animated_value(animated.0.width),
-            L::from_animated_value(animated.0.height),
-        ))
-    }
-}
-
-impl<L: SpecifiedValueInfo> SpecifiedValueInfo for Size<L> {
-    const SUPPORTED_TYPES: u8 = L::SUPPORTED_TYPES;
-}
--- a/servo/components/style/values/specified/border.rs
+++ b/servo/components/style/values/specified/border.rs
@@ -7,17 +7,17 @@
 use crate::parser::{Parse, ParserContext};
 use crate::values::computed::{self, Context, ToComputedValue};
 use crate::values::generics::border::BorderCornerRadius as GenericBorderCornerRadius;
 use crate::values::generics::border::BorderImageSideWidth as GenericBorderImageSideWidth;
 use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice;
 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::generics::size::Size2D;
 use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
 use crate::values::specified::{AllowQuirks, NonNegativeNumber, NonNegativeNumberOrPercentage};
 use cssparser::Parser;
 use std::fmt::{self, Write};
 use style_traits::{CssWriter, ParseError, ToCss};
 
 /// A specified value for a single side of a `border-style` property.
 ///
@@ -223,27 +223,27 @@ impl Parse for BorderRadius {
     }
 }
 
 impl Parse for BorderCornerRadius {
     fn parse<'i, 't>(
         context: &ParserContext,
         input: &mut Parser<'i, 't>,
     ) -> Result<Self, ParseError<'i>> {
-        Size::parse_with(context, input, NonNegativeLengthPercentage::parse)
+        Size2D::parse_with(context, input, NonNegativeLengthPercentage::parse)
             .map(GenericBorderCornerRadius)
     }
 }
 
 impl Parse for BorderSpacing {
     fn parse<'i, 't>(
         context: &ParserContext,
         input: &mut Parser<'i, 't>,
     ) -> Result<Self, ParseError<'i>> {
-        Size::parse_with(context, input, |context, input| {
+        Size2D::parse_with(context, input, |context, input| {
             NonNegativeLength::parse_quirky(context, input, AllowQuirks::Yes).map(From::from)
         })
         .map(GenericBorderSpacing)
     }
 }
 
 /// A single border-image-repeat keyword.
 #[allow(missing_docs)]