Commit acdbed99 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Add the ColorSchemeNativeThemeObserver on Mac

If certain flags are enabled, NativeThemeMac may return a different
NativeTheme instance for NativeTheme::GetInstanceForWeb(). This will
cause NativeTheme::GetInstanceForWeb() on Mac to be out of sync
in terms of dark mode and high contrast.

To fix this, NativeTheme::GetInstanceForWeb() is added as an
observer of NativeTheme::GetInstanceForNativeUi() in these cases.

Bug: 970285
Change-Id: I832d182647f81491a761a071bc5633c2efdeedb0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834028Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#702902}
parent e7227b3e
...@@ -85,6 +85,11 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase { ...@@ -85,6 +85,11 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
appearance_observer_; appearance_observer_;
id high_contrast_notification_token_; id high_contrast_notification_token_;
// Used to notify the web native theme of changes to dark mode and high
// contrast.
std::unique_ptr<NativeTheme::ColorSchemeNativeThemeObserver>
color_scheme_observer_;
DISALLOW_COPY_AND_ASSIGN(NativeThemeMac); DISALLOW_COPY_AND_ASSIGN(NativeThemeMac);
}; };
......
...@@ -299,6 +299,15 @@ NativeThemeMac::NativeThemeMac() { ...@@ -299,6 +299,15 @@ NativeThemeMac::NativeThemeMac() {
theme->NotifyObservers(); theme->NotifyObservers();
}]; }];
} }
// Add the web native theme as an observer to stay in sync with dark mode,
// high contrast, and preferred color scheme changes.
if (features::IsFormControlsRefreshEnabled()) {
color_scheme_observer_ =
std::make_unique<NativeTheme::ColorSchemeNativeThemeObserver>(
NativeTheme::GetInstanceForWeb());
AddObserver(color_scheme_observer_.get());
}
} }
NativeThemeMac::~NativeThemeMac() { NativeThemeMac::~NativeThemeMac() {
......
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