diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index 5ef6f45d568..75ef9c6215c 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -29,8 +29,8 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; use style::properties::longhands; use style::properties::make_cascade_vec; use style::properties::style_struct_traits::*; -use values::{ToGeckoStyleCoord, convert_rgba_to_nscolor, convert_nscolor_to_rgba}; -use values::round_border_to_device_pixels; +use values::{StyleCoordHelpers, ToGeckoStyleCoord, convert_nscolor_to_rgba}; +use values::{convert_rgba_to_nscolor, round_border_to_device_pixels}; #[derive(Clone)] pub struct GeckoComputedValues { @@ -552,17 +552,10 @@ fn static_assert() { % endfor fn set_z_index(&mut self, v: longhands::z_index::computed_value::T) { - use gecko_bindings::structs::nsStyleUnit; use style::properties::longhands::z_index::computed_value::T; match v { - T::Auto => { - self.gecko.mZIndex.mUnit = nsStyleUnit::eStyleUnit_Auto; - unsafe { *self.gecko.mZIndex.mValue.mInt.as_mut() = 0; } - } - T::Number(n) => { - self.gecko.mZIndex.mUnit = nsStyleUnit::eStyleUnit_Integer; - unsafe { *self.gecko.mZIndex.mValue.mInt.as_mut() = n; } - } + T::Auto => self.gecko.mZIndex.set_auto(), + T::Number(n) => self.gecko.mZIndex.set_int(n), } } fn copy_z_index_from(&mut self, other: &Self) { diff --git a/ports/geckolib/values.rs b/ports/geckolib/values.rs index 069fb9bc9b6..d9e6da0fd83 100644 --- a/ports/geckolib/values.rs +++ b/ports/geckolib/values.rs @@ -4,10 +4,44 @@ use app_units::Au; use cssparser::RGBA; -use gecko_bindings::structs::{nsStyleUnion, nsStyleUnit}; +use gecko_bindings::structs::{nsStyleCoord, nsStyleUnion, nsStyleUnit}; use std::cmp::max; use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto, LengthOrPercentageOrNone}; +pub trait StyleCoordHelpers { + fn set(&mut self, val: T); + fn set_auto(&mut self); + fn set_coord(&mut self, val: Au); + fn set_int(&mut self, val: i32); + fn set_percent(&mut self, val: f32); +} + +impl StyleCoordHelpers for nsStyleCoord { + fn set(&mut self, val: T) { + val.to_gecko_style_coord(&mut self.mUnit, &mut self.mValue); + } + + fn set_auto(&mut self) { + self.mUnit = nsStyleUnit::eStyleUnit_Auto; + unsafe { *self.mValue.mInt.as_mut() = 0; } + } + + fn set_coord(&mut self, val: Au) { + self.mUnit = nsStyleUnit::eStyleUnit_Coord; + unsafe { *self.mValue.mInt.as_mut() = val.0; } + } + + fn set_percent(&mut self, val: f32) { + self.mUnit = nsStyleUnit::eStyleUnit_Percent; + unsafe { *self.mValue.mFloat.as_mut() = val; } + } + + fn set_int(&mut self, val: i32) { + self.mUnit = nsStyleUnit::eStyleUnit_Integer; + unsafe { *self.mValue.mInt.as_mut() = val; } + } +} + pub trait ToGeckoStyleCoord { fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion); }