Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/native_theme/native_theme_mac.h" | 5 #include "ui/native_theme/native_theme_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 SkColorSetARGB(255, 230, 230, 230); | 34 SkColorSetARGB(255, 230, 230, 230); |
| 35 | 35 |
| 36 // Hardcoded color used for some existing dialogs in Chrome's Cocoa UI. | 36 // Hardcoded color used for some existing dialogs in Chrome's Cocoa UI. |
| 37 const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251); | 37 const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251); |
| 38 | 38 |
| 39 // Color for the highlighted text in a control when that control doesn't have | 39 // Color for the highlighted text in a control when that control doesn't have |
| 40 // keyboard focus. | 40 // keyboard focus. |
| 41 const SkColor kUnfocusedSelectedTextBackgroundColor = | 41 const SkColor kUnfocusedSelectedTextBackgroundColor = |
| 42 SkColorSetRGB(220, 220, 220); | 42 SkColorSetRGB(220, 220, 220); |
| 43 | 43 |
| 44 // Helper to make indexing an array by an enum class easier. | |
| 45 template <class KEY, class VALUE> | |
| 46 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
| |
| 47 VALUE& operator[](const KEY& key) { return array[static_cast<size_t>(key)]; } | |
| 48 VALUE array[static_cast<size_t>(KEY::COUNT)]; | |
| 49 }; | |
| 50 | |
| 44 // On 10.6 and 10.7 there is no way to get components from system colors. Here, | 51 // On 10.6 and 10.7 there is no way to get components from system colors. Here, |
| 45 // system colors are just opaque objects that can paint themselves and otherwise | 52 // system colors are just opaque objects that can paint themselves and otherwise |
| 46 // tell you nothing. In 10.8, some of the system color classes have incomplete | 53 // tell you nothing. In 10.8, some of the system color classes have incomplete |
| 47 // implementations and throw exceptions even attempting to convert using | 54 // implementations and throw exceptions even attempting to convert using |
| 48 // -[NSColor colorUsingColorSpace:], so don't bother there either. | 55 // -[NSColor colorUsingColorSpace:], so don't bother there either. |
| 49 // This function paints a single pixel to a 1x1 swatch and reads it back. | 56 // This function paints a single pixel to a 1x1 swatch and reads it back. |
| 50 SkColor GetSystemColorUsingSwatch(NSColor* color) { | 57 SkColor GetSystemColorUsingSwatch(NSColor* color) { |
| 51 SkColor swatch; | 58 SkColor swatch; |
| 52 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( | 59 base::ScopedCFTypeRef<CGColorSpaceRef> color_space( |
| 53 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 60 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 case kColorId_LabelBackgroundColor: | 155 case kColorId_LabelBackgroundColor: |
| 149 return NSSystemColorToSkColor([NSColor controlBackgroundColor]); | 156 return NSSystemColorToSkColor([NSColor controlBackgroundColor]); |
| 150 case kColorId_ButtonEnabledColor: | 157 case kColorId_ButtonEnabledColor: |
| 151 case kColorId_EnabledMenuButtonBorderColor: | 158 case kColorId_EnabledMenuButtonBorderColor: |
| 152 case kColorId_LabelEnabledColor: | 159 case kColorId_LabelEnabledColor: |
| 153 return NSSystemColorToSkColor([NSColor controlTextColor]); | 160 return NSSystemColorToSkColor([NSColor controlTextColor]); |
| 154 case kColorId_ButtonDisabledColor: | 161 case kColorId_ButtonDisabledColor: |
| 155 case kColorId_LabelDisabledColor: | 162 case kColorId_LabelDisabledColor: |
| 156 return NSSystemColorToSkColor([NSColor disabledControlTextColor]); | 163 return NSSystemColorToSkColor([NSColor disabledControlTextColor]); |
| 157 case kColorId_ButtonHighlightColor: | 164 case kColorId_ButtonHighlightColor: |
| 165 // Although the NSColor documentation names "selectedControlTextColor" as | |
| 166 // the color for a "text in a .. control being clicked or dragged", it | |
| 167 // remains black, and text on Yosemite-style pressed buttons is white. | |
| 168 return SK_ColorWHITE; | |
| 158 case kColorId_ButtonHoverColor: | 169 case kColorId_ButtonHoverColor: |
| 159 return NSSystemColorToSkColor([NSColor selectedControlTextColor]); | 170 return NSSystemColorToSkColor([NSColor selectedControlTextColor]); |
| 160 | 171 |
| 161 // Menus. | 172 // Menus. |
| 162 case kColorId_EnabledMenuItemForegroundColor: | 173 case kColorId_EnabledMenuItemForegroundColor: |
| 163 return NSSystemColorToSkColor([NSColor controlTextColor]); | 174 return NSSystemColorToSkColor([NSColor controlTextColor]); |
| 164 case kColorId_DisabledMenuItemForegroundColor: | 175 case kColorId_DisabledMenuItemForegroundColor: |
| 165 case kColorId_DisabledEmphasizedMenuItemForegroundColor: | 176 case kColorId_DisabledEmphasizedMenuItemForegroundColor: |
| 166 return NSSystemColorToSkColor([NSColor disabledControlTextColor]); | 177 return NSSystemColorToSkColor([NSColor disabledControlTextColor]); |
| 167 case kColorId_SelectedMenuItemForegroundColor: | 178 case kColorId_SelectedMenuItemForegroundColor: |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); | 272 paint.setColor(GetSystemColor(kColorId_HoverMenuItemBackgroundColor)); |
| 262 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 273 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
| 263 break; | 274 break; |
| 264 default: | 275 default: |
| 265 NOTREACHED(); | 276 NOTREACHED(); |
| 266 break; | 277 break; |
| 267 } | 278 } |
| 268 } | 279 } |
| 269 | 280 |
| 270 // static | 281 // static |
| 271 sk_sp<SkShader> NativeThemeMac::GetButtonBackgroundShader( | 282 sk_sp<SkShader> NativeThemeMac::GetButtonBackgroundShader(BackgroundType type, |
| 272 NativeTheme::State state, int height) { | 283 int height) { |
| 273 typedef SkColor ColorByState[NativeTheme::State::kNumStates]; | 284 typedef EnumArray<BackgroundType, SkColor> ColorByState; |
| 274 SkPoint gradient_points[2]; | 285 SkPoint gradient_points[2]; |
| 275 gradient_points[0].iset(0, 0); | 286 gradient_points[0].iset(0, 0); |
| 276 gradient_points[1].iset(0, height); | 287 gradient_points[1].iset(0, height); |
| 277 | 288 |
| 278 SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 }; | 289 SkScalar gradient_positions[] = { 0.0, 0.38, 1.0 }; |
| 279 | 290 |
| 280 ColorByState start_colors; | 291 ColorByState start_colors; |
| 281 start_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300; | 292 start_colors[BackgroundType::DISABLED] = gfx::kMaterialGrey300; |
| 282 start_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue300; | 293 start_colors[BackgroundType::HIGHLIGHTED] = gfx::kMaterialBlue300; |
| 283 start_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue300; | 294 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
| |
| 284 start_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue300; | 295 start_colors[BackgroundType::PRESSED] = gfx::kMaterialBlue300; |
| 285 ColorByState end_colors; | 296 ColorByState end_colors; |
| 286 end_colors[NativeTheme::State::kDisabled] = gfx::kMaterialGrey300; | 297 end_colors[BackgroundType::DISABLED] = gfx::kMaterialGrey300; |
| 287 end_colors[NativeTheme::State::kHovered] = gfx::kMaterialBlue700; | 298 end_colors[BackgroundType::HIGHLIGHTED] = gfx::kMaterialBlue700; |
| 288 end_colors[NativeTheme::State::kNormal] = gfx::kMaterialBlue700; | 299 end_colors[BackgroundType::NORMAL] = SK_ColorWHITE; |
| 289 end_colors[NativeTheme::State::kPressed] = gfx::kMaterialBlue700; | 300 end_colors[BackgroundType::PRESSED] = gfx::kMaterialBlue700; |
| 290 | 301 |
| 291 SkColor gradient_colors[] = { | 302 SkColor gradient_colors[] = {start_colors[type], start_colors[type], |
| 292 start_colors[state], start_colors[state], end_colors[state] | 303 end_colors[type]}; |
| 293 }; | |
| 294 | 304 |
| 295 return SkGradientShader::MakeLinear( | 305 return SkGradientShader::MakeLinear( |
| 296 gradient_points, gradient_colors, gradient_positions, 3, | 306 gradient_points, gradient_colors, gradient_positions, 3, |
| 297 SkShader::kClamp_TileMode); | 307 SkShader::kClamp_TileMode); |
| 298 } | 308 } |
| 299 | 309 |
| 300 NativeThemeMac::NativeThemeMac() { | 310 NativeThemeMac::NativeThemeMac() { |
| 301 } | 311 } |
| 302 | 312 |
| 303 NativeThemeMac::~NativeThemeMac() { | 313 NativeThemeMac::~NativeThemeMac() { |
| 304 } | 314 } |
| 305 | 315 |
| 306 } // namespace ui | 316 } // namespace ui |
| OLD | NEW |