Merge autoland to mozilla-central. a=merge
authorCsoregi Natalia <ncsoregi@mozilla.com>
Sun, 23 Jan 2022 23:47:07 +0200
changeset 605272 5c51b325c09f22a0d9384cfc5198f27ec9bdbfc8
parent 605264 72cf281f386ba04ce2ed40ef7fc1ceaf696cb703 (current diff)
parent 605271 1ce9d23799c35921a9458d145a50b5a57f1baea4 (diff)
child 605273 483fbf725784dd8494a9f2e80caba2a114a49493
child 605282 3ce30079b03ba4820640eabbb8157e2f09c656f3
push id39185
push userncsoregi@mozilla.com
push dateSun, 23 Jan 2022 21:48:50 +0000
treeherdermozilla-central@5c51b325c09f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone98.0a1
first release with
nightly linux32
5c51b325c09f / 98.0a1 / 20220123214850 / files
nightly linux64
5c51b325c09f / 98.0a1 / 20220123214850 / files
nightly mac
5c51b325c09f / 98.0a1 / 20220123214850 / files
nightly win32
5c51b325c09f / 98.0a1 / 20220123214850 / files
nightly win64
5c51b325c09f / 98.0a1 / 20220123214850 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge autoland to mozilla-central. a=merge
--- a/dom/xml/resources/XMLPrettyPrint.css
+++ b/dom/xml/resources/XMLPrettyPrint.css
@@ -1,22 +1,33 @@
 @charset "UTF-8";
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 @import url("resource://content-accessible/viewsource.css");
 
+:host {
+  color-scheme: light dark;
+}
+
 #header {
   background-color: #ccc;
   border-bottom: 3px solid black;
   padding: 0.5em;
   margin-bottom: 1em;
 }
 
+@media (prefers-color-scheme: dark) {
+  #header {
+    background-color: #333;
+    border-color: #555;
+  }
+}
+
 #tree,
 .expandable-children {
   margin-inline-start: 1em;
 }
 
 .expandable-body {
   display: inline-block;
 }
@@ -32,16 +43,16 @@
 [open] > .expandable-opening {
   list-style-type: '−';
 }
 
 .expandable-opening::marker {
   cursor: pointer;
   padding-inline-end: 2px;
   /* Don't want to inherit the styling from pi and comment elements */
-  color: initial;
+  color: buttontext;
   font: initial;
 }
 
 .comment {
   font-family: monospace;
   white-space: pre;
 }
--- a/layout/style/res/viewsource.css
+++ b/layout/style/res/viewsource.css
@@ -1,18 +1,17 @@
 @charset "utf-8";
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 @namespace url(http://www.w3.org/1999/xhtml); /* set default namespace to HTML */
 
 *|*:root {
-  background-color: white;
-  color: black;
+  color-scheme: light dark;
   direction: ltr;
   -moz-control-character-visibility: visible;
   height: 100%;
 }
 #viewsource {
   font-family: -moz-fixed;
   font-weight: normal;
   white-space: pre;
@@ -40,62 +39,80 @@ span[id]:before {
   display: inline-block;
   width: 5ch;
   margin: 0 0 0 -5ch;
   text-align: right;
   color: #ccc;
   font-weight: normal;
   font-style: normal;
 }
-.highlight .start-tag {
- color: purple;
- font-weight: bold;
-}
+.highlight .start-tag,
 .highlight .end-tag {
- color: purple;
- font-weight: bold;
+  color: purple;
+  font-weight: bold;
 }
 .highlight .comment {
- color: green;
- font-style: italic;
+  color: green;
+  font-style: italic;
 }
 .highlight .cdata {
- color: #CC0066;
+  color: #CC0066;
 }
-.highlight .doctype {
- color: steelblue;
- font-style: italic;
+.highlight .doctype,
+.highlight .markupdeclaration {
+  color: steelblue;
+  font-style: italic;
 }
 .highlight .pi {
- color: orchid;
- font-style: italic;
+  color: orchid;
+  font-style: italic;
 }
 .highlight .entity {
- color: #FF4500;
- font-weight: normal;
+  color: #FF4500;
+  font-weight: normal;
 }
 .highlight .text {
   font-weight: normal;
 }
 .highlight .attribute-name {
- color: black;
- font-weight: bold;
+  font-weight: bold;
 }
 .highlight .attribute-value {
- color: blue;
- font-weight: normal;
+  color: blue;
+  font-weight: normal;
 }
-.highlight .markupdeclaration {
- color: steelblue;
- font-style: italic;
-}
-span:not(.error), a:not(.error) {
- unicode-bidi: embed;
+span:not(.error),
+a:not(.error) {
+  unicode-bidi: embed;
 }
 span[id] {
- unicode-bidi: isolate;
+  unicode-bidi: isolate;
+}
+.highlight .error {
+  color: revert;
+  font-weight: bold;
+  text-decoration: underline;
+  text-decoration-color: red;
+  text-decoration-style: dotted;
+  text-decoration-skip-ink: none;
 }
-.highlight .error,
-.highlight .error > :is(.start-tag, .end-tag, .comment, .cdata, .doctype,
-                        .pi, .entity, .attribute-name, .attribute-value) {
-  color: red;
-  font-weight: bold;
+@media (prefers-color-scheme: dark) {
+  .highlight .start-tag,
+  .highlight .end-tag {
+    color: #f55e5e;
+  }
+  .highlight .comment {
+    color: lightgreen;
+  }
+  .highlight .cdata {
+    color: #f068ac;
+  }
+  .highlight .doctype,
+  .highlight .markupdeclaration {
+    color: lightgray;
+  }
+  .highlight .entity {
+    color: #f18a65;
+  }
+  .highlight .attribute-value {
+    color: #97bbff;
+  }
 }
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -12517,25 +12517,16 @@
 #endif
 
 # Whether to allow gtk dark themes in content.
 - name: widget.content.allow-gtk-dark-theme
   type: RelaxedAtomicBool
   value: false
   mirror: always
 
-# Whether we try to extract dark theme GTK colors.
-#
-# For now, needed for follow-firefox-theme. In the future will also be needed
-# for the color-scheme CSS property / meta tag / etc.
-- name: widget.gtk.alt-theme.dark
-  type: bool
-  value: true
-  mirror: always
-
 # Whether selection colors for the non-system theme get passed from the system
 # GTK theme.
 - name: widget.gtk.alt-theme.selection
   type: bool
   value: true
   mirror: always
 
 # Whether form control accent colors for the non-system theme get passed from
--- a/toolkit/themes/osx/global/dirListing/dirListing.css
+++ b/toolkit/themes/osx/global/dirListing/dirListing.css
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 :root {
   background-color: -moz-dialog;
   color: -moz-dialogtext;
   font: message-box;
   padding-inline: 2em;
+  color-scheme: light dark;
 }
 
 body {
   border: 1px solid ThreeDShadow;
   border-radius: 10px;
   padding: 3em;
   min-width: 30em;
   max-width: 65em;
--- a/toolkit/themes/windows/global/dirListing/dirListing.css
+++ b/toolkit/themes/windows/global/dirListing/dirListing.css
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 :root {
   background-color: -moz-dialog;
   color: -moz-dialogtext;
   font: message-box;
   padding-inline: 2em;
+  color-scheme: light dark;
 }
 
 body {
   border: 1px solid ThreeDShadow;
   border-radius: 10px;
   padding: 3em;
   min-width: 30em;
   max-width: 65em;
--- a/widget/gtk/nsLookAndFeel.cpp
+++ b/widget/gtk/nsLookAndFeel.cpp
@@ -892,17 +892,21 @@ nsresult nsLookAndFeel::NativeGetInt(Int
       aResult = mCSDReversedPlacement;
       break;
     case IntID::PrefersReducedMotion: {
       aResult = mPrefersReducedMotion;
       break;
     }
     case IntID::SystemUsesDarkTheme: {
       EnsureInit();
-      aResult = mSystemTheme.mIsDark;
+      if (mColorSchemePreference) {
+        aResult = *mColorSchemePreference == ColorScheme::Dark;
+      } else {
+        aResult = mSystemTheme.mIsDark;
+      }
       break;
     }
     case IntID::GTKCSDMaximizeButtonPosition:
       aResult = mCSDMaximizeButtonPosition;
       break;
     case IntID::GTKCSDMinimizeButtonPosition:
       aResult = mCSDMinimizeButtonPosition;
       break;
@@ -1150,44 +1154,47 @@ void nsLookAndFeel::ConfigureTheme(const
   MOZ_ASSERT(XRE_IsContentProcess());
   GtkSettings* settings = gtk_settings_get_default();
   g_object_set(settings, "gtk-theme-name", aTheme.themeName().get(),
                "gtk-application-prefer-dark-theme",
                aTheme.preferDarkTheme() ? TRUE : FALSE, nullptr);
 }
 
 void nsLookAndFeel::RestoreSystemTheme() {
-  LOGLNF("RestoreSystemTheme(%s, %d)\n", mSystemTheme.mName.get(),
-         mSystemTheme.mPreferDarkTheme);
+  LOGLNF("RestoreSystemTheme(%s, %d, %d)\n", mSystemTheme.mName.get(),
+         mSystemTheme.mPreferDarkTheme, mSystemThemeOverridden);
+
+  if (!mSystemThemeOverridden) {
+    return;
+  }
 
   // Available on Gtk 3.20+.
   static auto sGtkSettingsResetProperty =
       (void (*)(GtkSettings*, const gchar*))dlsym(
           RTLD_DEFAULT, "gtk_settings_reset_property");
 
   GtkSettings* settings = gtk_settings_get_default();
   if (sGtkSettingsResetProperty) {
     sGtkSettingsResetProperty(settings, "gtk-theme-name");
     sGtkSettingsResetProperty(settings, "gtk-application-prefer-dark-theme");
-    // If the prefer-dark-theme value was overridden by the dbus setting, make
-    // sure to keep it.
-    if (mSystemTheme.mPreferDarkTheme != GetPreferDarkTheme()) {
-      g_object_set(settings, "gtk-application-prefer-dark-theme",
-                   mSystemTheme.mPreferDarkTheme, nullptr);
-    }
   } else {
     g_object_set(settings, "gtk-theme-name", mSystemTheme.mName.get(),
                  "gtk-application-prefer-dark-theme",
                  mSystemTheme.mPreferDarkTheme, nullptr);
   }
   moz_gtk_refresh();
+  mSystemThemeOverridden = false;
 }
 
-template <typename Callback>
-void nsLookAndFeel::WithAltThemeConfigured(const Callback& aFn) {
+static bool AnyColorChannelIsDifferent(nscolor aColor) {
+  return NS_GET_R(aColor) != NS_GET_G(aColor) ||
+         NS_GET_R(aColor) != NS_GET_B(aColor);
+}
+
+void nsLookAndFeel::ConfigureAndInitializeAltTheme() {
   GtkSettings* settings = gtk_settings_get_default();
 
   bool fellBackToDefaultTheme = false;
 
   // Try to select the opposite variant of the current theme first...
   LOGLNF("    toggling gtk-application-prefer-dark-theme\n");
   g_object_set(settings, "gtk-application-prefer-dark-theme",
                !mSystemTheme.mIsDark, nullptr);
@@ -1227,61 +1234,51 @@ void nsLookAndFeel::WithAltThemeConfigur
     // If the theme still didn't change enough, fall back to either Adwaita or
     // Adwaita-dark.
     g_object_set(settings, "gtk-theme-name",
                  mSystemTheme.mIsDark ? "Adwaita" : "Adwaita-dark", nullptr);
     moz_gtk_refresh();
     fellBackToDefaultTheme = true;
   }
 
-  aFn(fellBackToDefaultTheme);
-
-  // Restore the system theme.
-  RestoreSystemTheme();
-}
-
-static bool AnyColorChannelIsDifferent(nscolor aColor) {
-  return NS_GET_R(aColor) != NS_GET_G(aColor) ||
-         NS_GET_R(aColor) != NS_GET_B(aColor);
-}
+  mAltTheme.Init();
 
-void nsLookAndFeel::InitializeAltTheme() {
-  WithAltThemeConfigured([&](bool aFellBackToDefaultTheme) {
-    mAltTheme.Init();
-    // Some of the alt theme colors we can grab from the system theme, if we
-    // fell back to the default light / dark themes.
-    if (aFellBackToDefaultTheme) {
-      if (StaticPrefs::widget_gtk_alt_theme_selection()) {
-        mAltTheme.mTextSelectedText = mSystemTheme.mTextSelectedText;
-        mAltTheme.mTextSelectedBackground =
-            mSystemTheme.mTextSelectedBackground;
-      }
+  // Some of the alt theme colors we can grab from the system theme, if we fell
+  // back to the default light / dark themes.
+  if (fellBackToDefaultTheme) {
+    if (StaticPrefs::widget_gtk_alt_theme_selection()) {
+      mAltTheme.mTextSelectedText = mSystemTheme.mTextSelectedText;
+      mAltTheme.mTextSelectedBackground = mSystemTheme.mTextSelectedBackground;
+    }
 
-      if (StaticPrefs::widget_gtk_alt_theme_scrollbar()) {
-        mAltTheme.mThemedScrollbar = mSystemTheme.mThemedScrollbar;
-        mAltTheme.mThemedScrollbarInactive =
-            mSystemTheme.mThemedScrollbarInactive;
-        mAltTheme.mThemedScrollbarThumb = mSystemTheme.mThemedScrollbarThumb;
-        mAltTheme.mThemedScrollbarThumbHover =
-            mSystemTheme.mThemedScrollbarThumbHover;
-        mAltTheme.mThemedScrollbarThumbInactive =
-            mSystemTheme.mThemedScrollbarThumbInactive;
-      }
+    if (StaticPrefs::widget_gtk_alt_theme_scrollbar()) {
+      mAltTheme.mThemedScrollbar = mSystemTheme.mThemedScrollbar;
+      mAltTheme.mThemedScrollbarInactive =
+          mSystemTheme.mThemedScrollbarInactive;
+      mAltTheme.mThemedScrollbarThumb = mSystemTheme.mThemedScrollbarThumb;
+      mAltTheme.mThemedScrollbarThumbHover =
+          mSystemTheme.mThemedScrollbarThumbHover;
+      mAltTheme.mThemedScrollbarThumbInactive =
+          mSystemTheme.mThemedScrollbarThumbInactive;
+    }
 
-      if (StaticPrefs::widget_gtk_alt_theme_scrollbar_active()) {
-        mAltTheme.mThemedScrollbarThumbActive =
-            mSystemTheme.mThemedScrollbarThumbActive;
-      }
+    if (StaticPrefs::widget_gtk_alt_theme_scrollbar_active()) {
+      mAltTheme.mThemedScrollbarThumbActive =
+          mSystemTheme.mThemedScrollbarThumbActive;
+    }
 
-      if (StaticPrefs::widget_gtk_alt_theme_selection()) {
-        mAltTheme.mAccentColor = mSystemTheme.mAccentColor;
-        mAltTheme.mAccentColorForeground = mSystemTheme.mAccentColorForeground;
-      }
+    if (StaticPrefs::widget_gtk_alt_theme_selection()) {
+      mAltTheme.mAccentColor = mSystemTheme.mAccentColor;
+      mAltTheme.mAccentColorForeground = mSystemTheme.mAccentColorForeground;
     }
-  });
+  }
+
+  // Right now we're using the opposite color-scheme theme, make sure to record
+  // it.
+  mSystemThemeOverridden = true;
 }
 
 Maybe<ColorScheme> nsLookAndFeel::ComputeColorSchemeSetting() {
   if (!mDBusSettingsProxy) {
     return Nothing();
   }
   GError* error = nullptr;
   RefPtr<GVariant> variant = dont_AddRef(g_dbus_proxy_call_sync(
@@ -1307,57 +1304,62 @@ Maybe<ColorScheme> nsLookAndFeel::Comput
     return Some(ColorScheme::Dark);
   }
   // If we get a valid, non-dark value from DBus, even if it's "no preference",
   // then we need to return a light color scheme, so that we properly override
   // it on changes.
   return Some(ColorScheme::Light);
 }
 
-void nsLookAndFeel::EnsureInit() {
-  if (mInitialized) {
-    return;
-  }
-
-  LOGLNF("nsLookAndFeel::EnsureInit");
+void nsLookAndFeel::Initialize() {
+  LOGLNF("nsLookAndFeel::Initialize");
+  MOZ_DIAGNOSTIC_ASSERT(!mInitialized);
+  MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread(),
+                        "LookAndFeel init should be done on the main thread");
 
-  AutoRestore<bool> restoreIgnoreSettings(sIgnoreChangedSettings);
-  sIgnoreChangedSettings = true;
+  mInitialized = true;
 
-  // 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_default();
   if (MOZ_UNLIKELY(!settings)) {
     NS_WARNING("EnsureInit: No settings");
     return;
   }
 
-  mInitialized = true;
-  if (mSystemThemeOverridden) {
-    // Our current theme may be different from the system theme if we're
-    // matching the firefox theme. Make sure to restore the original system
-    // theme.
-    RestoreSystemTheme();
-    mSystemThemeOverridden = false;
-  }
+  AutoRestore<bool> restoreIgnoreSettings(sIgnoreChangedSettings);
+  sIgnoreChangedSettings = true;
+
+  // Our current theme may be different from the system theme if we're matching
+  // the Firefox theme or using the alt theme intentionally due to the
+  // color-scheme preference. Make sure to restore the original system theme.
+  RestoreSystemTheme();
+
+  // First initialize global settings.
+  InitializeGlobalSettings();
+
+  // Record our system theme settings now.
+  mSystemTheme.Init();
 
-  // gtk does non threadsafe refcounting
-  MOZ_ASSERT(NS_IsMainThread());
+  // Find the alternative-scheme theme (light if the system theme is dark, or
+  // vice versa), configure it and initialize it.
+  ConfigureAndInitializeAltTheme();
+
+  LOGLNF("System Theme: %s. Alt Theme: %s\n", mSystemTheme.mName.get(),
+         mAltTheme.mName.get());
 
-  if (auto scheme = ComputeColorSchemeSetting()) {
-    // DBus settings color-scheme override the default. Ensure that this happens
-    // before the mSystemTheme.Init() call so that it gets correctly picked up.
-    bool dark = *scheme == ColorScheme::Dark;
-    if (dark != GetPreferDarkTheme()) {
-      g_object_set(settings, "gtk-application-prefer-dark-theme", dark,
-                   nullptr);
-      moz_gtk_refresh();
-    }
-  }
+  // Go back to the system theme or keep the alt theme configured, depending on
+  // Firefox theme or user color-scheme preference.
+  ConfigureFinalEffectiveTheme();
+
+  RecordTelemetry();
+}
+
+void nsLookAndFeel::InitializeGlobalSettings() {
+  GtkSettings* settings = gtk_settings_get_default();
+
+  mColorSchemePreference = ComputeColorSchemeSetting();
 
   gboolean enableAnimations = false;
   g_object_get(settings, "gtk-enable-animations", &enableAnimations, nullptr);
   mPrefersReducedMotion = !enableAnimations;
 
   gint blink_time = 0;     // In milliseconds
   gint blink_timeout = 0;  // in seconds
   gboolean blink;
@@ -1376,18 +1378,16 @@ void nsLookAndFeel::EnsureInit() {
     // blink_time * 2 because blink count is a full blink cycle.
     mCaretBlinkCount =
         std::max(1, int32_t(std::ceil(float(blink_timeout * 1000) /
                                       (float(blink_time) * 2.0f))));
   } else {
     mCaretBlinkCount = -1;
   }
 
-  mSystemTheme.Init();
-
   mCSDCloseButton = false;
   mCSDMinimizeButton = false;
   mCSDMaximizeButton = false;
   mCSDCloseButtonPosition = 0;
   mCSDMinimizeButtonPosition = 0;
   mCSDMaximizeButtonPosition = 0;
 
   // We need to initialize whole CSD config explicitly because it's queried
@@ -1418,81 +1418,64 @@ void nsLookAndFeel::EnsureInit() {
       default:
         break;
     }
 
     if (pos) {
       *pos = i;
     }
   }
-
-  // Switching themes on startup has some performance cost, so until we use the
-  // dark colors, keep it pref'd off.
-  if (mSystemTheme.mIsDark || StaticPrefs::widget_gtk_alt_theme_dark()) {
-    InitializeAltTheme();
-  } else {
-    mAltTheme = mSystemTheme;
-  }
-
-  LOGLNF("System Theme: %s. Alt Theme: %s\n", mSystemTheme.mName.get(),
-         mAltTheme.mName.get());
-
-  MatchFirefoxThemeIfNeeded();
-
-  RecordTelemetry();
 }
 
-bool nsLookAndFeel::MatchFirefoxThemeIfNeeded() {
-  AutoRestore<bool> restoreIgnoreSettings(sIgnoreChangedSettings);
-  sIgnoreChangedSettings = true;
+void nsLookAndFeel::ConfigureFinalEffectiveTheme() {
+  MOZ_ASSERT(mSystemThemeOverridden,
+             "By this point, the alt theme should be configured");
 
-  const bool matchesSystem = [&] {
+  const bool shouldUseSystemTheme = [&] {
     // NOTE: We can't call ColorSchemeForChrome directly because this might run
     // while we're computing it.
     switch (ColorSchemeSettingForChrome()) {
       case ChromeColorSchemeSetting::Light:
         return !mSystemTheme.mIsDark;
       case ChromeColorSchemeSetting::Dark:
         return mSystemTheme.mIsDark;
       case ChromeColorSchemeSetting::System:
         break;
     };
-    return true;
+    if (!mColorSchemePreference) {
+      return true;
+    }
+    bool preferenceIsDark = *mColorSchemePreference == ColorScheme::Dark;
+    return preferenceIsDark == mSystemTheme.mIsDark;
   }();
 
   const bool usingSystem = !mSystemThemeOverridden;
-
-  LOGLNF("MatchFirefoxThemeIfNeeded(matchesSystem=%d, usingSystem=%d)\n",
-         matchesSystem, usingSystem);
+  LOGLNF("OverrideSystemThemeIfNeeded(matchesSystem=%d, usingSystem=%d)\n",
+         shouldUseSystemTheme, usingSystem);
 
-  if (usingSystem == matchesSystem) {
-    return false;
-  }
-
-  mSystemThemeOverridden = !matchesSystem;
-  if (matchesSystem) {
+  if (shouldUseSystemTheme) {
     RestoreSystemTheme();
-  } else {
+  } else if (usingSystem) {
     LOGLNF("Setting theme %s, %d\n", mAltTheme.mName.get(),
            mAltTheme.mPreferDarkTheme);
 
     GtkSettings* settings = gtk_settings_get_default();
     if (mSystemTheme.mName == mAltTheme.mName) {
       // Prefer setting only gtk-application-prefer-dark-theme, so we can still
       // get notified from notify::gtk-theme-name if the user changes the theme.
       g_object_set(settings, "gtk-application-prefer-dark-theme",
                    mAltTheme.mPreferDarkTheme, nullptr);
     } else {
       g_object_set(settings, "gtk-theme-name", mAltTheme.mName.get(),
                    "gtk-application-prefer-dark-theme",
                    mAltTheme.mPreferDarkTheme, nullptr);
     }
     moz_gtk_refresh();
+    mSystemThemeOverridden = true;
   }
-  return true;
 }
 
 void nsLookAndFeel::GetGtkContentTheme(LookAndFeelTheme& aTheme) {
   if (NS_SUCCEEDED(Preferences::GetCString("widget.content.gtk-theme-override",
                                            aTheme.themeName()))) {
     return;
   }
 
--- a/widget/gtk/nsLookAndFeel.h
+++ b/widget/gtk/nsLookAndFeel.h
@@ -30,21 +30,16 @@ class nsLookAndFeel final : public nsXPL
   bool NativeGetFont(FontID aID, nsString& aFontName,
                      gfxFontStyle& aFontStyle) override;
 
   char16_t GetPasswordCharacterImpl() override;
   bool GetEchoPasswordImpl() override;
 
   bool GetDefaultDrawInTitlebar() override;
 
-  template <typename Callback>
-  void WithAltThemeConfigured(const Callback&);
-
-  void InitializeAltTheme();
-
   void GetGtkContentTheme(LookAndFeelTheme&) override;
   void GetThemeInfo(nsACString&) override;
 
   static void ConfigureTheme(const LookAndFeelTheme& aTheme);
 
   static const nscolor kBlack = NS_RGB(0, 0, 0);
   static const nscolor kWhite = NS_RGB(255, 255, 255);
 
@@ -139,42 +134,51 @@ class nsLookAndFeel final : public nsXPL
 
   PerThemeData mSystemTheme;
 
   // If the system theme is light, a dark theme. Otherwise, a light theme. The
   // alternative theme to the current one is preferred, but otherwise we fall
   // back to Adwaita / Adwaita Dark, respectively.
   PerThemeData mAltTheme;
 
-  GDBusProxy* mDBusSettingsProxy = nullptr;
-
   const PerThemeData& LightTheme() const {
     return mSystemTheme.mIsDark ? mAltTheme : mSystemTheme;
   }
 
   const PerThemeData& DarkTheme() const {
     return mSystemTheme.mIsDark ? mSystemTheme : mAltTheme;
   }
 
   const PerThemeData& EffectiveTheme() const {
     return mSystemThemeOverridden ? mAltTheme : mSystemTheme;
   }
 
+  GDBusProxy* mDBusSettingsProxy = nullptr;
+  mozilla::Maybe<ColorScheme> mColorSchemePreference;
   int32_t mCaretBlinkTime = 0;
   int32_t mCaretBlinkCount = -1;
   bool mCSDMaximizeButton = false;
   bool mCSDMinimizeButton = false;
   bool mCSDCloseButton = false;
   bool mCSDReversedPlacement = false;
   bool mPrefersReducedMotion = false;
   bool mInitialized = false;
   bool mSystemThemeOverridden = false;
   int32_t mCSDMaximizeButtonPosition = 0;
   int32_t mCSDMinimizeButtonPosition = 0;
   int32_t mCSDCloseButtonPosition = 0;
 
-  void EnsureInit();
+  void EnsureInit() {
+    if (mInitialized) {
+      return;
+    }
+    Initialize();
+  }
+
+  void Initialize();
 
   void RestoreSystemTheme();
-  bool MatchFirefoxThemeIfNeeded();
+  void InitializeGlobalSettings();
+  void ConfigureAndInitializeAltTheme();
+  void ConfigureFinalEffectiveTheme();
 };
 
 #endif