| 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> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| 11 | 11 |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.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/chooser_content_view.h" |
| 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 24 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 25 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" | 25 #include "chrome/browser/ui/website_settings/chooser_bubble_delegate.h" |
| 26 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/bubble/bubble_controller.h" | 27 #include "components/bubble/bubble_controller.h" |
| 28 #include "components/url_formatter/elide_url.h" | 28 #include "components/url_formatter/elide_url.h" |
| 29 #include "content/public/browser/native_web_keyboard_event.h" | 29 #include "content/public/browser/native_web_keyboard_event.h" |
| 30 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | |
| 31 #include "ui/base/cocoa/cocoa_base_utils.h" | 30 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 32 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | |
| 33 #include "ui/base/cocoa/window_size_constants.h" | 31 #include "ui/base/cocoa/window_size_constants.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/l10n/l10n_util_mac.h" | 33 #include "ui/base/l10n/l10n_util_mac.h" |
| 36 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 37 #include "url/origin.h" | 35 #include "url/origin.h" |
| 38 | 36 |
| 39 namespace { | |
| 40 | |
| 41 // Chooser bubble width. | |
| 42 const CGFloat kChooserBubbleWidth = 320.0f; | |
| 43 | |
| 44 // Chooser bubble height. | |
| 45 const CGFloat kChooserBubbleHeight = 280.0f; | |
| 46 | |
| 47 // Distance between the bubble border and the view that is closest to the | |
| 48 // border. | |
| 49 const CGFloat kMarginX = 20.0f; | |
| 50 const CGFloat kMarginY = 20.0f; | |
| 51 | |
| 52 // Distance between two views inside the bubble. | |
| 53 const CGFloat kHorizontalPadding = 10.0f; | |
| 54 const CGFloat kVerticalPadding = 10.0f; | |
| 55 | |
| 56 } // namespace | |
| 57 | |
| 58 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { | 37 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| 59 return base::WrapUnique( | 38 return base::WrapUnique( |
| 60 new ChooserBubbleUiCocoa(browser_, chooser_controller())); | 39 new ChooserBubbleUiCocoa(browser_, chooser_controller())); |
| 61 } | 40 } |
| 62 | 41 |
| 63 @interface ChooserBubbleUiController | 42 @interface ChooserBubbleUiController |
| 64 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 43 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
| 65 @private | 44 @private |
| 66 // Bridge to the C++ class that created this object. | 45 // Bridge to the C++ class that created this object. |
| 67 ChooserBubbleUiCocoa* bridge_; | 46 ChooserBubbleUiCocoa* bridge_; // Weak. |
| 47 bool buttonPressed_; |
| 68 | 48 |
| 69 base::scoped_nsobject<NSTextField> titleView_; | 49 base::scoped_nsobject<ChooserContentView> chooserContentView_; |
| 70 base::scoped_nsobject<NSScrollView> scrollView_; | 50 NSTableView* tableView_; // Weak. |
| 71 base::scoped_nsobject<NSTableColumn> tableColumn_; | 51 NSButton* connectButton_; // Weak. |
| 72 base::scoped_nsobject<NSTableView> tableView_; | 52 NSButton* cancelButton_; // Weak. |
| 73 base::scoped_nsobject<NSButton> connectButton_; | 53 NSButton* helpButton_; // Weak. |
| 74 base::scoped_nsobject<NSButton> cancelButton_; | |
| 75 base::scoped_nsobject<NSTextField> message_; | |
| 76 base::scoped_nsobject<NSButton> getHelpButton_; | |
| 77 bool buttonPressed_; | |
| 78 | 54 |
| 79 Browser* browser_; // Weak. | 55 Browser* browser_; // Weak. |
| 80 ChooserController* chooserController_; // Weak. | 56 ChooserController* chooserController_; // Weak. |
| 81 } | 57 } |
| 82 | 58 |
| 83 // Designated initializer. |browser| and |bridge| must both be non-nil. | 59 // Designated initializer. |browser| and |bridge| must both be non-nil. |
| 84 - (id)initWithBrowser:(Browser*)browser | 60 - (id)initWithBrowser:(Browser*)browser |
| 85 chooserController:(ChooserController*)chooserController | 61 chooserController:(ChooserController*)chooserController |
| 86 bubbleReference:(BubbleReference)bubbleReference | 62 bubbleReference:(BubbleReference)bubbleReference |
| 87 bridge:(ChooserBubbleUiCocoa*)bridge; | 63 bridge:(ChooserBubbleUiCocoa*)bridge; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 111 | 87 |
| 112 // Update |tableView_| when chooser options changed. | 88 // Update |tableView_| when chooser options changed. |
| 113 - (void)updateTableView; | 89 - (void)updateTableView; |
| 114 | 90 |
| 115 // Determines if the bubble has an anchor in a corner or no anchor at all. | 91 // Determines if the bubble has an anchor in a corner or no anchor at all. |
| 116 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; | 92 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation; |
| 117 | 93 |
| 118 // Returns the expected parent for this bubble. | 94 // Returns the expected parent for this bubble. |
| 119 - (NSWindow*)getExpectedParentWindow; | 95 - (NSWindow*)getExpectedParentWindow; |
| 120 | 96 |
| 121 // Creates the title for the bubble. | |
| 122 - (base::scoped_nsobject<NSTextField>)bubbleTitle; | |
| 123 | |
| 124 // Creates a button with |title| and |action|. | |
| 125 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | |
| 126 action:(SEL)action; | |
| 127 | |
| 128 // Creates the "Connect" button. | |
| 129 - (base::scoped_nsobject<NSButton>)connectButton; | |
| 130 | |
| 131 // Creates the "Cancel" button. | |
| 132 - (base::scoped_nsobject<NSButton>)cancelButton; | |
| 133 | |
| 134 // Creates the message. | |
| 135 - (base::scoped_nsobject<NSTextField>)message; | |
| 136 | |
| 137 // Creates the "Get help" button. | |
| 138 - (base::scoped_nsobject<NSButton>)getHelpButton; | |
| 139 | |
| 140 // Called when the "Connect" button is pressed. | 97 // Called when the "Connect" button is pressed. |
| 141 - (void)onConnect:(id)sender; | 98 - (void)onConnect:(id)sender; |
| 142 | 99 |
| 143 // Called when the "Cancel" button is pressed. | 100 // Called when the "Cancel" button is pressed. |
| 144 - (void)onCancel:(id)sender; | 101 - (void)onCancel:(id)sender; |
| 145 | 102 |
| 146 // Called when the "Get help" button is pressed. | 103 // Called when the "Get help" button is pressed. |
| 147 - (void)onGetHelpPressed:(id)sender; | 104 - (void)onHelpPressed:(id)sender; |
| 148 | 105 |
| 149 @end | 106 @end |
| 150 | 107 |
| 151 @implementation ChooserBubbleUiController | 108 @implementation ChooserBubbleUiController |
| 152 | 109 |
| 153 - (id)initWithBrowser:(Browser*)browser | 110 - (id)initWithBrowser:(Browser*)browser |
| 154 chooserController:(ChooserController*)chooserController | 111 chooserController:(ChooserController*)chooserController |
| 155 bubbleReference:(BubbleReference)bubbleReference | 112 bubbleReference:(BubbleReference)bubbleReference |
| 156 bridge:(ChooserBubbleUiCocoa*)bridge { | 113 bridge:(ChooserBubbleUiCocoa*)bridge { |
| 157 DCHECK(browser); | 114 DCHECK(browser); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 - (void)parentWindowDidResize:(NSNotification*)notification { | 161 - (void)parentWindowDidResize:(NSNotification*)notification { |
| 205 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 162 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 206 } | 163 } |
| 207 | 164 |
| 208 - (void)parentWindowDidMove:(NSNotification*)notification { | 165 - (void)parentWindowDidMove:(NSNotification*)notification { |
| 209 DCHECK(bridge_); | 166 DCHECK(bridge_); |
| 210 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 167 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 211 } | 168 } |
| 212 | 169 |
| 213 - (void)show { | 170 - (void)show { |
| 214 NSView* view = [[self window] contentView]; | 171 chooserContentView_.reset([[ChooserContentView alloc] |
| 172 initWithChooserTitle: |
| 173 l10n_util::GetNSStringF( |
| 174 IDS_CHOOSER_BUBBLE_PROMPT, |
| 175 url_formatter::FormatOriginForSecurityDisplay( |
| 176 chooserController_->GetOrigin(), |
| 177 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]); |
| 215 | 178 |
| 216 // ------------------------------------ | 179 tableView_ = [chooserContentView_ tableView]; |
| 217 // | Chooser bubble title | | 180 connectButton_ = [chooserContentView_ connectButton]; |
| 218 // | -------------------------------- | | 181 cancelButton_ = [chooserContentView_ cancelButton]; |
| 219 // | | option 0 | | | 182 helpButton_ = [chooserContentView_ helpButton]; |
| 220 // | | option 1 | | | |
| 221 // | | option 2 | | | |
| 222 // | | | | | |
| 223 // | | | | | |
| 224 // | | | | | |
| 225 // | -------------------------------- | | |
| 226 // | [ Connect ] [ Cancel ] | | |
| 227 // |----------------------------------| | |
| 228 // | Not seeing your device? Get help | | |
| 229 // ------------------------------------ | |
| 230 | 183 |
| 231 // Determine the dimensions of the bubble. | 184 [connectButton_ setTarget:self]; |
| 232 // Once the height and width are set, the buttons and permission menus can | 185 [connectButton_ setAction:@selector(onConnect:)]; |
| 233 // be laid out correctly. | 186 [cancelButton_ setTarget:self]; |
| 234 NSRect bubbleFrame = | 187 [cancelButton_ setAction:@selector(onCancel:)]; |
| 235 NSMakeRect(0, 0, kChooserBubbleWidth, kChooserBubbleHeight); | |
| 236 | |
| 237 // Create the views. | |
| 238 // Title. | |
| 239 titleView_ = [self bubbleTitle]; | |
| 240 CGFloat titleHeight = NSHeight([titleView_ frame]); | |
| 241 | |
| 242 // Connect button. | |
| 243 connectButton_ = [self connectButton]; | |
| 244 CGFloat connectButtonWidth = NSWidth([connectButton_ frame]); | |
| 245 CGFloat connectButtonHeight = NSHeight([connectButton_ frame]); | |
| 246 | |
| 247 // Cancel button. | |
| 248 cancelButton_ = [self cancelButton]; | |
| 249 CGFloat cancelButtonWidth = NSWidth([cancelButton_ frame]); | |
| 250 | |
| 251 // Message. | |
| 252 message_ = [self message]; | |
| 253 CGFloat messageWidth = NSWidth([message_ frame]); | |
| 254 CGFloat messageHeight = NSHeight([message_ frame]); | |
| 255 | |
| 256 // Get help button. | |
| 257 getHelpButton_ = [self getHelpButton]; | |
| 258 | |
| 259 // Separator. | |
| 260 CGFloat separatorOriginX = 0.0f; | |
| 261 CGFloat separatorOriginY = kMarginY + messageHeight + kVerticalPadding; | |
| 262 NSBox* separator = | |
| 263 [self horizontalSeparatorWithFrame:NSMakeRect(separatorOriginX, | |
| 264 separatorOriginY, | |
| 265 kChooserBubbleWidth, 0.0f)]; | |
| 266 | |
| 267 // ScollView embedding with TableView. | |
| 268 CGFloat scrollViewWidth = kChooserBubbleWidth - 2 * kMarginX; | |
| 269 CGFloat scrollViewHeight = kChooserBubbleHeight - 2 * kMarginY - | |
| 270 4 * kVerticalPadding - titleHeight - | |
| 271 connectButtonHeight - messageHeight; | |
| 272 NSRect scrollFrame = NSMakeRect( | |
| 273 kMarginX, | |
| 274 kMarginY + messageHeight + 3 * kVerticalPadding + connectButtonHeight, | |
| 275 scrollViewWidth, scrollViewHeight); | |
| 276 scrollView_.reset([[NSScrollView alloc] initWithFrame:scrollFrame]); | |
| 277 [scrollView_ setBorderType:NSBezelBorder]; | |
| 278 [scrollView_ setHasVerticalScroller:YES]; | |
| 279 [scrollView_ setHasHorizontalScroller:YES]; | |
| 280 [scrollView_ setAutohidesScrollers:YES]; | |
| 281 | |
| 282 // TableView. | |
| 283 tableView_.reset([[NSTableView alloc] initWithFrame:NSZeroRect]); | |
| 284 tableColumn_.reset([[NSTableColumn alloc] initWithIdentifier:@""]); | |
| 285 [tableColumn_ setWidth:(scrollViewWidth - kMarginX)]; | |
| 286 [tableView_ addTableColumn:tableColumn_]; | |
| 287 [tableView_ setDelegate:self]; | 188 [tableView_ setDelegate:self]; |
| 288 [tableView_ setDataSource:self]; | 189 [tableView_ setDataSource:self]; |
| 289 // Make the column title invisible. | 190 [helpButton_ setTarget:self]; |
| 290 [tableView_ setHeaderView:nil]; | 191 [helpButton_ setAction:@selector(onHelpPressed:)]; |
| 291 [tableView_ setFocusRingType:NSFocusRingTypeNone]; | |
| 292 | 192 |
| 293 // Lay out the views. | 193 [[[self window] contentView] addSubview:chooserContentView_.get()]; |
| 294 // Title. | |
| 295 CGFloat titleOriginX = kMarginX; | |
| 296 CGFloat titleOriginY = kChooserBubbleHeight - kMarginY - titleHeight; | |
| 297 [titleView_ setFrameOrigin:NSMakePoint(titleOriginX, titleOriginY)]; | |
| 298 [view addSubview:titleView_]; | |
| 299 | 194 |
| 300 // ScollView. | 195 NSRect bubbleFrame = |
| 301 [scrollView_ setDocumentView:tableView_]; | 196 [[self window] frameRectForContentRect:[chooserContentView_ frame]]; |
| 302 [view addSubview:scrollView_]; | |
| 303 | |
| 304 // Connect button. | |
| 305 CGFloat connectButtonOriginX = kChooserBubbleWidth - kMarginX - | |
| 306 kHorizontalPadding - connectButtonWidth - | |
| 307 cancelButtonWidth; | |
| 308 CGFloat connectButtonOriginY = | |
| 309 kMarginY + messageHeight + 2 * kVerticalPadding; | |
| 310 [connectButton_ | |
| 311 setFrameOrigin:NSMakePoint(connectButtonOriginX, connectButtonOriginY)]; | |
| 312 [connectButton_ setEnabled:NO]; | |
| 313 [view addSubview:connectButton_]; | |
| 314 | |
| 315 // Cancel button. | |
| 316 CGFloat cancelButtonOriginX = | |
| 317 kChooserBubbleWidth - kMarginX - cancelButtonWidth; | |
| 318 CGFloat cancelButtonOriginY = connectButtonOriginY; | |
| 319 [cancelButton_ | |
| 320 setFrameOrigin:NSMakePoint(cancelButtonOriginX, cancelButtonOriginY)]; | |
| 321 [view addSubview:cancelButton_]; | |
| 322 | |
| 323 // Separator. | |
| 324 [view addSubview:separator]; | |
| 325 | |
| 326 // Message. | |
| 327 CGFloat messageOriginX = kMarginX; | |
| 328 CGFloat messageOriginY = kMarginY; | |
| 329 [message_ setFrameOrigin:NSMakePoint(messageOriginX, messageOriginY)]; | |
| 330 [view addSubview:message_]; | |
| 331 | |
| 332 // Get help button. | |
| 333 getHelpButton_ = [self getHelpButton]; | |
| 334 CGFloat getHelpButtonOriginX = | |
| 335 kMarginX + messageWidth - kHorizontalPadding / 2; | |
| 336 CGFloat getHelpButtonOriginY = kMarginY; | |
| 337 [getHelpButton_ | |
| 338 setFrameOrigin:NSMakePoint(getHelpButtonOriginX, getHelpButtonOriginY)]; | |
| 339 [view addSubview:getHelpButton_]; | |
| 340 | |
| 341 bubbleFrame = [[self window] frameRectForContentRect:bubbleFrame]; | |
| 342 if ([[self window] isVisible]) { | 197 if ([[self window] isVisible]) { |
| 343 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called | 198 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called |
| 344 // within -setAnchorPoint) causes flickering. Avoid the flickering by | 199 // within -setAnchorPoint) causes flickering. Avoid the flickering by |
| 345 // manually adjusting the new frame's origin so that the top left stays the | 200 // manually adjusting the new frame's origin so that the top left stays the |
| 346 // same, and only calling -setFrame. | 201 // same, and only calling -setFrame. |
| 347 NSRect currentWindowFrame = [[self window] frame]; | 202 NSRect currentWindowFrame = [[self window] frame]; |
| 348 bubbleFrame.origin = currentWindowFrame.origin; | 203 bubbleFrame.origin = currentWindowFrame.origin; |
| 349 bubbleFrame.origin.y = bubbleFrame.origin.y + | 204 bubbleFrame.origin.y = bubbleFrame.origin.y + |
| 350 currentWindowFrame.size.height - | 205 currentWindowFrame.size.height - |
| 351 bubbleFrame.size.height; | 206 bubbleFrame.size.height; |
| 352 [[self window] setFrame:bubbleFrame display:YES]; | 207 [[self window] setFrame:bubbleFrame display:YES]; |
| 353 } else { | 208 } else { |
| 354 [[self window] setFrame:bubbleFrame display:NO]; | 209 [[self window] setFrame:bubbleFrame display:NO]; |
| 355 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 210 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 356 [self showWindow:nil]; | 211 [self showWindow:nil]; |
| 357 [[self window] makeFirstResponder:nil]; | 212 [[self window] makeFirstResponder:nil]; |
| 358 [[self window] setInitialFirstResponder:tableView_.get()]; | 213 [[self window] setInitialFirstResponder:tableView_]; |
| 359 } | 214 } |
| 360 } | 215 } |
| 361 | 216 |
| 362 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 217 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
| 363 // When there are no devices, the table contains a message saying there are | 218 // When there are no devices, the table contains a message saying there are |
| 364 // no devices, so the number of rows is always at least 1. | 219 // no devices, so the number of rows is always at least 1. |
| 365 return std::max(static_cast<NSInteger>(chooserController_->NumOptions()), | 220 return std::max(static_cast<NSInteger>(chooserController_->NumOptions()), |
| 366 static_cast<NSInteger>(1)); | 221 static_cast<NSInteger>(1)); |
| 367 } | 222 } |
| 368 | 223 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 | 297 |
| 443 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { | 298 - (info_bubble::BubbleArrowLocation)getExpectedArrowLocation { |
| 444 return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow; | 299 return [self hasLocationBar] ? info_bubble::kTopLeft : info_bubble::kNoArrow; |
| 445 } | 300 } |
| 446 | 301 |
| 447 - (NSWindow*)getExpectedParentWindow { | 302 - (NSWindow*)getExpectedParentWindow { |
| 448 DCHECK(browser_->window()); | 303 DCHECK(browser_->window()); |
| 449 return browser_->window()->GetNativeWindow(); | 304 return browser_->window()->GetNativeWindow(); |
| 450 } | 305 } |
| 451 | 306 |
| 452 - (base::scoped_nsobject<NSTextField>)bubbleTitle { | |
| 453 base::scoped_nsobject<NSTextField> titleView( | |
| 454 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 455 [titleView setDrawsBackground:NO]; | |
| 456 [titleView setBezeled:NO]; | |
| 457 [titleView setEditable:NO]; | |
| 458 [titleView setSelectable:NO]; | |
| 459 [titleView setStringValue: | |
| 460 l10n_util::GetNSStringF( | |
| 461 IDS_CHOOSER_BUBBLE_PROMPT, | |
| 462 url_formatter::FormatOriginForSecurityDisplay( | |
| 463 chooserController_->GetOrigin(), | |
| 464 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]; | |
| 465 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 466 // The height is arbitrary as it will be adjusted later. | |
| 467 [titleView setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, 0.0f)]; | |
| 468 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | |
| 469 return titleView; | |
| 470 } | |
| 471 | |
| 472 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | |
| 473 action:(SEL)action { | |
| 474 base::scoped_nsobject<NSButton> button( | |
| 475 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | |
| 476 [button setButtonType:NSMomentaryPushInButton]; | |
| 477 [button setTitle:title]; | |
| 478 [button setTarget:self]; | |
| 479 [button setAction:action]; | |
| 480 [button sizeToFit]; | |
| 481 return button; | |
| 482 } | |
| 483 | |
| 484 - (base::scoped_nsobject<NSButton>)connectButton { | |
| 485 NSString* connectTitle = | |
| 486 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CONNECT_BUTTON_TEXT); | |
| 487 return [self buttonWithTitle:connectTitle action:@selector(onConnect:)]; | |
| 488 } | |
| 489 | |
| 490 - (base::scoped_nsobject<NSButton>)cancelButton { | |
| 491 NSString* cancelTitle = | |
| 492 l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_CANCEL_BUTTON_TEXT); | |
| 493 return [self buttonWithTitle:cancelTitle action:@selector(onCancel:)]; | |
| 494 } | |
| 495 | |
| 496 - (base::scoped_nsobject<NSTextField>)message { | |
| 497 base::scoped_nsobject<NSTextField> messageView( | |
| 498 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 499 [messageView setDrawsBackground:NO]; | |
| 500 [messageView setBezeled:NO]; | |
| 501 [messageView setEditable:NO]; | |
| 502 [messageView setSelectable:NO]; | |
| 503 [messageView | |
| 504 setStringValue:l10n_util::GetNSStringF(IDS_CHOOSER_BUBBLE_FOOTNOTE_TEXT, | |
| 505 base::string16())]; | |
| 506 [messageView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 507 [messageView sizeToFit]; | |
| 508 return messageView; | |
| 509 } | |
| 510 | |
| 511 - (base::scoped_nsobject<NSButton>)getHelpButton { | |
| 512 base::scoped_nsobject<NSButton> button( | |
| 513 [[NSButton alloc] initWithFrame:NSZeroRect]); | |
| 514 base::scoped_nsobject<HyperlinkButtonCell> cell([[HyperlinkButtonCell alloc] | |
| 515 initTextCell:l10n_util::GetNSString( | |
| 516 IDS_CHOOSER_BUBBLE_GET_HELP_LINK_TEXT)]); | |
| 517 [button setCell:cell.get()]; | |
| 518 [button sizeToFit]; | |
| 519 [button setTarget:self]; | |
| 520 [button setAction:@selector(onGetHelpPressed:)]; | |
| 521 return button; | |
| 522 } | |
| 523 | |
| 524 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { | 307 + (CGFloat)matchWidthsOf:(NSView*)viewA andOf:(NSView*)viewB { |
| 525 NSRect frameA = [viewA frame]; | 308 NSRect frameA = [viewA frame]; |
| 526 NSRect frameB = [viewB frame]; | 309 NSRect frameB = [viewB frame]; |
| 527 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); | 310 CGFloat width = std::max(NSWidth(frameA), NSWidth(frameB)); |
| 528 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; | 311 [viewA setFrameSize:NSMakeSize(width, NSHeight(frameA))]; |
| 529 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; | 312 [viewB setFrameSize:NSMakeSize(width, NSHeight(frameB))]; |
| 530 return width; | 313 return width; |
| 531 } | 314 } |
| 532 | 315 |
| 533 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 316 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 546 [self close]; | 329 [self close]; |
| 547 } | 330 } |
| 548 | 331 |
| 549 - (void)onCancel:(id)sender { | 332 - (void)onCancel:(id)sender { |
| 550 buttonPressed_ = true; | 333 buttonPressed_ = true; |
| 551 chooserController_->Cancel(); | 334 chooserController_->Cancel(); |
| 552 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_CANCELED); | 335 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_CANCELED); |
| 553 [self close]; | 336 [self close]; |
| 554 } | 337 } |
| 555 | 338 |
| 556 - (void)onGetHelpPressed:(id)sender { | 339 - (void)onHelpPressed:(id)sender { |
| 557 chooserController_->OpenHelpCenterUrl(); | 340 chooserController_->OpenHelpCenterUrl(); |
| 558 } | 341 } |
| 559 | 342 |
| 560 @end | 343 @end |
| 561 | 344 |
| 562 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( | 345 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( |
| 563 Browser* browser, | 346 Browser* browser, |
| 564 ChooserController* chooser_controller) | 347 ChooserController* chooser_controller) |
| 565 : browser_(browser), | 348 : browser_(browser), |
| 566 chooser_controller_(chooser_controller), | 349 chooser_controller_(chooser_controller), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; | 389 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
| 607 } | 390 } |
| 608 | 391 |
| 609 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { | 392 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
| 610 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; | 393 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
| 611 } | 394 } |
| 612 | 395 |
| 613 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 396 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 614 chooser_bubble_ui_controller_ = nil; | 397 chooser_bubble_ui_controller_ = nil; |
| 615 } | 398 } |
| OLD | NEW |