| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 - (void)onOptionsInitialized { | 246 - (void)onOptionsInitialized { |
| 247 [self updateTableView]; | 247 [self updateTableView]; |
| 248 } | 248 } |
| 249 | 249 |
| 250 - (void)onOptionAdded:(NSInteger)index { | 250 - (void)onOptionAdded:(NSInteger)index { |
| 251 [self updateTableView]; | 251 [self updateTableView]; |
| 252 } | 252 } |
| 253 | 253 |
| 254 - (void)onOptionRemoved:(NSInteger)index { | 254 - (void)onOptionRemoved:(NSInteger)index { |
| 255 // |tableView_| will automatically selects the next item if the current | 255 // |tableView_| will automatically select the removed item's next item. |
| 256 // item is removed, so here it tracks if the removed item is the item | 256 // So here it tracks if the removed item is the item that was currently |
| 257 // that was previously selected, if so, deselect it. | 257 // selected, if so, deselect it. Also if the removed item is before the |
| 258 if ([tableView_ selectedRow] == index) | 258 // currently selected item, the currently selected item's index needs to |
| 259 // be adjusted by one. |
| 260 NSInteger selectedRow = [tableView_ selectedRow]; |
| 261 if (selectedRow == index) |
| 259 [tableView_ deselectRow:index]; | 262 [tableView_ deselectRow:index]; |
| 263 else if (selectedRow > index) |
| 264 [tableView_ selectRowIndexes:[NSIndexSet indexSetWithIndex:selectedRow - 1] |
| 265 byExtendingSelection:NO]; |
| 260 | 266 |
| 261 [self updateTableView]; | 267 [self updateTableView]; |
| 262 } | 268 } |
| 263 | 269 |
| 264 - (void)updateTableView { | 270 - (void)updateTableView { |
| 265 [tableView_ setEnabled:chooserController_->NumOptions() > 0]; | 271 [tableView_ setEnabled:chooserController_->NumOptions() > 0]; |
| 266 [tableView_ reloadData]; | 272 [tableView_ reloadData]; |
| 267 } | 273 } |
| 268 | 274 |
| 269 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { | 275 - (void)tableViewSelectionDidChange:(NSNotification*)aNotification { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; | 395 [chooser_bubble_ui_controller_ onOptionAdded:static_cast<NSInteger>(index)]; |
| 390 } | 396 } |
| 391 | 397 |
| 392 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { | 398 void ChooserBubbleUiCocoa::OnOptionRemoved(size_t index) { |
| 393 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; | 399 [chooser_bubble_ui_controller_ onOptionRemoved:static_cast<NSInteger>(index)]; |
| 394 } | 400 } |
| 395 | 401 |
| 396 void ChooserBubbleUiCocoa::OnBubbleClosing() { | 402 void ChooserBubbleUiCocoa::OnBubbleClosing() { |
| 397 chooser_bubble_ui_controller_ = nil; | 403 chooser_bubble_ui_controller_ = nil; |
| 398 } | 404 } |
| OLD | NEW |