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

macviews: support high contrast in menus

This change:
1) Draws exterior borders on menus, even if MenuConfig says not to use them,
   if the NativeTheme is in high contrast mode;
2) Draws separators in black instead of grey in high contrast mode on Mac;
3) Draws a heavy (2pt) border around the selected item in high contrast mode
   on Mac

Screenshots are attached to the bug as comment #10.

Bug: 829347
Change-Id: I8ffd7adbae5b35751c18b77a9e8b6564926f7012
Reviewed-on: https://chromium-review.googlesource.com/1010245
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551324}
parent ad1a7834
...@@ -66,6 +66,11 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase { ...@@ -66,6 +66,11 @@ class NATIVE_THEME_EXPORT NativeThemeMac : public NativeThemeBase {
NativeThemeMac(); NativeThemeMac();
~NativeThemeMac() override; ~NativeThemeMac() override;
// Paint the selected menu item background, and a border for emphasis when in
// high contrast.
void PaintSelectedMenuItem(cc::PaintCanvas* canvas,
const gfx::Rect& rect) const;
DISALLOW_COPY_AND_ASSIGN(NativeThemeMac); DISALLOW_COPY_AND_ASSIGN(NativeThemeMac);
}; };
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
namespace { namespace {
const SkColor kMenuPopupBackgroundColor = SK_ColorWHITE; const SkColor kMenuPopupBackgroundColor = SK_ColorWHITE;
const SkColor kMenuSeparatorColor = SkColorSetA(SK_ColorBLACK, 38);
const SkColor kMenuBorderColor = SkColorSetARGB(60, 0, 0, 0);
// Hardcoded color used for some existing dialogs in Chrome's Cocoa UI. // Hardcoded color used for some existing dialogs in Chrome's Cocoa UI.
const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251); const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251);
...@@ -144,9 +142,11 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const { ...@@ -144,9 +142,11 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
case kColorId_MenuBackgroundColor: case kColorId_MenuBackgroundColor:
return kMenuPopupBackgroundColor; return kMenuPopupBackgroundColor;
case kColorId_MenuSeparatorColor: case kColorId_MenuSeparatorColor:
return kMenuSeparatorColor; return UsesHighContrastColors() ? SK_ColorBLACK
: SkColorSetA(SK_ColorBLACK, 0x26);
case kColorId_MenuBorderColor: case kColorId_MenuBorderColor:
return kMenuBorderColor; return UsesHighContrastColors() ? SK_ColorBLACK
: SkColorSetA(SK_ColorBLACK, 0x60);
// Mac has a different "pressed button" styling because it doesn't use // Mac has a different "pressed button" styling because it doesn't use
// ripples. // ripples.
...@@ -270,19 +270,13 @@ void NativeThemeMac::PaintMenuItemBackground( ...@@ -270,19 +270,13 @@ void NativeThemeMac::PaintMenuItemBackground(
State state, State state,
const gfx::Rect& rect, const gfx::Rect& rect,
const MenuItemExtraParams& menu_item) const { const MenuItemExtraParams& menu_item) const {
cc::PaintFlags flags;
switch (state) { switch (state) {
case NativeTheme::kNormal: case NativeTheme::kNormal:
case NativeTheme::kDisabled: case NativeTheme::kDisabled:
// Draw nothing over the regular background. // Draw nothing over the regular background.
break; break;
case NativeTheme::kHovered: case NativeTheme::kHovered:
// TODO(tapted): Draw a gradient, and use [NSColor currentControlTint] to PaintSelectedMenuItem(canvas, rect);
// pick colors. The System color "selectedMenuItemColor" is actually still
// blue for Graphite. And while "keyboardFocusIndicatorColor" does change,
// and is a good shade of gray, it's not blue enough for the Blue theme.
flags.setColor(GetSystemColor(kColorId_FocusedMenuItemBackgroundColor));
canvas->drawRect(gfx::RectToSkRect(rect), flags);
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -307,4 +301,24 @@ NativeThemeMac::NativeThemeMac() { ...@@ -307,4 +301,24 @@ NativeThemeMac::NativeThemeMac() {
NativeThemeMac::~NativeThemeMac() { NativeThemeMac::~NativeThemeMac() {
} }
void NativeThemeMac::PaintSelectedMenuItem(cc::PaintCanvas* canvas,
const gfx::Rect& rect) const {
// Draw the background.
cc::PaintFlags flags;
flags.setColor(GetSystemColor(kColorId_FocusedMenuItemBackgroundColor));
canvas->drawRect(gfx::RectToSkRect(rect), flags);
// In high contrast, draw a border stroke as well.
if (UsesHighContrastColors()) {
constexpr int kStrokeWidth = 2;
cc::PaintFlags border_flags;
gfx::Rect border_rect = rect;
border_rect.Inset(kStrokeWidth / 2, kStrokeWidth / 2);
border_flags.setColor(GetSystemColor(kColorId_MenuBorderColor));
border_flags.setStyle(cc::PaintFlags::kStroke_Style);
border_flags.setStrokeWidth(kStrokeWidth);
canvas->drawRect(gfx::RectToSkRect(border_rect), border_flags);
}
}
} // namespace ui } // namespace ui
...@@ -277,8 +277,12 @@ void MenuScrollViewContainer::CreateDefaultBorder() { ...@@ -277,8 +277,12 @@ void MenuScrollViewContainer::CreateDefaultBorder() {
bubble_border_ = nullptr; bubble_border_ = nullptr;
const MenuConfig& menu_config = MenuConfig::instance(); const MenuConfig& menu_config = MenuConfig::instance();
const ui::NativeTheme* native_theme = GetNativeTheme();
bool use_outer_border =
menu_config.use_outer_border ||
(native_theme && native_theme->UsesHighContrastColors());
int padding = menu_config.use_outer_border && menu_config.corner_radius > 0 int padding = use_outer_border && menu_config.corner_radius > 0
? kBorderPaddingDueToRoundedCorners ? kBorderPaddingDueToRoundedCorners
: 0; : 0;
...@@ -286,7 +290,7 @@ void MenuScrollViewContainer::CreateDefaultBorder() { ...@@ -286,7 +290,7 @@ void MenuScrollViewContainer::CreateDefaultBorder() {
const int horizontal_inset = const int horizontal_inset =
menu_config.menu_horizontal_border_size + padding; menu_config.menu_horizontal_border_size + padding;
if (menu_config.use_outer_border) { if (use_outer_border) {
SkColor color = GetNativeTheme() SkColor color = GetNativeTheme()
? GetNativeTheme()->GetSystemColor( ? GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_MenuBorderColor) ui::NativeTheme::kColorId_MenuBorderColor)
......
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