Chromium Code Reviews| Index: chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm |
| diff --git a/chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm b/chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm |
| index 409d5e41c537ac700067376fb782e7685e5dbab3..e6611234a79afacf6d1bb7034eb251a5afd0a520 100644 |
| --- a/chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm |
| @@ -315,16 +315,20 @@ void ChooserContentViewController::OnOptionRemoved(size_t index) { |
| // selected, if so, deselect it. Also if the removed item is before the |
| // currently selected item, the currently selected item's index needs to |
| // be adjusted by one. |
| - NSInteger idx = static_cast<NSInteger>(index); |
| - NSInteger selected_row = [table_view_ selectedRow]; |
| - if (selected_row == idx) { |
| - [table_view_ deselectRow:idx]; |
| - } else if (selected_row > idx) { |
| - [table_view_ |
| - selectRowIndexes:[NSIndexSet indexSetWithIndex:selected_row - 1] |
| - byExtendingSelection:NO]; |
| + NSUInteger idx = static_cast<NSUInteger>(index); |
|
Robert Sesek
2016/11/22 19:07:29
Is the cast necessary? size_t should be the same a
juncai
2016/11/22 23:12:06
Done.
|
| + NSIndexSet* selected_rows = [table_view_ selectedRowIndexes]; |
| + NSMutableIndexSet* updated_selected_rows = [NSMutableIndexSet indexSet]; |
| + NSUInteger row = [selected_rows firstIndex]; |
| + while (row != NSNotFound) { |
| + if (row < idx) |
| + [updated_selected_rows addIndex:row]; |
| + else if (row > idx) |
| + [updated_selected_rows addIndex:row - 1]; |
| + row = [selected_rows indexGreaterThanIndex:row]; |
| } |
| + [table_view_ selectRowIndexes:updated_selected_rows byExtendingSelection:NO]; |
| + |
| UpdateTableView(); |
| } |
| @@ -379,14 +383,11 @@ void ChooserContentViewController::OnRefreshStateChanged(bool refreshing) { |
| void ChooserContentViewController::UpdateTableView() { |
| [table_view_ setEnabled:chooser_controller_->NumOptions() > 0]; |
| // For NSView-based table views, calling reloadData will deselect the |
| - // currently selected row, so |selected_row| stores the currently selected |
| - // row in order to select it again. |
| - NSInteger selected_row = [table_view_ selectedRow]; |
| + // currently selected row, so |selected_rows| stores the currently selected |
| + // rows in order to select them again. |
| + NSIndexSet* selected_rows = [table_view_ selectedRowIndexes]; |
| [table_view_ reloadData]; |
| - if (selected_row != -1) { |
| - [table_view_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selected_row] |
| - byExtendingSelection:NO]; |
| - } |
| + [table_view_ selectRowIndexes:selected_rows byExtendingSelection:NO]; |
| } |
| @implementation ChooserContentViewCocoa |
| @@ -500,6 +501,10 @@ void ChooserContentViewController::UpdateTableView() { |
| // Make the column title invisible. |
| [tableView_ setHeaderView:nil]; |
| [tableView_ setFocusRingType:NSFocusRingTypeNone]; |
| + [tableView_ |
| + setAllowsMultipleSelection:chooserController_->AllowMultipleSelection() |
| + ? YES |
| + : NO]; |
| // Spinner. |
| // Set the spinner in the center of the scroll view. |
| @@ -794,7 +799,12 @@ void ChooserContentViewController::UpdateTableView() { |
| } |
| - (void)accept { |
| - chooserController_->Select([tableView_ selectedRow]); |
| + NSIndexSet* selectedRows = [tableView_ selectedRowIndexes]; |
| + NSUInteger index = [selectedRows firstIndex]; |
| + while (index != NSNotFound) { |
| + chooserController_->Select(index); |
| + index = [selectedRows indexGreaterThanIndex:index]; |
| + } |
| } |
| - (void)cancel { |
| @@ -818,15 +828,16 @@ void ChooserContentViewController::UpdateTableView() { |
| } |
| - (void)updateContentRowColor { |
| - NSInteger selectedRow = [tableView_ selectedRow]; |
| + NSIndexSet* selectedRows = [tableView_ selectedRowIndexes]; |
| NSInteger numOptions = |
| base::checked_cast<NSInteger>(chooserController_->NumOptions()); |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| for (NSInteger rowIndex = 0; rowIndex < numOptions; ++rowIndex) { |
| + BOOL isSelected = [selectedRows containsIndex:rowIndex]; |
| // Update the color of the text. |
| [[self tableRowViewText:rowIndex] |
| - setTextColor:(rowIndex == selectedRow ? [NSColor whiteColor] |
| - : [NSColor blackColor])]; |
| + setTextColor:(isSelected ? [NSColor whiteColor] |
| + : [NSColor blackColor])]; |
| // Update the color of the image. |
| if (chooserController_->ShouldShowIconBeforeText()) { |
| @@ -834,14 +845,13 @@ void ChooserContentViewController::UpdateTableView() { |
| [[self tableRowViewImage:rowIndex] |
| setImage:gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( |
| gfx::VectorIconId::BLUETOOTH_CONNECTED, |
| - rowIndex == selectedRow ? SK_ColorWHITE |
| - : gfx::kChromeIconGrey))]; |
| + isSelected ? SK_ColorWHITE : gfx::kChromeIconGrey))]; |
| } else { |
| int signalStrengthLevel = |
| chooserController_->GetSignalStrengthLevel(rowIndex); |
| if (signalStrengthLevel != -1) { |
| int imageId = |
| - rowIndex == selectedRow |
| + isSelected |
| ? kSignalStrengthLevelImageSelectedIds[signalStrengthLevel] |
| : kSignalStrengthLevelImageIds[signalStrengthLevel]; |
| [[self tableRowViewImage:rowIndex] |
| @@ -853,10 +863,9 @@ void ChooserContentViewController::UpdateTableView() { |
| // Update the color of paired status. |
| NSTextField* pairedStatusText = [self tableRowViewPairedStatus:rowIndex]; |
| if (pairedStatusText) { |
| - [pairedStatusText |
| - setTextColor:(skia::SkColorToCalibratedNSColor( |
| - rowIndex == selectedRow ? gfx::kGoogleGreen300 |
| - : gfx::kGoogleGreen700))]; |
| + [pairedStatusText setTextColor:(skia::SkColorToCalibratedNSColor( |
| + isSelected ? gfx::kGoogleGreen300 |
| + : gfx::kGoogleGreen700))]; |
| } |
| } |
| } |