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/website_settings/chooser_bubble_ui_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
17 #import "chrome/browser/ui/chrome_style.h" | 17 #import "chrome/browser/ui/chrome_style.h" |
18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
22 #import "chrome/browser/ui/cocoa/hover_close_button.h" | 22 #import "chrome/browser/ui/cocoa/hover_close_button.h" |
23 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 24 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 25 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
26 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" | 26 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" |
27 #include "chrome/common/url_constants.h" | |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "content/public/browser/native_web_keyboard_event.h" | 29 #include "content/public/browser/native_web_keyboard_event.h" |
30 #include "skia/ext/skia_utils_mac.h" | |
31 #include "ui/base/cocoa/controls/hyperlink_text_view.h" | |
29 #include "ui/base/cocoa/window_size_constants.h" | 32 #include "ui/base/cocoa/window_size_constants.h" |
30 #include "ui/base/l10n/l10n_util_mac.h" | 33 #include "ui/base/l10n/l10n_util_mac.h" |
31 | 34 |
32 namespace { | 35 namespace { |
33 | 36 |
34 // Chooser bubble width. | 37 // Chooser bubble width. |
35 const CGFloat kChooserBubbleWidth = 320.0f; | 38 const CGFloat kChooserBubbleWidth = 320.0f; |
36 | 39 |
37 // Chooser bubble height. | 40 // Chooser bubble height. |
38 const CGFloat kChooserBubbleHeight = 220.0f; | 41 const CGFloat kChooserBubbleHeight = 280.0f; |
39 | 42 |
40 // Distance between the bubble border and the view that is closest to the | 43 // Distance between the bubble border and the view that is closest to the |
41 // border. | 44 // border. |
42 const CGFloat kMarginX = 20.0f; | 45 const CGFloat kMarginX = 20.0f; |
43 const CGFloat kMarginY = 20.0f; | 46 const CGFloat kMarginY = 20.0f; |
44 | 47 |
45 // Distance between two views inside the bubble. | 48 // Distance between two views inside the bubble. |
46 const CGFloat kHorizontalPadding = 10.0f; | 49 const CGFloat kHorizontalPadding = 10.0f; |
47 const CGFloat kVerticalPadding = 10.0f; | 50 const CGFloat kVerticalPadding = 10.0f; |
48 | 51 |
49 const CGFloat kTitlePaddingX = 50.0f; | 52 } // namespace |
50 } | |
51 | 53 |
52 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 54 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
53 return make_scoped_ptr(new ChooserBubbleUiCocoa(browser_, this)); | 55 return make_scoped_ptr(new ChooserBubbleUiCocoa(browser_, this)); |
54 } | 56 } |
55 | 57 |
56 @interface ChooserBubbleUiController | 58 @interface ChooserBubbleUiController |
57 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 59 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
58 @private | 60 @private |
59 // Bridge to the C++ class that created this object. | 61 // Bridge to the C++ class that created this object. |
60 ChooserBubbleUiCocoa* bridge_; | 62 ChooserBubbleUiCocoa* bridge_; |
61 | 63 |
62 base::scoped_nsobject<NSTextField> titleView_; | 64 base::scoped_nsobject<NSTextField> titleView_; |
63 base::scoped_nsobject<NSScrollView> scrollView_; | 65 base::scoped_nsobject<NSScrollView> scrollView_; |
64 base::scoped_nsobject<NSTableColumn> tableColumn_; | 66 base::scoped_nsobject<NSTableColumn> tableColumn_; |
65 base::scoped_nsobject<NSTableView> tableView_; | 67 base::scoped_nsobject<NSTableView> tableView_; |
66 base::scoped_nsobject<NSButton> connectButton_; | 68 base::scoped_nsobject<NSButton> connectButton_; |
67 base::scoped_nsobject<NSButton> cancelButton_; | 69 base::scoped_nsobject<NSButton> cancelButton_; |
70 base::scoped_nsobject<NSTextField> message_; | |
71 base::scoped_nsobject<HyperlinkTextView> helpLink_; | |
68 bool buttonPressed_; | 72 bool buttonPressed_; |
69 | 73 |
70 Browser* browser_; // Weak. | 74 Browser* browser_; // Weak. |
71 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. | 75 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. |
72 } | 76 } |
73 | 77 |
74 // Designated initializer. |browser| and |bridge| must both be non-nil. | 78 // Designated initializer. |browser| and |bridge| must both be non-nil. |
75 - (id)initWithBrowser:(Browser*)browser | 79 - (id)initWithBrowser:(Browser*)browser |
76 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate | 80 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate |
77 bridge:(ChooserBubbleUiCocoa*)bridge; | 81 bridge:(ChooserBubbleUiCocoa*)bridge; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // Creates a button with |title| and |action|. | 118 // Creates a button with |title| and |action|. |
115 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | 119 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title |
116 action:(SEL)action; | 120 action:(SEL)action; |
117 | 121 |
118 // Creates the "Connect" button. | 122 // Creates the "Connect" button. |
119 - (base::scoped_nsobject<NSButton>)connectButton; | 123 - (base::scoped_nsobject<NSButton>)connectButton; |
120 | 124 |
121 // Creates the "Cancel" button. | 125 // Creates the "Cancel" button. |
122 - (base::scoped_nsobject<NSButton>)cancelButton; | 126 - (base::scoped_nsobject<NSButton>)cancelButton; |
123 | 127 |
128 // Creates the message. | |
129 - (base::scoped_nsobject<NSTextField>)message; | |
130 | |
131 // Creates the help link. | |
132 - (base::scoped_nsobject<HyperlinkTextView>)helpLink; | |
133 | |
124 // Called when the "Connect" button is pressed. | 134 // Called when the "Connect" button is pressed. |
125 - (void)onConnect:(id)sender; | 135 - (void)onConnect:(id)sender; |
126 | 136 |
127 // Called when the "Cancel" button is pressed. | 137 // Called when the "Cancel" button is pressed. |
128 - (void)onCancel:(id)sender; | 138 - (void)onCancel:(id)sender; |
129 | 139 |
130 @end | 140 @end |
131 | 141 |
132 @implementation ChooserBubbleUiController | 142 @implementation ChooserBubbleUiController |
133 | 143 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 // | Chooser bubble title | | 205 // | Chooser bubble title | |
196 // | -------------------------------- | | 206 // | -------------------------------- | |
197 // | | option 0 | | | 207 // | | option 0 | | |
198 // | | option 1 | | | 208 // | | option 1 | | |
199 // | | option 2 | | | 209 // | | option 2 | | |
200 // | | | | | 210 // | | | | |
201 // | | | | | 211 // | | | | |
202 // | | | | | 212 // | | | | |
203 // | -------------------------------- | | 213 // | -------------------------------- | |
204 // | [ Connect] [ Cancel ] | | 214 // | [ Connect] [ Cancel ] | |
215 // |----------------------------------| | |
216 // | Not seeing your device? Get help | | |
205 // ------------------------------------ | 217 // ------------------------------------ |
206 | 218 |
207 // Determine the dimensions of the bubble. | 219 // Determine the dimensions of the bubble. |
208 // Once the height and width are set, the buttons and permission menus can | 220 // Once the height and width are set, the buttons and permission menus can |
209 // be laid out correctly. | 221 // be laid out correctly. |
210 NSRect bubbleFrame = | 222 NSRect bubbleFrame = |
211 NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight); | 223 NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight); |
212 | 224 |
213 // Create the views. | 225 // Create the views. |
214 // Title. | 226 // Title. |
215 titleView_ = [self bubbleTitle]; | 227 titleView_ = [self bubbleTitle]; |
216 CGFloat titleOriginX = kMarginX; | |
217 CGFloat titleHeight = NSHeight([titleView_ frame]); | 228 CGFloat titleHeight = NSHeight([titleView_ frame]); |
218 CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; | |
219 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; | |
220 [view addSubview:titleView_]; | |
221 | 229 |
222 // Connect button. | 230 // Connect button. |
223 connectButton_ = [self connectButton]; | 231 connectButton_ = [self connectButton]; |
232 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | |
233 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
234 | |
224 // Cancel button. | 235 // Cancel button. |
225 cancelButton_ = [self cancelButton]; | 236 cancelButton_ = [self cancelButton]; |
226 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | |
227 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
228 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); | 237 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); |
229 | 238 |
239 // Message. | |
240 message_ = [self message]; | |
241 CGFloat messageWidth = NSWidth([message_ frame]); | |
242 CGFloat messageHeight = NSHeight([message_ frame]); | |
243 | |
244 // Help link. | |
245 helpLink_ = [self helpLink]; | |
246 | |
247 // Separator. | |
248 CGFloat separatorOriginX = 0.0f; | |
249 CGFloat separatorOriginY = kMarginY + messageHeight + kVerticalPadding; | |
250 NSBox* separator = | |
251 [self horizontalSeparatorWithFrame:NSMakeRect(separatorOriginX, | |
252 separatorOriginY, | |
253 kChooserBubbleWidth, 0.0f)]; | |
254 | |
230 // ScollView embedding with TableView. | 255 // ScollView embedding with TableView. |
231 CGFloat scrollViewWidth = kChooserBubbleWidth - 2 * kMarginX; | 256 CGFloat scrollViewWidth = kChooserBubbleWidth - 2 * kMarginX; |
232 CGFloat scrollViewHeight = kChooserBubbleHeight - 2 * kMarginY - | 257 CGFloat scrollViewHeight = kChooserBubbleHeight - 2 * kMarginY - |
233 2 * kVerticalPadding - titleHeight - | 258 4 * kVerticalPadding - titleHeight - |
234 connectButtonHeight; | 259 connectButtonHeight - messageHeight; |
235 NSRect scrollFrame = | 260 NSRect scrollFrame = NSMakeRect( |
236 NSMakeRect(kMarginX, kMarginY + connectButtonHeight + kVerticalPadding, | 261 kMarginX, |
237 scrollViewWidth, scrollViewHeight); | 262 kMarginY + messageHeight + 3 * kVerticalPadding + connectButtonHeight, |
263 scrollViewWidth, scrollViewHeight); | |
238 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); | 264 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); |
239 [scrollView_ setBorderType:NSBezelBorder]; | 265 [scrollView_ setBorderType:NSBezelBorder]; |
240 [scrollView_ setHasVerticalScroller:YES]; | 266 [scrollView_ setHasVerticalScroller:YES]; |
241 [scrollView_ setHasHorizontalScroller:YES]; | 267 [scrollView_ setHasHorizontalScroller:YES]; |
242 [scrollView_ setAutohidesScrollers:YES]; | 268 [scrollView_ setAutohidesScrollers:YES]; |
243 | 269 |
244 // TableView. | 270 // TableView. |
245 tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); | 271 tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); |
246 tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]); | 272 tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]); |
247 [tableColumn_ setWidth:(scrollViewWidth - kMarginX)]; | 273 [tableColumn_ setWidth:(scrollViewWidth - kMarginX)]; |
248 [tableView_ addTableColumn:tableColumn_]; | 274 [tableView_ addTableColumn:tableColumn_]; |
249 [tableView_ setDelegate:self]; | 275 [tableView_ setDelegate:self]; |
250 [tableView_ setDataSource:self]; | 276 [tableView_ setDataSource:self]; |
251 // Make the column title invisible. | 277 // Make the column title invisible. |
252 [tableView_ setHeaderView:nil]; | 278 [tableView_ setHeaderView:nil]; |
253 [tableView_ setFocusRingType:NSFocusRingTypeNone]; | 279 [tableView_ setFocusRingType:NSFocusRingTypeNone]; |
254 | 280 |
281 // Lay out the views. | |
282 // Title. | |
283 CGFloat titleOriginX = kMarginX; | |
284 CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; | |
285 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; | |
286 [view addSubview:titleView_]; | |
287 | |
288 // ScollView. | |
255 [scrollView_ setDocumentView:tableView_]; | 289 [scrollView_ setDocumentView:tableView_]; |
256 [view addSubview:scrollView_]; | 290 [view addSubview:scrollView_]; |
257 | 291 |
258 // Set connect button and cancel button to the right place. | 292 // Connect button. |
259 CGFloat connectButtonOriginX = kChooserBubbleWidth - kMarginX - | 293 CGFloat connectButtonOriginX = kChooserBubbleWidth - kMarginX - |
260 kHorizontalPadding - connectButtonWidth - | 294 kHorizontalPadding - connectButtonWidth - |
261 cancelButtonWidth; | 295 cancelButtonWidth; |
262 CGFloat connectButtonOriginY = kMarginY; | 296 CGFloat connectButtonOriginY = |
297 kMarginY + messageHeight + 2 * kVerticalPadding; | |
263 [connectButton_ | 298 [connectButton_ |
264 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; | 299 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; |
265 [connectButton_ setEnabled:NO]; | 300 [connectButton_ setEnabled:NO]; |
266 [view addSubview:connectButton_]; | 301 [view addSubview:connectButton_]; |
267 | 302 |
303 // Cancel button. | |
268 CGFloat cancelButtonOriginX = | 304 CGFloat cancelButtonOriginX = |
269 kChooserBubbleWidth - kMarginX - cancelButtonWidth; | 305 kChooserBubbleWidth - kMarginX - cancelButtonWidth; |
270 CGFloat cancelButtonOriginY = kMarginY; | 306 CGFloat cancelButtonOriginY = connectButtonOriginY; |
271 [cancelButton_ | 307 [cancelButton_ |
272 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; | 308 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; |
273 [view addSubview:cancelButton_]; | 309 [view addSubview:cancelButton_]; |
274 | 310 |
311 // Separator. | |
312 [view addSubview:separator]; | |
313 | |
314 // Message. | |
315 CGFloat messageOriginX = kMarginX; | |
316 CGFloat messageOriginY = kMarginY; | |
317 [message_ setFrameOrigin:NSMakePoint(messageOriginX, messageOriginY)]; | |
318 [view addSubview:message_]; | |
319 | |
320 // Help link. | |
321 CGFloat helpLinkOriginX = kMarginX + messageWidth; | |
322 CGFloat helpLinkOriginY = kMarginY; | |
323 [helpLink_ setFrameOrigin:NSMakePoint(helpLinkOriginX, helpLinkOriginY)]; | |
324 [view addSubview:helpLink_]; | |
325 | |
275 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; | 326 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; |
276 if ([[self window] isVisible]) { | 327 if ([[self window] isVisible]) { |
277 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called | 328 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called |
278 // within -setAnchorPoint) causes flickering. Avoid the flickering by | 329 // within -setAnchorPoint) causes flickering. Avoid the flickering by |
279 // manually adjusting the new frame's origin so that the top left stays the | 330 // manually adjusting the new frame's origin so that the top left stays the |
280 // same, and only calling -setFrame. | 331 // same, and only calling -setFrame. |
281 NSRect currentWindowFrame = [[self window] frame]; | 332 NSRect currentWindowFrame = [[self window] frame]; |
282 bubbleFrame.origin = currentWindowFrame.origin; | 333 bubbleFrame.origin = currentWindowFrame.origin; |
283 bubbleFrame.origin.y = bubbleFrame.origin.y + | 334 bubbleFrame.origin.y = bubbleFrame.origin.y + |
284 currentWindowFrame.size.height - | 335 currentWindowFrame.size.height - |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 - (base::scoped_nsobject<NSTextField>)bubbleTitle { | 436 - (base::scoped_nsobject<NSTextField>)bubbleTitle { |
386 base::scoped_nsobject<NSTextField> titleView( | 437 base::scoped_nsobject<NSTextField> titleView( |
387 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 438 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
388 [titleView setDrawsBackground:NO]; | 439 [titleView setDrawsBackground:NO]; |
389 [titleView setBezeled:NO]; | 440 [titleView setBezeled:NO]; |
390 [titleView setEditable:NO]; | 441 [titleView setEditable:NO]; |
391 [titleView setSelectable:NO]; | 442 [titleView setSelectable:NO]; |
392 [titleView setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_PROMPT)]; | 443 [titleView setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_PROMPT)]; |
393 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 444 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
394 [titleView sizeToFit]; | 445 [titleView sizeToFit]; |
395 NSRect titleFrame = [titleView frame]; | |
396 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, | |
397 NSHeight(titleFrame))]; | |
398 return titleView; | 446 return titleView; |
399 } | 447 } |
400 | 448 |
401 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | 449 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title |
402 action:(SEL)action { | 450 action:(SEL)action { |
403 base::scoped_nsobject<NSButton> button( | 451 base::scoped_nsobject<NSButton> button( |
404 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 452 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
405 [button setButtonType:NSMomentaryPushInButton]; | 453 [button setButtonType:NSMomentaryPushInButton]; |
406 [button setTitle:title]; | 454 [button setTitle:title]; |
407 [button setTarget:self]; | 455 [button setTarget:self]; |
408 [button setAction:action]; | 456 [button setAction:action]; |
409 [button sizeToFit]; | 457 [button sizeToFit]; |
410 return button; | 458 return button; |
411 } | 459 } |
412 | 460 |
413 - (base::scoped_nsobject<NSButton>)connectButton { | 461 - (base::scoped_nsobject<NSButton>)connectButton { |
414 NSString* connectTitle = | 462 NSString* connectTitle = |
415 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); | 463 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); |
416 return [self buttonWithTitle:connectTitle action:@selector(onConnect:)]; | 464 return [self buttonWithTitle:connectTitle action:@selector(onConnect:)]; |
417 } | 465 } |
418 | 466 |
419 - (base::scoped_nsobject<NSButton>)cancelButton { | 467 - (base::scoped_nsobject<NSButton>)cancelButton { |
420 NSString* cancelTitle = | 468 NSString* cancelTitle = |
421 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); | 469 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); |
422 return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; | 470 return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; |
423 } | 471 } |
424 | 472 |
473 - (base::scoped_nsobject<NSTextField>)message { | |
474 base::scoped_nsobject<NSTextField> messageView( | |
475 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
476 [messageView setDrawsBackground:NO]; | |
477 [messageView setBezeled:NO]; | |
478 [messageView setEditable:NO]; | |
479 [messageView setSelectable:NO]; | |
480 [messageView | |
481 setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICE_TEXT)]; | |
482 [messageView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
483 [messageView sizeToFit]; | |
484 return messageView; | |
485 } | |
486 | |
487 - (base::scoped_nsobject<HyperlinkTextView>)helpLink { | |
488 base::scoped_nsobject<HyperlinkTextView> helpTextView( | |
489 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); | |
490 NSString* getHelpText = | |
491 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT); | |
492 | |
493 NSColor* linkColor = | |
494 skia::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); | |
495 [helpTextView setMessage:getHelpText | |
496 withFont:[NSFont systemFontOfSize:[NSFont systemFontSize]] | |
497 messageColor:linkColor]; | |
498 | |
499 NSUInteger getHelpOffset = 0; | |
500 [helpTextView addLinkRange:NSMakeRange(getHelpOffset, [getHelpText length]) | |
Robert Sesek
2016/02/16 21:26:40
Since you're linkifying the entire text content, d
juncai
2016/02/17 01:06:42
Done.
| |
501 withURL:@(chrome::kChooserUIGetHelpURL) | |
502 linkColor:linkColor]; | |
503 | |
504 // Removes the underlining from the link. | |
505 NSTextStorage* textStorage = [helpTextView textStorage]; | |
506 [textStorage addAttribute:NSUnderlineStyleAttributeName | |
507 value:@(NSUnderlineStyleNone) | |
508 range:NSMakeRange(getHelpOffset, [getHelpText length])]; | |
509 | |
510 [helpTextView setFrameSize:NSMakeSize(70, 17)]; | |
511 | |
512 return helpTextView; | |
513 } | |
514 | |
425 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { | 515 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
426 NSRect frameA = [viewA frame]; | 516 NSRect frameA = [viewA frame]; |
427 NSRect frameB = [viewB frame]; | 517 NSRect frameB = [viewB frame]; |
428 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); | 518 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); |
429 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; | 519 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; |
430 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; | 520 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; |
431 return width; | 521 return width; |
432 } | 522 } |
433 | 523 |
434 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 524 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; | 590 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
501 } | 591 } |
502 | 592 |
503 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { | 593 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
504 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; | 594 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
505 } | 595 } |
506 | 596 |
507 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 597 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
508 chooser_bubble_ui_controller_ = nil; | 598 chooser_bubble_ui_controller_ = nil; |
509 } | 599 } |
OLD | NEW |