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