Skip to content
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
merged 6 commits into from Jul 20, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Allow calc() in GeckoStyleCoordConvertible

  • Loading branch information
Manishearth committed Jul 19, 2016
commit 8fddc460201b7c1d00358f618a07736c7a1be926
@@ -56,6 +56,7 @@ impl StyleCoordHelpers for nsStyleCoord {

#[inline]
fn set_auto(&mut self) {
unsafe { self.mValue.reset(&mut self.mUnit)};

This comment has been minimized.

@heycam

heycam Jul 19, 2016

Member

Nit: space before }, and in all the other methods in this patch.

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) {

This comment has been minimized.

@heycam

heycam Jul 19, 2016

Member

If the functions on nsStyleUnion are unsafe because they require particular nsStyleUnit references to be passed in, shouldn't that also mean to_gecko_style_coord and from_gecko_style_coord are unsafe too? Or do I misunderstand the use of unsafe on the nsStyleUnion functions.

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()) },

This comment has been minimized.

@heycam

heycam Jul 19, 2016

Member

Nit: space after {.

};
}

@@ -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()})),

This comment has been minimized.

@heycam

heycam Jul 19, 2016

Member

Nit: space before }.

_ => 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.
You can’t perform that action at this time.