New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bindings for calc() #12465
Add bindings for calc() #12465
Changes from 1 commit
8b76bd7
b52b78c
67bcb96
8fddc46
704d7a0
f51b115
File filter...
Jump to…
Handle Calc refcounting
- Loading branch information
Verified
| @@ -2,8 +2,9 @@ | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
|
||
| use structs::{nsStyleCoord_CalcValue, nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion}; | ||
| use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue}; | ||
| use bindings::{Gecko_ResetStyleCoord, Gecko_SetStyleCoordCalcValue, Gecko_AddRefCalcArbitraryThread}; | ||
| use std::mem::transmute; | ||
| use structs::{nsStyleCoord_CalcValue, nsStyleCoord_Calc, nsStyleUnit, nsStyleUnion, nsStyleCoord}; | ||
|
|
||
| // Functions here are unsafe because it is possible to use the wrong nsStyleUnit | ||
|
||
| // FIXME we should be pairing up nsStyleUnion and nsStyleUnit somehow | ||
| @@ -29,6 +30,25 @@ impl nsStyleUnion { | ||
| } | ||
|
|
||
| pub unsafe fn get_calc(&self) -> nsStyleCoord_CalcValue { | ||
| (*(*self.mPointer.as_ref() as *const nsStyleCoord_Calc))._base | ||
| (*self.as_calc())._base | ||
| } | ||
|
|
||
| pub unsafe fn addref_opt(&mut self, unit: &nsStyleUnit) { | ||
bholley
Contributor
|
||
| if *unit == nsStyleUnit::eStyleUnit_Calc { | ||
| Gecko_AddRefCalcArbitraryThread(self.as_calc_mut()); | ||
| } | ||
| } | ||
|
|
||
| pub unsafe fn as_calc_mut(&mut self) -> &mut nsStyleCoord_Calc { | ||
heycam
Member
|
||
| transmute(*self.mPointer.as_mut() as *mut nsStyleCoord_Calc) | ||
| } | ||
| pub unsafe fn as_calc(&self) -> &nsStyleCoord_Calc { | ||
| transmute(*self.mPointer.as_ref() as *const nsStyleCoord_Calc) | ||
| } | ||
| } | ||
|
|
||
| impl nsStyleCoord { | ||
| pub unsafe fn addref_opt(&mut self) { | ||
| self.mValue.addref_opt(&self.mUnit); | ||
| } | ||
| } | ||
| @@ -35,7 +35,7 @@ use style::properties::{CascadePropertyFn, ServoComputedValues, ComputedValues}; | ||
| use style::properties::longhands; | ||
| use style::properties::style_struct_traits::*; | ||
| use values::{StyleCoordHelpers, GeckoStyleCoordConvertible, convert_nscolor_to_rgba}; | ||
| use values::{convert_rgba_to_nscolor, debug_assert_unit_is_safe_to_copy}; | ||
| use values::convert_rgba_to_nscolor; | ||
| use values::round_border_to_device_pixels; | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| @@ -317,9 +317,10 @@ def set_gecko_property(ffi_name, expr): | ||
| &mut self.gecko.${union_ffi_name}); | ||
| } | ||
| fn copy_${ident}_from(&mut self, other: &Self) { | ||
| debug_assert_unit_is_safe_to_copy(self.gecko.${unit_ffi_name}); | ||
| unsafe { self.gecko.${union_ffi_name}.reset(&mut self.gecko.${unit_ffi_name}) }; | ||
| self.gecko.${unit_ffi_name} = other.gecko.${unit_ffi_name}; | ||
| self.gecko.${union_ffi_name} = other.gecko.${union_ffi_name}; | ||
| unsafe { self.gecko.${union_ffi_name}.addref_opt(&self.gecko.${unit_ffi_name}) }; | ||
heycam
Member
|
||
| } | ||
| % if need_clone: | ||
| fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { | ||
| @@ -347,12 +348,14 @@ ${impl_split_style_coord(ident, | ||
| &mut self.gecko.${y_union_ffi_name}); | ||
| } | ||
| fn copy_${ident}_from(&mut self, other: &Self) { | ||
| debug_assert_unit_is_safe_to_copy(self.gecko.${x_unit_ffi_name}); | ||
| debug_assert_unit_is_safe_to_copy(self.gecko.${y_unit_ffi_name}); | ||
| unsafe { self.gecko.${x_union_ffi_name}.reset(&mut self.gecko.${x_unit_ffi_name}) }; | ||
| unsafe { self.gecko.${y_union_ffi_name}.reset(&mut self.gecko.${y_unit_ffi_name}) }; | ||
| self.gecko.${x_unit_ffi_name} = other.gecko.${x_unit_ffi_name}; | ||
| self.gecko.${x_union_ffi_name} = other.gecko.${x_union_ffi_name}; | ||
| self.gecko.${y_unit_ffi_name} = other.gecko.${y_unit_ffi_name}; | ||
| self.gecko.${y_union_ffi_name} = other.gecko.${y_union_ffi_name}; | ||
| unsafe { self.gecko.${x_union_ffi_name}.addref_opt(&self.gecko.${x_unit_ffi_name}) }; | ||
| unsafe { self.gecko.${y_union_ffi_name}.addref_opt(&self.gecko.${y_unit_ffi_name}) }; | ||
heycam
Member
|
||
| } | ||
| % if need_clone: | ||
| fn clone_${ident}(&self) -> longhands::${ident}::computed_value::T { | ||
| @@ -628,9 +631,10 @@ fn static_assert() { | ||
| } | ||
|
|
||
| fn copy_z_index_from(&mut self, other: &Self) { | ||
| debug_assert_unit_is_safe_to_copy(self.gecko.mZIndex.mUnit); | ||
| unsafe { self.gecko.mZIndex.mValue.reset(&mut self.gecko.mZIndex.mUnit) }; | ||
| self.gecko.mZIndex.mUnit = other.gecko.mZIndex.mUnit; | ||
| self.gecko.mZIndex.mValue = other.gecko.mZIndex.mValue; | ||
| unsafe { self.gecko.mZIndex.mValue.addref_opt(&self.gecko.mZIndex.mUnit) }; | ||
heycam
Member
|
||
| } | ||
|
|
||
| fn clone_z_index(&self) -> longhands::z_index::computed_value::T { | ||
I'd like to understand the difference between
unsafeon the function interface vs wrapping the body of the function inunsafehere. Is it because we have a requirement that is not expressible in the type system, which must be adhered to otherwise we will have a memory safety issue, namely that you must pass in a reference to thensStyleUnitassociated with thensStyleUnionand not just any one you have access to? And to signal to users ofnsStyleUnionthat we have other requirements the compiler won't catch, we useunsafehere?