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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 | 131 |
131 @implementation ChooserBubbleUiController | 132 @implementation ChooserBubbleUiController |
132 | 133 |
133 - (id)initWithBrowser:(Browser*)browser | 134 - (id)initWithBrowser:(Browser*)browser |
134 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate | 135 initWithChooserBubbleDelegate:(ChooserBubbleDelegate*)chooserBubbleDelegate |
135 bridge:(ChooserBubbleUiCocoa*)bridge { | 136 bridge:(ChooserBubbleUiCocoa*)bridge { |
136 DCHECK(browser); | 137 DCHECK(browser); |
137 DCHECK(chooserBubbleDelegate); | 138 DCHECK(chooserBubbleDelegate); |
138 DCHECK(bridge); | 139 DCHECK(bridge); |
139 | 140 |
141 buttonPressed_ = false; | |
Robert Sesek
2015/12/21 21:22:17
Can remove, ObjC objects are zero-initialized.
juncai
2015/12/21 21:38:04
Done.
| |
140 browser_ = browser; | 142 browser_ = browser; |
141 chooserBubbleDelegate_ = chooserBubbleDelegate; | 143 chooserBubbleDelegate_ = chooserBubbleDelegate; |
142 | 144 |
143 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 145 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
144 initWithContentRect:ui::kWindowSizeDeterminedLater | 146 initWithContentRect:ui::kWindowSizeDeterminedLater |
145 styleMask:NSBorderlessWindowMask | 147 styleMask:NSBorderlessWindowMask |
146 backing:NSBackingStoreBuffered | 148 backing:NSBackingStoreBuffered |
147 defer:NO]); | 149 defer:NO]); |
148 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 150 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
149 [window setReleasedWhenClosed:NO]; | 151 [window setReleasedWhenClosed:NO]; |
(...skipping 11 matching lines...) Expand all Loading... | |
161 object:[self getExpectedParentWindow]]; | 163 object:[self getExpectedParentWindow]]; |
162 } | 164 } |
163 return self; | 165 return self; |
164 } | 166 } |
165 | 167 |
166 - (void)windowWillClose:(NSNotification*)notification { | 168 - (void)windowWillClose:(NSNotification*)notification { |
167 [[NSNotificationCenter defaultCenter] | 169 [[NSNotificationCenter defaultCenter] |
168 removeObserver:self | 170 removeObserver:self |
169 name:NSWindowDidMoveNotification | 171 name:NSWindowDidMoveNotification |
170 object:nil]; | 172 object:nil]; |
173 if (!buttonPressed_) | |
174 chooserBubbleDelegate_->Close(); | |
171 bridge_->OnBubbleClosing(); | 175 bridge_->OnBubbleClosing(); |
172 [super windowWillClose:notification]; | 176 [super windowWillClose:notification]; |
173 } | 177 } |
174 | 178 |
175 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { | 179 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { |
176 // Override the base class implementation, which would have closed the bubble. | 180 // Override the base class implementation, which would have closed the bubble. |
177 } | 181 } |
178 | 182 |
179 - (void)parentWindowDidResize:(NSNotification*)notification { | 183 - (void)parentWindowDidResize:(NSNotification*)notification { |
180 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 184 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 | 441 |
438 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { | 442 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { |
439 NSRect frameA = [viewA frame]; | 443 NSRect frameA = [viewA frame]; |
440 NSRect frameB = [viewB frame]; | 444 NSRect frameB = [viewB frame]; |
441 frameA.origin.y = | 445 frameA.origin.y = |
442 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); | 446 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); |
443 [viewA setFrameOrigin:frameA.origin]; | 447 [viewA setFrameOrigin:frameA.origin]; |
444 } | 448 } |
445 | 449 |
446 - (void)onConnect:(id)sender { | 450 - (void)onConnect:(id)sender { |
451 buttonPressed_ = true; | |
447 NSInteger row = [tableView_ selectedRow]; | 452 NSInteger row = [tableView_ selectedRow]; |
448 chooserBubbleDelegate_->Select(row); | 453 chooserBubbleDelegate_->Select(row); |
449 [self close]; | 454 [self close]; |
450 } | 455 } |
451 | 456 |
452 - (void)onCancel:(id)sender { | 457 - (void)onCancel:(id)sender { |
458 buttonPressed_ = true; | |
453 chooserBubbleDelegate_->Cancel(); | 459 chooserBubbleDelegate_->Cancel(); |
454 [self close]; | 460 [self close]; |
455 } | 461 } |
456 | 462 |
457 @end | 463 @end |
458 | 464 |
459 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( | 465 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( |
460 Browser* browser, | 466 Browser* browser, |
461 ChooserBubbleDelegate* chooser_bubble_delegate) | 467 ChooserBubbleDelegate* chooser_bubble_delegate) |
462 : browser_(browser), | 468 : browser_(browser), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 [chooser_bubble_ui_controller_ onOptionAdded:index]; | 508 [chooser_bubble_ui_controller_ onOptionAdded:index]; |
503 } | 509 } |
504 | 510 |
505 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { | 511 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { |
506 [chooser_bubble_ui_controller_ onOptionRemoved:index]; | 512 [chooser_bubble_ui_controller_ onOptionRemoved:index]; |
507 } | 513 } |
508 | 514 |
509 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 515 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
510 chooser_bubble_ui_controller_ = nil; | 516 chooser_bubble_ui_controller_ = nil; |
511 } | 517 } |
OLD | NEW |