Bug 1639905 - Derive parse for TextOverflowSide. r=boris
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 21 May 2020 18:44:19 +0000
changeset 531495 97c335c0d79f429f33831f39b974df1ab1132fed
parent 531494 b55f7e60274403af65725021ef85361137846f4b
child 531496 a52fc20a6c06a6e74e62a87aebc3ae5d3593ed07
push id37440
push userabutkovits@mozilla.com
push dateFri, 22 May 2020 09:43:16 +0000
treeherdermozilla-central@fbf71e4d2e21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersboris
bugs1639905
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1639905 - Derive parse for TextOverflowSide. r=boris Depends on D76330 Differential Revision: https://phabricator.services.mozilla.com/D76331
servo/components/style/parser.rs
servo/components/style/values/specified/text.rs
--- a/servo/components/style/parser.rs
+++ b/servo/components/style/parser.rs
@@ -202,13 +202,19 @@ where
     fn parse<'i, 't>(
         context: &ParserContext,
         input: &mut Parser<'i, 't>,
     ) -> Result<Self, ParseError<'i>> {
         <T as OneOrMoreSeparated>::S::parse(input, |i| T::parse(context, i))
     }
 }
 
+impl Parse for crate::OwnedStr {
+    fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
+        Ok(input.expect_string()?.as_ref().to_owned().into())
+    }
+}
+
 impl Parse for UnicodeRange {
     fn parse<'i, 't>(_: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
         Ok(UnicodeRange::parse(input)?)
     }
 }
--- a/servo/components/style/values/specified/text.rs
+++ b/servo/components/style/values/specified/text.rs
@@ -123,56 +123,33 @@ impl ToComputedValue for LineHeight {
 
 /// A generic value for the `text-overflow` property.
 #[derive(
     Clone,
     Debug,
     Eq,
     MallocSizeOf,
     PartialEq,
+    Parse,
     SpecifiedValueInfo,
     ToComputedValue,
     ToCss,
     ToResolvedValue,
     ToShmem,
 )]
 #[repr(C, u8)]
 pub enum TextOverflowSide {
     /// Clip inline content.
     Clip,
     /// Render ellipsis to represent clipped inline content.
     Ellipsis,
     /// Render a given string to represent clipped inline content.
     String(crate::OwnedStr),
 }
 
-impl Parse for TextOverflowSide {
-    fn parse<'i, 't>(
-        _context: &ParserContext,
-        input: &mut Parser<'i, 't>,
-    ) -> Result<TextOverflowSide, ParseError<'i>> {
-        let location = input.current_source_location();
-        match *input.next()? {
-            Token::Ident(ref ident) => {
-                match_ignore_ascii_case! { ident,
-                    "clip" => Ok(TextOverflowSide::Clip),
-                    "ellipsis" => Ok(TextOverflowSide::Ellipsis),
-                    _ => Err(location.new_custom_error(
-                        SelectorParseErrorKind::UnexpectedIdent(ident.clone())
-                    ))
-                }
-            },
-            Token::QuotedString(ref v) => {
-                Ok(TextOverflowSide::String(v.as_ref().to_owned().into()))
-            },
-            ref t => Err(location.new_unexpected_token_error(t.clone())),
-        }
-    }
-}
-
 #[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
 /// text-overflow. Specifies rendering when inline content overflows its line box edge.
 pub struct TextOverflow {
     /// First value. Applies to end line box edge if no second is supplied; line-left edge otherwise.
     pub first: TextOverflowSide,
     /// Second value. Applies to the line-right edge if supplied.
     pub second: Option<TextOverflowSide>,
 }