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/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
28 #include "content/public/browser/native_web_keyboard_event.h" | 28 #include "content/public/browser/native_web_keyboard_event.h" |
29 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | |
29 #include "ui/base/cocoa/window_size_constants.h" | 30 #include "ui/base/cocoa/window_size_constants.h" |
30 #include "ui/base/l10n/l10n_util_mac.h" | 31 #include "ui/base/l10n/l10n_util_mac.h" |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Chooser bubble width. | 35 // Chooser bubble width. |
35 const CGFloat kChooserBubbleWidth = 320.0f; | 36 const CGFloat kChooserBubbleWidth = 320.0f; |
36 | 37 |
37 // Chooser bubble height. | 38 // Chooser bubble height. |
38 const CGFloat kChooserBubbleHeight = 220.0f; | 39 const CGFloat kChooserBubbleHeight = 300.0f; |
39 | 40 |
40 // Distance between the bubble border and the view that is closest to the | 41 // Distance between the bubble border and the view that is closest to the |
41 // border. | 42 // border. |
42 const CGFloat kMarginX = 20.0f; | 43 const CGFloat kMarginX = 20.0f; |
43 const CGFloat kMarginY = 20.0f; | 44 const CGFloat kMarginY = 20.0f; |
44 | 45 |
45 // Distance between two views inside the bubble. | 46 // Distance between two views inside the bubble. |
46 const CGFloat kHorizontalPadding = 10.0f; | 47 const CGFloat kHorizontalPadding = 10.0f; |
47 const CGFloat kVerticalPadding = 10.0f; | 48 const CGFloat kVerticalPadding = 10.0f; |
48 | 49 |
49 const CGFloat kTitlePaddingX = 50.0f; | 50 // Separator alpha value. |
51 const CGFloat kSeparatorAlphaValue = 0.6f; | |
52 | |
53 // Separator height. | |
54 const CGFloat kSeparatorHeight = 1.0f; | |
50 } | 55 } |
Robert Sesek
2016/02/04 23:11:59
Add a missing " // namespace" comment here.
juncai
2016/02/05 00:20:40
Done.
| |
51 | 56 |
52 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 57 scoped_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
53 return make_scoped_ptr(new ChooserBubbleUiCocoa(browser_, this)); | 58 return make_scoped_ptr(new ChooserBubbleUiCocoa(browser_, this)); |
54 } | 59 } |
55 | 60 |
56 @interface ChooserBubbleUiController | 61 @interface ChooserBubbleUiController |
57 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 62 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
58 @private | 63 @private |
59 // Bridge to the C++ class that created this object. | 64 // Bridge to the C++ class that created this object. |
60 ChooserBubbleUiCocoa* bridge_; | 65 ChooserBubbleUiCocoa* bridge_; |
61 | 66 |
62 base::scoped_nsobject<NSTextField> titleView_; | 67 base::scoped_nsobject<NSTextField> titleView_; |
63 base::scoped_nsobject<NSScrollView> scrollView_; | 68 base::scoped_nsobject<NSScrollView> scrollView_; |
64 base::scoped_nsobject<NSTableColumn> tableColumn_; | 69 base::scoped_nsobject<NSTableColumn> tableColumn_; |
65 base::scoped_nsobject<NSTableView> tableView_; | 70 base::scoped_nsobject<NSTableView> tableView_; |
66 base::scoped_nsobject<NSButton> connectButton_; | 71 base::scoped_nsobject<NSButton> connectButton_; |
67 base::scoped_nsobject<NSButton> cancelButton_; | 72 base::scoped_nsobject<NSButton> cancelButton_; |
73 base::scoped_nsobject<NSBox> separator_; | |
74 base::scoped_nsobject<NSTextField> privacyMessage_; | |
68 bool buttonPressed_; | 75 bool buttonPressed_; |
69 | 76 |
70 Browser* browser_; // Weak. | 77 Browser* browser_; // Weak. |
71 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. | 78 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. |
72 } | 79 } |
73 | 80 |
74 // Designated initializer. |browser| and |bridge| must both be non-nil. | 81 // Designated initializer. |browser| and |bridge| must both be non-nil. |
75 - (id)initWithBrowser:(Browser*)browser | 82 - (id)initWithBrowser:(Browser*)browser |
76 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate | 83 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate |
77 bridge:(ChooserBubbleUiCocoa*)bridge; | 84 bridge:(ChooserBubbleUiCocoa*)bridge; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 // Creates a button with |title| and |action|. | 121 // Creates a button with |title| and |action|. |
115 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | 122 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title |
116 action:(SEL)action; | 123 action:(SEL)action; |
117 | 124 |
118 // Creates the "Connect" button. | 125 // Creates the "Connect" button. |
119 - (base::scoped_nsobject<NSButton>)connectButton; | 126 - (base::scoped_nsobject<NSButton>)connectButton; |
120 | 127 |
121 // Creates the "Cancel" button. | 128 // Creates the "Cancel" button. |
122 - (base::scoped_nsobject<NSButton>)cancelButton; | 129 - (base::scoped_nsobject<NSButton>)cancelButton; |
123 | 130 |
131 // Creates the separator. | |
132 - (base::scoped_nsobject<NSBox>)separator; | |
133 | |
134 // Creates the privacy message. | |
135 - (base::scoped_nsobject<NSTextField>)privacyMessage; | |
136 | |
124 // Called when the "Connect" button is pressed. | 137 // Called when the "Connect" button is pressed. |
125 - (void)onConnect:(id)sender; | 138 - (void)onConnect:(id)sender; |
126 | 139 |
127 // Called when the "Cancel" button is pressed. | 140 // Called when the "Cancel" button is pressed. |
128 - (void)onCancel:(id)sender; | 141 - (void)onCancel:(id)sender; |
129 | 142 |
130 @end | 143 @end |
131 | 144 |
132 @implementation ChooserBubbleUiController | 145 @implementation ChooserBubbleUiController |
133 | 146 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 // | Chooser bubble title | | 208 // | Chooser bubble title | |
196 // | -------------------------------- | | 209 // | -------------------------------- | |
197 // | | option 0 | | | 210 // | | option 0 | | |
198 // | | option 1 | | | 211 // | | option 1 | | |
199 // | | option 2 | | | 212 // | | option 2 | | |
200 // | | | | | 213 // | | | | |
201 // | | | | | 214 // | | | | |
202 // | | | | | 215 // | | | | |
203 // | -------------------------------- | | 216 // | -------------------------------- | |
204 // | [ Connect] [ Cancel ] | | 217 // | [ Connect] [ Cancel ] | |
218 // |----------------------------------| | |
219 // | Privacy message | | |
205 // ------------------------------------ | 220 // ------------------------------------ |
206 | 221 |
207 // Determine the dimensions of the bubble. | 222 // Determine the dimensions of the bubble. |
208 // Once the height and width are set, the buttons and permission menus can | 223 // Once the height and width are set, the buttons and permission menus can |
209 // be laid out correctly. | 224 // be laid out correctly. |
210 NSRect bubbleFrame = | 225 NSRect bubbleFrame = |
211 NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight); | 226 NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight); |
212 | 227 |
213 // Create the views. | 228 // Create the views. |
214 // Title. | 229 // Title. |
215 titleView_ = [self bubbleTitle]; | 230 titleView_ = [self bubbleTitle]; |
216 CGFloat titleOriginX = kMarginX; | |
217 CGFloat titleHeight = NSHeight([titleView_ frame]); | 231 CGFloat titleHeight = NSHeight([titleView_ frame]); |
218 CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; | |
219 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; | |
220 [view addSubview:titleView_]; | |
221 | 232 |
222 // Connect button. | 233 // Connect button. |
223 connectButton_ = [self connectButton]; | 234 connectButton_ = [self connectButton]; |
235 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | |
236 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
237 | |
224 // Cancel button. | 238 // Cancel button. |
225 cancelButton_ = [self cancelButton]; | 239 cancelButton_ = [self cancelButton]; |
226 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | |
227 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
228 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); | 240 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); |
229 | 241 |
242 // Separator. | |
243 separator_ = [self separator]; | |
244 | |
245 // Privacy message. | |
246 privacyMessage_ = [self privacyMessage]; | |
247 CGFloat privacyMessageHeight = NSHeight([privacyMessage_ frame]); | |
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 - privacyMessageHeight; |
235 NSRect scrollFrame = | 254 NSRect scrollFrame = |
236 NSMakeRect(kMarginX, kMarginY + connectButtonHeight + kVerticalPadding, | 255 NSMakeRect(kMarginX, kMarginY + privacyMessageHeight + |
256 3 * kVerticalPadding + connectButtonHeight, | |
237 scrollViewWidth, scrollViewHeight); | 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 + privacyMessageHeight + 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 CGFloat separatorOriginX = 0.0f; | |
307 CGFloat separatorOriginY = kMarginY + privacyMessageHeight + kVerticalPadding; | |
308 [separator_ setFrameOrigin:NSMakePoint(separatorOriginX, separatorOriginY)]; | |
309 [view addSubview:separator_]; | |
310 | |
311 // Privacy message. | |
312 CGFloat privacyMessageOriginX = kMarginX; | |
313 CGFloat privacyMessageOriginY = kMarginY; | |
314 [privacyMessage_ | |
315 setFrameOrigin:NSMakePoint(privacyMessageOriginX, privacyMessageOriginY)]; | |
316 [view addSubview:privacyMessage_]; | |
317 | |
275 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; | 318 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; |
276 if ([[self window] isVisible]) { | 319 if ([[self window] isVisible]) { |
277 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called | 320 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called |
278 // within -setAnchorPoint) causes flickering. Avoid the flickering by | 321 // within -setAnchorPoint) causes flickering. Avoid the flickering by |
279 // manually adjusting the new frame's origin so that the top left stays the | 322 // manually adjusting the new frame's origin so that the top left stays the |
280 // same, and only calling -setFrame. | 323 // same, and only calling -setFrame. |
281 NSRect currentWindowFrame = [[self window] frame]; | 324 NSRect currentWindowFrame = [[self window] frame]; |
282 bubbleFrame.origin = currentWindowFrame.origin; | 325 bubbleFrame.origin = currentWindowFrame.origin; |
283 bubbleFrame.origin.y = bubbleFrame.origin.y + | 326 bubbleFrame.origin.y = bubbleFrame.origin.y + |
284 currentWindowFrame.size.height - | 327 currentWindowFrame.size.height - |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 - (base::scoped_nsobject<NSTextField>)bubbleTitle { | 428 - (base::scoped_nsobject<NSTextField>)bubbleTitle { |
386 base::scoped_nsobject<NSTextField> titleView( | 429 base::scoped_nsobject<NSTextField> titleView( |
387 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 430 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
388 [titleView setDrawsBackground:NO]; | 431 [titleView setDrawsBackground:NO]; |
389 [titleView setBezeled:NO]; | 432 [titleView setBezeled:NO]; |
390 [titleView setEditable:NO]; | 433 [titleView setEditable:NO]; |
391 [titleView setSelectable:NO]; | 434 [titleView setSelectable:NO]; |
392 [titleView setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_PROMPT)]; | 435 [titleView setStringValue:l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_PROMPT)]; |
393 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 436 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
394 [titleView sizeToFit]; | 437 [titleView sizeToFit]; |
395 NSRect titleFrame = [titleView frame]; | |
396 [titleView setFrameSize:NSMakeSize(NSWidth(titleFrame) + kTitlePaddingX, | |
397 NSHeight(titleFrame))]; | |
398 return titleView; | 438 return titleView; |
399 } | 439 } |
400 | 440 |
401 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | 441 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title |
402 action:(SEL)action { | 442 action:(SEL)action { |
403 base::scoped_nsobject<NSButton> button( | 443 base::scoped_nsobject<NSButton> button( |
404 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 444 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
405 [button setButtonType:NSMomentaryPushInButton]; | 445 [button setButtonType:NSMomentaryPushInButton]; |
406 [button setTitle:title]; | 446 [button setTitle:title]; |
407 [button setTarget:self]; | 447 [button setTarget:self]; |
408 [button setAction:action]; | 448 [button setAction:action]; |
409 [button sizeToFit]; | 449 [button sizeToFit]; |
410 return button; | 450 return button; |
411 } | 451 } |
412 | 452 |
413 - (base::scoped_nsobject<NSButton>)connectButton { | 453 - (base::scoped_nsobject<NSButton>)connectButton { |
414 NSString* connectTitle = | 454 NSString* connectTitle = |
415 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); | 455 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); |
416 return [self buttonWithTitle:connectTitle action:@selector(onConnect:)]; | 456 return [self buttonWithTitle:connectTitle action:@selector(onConnect:)]; |
417 } | 457 } |
418 | 458 |
419 - (base::scoped_nsobject<NSButton>)cancelButton { | 459 - (base::scoped_nsobject<NSButton>)cancelButton { |
420 NSString* cancelTitle = | 460 NSString* cancelTitle = |
421 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); | 461 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); |
422 return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; | 462 return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; |
423 } | 463 } |
424 | 464 |
465 - (base::scoped_nsobject<NSBox>)separator { | |
Robert Sesek
2016/02/04 23:11:59
Can you use -[BaseBubbleController horizontalSepar
juncai
2016/02/05 00:20:40
Done.
| |
466 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); | |
467 [spacer setBoxType:NSBoxSeparator]; | |
468 [spacer setBorderType:NSLineBorder]; | |
469 [spacer setAlphaValue:kSeparatorAlphaValue]; | |
470 [spacer setFrameSize:NSMakeSize(kChooserBubbleWidth, kSeparatorHeight)]; | |
471 return spacer; | |
472 } | |
473 | |
474 - (base::scoped_nsobject<NSTextField>)privacyMessage { | |
475 base::scoped_nsobject<NSTextField> privacyMessageView( | |
476 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
477 [privacyMessageView setDrawsBackground:NO]; | |
478 [privacyMessageView setBezeled:NO]; | |
479 [privacyMessageView setEditable:NO]; | |
480 [privacyMessageView setSelectable:NO]; | |
481 [privacyMessageView | |
482 setStringValue:l10n_util::GetNSString( | |
483 IDS_CHOOSER_BUBBLE_PRIVACY_MESSAGE_TEXT)]; | |
484 [privacyMessageView | |
485 setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
486 // The height is arbitrary as it will be adjusted later. | |
487 [privacyMessageView | |
488 setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, 0.0f)]; | |
489 [GTMUILocalizerAndLayoutTweaker | |
490 sizeToFitFixedWidthTextField:privacyMessageView]; | |
491 return privacyMessageView; | |
492 } | |
493 | |
425 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { | 494 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
426 NSRect frameA = [viewA frame]; | 495 NSRect frameA = [viewA frame]; |
427 NSRect frameB = [viewB frame]; | 496 NSRect frameB = [viewB frame]; |
428 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); | 497 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); |
429 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; | 498 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; |
430 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; | 499 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; |
431 return width; | 500 return width; |
432 } | 501 } |
433 | 502 |
434 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 503 + (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)]; | 569 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
501 } | 570 } |
502 | 571 |
503 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { | 572 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
504 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; | 573 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
505 } | 574 } |
506 | 575 |
507 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 576 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
508 chooser_bubble_ui_controller_ = nil; | 577 chooser_bubble_ui_controller_ = nil; |
509 } | 578 } |
OLD | NEW |