mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Add some safe setters for nsStyleCoord
This commit is contained in:
parent
c921fa6d99
commit
f998a6113e
2 changed files with 39 additions and 12 deletions
|
@ -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) {
|
||||
|
|
|
@ -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<T: ToGeckoStyleCoord>(&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<T: ToGeckoStyleCoord>(&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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue