From 4ad23f942b60b6f2623a095603746d1e936af003 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Wed, 10 Mar 2021 22:08:11 +0000 Subject: [PATCH] Bug 1546540 - Part 4: Support dark_theme Lightweight Theme variants on Linux, r=dao Previously due to the decision to use native styles on linux in the parent process, we would always ignore the dark_theme variant provided Lightweight Themes, in order to ignore the overrides used by the default theme. This changes that logic to respect dark_theme variants for all non-default themes on Linux, bring it closer to feature parity with other platforms. Differential Revision: https://phabricator.services.mozilla.com/D107774 --- toolkit/modules/LightweightThemeConsumer.jsm | 27 +++++++++----------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/toolkit/modules/LightweightThemeConsumer.jsm b/toolkit/modules/LightweightThemeConsumer.jsm index 52da2fe9a77e..5a616692520c 100644 --- a/toolkit/modules/LightweightThemeConsumer.jsm +++ b/toolkit/modules/LightweightThemeConsumer.jsm @@ -217,11 +217,8 @@ function LightweightThemeConsumer(aDocument) { Services.obs.addObserver(this, "lightweight-theme-styling-update"); - // In Linux, the default theme picks up the right colors from dark GTK themes. - if (AppConstants.platform != "linux") { - this.darkThemeMediaQuery = this._win.matchMedia("(-moz-system-dark-theme)"); - this.darkThemeMediaQuery.addListener(this); - } + this.darkThemeMediaQuery = this._win.matchMedia("(-moz-system-dark-theme)"); + this.darkThemeMediaQuery.addListener(this); const { LightweightThemeManager } = ChromeUtils.import( "resource://gre/modules/LightweightThemeManager.jsm" @@ -266,17 +263,17 @@ LightweightThemeConsumer.prototype = { } }, - get darkMode() { - return this.darkThemeMediaQuery && this.darkThemeMediaQuery.matches; - }, - _update(themeData) { this._lastData = themeData; - let theme = themeData.theme; - if (themeData.darkTheme && this.darkMode) { - theme = themeData.darkTheme; - } + // In Linux, the default theme picks up the right colors from dark GTK themes. + const useDarkTheme = + themeData.darkTheme && + this.darkThemeMediaQuery?.matches && + (themeData.darkTheme.id != DEFAULT_THEME_ID || + AppConstants.platform != "linux"); + + let theme = useDarkTheme ? themeData.darkTheme : themeData.theme; if (!theme) { theme = { id: DEFAULT_THEME_ID }; } @@ -301,13 +298,13 @@ LightweightThemeConsumer.prototype = { ); _setProperties(root, active, theme); - if (theme.id != DEFAULT_THEME_ID || this.darkMode) { + if (theme.id != DEFAULT_THEME_ID || useDarkTheme) { root.setAttribute("lwtheme", "true"); } else { root.removeAttribute("lwtheme"); root.removeAttribute("lwthemetextcolor"); } - if (theme.id == DEFAULT_THEME_ID && this.darkMode) { + if (theme.id == DEFAULT_THEME_ID && useDarkTheme) { root.setAttribute("lwt-default-theme-in-dark-mode", "true"); } else { root.removeAttribute("lwt-default-theme-in-dark-mode");