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
Merged
+244
−30
Merged
Add bindings for calc() #12465
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8b76bd7
Sync stylo bindings
Manishearth b52b78c
Regen bindings for Calc
Manishearth 67bcb96
Add glue for calc values
Manishearth 8fddc46
Allow calc() in GeckoStyleCoordConvertible
Manishearth 704d7a0
Handle Calc refcounting
Manishearth f51b115
Address review comments
Manishearth File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Allow calc() in GeckoStyleCoordConvertible
- Loading branch information
Manishearth
committed
Jul 19, 2016
Manishearth
Manish Goregaokar
commit 8fddc460201b7c1d00358f618a07736c7a1be926
Verified
This commit was signed with a verified signature.
GPG key ID: 3BBF4D3E2EF79F98
Learn about signing commits
| @@ -56,6 +56,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_auto(&mut self) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
|
||
| self.mUnit = nsStyleUnit::eStyleUnit_Auto; | ||
| unsafe { *self.mValue.mInt.as_mut() = 0; } | ||
| } | ||
| @@ -66,6 +67,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_normal(&mut self) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Normal; | ||
| unsafe { *self.mValue.mInt.as_mut() = 0; } | ||
| } | ||
| @@ -76,6 +78,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_coord(&mut self, val: Au) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Coord; | ||
| unsafe { *self.mValue.mInt.as_mut() = val.0; } | ||
| } | ||
| @@ -91,6 +94,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_int(&mut self, val: i32) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Integer; | ||
| unsafe { *self.mValue.mInt.as_mut() = val; } | ||
| } | ||
| @@ -106,6 +110,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_enum(&mut self, val: i32) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Enumerated; | ||
| unsafe { *self.mValue.mInt.as_mut() = val; } | ||
| } | ||
| @@ -121,6 +126,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_percent(&mut self, val: f32) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Percent; | ||
| unsafe { *self.mValue.mFloat.as_mut() = val; } | ||
| } | ||
| @@ -136,6 +142,7 @@ impl StyleCoordHelpers for nsStyleCoord { | ||
|
|
||
| #[inline] | ||
| fn set_factor(&mut self, val: f32) { | ||
| unsafe { self.mValue.reset(&mut self.mUnit)}; | ||
| self.mUnit = nsStyleUnit::eStyleUnit_Factor; | ||
| unsafe { *self.mValue.mFloat.as_mut() = val; } | ||
| } | ||
| @@ -157,6 +164,7 @@ pub trait GeckoStyleCoordConvertible : Sized { | ||
|
|
||
| impl GeckoStyleCoordConvertible for LengthOrPercentage { | ||
| fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { | ||
heycam
Member
|
||
| unsafe { union.reset(unit) }; | ||
| match *self { | ||
| LengthOrPercentage::Length(au) => { | ||
| *unit = nsStyleUnit::eStyleUnit_Coord; | ||
| @@ -166,7 +174,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentage { | ||
| *unit = nsStyleUnit::eStyleUnit_Percent; | ||
| unsafe { *union.mFloat.as_mut() = p; } | ||
| }, | ||
| LengthOrPercentage::Calc(_) => unimplemented!(), | ||
| LengthOrPercentage::Calc(calc) => unsafe {union.set_calc_value(unit, calc.into()) }, | ||
|
||
| }; | ||
| } | ||
|
|
||
| @@ -177,14 +185,15 @@ impl GeckoStyleCoordConvertible for LengthOrPercentage { | ||
| nsStyleUnit::eStyleUnit_Percent | ||
| => Some(LengthOrPercentage::Percentage(unsafe { *union.mFloat.as_ref() })), | ||
| nsStyleUnit::eStyleUnit_Calc | ||
| => unimplemented!(), | ||
| => Some(LengthOrPercentage::Calc(unsafe { union.get_calc().into()})), | ||
|
||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { | ||
| fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { | ||
| unsafe { union.reset(unit) }; | ||
| match *self { | ||
| LengthOrPercentageOrAuto::Length(au) => { | ||
| *unit = nsStyleUnit::eStyleUnit_Coord; | ||
| @@ -198,7 +207,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { | ||
| *unit = nsStyleUnit::eStyleUnit_Auto; | ||
| unsafe { *union.mInt.as_mut() = 0; } | ||
| }, | ||
| LengthOrPercentageOrAuto::Calc(_) => unimplemented!(), | ||
| LengthOrPercentageOrAuto::Calc(calc) => unsafe {union.set_calc_value(unit, calc.into()) }, | ||
| }; | ||
| } | ||
|
|
||
| @@ -211,14 +220,15 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrAuto { | ||
| nsStyleUnit::eStyleUnit_Percent | ||
| => Some(LengthOrPercentageOrAuto::Percentage(unsafe { *union.mFloat.as_ref() })), | ||
| nsStyleUnit::eStyleUnit_Calc | ||
| => unimplemented!(), | ||
| => Some(LengthOrPercentageOrAuto::Calc(unsafe { union.get_calc().into()})), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { | ||
| fn to_gecko_style_coord(&self, unit: &mut nsStyleUnit, union: &mut nsStyleUnion) { | ||
| unsafe { union.reset(unit) }; | ||
| match *self { | ||
| LengthOrPercentageOrNone::Length(au) => { | ||
| *unit = nsStyleUnit::eStyleUnit_Coord; | ||
| @@ -232,7 +242,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { | ||
| *unit = nsStyleUnit::eStyleUnit_None; | ||
| unsafe { *union.mInt.as_mut() = 0; } | ||
| }, | ||
| LengthOrPercentageOrNone::Calc(_) => unimplemented!(), | ||
| LengthOrPercentageOrNone::Calc(calc) => unsafe { union.set_calc_value(unit, calc.into()) }, | ||
| }; | ||
| } | ||
|
|
||
| @@ -245,7 +255,7 @@ impl GeckoStyleCoordConvertible for LengthOrPercentageOrNone { | ||
| nsStyleUnit::eStyleUnit_Percent | ||
| => Some(LengthOrPercentageOrNone::Percentage(unsafe { *union.mFloat.as_ref() })), | ||
| nsStyleUnit::eStyleUnit_Calc | ||
| => unimplemented!(), | ||
| => Some(LengthOrPercentageOrNone::Calc(unsafe { union.get_calc().into()})), | ||
| _ => None, | ||
| } | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Nit: space before
}, and in all the other methods in this patch.