Bug 1434130 part 8 - Have TextAlign derive ToCss and unship char value from it. r?emilio
MozReview-Commit-ID: CXDnyqzjQkq
--- a/layout/style/test/property_database.js
+++ b/layout/style/test/property_database.js
@@ -4420,17 +4420,17 @@ var gCSSProperties = {
"text-align": {
domProp: "textAlign",
inherited: true,
type: CSS_TYPE_LONGHAND,
applies_to_placeholder: true,
// don't know whether left and right are same as start
initial_values: [ "start" ],
other_values: [ "center", "justify", "end", "match-parent" ],
- invalid_values: [ "true", "true true" ]
+ invalid_values: [ "true", "true true", "char", "-moz-center-or-inherit" ]
},
"text-align-last": {
domProp: "textAlignLast",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "auto" ],
other_values: [ "center", "justify", "start", "end", "left", "right" ],
invalid_values: []
--- a/servo/components/style/values/specified/text.rs
+++ b/servo/components/style/values/specified/text.rs
@@ -350,23 +350,27 @@ impl Parse for TextDecorationLine {
Ok(result)
} else {
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
}
}
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,
)+
}
impl TextAlignKeyword {
/// Construct a TextAlignKeyword from u32.
pub fn from_u32(discriminant: u32) -> Option<TextAlignKeyword> {
match discriminant {
@@ -387,16 +391,17 @@ define_text_align_keyword! {
End => 1,
Left => 2,
Right => 3,
Center => 4,
Justify => 5,
MozCenter => 6,
MozLeft => 7,
MozRight => 8,
+ #[css(skip)]
Char => 10,
}
#[cfg(feature = "servo")]
define_text_align_keyword! {
Start => 0,
End => 1,
Left => 2,
@@ -413,28 +418,29 @@ impl TextAlignKeyword {
#[inline]
pub fn start() -> TextAlignKeyword {
TextAlignKeyword::Start
}
}
/// 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),
/// `match-parent` value of text-align property. It has a different handling
/// unlike other keywords.
#[cfg(feature = "gecko")]
MatchParent,
/// `MozCenterOrInherit` value of text-align property. It cannot be parsed,
/// only set directly on the elements and it has a different handling
/// unlike other values.
#[cfg(feature = "gecko")]
+ #[css(skip)]
MozCenterOrInherit,
}
impl Parse for TextAlign {
fn parse<'i, 't>(
_context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
@@ -449,31 +455,16 @@ impl Parse for TextAlign {
}
#[cfg(feature = "servo")]
{
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
}
}
-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")]
pub fn from_gecko_keyword(kw: u32) -> Self {
use gecko_bindings::structs::NS_STYLE_TEXT_ALIGN_MATCH_PARENT;
if kw == NS_STYLE_TEXT_ALIGN_MATCH_PARENT {
TextAlign::MatchParent
} else {