style: Use cbindgen for ExtremumLength.

ExtremumLength is the keyword type for css sizing properties, so we
could use cbindgen.

In Gecko, we use nsStyleCoord to store the sizing properties, and use
integer values to check the enum values, so I keep the macros in nsStyleConsts.
Even though we need to convert the enum type into integer, we still have
benefits to reduce the complexity of converting Rust into C++, and leave
the simplified mappings in C++ for better readability.

Differential Revision: https://phabricator.services.mozilla.com/D7535
This commit is contained in:
Boris Chiou 2018-12-18 18:47:35 +00:00 committed by Emilio Cobos Álvarez
parent ca1ad003bd
commit 3ed525f6c9
3 changed files with 6 additions and 30 deletions

View file

@ -362,40 +362,13 @@ impl GeckoStyleCoordConvertible for Normal {
impl GeckoStyleCoordConvertible for ExtremumLength {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
use crate::gecko_bindings::structs::{
NS_STYLE_WIDTH_AVAILABLE, NS_STYLE_WIDTH_FIT_CONTENT,
};
use crate::gecko_bindings::structs::{
NS_STYLE_WIDTH_MAX_CONTENT, NS_STYLE_WIDTH_MIN_CONTENT,
};
coord.set_value(CoordDataValue::Enumerated(match *self {
ExtremumLength::MozMaxContent => NS_STYLE_WIDTH_MAX_CONTENT,
ExtremumLength::MozMinContent => NS_STYLE_WIDTH_MIN_CONTENT,
ExtremumLength::MozFitContent => NS_STYLE_WIDTH_FIT_CONTENT,
ExtremumLength::MozAvailable => NS_STYLE_WIDTH_AVAILABLE,
}))
coord.set_value(CoordDataValue::Enumerated(*self as u32));
}
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
use crate::gecko_bindings::structs::{
NS_STYLE_WIDTH_AVAILABLE, NS_STYLE_WIDTH_FIT_CONTENT,
};
use crate::gecko_bindings::structs::{
NS_STYLE_WIDTH_MAX_CONTENT, NS_STYLE_WIDTH_MIN_CONTENT,
};
use num_traits::FromPrimitive;
match coord.as_value() {
CoordDataValue::Enumerated(NS_STYLE_WIDTH_MAX_CONTENT) => {
Some(ExtremumLength::MozMaxContent)
},
CoordDataValue::Enumerated(NS_STYLE_WIDTH_MIN_CONTENT) => {
Some(ExtremumLength::MozMinContent)
},
CoordDataValue::Enumerated(NS_STYLE_WIDTH_FIT_CONTENT) => {
Some(ExtremumLength::MozFitContent)
},
CoordDataValue::Enumerated(NS_STYLE_WIDTH_AVAILABLE) => {
Some(ExtremumLength::MozAvailable)
},
CoordDataValue::Enumerated(v) => ExtremumLength::from_u32(v),
_ => None,
}
}