Bug 1460456 part 2 - Rename CaretColor to ColorOrAuto for reusing. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Thu, 10 May 2018 09:56:10 +1000
changeset 795171 472637b2ade99e94222be7fcafbc0c4070776398
parent 795170 559726971bf1c6b1c4fb7364e46f7f9448385abc
child 795172 d6c176f410fd9ab262855845404938ba5fda7ff1
push id109884
push userxquan@mozilla.com
push dateTue, 15 May 2018 05:52:23 +0000
reviewersheycam
bugs1460456
milestone62.0a1
Bug 1460456 part 2 - Rename CaretColor to ColorOrAuto for reusing. r?heycam MozReview-Commit-ID: LD6PlNI60GC
servo/components/style/gecko_bindings/sugar/style_complex_color.rs
servo/components/style/properties/longhand/inherited_ui.mako.rs
servo/components/style/values/computed/mod.rs
servo/components/style/values/computed/ui.rs
servo/components/style/values/generics/ui.rs
servo/components/style/values/specified/mod.rs
servo/components/style/values/specified/ui.rs
--- a/servo/components/style/gecko_bindings/sugar/style_complex_color.rs
+++ b/servo/components/style/gecko_bindings/sugar/style_complex_color.rs
@@ -1,18 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Rust helpers to interact with Gecko's StyleComplexColor.
 
 use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
 use gecko_bindings::structs::{nscolor, StyleComplexColor};
+use values::{Auto, Either};
 use values::computed::Color as ComputedColor;
-use values::generics::ui::CaretColor;
+use values::computed::ui::ColorOrAuto;
 
 impl From<nscolor> for StyleComplexColor {
     fn from(other: nscolor) -> Self {
         StyleComplexColor {
             mColor: other,
             mForegroundRatio: 0,
             mIsAuto: false,
         }
@@ -54,32 +55,26 @@ impl From<StyleComplexColor> for Compute
         debug_assert!(!other.mIsAuto);
         ComputedColor {
             color: convert_nscolor_to_rgba(other.mColor),
             foreground_ratio: other.mForegroundRatio,
         }
     }
 }
 
-impl<Color> From<CaretColor<Color>> for StyleComplexColor
-where
-    Color: Into<StyleComplexColor>,
-{
-    fn from(other: CaretColor<Color>) -> Self {
+impl From<ColorOrAuto> for StyleComplexColor {
+    fn from(other: ColorOrAuto) -> Self {
         match other {
-            CaretColor::Color(color) => color.into(),
-            CaretColor::Auto => StyleComplexColor::auto(),
+            Either::First(color) => color.into(),
+            Either::Second(_) => StyleComplexColor::auto(),
         }
     }
 }
 
-impl<Color> From<StyleComplexColor> for CaretColor<Color>
-where
-    StyleComplexColor: Into<Color>,
-{
+impl From<StyleComplexColor> for ColorOrAuto {
     fn from(other: StyleComplexColor) -> Self {
         if !other.mIsAuto {
-            CaretColor::Color(other.into())
+            Either::First(other.into())
         } else {
-            CaretColor::Auto
+            Either::Second(Auto)
         }
     }
 }
--- a/servo/components/style/properties/longhand/inherited_ui.mako.rs
+++ b/servo/components/style/properties/longhand/inherited_ui.mako.rs
@@ -38,15 +38,15 @@
                          "none ignore normal select-after select-before select-menu select-same select-all",
                          products="gecko", gecko_ffi_name="mUserFocus",
                          gecko_enum_prefix="StyleUserFocus",
                          animation_value_type="discrete",
                          spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-user-focus)")}
 
 ${helpers.predefined_type(
     "caret-color",
-    "CaretColor",
-    "generics::ui::CaretColor::Auto",
+    "ColorOrAuto",
+    "Either::Second(Auto)",
     spec="https://drafts.csswg.org/css-ui/#caret-color",
     animation_value_type="AnimatedCaretColor",
     ignored_when_colors_disabled=True,
     products="gecko",
 )}
--- a/servo/components/style/values/computed/mod.rs
+++ b/servo/components/style/values/computed/mod.rs
@@ -73,17 +73,17 @@ pub use self::svg::{SVGLength, SVGOpacit
 pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
 pub use self::svg::MozContextProperties;
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize};
 pub use self::text::{TextAlign, TextEmphasisPosition, TextEmphasisStyle, TextOverflow, WordSpacing};
 pub use self::time::Time;
 pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation};
 pub use self::transform::{TransformOrigin, TransformStyle, Translate};
-pub use self::ui::{CaretColor, Cursor, MozForceBrokenImageIcon};
+pub use self::ui::{ColorOrAuto, Cursor, MozForceBrokenImageIcon};
 #[cfg(feature = "gecko")]
 pub use self::ui::CursorImage;
 
 #[cfg(feature = "gecko")]
 pub mod align;
 pub mod angle;
 pub mod background;
 pub mod basic_shape;
--- a/servo/components/style/values/computed/ui.rs
+++ b/servo/components/style/values/computed/ui.rs
@@ -1,21 +1,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Computed values for UI properties
 
+use values::{Auto, Either};
 use values::computed::Number;
 use values::computed::color::Color;
 use values::computed::url::ComputedImageUrl;
 use values::generics::ui as generics;
 
 pub use values::specified::ui::MozForceBrokenImageIcon;
 
-/// A computed value for the `caret-color` property.
-pub type CaretColor = generics::CaretColor<Color>;
+/// auto | <color>
+pub type ColorOrAuto = Either<Color, Auto>;
 
 /// A computed value for the `cursor` property.
 pub type Cursor = generics::Cursor<CursorImage>;
 
 /// A computed value for item of `image cursors`.
 pub type CursorImage = generics::CursorImage<ComputedImageUrl, Number>;
--- a/servo/components/style/values/generics/ui.rs
+++ b/servo/components/style/values/generics/ui.rs
@@ -3,27 +3,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Generic values for UI properties.
 
 use std::fmt::{self, Write};
 use style_traits::{CssWriter, ToCss};
 use style_traits::cursor::CursorKind;
 
-/// A generic value for the `caret-color` property.
-#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf,
-         PartialEq, SpecifiedValueInfo, ToAnimatedValue, ToAnimatedZero,
-         ToComputedValue, ToCss)]
-pub enum CaretColor<Color> {
-    /// An explicit color.
-    Color(Color),
-    /// The keyword `auto`.
-    Auto,
-}
-
 /// A generic value for the `cursor` property.
 ///
 /// https://drafts.csswg.org/css-ui/#cursor
 #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
          ToComputedValue)]
 pub struct Cursor<Image> {
     /// The parsed images for the cursor.
     pub images: Box<[Image]>,
--- a/servo/components/style/values/specified/mod.rs
+++ b/servo/components/style/values/specified/mod.rs
@@ -70,17 +70,17 @@ pub use self::svg::{SVGPaintOrder, SVGSt
 pub use self::svg::MozContextProperties;
 pub use self::table::XSpan;
 pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign};
 pub use self::text::{TextEmphasisPosition, TextEmphasisStyle};
 pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
 pub use self::time::Time;
 pub use self::transform::{Rotate, Scale, TimingFunction, Transform};
 pub use self::transform::{TransformOrigin, TransformStyle, Translate};
-pub use self::ui::{CaretColor, Cursor, MozForceBrokenImageIcon};
+pub use self::ui::{ColorOrAuto, Cursor, MozForceBrokenImageIcon};
 #[cfg(feature = "gecko")]
 pub use self::ui::CursorImage;
 pub use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
 
 #[cfg(feature = "gecko")]
 pub mod align;
 pub mod angle;
 pub mod background;
--- a/servo/components/style/values/specified/ui.rs
+++ b/servo/components/style/values/specified/ui.rs
@@ -4,35 +4,24 @@
 
 //! Specified types for UI properties.
 
 use cssparser::Parser;
 use parser::{Parse, ParserContext};
 use std::fmt::{self, Write};
 use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
 use style_traits::cursor::CursorKind;
+use values::{Auto, Either};
 use values::generics::ui as generics;
 use values::specified::Number;
 use values::specified::color::Color;
 use values::specified::url::SpecifiedImageUrl;
 
-/// A specified value for the `caret-color` property.
-pub type CaretColor = generics::CaretColor<Color>;
-
-impl Parse for CaretColor {
-    fn parse<'i, 't>(
-        context: &ParserContext,
-        input: &mut Parser<'i, 't>,
-    ) -> Result<Self, ParseError<'i>> {
-        if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
-            return Ok(generics::CaretColor::Auto);
-        }
-        Ok(generics::CaretColor::Color(Color::parse(context, input)?))
-    }
-}
+/// auto | <color>
+pub type ColorOrAuto = Either<Color, Auto>;
 
 /// A specified value for the `cursor` property.
 pub type Cursor = generics::Cursor<CursorImage>;
 
 /// A specified value for item of `image cursors`.
 pub type CursorImage = generics::CursorImage<SpecifiedImageUrl, Number>;
 
 impl Parse for Cursor {