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

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: address reillyg@'s 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 size_t num_options = chooserBubbleDelegate_->NumOptions();
298 chooserBubbleDelegate_->GetOptions(); 298 return num_options == 0 ? 1 : static_cast<NSInteger>(num_options);
Peter Kasting 2016/01/04 21:02:52 Nit: Shorter: return static_cast<NSInteger>(std
juncai 2016/01/04 22:44:46 I think here it needs to use std::max instead of s
Peter Kasting 2016/01/04 23:54:00 Oops! Yes.
299 if (device_names.empty()) {
300 return 1;
301 } else {
302 return static_cast<NSInteger>(device_names.size());
303 }
304 } 299 }
305 300
306 - (id)tableView:(NSTableView*)tableView 301 - (id)tableView:(NSTableView*)tableView
307 objectValueForTableColumn:(NSTableColumn*)tableColumn 302 objectValueForTableColumn:(NSTableColumn*)tableColumn
308 row:(NSInteger)rowIndex { 303 row:(NSInteger)rowIndex {
309 const std::vector<base::string16>& device_names = 304 NSInteger num_options =
310 chooserBubbleDelegate_->GetOptions(); 305 static_cast<NSInteger>(chooserBubbleDelegate_->NumOptions());
311 if (device_names.empty()) { 306 if (num_options == 0) {
312 DCHECK(rowIndex == 0); 307 DCHECK(rowIndex == 0);
Peter Kasting 2016/01/04 21:02:52 Nit: While here: DCHECK_EQ(0, rowIndex);
juncai 2016/01/04 22:44:46 Done.
313 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT); 308 return l10n_util::GetNSString(IDS_CHOOSER_BUBBLE_NO_DEVICES_FOUND_PROMPT);
314 } else { 309 } else {
Peter Kasting 2016/01/04 21:02:52 Nit: While here: No "else" after return (multiple
juncai 2016/01/04 22:44:46 Done.
315 if (rowIndex >= 0 && 310 if (rowIndex >= 0 && rowIndex < num_options) {
Peter Kasting 2016/01/04 21:02:52 Should this be DCHECKs instead of conditionals? H
juncai 2016/01/04 22:44:46 Done.
316 rowIndex < static_cast<NSInteger>(device_names.size())) { 311 return base::SysUTF16ToNSString(
317 return base::SysUTF16ToNSString(device_names[rowIndex]); 312 chooserBubbleDelegate_->GetOption(static_cast<size_t>(rowIndex)));
318 } else { 313 } else {
319 return @""; 314 return @"";
320 } 315 }
321 } 316 }
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;
(...skipping 11 matching lines...) Expand all
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