Browse Source

fix: add support for prefers-color-scheme CSS query (#19250)

The wiring to update prefs when you toggle between dark mode and light mode exists in the content layer but the actual value setting is done in either //chrome or in shell.  We need to set the preferred_color_scheme pref value in order for the CSS query to work correctly.  The DarkModeObserver in content will automatically regenerate prefs when dark mode is toggled.

Fixes #15540
trop[bot] 5 years ago
parent
commit
bb0f4fdbdf
1 changed files with 6 additions and 0 deletions
  1. 6 0
      atom/browser/atom_browser_client.cc

+ 6 - 0
atom/browser/atom_browser_client.cc

@@ -78,6 +78,7 @@
 #include "services/network/public/cpp/resource_request_body.h"
 #include "ui/base/l10n/l10n_util.h"
 #include "ui/base/resource/resource_bundle.h"
+#include "ui/native_theme/native_theme.h"
 #include "v8/include/v8.h"
 
 #if defined(OS_WIN)
@@ -392,6 +393,11 @@ void AtomBrowserClient::OverrideWebkitPrefs(content::RenderViewHost* host,
   prefs->default_maximum_page_scale_factor = 1.f;
   prefs->navigate_on_drag_drop = false;
 
+  ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
+  prefs->preferred_color_scheme = native_theme->SystemDarkModeEnabled()
+                                      ? blink::PreferredColorScheme::kDark
+                                      : blink::PreferredColorScheme::kLight;
+
   SetFontDefaults(prefs);
 
   // Custom preferences of guest page.