Bug 1592189 - Remove SpecialColorKeyword enum and merge into SystemColor r=emilio
authorSam Mauldin <sam@mauldin.me>
Thu, 14 Nov 2019 00:17:23 +0000
changeset 501896 6514e3ddd69bd92dad544554768b5fa3c4960613
parent 501895 a65aef85ad0df16d756283fb1975cdd90ea61843
child 501897 6a2d40014464a2bb1489921bd152d229e273d14d
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1592189
milestone72.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 1592189 - Remove SpecialColorKeyword enum and merge into SystemColor r=emilio Move all the entires of SpecialColorKeyword into SystemColor and rearrange their computation to match. Add the new SystemColor entries into the property list of nsXPLookAndFeel. Differential Revision: https://phabricator.services.mozilla.com/D50903
servo/components/style/values/specified/color.rs
widget/nsXPLookAndFeel.cpp
--- a/servo/components/style/values/specified/color.rs
+++ b/servo/components/style/values/specified/color.rs
@@ -31,19 +31,16 @@ pub enum Color {
         /// Authored representation
         authored: Option<Box<str>>,
     },
     /// A complex color value from computed value
     Complex(ComputedColor),
     /// A system color
     #[cfg(feature = "gecko")]
     System(SystemColor),
-    /// A special color keyword value used in Gecko
-    #[cfg(feature = "gecko")]
-    Special(gecko::SpecialColorKeyword),
     /// Quirksmode-only rule for inheriting color from the body
     #[cfg(feature = "gecko")]
     InheritFromBodyQuirk,
 }
 
 /// System colors.
 #[allow(missing_docs)]
 #[cfg(feature = "gecko")]
@@ -138,16 +135,18 @@ pub enum SystemColor {
     Threedface,
     Threedhighlight,
     Threedlightshadow,
     Threedshadow,
     Window,
     Windowframe,
     Windowtext,
     MozButtondefault,
+    MozDefaultColor,
+    MozDefaultBackgroundColor,
     MozDialog,
     MozDialogtext,
     /// Used to highlight valid regions to drop something onto.
     MozDragtargetzone,
     /// Used for selected but not focused cell backgrounds.
     MozCellhighlight,
     /// Used for selected but not focused cell text.
     MozCellhighlighttext,
@@ -226,49 +225,53 @@ pub enum SystemColor {
     /// Hyperlink color extracted from the system, not affected by the
     /// browser.anchor_color user pref.
     ///
     /// There is no OS-specified safe background color for this text, but it is
     /// used regularly within Windows and the Gnome DE on Dialog and Window
     /// colors.
     MozNativehyperlinktext,
 
+    MozHyperlinktext,
+    MozActivehyperlinktext,
+    MozVisitedhyperlinktext,
+
     /// Combobox widgets
     MozComboboxtext,
     MozCombobox,
 
     MozGtkInfoBarText,
 
     #[css(skip)]
     End, // Just for array-indexing purposes.
 }
 
 #[cfg(feature = "gecko")]
 impl SystemColor {
     #[inline]
     fn compute(&self, cx: &Context) -> ComputedColor {
         use crate::gecko_bindings::bindings;
-        unsafe {
-            convert_nscolor_to_computedcolor(bindings::Gecko_GetLookAndFeelSystemColor(
-                *self as i32,
-                cx.device().document(),
-            ))
-        }
-    }
-}
+
+        let prefs = cx.device().pref_sheet_prefs();
 
-#[cfg(feature = "gecko")]
-mod gecko {
-    #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToCss, ToShmem)]
-    pub enum SpecialColorKeyword {
-        MozDefaultColor,
-        MozDefaultBackgroundColor,
-        MozHyperlinktext,
-        MozActivehyperlinktext,
-        MozVisitedhyperlinktext,
+        convert_nscolor_to_computedcolor(match *self {
+            SystemColor::MozDefaultColor => prefs.mDefaultColor,
+            SystemColor::MozDefaultBackgroundColor => prefs.mDefaultBackgroundColor,
+            SystemColor::MozHyperlinktext => prefs.mLinkColor,
+            SystemColor::MozActivehyperlinktext => prefs.mActiveLinkColor,
+            SystemColor::MozVisitedhyperlinktext => prefs.mVisitedLinkColor,
+
+            _ => unsafe {
+                bindings::Gecko_GetLookAndFeelSystemColor(
+                    *self as i32,
+                    cx.device().document()
+                )
+            }
+        })
+
     }
 }
 
 impl From<RGBA> for Color {
     fn from(value: RGBA) -> Self {
         Color::rgba(value)
     }
 }
@@ -359,20 +362,16 @@ impl Parse for Color {
                 },
             }),
             Err(e) => {
                 #[cfg(feature = "gecko")]
                 {
                     if let Ok(system) = input.try(|i| SystemColor::parse(context, i)) {
                         return Ok(Color::System(system));
                     }
-
-                    if let Ok(c) = input.try(gecko::SpecialColorKeyword::parse) {
-                        return Ok(Color::Special(c));
-                    }
                 }
 
                 match e.kind {
                     ParseErrorKind::Basic(BasicParseErrorKind::UnexpectedToken(t)) => {
                         Err(e.location.new_custom_error(StyleParseErrorKind::ValueError(
                             ValueParseErrorKind::InvalidColor(t),
                         )))
                     },
@@ -396,18 +395,16 @@ impl ToCss for Color {
             } => dest.write_str(authored),
             Color::Numeric {
                 parsed: ref rgba, ..
             } => rgba.to_css(dest),
             Color::Complex(_) => Ok(()),
             #[cfg(feature = "gecko")]
             Color::System(system) => system.to_css(dest),
             #[cfg(feature = "gecko")]
-            Color::Special(special) => special.to_css(dest),
-            #[cfg(feature = "gecko")]
             Color::InheritFromBodyQuirk => Ok(()),
         }
     }
 }
 
 /// A wrapper of cssparser::Color::parse_hash.
 ///
 /// That function should never return CurrentColor, so it makes no sense to
@@ -548,28 +545,16 @@ impl Color {
     pub fn to_computed_color(&self, _context: Option<&Context>) -> Option<ComputedColor> {
         Some(match *self {
             Color::CurrentColor => ComputedColor::currentcolor(),
             Color::Numeric { ref parsed, .. } => ComputedColor::rgba(*parsed),
             Color::Complex(ref complex) => *complex,
             #[cfg(feature = "gecko")]
             Color::System(system) => system.compute(_context?),
             #[cfg(feature = "gecko")]
-            Color::Special(special) => {
-                use self::gecko::SpecialColorKeyword as Keyword;
-                let prefs = _context?.device().pref_sheet_prefs();
-                convert_nscolor_to_computedcolor(match special {
-                    Keyword::MozDefaultColor => prefs.mDefaultColor,
-                    Keyword::MozDefaultBackgroundColor => prefs.mDefaultBackgroundColor,
-                    Keyword::MozHyperlinktext => prefs.mLinkColor,
-                    Keyword::MozActivehyperlinktext => prefs.mActiveLinkColor,
-                    Keyword::MozVisitedhyperlinktext => prefs.mVisitedLinkColor,
-                })
-            },
-            #[cfg(feature = "gecko")]
             Color::InheritFromBodyQuirk => {
                 ComputedColor::rgba(_context?.device().body_text_color())
             },
         })
     }
 }
 
 impl ToComputedValue for Color {
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -163,16 +163,18 @@ const char nsXPLookAndFeel::sColorPrefs[
     "ui.threedface",
     "ui.threedhighlight",
     "ui.threedlightshadow",
     "ui.threedshadow",
     "ui.window",
     "ui.windowframe",
     "ui.windowtext",
     "ui.-moz-buttondefault",
+    "ui.-moz-default-color",
+    "ui.-moz-default-background-color",
     "ui.-moz-dialog",
     "ui.-moz-dialogtext",
     "ui.-moz-dragtargetzone",
     "ui.-moz-cellhighlight",
     "ui.-moz_cellhighlighttext",
     "ui.-moz-html-cellhighlight",
     "ui.-moz-html-cellhighlighttext",
     "ui.-moz-buttonhoverface",
@@ -206,16 +208,19 @@ const char nsXPLookAndFeel::sColorPrefs[
     "ui.-moz-mac-source-list-selection",
     "ui.-moz-mac-active-source-list-selection",
     "ui.-moz-mac-tooltip",
     "ui.-moz-win-accentcolor",
     "ui.-moz-win-accentcolortext",
     "ui.-moz-win-mediatext",
     "ui.-moz-win-communicationstext",
     "ui.-moz-nativehyperlinktext",
+    "ui.-moz-hyperlinktext",
+    "ui.-moz-activehyperlinktext",
+    "ui.-moz-visitedhyperlinktext",
     "ui.-moz-comboboxtext",
     "ui.-moz-combobox",
     "ui.-moz-gtk-info-bar-text"};
 
 int32_t nsXPLookAndFeel::sCachedColors[size_t(LookAndFeel::ColorID::End)] = {0};
 int32_t nsXPLookAndFeel::sCachedColorBits[COLOR_CACHE_SIZE] = {0};
 
 bool nsXPLookAndFeel::sInitialized = false;