OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/cocoa/extensions/extension_toolbar_icon_surfacing_bub
ble_mac.h" | 5 #import "chrome/browser/ui/cocoa/extensions/toolbar_actions_bar_bubble_mac.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
8 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 9 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
10 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" | 11 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_bubble_delegate.h" |
11 #include "grit/chromium_strings.h" | |
12 #include "grit/generated_resources.h" | |
13 #include "skia/ext/skia_utils_mac.h" | 12 #include "skia/ext/skia_utils_mac.h" |
14 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 13 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 15 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
16 #import "ui/base/cocoa/hover_button.h" | 16 #import "ui/base/cocoa/hover_button.h" |
17 #import "ui/base/cocoa/window_size_constants.h" | 17 #import "ui/base/cocoa/window_size_constants.h" |
18 #include "ui/base/l10n/l10n_util.h" | |
19 #include "ui/native_theme/native_theme.h" | 18 #include "ui/native_theme/native_theme.h" |
20 | 19 |
21 @interface ExtensionToolbarIconSurfacingBubbleMac () | 20 @class ExtensionMessageBubbleButton; |
| 21 |
| 22 @interface ToolbarActionsBarBubbleMac () |
22 | 23 |
23 // Handles the notification that the window will close. | 24 // Handles the notification that the window will close. |
24 - (void)windowWillClose:(NSNotification*)notification; | 25 - (void)windowWillClose:(NSNotification*)notification; |
25 | 26 |
26 // Creates and returns an NSAttributed string with the specified size and | 27 // Creates and returns an NSAttributed string with the specified size and |
27 // alignment. | 28 // alignment. |
28 - (NSAttributedString*)attributedStringWithString:(int)stringId | 29 - (NSAttributedString*)attributedStringWithString:(const base::string16&)string |
29 fontSize:(CGFloat)fontSize | 30 fontSize:(CGFloat)fontSize |
30 alignment:(NSTextAlignment)alignment; | 31 alignment:(NSTextAlignment)alignment; |
31 | 32 |
32 // Creates an NSTextField with the given string, and adds it to the window. | 33 // Creates an NSTextField with the given string, size, and alignment,, and adds |
33 - (NSTextField*)addTextFieldWithString:(NSAttributedString*)attributedString; | 34 // it to the window. |
| 35 - (NSTextField*)addTextFieldWithString:(const base::string16&)string |
| 36 fontSize:(CGFloat)fontSize |
| 37 alignment:(NSTextAlignment)alignment; |
| 38 |
| 39 // Creates an ExtensionMessagebubbleButton the given string id, and adds it to |
| 40 // the window. |
| 41 - (ExtensionMessageBubbleButton*) addButtonWithString: |
| 42 (const base::string16&)string |
| 43 isPrimary:(BOOL)isPrimary; |
34 | 44 |
35 // Initializes the bubble's content. | 45 // Initializes the bubble's content. |
36 - (void)layout; | 46 - (void)layout; |
37 | 47 |
38 // Handles the "ok" button being clicked. | 48 // Handles a button being clicked. |
39 - (void)onButtonClicked:(id)sender; | 49 - (void)onButtonClicked:(id)sender; |
40 | 50 |
41 @end | 51 @end |
42 | 52 |
43 @interface ExtensionToolbarIconSurfacingBubbleButton : HoverButton | 53 @interface ExtensionMessageBubbleButton : HoverButton { |
| 54 BOOL isPrimary_; |
| 55 } |
| 56 |
44 // Draws with a blue background and white text. | 57 // Draws with a blue background and white text. |
45 - (void)drawRect:(NSRect)rect; | 58 - (void)drawRect:(NSRect)rect; |
| 59 |
| 60 @property(nonatomic) BOOL isPrimary; |
| 61 |
46 @end | 62 @end |
47 | 63 |
48 @implementation ExtensionToolbarIconSurfacingBubbleMac | 64 @implementation ToolbarActionsBarBubbleMac |
| 65 |
| 66 @synthesize actionButton = actionButton_; |
| 67 @synthesize dismissButton = dismissButton_; |
| 68 @synthesize learnMoreButton = learnMoreButton_; |
49 | 69 |
50 - (id)initWithParentWindow:(NSWindow*)parentWindow | 70 - (id)initWithParentWindow:(NSWindow*)parentWindow |
51 anchorPoint:(NSPoint)anchorPoint | 71 anchorPoint:(NSPoint)anchorPoint |
52 delegate:(ToolbarActionsBarBubbleDelegate*)delegate { | 72 delegate:(scoped_ptr<ToolbarActionsBarBubbleDelegate>) |
| 73 delegate { |
53 base::scoped_nsobject<InfoBubbleWindow> window( | 74 base::scoped_nsobject<InfoBubbleWindow> window( |
54 [[InfoBubbleWindow alloc] | 75 [[InfoBubbleWindow alloc] |
55 initWithContentRect:ui::kWindowSizeDeterminedLater | 76 initWithContentRect:ui::kWindowSizeDeterminedLater |
56 styleMask:NSBorderlessWindowMask | 77 styleMask:NSBorderlessWindowMask |
57 backing:NSBackingStoreBuffered | 78 backing:NSBackingStoreBuffered |
58 defer:NO]); | 79 defer:NO]); |
59 if ((self = [super initWithWindow:window | 80 if ((self = [super initWithWindow:window |
60 parentWindow:parentWindow | 81 parentWindow:parentWindow |
61 anchoredAt:anchorPoint])) { | 82 anchoredAt:anchorPoint])) { |
62 delegate_ = delegate; | |
63 acknowledged_ = NO; | 83 acknowledged_ = NO; |
64 [window setCanBecomeKeyWindow:NO]; | 84 [window setCanBecomeKeyWindow:NO]; |
| 85 delegate_ = delegate.Pass(); |
65 | 86 |
66 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); | 87 ui::NativeTheme* nativeTheme = ui::NativeTheme::instance(); |
67 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; | 88 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; |
68 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; | 89 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; |
69 [[self bubble] setBackgroundColor: | 90 [[self bubble] setBackgroundColor: |
70 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( | 91 gfx::SkColorToCalibratedNSColor(nativeTheme->GetSystemColor( |
71 ui::NativeTheme::kColorId_DialogBackground))]; | 92 ui::NativeTheme::kColorId_DialogBackground))]; |
72 | 93 |
73 [self layout]; | 94 [self layout]; |
74 | |
75 delegate_->OnToolbarActionsBarBubbleShown(); | |
76 } | 95 } |
77 return self; | 96 return self; |
78 } | 97 } |
79 | 98 |
| 99 - (IBAction)showWindow:(id)sender { |
| 100 delegate_->OnBubbleShown(); |
| 101 [super showWindow:sender]; |
| 102 } |
| 103 |
80 // Private ///////////////////////////////////////////////////////////////////// | 104 // Private ///////////////////////////////////////////////////////////////////// |
81 | 105 |
82 - (void)windowWillClose:(NSNotification*)notification { | 106 - (void)windowWillClose:(NSNotification*)notification { |
83 if (!acknowledged_) { | 107 if (!acknowledged_) { |
84 delegate_->OnToolbarActionsBarBubbleClosed( | 108 delegate_->OnBubbleClosed( |
85 ToolbarActionsBarBubbleDelegate::DISMISSED); | 109 ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS); |
86 acknowledged_ = YES; | 110 acknowledged_ = YES; |
87 } | 111 } |
88 [super windowWillClose:notification]; | 112 [super windowWillClose:notification]; |
89 } | 113 } |
90 | 114 |
91 - (NSAttributedString*)attributedStringWithString:(int)stringId | 115 - (NSAttributedString*)attributedStringWithString:(const base::string16&)string |
92 fontSize:(CGFloat)fontSize | 116 fontSize:(CGFloat)fontSize |
93 alignment:(NSTextAlignment)alignment { | 117 alignment:(NSTextAlignment)alignment { |
94 NSString* string = l10n_util::GetNSString(stringId); | 118 NSString* cocoaString = base::SysUTF16ToNSString(string); |
95 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 119 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
96 [[NSMutableParagraphStyle alloc] init]); | 120 [[NSMutableParagraphStyle alloc] init]); |
97 [paragraphStyle setAlignment:alignment]; | 121 [paragraphStyle setAlignment:alignment]; |
98 NSDictionary* attributes = @{ | 122 NSDictionary* attributes = @{ |
99 NSFontAttributeName : [NSFont systemFontOfSize:fontSize], | 123 NSFontAttributeName : [NSFont systemFontOfSize:fontSize], |
100 NSForegroundColorAttributeName : | 124 NSForegroundColorAttributeName : |
101 [NSColor colorWithCalibratedWhite:0.2 alpha:1.0], | 125 [NSColor colorWithCalibratedWhite:0.2 alpha:1.0], |
102 NSParagraphStyleAttributeName : paragraphStyle.get() | 126 NSParagraphStyleAttributeName : paragraphStyle.get() |
103 }; | 127 }; |
104 return [[[NSAttributedString alloc] initWithString:string | 128 return [[[NSAttributedString alloc] initWithString:cocoaString |
105 attributes:attributes] autorelease]; | 129 attributes:attributes] autorelease]; |
106 } | 130 } |
107 | 131 |
108 - (NSTextField*)addTextFieldWithString:(NSAttributedString*)attributedString { | 132 - (NSTextField*)addTextFieldWithString:(const base::string16&)string |
| 133 fontSize:(CGFloat)fontSize |
| 134 alignment:(NSTextAlignment)alignment { |
| 135 NSAttributedString* attributedString = |
| 136 [self attributedStringWithString:string |
| 137 fontSize:fontSize |
| 138 alignment:alignment]; |
| 139 |
109 base::scoped_nsobject<NSTextField> textField( | 140 base::scoped_nsobject<NSTextField> textField( |
110 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 141 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
111 [textField setEditable:NO]; | 142 [textField setEditable:NO]; |
112 [textField setBordered:NO]; | 143 [textField setBordered:NO]; |
113 [textField setDrawsBackground:NO]; | 144 [textField setDrawsBackground:NO]; |
114 [textField setAttributedStringValue:attributedString]; | 145 [textField setAttributedStringValue:attributedString]; |
115 [[[self window] contentView] addSubview:textField]; | 146 [[[self window] contentView] addSubview:textField]; |
| 147 [textField sizeToFit]; |
116 return textField.autorelease(); | 148 return textField.autorelease(); |
117 } | 149 } |
118 | 150 |
| 151 - (ExtensionMessageBubbleButton*)addButtonWithString: |
| 152 (const base::string16&)string |
| 153 isPrimary:(BOOL)isPrimary { |
| 154 ExtensionMessageBubbleButton* button = |
| 155 [[ExtensionMessageBubbleButton alloc] initWithFrame:NSZeroRect]; |
| 156 NSAttributedString* buttonString = |
| 157 [self attributedStringWithString:string |
| 158 fontSize:13.0 |
| 159 alignment:NSCenterTextAlignment]; |
| 160 [button setAttributedTitle:buttonString]; |
| 161 [button setIsPrimary:isPrimary]; |
| 162 [[button cell] setBordered:NO]; |
| 163 [button setTarget:self]; |
| 164 [button setAction:@selector(onButtonClicked:)]; |
| 165 [[[self window] contentView] addSubview:button]; |
| 166 [button sizeToFit]; |
| 167 return button; |
| 168 } |
| 169 |
119 - (void)layout { | 170 - (void)layout { |
120 // We first construct the different pieces of the bubble (the heading, the | 171 // We first construct the different pieces of the bubble (the heading, the |
121 // content, and the button), and size them appropriately. | 172 // content, and the button), and size them appropriately. |
122 NSAttributedString* headingString = | 173 NSTextField* heading = |
123 [self attributedStringWithString:IDS_EXTENSION_TOOLBAR_BUBBLE_HEADING | 174 [self addTextFieldWithString:delegate_->GetHeadingText() |
124 fontSize:13.0 | 175 fontSize:13.0 |
125 alignment:NSLeftTextAlignment]; | 176 alignment:NSLeftTextAlignment]; |
126 NSTextField* heading = [self addTextFieldWithString:headingString]; | |
127 [heading sizeToFit]; | |
128 NSSize headingSize = [heading frame].size; | 177 NSSize headingSize = [heading frame].size; |
129 | 178 |
130 NSAttributedString* contentString = | 179 NSTextField* content = |
131 [self attributedStringWithString:IDS_EXTENSION_TOOLBAR_BUBBLE_CONTENT | 180 [self addTextFieldWithString:delegate_->GetBodyText() |
132 fontSize:12.0 | 181 fontSize:12.0 |
133 alignment:NSLeftTextAlignment]; | 182 alignment:NSLeftTextAlignment]; |
134 NSTextField* content = [self addTextFieldWithString:contentString]; | 183 CGFloat newWidth = headingSize.width + 50; |
135 [content setFrame:NSMakeRect(0, 0, headingSize.width, 0)]; | 184 [content setFrame:NSMakeRect(0, 0, newWidth, 0)]; |
136 // The content should have the same (max) width as the heading, which means | 185 // The content should have the same (max) width as the heading, which means |
137 // the text will most likely wrap. | 186 // the text will most likely wrap. |
138 NSSize contentSize = NSMakeSize(headingSize.width, | 187 NSSize contentSize = NSMakeSize(newWidth, |
139 [GTMUILocalizerAndLayoutTweaker | 188 [GTMUILocalizerAndLayoutTweaker |
140 sizeToFitFixedWidthTextField:content]); | 189 sizeToFitFixedWidthTextField:content]); |
141 | 190 |
142 NSButton* button = [[ExtensionToolbarIconSurfacingBubbleButton alloc] | 191 base::string16 learnMore = delegate_->GetLearnMoreButtonText(); |
143 initWithFrame:NSZeroRect]; | 192 NSSize learnMoreSize = NSZeroSize; |
144 NSAttributedString* buttonString = | 193 if (!learnMore.empty()) { // The "learn more" link is optional. |
145 [self attributedStringWithString:IDS_EXTENSION_TOOLBAR_BUBBLE_OK | 194 NSAttributedString* learnMoreString = |
146 fontSize:13.0 | 195 [self attributedStringWithString:learnMore |
147 alignment:NSCenterTextAlignment]; | 196 fontSize:13.0 |
148 [button setAttributedTitle:buttonString]; | 197 alignment:NSLeftTextAlignment]; |
149 [[button cell] setBordered:NO]; | 198 learnMoreButton_ = |
150 [button setTarget:self]; | 199 [[HyperlinkButtonCell buttonWithString:learnMoreString.string] retain]; |
151 [button setAction:@selector(onButtonClicked:)]; | 200 [learnMoreButton_ setTarget:self]; |
152 [[[self window] contentView] addSubview:button]; | 201 [learnMoreButton_ setAction:@selector(onButtonClicked:)]; |
153 [button sizeToFit]; | 202 [[[self window] contentView] addSubview:learnMoreButton_]; |
154 // The button's size will only account for the text by default, so pad it a | 203 [learnMoreButton_ sizeToFit]; |
| 204 learnMoreSize = NSMakeSize(NSWidth([learnMoreButton_ frame]), |
| 205 NSHeight([learnMoreButton_ frame])); |
| 206 } |
| 207 |
| 208 // The buttons' sizes will only account for the text by default, so pad them a |
155 // bit to make it look good. | 209 // bit to make it look good. |
156 NSSize buttonSize = NSMakeSize(NSWidth([button frame]) + 40.0, | 210 const CGFloat kButtonHorizontalPadding = 40.0; |
157 NSHeight([button frame]) + 20.0); | 211 const CGFloat kButtonVerticalPadding = 20.0; |
| 212 |
| 213 base::string16 cancelStr = delegate_->GetDismissButtonText(); |
| 214 NSSize dismissButtonSize = NSZeroSize; |
| 215 if (!cancelStr.empty()) { // A cancel/dismiss button is optional. |
| 216 dismissButton_ = [self addButtonWithString:cancelStr |
| 217 isPrimary:NO]; |
| 218 dismissButtonSize = |
| 219 NSMakeSize(NSWidth([dismissButton_ frame]) + kButtonHorizontalPadding, |
| 220 NSHeight([dismissButton_ frame]) + kButtonVerticalPadding); |
| 221 } |
| 222 |
| 223 actionButton_ = [self addButtonWithString:delegate_->GetActionButtonText() |
| 224 isPrimary:YES]; |
| 225 NSSize actionButtonSize = |
| 226 NSMakeSize(NSWidth([actionButton_ frame]) + kButtonHorizontalPadding, |
| 227 NSHeight([actionButton_ frame]) + kButtonVerticalPadding); |
158 | 228 |
159 const CGFloat kHorizontalPadding = 15.0; | 229 const CGFloat kHorizontalPadding = 15.0; |
160 const CGFloat kVerticalPadding = 10.0; | 230 const CGFloat kVerticalPadding = 10.0; |
161 | 231 |
162 // Next, we set frame for all the different pieces of the bubble, from bottom | 232 // Next, we set frame for all the different pieces of the bubble, from bottom |
163 // to top. | 233 // to top. |
164 CGFloat windowWidth = headingSize.width + kHorizontalPadding * 2; | 234 CGFloat windowWidth = newWidth + kHorizontalPadding * 2; |
165 | 235 |
166 CGFloat currentHeight = 0; | 236 CGFloat currentHeight = 0; |
167 [button setFrame:NSMakeRect(windowWidth - buttonSize.width, | 237 [actionButton_ setFrame:NSMakeRect(windowWidth - actionButtonSize.width, |
168 currentHeight, | 238 currentHeight, |
169 buttonSize.width, | 239 actionButtonSize.width, |
170 buttonSize.height)]; | 240 actionButtonSize.height)]; |
171 currentHeight += buttonSize.height + kVerticalPadding; | 241 if (dismissButton_) { |
| 242 [dismissButton_ setFrame:NSMakeRect( |
| 243 windowWidth - actionButtonSize.width - dismissButtonSize.width, |
| 244 currentHeight, |
| 245 dismissButtonSize.width, |
| 246 dismissButtonSize.height)]; |
| 247 } |
| 248 currentHeight += actionButtonSize.height + kVerticalPadding; |
| 249 |
| 250 if (learnMoreButton_) { |
| 251 [learnMoreButton_ setFrame:NSMakeRect(kHorizontalPadding, |
| 252 currentHeight, |
| 253 learnMoreSize.width, |
| 254 learnMoreSize.height)]; |
| 255 currentHeight += learnMoreSize.height + kVerticalPadding; |
| 256 } |
| 257 |
172 [content setFrame:NSMakeRect(kHorizontalPadding, | 258 [content setFrame:NSMakeRect(kHorizontalPadding, |
173 currentHeight, | 259 currentHeight, |
174 contentSize.width, | 260 contentSize.width, |
175 contentSize.height)]; | 261 contentSize.height)]; |
176 currentHeight += contentSize.height + kVerticalPadding; | 262 currentHeight += contentSize.height + kVerticalPadding; |
177 [heading setFrame:NSMakeRect(kHorizontalPadding, | 263 [heading setFrame:NSMakeRect(kHorizontalPadding, |
178 currentHeight, | 264 currentHeight, |
179 headingSize.width, | 265 headingSize.width, |
180 headingSize.height)]; | 266 headingSize.height)]; |
181 | 267 |
182 // Update window frame. | 268 // Update window frame. |
183 NSRect windowFrame = [[self window] frame]; | 269 NSRect windowFrame = [[self window] frame]; |
184 NSSize windowSize = | 270 NSSize windowSize = |
185 NSMakeSize(windowWidth, | 271 NSMakeSize(windowWidth, |
186 currentHeight + headingSize.height + kVerticalPadding); | 272 currentHeight + headingSize.height + kVerticalPadding); |
187 // We need to convert the size to be in the window's coordinate system. Since | 273 // We need to convert the size to be in the window's coordinate system. Since |
188 // all we're doing is converting a size, and all views within a window share | 274 // all we're doing is converting a size, and all views within a window share |
189 // the same size metrics, it's okay that the size calculation came from | 275 // the same size metrics, it's okay that the size calculation came from |
190 // multiple different views. Pick a view to convert it. | 276 // multiple different views. Pick a view to convert it. |
191 windowSize = [heading convertSize:windowSize toView:nil]; | 277 windowSize = [heading convertSize:windowSize toView:nil]; |
192 windowFrame.size = windowSize; | 278 windowFrame.size = windowSize; |
193 [[self window] setFrame:windowFrame display:YES]; | 279 [[self window] setFrame:windowFrame display:YES]; |
194 } | 280 } |
195 | 281 |
196 - (void)onButtonClicked:(id)sender { | 282 - (void)onButtonClicked:(id)sender { |
197 if (!acknowledged_) { | 283 if (acknowledged_) |
198 delegate_->OnToolbarActionsBarBubbleClosed( | 284 return; |
199 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); | 285 ToolbarActionsBarBubbleDelegate::CloseAction action = |
200 acknowledged_ = YES; | 286 ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE; |
201 [self close]; | 287 if (learnMoreButton_ && sender == learnMoreButton_) { |
| 288 action = ToolbarActionsBarBubbleDelegate::CLOSE_LEARN_MORE; |
| 289 } else if (dismissButton_ && sender == dismissButton_) { |
| 290 action = ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS; |
| 291 } else { |
| 292 DCHECK_EQ(sender, actionButton_); |
| 293 action = ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE; |
202 } | 294 } |
| 295 acknowledged_ = YES; |
| 296 delegate_->OnBubbleClosed(action); |
| 297 [self close]; |
203 } | 298 } |
204 | 299 |
205 @end | 300 @end |
206 | 301 |
207 @implementation ExtensionToolbarIconSurfacingBubbleButton | 302 @implementation ExtensionMessageBubbleButton |
| 303 |
| 304 @synthesize isPrimary = isPrimary_; |
208 | 305 |
209 - (void)drawRect:(NSRect)rect { | 306 - (void)drawRect:(NSRect)rect { |
210 SkColor buttonColor = SkColorSetRGB(66, 133, 244); | 307 SkColor buttonColor; |
211 SkColor textColor = [self hoverState] == kHoverStateNone ? | 308 SkColor textColor; |
212 SkColorSetARGB(230, 255, 255, 255) : SK_ColorWHITE; | 309 if (isPrimary_) { |
| 310 buttonColor = SkColorSetRGB(66, 133, 244); |
| 311 textColor = [self hoverState] == kHoverStateNone ? |
| 312 SkColorSetARGB(220, 255, 255, 255) : SK_ColorWHITE; |
| 313 } else { |
| 314 buttonColor = SK_ColorTRANSPARENT; |
| 315 textColor = [self hoverState] == kHoverStateNone ? |
| 316 SkColorSetARGB(220, 0, 0, 0) : SK_ColorBLACK; |
| 317 } |
213 NSRect bounds = [self bounds]; | 318 NSRect bounds = [self bounds]; |
214 NSAttributedString* title = [self attributedTitle]; | 319 NSAttributedString* title = [self attributedTitle]; |
215 | 320 |
216 [gfx::SkColorToCalibratedNSColor(buttonColor) set]; | 321 [gfx::SkColorToCalibratedNSColor(buttonColor) set]; |
217 NSRectFillUsingOperation(bounds, NSCompositeSourceOver); | 322 NSRectFillUsingOperation(bounds, NSCompositeSourceOver); |
218 | 323 |
219 base::scoped_nsobject<NSMutableAttributedString> selectedTitle( | 324 base::scoped_nsobject<NSMutableAttributedString> selectedTitle( |
220 [[NSMutableAttributedString alloc] initWithAttributedString:title]); | 325 [[NSMutableAttributedString alloc] initWithAttributedString:title]); |
221 NSColor* selectedTitleColor = | 326 NSColor* selectedTitleColor = |
222 gfx::SkColorToCalibratedNSColor(textColor); | 327 gfx::SkColorToCalibratedNSColor(textColor); |
223 [selectedTitle addAttribute:NSForegroundColorAttributeName | 328 [selectedTitle addAttribute:NSForegroundColorAttributeName |
224 value:selectedTitleColor | 329 value:selectedTitleColor |
225 range:NSMakeRange(0, [title length])]; | 330 range:NSMakeRange(0, [title length])]; |
226 | 331 |
| 332 if (!isPrimary_) { |
| 333 [[NSColor darkGrayColor] setStroke]; |
| 334 [NSBezierPath strokeRect:bounds]; |
| 335 } |
227 [[self cell] drawTitle:selectedTitle.get() | 336 [[self cell] drawTitle:selectedTitle.get() |
228 withFrame:bounds | 337 withFrame:bounds |
229 inView:self]; | 338 inView:self]; |
230 } | 339 } |
231 | 340 |
232 @end | 341 @end |
OLD | NEW |