Commit 23415198 authored by Ionel Popescu's avatar Ionel Popescu Committed by Commit Bot

Correctly initialize web theme state on Mac.

With FormControlsRefresh, the used native theme web instance
is NativeThemeAura instead of NativeThemeMac.

Prior to this CL, there was no support to initialize the dark mode,
preferred color scheme and high contrast states for NativeThemeAura.

Note that these states are going to be sent to the renderer processes
by using the communication mechanism introduced by [1].

[1]: crrev.com/c/1728056

Bug: 1054725
Change-Id: I45f0d382b70bd1e616cfb8e4a59bc3db392d744a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2068870Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Ionel Popescu <iopopesc@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#743970}
parent 7809fc42
...@@ -81,6 +81,8 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase { ...@@ -81,6 +81,8 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
void InitializeDarkModeStateAndObserver(); void InitializeDarkModeStateAndObserver();
void InitializeWebThemeState() const;
base::scoped_nsobject<NativeThemeEffectiveAppearanceObserver> base::scoped_nsobject<NativeThemeEffectiveAppearanceObserver>
appearance_observer_; appearance_observer_;
id high_contrast_notification_token_; id high_contrast_notification_token_;
......
...@@ -299,6 +299,8 @@ NativeThemeMac::NativeThemeMac() { ...@@ -299,6 +299,8 @@ NativeThemeMac::NativeThemeMac() {
}]; }];
} }
InitializeWebThemeState();
// Add the web native theme as an observer to stay in sync with dark mode, // Add the web native theme as an observer to stay in sync with dark mode,
// high contrast, and preferred color scheme changes. // high contrast, and preferred color scheme changes.
if (features::IsFormControlsRefreshEnabled()) { if (features::IsFormControlsRefreshEnabled()) {
...@@ -336,4 +338,16 @@ void NativeThemeMac::InitializeDarkModeStateAndObserver() { ...@@ -336,4 +338,16 @@ void NativeThemeMac::InitializeDarkModeStateAndObserver() {
}]); }]);
} }
void NativeThemeMac::InitializeWebThemeState() const {
if (!features::IsFormControlsRefreshEnabled())
return;
// For FormControlsRefresh, NativeThemeAura is used as web instance so we need
// to initialize its state.
NativeTheme* web_instance = NativeTheme::GetInstanceForWeb();
web_instance->set_use_dark_colors(IsDarkMode());
web_instance->set_preferred_color_scheme(CalculatePreferredColorScheme());
web_instance->set_high_contrast(IsHighContrast());
}
} // namespace ui } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment