mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user