From e66e612452d48f3edafcaf7855f2dabb8fb152c7 Mon Sep 17 00:00:00 2001 From: violet Date: Fri, 24 May 2019 04:48:46 +0000 Subject: [PATCH] style: Use cbindgen for text-overflow. Differential Revision: https://phabricator.services.mozilla.com/D32285 --- components/style/properties/gecko.mako.rs | 78 +---------------------- components/style/values/computed/text.rs | 1 + components/style/values/specified/text.rs | 6 +- 3 files changed, 6 insertions(+), 79 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 2c83e8cf656..dd5bcf2febf 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -3342,83 +3342,7 @@ fn static_assert() { -<%self:impl_trait style_struct_name="Text" - skip_longhands="text-overflow initial-letter"> - - fn clear_overflow_sides_if_string(&mut self) { - use crate::gecko_bindings::structs::nsStyleTextOverflowSide; - fn clear_if_string(side: &mut nsStyleTextOverflowSide) { - if side.mType == structs::NS_STYLE_TEXT_OVERFLOW_STRING as u8 { - side.mString.truncate(); - side.mType = structs::NS_STYLE_TEXT_OVERFLOW_CLIP as u8; - } - } - clear_if_string(&mut self.gecko.mTextOverflow.mLeft); - clear_if_string(&mut self.gecko.mTextOverflow.mRight); - } - - pub fn set_text_overflow(&mut self, v: longhands::text_overflow::computed_value::T) { - use crate::gecko_bindings::structs::nsStyleTextOverflowSide; - use crate::values::specified::text::TextOverflowSide; - - fn set(side: &mut nsStyleTextOverflowSide, value: &TextOverflowSide) { - let ty = match *value { - TextOverflowSide::Clip => structs::NS_STYLE_TEXT_OVERFLOW_CLIP, - TextOverflowSide::Ellipsis => structs::NS_STYLE_TEXT_OVERFLOW_ELLIPSIS, - TextOverflowSide::String(ref s) => { - side.mString.assign_str(s); - structs::NS_STYLE_TEXT_OVERFLOW_STRING - } - }; - side.mType = ty as u8; - } - - self.clear_overflow_sides_if_string(); - self.gecko.mTextOverflow.mLogicalDirections = v.sides_are_logical; - - set(&mut self.gecko.mTextOverflow.mLeft, &v.first); - set(&mut self.gecko.mTextOverflow.mRight, &v.second); - } - - pub fn copy_text_overflow_from(&mut self, other: &Self) { - use crate::gecko_bindings::structs::nsStyleTextOverflowSide; - fn set(side: &mut nsStyleTextOverflowSide, other: &nsStyleTextOverflowSide) { - if other.mType == structs::NS_STYLE_TEXT_OVERFLOW_STRING as u8 { - side.mString.assign(&*other.mString) - } - side.mType = other.mType - } - self.clear_overflow_sides_if_string(); - set(&mut self.gecko.mTextOverflow.mLeft, &other.gecko.mTextOverflow.mLeft); - set(&mut self.gecko.mTextOverflow.mRight, &other.gecko.mTextOverflow.mRight); - self.gecko.mTextOverflow.mLogicalDirections = other.gecko.mTextOverflow.mLogicalDirections; - } - - pub fn reset_text_overflow(&mut self, other: &Self) { - self.copy_text_overflow_from(other) - } - - pub fn clone_text_overflow(&self) -> longhands::text_overflow::computed_value::T { - use crate::gecko_bindings::structs::nsStyleTextOverflowSide; - use crate::values::specified::text::TextOverflowSide; - - fn to_servo(side: &nsStyleTextOverflowSide) -> TextOverflowSide { - match side.mType as u32 { - structs::NS_STYLE_TEXT_OVERFLOW_CLIP => TextOverflowSide::Clip, - structs::NS_STYLE_TEXT_OVERFLOW_ELLIPSIS => TextOverflowSide::Ellipsis, - structs::NS_STYLE_TEXT_OVERFLOW_STRING => - TextOverflowSide::String(side.mString.to_string().into_boxed_str()), - _ => panic!("Found unexpected value in style struct for text_overflow property"), - } - } - - longhands::text_overflow::computed_value::T { - first: to_servo(&self.gecko.mTextOverflow.mLeft), - second: to_servo(&self.gecko.mTextOverflow.mRight), - sides_are_logical: self.gecko.mTextOverflow.mLogicalDirections - } - } - +<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter"> pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) { use crate::values::generics::text::InitialLetter; match v { diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 7395cf71bb2..bc4086a2b9c 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -105,6 +105,7 @@ impl ToComputedValue for specified::WordSpacing { pub type LineHeight = GenericLineHeight; #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue)] +#[repr(C)] /// text-overflow. /// When the specified value only has one side, that's the "second" /// side, and the sides are logical, so "second" means "end". The diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 1ab805cdcfb..165462c8175 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -134,14 +134,16 @@ impl ToComputedValue for LineHeight { } /// A generic value for the `text-overflow` property. +/// cbindgen:derive-tagged-enum-copy-constructor=true #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)] +#[repr(C, u8)] pub enum TextOverflowSide { /// Clip inline content. Clip, /// Render ellipsis to represent clipped inline content. Ellipsis, /// Render a given string to represent clipped inline content. - String(Box), + String(crate::OwnedStr), } impl Parse for TextOverflowSide { @@ -161,7 +163,7 @@ impl Parse for TextOverflowSide { } }, Token::QuotedString(ref v) => Ok(TextOverflowSide::String( - v.as_ref().to_owned().into_boxed_str(), + v.as_ref().to_owned().into(), )), ref t => Err(location.new_unexpected_token_error(t.clone())), }