Skip to content

Commit

Permalink
style: Use cbindgen for text-overflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
violette77 authored and emilio committed May 29, 2019
1 parent 73b0b7c commit e66e612
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 79 deletions.
78 changes: 1 addition & 77 deletions components/style/properties/gecko.mako.rs
Expand Up @@ -3342,83 +3342,7 @@ fn static_assert() {

</%self:impl_trait>

<%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 {
Expand Down
1 change: 1 addition & 0 deletions components/style/values/computed/text.rs
Expand Up @@ -105,6 +105,7 @@ impl ToComputedValue for specified::WordSpacing {
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;

#[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
Expand Down
6 changes: 4 additions & 2 deletions components/style/values/specified/text.rs
Expand Up @@ -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<str>),
String(crate::OwnedStr),
}

impl Parse for TextOverflowSide {
Expand All @@ -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())),
}
Expand Down

0 comments on commit e66e612

Please sign in to comment.