mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Cleanup text-align.
Use derive(FromPrimitive) instead. Differential Revision: https://phabricator.services.mozilla.com/D11332
This commit is contained in:
parent
fa764fc8e9
commit
b7cefa5814
2 changed files with 39 additions and 66 deletions
|
@ -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",
|
||||||
|
|
|
@ -380,71 +380,44 @@ impl TextDecorationLine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! define_text_align_keyword {
|
/// Specified value of text-align keyword value.
|
||||||
($(
|
#[derive(
|
||||||
$(#[$($meta:tt)+])*
|
Clone,
|
||||||
$name: ident => $discriminant: expr,
|
Copy,
|
||||||
)+) => {
|
Debug,
|
||||||
/// Specified value of text-align keyword value.
|
Eq,
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq,
|
FromPrimitive,
|
||||||
SpecifiedValueInfo, ToComputedValue, ToCss)]
|
Hash,
|
||||||
#[allow(missing_docs)]
|
MallocSizeOf,
|
||||||
pub enum TextAlignKeyword {
|
Parse,
|
||||||
$(
|
PartialEq,
|
||||||
$(#[$($meta)+])*
|
SpecifiedValueInfo,
|
||||||
$name = $discriminant,
|
ToComputedValue,
|
||||||
)+
|
ToCss,
|
||||||
}
|
)]
|
||||||
|
#[allow(missing_docs)]
|
||||||
impl TextAlignKeyword {
|
pub enum TextAlignKeyword {
|
||||||
/// Construct a TextAlignKeyword from u32.
|
Start,
|
||||||
pub fn from_u32(discriminant: u32) -> Option<TextAlignKeyword> {
|
End,
|
||||||
match discriminant {
|
Left,
|
||||||
$(
|
Right,
|
||||||
$discriminant => Some(TextAlignKeyword::$name),
|
Center,
|
||||||
)+
|
Justify,
|
||||||
_ => None
|
#[cfg(feature = "gecko")]
|
||||||
}
|
MozCenter,
|
||||||
}
|
#[cfg(feature = "gecko")]
|
||||||
}
|
MozLeft,
|
||||||
}
|
#[cfg(feature = "gecko")]
|
||||||
}
|
MozRight,
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
// FIXME(emilio): Why reinventing the world?
|
ServoCenter,
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "servo")]
|
||||||
define_text_align_keyword! {
|
ServoLeft,
|
||||||
Start => 0,
|
#[cfg(feature = "servo")]
|
||||||
End => 1,
|
ServoRight,
|
||||||
Left => 2,
|
|
||||||
Right => 3,
|
|
||||||
Center => 4,
|
|
||||||
Justify => 5,
|
|
||||||
MozCenter => 6,
|
|
||||||
MozLeft => 7,
|
|
||||||
MozRight => 8,
|
|
||||||
#[css(skip)]
|
#[css(skip)]
|
||||||
Char => 10,
|
#[cfg(feature = "gecko")]
|
||||||
}
|
Char,
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
define_text_align_keyword! {
|
|
||||||
Start => 0,
|
|
||||||
End => 1,
|
|
||||||
Left => 2,
|
|
||||||
Right => 3,
|
|
||||||
Center => 4,
|
|
||||||
Justify => 5,
|
|
||||||
ServoCenter => 6,
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue