Bug 1671401 - Use separate Scrollbar and ThemedScrollbar ColorIDs. r=spohl
authorCameron McCormack <cam@mcc.id.au>
Fri, 16 Oct 2020 12:49:47 +0000
changeset 553331 67cc13c5744b6d3dfd9499cf7e8bdf638829fd06
parent 553330 3a04ed65eabc1d01285a2fdf7479da114f5778fc
child 553332 431f3b75086b61509dc3fa6a892c81c23e402074
push id37869
push userrmaries@mozilla.com
push dateSat, 17 Oct 2020 09:14:56 +0000
treeherdermozilla-central@f9a6da3ea564 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1671401
milestone83.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 1671401 - Use separate Scrollbar and ThemedScrollbar ColorIDs. r=spohl Otherwise on Windows, we have a ColorID::Scrollbar but not any of the other scrollbar part colors, and the Windows-provided value for Scrollbar doesn't work well with the default values for the other scrollbar parts that come from the non-native theme. Differential Revision: https://phabricator.services.mozilla.com/D93728
servo/components/style/values/specified/color.rs
widget/gtk/nsLookAndFeel.cpp
widget/gtk/nsLookAndFeel.h
widget/nsNativeBasicTheme.cpp
widget/nsXPLookAndFeel.cpp
--- a/servo/components/style/values/specified/color.rs
+++ b/servo/components/style/values/specified/color.rs
@@ -103,25 +103,27 @@ pub enum SystemColor {
     IMESelectedConvertedTextBackground,
     #[css(skip)]
     IMESelectedConvertedTextForeground,
     #[css(skip)]
     IMESelectedConvertedTextUnderline,
     #[css(skip)]
     SpellCheckerUnderline,
     #[css(skip)]
-    ScrollbarInactive,
+    ThemedScrollbar,
     #[css(skip)]
-    ScrollbarThumb,
+    ThemedScrollbarInactive,
+    #[css(skip)]
+    ThemedScrollbarThumb,
     #[css(skip)]
-    ScrollbarThumbHover,
+    ThemedScrollbarThumbHover,
     #[css(skip)]
-    ScrollbarThumbActive,
+    ThemedScrollbarThumbActive,
     #[css(skip)]
-    ScrollbarThumbInactive,
+    ThemedScrollbarThumbInactive,
     Activeborder,
     Activecaption,
     Appworkspace,
     Background,
     Buttonface,
     Buttonhighlight,
     Buttonshadow,
     Buttontext,
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -268,22 +268,23 @@ void nsLookAndFeel::RefreshImpl() {
 }
 
 LookAndFeelCache nsLookAndFeel::GetCacheImpl() {
   LookAndFeelCache cache = nsXPLookAndFeel::GetCacheImpl();
 
   constexpr IntID kIntIdsToCache[] = {IntID::SystemUsesDarkTheme,
                                       IntID::PrefersReducedMotion,
                                       IntID::UseAccessibilityTheme};
-  constexpr ColorID kColorIdsToCache[] = {ColorID::Scrollbar,
-                                          ColorID::ScrollbarInactive,
-                                          ColorID::ScrollbarThumb,
-                                          ColorID::ScrollbarThumbHover,
-                                          ColorID::ScrollbarThumbActive,
-                                          ColorID::ScrollbarThumbInactive};
+  constexpr ColorID kColorIdsToCache[] = {
+      ColorID::ThemedScrollbar,
+      ColorID::ThemedScrollbarInactive,
+      ColorID::ThemedScrollbarThumb,
+      ColorID::ThemedScrollbarThumbHover,
+      ColorID::ThemedScrollbarThumbActive,
+      ColorID::ThemedScrollbarThumbInactive};
 
   for (IntID id : kIntIdsToCache) {
     cache.mInts.AppendElement(LookAndFeelInt{.id = id, .value = GetInt(id)});
   }
   for (ColorID id : kColorIdsToCache) {
     cache.mColors.AppendElement(
         LookAndFeelColor{.id = id, .color = GetColor(id)});
   }
@@ -305,33 +306,33 @@ void nsLookAndFeel::SetCacheImpl(const L
         break;
       default:
         MOZ_ASSERT_UNREACHABLE("Bogus Int ID in cache");
         break;
     }
   }
   for (const auto& entry : aCache.mColors) {
     switch (entry.id) {
-      case ColorID::Scrollbar:
-        mMozScrollbar = entry.color;
+      case ColorID::ThemedScrollbar:
+        mThemedScrollbar = entry.color;
         break;
-      case ColorID::ScrollbarInactive:
-        mScrollbarInactive = entry.color;
+      case ColorID::ThemedScrollbarInactive:
+        mThemedScrollbarInactive = entry.color;
         break;
-      case ColorID::ScrollbarThumb:
-        mScrollbarThumb = entry.color;
+      case ColorID::ThemedScrollbarThumb:
+        mThemedScrollbarThumb = entry.color;
         break;
-      case ColorID::ScrollbarThumbHover:
-        mScrollbarThumbHover = entry.color;
+      case ColorID::ThemedScrollbarThumbHover:
+        mThemedScrollbarThumbHover = entry.color;
         break;
-      case ColorID::ScrollbarThumbActive:
-        mScrollbarThumbActive = entry.color;
+      case ColorID::ThemedScrollbarThumbActive:
+        mThemedScrollbarThumbActive = entry.color;
         break;
-      case ColorID::ScrollbarThumbInactive:
-        mScrollbarThumbInactive = entry.color;
+      case ColorID::ThemedScrollbarThumbInactive:
+        mThemedScrollbarThumbInactive = entry.color;
         break;
       default:
         MOZ_ASSERT_UNREACHABLE("Bogus Color ID in cache");
         break;
     }
   }
 }
 
@@ -408,30 +409,33 @@ nsresult nsLookAndFeel::NativeGetColor(C
       break;
     case ColorID::IMESelectedRawTextUnderline:
     case ColorID::IMESelectedConvertedTextUnderline:
       aColor = NS_TRANSPARENT;
       break;
     case ColorID::SpellCheckerUnderline:
       aColor = NS_RGB(0xff, 0, 0);
       break;
-    case ColorID::ScrollbarInactive:
-      aColor = mScrollbarInactive;
+    case ColorID::ThemedScrollbar:
+      aColor = mThemedScrollbar;
       break;
-    case ColorID::ScrollbarThumb:
-      aColor = mScrollbarThumb;
+    case ColorID::ThemedScrollbarInactive:
+      aColor = mThemedScrollbarInactive;
+      break;
+    case ColorID::ThemedScrollbarThumb:
+      aColor = mThemedScrollbarThumb;
       break;
-    case ColorID::ScrollbarThumbHover:
-      aColor = mScrollbarThumbHover;
+    case ColorID::ThemedScrollbarThumbHover:
+      aColor = mThemedScrollbarThumbHover;
       break;
-    case ColorID::ScrollbarThumbActive:
-      aColor = mScrollbarThumbActive;
+    case ColorID::ThemedScrollbarThumbActive:
+      aColor = mThemedScrollbarThumbActive;
       break;
-    case ColorID::ScrollbarThumbInactive:
-      aColor = mScrollbarThumbInactive;
+    case ColorID::ThemedScrollbarThumbInactive:
+      aColor = mThemedScrollbarThumbInactive;
       break;
 
       // css2  http://www.w3.org/TR/REC-CSS2/ui.html#system-colors
     case ColorID::Activeborder:
       // active window border
       aColor = mMozWindowActiveBorder;
       break;
     case ColorID::Inactiveborder:
@@ -1075,35 +1079,35 @@ void nsLookAndFeel::EnsureInit() {
     gboolean enableAnimations = false;
     g_object_get(settings, "gtk-enable-animations", &enableAnimations, nullptr);
     mPrefersReducedMotion = !enableAnimations;
 
     // Colors that we pass to content processes through the LookAndFeelCache.
     style = GetStyleContext(MOZ_GTK_SCROLLBAR_TROUGH_VERTICAL);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
                                            &color);
-    mMozScrollbar = GDK_RGBA_TO_NS_RGBA(color);
+    mMozScrollbar = mThemedScrollbar = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_BACKDROP,
                                            &color);
-    mScrollbarInactive = GDK_RGBA_TO_NS_RGBA(color);
+    mThemedScrollbarInactive = GDK_RGBA_TO_NS_RGBA(color);
 
     style = GetStyleContext(MOZ_GTK_SCROLLBAR_THUMB_VERTICAL);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL,
                                            &color);
-    mScrollbarThumb = GDK_RGBA_TO_NS_RGBA(color);
+    mThemedScrollbarThumb = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_PRELIGHT,
                                            &color);
-    mScrollbarThumbHover = GDK_RGBA_TO_NS_RGBA(color);
+    mThemedScrollbarThumbHover = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_background_color(
         style, GtkStateFlags(GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE),
         &color);
-    mScrollbarThumbActive = GDK_RGBA_TO_NS_RGBA(color);
+    mThemedScrollbarThumbActive = GDK_RGBA_TO_NS_RGBA(color);
     gtk_style_context_get_background_color(style, GTK_STATE_FLAG_BACKDROP,
                                            &color);
-    mScrollbarThumbInactive = GDK_RGBA_TO_NS_RGBA(color);
+    mThemedScrollbarThumbInactive = GDK_RGBA_TO_NS_RGBA(color);
   }
 
   // The label is not added to a parent widget, but shared for constructing
   // different style contexts.  The node hierarchy is constructed only on
   // the label style context.
   GtkWidget* labelWidget = gtk_label_new("M");
   g_object_ref_sink(labelWidget);
 
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -85,21 +85,22 @@ class nsLookAndFeel final : public nsXPL
   nscolor mMozCellHighlightBackground = kWhite;
   nscolor mMozCellHighlightText = kBlack;
   nscolor mTextSelectedText = kBlack;
   nscolor mTextSelectedBackground = kWhite;
   nscolor mMozScrollbar = kWhite;
   nscolor mInfoBarText = kBlack;
   nscolor mMozColHeaderText = kBlack;
   nscolor mMozColHeaderHoverText = kBlack;
-  nscolor mScrollbarInactive = kBlack;
-  nscolor mScrollbarThumb = kBlack;
-  nscolor mScrollbarThumbHover = kBlack;
-  nscolor mScrollbarThumbActive = kBlack;
-  nscolor mScrollbarThumbInactive = kBlack;
+  nscolor mThemedScrollbar = kWhite;
+  nscolor mThemedScrollbarInactive = kWhite;
+  nscolor mThemedScrollbarThumb = kBlack;
+  nscolor mThemedScrollbarThumbHover = kBlack;
+  nscolor mThemedScrollbarThumbActive = kBlack;
+  nscolor mThemedScrollbarThumbInactive = kBlack;
   char16_t mInvisibleCharacter = 0;
   float mCaretRatio = 0.0f;
   int32_t mCaretBlinkTime = 0;
   bool mMenuSupportsDrag = false;
   bool mCSDAvailable = false;
   bool mCSDHideTitlebarByDefault = false;
   bool mCSDMaximizeButton = false;
   bool mCSDMinimizeButton = false;
--- a/widget/nsNativeBasicTheme.cpp
+++ b/widget/nsNativeBasicTheme.cpp
@@ -874,43 +874,46 @@ void nsNativeBasicTheme::PaintButton(nsI
 sRGBColor nsNativeBasicTheme::ComputeScrollbarthumbColor(
     const ComputedStyle& aStyle, const EventStates& aElementState,
     const EventStates& aDocumentState) {
   const nsStyleUI* ui = aStyle.StyleUI();
   nscolor color;
   if (ui->mScrollbarColor.IsColors()) {
     color = ui->mScrollbarColor.AsColors().thumb.CalcColor(aStyle);
   } else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ScrollbarThumbInactive,
-                                  sScrollbarThumbColor.ToABGR());
+    color = LookAndFeel::GetColor(
+        LookAndFeel::ColorID::ThemedScrollbarThumbInactive,
+        sScrollbarThumbColor.ToABGR());
   } else if (aElementState.HasAllStates(NS_EVENT_STATE_ACTIVE)) {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ScrollbarThumbActive,
-                                  sScrollbarThumbColorActive.ToABGR());
+    color =
+        LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbActive,
+                              sScrollbarThumbColorActive.ToABGR());
   } else if (aElementState.HasAllStates(NS_EVENT_STATE_HOVER)) {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ScrollbarThumbHover,
-                                  sScrollbarThumbColorHover.ToABGR());
+    color =
+        LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumbHover,
+                              sScrollbarThumbColorHover.ToABGR());
   } else {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ScrollbarThumb,
+    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarThumb,
                                   sScrollbarThumbColor.ToABGR());
   }
   return gfx::sRGBColor::FromABGR(color);
 }
 
 sRGBColor nsNativeBasicTheme::ComputeScrollbarColor(
     const ComputedStyle& aStyle, const EventStates& aDocumentState,
     bool aIsRoot) {
   const nsStyleUI* ui = aStyle.StyleUI();
   nscolor color;
   if (ui->mScrollbarColor.IsColors()) {
     color = ui->mScrollbarColor.AsColors().track.CalcColor(aStyle);
   } else if (aDocumentState.HasAllStates(NS_DOCUMENT_STATE_WINDOW_INACTIVE)) {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ScrollbarInactive,
+    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbarInactive,
                                   sScrollbarColor.ToABGR());
   } else {
-    color = LookAndFeel::GetColor(LookAndFeel::ColorID::Scrollbar,
+    color = LookAndFeel::GetColor(LookAndFeel::ColorID::ThemedScrollbar,
                                   sScrollbarColor.ToABGR());
   }
   if (aIsRoot) {
     // Root scrollbars must be opaque.
     nscolor bg = LookAndFeel::GetColor(LookAndFeel::ColorID::WindowBackground,
                                        NS_RGB(0xff, 0xff, 0xff));
     color = NS_ComposeColors(bg, color);
   }
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -141,21 +141,22 @@ const char nsXPLookAndFeel::sColorPrefs[
     "ui.IMESelectedRawTextUnderline",
     "ui.IMEConvertedTextBackground",
     "ui.IMEConvertedTextForeground",
     "ui.IMEConvertedTextUnderline",
     "ui.IMESelectedConvertedTextBackground",
     "ui.IMESelectedConvertedTextForeground",
     "ui.IMESelectedConvertedTextUnderline",
     "ui.SpellCheckerUnderline",
-    "ui.scrollbarInactive",
-    "ui.scrollbarThumb",
-    "ui.scrollbarThumbHover",
-    "ui.scrollbarThumbActive",
-    "ui.scrollbarThumbInactive",
+    "ui.themedScrollbar",
+    "ui.themedScrollbarInactive",
+    "ui.themedScrollbarThumb",
+    "ui.themedScrollbarThumbHover",
+    "ui.themedScrollbarThumbActive",
+    "ui.themedScrollbarThumbInactive",
     "ui.activeborder",
     "ui.activecaption",
     "ui.appworkspace",
     "ui.background",
     "ui.buttonface",
     "ui.buttonhighlight",
     "ui.buttonshadow",
     "ui.buttontext",