diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index d4dfa3bc853..074e4e08579 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -661,9 +661,10 @@ fn static_assert() { use gecko_bindings::structs::nsStyleUnit; // z-index is never a calc(). If it were, we'd be leaking here, so // assert that it isn't. - debug_assert!(self.gecko.mZIndex.mUnit != nsStyleUnit::eStyleUnit_Calc); - self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit; - self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue; + debug_assert!(self.gecko.mZIndex.unit() != nsStyleUnit::eStyleUnit_Calc); + unsafe { + self.gecko.mZIndex.copy_from_unchecked(&other.gecko.mZIndex); + } } pub fn clone_z_index(&self) -> longhands::z_index::computed_value::T { diff --git a/ports/geckolib/gecko_bindings/structs_debug.rs b/ports/geckolib/gecko_bindings/structs_debug.rs index 1ad3478eac0..1ac5b06026e 100644 --- a/ports/geckolib/gecko_bindings/structs_debug.rs +++ b/ports/geckolib/gecko_bindings/structs_debug.rs @@ -5150,11 +5150,24 @@ pub type nsStyleUnion = nsStyleCoord_h_unnamed_18; * the unit is a must before asking for the value in any particular * form. */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleCoord { - pub mUnit: nsStyleUnit, - pub mValue: nsStyleUnion, + mUnit: nsStyleUnit, + mValue: nsStyleUnion, +} +impl nsStyleCoord { + #[inline] + pub unsafe fn get_mUnit(&self) -> &nsStyleUnit { &self.mUnit } + pub unsafe fn get_mUnit_mut(&mut self) -> &mut nsStyleUnit { + &mut self.mUnit + } + #[inline] + pub unsafe fn get_mValue(&self) -> &nsStyleUnion { &self.mValue } + pub unsafe fn get_mValue_mut(&mut self) -> &mut nsStyleUnion { + &mut self.mValue + } } #[repr(C)] #[derive(Debug, Copy)] @@ -5195,11 +5208,26 @@ fn bindgen_test_layout_nsStyleCoord() { * This is commonly used to hold the widths of the borders, margins, * or paddings of a box. */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleSides { - pub mUnits: [nsStyleUnit; 4usize], - pub mValues: [nsStyleUnion; 4usize], + mUnits: [nsStyleUnit; 4usize], + mValues: [nsStyleUnion; 4usize], +} +impl nsStyleSides { + #[inline] + pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 4usize] { &self.mUnits } + pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 4usize] { + &mut self.mUnits + } + #[inline] + pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 4usize] { + &self.mValues + } + pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 4usize] { + &mut self.mValues + } } #[test] fn bindgen_test_layout_nsStyleSides() { @@ -5211,11 +5239,26 @@ fn bindgen_test_layout_nsStyleSides() { * nsStyleCoord pairs. This is used to hold the dimensions of the * corners of a box (for, e.g., border-radius and outline-radius). */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleCorners { - pub mUnits: [nsStyleUnit; 8usize], - pub mValues: [nsStyleUnion; 8usize], + mUnits: [nsStyleUnit; 8usize], + mValues: [nsStyleUnion; 8usize], +} +impl nsStyleCorners { + #[inline] + pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 8usize] { &self.mUnits } + pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 8usize] { + &mut self.mUnits + } + #[inline] + pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 8usize] { + &self.mValues + } + pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 8usize] { + &mut self.mValues + } } #[test] fn bindgen_test_layout_nsStyleCorners() { diff --git a/ports/geckolib/gecko_bindings/structs_release.rs b/ports/geckolib/gecko_bindings/structs_release.rs index 8ce95c33632..418b428cc16 100644 --- a/ports/geckolib/gecko_bindings/structs_release.rs +++ b/ports/geckolib/gecko_bindings/structs_release.rs @@ -5129,11 +5129,24 @@ pub type nsStyleUnion = nsStyleCoord_h_unnamed_18; * the unit is a must before asking for the value in any particular * form. */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleCoord { - pub mUnit: nsStyleUnit, - pub mValue: nsStyleUnion, + mUnit: nsStyleUnit, + mValue: nsStyleUnion, +} +impl nsStyleCoord { + #[inline] + pub unsafe fn get_mUnit(&self) -> &nsStyleUnit { &self.mUnit } + pub unsafe fn get_mUnit_mut(&mut self) -> &mut nsStyleUnit { + &mut self.mUnit + } + #[inline] + pub unsafe fn get_mValue(&self) -> &nsStyleUnion { &self.mValue } + pub unsafe fn get_mValue_mut(&mut self) -> &mut nsStyleUnion { + &mut self.mValue + } } #[repr(C)] #[derive(Debug, Copy)] @@ -5174,11 +5187,26 @@ fn bindgen_test_layout_nsStyleCoord() { * This is commonly used to hold the widths of the borders, margins, * or paddings of a box. */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleSides { - pub mUnits: [nsStyleUnit; 4usize], - pub mValues: [nsStyleUnion; 4usize], + mUnits: [nsStyleUnit; 4usize], + mValues: [nsStyleUnion; 4usize], +} +impl nsStyleSides { + #[inline] + pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 4usize] { &self.mUnits } + pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 4usize] { + &mut self.mUnits + } + #[inline] + pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 4usize] { + &self.mValues + } + pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 4usize] { + &mut self.mValues + } } #[test] fn bindgen_test_layout_nsStyleSides() { @@ -5190,11 +5218,26 @@ fn bindgen_test_layout_nsStyleSides() { * nsStyleCoord pairs. This is used to hold the dimensions of the * corners of a box (for, e.g., border-radius and outline-radius). */ + /**
*/ #[repr(C)] #[derive(Debug)] pub struct nsStyleCorners { - pub mUnits: [nsStyleUnit; 8usize], - pub mValues: [nsStyleUnion; 8usize], + mUnits: [nsStyleUnit; 8usize], + mValues: [nsStyleUnion; 8usize], +} +impl nsStyleCorners { + #[inline] + pub unsafe fn get_mUnits(&self) -> &[nsStyleUnit; 8usize] { &self.mUnits } + pub unsafe fn get_mUnits_mut(&mut self) -> &mut [nsStyleUnit; 8usize] { + &mut self.mUnits + } + #[inline] + pub unsafe fn get_mValues(&self) -> &[nsStyleUnion; 8usize] { + &self.mValues + } + pub unsafe fn get_mValues_mut(&mut self) -> &mut [nsStyleUnion; 8usize] { + &mut self.mValues + } } #[test] fn bindgen_test_layout_nsStyleCorners() { diff --git a/ports/geckolib/gecko_bindings/sugar/ns_style_coord.rs b/ports/geckolib/gecko_bindings/sugar/ns_style_coord.rs index 33dff1a705d..a13f08ea37b 100644 --- a/ports/geckolib/gecko_bindings/sugar/ns_style_coord.rs +++ b/ports/geckolib/gecko_bindings/sugar/ns_style_coord.rs @@ -3,24 +3,29 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread}; -use std::mem::transmute; use structs::{nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord, nsStyleSides, nsStyleCorners}; use structs::{nsStyleCoord_CalcValue, nscoord}; impl CoordData for nsStyleCoord { #[inline] fn unit(&self) -> nsStyleUnit { - self.mUnit + unsafe { + *self.get_mUnit() + } } #[inline] fn union(&self) -> nsStyleUnion { - self.mValue + unsafe { + *self.get_mValue() + } } } impl CoordDataMut for nsStyleCoord { unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) { - (&mut self.mUnit, &mut self.mValue) + let unit = self.get_mUnit_mut() as *mut _; + let value = self.get_mValue_mut() as *mut _; + (&mut *unit, &mut *value) } } @@ -53,26 +58,36 @@ pub struct SidesDataMut<'a> { impl<'a> CoordData for SidesData<'a> { #[inline] fn unit(&self) -> nsStyleUnit { - self.sides.mUnits[self.index] + unsafe { + self.sides.get_mUnits()[self.index] + } } #[inline] fn union(&self) -> nsStyleUnion { - self.sides.mValues[self.index] + unsafe { + self.sides.get_mValues()[self.index] + } } } impl<'a> CoordData for SidesDataMut<'a> { #[inline] fn unit(&self) -> nsStyleUnit { - self.sides.mUnits[self.index] + unsafe { + self.sides.get_mUnits()[self.index] + } } #[inline] fn union(&self) -> nsStyleUnion { - self.sides.mValues[self.index] + unsafe { + self.sides.get_mValues()[self.index] + } } } impl<'a> CoordDataMut for SidesDataMut<'a> { unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) { - (&mut self.sides.mUnits[self.index], &mut self.sides.mValues[self.index]) + let unit = &mut self.sides.get_mUnits_mut()[self.index] as *mut _; + let value = &mut self.sides.get_mValues_mut()[self.index] as *mut _; + (&mut *unit, &mut *value) } } @@ -104,23 +119,33 @@ pub struct CornersDataMut<'a> { impl<'a> CoordData for CornersData<'a> { fn unit(&self) -> nsStyleUnit { - self.corners.mUnits[self.index] + unsafe { + self.corners.get_mUnits()[self.index] + } } fn union(&self) -> nsStyleUnion { - self.corners.mValues[self.index] + unsafe { + self.corners.get_mValues()[self.index] + } } } impl<'a> CoordData for CornersDataMut<'a> { fn unit(&self) -> nsStyleUnit { - self.corners.mUnits[self.index] + unsafe { + self.corners.get_mUnits()[self.index] + } } fn union(&self) -> nsStyleUnion { - self.corners.mValues[self.index] + unsafe { + self.corners.get_mValues()[self.index] + } } } impl<'a> CoordDataMut for CornersDataMut<'a> { unsafe fn values_mut(&mut self) -> (&mut nsStyleUnit, &mut nsStyleUnion) { - (&mut self.corners.mUnits[self.index], &mut self.corners.mValues[self.index]) + let unit = &mut self.corners.get_mUnits_mut()[self.index] as *mut _; + let value = &mut self.corners.get_mValues_mut()[self.index] as *mut _; + (&mut *unit, &mut *value) } } @@ -179,6 +204,13 @@ pub trait CoordDataMut : CoordData { } } + #[inline] + unsafe fn copy_from_unchecked(&mut self, other: &T) { + let (unit, union) = self.values_mut(); + *unit = other.unit(); + *union = other.union(); + } + #[inline(always)] fn set_value(&mut self, value: CoordDataValue) { use self::CoordDataValue::*; @@ -254,7 +286,7 @@ pub trait CoordDataMut : CoordData { #[inline] unsafe fn as_calc_mut(&mut self) -> &mut nsStyleCoord_Calc { debug_assert!(self.unit() == nsStyleUnit::eStyleUnit_Calc); - transmute(*self.union().mPointer.as_mut() as *mut nsStyleCoord_Calc) + &mut *(*self.union().mPointer.as_mut() as *mut nsStyleCoord_Calc) } #[inline] @@ -328,6 +360,6 @@ pub trait CoordData { #[inline] unsafe fn as_calc(&self) -> &nsStyleCoord_Calc { debug_assert!(self.unit() == nsStyleUnit::eStyleUnit_Calc); - transmute(*self.union().mPointer.as_ref() as *const nsStyleCoord_Calc) + &*(*self.union().mPointer.as_ref() as *const nsStyleCoord_Calc) } }