From 3ed525f6c998977853fb266747a99d9c38aa907e Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Tue, 18 Dec 2018 18:47:35 +0000 Subject: [PATCH] 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 --- components/style/cbindgen.toml | 1 + components/style/gecko/values.rs | 33 ++-------------------- components/style/values/computed/length.rs | 2 ++ 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 6005126fb27..27ad7bc80a1 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -50,6 +50,7 @@ include = [ "ComputedTimingFunction", "Display", "DisplayMode", + "ExtremumLength", "FillRule", "FontDisplay", "FontFaceSourceListComponent", diff --git a/components/style/gecko/values.rs b/components/style/gecko/values.rs index 59ccd0afeca..8006d50925f 100644 --- a/components/style/gecko/values.rs +++ b/components/style/gecko/values.rs @@ -362,40 +362,13 @@ impl GeckoStyleCoordConvertible for Normal { impl GeckoStyleCoordConvertible for ExtremumLength { fn to_gecko_style_coord(&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(coord: &T) -> Option { - 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, } } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 96886e9096a..7592c3a2cae 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -975,6 +975,7 @@ pub type NonNegativeLengthOrPercentageOrNormal = Either