Bug 1525775 - [css-mediaqueries] Synthesize a value for eIntID_SystemUsesDarkTheme to determine if GTK are using a light or dark theme. r=heycam,karlt
☠☠ backed out by 659c7fae6ae4 ☠ ☠
authorMats Palmgren <mats@mozilla.com>
Mon, 18 Feb 2019 18:17:10 +0100
changeset 459822 133509097b7c
parent 459805 4a7c9fc1c794
child 459823 e919946fd913
push id35575
push usercbrindusan@mozilla.com
push dateTue, 19 Feb 2019 04:40:03 +0000
treeherdermozilla-central@ee6e77950205 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam, karlt
bugs1525775
milestone67.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 1525775 - [css-mediaqueries] Synthesize a value for eIntID_SystemUsesDarkTheme to determine if GTK are using a light or dark theme. r=heycam,karlt
widget/gtk/nsLookAndFeel.cpp
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -701,16 +701,28 @@ nsresult nsLookAndFeel::GetIntImpl(IntID
       gboolean enableAnimations;
 
       settings = gtk_settings_get_default();
       g_object_get(settings, "gtk-enable-animations", &enableAnimations,
                    nullptr);
       aResult = enableAnimations ? 0 : 1;
       break;
     }
+    case eIntID_SystemUsesDarkTheme: {
+      // It seems GTK doesn't have an API to query if the current theme is
+      // "light" or "dark", so we synthesize it from the CSS2 Window/WindowText
+      // colors instead, by comparing their luminosity.
+      nscolor fg, bg;
+      if (NS_SUCCEEDED(NativeGetColor(eColorID_windowtext, fg)) &&
+          NS_SUCCEEDED(NativeGetColor(eColorID_window, bg))) {
+        aResult = NS_GetLuminosity(bg) < NS_GetLuminosity(fg) ? 1 : 0;
+        break;
+      }
+      MOZ_FALLTHROUGH;
+    }
     default:
       aResult = 0;
       res = NS_ERROR_FAILURE;
   }
 
   return res;
 }