Chromium Code Reviews| Index: ui/native_theme/native_theme_mac.mm |
| diff --git a/ui/native_theme/native_theme_mac.mm b/ui/native_theme/native_theme_mac.mm |
| index 2fba8f861a91c62aafdc42037210d0039927c624..3629cb426b11436e7f0753506b5ccef8f3f0351a 100644 |
| --- a/ui/native_theme/native_theme_mac.mm |
| +++ b/ui/native_theme/native_theme_mac.mm |
| @@ -41,6 +41,13 @@ const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251); |
| const SkColor kUnfocusedSelectedTextBackgroundColor = |
| SkColorSetRGB(220, 220, 220); |
| +// Helper to make indexing an array by an enum class easier. |
| +template <class KEY, class VALUE> |
| +struct EnumArray { |
|
Elly Fong-Jones
2016/04/05 16:43:25
Oh, this is a very clever idea, and I like it.
tapted
2016/04/06 12:08:33
:) Although the obvious question is whether we mak
|
| + VALUE& operator[](const KEY& key) { return array[static_cast<size_t>(key)]; } |
| + VALUE array[static_cast<size_t>(KEY::COUNT)]; |
| +}; |
| + |
| // On 10.6 and 10.7 there is no way to get components from system colors. Here, |
| // system colors are just opaque objects that can paint themselves and otherwise |
| // tell you nothing. In 10.8, some of the system color classes have incomplete |
| @@ -155,6 +162,10 @@ SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const { |
| case kColorId_LabelDisabledColor: |
| return NSSystemColorToSkColor([NSColor disabledControlTextColor]); |
| case kColorId_ButtonHighlightColor: |
| + // Although the NSColor documentation names "selectedControlTextColor" as |
| + // the color for a "text in a .. control being clicked or dragged", it |
| + // remains black, and text on Yosemite-style pressed buttons is white. |
| + return SK_ColorWHITE; |
| case kColorId_ButtonHoverColor: |
| return NSSystemColorToSkColor([NSColor selectedControlTextColor]); |
| @@ -268,9 +279,9 @@ void NativeThemeMac::PaintMenuItemBackground( |
| } |
| // static |
| -sk_sp<SkShader> NativeThemeMac::GetButtonBackgroundShader( |
| - NativeTheme::State state, int height) { |
| - typedef SkColor ColorByState[NativeTheme::State::kNumStates]; |
| +sk_sp<SkShader> NativeThemeMac::GetButtonBackgroundShader(BackgroundType type, |
| + int height) { |
| + typedef EnumArray<BackgroundType, SkColor> ColorByState; |
| SkPoint gradient_points[2]; |
| gradient_points[0].iset(0, 0); |
| gradient_points[1].iset(0, height); |
| @@ -278,19 +289,18 @@ sk_sp<SkShader> NativeThemeMac::GetButtonBackgroundShader( |
| SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 }; |
| ColorByState start_colors; |
| - start_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300; |
| - start_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue300; |
| - start_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue300; |
| - start_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue300; |
| + start_colors[BackgroundType::DISABLED] = gfx::kMaterialGrey300; |
| + start_colors[BackgroundType::HIGHLIGHTED] = gfx::kMaterialBlue300; |
| + start_colors[BackgroundType::NORMAL] = SK_ColorWHITE; |
|
Elly Fong-Jones
2016/04/05 16:43:25
Why are normal buttons SK_ColorWHITE instead of gf
tapted
2016/04/06 12:08:33
This is from the mocks -- only the "primary" / def
|
| + start_colors[BackgroundType::PRESSED] = gfx::kMaterialBlue300; |
| ColorByState end_colors; |
| - end_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300; |
| - end_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue700; |
| - end_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue700; |
| - end_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue700; |
| - |
| - SkColor gradient_colors[] = { |
| - start_colors[state], start_colors[state], end_colors[state] |
| - }; |
| + end_colors[BackgroundType::DISABLED] = gfx::kMaterialGrey300; |
| + end_colors[BackgroundType::HIGHLIGHTED] = gfx::kMaterialBlue700; |
| + end_colors[BackgroundType::NORMAL] = SK_ColorWHITE; |
| + end_colors[BackgroundType::PRESSED] = gfx::kMaterialBlue700; |
| + |
| + SkColor gradient_colors[] = {start_colors[type], start_colors[type], |
| + end_colors[type]}; |
| return SkGradientShader::MakeLinear( |
| gradient_points, gradient_colors, gradient_positions, 3, |