From ae2dec4e604b63b88b8709360572d3992af5cc68 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 31 May 2016 16:13:29 -0700 Subject: [PATCH] Factor out nsStyleCoord::copy_from --- ports/geckolib/properties.mako.rs | 20 ++++++++++---------- ports/geckolib/values.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 234f667a1750..a92262692423 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -149,6 +149,12 @@ pub struct ${style_struct.gecko_struct_name} { } +<%def name="impl_coord_copy(ident, gecko_ffi_name)"> + fn copy_${ident}_from(&mut self, other: &Self) { + self.gecko.${gecko_ffi_name}.copy_from(&other.gecko.${gecko_ffi_name}); + } + + <%! def is_border_style_masked(ffi_name): return ffi_name.split("[")[0] in ["mBorderStyle", "mOutlineStyle", "mTextDecorationStyle"] @@ -673,11 +679,8 @@ fn static_assert() { T::LengthOrPercentage(v) => self.gecko.mVerticalAlign.set(v), } } - fn copy_vertical_align_from(&mut self, other: &Self) { - debug_assert_unit_is_safe_to_copy(self.gecko.mVerticalAlign.mUnit); - self.gecko.mVerticalAlign.mUnit = other.gecko.mVerticalAlign.mUnit; - self.gecko.mVerticalAlign.mValue = other.gecko.mVerticalAlign.mValue; - } + + <%call expr="impl_coord_copy('vertical_align', 'mVerticalAlign')"> fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) { use style::properties::longhands::_moz_binding::SpecifiedValue as BindingValue; @@ -736,11 +739,8 @@ fn static_assert() { self.gecko.mLineHeight.set_enum(structs::NS_STYLE_LINE_HEIGHT_BLOCK_HEIGHT as i32), } } - fn copy_line_height_from(&mut self, other: &Self) { - debug_assert_unit_is_safe_to_copy(self.gecko.mLineHeight.mUnit); - self.gecko.mLineHeight.mUnit = other.gecko.mLineHeight.mUnit; - self.gecko.mLineHeight.mValue = other.gecko.mLineHeight.mValue; - } + + <%call expr="impl_coord_copy('line_height', 'mLineHeight')"> diff --git a/ports/geckolib/values.rs b/ports/geckolib/values.rs index 6909989311df..3f0ab125d3b3 100644 --- a/ports/geckolib/values.rs +++ b/ports/geckolib/values.rs @@ -9,6 +9,7 @@ use std::cmp::max; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; pub trait StyleCoordHelpers { + fn copy_from(&mut self, other: &Self); fn set(&mut self, val: T); fn set_auto(&mut self); fn set_normal(&mut self); @@ -20,6 +21,13 @@ pub trait StyleCoordHelpers { } impl StyleCoordHelpers for nsStyleCoord { + fn copy_from(&mut self, other: &Self) { + debug_assert_unit_is_safe_to_copy(self.mUnit); + debug_assert_unit_is_safe_to_copy(other.mUnit); + self.mUnit = other.mUnit; + self.mValue = other.mValue; + } + fn set(&mut self, val: T) { val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue); }