Simplify caret-color conversion. r?manishearth draft
authorXidorn Quan <me@upsuper.org>
Wed, 07 Jun 2017 14:55:16 +1000
changeset 590142 faaaed30efb2e5506b86f908f4b4545d1d930af5
parent 590141 d8d2d5b4c1b718833090979631655f70ea962001
child 632097 86955d2c40234d3323f11dff9134b6bfa45159e2
push id62604
push userxquan@mozilla.com
push dateWed, 07 Jun 2017 07:07:54 +0000
reviewersmanishearth
milestone55.0a1
Simplify caret-color conversion. r?manishearth MozReview-Commit-ID: BfYXUmzBFb9
servo/components/style/gecko_bindings/sugar/style_complex_color.rs
servo/components/style/properties/gecko.mako.rs
--- a/servo/components/style/gecko_bindings/sugar/style_complex_color.rs
+++ b/servo/components/style/gecko_bindings/sugar/style_complex_color.rs
@@ -1,17 +1,17 @@
 /* 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;
+use values::{Auto, Either};
 use values::computed::Color as ComputedColor;
 
 impl From<nscolor> for StyleComplexColor {
     fn from(other: nscolor) -> Self {
         StyleComplexColor {
             mColor: other,
             mForegroundRatio: 0,
             mIsAuto: false,
@@ -44,29 +44,36 @@ impl From<ComputedColor> for StyleComple
         StyleComplexColor {
             mColor: convert_rgba_to_nscolor(&other.color).into(),
             mForegroundRatio: other.foreground_ratio,
             mIsAuto: false,
         }
     }
 }
 
-impl From<StyleComplexColor> for values::computed::ColorOrAuto {
-    fn from(color: StyleComplexColor) -> Self {
-        use values::{Auto, Either};
-
-        if color.mIsAuto {
-            return Either::Second(Auto);
-        }
-
-        Either::First(color.into())
-    }
-}
-
 impl From<StyleComplexColor> for ComputedColor {
     fn from(other: StyleComplexColor) -> Self {
         debug_assert!(!other.mIsAuto);
         ComputedColor {
             color: convert_nscolor_to_rgba(other.mColor),
             foreground_ratio: other.mForegroundRatio,
         }
     }
 }
+
+impl From<Either<ComputedColor, Auto>> for StyleComplexColor {
+    fn from(other: Either<ComputedColor, Auto>) -> Self {
+        match other {
+            Either::First(color) => color.into(),
+            Either::Second(_auto) => StyleComplexColor::auto(),
+        }
+    }
+}
+
+impl From<StyleComplexColor> for Either<ComputedColor, Auto> {
+    fn from(other: StyleComplexColor) -> Self {
+        if !other.mIsAuto {
+            Either::First(other.into())
+        } else {
+            Either::Second(Auto)
+        }
+    }
+}
--- a/servo/components/style/properties/gecko.mako.rs
+++ b/servo/components/style/properties/gecko.mako.rs
@@ -37,17 +37,17 @@ use gecko_bindings::bindings::Gecko_NewC
 use gecko_bindings::bindings::Gecko_nsStyleFont_SetLang;
 use gecko_bindings::bindings::Gecko_nsStyleFont_CopyLangFrom;
 use gecko_bindings::bindings::Gecko_SetListStyleImageNone;
 use gecko_bindings::bindings::Gecko_SetListStyleImageImageValue;
 use gecko_bindings::bindings::Gecko_SetNullImageValue;
 use gecko_bindings::bindings::ServoComputedValuesBorrowedOrNull;
 use gecko_bindings::bindings::{Gecko_ResetFilters, Gecko_CopyFiltersFrom};
 use gecko_bindings::bindings::RawGeckoPresContextBorrowed;
-use gecko_bindings::structs::{self, StyleComplexColor};
+use gecko_bindings::structs;
 use gecko_bindings::structs::nsCSSPropertyID;
 use gecko_bindings::structs::nsStyleVariables;
 use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordData, CoordDataMut};
 use gecko_bindings::sugar::ownership::HasArcFFI;
 use gecko::values::convert_nscolor_to_rgba;
 use gecko::values::convert_rgba_to_nscolor;
 use gecko::values::GeckoStyleCoordConvertible;
 use gecko::values::round_border_to_device_pixels;
@@ -4222,35 +4222,17 @@ clip-path
 
     pub fn copy_cursor_from(&mut self, other: &Self) {
         self.gecko.mCursor = other.gecko.mCursor;
         unsafe {
             Gecko_CopyCursorArrayFrom(&mut self.gecko, &other.gecko);
         }
     }
 
-    pub fn set_caret_color(&mut self, v: longhands::caret_color::computed_value::T){
-        use values::Either;
-
-        match v {
-            Either::First(color) => {
-                self.gecko.mCaretColor = StyleComplexColor::from(color);
-            }
-            Either::Second(_auto) => {
-                self.gecko.mCaretColor = StyleComplexColor::auto();
-            }
-        }
-    }
-
-    pub fn copy_caret_color_from(&mut self, other: &Self){
-        self.gecko.mCaretColor = other.gecko.mCaretColor;
-    }
-
-    <%call expr="impl_color_clone('caret_color', 'mCaretColor')"></%call>
-
+    <%call expr="impl_color('caret_color', 'mCaretColor', need_clone=True)"></%call>
 </%self:impl_trait>
 
 <%self:impl_trait style_struct_name="Column"
                   skip_longhands="column-count column-rule-width">
 
     #[allow(unused_unsafe)]
     pub fn set_column_count(&mut self, v: longhands::column_count::computed_value::T) {
         use gecko_bindings::structs::{NS_STYLE_COLUMN_COUNT_AUTO, nsStyleColumn_kMaxColumnCount};