style: Cleanup text-align.

Use derive(FromPrimitive) instead.

Differential Revision: https://phabricator.services.mozilla.com/D11332
This commit is contained in:
Emilio Cobos Álvarez 2018-11-08 22:57:18 +00:00
parent fa764fc8e9
commit b7cefa5814
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 39 additions and 66 deletions

View file

@ -137,7 +137,7 @@ ${helpers.single_keyword(
${helpers.predefined_type( ${helpers.predefined_type(
"text-align", "text-align",
"TextAlign", "TextAlign",
"computed::TextAlign::start()", "computed::TextAlign::Start",
animation_value_type="discrete", animation_value_type="discrete",
flags="APPLIES_TO_PLACEHOLDER", flags="APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-text/#propdef-text-align", spec="https://drafts.csswg.org/css-text/#propdef-text-align",

View file

@ -380,71 +380,44 @@ impl TextDecorationLine {
} }
} }
macro_rules! define_text_align_keyword {
($(
$(#[$($meta:tt)+])*
$name: ident => $discriminant: expr,
)+) => {
/// Specified value of text-align keyword value. /// Specified value of text-align keyword value.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, #[derive(
SpecifiedValueInfo, ToComputedValue, ToCss)] Clone,
Copy,
Debug,
Eq,
FromPrimitive,
Hash,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub enum TextAlignKeyword { pub enum TextAlignKeyword {
$( Start,
$(#[$($meta)+])* End,
$name = $discriminant, Left,
)+ Right,
} Center,
Justify,
impl TextAlignKeyword {
/// Construct a TextAlignKeyword from u32.
pub fn from_u32(discriminant: u32) -> Option<TextAlignKeyword> {
match discriminant {
$(
$discriminant => Some(TextAlignKeyword::$name),
)+
_ => None
}
}
}
}
}
// FIXME(emilio): Why reinventing the world?
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
define_text_align_keyword! { MozCenter,
Start => 0, #[cfg(feature = "gecko")]
End => 1, MozLeft,
Left => 2, #[cfg(feature = "gecko")]
Right => 3, MozRight,
Center => 4,
Justify => 5,
MozCenter => 6,
MozLeft => 7,
MozRight => 8,
#[css(skip)]
Char => 10,
}
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
define_text_align_keyword! { ServoCenter,
Start => 0, #[cfg(feature = "servo")]
End => 1, ServoLeft,
Left => 2, #[cfg(feature = "servo")]
Right => 3, ServoRight,
Center => 4, #[css(skip)]
Justify => 5, #[cfg(feature = "gecko")]
ServoCenter => 6, Char,
ServoLeft => 7,
ServoRight => 8,
}
impl TextAlignKeyword {
/// Return the initial value of TextAlignKeyword.
#[inline]
pub fn start() -> TextAlignKeyword {
TextAlignKeyword::Start
}
} }
/// Specified value of text-align property. /// Specified value of text-align property.
@ -510,7 +483,7 @@ impl ToComputedValue for TextAlign {
// but we want to set it to right -- instead set it to the default (`start`), // but we want to set it to right -- instead set it to the default (`start`),
// which will do the right thing in this case (but not the general case) // which will do the right thing in this case (but not the general case)
if _context.is_root_element { if _context.is_root_element {
return TextAlignKeyword::start(); return TextAlignKeyword::Start;
} }
let parent = _context let parent = _context
.builder .builder