Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Side by Side Diff: chrome/browser/ui/cocoa/website_settings/chooser_bubble_ui_cocoa.mm

Issue 2595083002: Change ChooserContentView[Cocoa] class name to be DeviceChooserContentView[Cocoa] (Closed)
Patch Set: merge master Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/chooser_controller/chooser_controller.h" 15 #include "chrome/browser/chooser_controller/chooser_controller.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/chooser_content_view_cocoa.h" 21 #import "chrome/browser/ui/cocoa/device_chooser_content_view_cocoa.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 "components/bubble/bubble_controller.h" 26 #include "components/bubble/bubble_controller.h"
27 #include "content/public/browser/native_web_keyboard_event.h" 27 #include "content/public/browser/native_web_keyboard_event.h"
28 #include "ui/base/cocoa/cocoa_base_utils.h" 28 #include "ui/base/cocoa/cocoa_base_utils.h"
29 #include "ui/base/cocoa/window_size_constants.h" 29 #include "ui/base/cocoa/window_size_constants.h"
30 30
31 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() { 31 std::unique_ptr<BubbleUi> ChooserBubbleDelegate::BuildBubbleUi() {
32 return base::MakeUnique<ChooserBubbleUiCocoa>(browser_, 32 return base::MakeUnique<ChooserBubbleUiCocoa>(browser_,
33 std::move(chooser_controller_)); 33 std::move(chooser_controller_));
34 } 34 }
35 35
36 @interface ChooserBubbleUiController 36 @interface ChooserBubbleUiController
37 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> { 37 : BaseBubbleController<NSTableViewDataSource, NSTableViewDelegate> {
38 @private 38 @private
39 // Bridge to the C++ class that created this object. 39 // Bridge to the C++ class that created this object.
40 ChooserBubbleUiCocoa* bridge_; // Weak. 40 ChooserBubbleUiCocoa* bridge_; // Weak.
41 bool buttonPressed_; 41 bool buttonPressed_;
42 42
43 base::scoped_nsobject<ChooserContentViewCocoa> chooserContentView_; 43 base::scoped_nsobject<DeviceChooserContentViewCocoa>
44 deviceChooserContentView_;
44 NSTableView* tableView_; // Weak. 45 NSTableView* tableView_; // Weak.
45 NSButton* connectButton_; // Weak. 46 NSButton* connectButton_; // Weak.
46 NSButton* cancelButton_; // Weak. 47 NSButton* cancelButton_; // Weak.
47 48
48 Browser* browser_; // Weak. 49 Browser* browser_; // Weak.
49 } 50 }
50 51
51 // Designated initializer. |browser| and |bridge| must both be non-nil. 52 // Designated initializer. |browser| and |bridge| must both be non-nil.
52 - (id)initWithBrowser:(Browser*)browser 53 - (id)initWithBrowser:(Browser*)browser
53 chooserController:(std::unique_ptr<ChooserController>)chooserController 54 chooserController:(std::unique_ptr<ChooserController>)chooserController
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 [self setShouldOpenAsKeyWindow:YES]; 110 [self setShouldOpenAsKeyWindow:YES];
110 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]]; 111 [[self bubble] setArrowLocation:[self getExpectedArrowLocation]];
111 bridge_ = bridge; 112 bridge_ = bridge;
112 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 113 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
113 [center addObserver:self 114 [center addObserver:self
114 selector:@selector(parentWindowDidMove:) 115 selector:@selector(parentWindowDidMove:)
115 name:NSWindowDidMoveNotification 116 name:NSWindowDidMoveNotification
116 object:[self getExpectedParentWindow]]; 117 object:[self getExpectedParentWindow]];
117 118
118 base::string16 chooserTitle = chooserController->GetTitle(); 119 base::string16 chooserTitle = chooserController->GetTitle();
119 chooserContentView_.reset([[ChooserContentViewCocoa alloc] 120 deviceChooserContentView_.reset([[DeviceChooserContentViewCocoa alloc]
120 initWithChooserTitle:base::SysUTF16ToNSString(chooserTitle) 121 initWithChooserTitle:base::SysUTF16ToNSString(chooserTitle)
121 chooserController:std::move(chooserController)]); 122 chooserController:std::move(chooserController)]);
122 123
123 tableView_ = [chooserContentView_ tableView]; 124 tableView_ = [deviceChooserContentView_ tableView];
124 connectButton_ = [chooserContentView_ connectButton]; 125 connectButton_ = [deviceChooserContentView_ connectButton];
125 cancelButton_ = [chooserContentView_ cancelButton]; 126 cancelButton_ = [deviceChooserContentView_ cancelButton];
126 127
127 [connectButton_ setTarget:self]; 128 [connectButton_ setTarget:self];
128 [connectButton_ setAction:@selector(onConnect:)]; 129 [connectButton_ setAction:@selector(onConnect:)];
129 [cancelButton_ setTarget:self]; 130 [cancelButton_ setTarget:self];
130 [cancelButton_ setAction:@selector(onCancel:)]; 131 [cancelButton_ setAction:@selector(onCancel:)];
131 [tableView_ setDelegate:self]; 132 [tableView_ setDelegate:self];
132 [tableView_ setDataSource:self]; 133 [tableView_ setDataSource:self];
133 134
134 [[[self window] contentView] addSubview:chooserContentView_.get()]; 135 [[[self window] contentView] addSubview:deviceChooserContentView_.get()];
135 } 136 }
136 137
137 return self; 138 return self;
138 } 139 }
139 140
140 - (void)windowWillClose:(NSNotification*)notification { 141 - (void)windowWillClose:(NSNotification*)notification {
141 [[NSNotificationCenter defaultCenter] 142 [[NSNotificationCenter defaultCenter]
142 removeObserver:self 143 removeObserver:self
143 name:NSWindowDidMoveNotification 144 name:NSWindowDidMoveNotification
144 object:nil]; 145 object:nil];
145 if (!buttonPressed_) 146 if (!buttonPressed_)
146 [chooserContentView_ close]; 147 [deviceChooserContentView_ close];
147 bridge_->OnBubbleClosing(); 148 bridge_->OnBubbleClosing();
148 [super windowWillClose:notification]; 149 [super windowWillClose:notification];
149 } 150 }
150 151
151 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification { 152 - (void)parentWindowWillToggleFullScreen:(NSNotification*)notification {
152 // Override the base class implementation, which would have closed the bubble. 153 // Override the base class implementation, which would have closed the bubble.
153 } 154 }
154 155
155 - (void)parentWindowDidResize:(NSNotification*)notification { 156 - (void)parentWindowDidResize:(NSNotification*)notification {
156 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 157 [self setAnchorPoint:[self getExpectedAnchorPoint]];
157 } 158 }
158 159
159 - (void)parentWindowDidMove:(NSNotification*)notification { 160 - (void)parentWindowDidMove:(NSNotification*)notification {
160 DCHECK(bridge_); 161 DCHECK(bridge_);
161 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 162 [self setAnchorPoint:[self getExpectedAnchorPoint]];
162 } 163 }
163 164
164 - (void)show { 165 - (void)show {
165 NSRect bubbleFrame = 166 NSRect bubbleFrame =
166 [[self window] frameRectForContentRect:[chooserContentView_ frame]]; 167 [[self window] frameRectForContentRect:[deviceChooserContentView_ frame]];
167 if ([[self window] isVisible]) { 168 if ([[self window] isVisible]) {
168 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called 169 // Unfortunately, calling -setFrame followed by -setFrameOrigin (called
169 // within -setAnchorPoint) causes flickering. Avoid the flickering by 170 // within -setAnchorPoint) causes flickering. Avoid the flickering by
170 // manually adjusting the new frame's origin so that the top left stays the 171 // manually adjusting the new frame's origin so that the top left stays the
171 // same, and only calling -setFrame. 172 // same, and only calling -setFrame.
172 NSRect currentWindowFrame = [[self window] frame]; 173 NSRect currentWindowFrame = [[self window] frame];
173 bubbleFrame.origin = currentWindowFrame.origin; 174 bubbleFrame.origin = currentWindowFrame.origin;
174 bubbleFrame.origin.y = bubbleFrame.origin.y + 175 bubbleFrame.origin.y = bubbleFrame.origin.y +
175 currentWindowFrame.size.height - 176 currentWindowFrame.size.height -
176 bubbleFrame.size.height; 177 bubbleFrame.size.height;
177 [[self window] setFrame:bubbleFrame display:YES]; 178 [[self window] setFrame:bubbleFrame display:YES];
178 } else { 179 } else {
179 [[self window] setFrame:bubbleFrame display:NO]; 180 [[self window] setFrame:bubbleFrame display:NO];
180 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 181 [self setAnchorPoint:[self getExpectedAnchorPoint]];
181 [self showWindow:nil]; 182 [self showWindow:nil];
182 [[self window] makeFirstResponder:nil]; 183 [[self window] makeFirstResponder:nil];
183 [[self window] setInitialFirstResponder:tableView_]; 184 [[self window] setInitialFirstResponder:tableView_];
184 } 185 }
185 } 186 }
186 187
187 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { 188 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
188 return [chooserContentView_ numberOfOptions]; 189 return [deviceChooserContentView_ numberOfOptions];
189 } 190 }
190 191
191 - (NSView*)tableView:(NSTableView*)tableView 192 - (NSView*)tableView:(NSTableView*)tableView
192 viewForTableColumn:(NSTableColumn*)tableColumn 193 viewForTableColumn:(NSTableColumn*)tableColumn
193 row:(NSInteger)row { 194 row:(NSInteger)row {
194 return [chooserContentView_ createTableRowView:row].autorelease(); 195 return [deviceChooserContentView_ createTableRowView:row].autorelease();
195 } 196 }
196 197
197 - (BOOL)tableView:(NSTableView*)aTableView 198 - (BOOL)tableView:(NSTableView*)aTableView
198 shouldEditTableColumn:(NSTableColumn*)aTableColumn 199 shouldEditTableColumn:(NSTableColumn*)aTableColumn
199 row:(NSInteger)rowIndex { 200 row:(NSInteger)rowIndex {
200 return NO; 201 return NO;
201 } 202 }
202 203
203 - (CGFloat)tableView:(NSTableView*)tableView heightOfRow:(NSInteger)row { 204 - (CGFloat)tableView:(NSTableView*)tableView heightOfRow:(NSInteger)row {
204 return [chooserContentView_ tableRowViewHeight:row]; 205 return [deviceChooserContentView_ tableRowViewHeight:row];
205 } 206 }
206 207
207 - (void)updateTableView { 208 - (void)updateTableView {
208 [chooserContentView_ updateTableView]; 209 [deviceChooserContentView_ updateTableView];
209 } 210 }
210 211
211 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { 212 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification {
212 [chooserContentView_ updateContentRowColor]; 213 [deviceChooserContentView_ updateContentRowColor];
213 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; 214 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0];
214 } 215 }
215 216
216 // Selection changes (while the mouse button is still down). 217 // Selection changes (while the mouse button is still down).
217 - (void)tableViewSelectionIsChanging:(NSNotification*)aNotification { 218 - (void)tableViewSelectionIsChanging:(NSNotification*)aNotification {
218 [chooserContentView_ updateContentRowColor]; 219 [deviceChooserContentView_ updateContentRowColor];
219 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; 220 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0];
220 } 221 }
221 222
222 - (void)updateAnchorPosition { 223 - (void)updateAnchorPosition {
223 [self setParentWindow:[self getExpectedParentWindow]]; 224 [self setParentWindow:[self getExpectedParentWindow]];
224 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 225 [self setAnchorPoint:[self getExpectedAnchorPoint]];
225 } 226 }
226 227
227 - (NSPoint)getExpectedAnchorPoint { 228 - (NSPoint)getExpectedAnchorPoint {
228 NSPoint anchor; 229 NSPoint anchor;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB { 266 + (void)alignCenterOf:(NSView*)viewA verticallyToCenterOf:(NSView*)viewB {
266 NSRect frameA = [viewA frame]; 267 NSRect frameA = [viewA frame];
267 NSRect frameB = [viewB frame]; 268 NSRect frameB = [viewB frame];
268 frameA.origin.y = 269 frameA.origin.y =
269 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2); 270 NSMinY(frameB) + std::floor((NSHeight(frameB) - NSHeight(frameA)) / 2);
270 [viewA setFrameOrigin:frameA.origin]; 271 [viewA setFrameOrigin:frameA.origin];
271 } 272 }
272 273
273 - (void)onConnect:(id)sender { 274 - (void)onConnect:(id)sender {
274 buttonPressed_ = true; 275 buttonPressed_ = true;
275 [chooserContentView_ accept]; 276 [deviceChooserContentView_ accept];
276 if (self.bubbleReference) 277 if (self.bubbleReference)
277 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_ACCEPTED); 278 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_ACCEPTED);
278 [self close]; 279 [self close];
279 } 280 }
280 281
281 - (void)onCancel:(id)sender { 282 - (void)onCancel:(id)sender {
282 buttonPressed_ = true; 283 buttonPressed_ = true;
283 [chooserContentView_ cancel]; 284 [deviceChooserContentView_ cancel];
284 if (self.bubbleReference) 285 if (self.bubbleReference)
285 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_CANCELED); 286 self.bubbleReference->CloseBubble(BUBBLE_CLOSE_CANCELED);
286 [self close]; 287 [self close];
287 } 288 }
288 289
289 @end 290 @end
290 291
291 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa( 292 ChooserBubbleUiCocoa::ChooserBubbleUiCocoa(
292 Browser* browser, 293 Browser* browser,
293 std::unique_ptr<ChooserController> chooser_controller) 294 std::unique_ptr<ChooserController> chooser_controller)
(...skipping 28 matching lines...) Expand all
322 } 323 }
323 324
324 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { 325 void ChooserBubbleUiCocoa::UpdateAnchorPosition() {
325 if (chooser_bubble_ui_controller_) 326 if (chooser_bubble_ui_controller_)
326 [chooser_bubble_ui_controller_ updateAnchorPosition]; 327 [chooser_bubble_ui_controller_ updateAnchorPosition];
327 } 328 }
328 329
329 void ChooserBubbleUiCocoa::OnBubbleClosing() { 330 void ChooserBubbleUiCocoa::OnBubbleClosing() {
330 chooser_bubble_ui_controller_ = nil; 331 chooser_bubble_ui_controller_ = nil;
331 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698