Skip to content

Commit

Permalink
style: Have TextAlign derive ToCss and unship char value from it.
Browse files Browse the repository at this point in the history
Bug: 1434130
Reviewed-by: emilio
MozReview-Commit-ID: CXDnyqzjQkq
  • Loading branch information
upsuper authored and emilio committed Apr 29, 2018
1 parent 43bb636 commit 5437c96
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions components/style/values/specified/text.rs
Expand Up @@ -355,13 +355,17 @@ impl Parse for TextDecorationLine {
}

macro_rules! define_text_align_keyword {
($($name: ident => $discriminant: expr,)+) => {
($(
$(#[$($meta:tt)+])*
$name: ident => $discriminant: expr,
)+) => {
/// Specified value of text-align keyword value.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq,
SpecifiedValueInfo, ToComputedValue, ToCss)]
#[allow(missing_docs)]
pub enum TextAlignKeyword {
$(
$(#[$($meta)+])*
$name = $discriminant,
)+
}
Expand Down Expand Up @@ -392,6 +396,7 @@ define_text_align_keyword! {
MozCenter => 6,
MozLeft => 7,
MozRight => 8,
#[css(skip)]
Char => 10,
}

Expand All @@ -418,7 +423,7 @@ impl TextAlignKeyword {

/// Specified value of text-align property.
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, SpecifiedValueInfo, ToCss)]
pub enum TextAlign {
/// Keyword value of text-align property.
Keyword(TextAlignKeyword),
Expand All @@ -430,6 +435,7 @@ pub enum TextAlign {
/// only set directly on the elements and it has a different handling
/// unlike other values.
#[cfg(feature = "gecko")]
#[css(skip)]
MozCenterOrInherit,
}

Expand All @@ -454,21 +460,6 @@ impl Parse for TextAlign {
}
}

impl ToCss for TextAlign {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
TextAlign::Keyword(key) => key.to_css(dest),
#[cfg(feature = "gecko")]
TextAlign::MatchParent => dest.write_str("match-parent"),
#[cfg(feature = "gecko")]
TextAlign::MozCenterOrInherit => Ok(()),
}
}
}

impl TextAlign {
/// Convert an enumerated value coming from Gecko to a `TextAlign`.
#[cfg(feature = "gecko")]
Expand Down

0 comments on commit 5437c96

Please sign in to comment.