зеркало из 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:
Родитель
1a5439aa95
Коммит
84dabd109d
|
@ -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;
|
||||
|
@ -920,6 +910,17 @@ void nsLookAndFeel::EnsureInit() {
|
|||
GdkRGBA color;
|
||||
GtkStyleContext* style;
|
||||
|
||||
// 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)));
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче