Commit a6e94cb4 authored by Andres Pico's avatar Andres Pico Committed by Chromium LUCI CQ

Update NativeThemeAura when high contrast changes

The NativeThemeGtk instance is able to detect high contrast changes
in the system by reading the GTK theme name. NativeThemeAura is not
capable of doing this however, and is never aware of the true state of
high contrast in the system. With this change, NativeThemeGtk will
update NativeThemeAura when high contrast changes.

Bug: 1157686
Change-Id: I6f0407dd639a1d61d1d7f99fccd2122cb0fdc669
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586068
Commit-Queue: Andres Pico <anpico@microsoft.com>
Reviewed-by: default avatarAlison Maher <almaher@microsoft.com>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846188}
parent af912d6b
......@@ -5,6 +5,7 @@
#include "chrome/browser/themes/theme_service.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "chrome/browser/themes/browser_theme_pack.h"
#include "chrome/browser/themes/custom_theme_supplier.h"
#include "chrome/browser/themes/theme_properties.h"
......@@ -300,7 +301,13 @@ bool ThemeHelper::ShouldUseNativeFrame(
bool ThemeHelper::ShouldUseIncreasedContrastThemeSupplier(
ui::NativeTheme* native_theme) const {
#if defined(OS_LINUX)
// On Linux the GTK system theme provides the high contrast colors,
// so don't use the IncreasedContrastThemeSupplier.
return false;
#else
return native_theme && native_theme->UserHasContrastPreference();
#endif
}
SkColor ThemeHelper::GetDefaultColor(
......
......@@ -11,6 +11,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/skia_util.h"
#include "ui/gtk/gtk_util.h"
#include "ui/native_theme/native_theme_aura.h"
namespace gtk {
......@@ -458,6 +459,19 @@ void NativeThemeGtk::SetThemeCssOverride(ScopedCssProvider provider) {
}
}
void NativeThemeGtk::NotifyObservers() {
NativeTheme::NotifyObservers();
// Update the preferred contrast settings for the NativeThemeAura instance and
// notify its observers about the change.
ui::NativeTheme* native_theme = ui::NativeTheme::GetInstanceForNativeUi();
native_theme->set_preferred_contrast(
UserHasContrastPreference()
? ui::NativeThemeBase::PreferredContrast::kMore
: ui::NativeThemeBase::PreferredContrast::kNoPreference);
native_theme->NotifyObservers();
}
void NativeThemeGtk::OnThemeChanged(GtkSettings* settings,
GtkParamSpec* param) {
SetThemeCssOverride(ScopedCssProvider());
......
......@@ -71,6 +71,7 @@ class NativeThemeGtk : public ui::NativeThemeBase {
const gfx::Rect& rect,
const FrameTopAreaExtraParams& frame_top_area,
ColorScheme color_scheme) const override;
void NotifyObservers() override;
void OnThemeChanged(GtkSettings* settings, GtkParamSpec* param);
......
......@@ -424,7 +424,7 @@ class NATIVE_THEME_EXPORT NativeTheme {
void RemoveObserver(NativeThemeObserver* observer);
// Notify observers of native theme changes.
void NotifyObservers();
virtual void NotifyObservers();
// Returns whether the user has an explicit contrast preference, i.e. whether
// we are in forced colors mode or PreferredContrast is set.
......
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