mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use cbindgen for text-overflow.
Differential Revision: https://phabricator.services.mozilla.com/D32285
This commit is contained in:
parent
73b0b7c477
commit
e66e612452
3 changed files with 6 additions and 79 deletions
|
@ -3342,83 +3342,7 @@ fn static_assert() {
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="Text"
|
<%self:impl_trait style_struct_name="Text" skip_longhands="initial-letter">
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) {
|
pub fn set_initial_letter(&mut self, v: longhands::initial_letter::computed_value::T) {
|
||||||
use crate::values::generics::text::InitialLetter;
|
use crate::values::generics::text::InitialLetter;
|
||||||
match v {
|
match v {
|
||||||
|
|
|
@ -105,6 +105,7 @@ impl ToComputedValue for specified::WordSpacing {
|
||||||
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;
|
pub type LineHeight = GenericLineHeight<NonNegativeNumber, NonNegativeLength>;
|
||||||
|
|
||||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue)]
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToResolvedValue)]
|
||||||
|
#[repr(C)]
|
||||||
/// text-overflow.
|
/// text-overflow.
|
||||||
/// When the specified value only has one side, that's the "second"
|
/// When the specified value only has one side, that's the "second"
|
||||||
/// side, and the sides are logical, so "second" means "end". The
|
/// side, and the sides are logical, so "second" means "end". The
|
||||||
|
|
|
@ -134,14 +134,16 @@ impl ToComputedValue for LineHeight {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A generic value for the `text-overflow` property.
|
/// A generic value for the `text-overflow` property.
|
||||||
|
/// cbindgen:derive-tagged-enum-copy-constructor=true
|
||||||
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
|
||||||
|
#[repr(C, u8)]
|
||||||
pub enum TextOverflowSide {
|
pub enum TextOverflowSide {
|
||||||
/// Clip inline content.
|
/// Clip inline content.
|
||||||
Clip,
|
Clip,
|
||||||
/// Render ellipsis to represent clipped inline content.
|
/// Render ellipsis to represent clipped inline content.
|
||||||
Ellipsis,
|
Ellipsis,
|
||||||
/// Render a given string to represent clipped inline content.
|
/// Render a given string to represent clipped inline content.
|
||||||
String(Box<str>),
|
String(crate::OwnedStr),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for TextOverflowSide {
|
impl Parse for TextOverflowSide {
|
||||||
|
@ -161,7 +163,7 @@ impl Parse for TextOverflowSide {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Token::QuotedString(ref v) => Ok(TextOverflowSide::String(
|
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())),
|
ref t => Err(location.new_unexpected_token_error(t.clone())),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue