From 4bdef435cc4ae37c874e75925f14a7b9896a29da Mon Sep 17 00:00:00 2001 From: hsinewu Date: Mon, 22 Aug 2016 06:01:03 -0500 Subject: [PATCH] servo: Merge #12918 - 12902 typedefs (from hsinewu:12902-typedefs); r=Manishearth Using type alias instead of newtype. Removing duplicated implementation, it's already inherited. No more type constructors and foo.0 --- - [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). - [X] These changes do not require tests because it's refactoring. Source-Repo: https://github.com/servo/servo Source-Revision: daee53cb7697459b9ad28a9ee377cd6d0b90c0a7 --- .../components/layout/display_list_builder.rs | 4 +- .../components/style/properties/gecko.mako.rs | 8 ++-- .../helpers/animated_properties.mako.rs | 7 ---- .../properties/longhand/background.mako.rs | 41 +++---------------- .../unit/style/properties/serialization.rs | 12 +++--- 5 files changed, 17 insertions(+), 55 deletions(-) diff --git a/servo/components/layout/display_list_builder.rs b/servo/components/layout/display_list_builder.rs index 2c0063b7c397..27ff1f7eb845 100644 --- a/servo/components/layout/display_list_builder.rs +++ b/servo/components/layout/display_list_builder.rs @@ -520,9 +520,9 @@ impl FragmentDisplayListBuilding for Fragment { }; // 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; diff --git a/servo/components/style/properties/gecko.mako.rs b/servo/components/style/properties/gecko.mako.rs index 0c717ee678cd..2c7e6f0ea1a2 100644 --- a/servo/components/style/properties/gecko.mako.rs +++ b/servo/components/style/properties/gecko.mako.rs @@ -1041,16 +1041,16 @@ fn static_assert() { 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; } diff --git a/servo/components/style/properties/helpers/animated_properties.mako.rs b/servo/components/style/properties/helpers/animated_properties.mako.rs index 3ba52cecef98..a45b68b6816e 100644 --- a/servo/components/style/properties/helpers/animated_properties.mako.rs +++ b/servo/components/style/properties/helpers/animated_properties.mako.rs @@ -496,13 +496,6 @@ impl Interpolate for Position { } } -impl Interpolate for BackgroundPosition { - #[inline] - fn interpolate(&self, other: &Self, time: f64) -> Result { - Ok(BackgroundPosition(try!(self.0.interpolate(&other.0, time)))) - } -} - impl Interpolate for BackgroundSize { fn interpolate(&self, other: &Self, time: f64) -> Result { use properties::longhands::background_size::computed_value::ExplicitSize; diff --git a/servo/components/style/properties/longhand/background.mako.rs b/servo/components/style/properties/longhand/background.mako.rs index 1a0f2aaeffe1..c36e6e63e747 100644 --- a/servo/components/style/properties/longhand/background.mako.rs +++ b/servo/components/style/properties/longhand/background.mako.rs @@ -85,54 +85,23 @@ ${helpers.predefined_type("background-color", "CSSColor", 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); + pub type T = Position; } - impl HasViewportPercentage for SpecifiedValue { - fn has_viewport_percentage(&self) -> bool { - self.0.has_viewport_percentage() - } - } - - #[derive(Debug, Clone, PartialEq, Copy)] - #[cfg_attr(feature = "servo", derive(HeapSizeOf))] - pub struct SpecifiedValue(pub Position); - - impl ToCss for SpecifiedValue { - fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - self.0.to_css(dest) - } - } - - impl ToCss for computed_value::T { - fn to_css(&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 { - Ok(SpecifiedValue(try!(Position::parse(input)))) + Ok(try!(Position::parse(input))) } diff --git a/servo/tests/unit/style/properties/serialization.rs b/servo/tests/unit/style/properties/serialization.rs index f47b5303a0fe..5bbe03fb610e 100644 --- a/servo/tests/unit/style/properties/serialization.rs +++ b/servo/tests/unit/style/properties/serialization.rs @@ -704,12 +704,12 @@ mod shorthand_serialization { 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); @@ -755,12 +755,12 @@ mod shorthand_serialization { 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); @@ -805,12 +805,12 @@ mod shorthand_serialization { 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);