Skip to content

Commit

Permalink
Factor out nsStyleCoord::copy_from
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrubeck committed May 31, 2016
1 parent 1389fbe commit ae2dec4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ports/geckolib/properties.mako.rs
Expand Up @@ -149,6 +149,12 @@ pub struct ${style_struct.gecko_struct_name} {
}
</%def>

<%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>

<%!
def is_border_style_masked(ffi_name):
return ffi_name.split("[")[0] in ["mBorderStyle", "mOutlineStyle", "mTextDecorationStyle"]
Expand Down Expand Up @@ -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')"></%call>

fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
use style::properties::longhands::_moz_binding::SpecifiedValue as BindingValue;
Expand Down Expand Up @@ -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')"></%call>

</%self:impl_trait>

Expand Down
8 changes: 8 additions & 0 deletions ports/geckolib/values.rs
Expand Up @@ -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<T: ToGeckoStyleCoord>(&mut self, val: T);
fn set_auto(&mut self);
fn set_normal(&mut self);
Expand All @@ -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<T: ToGeckoStyleCoord>(&mut self, val: T) {
val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue);
}
Expand Down

0 comments on commit ae2dec4

Please sign in to comment.