| 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_finder.h" | |
| 18 #include "chrome/browser/ui/browser_window.h" | 17 #include "chrome/browser/ui/browser_window.h" |
| 19 #import "chrome/browser/ui/chrome_style.h" | |
| 20 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 18 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 22 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 23 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 21 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 24 #import "chrome/browser/ui/cocoa/hover_close_button.h" | |
| 25 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 22 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 26 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 23 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 27 #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" |
| 28 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/bubble/bubble_controller.h" |
| 29 #include "components/url_formatter/elide_url.h" | 28 #include "components/url_formatter/elide_url.h" |
| 30 #include "content/public/browser/native_web_keyboard_event.h" | 29 #include "content/public/browser/native_web_keyboard_event.h" |
| 31 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 30 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
| 32 #include "ui/base/cocoa/cocoa_base_utils.h" | 31 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 33 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 32 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 34 #include "ui/base/cocoa/window_size_constants.h" | 33 #include "ui/base/cocoa/window_size_constants.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/l10n/l10n_util_mac.h" | 35 #include "ui/base/l10n/l10n_util_mac.h" |
| 37 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 38 #include "url/origin.h" | 37 #include "url/origin.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 49 // border. | 48 // border. |
| 50 const CGFloat kMarginX = 20.0f; | 49 const CGFloat kMarginX = 20.0f; |
| 51 const CGFloat kMarginY = 20.0f; | 50 const CGFloat kMarginY = 20.0f; |
| 52 | 51 |
| 53 // Distance between two views inside the bubble. | 52 // Distance between two views inside the bubble. |
| 54 const CGFloat kHorizontalPadding = 10.0f; | 53 const CGFloat kHorizontalPadding = 10.0f; |
| 55 const CGFloat kVerticalPadding = 10.0f; | 54 const CGFloat kVerticalPadding = 10.0f; |
| 56 | 55 |
| 57 } // namespace | 56 } // namespace |
| 58 | 57 |
| 59 std::unique_ptr<BubbleUi> ChooserBubbleController::BuildBubbleUi() { | 58 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { |
| 60 return base::WrapUnique(new ChooserBubbleUiCocoa(browser_, this)); | 59 return base::WrapUnique( |
| 60 new ChooserBubbleUiCocoa(browser_, chooser_controller())); |
| 61 } | 61 } |
| 62 | 62 |
| 63 @interface ChooserBubbleUiController | 63 @interface ChooserBubbleUiController |
| 64 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { | 64 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { |
| 65 @private | 65 @private |
| 66 // Bridge to the C++ class that created this object. | 66 // Bridge to the C++ class that created this object. |
| 67 ChooserBubbleUiCocoa* bridge_; | 67 ChooserBubbleUiCocoa* bridge_; |
| 68 | 68 |
| 69 base::scoped_nsobject<NSTextField> titleView_; | 69 base::scoped_nsobject<NSTextField> titleView_; |
| 70 base::scoped_nsobject<NSScrollView> scrollView_; | 70 base::scoped_nsobject<NSScrollView> scrollView_; |
| 71 base::scoped_nsobject<NSTableColumn> tableColumn_; | 71 base::scoped_nsobject<NSTableColumn> tableColumn_; |
| 72 base::scoped_nsobject<NSTableView> tableView_; | 72 base::scoped_nsobject<NSTableView> tableView_; |
| 73 base::scoped_nsobject<NSButton> connectButton_; | 73 base::scoped_nsobject<NSButton> connectButton_; |
| 74 base::scoped_nsobject<NSButton> cancelButton_; | 74 base::scoped_nsobject<NSButton> cancelButton_; |
| 75 base::scoped_nsobject<NSTextField> message_; | 75 base::scoped_nsobject<NSTextField> message_; |
| 76 base::scoped_nsobject<NSButton> getHelpButton_; | 76 base::scoped_nsobject<NSButton> getHelpButton_; |
| 77 bool buttonPressed_; | 77 bool buttonPressed_; |
| 78 | 78 |
| 79 Browser* browser_; // Weak. | 79 Browser* browser_; // Weak. |
| 80 ChooserBubbleController* chooserBubbleController_; // Weak. | 80 ChooserController* chooserController_; // Weak. |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Designated initializer. |browser| and |bridge| must both be non-nil. | 83 // Designated initializer. |browser| and |bridge| must both be non-nil. |
| 84 - (id)initWithBrowser:(Browser*)browser | 84 - (id)initWithBrowser:(Browser*)browser |
| 85 initWithChooserBubbleController: | 85 chooserController:(ChooserController*)chooserController |
| 86 (ChooserBubbleController*)chooserBubbleController | 86 bubbleReference:(BubbleReference)bubbleReference |
| 87 bridge:(ChooserBubbleUiCocoa*)bridge; | 87 bridge:(ChooserBubbleUiCocoa*)bridge; |
| 88 | 88 |
| 89 // Makes the bubble visible. | 89 // Makes the bubble visible. |
| 90 - (void)show; | 90 - (void)show; |
| 91 | 91 |
| 92 // Will reposition the bubble based in case the anchor or parent should change. | 92 // Will reposition the bubble based in case the anchor or parent should change. |
| 93 - (void)updateAnchorPosition; | 93 - (void)updateAnchorPosition; |
| 94 | 94 |
| 95 // Will calculate the expected anchor point for this bubble. | 95 // Will calculate the expected anchor point for this bubble. |
| 96 // Should only be used outside this class for tests. | 96 // Should only be used outside this class for tests. |
| 97 - (NSPoint)getExpectedAnchorPoint; | 97 - (NSPoint)getExpectedAnchorPoint; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 - (void)onCancel:(id)sender; | 144 - (void)onCancel:(id)sender; |
| 145 | 145 |
| 146 // Called when the "Get help" button is pressed. | 146 // Called when the "Get help" button is pressed. |
| 147 - (void)onGetHelpPressed:(id)sender; | 147 - (void)onGetHelpPressed:(id)sender; |
| 148 | 148 |
| 149 @end | 149 @end |
| 150 | 150 |
| 151 @implementation ChooserBubbleUiController | 151 @implementation ChooserBubbleUiController |
| 152 | 152 |
| 153 - (id)initWithBrowser:(Browser*)browser | 153 - (id)initWithBrowser:(Browser*)browser |
| 154 initWithChooserBubbleController: | 154 chooserController:(ChooserController*)chooserController |
| 155 (ChooserBubbleController*)chooserBubbleController | 155 bubbleReference:(BubbleReference)bubbleReference |
| 156 bridge:(ChooserBubbleUiCocoa*)bridge { | 156 bridge:(ChooserBubbleUiCocoa*)bridge { |
| 157 DCHECK(browser); | 157 DCHECK(browser); |
| 158 DCHECK(chooserBubbleController); | 158 DCHECK(chooserController); |
| 159 DCHECK(bubbleReference); |
| 159 DCHECK(bridge); | 160 DCHECK(bridge); |
| 160 | 161 |
| 161 browser_ = browser; | 162 browser_ = browser; |
| 162 chooserBubbleController_ = chooserBubbleController; | 163 chooserController_ = chooserController; |
| 163 | 164 |
| 164 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 165 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
| 165 initWithContentRect:ui::kWindowSizeDeterminedLater | 166 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 166 styleMask:NSBorderlessWindowMask | 167 styleMask:NSBorderlessWindowMask |
| 167 backing:NSBackingStoreBuffered | 168 backing:NSBackingStoreBuffered |
| 168 defer:NO]); | 169 defer:NO]); |
| 169 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 170 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
| 170 [window setReleasedWhenClosed:NO]; | 171 [window setReleasedWhenClosed:NO]; |
| 171 if ((self = [super initWithWindow:window | 172 if ((self = [super initWithWindow:window |
| 172 parentWindow:[self getExpectedParentWindow] | 173 parentWindow:[self getExpectedParentWindow] |
| 173 anchoredAt:NSZeroPoint])) { | 174 anchoredAt:NSZeroPoint])) { |
| 175 self.bubbleReference = bubbleReference; |
| 174 [self setShouldCloseOnResignKey:NO]; | 176 [self setShouldCloseOnResignKey:NO]; |
| 175 [self setShouldOpenAsKeyWindow:YES]; | 177 [self setShouldOpenAsKeyWindow:YES]; |
| 176 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; | 178 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; |
| 177 bridge_ = bridge; | 179 bridge_ = bridge; |
| 178 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 180 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 179 [center addObserver:self | 181 [center addObserver:self |
| 180 selector:@selector(parentWindowDidMove:) | 182 selector:@selector(parentWindowDidMove:) |
| 181 name:NSWindowDidMoveNotification | 183 name:NSWindowDidMoveNotification |
| 182 object:[self getExpectedParentWindow]]; | 184 object:[self getExpectedParentWindow]]; |
| 183 } | 185 } |
| 184 return self; | 186 return self; |
| 185 } | 187 } |
| 186 | 188 |
| 187 - (void)windowWillClose:(NSNotification*)notification { | 189 - (void)windowWillClose:(NSNotification*)notification { |
| 188 [[NSNotificationCenter defaultCenter] | 190 [[NSNotificationCenter defaultCenter] |
| 189 removeObserver:self | 191 removeObserver:self |
| 190 name:NSWindowDidMoveNotification | 192 name:NSWindowDidMoveNotification |
| 191 object:nil]; | 193 object:nil]; |
| 192 if (!buttonPressed_) | 194 if (!buttonPressed_) |
| 193 chooserBubbleController_->Close(); | 195 chooserController_->Close(); |
| 194 bridge_->OnBubbleClosing(); | 196 bridge_->OnBubbleClosing(); |
| 195 [super windowWillClose:notification]; | 197 [super windowWillClose:notification]; |
| 196 } | 198 } |
| 197 | 199 |
| 198 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 200 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
| 199 // Override the base class implementation, which would have closed the bubble. | 201 // Override the base class implementation, which would have closed the bubble. |
| 200 } | 202 } |
| 201 | 203 |
| 202 - (void)parentWindowDidResize:(NSNotification*)notification { | 204 - (void)parentWindowDidResize:(NSNotification*)notification { |
| 203 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 205 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 355 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| 354 [self showWindow:nil]; | 356 [self showWindow:nil]; |
| 355 [[self window] makeFirstResponder:nil]; | 357 [[self window] makeFirstResponder:nil]; |
| 356 [[self window] setInitialFirstResponder:tableView_.get()]; | 358 [[self window] setInitialFirstResponder:tableView_.get()]; |
| 357 } | 359 } |
| 358 } | 360 } |
| 359 | 361 |
| 360 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { | 362 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { |
| 361 // When there are no devices, the table contains a message saying there are | 363 // When there are no devices, the table contains a message saying there are |
| 362 // no devices, so the number of rows is always at least 1. | 364 // no devices, so the number of rows is always at least 1. |
| 363 return std::max( | 365 return std::max(static_cast<NSInteger>(chooserController_->NumOptions()), |
| 364 static_cast<NSInteger>(chooserBubbleController_->NumOptions()), | 366 static_cast<NSInteger>(1)); |
| 365 static_cast<NSInteger>(1)); | |
| 366 } | 367 } |
| 367 | 368 |
| 368 - (id)tableView:(NSTableView*)tableView | 369 - (id)tableView:(NSTableView*)tableView |
| 369 objectValueForTableColumn:(NSTableColumn*)tableColumn | 370 objectValueForTableColumn:(NSTableColumn*)tableColumn |
| 370 row:(NSInteger)rowIndex { | 371 row:(NSInteger)rowIndex { |
| 371 NSInteger num_options = | 372 NSInteger num_options = |
| 372 static_cast<NSInteger>(chooserBubbleController_->NumOptions()); | 373 static_cast<NSInteger>(chooserController_->NumOptions()); |
| 373 if (num_options == 0) { | 374 if (num_options == 0) { |
| 374 DCHECK_EQ(0, rowIndex); | 375 DCHECK_EQ(0, rowIndex); |
| 375 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT); | 376 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT); |
| 376 } | 377 } |
| 377 | 378 |
| 378 DCHECK_GE(rowIndex, 0); | 379 DCHECK_GE(rowIndex, 0); |
| 379 DCHECK_LT(rowIndex, num_options); | 380 DCHECK_LT(rowIndex, num_options); |
| 380 return base::SysUTF16ToNSString( | 381 return base::SysUTF16ToNSString( |
| 381 chooserBubbleController_->GetOption(static_cast<size_t>(rowIndex))); | 382 chooserController_->GetOption(static_cast<size_t>(rowIndex))); |
| 382 } | 383 } |
| 383 | 384 |
| 384 - (BOOL)tableView:(NSTableView*)aTableView | 385 - (BOOL)tableView:(NSTableView*)aTableView |
| 385 shouldEditTableColumn:(NSTableColumn*)aTableColumn | 386 shouldEditTableColumn:(NSTableColumn*)aTableColumn |
| 386 row:(NSInteger)rowIndex { | 387 row:(NSInteger)rowIndex { |
| 387 return NO; | 388 return NO; |
| 388 } | 389 } |
| 389 | 390 |
| 390 - (void)onOptionsInitialized { | 391 - (void)onOptionsInitialized { |
| 391 [self updateTableView]; | 392 [self updateTableView]; |
| 392 } | 393 } |
| 393 | 394 |
| 394 - (void)onOptionAdded:(NSInteger)index { | 395 - (void)onOptionAdded:(NSInteger)index { |
| 395 [self updateTableView]; | 396 [self updateTableView]; |
| 396 } | 397 } |
| 397 | 398 |
| 398 - (void)onOptionRemoved:(NSInteger)index { | 399 - (void)onOptionRemoved:(NSInteger)index { |
| 399 // |tableView_| will automatically selects the next item if the current | 400 // |tableView_| will automatically selects the next item if the current |
| 400 // item is removed, so here it tracks if the removed item is the item | 401 // item is removed, so here it tracks if the removed item is the item |
| 401 // that was previously selected, if so, deselect it. | 402 // that was previously selected, if so, deselect it. |
| 402 if ([tableView_ selectedRow] == index) | 403 if ([tableView_ selectedRow] == index) |
| 403 [tableView_ deselectRow:index]; | 404 [tableView_ deselectRow:index]; |
| 404 | 405 |
| 405 [self updateTableView]; | 406 [self updateTableView]; |
| 406 } | 407 } |
| 407 | 408 |
| 408 - (void)updateTableView { | 409 - (void)updateTableView { |
| 409 [tableView_ setEnabled:chooserBubbleController_->NumOptions() > 0]; | 410 [tableView_ setEnabled:chooserController_->NumOptions() > 0]; |
| 410 [tableView_ reloadData]; | 411 [tableView_ reloadData]; |
| 411 } | 412 } |
| 412 | 413 |
| 413 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { | 414 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { |
| 414 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; | 415 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; |
| 415 } | 416 } |
| 416 | 417 |
| 417 - (void)updateAnchorPosition { | 418 - (void)updateAnchorPosition { |
| 418 [self setParentWindow:[self getExpectedParentWindow]]; | 419 [self setParentWindow:[self getExpectedParentWindow]]; |
| 419 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 420 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 base::scoped_nsobject<NSTextField> titleView( | 453 base::scoped_nsobject<NSTextField> titleView( |
| 453 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 454 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
| 454 [titleView setDrawsBackground:NO]; | 455 [titleView setDrawsBackground:NO]; |
| 455 [titleView setBezeled:NO]; | 456 [titleView setBezeled:NO]; |
| 456 [titleView setEditable:NO]; | 457 [titleView setEditable:NO]; |
| 457 [titleView setSelectable:NO]; | 458 [titleView setSelectable:NO]; |
| 458 [titleView setStringValue: | 459 [titleView setStringValue: |
| 459 l10n_util::GetNSStringF( | 460 l10n_util::GetNSStringF( |
| 460 IDS_CHOOSER_BUBBLE_PROMPT, | 461 IDS_CHOOSER_BUBBLE_PROMPT, |
| 461 url_formatter::FormatOriginForSecurityDisplay( | 462 url_formatter::FormatOriginForSecurityDisplay( |
| 462 chooserBubbleController_->GetOrigin(), | 463 chooserController_->GetOrigin(), |
| 463 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]; | 464 url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC))]; |
| 464 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 465 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 465 // The height is arbitrary as it will be adjusted later. | 466 // The height is arbitrary as it will be adjusted later. |
| 466 [titleView setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, 0.0f)]; | 467 [titleView setFrameSize:NSMakeSize(kChooserBubbleWidth - 2 * kMarginX, 0.0f)]; |
| 467 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | 468 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; |
| 468 return titleView; | 469 return titleView; |
| 469 } | 470 } |
| 470 | 471 |
| 471 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title | 472 - (base::scoped_nsobject<NSButton>)buttonWithTitle:(NSString*)title |
| 472 action:(SEL)action { | 473 action:(SEL)action { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 NSRect frameA = [viewA frame]; | 534 NSRect frameA = [viewA frame]; |
| 534 NSRect frameB = [viewB frame]; | 535 NSRect frameB = [viewB frame]; |
| 535 frameA.origin.y = | 536 frameA.origin.y = |
| 536 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 537 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 537 [viewA setFrameOrigin:frameA.origin]; | 538 [viewA setFrameOrigin:frameA.origin]; |
| 538 } | 539 } |
| 539 | 540 |
| 540 - (void)onConnect:(id)sender { | 541 - (void)onConnect:(id)sender { |
| 541 buttonPressed_ = true; | 542 buttonPressed_ = true; |
| 542 NSInteger row = [tableView_ selectedRow]; | 543 NSInteger row = [tableView_ selectedRow]; |
| 543 chooserBubbleController_->Select(row); | 544 chooserController_->Select(row); |
| 545 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_ACCEPTED); |
| 544 [self close]; | 546 [self close]; |
| 545 } | 547 } |
| 546 | 548 |
| 547 - (void)onCancel:(id)sender { | 549 - (void)onCancel:(id)sender { |
| 548 buttonPressed_ = true; | 550 buttonPressed_ = true; |
| 549 chooserBubbleController_->Cancel(); | 551 chooserController_->Cancel(); |
| 552 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_CANCELED); |
| 550 [self close]; | 553 [self close]; |
| 551 } | 554 } |
| 552 | 555 |
| 553 - (void)onGetHelpPressed:(id)sender { | 556 - (void)onGetHelpPressed:(id)sender { |
| 554 chooserBubbleController_->OpenHelpCenterUrl(); | 557 chooserController_->OpenHelpCenterUrl(); |
| 555 } | 558 } |
| 556 | 559 |
| 557 @end | 560 @end |
| 558 | 561 |
| 559 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( | 562 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( |
| 560 Browser* browser, | 563 Browser* browser, |
| 561 ChooserBubbleController* chooser_bubble_controller) | 564 ChooserController* chooser_controller) |
| 562 : browser_(browser), | 565 : browser_(browser), |
| 563 chooser_bubble_controller_(chooser_bubble_controller), | 566 chooser_controller_(chooser_controller), |
| 564 chooser_bubble_ui_controller_(nil) { | 567 chooser_bubble_ui_controller_(nil) { |
| 565 DCHECK(browser); | 568 DCHECK(browser); |
| 566 DCHECK(chooser_bubble_controller); | 569 DCHECK(chooser_controller); |
| 567 chooser_bubble_controller_->set_observer(this); | 570 chooser_controller_->set_observer(this); |
| 568 } | 571 } |
| 569 | 572 |
| 570 ChooserBubbleUiCocoa::~ChooserBubbleUiCocoa() { | 573 ChooserBubbleUiCocoa::~ChooserBubbleUiCocoa() { |
| 571 chooser_bubble_controller_->set_observer(nullptr); | 574 chooser_controller_->set_observer(nullptr); |
| 572 [chooser_bubble_ui_controller_ close]; | 575 [chooser_bubble_ui_controller_ close]; |
| 573 chooser_bubble_ui_controller_ = nil; | 576 chooser_bubble_ui_controller_ = nil; |
| 574 } | 577 } |
| 575 | 578 |
| 576 void ChooserBubbleUiCocoa::Show(BubbleReference bubble_reference) { | 579 void ChooserBubbleUiCocoa::Show(BubbleReference bubble_reference) { |
| 577 if (!chooser_bubble_ui_controller_) { | 580 if (!chooser_bubble_ui_controller_) { |
| 578 chooser_bubble_ui_controller_ = [[ChooserBubbleUiController alloc] | 581 chooser_bubble_ui_controller_ = |
| 579 initWithBrowser:browser_ | 582 [[ChooserBubbleUiController alloc] initWithBrowser:browser_ |
| 580 initWithChooserBubbleController:chooser_bubble_controller_ | 583 chooserController:chooser_controller_ |
| 581 bridge:this]; | 584 bubbleReference:bubble_reference |
| 585 bridge:this]; |
| 582 } | 586 } |
| 583 | 587 |
| 584 [chooser_bubble_ui_controller_ show]; | 588 [chooser_bubble_ui_controller_ show]; |
| 585 [chooser_bubble_ui_controller_ updateTableView]; | 589 [chooser_bubble_ui_controller_ updateTableView]; |
| 586 } | 590 } |
| 587 | 591 |
| 588 void ChooserBubbleUiCocoa::Close() { | 592 void ChooserBubbleUiCocoa::Close() { |
| 589 [chooser_bubble_ui_controller_ close]; | 593 [chooser_bubble_ui_controller_ close]; |
| 590 chooser_bubble_ui_controller_ = nil; | 594 chooser_bubble_ui_controller_ = nil; |
| 591 } | 595 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 602 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; | 606 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
| 603 } | 607 } |
| 604 | 608 |
| 605 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { | 609 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
| 606 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; | 610 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
| 607 } | 611 } |
| 608 | 612 |
| 609 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 613 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 610 chooser_bubble_ui_controller_ = nil; | 614 chooser_bubble_ui_controller_ = nil; |
| 611 } | 615 } |
| OLD | NEW |