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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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); |
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); |
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 { |
315 if (rowIndex >= 0 && | 310 if (rowIndex >= 0 && rowIndex < num_options) { |
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 Loading... | |
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()]; |
Reilly Grant (use Gerrit)
2016/01/04 19:00:25
Please explicitly compare this value to 0.
juncai
2016/01/04 19:35:55
Done.
| |
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 Loading... | |
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 } |
OLD | NEW |