зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1555565 - Export correct user's preference for dark theme by prefers-color-scheme media query, r=mats
Differential Revision: https://phabricator.services.mozilla.com/D33133 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
4aedd52bab
Коммит
df1a302293
|
@ -700,19 +700,9 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
|
|||
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(ColorID::Windowtext, fg)) &&
|
||||
NS_SUCCEEDED(NativeGetColor(ColorID::Window, bg))) {
|
||||
aResult = (RelativeLuminanceUtils::Compute(bg) <
|
||||
RelativeLuminanceUtils::Compute(fg))
|
||||
? 1
|
||||
: 0;
|
||||
break;
|
||||
}
|
||||
MOZ_FALLTHROUGH;
|
||||
EnsureInit();
|
||||
aResult = mSystemUsesDarkTheme;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
aResult = 0;
|
||||
|
@ -911,7 +901,24 @@ void nsLookAndFeel::EnsureInit() {
|
|||
GdkColor colorValue;
|
||||
GdkColor* colorValuePtr;
|
||||
|
||||
if (mInitialized) return;
|
||||
if (mInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Gtk manages a screen's CSS in the settings object so we
|
||||
// ask Gtk to create it explicitly. Otherwise we may end up
|
||||
// with wrong color theme, see Bug 972382
|
||||
GdkScreen* screen = gdk_screen_get_default();
|
||||
if (MOZ_UNLIKELY(!screen)) {
|
||||
NS_WARNING("EnsureInit: No screen");
|
||||
return;
|
||||
}
|
||||
GtkSettings* settings = gtk_settings_get_for_screen(screen);
|
||||
if (MOZ_UNLIKELY(!settings)) {
|
||||
NS_WARNING("EnsureInit: No settings");
|
||||
return;
|
||||
}
|
||||
|
||||
mInitialized = true;
|
||||
|
||||
// gtk does non threadsafe refcounting
|
||||
|
@ -920,15 +927,16 @@ void nsLookAndFeel::EnsureInit() {
|
|||
GdkRGBA color;
|
||||
GtkStyleContext* style;
|
||||
|
||||
// Gtk manages a screen's CSS in the settings object so we
|
||||
// ask Gtk to create it explicitly. Otherwise we may end up
|
||||
// with wrong color theme, see Bug 972382
|
||||
GtkSettings* settings = gtk_settings_get_for_screen(gdk_screen_get_default());
|
||||
|
||||
if (MOZ_UNLIKELY(!settings)) {
|
||||
NS_WARNING("EnsureInit: No settings");
|
||||
return;
|
||||
}
|
||||
// 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.
|
||||
GdkRGBA bg, fg;
|
||||
style = GetStyleContext(MOZ_GTK_WINDOW);
|
||||
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_NORMAL, &bg);
|
||||
gtk_style_context_get_color(style, GTK_STATE_FLAG_NORMAL, &fg);
|
||||
mSystemUsesDarkTheme =
|
||||
(RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(bg)) <
|
||||
RelativeLuminanceUtils::Compute(GDK_RGBA_TO_NS_RGBA(fg)));
|
||||
|
||||
if (XRE_IsContentProcess()) {
|
||||
// Dark themes interacts poorly with widget styling (see bug 1216658).
|
||||
|
|
|
@ -95,6 +95,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
|||
bool mCSDMinimizeButton = false;
|
||||
bool mCSDCloseButton = false;
|
||||
bool mCSDReversedPlacement = false;
|
||||
bool mSystemUsesDarkTheme = false;
|
||||
bool mInitialized = false;
|
||||
|
||||
void EnsureInit();
|
||||
|
|
Загрузка…
Ссылка в новой задаче