style: Move text-overflow outside of mako

This commit is contained in:
Connor Brewster 2017-10-27 15:31:26 -05:00
parent d0213b2111
commit deb932784e
7 changed files with 160 additions and 137 deletions

View file

@ -12,126 +12,13 @@
Method("has_overline", "bool"),
Method("has_line_through", "bool")]) %>
<%helpers:longhand name="text-overflow" animation_value_type="discrete" boxed="True"
flags="APPLIES_TO_PLACEHOLDER"
spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow">
use std::fmt;
use style_traits::ToCss;
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
pub enum Side {
Clip,
Ellipsis,
String(Box<str>),
}
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, ToCss)]
pub struct SpecifiedValue {
pub first: Side,
pub second: Option<Side>
}
pub mod computed_value {
pub use super::Side;
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
pub struct T {
// When the specified value only has one side, that's the "second"
// side, and the sides are logical, so "second" means "end". The
// start side is Clip in that case.
//
// When the specified value has two sides, those are our "first"
// and "second" sides, and they are physical sides ("left" and
// "right").
pub first: Side,
pub second: Side,
pub sides_are_logical: bool
}
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.sides_are_logical {
assert!(self.first == Side::Clip);
self.second.to_css(dest)?;
} else {
self.first.to_css(dest)?;
dest.write_str(" ")?;
self.second.to_css(dest)?;
}
Ok(())
}
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _context: &Context) -> Self::ComputedValue {
if let Some(ref second) = self.second {
Self::ComputedValue { first: self.first.clone(),
second: second.clone(),
sides_are_logical: false }
} else {
Self::ComputedValue { first: Side::Clip,
second: self.first.clone(),
sides_are_logical: true }
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
if computed.sides_are_logical {
assert!(computed.first == Side::Clip);
SpecifiedValue { first: computed.second.clone(),
second: None }
} else {
SpecifiedValue { first: computed.first.clone(),
second: Some(computed.second.clone()) }
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T {
first: Side::Clip,
second: Side::Clip,
sides_are_logical: true,
}
}
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> {
let first = Side::parse(context, input)?;
let second = input.try(|input| Side::parse(context, input)).ok();
Ok(SpecifiedValue {
first: first,
second: second,
})
}
impl Parse for Side {
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Side, ParseError<'i>> {
let location = input.current_source_location();
match *input.next()? {
Token::Ident(ref ident) => {
match_ignore_ascii_case! { ident,
"clip" => Ok(Side::Clip),
"ellipsis" => Ok(Side::Ellipsis),
_ => Err(location.new_custom_error(
SelectorParseErrorKind::UnexpectedIdent(ident.clone())
))
}
}
Token::QuotedString(ref v) => {
Ok(Side::String(v.as_ref().to_owned().into_boxed_str()))
}
ref t => Err(location.new_unexpected_token_error(t.clone())),
}
}
}
</%helpers:longhand>
${helpers.predefined_type("text-overflow",
"TextOverflow",
"computed::TextOverflow::get_initial_value()",
animation_value_type="discrete",
boxed=True,
flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-ui/#propdef-text-overflow")}
${helpers.single_keyword("unicode-bidi",
"normal embed isolate bidi-override isolate-override plaintext",