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 return std::max(static_cast<NSInteger>(chooserBubbleDelegate_->NumOptions()), |
Peter Kasting
2016/01/04 23:54:00
Nit: Might as well copy the comment from the other
juncai
2016/01/05 03:37:27
Done.
| |
298 chooserBubbleDelegate_->GetOptions(); | 298 static_cast<NSInteger>(1)); |
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_EQ(0, rowIndex); |
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 { | |
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 } | 309 } |
310 | |
311 DCHECK_GE(rowIndex, 0); | |
312 DCHECK_LT(rowIndex, num_options); | |
313 return base::SysUTF16ToNSString( | |
314 chooserBubbleDelegate_->GetOption(static_cast<size_t>(rowIndex))); | |
322 } | 315 } |
323 | 316 |
324 - (BOOL)tableView:(NSTableView*)aTableView | 317 - (BOOL)tableView:(NSTableView*)aTableView |
325 shouldEditTableColumn:(NSTableColumn*)aTableColumn | 318 shouldEditTableColumn:(NSTableColumn*)aTableColumn |
326 row:(NSInteger)rowIndex { | 319 row:(NSInteger)rowIndex { |
327 return NO; | 320 return NO; |
328 } | 321 } |
329 | 322 |
330 - (void)onOptionsInitialized { | 323 - (void)onOptionsInitialized { |
331 [self updateTableView]; | 324 [self updateTableView]; |
332 } | 325 } |
333 | 326 |
334 - (void)onOptionAdded:(NSInteger)index { | 327 - (void)onOptionAdded:(NSInteger)index { |
335 [self updateTableView]; | 328 [self updateTableView]; |
336 } | 329 } |
337 | 330 |
338 - (void)onOptionRemoved:(NSInteger)index { | 331 - (void)onOptionRemoved:(NSInteger)index { |
339 // |tableView_| will automatically selects the next item if the current | 332 // |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 | 333 // item is removed, so here it tracks if the removed item is the item |
341 // that was previously selected, if so, deselect it. | 334 // that was previously selected, if so, deselect it. |
342 if ([tableView_ selectedRow] == index) | 335 if ([tableView_ selectedRow] == index) |
343 [tableView_ deselectRow:index]; | 336 [tableView_ deselectRow:index]; |
344 | 337 |
345 [self updateTableView]; | 338 [self updateTableView]; |
346 } | 339 } |
347 | 340 |
348 - (void)updateTableView { | 341 - (void)updateTableView { |
349 const std::vector<base::string16>& device_names = | 342 [tableView_ setEnabled:chooserBubbleDelegate_->NumOptions() > 0]; |
350 chooserBubbleDelegate_->GetOptions(); | |
351 [tableView_ setEnabled:!device_names.empty()]; | |
352 [tableView_ reloadData]; | 343 [tableView_ reloadData]; |
353 } | 344 } |
354 | 345 |
355 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { | 346 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { |
356 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; | 347 [connectButton_ setEnabled:[tableView_ numberOfSelectedRows] > 0]; |
357 } | 348 } |
358 | 349 |
359 - (void)updateAnchorPosition { | 350 - (void)updateAnchorPosition { |
360 [self setParentWindow:[self getExpectedParentWindow]]; | 351 [self setParentWindow:[self getExpectedParentWindow]]; |
361 [self setAnchorPoint:[self getExpectedAnchorPoint]]; | 352 [self setAnchorPoint:[self getExpectedAnchorPoint]]; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 } | 487 } |
497 | 488 |
498 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { | 489 void ChooserBubbleUiCocoa::UpdateAnchorPosition() { |
499 [chooser_bubble_ui_controller_ updateAnchorPosition]; | 490 [chooser_bubble_ui_controller_ updateAnchorPosition]; |
500 } | 491 } |
501 | 492 |
502 void ChooserBubbleUiCocoa::OnOptionsInitialized() { | 493 void ChooserBubbleUiCocoa::OnOptionsInitialized() { |
503 [chooser_bubble_ui_controller_ onOptionsInitialized]; | 494 [chooser_bubble_ui_controller_ onOptionsInitialized]; |
504 } | 495 } |
505 | 496 |
506 void ChooserBubbleUiCocoa::OnOptionAdded(int index) { | 497 void ChooserBubbleUiCocoa::OnOptionAdded(size_t index) { |
507 [chooser_bubble_ui_controller_ onOptionAdded:index]; | 498 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
508 } | 499 } |
509 | 500 |
510 void ChooserBubbleUiCocoa::OnOptionRemoved(int index) { | 501 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
511 [chooser_bubble_ui_controller_ onOptionRemoved:index]; | 502 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
512 } | 503 } |
513 | 504 |
514 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 505 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
515 chooser_bubble_ui_controller_ = nil; | 506 chooser_bubble_ui_controller_ = nil; |
516 } | 507 } |
OLD | NEW |