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