From cb2533d61ae62b1032f41cb42894e8a23649d82c Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Wed, 31 Oct 2018 06:20:07 +0000 Subject: [PATCH] style: Use alias for StyleDisplay and StyleDisplayMode. Map these two types to their original rust type in rust-bindgen. Differential Revision: https://phabricator.services.mozilla.com/D10141 --- components/style/gecko/media_features.rs | 16 +++++----------- components/style/properties/gecko.mako.rs | 11 ++++------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index 9e84a7722b10..e6f08c60f0cb 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -179,7 +179,7 @@ fn eval_device_orientation(device: &Device, value: Option) -> bool } /// Values for the display-mode media feature. -#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)] +#[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)] #[repr(u8)] #[allow(missing_docs)] pub enum DisplayMode { @@ -191,16 +191,10 @@ pub enum DisplayMode { /// https://w3c.github.io/manifest/#the-display-mode-media-feature fn eval_display_mode(device: &Device, query_value: Option) -> bool { - let query_value = match query_value { - Some(v) => v, - None => return true, - }; - - let gecko_display_mode = - unsafe { bindings::Gecko_MediaFeatures_GetDisplayMode(device.document()) }; - - // NOTE: cbindgen guarantees the same representation. - gecko_display_mode as u8 == query_value as u8 + match query_value { + Some(v) => v == unsafe { bindings::Gecko_MediaFeatures_GetDisplayMode(device.document()) }, + None => true, + } } /// https://drafts.csswg.org/mediaqueries-4/#grid diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 47143343824d..b9eb68307771 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -3031,9 +3031,8 @@ fn static_assert() { <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> #[inline] pub fn set_display(&mut self, v: longhands::display::computed_value::T) { - // unsafe: cbindgen ensures the representation is the same. - self.gecko.mDisplay = unsafe { transmute(v) }; - self.gecko.mOriginalDisplay = unsafe { transmute(v) }; + self.gecko.mDisplay = v; + self.gecko.mOriginalDisplay = v; } #[inline] @@ -3053,14 +3052,12 @@ fn static_assert() { v: longhands::display::computed_value::T, _is_item_or_root: bool ) { - // unsafe: cbindgen ensures the representation is the same. - self.gecko.mDisplay = unsafe { transmute(v) }; + self.gecko.mDisplay = v; } #[inline] pub fn clone_display(&self) -> longhands::display::computed_value::T { - // unsafe: cbindgen ensures the representation is the same. - unsafe { transmute(self.gecko.mDisplay) } + self.gecko.mDisplay } ${impl_simple('_moz_appearance', 'mAppearance')}