Commit 1386bee6 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

macviews: support "increase contrast" system setting

This change:
1) Adds NativeTheme::UsesHighContrastColors(), which returns whether special
   high contrast colors should be used, based on system settings;
2) Adds a new --force-high-contrast switch to override the system settings;
3) Adds overrides for certain colors to use black or GoogleBlue900 as needed;
4) Adds gfx::kGoogleBlue900 from the Polymer color specs

Bug: 565996
Change-Id: Ie63f4d965a62bcfdb092660673b52534ce4507dd
Reviewed-on: https://chromium-review.googlesource.com/761316Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523846}
parent b4c032d2
...@@ -492,7 +492,7 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const { ...@@ -492,7 +492,7 @@ SkColor ThemeService::GetDefaultColor(int id, bool incognito) const {
ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING ui::GetAuraColor(id == ThemeProperties::COLOR_TAB_THROBBER_SPINNING
? ui::NativeTheme::kColorId_ThrobberSpinningColor ? ui::NativeTheme::kColorId_ThrobberSpinningColor
: ui::NativeTheme::kColorId_ThrobberWaitingColor, : ui::NativeTheme::kColorId_ThrobberWaitingColor,
nullptr); ui::NativeTheme::GetInstanceForNativeUi());
color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito); color_utils::HSL hsl = GetTint(ThemeProperties::TINT_BUTTONS, incognito);
return color_utils::HSLShift(base_color, hsl); return color_utils::HSLShift(base_color, hsl);
} }
......
...@@ -31,10 +31,9 @@ namespace { ...@@ -31,10 +31,9 @@ namespace {
// in Windows 10 still has black text, but (since the user wants high contrast) // in Windows 10 still has black text, but (since the user wants high contrast)
// the grey text shades in Harmony should not be used. // the grey text shades in Harmony should not be used.
bool ShouldIgnoreHarmonySpec(const ui::NativeTheme& theme) { bool ShouldIgnoreHarmonySpec(const ui::NativeTheme& theme) {
#if defined(OS_WIN) if (theme.UsesHighContrastColors())
if (ui::NativeThemeWin::IsUsingHighContrastTheme())
return true; return true;
#endif
constexpr auto kTestColorId = ui::NativeTheme::kColorId_LabelEnabledColor; constexpr auto kTestColorId = ui::NativeTheme::kColorId_LabelEnabledColor;
return theme.GetSystemColor(kTestColorId) != SK_ColorBLACK; return theme.GetSystemColor(kTestColorId) != SK_ColorBLACK;
} }
......
...@@ -14,7 +14,7 @@ bool ShouldCustomDrawSystemTitlebar() { ...@@ -14,7 +14,7 @@ bool ShouldCustomDrawSystemTitlebar() {
// mode so that we can correctly draw the caption buttons on the left in RTL // mode so that we can correctly draw the caption buttons on the left in RTL
// mode. But they require a different style and color selection that isn't // mode. But they require a different style and color selection that isn't
// currently implemented. // currently implemented.
return !ui::NativeThemeWin::IsUsingHighContrastTheme() && return !ui::NativeTheme::GetInstanceForNativeUi()->UsesHighContrastColors() &&
base::CommandLine::ForCurrentProcess()->HasSwitch( base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kWindows10CustomTitlebar) && switches::kWindows10CustomTitlebar) &&
base::win::GetVersion() >= base::win::VERSION_WIN10; base::win::GetVersion() >= base::win::VERSION_WIN10;
......
...@@ -53,6 +53,11 @@ const char kDisableTouchDragDrop[] = "disable-touch-drag-drop"; ...@@ -53,6 +53,11 @@ const char kDisableTouchDragDrop[] = "disable-touch-drag-drop";
// Enables touch event based drag and drop. // Enables touch event based drag and drop.
const char kEnableTouchDragDrop[] = "enable-touch-drag-drop"; const char kEnableTouchDragDrop[] = "enable-touch-drag-drop";
// Forces high-contrast mode in native UI drawing, regardless of system
// settings. Note that this has limited effect on Windows: only Aura colors will
// be switched to high contrast, not other system colors.
const char kForceHighContrast[] = "force-high-contrast";
// TODO(dcastagna): Draw debug quad borders only when it is actually // TODO(dcastagna): Draw debug quad borders only when it is actually
// an overlay candidate. // an overlay candidate.
// Renders a border around GL composited overlay candidate quads to // Renders a border around GL composited overlay candidate quads to
......
...@@ -38,6 +38,7 @@ UI_BASE_EXPORT extern const char kDisableTouchAdjustment[]; ...@@ -38,6 +38,7 @@ UI_BASE_EXPORT extern const char kDisableTouchAdjustment[];
UI_BASE_EXPORT extern const char kDisableTouchDragDrop[]; UI_BASE_EXPORT extern const char kDisableTouchDragDrop[];
UI_BASE_EXPORT extern const char kEnableDrawOcclusion[]; UI_BASE_EXPORT extern const char kEnableDrawOcclusion[];
UI_BASE_EXPORT extern const char kEnableTouchDragDrop[]; UI_BASE_EXPORT extern const char kEnableTouchDragDrop[];
UI_BASE_EXPORT extern const char kForceHighContrast[];
UI_BASE_EXPORT extern const char kGlCompositedOverlayCandidateQuadBorder[]; UI_BASE_EXPORT extern const char kGlCompositedOverlayCandidateQuadBorder[];
UI_BASE_EXPORT extern const char kLang[]; UI_BASE_EXPORT extern const char kLang[];
UI_BASE_EXPORT extern const char kMaterialDesignInkDropAnimationSpeed[]; UI_BASE_EXPORT extern const char kMaterialDesignInkDropAnimationSpeed[];
......
...@@ -20,6 +20,7 @@ const SkColor kChromeIconGrey = SkColorSetRGB(0x5A, 0x5A, 0x5A); ...@@ -20,6 +20,7 @@ const SkColor kChromeIconGrey = SkColorSetRGB(0x5A, 0x5A, 0x5A);
const SkColor kGoogleBlue300 = SkColorSetRGB(0x7B, 0xAA, 0xF7); const SkColor kGoogleBlue300 = SkColorSetRGB(0x7B, 0xAA, 0xF7);
const SkColor kGoogleBlue500 = SkColorSetRGB(0x42, 0x85, 0xF4); const SkColor kGoogleBlue500 = SkColorSetRGB(0x42, 0x85, 0xF4);
const SkColor kGoogleBlue700 = SkColorSetRGB(0x33, 0x67, 0xD6); const SkColor kGoogleBlue700 = SkColorSetRGB(0x33, 0x67, 0xD6);
const SkColor kGoogleBlue900 = SkColorSetRGB(0x1C, 0x3A, 0xA9);
const SkColor kGoogleRed300 = SkColorSetRGB(0xE6, 0x7C, 0x73); const SkColor kGoogleRed300 = SkColorSetRGB(0xE6, 0x7C, 0x73);
const SkColor kGoogleRed700 = SkColorSetRGB(0xC5, 0x39, 0x29); const SkColor kGoogleRed700 = SkColorSetRGB(0xC5, 0x39, 0x29);
const SkColor kGoogleGreen300 = SkColorSetRGB(0x57, 0xBB, 0x8A); const SkColor kGoogleGreen300 = SkColorSetRGB(0x57, 0xBB, 0x8A);
......
...@@ -20,6 +20,31 @@ namespace ui { ...@@ -20,6 +20,31 @@ namespace ui {
SkColor GetAuraColor(NativeTheme::ColorId color_id, SkColor GetAuraColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme) { const NativeTheme* base_theme) {
// High contrast overrides the normal colors for certain ColorIds to be much
// darker or lighter.
if (base_theme->UsesHighContrastColors()) {
switch (color_id) {
case NativeTheme::kColorId_ButtonEnabledColor:
case NativeTheme::kColorId_ButtonHoverColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_MenuBorderColor:
case NativeTheme::kColorId_MenuSeparatorColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_SeparatorColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_FocusedBorderColor:
return gfx::kGoogleBlue900;
case NativeTheme::kColorId_UnfocusedBorderColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_TabBottomBorder:
return SK_ColorBLACK;
case NativeTheme::kColorId_ProminentButtonColor:
return gfx::kGoogleBlue900;
default:
break;
}
}
// Second wave of MD colors (colors that only appear in secondary UI). // Second wave of MD colors (colors that only appear in secondary UI).
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
static const SkColor kPrimaryTextColor = SK_ColorBLACK; static const SkColor kPrimaryTextColor = SK_ColorBLACK;
......
...@@ -420,6 +420,10 @@ class NATIVE_THEME_EXPORT NativeTheme { ...@@ -420,6 +420,10 @@ class NATIVE_THEME_EXPORT NativeTheme {
// Notify observers of native theme changes. // Notify observers of native theme changes.
void NotifyObservers(); void NotifyObservers();
// Returns whether this NativeTheme uses higher-contrast colors, controlled by
// system accessibility settings and the system theme.
virtual bool UsesHighContrastColors() const = 0;
protected: protected:
NativeTheme(); NativeTheme();
virtual ~NativeTheme(); virtual ~NativeTheme();
......
...@@ -264,6 +264,11 @@ gfx::Rect NativeThemeBase::GetNinePatchAperture(Part part) const { ...@@ -264,6 +264,11 @@ gfx::Rect NativeThemeBase::GetNinePatchAperture(Part part) const {
return gfx::Rect(); return gfx::Rect();
} }
bool NativeThemeBase::UsesHighContrastColors() const {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceHighContrast);
}
NativeThemeBase::NativeThemeBase() NativeThemeBase::NativeThemeBase()
: scrollbar_width_(kDefaultScrollbarWidth), : scrollbar_width_(kDefaultScrollbarWidth),
scrollbar_button_length_(kDefaultScrollbarButtonLength) { scrollbar_button_length_(kDefaultScrollbarButtonLength) {
......
...@@ -36,6 +36,7 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { ...@@ -36,6 +36,7 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
bool SupportsNinePatch(Part part) const override; bool SupportsNinePatch(Part part) const override;
gfx::Size GetNinePatchCanvasSize(Part part) const override; gfx::Size GetNinePatchCanvasSize(Part part) const override;
gfx::Rect GetNinePatchAperture(Part part) const override; gfx::Rect GetNinePatchAperture(Part part) const override;
bool UsesHighContrastColors() const override;
protected: protected:
NativeThemeBase(); NativeThemeBase();
......
...@@ -45,6 +45,7 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase { ...@@ -45,6 +45,7 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
State state, State state,
const gfx::Rect& rect, const gfx::Rect& rect,
const MenuItemExtraParams& menu_item) const override; const MenuItemExtraParams& menu_item) const override;
bool UsesHighContrastColors() const override;
// Paints the styled button shape used for default controls on Mac. The basic // Paints the styled button shape used for default controls on Mac. The basic
// style is used for dialog buttons, comboboxes, and tabbed pane tabs. // style is used for dialog buttons, comboboxes, and tabbed pane tabs.
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h" #include "ui/native_theme/common_theme.h"
@interface NSWorkspace (Redeclarations)
@property(readonly) BOOL accessibilityDisplayShouldIncreaseContrast;
@end
namespace { namespace {
// Values calculated by reading pixels and solving simultaneous equations // Values calculated by reading pixels and solving simultaneous equations
...@@ -283,6 +289,17 @@ void NativeThemeMac::PaintMenuItemBackground( ...@@ -283,6 +289,17 @@ void NativeThemeMac::PaintMenuItemBackground(
} }
} }
bool NativeThemeMac::UsesHighContrastColors() const {
if (NativeThemeBase::UsesHighContrastColors())
return true;
NSWorkspace* workspace = [NSWorkspace sharedWorkspace];
if ([workspace respondsToSelector:@selector
(accessibilityDisplayShouldIncreaseContrast)]) {
return workspace.accessibilityDisplayShouldIncreaseContrast;
}
return false;
}
NativeThemeMac::NativeThemeMac() { NativeThemeMac::NativeThemeMac() {
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vsstyle.h> #include <vsstyle.h>
#include <vssym32.h> #include <vssym32.h>
#include "base/command_line.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/win/scoped_gdi_object.h" #include "base/win/scoped_gdi_object.h"
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/base/material_design/material_design_controller.h" #include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
...@@ -149,11 +151,6 @@ NativeTheme* NativeTheme::GetInstanceForNativeUi() { ...@@ -149,11 +151,6 @@ NativeTheme* NativeTheme::GetInstanceForNativeUi() {
return NativeThemeWin::instance(); return NativeThemeWin::instance();
} }
// static
bool NativeThemeWin::IsUsingHighContrastTheme() {
return instance()->IsUsingHighContrastThemeInternal();
}
// static // static
void NativeThemeWin::CloseHandles() { void NativeThemeWin::CloseHandles() {
instance()->CloseHandlesInternal(); instance()->CloseHandlesInternal();
...@@ -272,7 +269,7 @@ NativeThemeWin::~NativeThemeWin() { ...@@ -272,7 +269,7 @@ NativeThemeWin::~NativeThemeWin() {
} }
} }
bool NativeThemeWin::IsUsingHighContrastThemeInternal() { bool NativeThemeWin::IsUsingHighContrastThemeInternal() const {
if (is_using_high_contrast_valid_) if (is_using_high_contrast_valid_)
return is_using_high_contrast_; return is_using_high_contrast_;
HIGHCONTRAST result; HIGHCONTRAST result;
...@@ -514,8 +511,8 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { ...@@ -514,8 +511,8 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const {
case kColorId_TreeSelectionBackgroundFocused: case kColorId_TreeSelectionBackgroundFocused:
return system_colors_[COLOR_HIGHLIGHT]; return system_colors_[COLOR_HIGHLIGHT];
case kColorId_TreeSelectionBackgroundUnfocused: case kColorId_TreeSelectionBackgroundUnfocused:
return system_colors_[IsUsingHighContrastTheme() ? return system_colors_[UsesHighContrastColors() ? COLOR_MENUHIGHLIGHT
COLOR_MENUHIGHLIGHT : COLOR_BTNFACE]; : COLOR_BTNFACE];
// Table // Table
case kColorId_TableBackground: case kColorId_TableBackground:
...@@ -529,8 +526,8 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { ...@@ -529,8 +526,8 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const {
case kColorId_TableSelectionBackgroundFocused: case kColorId_TableSelectionBackgroundFocused:
return system_colors_[COLOR_HIGHLIGHT]; return system_colors_[COLOR_HIGHLIGHT];
case kColorId_TableSelectionBackgroundUnfocused: case kColorId_TableSelectionBackgroundUnfocused:
return system_colors_[IsUsingHighContrastTheme() ? return system_colors_[UsesHighContrastColors() ? COLOR_MENUHIGHLIGHT
COLOR_MENUHIGHLIGHT : COLOR_BTNFACE]; : COLOR_BTNFACE];
case kColorId_TableGroupingIndicatorColor: case kColorId_TableGroupingIndicatorColor:
return system_colors_[COLOR_GRAYTEXT]; return system_colors_[COLOR_GRAYTEXT];
...@@ -625,6 +622,12 @@ gfx::Rect NativeThemeWin::GetNinePatchAperture(Part part) const { ...@@ -625,6 +622,12 @@ gfx::Rect NativeThemeWin::GetNinePatchAperture(Part part) const {
return gfx::Rect(); return gfx::Rect();
} }
bool NativeThemeWin::UsesHighContrastColors() const {
bool force_enabled = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceHighContrast);
return force_enabled || IsUsingHighContrastThemeInternal();
}
void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas, void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas,
Part part, Part part,
State state, State state,
......
...@@ -52,9 +52,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, ...@@ -52,9 +52,6 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
LAST LAST
}; };
// Returns true if a high contrast theme is being used.
static bool IsUsingHighContrastTheme();
// Closes cached theme handles so we can unload the DLL or update our UI // Closes cached theme handles so we can unload the DLL or update our UI
// for a theme change. // for a theme change.
static void CloseHandles(); static void CloseHandles();
...@@ -78,10 +75,10 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, ...@@ -78,10 +75,10 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
const gfx::Rect& rect, const gfx::Rect& rect,
const ExtraParams& extra) const override; const ExtraParams& extra) const override;
SkColor GetSystemColor(ColorId color_id) const override; SkColor GetSystemColor(ColorId color_id) const override;
bool SupportsNinePatch(Part part) const override; bool SupportsNinePatch(Part part) const override;
gfx::Size GetNinePatchCanvasSize(Part part) const override; gfx::Size GetNinePatchCanvasSize(Part part) const override;
gfx::Rect GetNinePatchAperture(Part part) const override; gfx::Rect GetNinePatchAperture(Part part) const override;
bool UsesHighContrastColors() const override;
protected: protected:
friend class NativeTheme; friend class NativeTheme;
...@@ -92,7 +89,7 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, ...@@ -92,7 +89,7 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
~NativeThemeWin() override; ~NativeThemeWin() override;
private: private:
bool IsUsingHighContrastThemeInternal(); bool IsUsingHighContrastThemeInternal() const;
void CloseHandlesInternal(); void CloseHandlesInternal();
// gfx::SysColorChangeListener implementation: // gfx::SysColorChangeListener implementation:
......
...@@ -4790,6 +4790,7 @@ class TestNativeTheme : public ui::NativeTheme { ...@@ -4790,6 +4790,7 @@ class TestNativeTheme : public ui::NativeTheme {
gfx::Rect GetNinePatchAperture(Part part) const override { gfx::Rect GetNinePatchAperture(Part part) const override {
return gfx::Rect(); return gfx::Rect();
} }
bool UsesHighContrastColors() const override { return false; }
private: private:
DISALLOW_COPY_AND_ASSIGN(TestNativeTheme); DISALLOW_COPY_AND_ASSIGN(TestNativeTheme);
......
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