Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ui/native_theme/native_theme_mac.mm

Issue 303543004: MacViews: views_examples_with_content_exe working! Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add files Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include <Cocoa/Cocoa.h>
8
7 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/mac/scoped_cftyperef.h"
8 #include "ui/native_theme/common_theme.h" 11 #include "ui/native_theme/common_theme.h"
12 #include "skia/ext/skia_utils_mac.h"
13
14 #if !defined(MAC_OS_X_VERSION_10_8) || \
15 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8
16
17 @interface NSColor (MountainLionAPI)
18 - (CGColorRef)CGColor;
19 @end
20
21 #endif
9 22
10 namespace { 23 namespace {
11 24
12 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); 25 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128);
13 const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251); 26 const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251);
14 27
28 // System colors use NSNamedColorSpace System.
29 SkColor SystemColor(NSColor* color) {
30 NSColor* deviceColor =
31 [color colorUsingColorSpace:[NSColorSpace deviceRGBColorSpace]];
32 if (!deviceColor) {
33 // Sometimes the conversion is not possible, but we can get an approximation
34 // by going through a CGColorRef.
35 if ([color respondsToSelector:@selector(CGColor)]) {
36 CGColorRef cg_color = ([color CGColor]);
37 if (CGColorGetNumberOfComponents(cg_color) == 2) {
38 const CGFloat* components = CGColorGetComponents(cg_color);
39 return SkColorSetARGB(SkScalarRoundToInt(255.0 * components[1]),
40 SkScalarRoundToInt(255.0 * components[0]),
41 SkScalarRoundToInt(255.0 * components[0]),
42 SkScalarRoundToInt(255.0 * components[0]));
43 }
44 return gfx::CGColorRefToSkColor(cg_color);
45 } else {
46 NOTIMPLEMENTED();
47 return SkColor();
48 }
49 }
50 return gfx::NSDeviceColorToSkColor(deviceColor);
51 }
52
15 } // namespace 53 } // namespace
16 54
17 namespace ui { 55 namespace ui {
18 56
19 // static 57 // static
20 NativeTheme* NativeTheme::instance() { 58 NativeTheme* NativeTheme::instance() {
21 return NativeThemeMac::instance(); 59 return NativeThemeMac::instance();
22 } 60 }
23 61
24 // static 62 // static
25 NativeThemeMac* NativeThemeMac::instance() { 63 NativeThemeMac* NativeThemeMac::instance() {
26 CR_DEFINE_STATIC_LOCAL(NativeThemeMac, s_native_theme, ()); 64 CR_DEFINE_STATIC_LOCAL(NativeThemeMac, s_native_theme, ());
27 return &s_native_theme; 65 return &s_native_theme;
28 } 66 }
29 67
30 SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const { 68 SkColor NativeThemeMac::GetSystemColor(ColorId color_id) const {
31 SkColor color; 69 SkColor color;
32 if (CommonThemeGetSystemColor(color_id, &color)) 70 if (CommonThemeGetSystemColor(color_id, &color))
33 return color; 71 return color;
34 72
35 switch (color_id) { 73 switch (color_id) {
74 case kColorId_WindowBackground:
75 return SystemColor([NSColor windowBackgroundColor]);
36 case kColorId_DialogBackground: 76 case kColorId_DialogBackground:
37 return kDialogBackgroundColor; 77 return kDialogBackgroundColor;
78 case kColorId_ButtonBackgroundColor:
79 return SystemColor([NSColor controlBackgroundColor]);
80 case kColorId_LabelEnabledColor:
81 return SystemColor([NSColor controlTextColor]);
82 case kColorId_LabelDisabledColor:
83 return SystemColor([NSColor disabledControlTextColor]);
84 case kColorId_LabelBackgroundColor:
85 return SystemColor([NSColor textBackgroundColor]);
86 case kColorId_ButtonEnabledColor:
87 case kColorId_ButtonDisabledColor:
88 return SystemColor([NSColor controlColor]);
89 case kColorId_ButtonHighlightColor:
90 return SystemColor([NSColor selectedControlColor]);
91 case kColorId_ButtonHoverColor:
92 return SystemColor([NSColor controlHighlightColor]);
93 case kColorId_TextfieldDefaultColor:
94 return SystemColor([NSColor textColor]);
95 case kColorId_TextfieldDefaultBackground:
96 return SystemColor([NSColor textBackgroundColor]);
97 case kColorId_TextfieldSelectionColor:
98 return SystemColor([NSColor selectedTextColor]);
99 case kColorId_TextfieldSelectionBackgroundFocused:
100 return SystemColor([NSColor selectedTextBackgroundColor]);
38 default: 101 default:
39 NOTREACHED() << "Invalid color_id: " << color_id; 102 NOTIMPLEMENTED() << " Invalid color_id: " << color_id;
103 return FallbackTheme::GetSystemColor(color_id);
40 } 104 }
41 105
42 return kInvalidColorIdColor; 106 return kInvalidColorIdColor;
43 } 107 }
44 108
45 NativeThemeMac::NativeThemeMac() { 109 NativeThemeMac::NativeThemeMac() {
46 } 110 }
47 111
48 NativeThemeMac::~NativeThemeMac() { 112 NativeThemeMac::~NativeThemeMac() {
49 } 113 }
50 114
51 } // namespace ui 115 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_mac.h ('k') | ui/views/accessibility/native_view_accessibility_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698