| 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 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 @private | 58 @private |
| 59 // Bridge to the C++ class that created this object. | 59 // Bridge to the C++ class that created this object. |
| 60 ChooserBubbleUiCocoa* bridge_; | 60 ChooserBubbleUiCocoa* bridge_; |
| 61 | 61 |
| 62 base::scoped_nsobject<NSTextField> titleView_; | 62 base::scoped_nsobject<NSTextField> titleView_; |
| 63 base::scoped_nsobject<NSScrollView> scrollView_; | 63 base::scoped_nsobject<NSScrollView> scrollView_; |
| 64 base::scoped_nsobject<NSTableColumn> tableColumn_; | 64 base::scoped_nsobject<NSTableColumn> tableColumn_; |
| 65 base::scoped_nsobject<NSTableView> tableView_; | 65 base::scoped_nsobject<NSTableView> tableView_; |
| 66 base::scoped_nsobject<NSButton> connectButton_; | 66 base::scoped_nsobject<NSButton> connectButton_; |
| 67 base::scoped_nsobject<NSButton> cancelButton_; | 67 base::scoped_nsobject<NSButton> cancelButton_; |
| 68 bool buttonPressed_; |
| 68 | 69 |
| 69 Browser* browser_; // Weak. | 70 Browser* browser_; // Weak. |
| 70 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. | 71 ChooserBubbleDelegate* chooserBubbleDelegate_; // Weak. |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Designated initializer. |browser| and |bridge| must both be non-nil. | 74 // Designated initializer. |browser| and |bridge| must both be non-nil. |
| 74 - (id)initWithBrowser:(Browser*)browser | 75 - (id)initWithBrowser:(Browser*)browser |
| 75 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate | 76 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate |
| 76 bridge:(ChooserBubbleUiCocoa*)bridge; | 77 bridge:(ChooserBubbleUiCocoa*)bridge; |
| 77 | 78 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 object:[self getExpectedParentWindow]]; | 162 object:[self getExpectedParentWindow]]; |
| 162 } | 163 } |
| 163 return self; | 164 return self; |
| 164 } | 165 } |
| 165 | 166 |
| 166 - (void)windowWillClose:(NSNotification*)notification { | 167 - (void)windowWillClose:(NSNotification*)notification { |
| 167 [[NSNotificationCenter defaultCenter] | 168 [[NSNotificationCenter defaultCenter] |
| 168 removeObserver:self | 169 removeObserver:self |
| 169 name:NSWindowDidMoveNotification | 170 name:NSWindowDidMoveNotification |
| 170 object:nil]; | 171 object:nil]; |
| 172 if (!buttonPressed_) |
| 173 chooserBubbleDelegate_->Close(); |
| 171 bridge_->OnBubbleClosing(); | 174 bridge_->OnBubbleClosing(); |
| 172 [super windowWillClose:notification]; | 175 [super windowWillClose:notification]; |
| 173 } | 176 } |
| 174 | 177 |
| 175 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 178 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
| 176 // Override the base class implementation, which would have closed the bubble. | 179 // Override the base class implementation, which would have closed the bubble. |
| 177 } | 180 } |
| 178 | 181 |
| 179 - (void)parentWindowDidResize:(NSNotification*)notification { | 182 - (void)parentWindowDidResize:(NSNotification*)notification { |
| 180 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 183 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 440 |
| 438 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 441 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
| 439 NSRect frameA = [viewA frame]; | 442 NSRect frameA = [viewA frame]; |
| 440 NSRect frameB = [viewB frame]; | 443 NSRect frameB = [viewB frame]; |
| 441 frameA.origin.y = | 444 frameA.origin.y = |
| 442 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 445 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
| 443 [viewA setFrameOrigin:frameA.origin]; | 446 [viewA setFrameOrigin:frameA.origin]; |
| 444 } | 447 } |
| 445 | 448 |
| 446 - (void)onConnect:(id)sender { | 449 - (void)onConnect:(id)sender { |
| 450 buttonPressed_ = true; |
| 447 NSInteger row = [tableView_ selectedRow]; | 451 NSInteger row = [tableView_ selectedRow]; |
| 448 chooserBubbleDelegate_->Select(row); | 452 chooserBubbleDelegate_->Select(row); |
| 449 [self close]; | 453 [self close]; |
| 450 } | 454 } |
| 451 | 455 |
| 452 - (void)onCancel:(id)sender { | 456 - (void)onCancel:(id)sender { |
| 457 buttonPressed_ = true; |
| 453 chooserBubbleDelegate_->Cancel(); | 458 chooserBubbleDelegate_->Cancel(); |
| 454 [self close]; | 459 [self close]; |
| 455 } | 460 } |
| 456 | 461 |
| 457 @end | 462 @end |
| 458 | 463 |
| 459 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( | 464 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( |
| 460 Browser* browser, | 465 Browser* browser, |
| 461 ChooserBubbleDelegate* chooser_bubble_delegate) | 466 ChooserBubbleDelegate* chooser_bubble_delegate) |
| 462 : browser_(browser), | 467 : browser_(browser), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 [chooser_bubble_ui_controller_ onOptionAdded:index]; | 507 [chooser_bubble_ui_controller_ onOptionAdded:index]; |
| 503 } | 508 } |
| 504 | 509 |
| 505 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { | 510 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { |
| 506 [chooser_bubble_ui_controller_ onOptionRemoved:index]; | 511 [chooser_bubble_ui_controller_ onOptionRemoved:index]; |
| 507 } | 512 } |
| 508 | 513 |
| 509 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 514 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 510 chooser_bubble_ui_controller_ = nil; | 515 chooser_bubble_ui_controller_ = nil; |
| 511 } | 516 } |
| OLD | NEW |