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

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

Issue 1545773002: Address some TODOs for ChooserBubbleDelegate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated comments Created 4 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 <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } else { 287 } else {
288 [[self window] setFrame:bubbleFrame display:NO]; 288 [[self window] setFrame:bubbleFrame display:NO];
289 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 289 [self setAnchorPoint:[self getExpectedAnchorPoint]];
290 [self showWindow:nil]; 290 [self showWindow:nil];
291 [[self window] makeFirstResponder:nil]; 291 [[self window] makeFirstResponder:nil];
292 [[self window] setInitialFirstResponder:connectButton_.get()]; 292 [[self window] setInitialFirstResponder:connectButton_.get()];
293 } 293 }
294 } 294 }
295 295
296 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView { 296 - (NSInteger)numberOfRowsInTableView:(NSTableView*)tableView {
297 const std::vector<base::string16>& device_names = 297 // When there are no devices, the table contains a message saying there are
298 chooserBubbleDelegate_->GetOptions(); 298 // no devices, so the number of rows is always at least 1.
299 if (device_names.empty()) { 299 return std::max(static_cast<NSInteger>(chooserBubbleDelegate_->NumOptions()),
300 return 1; 300 static_cast<NSInteger>(1));
301 } else {
302 return static_cast<NSInteger>(device_names.size());
303 }
304 } 301 }
305 302
306 - (id)tableView:(NSTableView*)tableView 303 - (id)tableView:(NSTableView*)tableView
307 objectValueForTableColumn:(NSTableColumn*)tableColumn 304 objectValueForTableColumn:(NSTableColumn*)tableColumn
308 row:(NSInteger)rowIndex { 305 row:(NSInteger)rowIndex {
309 const std::vector<base::string16>& device_names = 306 NSInteger num_options =
310 chooserBubbleDelegate_->GetOptions(); 307 static_cast<NSInteger>(chooserBubbleDelegate_->NumOptions());
311 if (device_names.empty()) { 308 if (num_options == 0) {
312 DCHECK(rowIndex == 0); 309 DCHECK_EQ(0, rowIndex);
313 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT); 310 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT);
314 } else {
315 if (rowIndex >= 0 &&
316 rowIndex < static_cast<NSInteger>(device_names.size())) {
317 return base::SysUTF16ToNSString(device_names[rowIndex]);
318 } else {
319 return @"";
320 }
321 } 311 }
312
313 DCHECK_GE(rowIndex, 0);
314 DCHECK_LT(rowIndex, num_options);
315 return base::SysUTF16ToNSString(
316 chooserBubbleDelegate_->GetOption(static_cast<size_t>(rowIndex)));
322 } 317 }
323 318
324 - (BOOL)tableView:(NSTableView*)aTableView 319 - (BOOL)tableView:(NSTableView*)aTableView
325 shouldEditTableColumn:(NSTableColumn*)aTableColumn 320 shouldEditTableColumn:(NSTableColumn*)aTableColumn
326 row:(NSInteger)rowIndex { 321 row:(NSInteger)rowIndex {
327 return NO; 322 return NO;
328 } 323 }
329 324
330 - (void)onOptionsInitialized { 325 - (void)onOptionsInitialized {
331 [self updateTableView]; 326 [self updateTableView];
332 } 327 }
333 328
334 - (void)onOptionAdded:(NSInteger)index { 329 - (void)onOptionAdded:(NSInteger)index {
335 [self updateTableView]; 330 [self updateTableView];
336 } 331 }
337 332
338 - (void)onOptionRemoved:(NSInteger)index { 333 - (void)onOptionRemoved:(NSInteger)index {
339 // |tableView_| will automatically selects the next item if the current 334 // |tableView_| will automatically selects the next item if the current
340 // item is removed, so here it tracks if the removed item is the item 335 // item is removed, so here it tracks if the removed item is the item
341 // that was previously selected, if so, deselect it. 336 // that was previously selected, if so, deselect it.
342 if ([tableView_ selectedRow] == index) 337 if ([tableView_ selectedRow] == index)
343 [tableView_ deselectRow:index]; 338 [tableView_ deselectRow:index];
344 339
345 [self updateTableView]; 340 [self updateTableView];
346 } 341 }
347 342
348 - (void)updateTableView { 343 - (void)updateTableView {
349 const std::vector<base::string16>& device_names = 344 [tableView_ setEnabled:chooserBubbleDelegate_->NumOptions() > 0];
350 chooserBubbleDelegate_->GetOptions();
351 [tableView_ setEnabled:!device_names.empty()];
352 [tableView_ reloadData]; 345 [tableView_ reloadData];
353 } 346 }
354 347
355 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { 348 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification {
356 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; 349 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0];
357 } 350 }
358 351
359 - (void)updateAnchorPosition { 352 - (void)updateAnchorPosition {
360 [self setParentWindow:[self getExpectedParentWindow]]; 353 [self setParentWindow:[self getExpectedParentWindow]];
361 [self setAnchorPoint:[self getExpectedAnchorPoint]]; 354 [self setAnchorPoint:[self getExpectedAnchorPoint]];
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 489 }
497 490
498 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { 491 void ChooserBubbleUiCocoa::UpdateAnchorPosition() {
499 [chooser_bubble_ui_controller_ updateAnchorPosition]; 492 [chooser_bubble_ui_controller_ updateAnchorPosition];
500 } 493 }
501 494
502 void ChooserBubbleUiCocoa::OnOptionsInitialized() { 495 void ChooserBubbleUiCocoa::OnOptionsInitialized() {
503 [chooser_bubble_ui_controller_ onOptionsInitialized]; 496 [chooser_bubble_ui_controller_ onOptionsInitialized];
504 } 497 }
505 498
506 void ChooserBubbleUiCocoa::OnOptionAdded(int index) { 499 void ChooserBubbleUiCocoa::OnOptionAdded(size_t index) {
507 [chooser_bubble_ui_controller_ onOptionAdded:index]; 500 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)];
508 } 501 }
509 502
510 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { 503 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) {
511 [chooser_bubble_ui_controller_ onOptionRemoved:index]; 504 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)];
512 } 505 }
513 506
514 void ChooserBubbleUiCocoa::OnBubbleClosing() { 507 void ChooserBubbleUiCocoa::OnBubbleClosing() {
515 chooser_bubble_ui_controller_ = nil; 508 chooser_bubble_ui_controller_ = nil;
516 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698