OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #import "ui/base/cocoa/controls/blue_label_button.h" | 5 #import "ui/base/cocoa/controls/blue_label_button.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "skia/ext/skia_utils_mac.h" | 8 #include "skia/ext/skia_utils_mac.h" |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/base/cocoa/scoped_cg_context_smooth_fonts.h" |
10 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 12 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
12 | 13 |
13 const CGFloat kCornerRadius = 2; | 14 const CGFloat kCornerRadius = 2; |
14 | 15 |
15 const CGFloat kTopBottomTextPadding = 7; | 16 const CGFloat kTopBottomTextPadding = 7; |
16 const CGFloat kLeftRightTextPadding = 15; | 17 const CGFloat kLeftRightTextPadding = 15; |
17 const SkColor kTextShadowColor = SkColorSetRGB(0x53, 0x8c, 0xea); | 18 const SkColor kTextShadowColor = SkColorSetRGB(0x53, 0x8c, 0xea); |
18 | 19 |
19 const SkColor kShadowColor = SkColorSetRGB(0xe9, 0xe9, 0xe9); | 20 const SkColor kShadowColor = SkColorSetRGB(0xe9, 0xe9, 0xe9); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 textSize.width += 2 * kLeftRightTextPadding; | 87 textSize.width += 2 * kLeftRightTextPadding; |
87 return textSize; | 88 return textSize; |
88 } | 89 } |
89 | 90 |
90 - (NSRect)drawTitle:(NSAttributedString*)title | 91 - (NSRect)drawTitle:(NSAttributedString*)title |
91 withFrame:(NSRect)frame | 92 withFrame:(NSRect)frame |
92 inView:(NSView*)controlView { | 93 inView:(NSView*)controlView { |
93 // Fuzz factor to adjust for the drop shadow. Based on visual inspection. | 94 // Fuzz factor to adjust for the drop shadow. Based on visual inspection. |
94 frame.origin.y -= 1; | 95 frame.origin.y -= 1; |
95 | 96 |
96 // Ensure LCD font smoothing is enabled when layer backed. | 97 ui::ScopedCGContextSmoothFonts fontSmoothing; |
97 // This is safe to do because we know we are drawing on an opaque background. | |
98 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | |
99 NSGraphicsContext* context = [NSGraphicsContext currentContext]; | |
100 CGContextRef cgContext = static_cast<CGContextRef>([context graphicsPort]); | |
101 CGContextSetShouldSmoothFonts(cgContext, true); | |
102 | |
103 NSAttributedString* attributedTitle = | 98 NSAttributedString* attributedTitle = |
104 [[self class] generateAttributedString:[self title]]; | 99 [[self class] generateAttributedString:[self title]]; |
105 [attributedTitle drawInRect:frame]; | 100 [attributedTitle drawInRect:frame]; |
106 return frame; | 101 return frame; |
107 } | 102 } |
108 | 103 |
109 - (void)drawBezelWithFrame:(NSRect)frame | 104 - (void)drawBezelWithFrame:(NSRect)frame |
110 inView:(NSView*)controlView { | 105 inView:(NSView*)controlView { |
111 NSColor* centerColor; | 106 NSColor* centerColor; |
112 NSColor* innerColor; | 107 NSColor* innerColor; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 1, 1) | 142 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 1, 1) |
148 xRadius:kCornerRadius | 143 xRadius:kCornerRadius |
149 yRadius:kCornerRadius] fill]; | 144 yRadius:kCornerRadius] fill]; |
150 [centerColor set]; | 145 [centerColor set]; |
151 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 2, 2) | 146 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 2, 2) |
152 xRadius:kCornerRadius | 147 xRadius:kCornerRadius |
153 yRadius:kCornerRadius] fill]; | 148 yRadius:kCornerRadius] fill]; |
154 } | 149 } |
155 | 150 |
156 @end | 151 @end |
OLD | NEW |