servo: Merge #12918 - 12902 typedefs (from hsinewu:12902-typedefs); r=Manishearth
authorhsinewu <extraordinary1022@gmail.com>
Mon, 22 Aug 2016 06:01:03 -0500
changeset 339536 1717e7008dc7264fff9f4235a1f7d7336011a741
parent 339535 281631312857179b36e220bf482b341838d030b5
child 339537 e30abec7536067d297b11195df5faf58c0bd6900
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersManishearth
servo: Merge #12918 - 12902 typedefs (from hsinewu:12902-typedefs); r=Manishearth <!-- Please describe your changes on the following line: --> Using type alias instead of newtype. Removing duplicated implementation, it's already inherited. No more type constructors and foo.0 --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12902 (github issue number if applicable). <!-- Either: --> - [X] These changes do not require tests because it's refactoring. <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: daee53cb7697459b9ad28a9ee377cd6d0b90c0a7
servo/components/layout/display_list_builder.rs
servo/components/style/properties/gecko.mako.rs
servo/components/style/properties/helpers/animated_properties.mako.rs
servo/components/style/properties/longhand/background.mako.rs
servo/tests/unit/style/properties/serialization.rs
--- a/servo/components/layout/display_list_builder.rs
+++ b/servo/components/layout/display_list_builder.rs
@@ -515,19 +515,19 @@ impl FragmentDisplayListBuilding for Fra
                     // 'background-origin' has no effect.
                     origin_x = Au(0);
                     origin_y = Au(0);
                     (Au(0), Au(0))
                 }
             };
 
             // Use `background-position` to get the offset.
-            let horizontal_position = model::specified(background.background_position.0.horizontal,
+            let horizontal_position = model::specified(background.background_position.horizontal,
                                                        bounds.size.width - image_size.width);
-            let vertical_position = model::specified(background.background_position.0.vertical,
+            let vertical_position = model::specified(background.background_position.vertical,
                                                      bounds.size.height - image_size.height);
 
             let abs_x = border.left + virtual_origin_x + horizontal_position + origin_x;
             let abs_y = border.top + virtual_origin_y + vertical_position + origin_y;
 
             // Adjust origin and size based on background-repeat
             match background.background_repeat {
                 background_repeat::T::no_repeat => {
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -1036,26 +1036,26 @@ fn static_assert() {
         self.gecko.mImage.mPositionYCount = cmp::min(1, other.gecko.mImage.mPositionYCount);
         self.gecko.mImage.mLayers.mFirstElement.mPosition =
             other.gecko.mImage.mLayers.mFirstElement.mPosition;
     }
 
     pub fn clone_background_position(&self) -> longhands::background_position::computed_value::T {
         use values::computed::position::Position;
         let position = &self.gecko.mImage.mLayers.mFirstElement.mPosition;
-        longhands::background_position::computed_value::T(Position {
+        Position {
             horizontal: position.mXPosition.into(),
             vertical: position.mYPosition.into(),
-        })
+        }
     }
 
     pub fn set_background_position(&mut self, v: longhands::background_position::computed_value::T) {
         let position = &mut self.gecko.mImage.mLayers.mFirstElement.mPosition;
-        position.mXPosition = v.0.horizontal.into();
-        position.mYPosition = v.0.vertical.into();
+        position.mXPosition = v.horizontal.into();
+        position.mYPosition = v.vertical.into();
         self.gecko.mImage.mPositionXCount = 1;
         self.gecko.mImage.mPositionYCount = 1;
     }
 
     pub fn copy_background_image_from(&mut self, other: &Self) {
         unsafe {
             Gecko_CopyImageValueFrom(&mut self.gecko.mImage.mLayers.mFirstElement.mImage,
                                      &other.gecko.mImage.mLayers.mFirstElement.mImage);
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -491,23 +491,16 @@ impl Interpolate for Position {
     fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
         Ok(Position {
             horizontal: try!(self.horizontal.interpolate(&other.horizontal, time)),
             vertical: try!(self.vertical.interpolate(&other.vertical, time)),
         })
     }
 }
 
-impl Interpolate for BackgroundPosition {
-    #[inline]
-    fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
-        Ok(BackgroundPosition(try!(self.0.interpolate(&other.0, time))))
-    }
-}
-
 impl Interpolate for BackgroundSize {
     fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
         use properties::longhands::background_size::computed_value::ExplicitSize;
         match (self, other) {
             (&BackgroundSize::Explicit(ref me), &BackgroundSize::Explicit(ref other)) => {
                 Ok(BackgroundSize::Explicit(ExplicitSize {
                     width: try!(me.width.interpolate(&other.width, time)),
                     height: try!(me.height.interpolate(&other.height, time)),
--- a/servo/components/style/properties/longhand/background.mako.rs
+++ b/servo/components/style/properties/longhand/background.mako.rs
@@ -80,64 +80,33 @@
         use std::fmt;
         use values::LocalToCss;
         use values::HasViewportPercentage;
         use values::specified::position::Position;
 
         pub mod computed_value {
             use values::computed::position::Position;
 
-            #[derive(PartialEq, Copy, Clone, Debug)]
-            #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
-            pub struct T(pub Position);
-        }
-
-        impl HasViewportPercentage for SpecifiedValue {
-            fn has_viewport_percentage(&self) -> bool {
-                self.0.has_viewport_percentage()
-            }
+            pub type T = Position;
         }
 
-        #[derive(Debug, Clone, PartialEq, Copy)]
-        #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
-        pub struct SpecifiedValue(pub Position);
-
-        impl ToCss for SpecifiedValue {
-            fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-                self.0.to_css(dest)
-            }
-        }
-
-        impl ToCss for computed_value::T {
-            fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
-                self.0.to_css(dest)
-            }
-        }
-
-        impl ToComputedValue for SpecifiedValue {
-            type ComputedValue = computed_value::T;
-
-            #[inline]
-            fn to_computed_value(&self, context: &Context) -> computed_value::T {
-                computed_value::T(self.0.to_computed_value(context))
-            }
-        }
+        pub type SpecifiedValue = Position;
 
         #[inline]
         pub fn get_initial_value() -> computed_value::T {
             use values::computed::position::Position;
-            computed_value::T(Position {
+            Position {
                 horizontal: computed::LengthOrPercentage::Percentage(0.0),
                 vertical: computed::LengthOrPercentage::Percentage(0.0),
-            })
+            }
         }
 
         pub fn parse(_context: &ParserContext, input: &mut Parser)
                      -> Result<SpecifiedValue, ()> {
-            Ok(SpecifiedValue(try!(Position::parse(input))))
+            Ok(try!(Position::parse(input)))
         }
 </%helpers:longhand>
 
 ${helpers.single_keyword("background-repeat",
                          "repeat repeat-x repeat-y no-repeat",
                          animatable=False)}
 
 ${helpers.single_keyword("background-attachment",
--- a/servo/tests/unit/style/properties/serialization.rs
+++ b/servo/tests/unit/style/properties/serialization.rs
@@ -699,22 +699,22 @@ mod shorthand_serialization {
         fn background_should_serialize_all_available_properties_when_specified() {
             let mut properties = Vec::new();
 
             let color = DeclaredValue::Value(CSSColor {
                 parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
                 authored: None
             });
 
-            let position = DeclaredValue::Value(PositionContainer(
+            let position = DeclaredValue::Value(
                 Position {
                     horizontal: LengthOrPercentage::Length(Length::from_px(7f32)),
                     vertical: LengthOrPercentage::Length(Length::from_px(4f32))
                 }
-            ));
+            );
 
             let repeat = DeclaredValue::Value(Repeat::repeat_x);
             let attachment = DeclaredValue::Value(Attachment::scroll);
 
             let image = DeclaredValue::Value(ImageContainer(
                 Some(Image::Url(Url::parse("http://servo/test.png").unwrap(), UrlExtraData {}))
             ));
 
@@ -750,22 +750,22 @@ mod shorthand_serialization {
         fn background_should_combine_origin_and_clip_properties_when_equal() {
             let mut properties = Vec::new();
 
             let color = DeclaredValue::Value(CSSColor {
                 parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
                 authored: None
             });
 
-            let position = DeclaredValue::Value(PositionContainer(
+            let position = DeclaredValue::Value(
                 Position {
                     horizontal: LengthOrPercentage::Length(Length::from_px(7f32)),
                     vertical: LengthOrPercentage::Length(Length::from_px(4f32))
                 }
-            ));
+            );
 
             let repeat = DeclaredValue::Value(Repeat::repeat_x);
             let attachment = DeclaredValue::Value(Attachment::scroll);
 
             let image = DeclaredValue::Value(ImageContainer(
                 Some(Image::Url(Url::parse("http://servo/test.png").unwrap(), UrlExtraData {}))
             ));
 
@@ -800,22 +800,22 @@ mod shorthand_serialization {
         fn background_should_always_print_color_and_url_and_repeat_and_attachment_and_position() {
             let mut properties = Vec::new();
 
             let color = DeclaredValue::Value(CSSColor {
                 parsed: ComputedColor::RGBA(RGBA { red: 1f32, green: 0f32, blue: 0f32, alpha: 1f32 }),
                 authored: None
             });
 
-            let position = DeclaredValue::Value(PositionContainer(
+            let position = DeclaredValue::Value(
                 Position {
                     horizontal: LengthOrPercentage::Length(Length::from_px(0f32)),
                     vertical: LengthOrPercentage::Length(Length::from_px(0f32))
                 }
-            ));
+            );
 
             let repeat = DeclaredValue::Value(Repeat::repeat_x);
             let attachment = DeclaredValue::Value(Attachment::scroll);
 
             let image = DeclaredValue::Value(ImageContainer(None));
 
             let size = DeclaredValue::Initial;