Commit 02ff42ef authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Optimize invalidation for high contrast/dark mode

Only invalidate for  high contrast and dark mode if the system colors
changed, if the preferred color scheme changed, if the state of high
contrast changed, or if the state of dark mode changed.

Bug: 970285
Change-Id: I6da9787b84ba3790a94df5b961c6e1ec2a762270
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1869758Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarKevin Babbitt <kbabbitt@microsoft.com>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#707897}
parent 3eec7d08
...@@ -2167,11 +2167,14 @@ void RenderThreadImpl::OnSystemColorsChanged( ...@@ -2167,11 +2167,14 @@ void RenderThreadImpl::OnSystemColorsChanged(
void RenderThreadImpl::UpdateSystemColorInfo( void RenderThreadImpl::UpdateSystemColorInfo(
mojom::UpdateSystemColorInfoParamsPtr params) { mojom::UpdateSystemColorInfoParamsPtr params) {
ui::NativeTheme::GetInstanceForWeb()->UpdateSystemColorInfo( bool did_system_color_info_change =
params->is_dark_mode, params->is_high_contrast, ui::NativeTheme::GetInstanceForWeb()->UpdateSystemColorInfo(
params->preferred_color_scheme, params->colors); params->is_dark_mode, params->is_high_contrast,
blink::SystemColorsChanged(); params->preferred_color_scheme, params->colors);
blink::ColorSchemeChanged(); if (did_system_color_info_change) {
blink::SystemColorsChanged();
blink::ColorSchemeChanged();
}
} }
void RenderThreadImpl::PurgePluginListCache(bool reload_pages) { void RenderThreadImpl::PurgePluginListCache(bool reload_pages) {
......
...@@ -103,17 +103,31 @@ void NativeTheme::set_system_colors( ...@@ -103,17 +103,31 @@ void NativeTheme::set_system_colors(
system_colors_ = colors; system_colors_ = colors;
} }
void NativeTheme::UpdateSystemColorInfo( bool NativeTheme::UpdateSystemColorInfo(
bool is_dark_mode, bool is_dark_mode,
bool is_high_contrast, bool is_high_contrast,
PreferredColorScheme preferred_color_scheme, PreferredColorScheme preferred_color_scheme,
const base::flat_map<SystemThemeColor, uint32_t>& colors) { const base::flat_map<SystemThemeColor, uint32_t>& colors) {
set_use_dark_colors(is_dark_mode); bool did_system_color_info_change = false;
set_high_contrast(is_high_contrast); if (is_dark_mode != ShouldUseDarkColors()) {
set_preferred_color_scheme(preferred_color_scheme); did_system_color_info_change = true;
set_use_dark_colors(is_dark_mode);
}
if (is_high_contrast != UsesHighContrastColors()) {
did_system_color_info_change = true;
set_high_contrast(is_high_contrast);
}
if (preferred_color_scheme != GetPreferredColorScheme()) {
did_system_color_info_change = true;
set_preferred_color_scheme(preferred_color_scheme);
}
for (const auto& color : colors) { for (const auto& color : colors) {
system_colors_[color.first] = color.second; if (color.second != GetSystemColorFromMap(color.first)) {
did_system_color_info_change = true;
system_colors_[color.first] = color.second;
}
} }
return did_system_color_info_change;
} }
NativeTheme::ColorSchemeNativeThemeObserver::ColorSchemeNativeThemeObserver( NativeTheme::ColorSchemeNativeThemeObserver::ColorSchemeNativeThemeObserver(
......
...@@ -484,7 +484,10 @@ class NATIVE_THEME_EXPORT NativeTheme { ...@@ -484,7 +484,10 @@ class NATIVE_THEME_EXPORT NativeTheme {
void set_system_colors(const std::map<SystemThemeColor, SkColor>& colors); void set_system_colors(const std::map<SystemThemeColor, SkColor>& colors);
void UpdateSystemColorInfo( // Updates the state of dark mode, high contrast, preferred color scheme,
// and the map of system colors. Returns true if NativeTheme was updated
// as a result, or false if the state of NativeTheme was untouched.
bool UpdateSystemColorInfo(
bool is_dark_mode, bool is_dark_mode,
bool is_high_contrast, bool is_high_contrast,
PreferredColorScheme preferred_color_scheme, PreferredColorScheme preferred_color_scheme,
......
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