OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "chrome/browser/views/options/cookies_view.h" | 7 #include "chrome/browser/views/options/cookies_view.h" |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time_format.h" | 10 #include "base/time_format.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (SelectedRowCount() <= 0) | 273 if (SelectedRowCount() <= 0) |
274 return; | 274 return; |
275 | 275 |
276 if (SelectedRowCount() == cookies_model_->RowCount()) { | 276 if (SelectedRowCount() == cookies_model_->RowCount()) { |
277 cookies_model_->RemoveAllShownCookies(); | 277 cookies_model_->RemoveAllShownCookies(); |
278 return; | 278 return; |
279 } | 279 } |
280 | 280 |
281 // Remove the selected cookies. This iterates over the rows backwards, which | 281 // Remove the selected cookies. This iterates over the rows backwards, which |
282 // is required when calling RemoveCookies, see bug 2994. | 282 // is required when calling RemoveCookies, see bug 2994. |
283 int first_selected_row = -1; | 283 int last_selected_view_row = -1; |
| 284 int remove_count = 0; |
284 for (views::TableView::iterator i = SelectionBegin(); | 285 for (views::TableView::iterator i = SelectionBegin(); |
285 i != SelectionEnd(); ++i) { | 286 i != SelectionEnd(); ++i) { |
286 int selected_row = *i; | 287 int selected_model_row = *i; |
287 if (first_selected_row == -1) | 288 ++remove_count; |
288 first_selected_row = selected_row; | 289 if (last_selected_view_row == -1) { |
289 cookies_model_->RemoveCookies(selected_row, 1); | 290 // Store the view row since the view to model mapping changes when |
| 291 // we delete. |
| 292 last_selected_view_row = model_to_view(selected_model_row); |
| 293 } |
| 294 cookies_model_->RemoveCookies(selected_model_row, 1); |
290 } | 295 } |
291 // Keep an element selected | 296 |
292 if (RowCount() > 0) | 297 // Select the next row after the last row deleted (unless removing last row). |
293 Select(std::min(RowCount() - 1, first_selected_row)); | 298 DCHECK(RowCount() > 0); |
| 299 Select(view_to_model(std::min(RowCount() - 1, |
| 300 last_selected_view_row - remove_count + 1))); |
294 } | 301 } |
295 | 302 |
296 void CookiesTableView::OnKeyDown(unsigned short virtual_keycode) { | 303 void CookiesTableView::OnKeyDown(unsigned short virtual_keycode) { |
297 if (virtual_keycode == VK_DELETE) | 304 if (virtual_keycode == VK_DELETE) |
298 RemoveSelectedCookies(); | 305 RemoveSelectedCookies(); |
299 } | 306 } |
300 | 307 |
301 /////////////////////////////////////////////////////////////////////////////// | 308 /////////////////////////////////////////////////////////////////////////////// |
302 // CookieInfoView | 309 // CookieInfoView |
303 // | 310 // |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 void CookiesView::ResetSearchQuery() { | 780 void CookiesView::ResetSearchQuery() { |
774 search_field_->SetText(EmptyWString()); | 781 search_field_->SetText(EmptyWString()); |
775 UpdateSearchResults(); | 782 UpdateSearchResults(); |
776 } | 783 } |
777 | 784 |
778 void CookiesView::UpdateForEmptyState() { | 785 void CookiesView::UpdateForEmptyState() { |
779 info_view_->ClearCookieDisplay(); | 786 info_view_->ClearCookieDisplay(); |
780 remove_button_->SetEnabled(false); | 787 remove_button_->SetEnabled(false); |
781 remove_all_button_->SetEnabled(false); | 788 remove_all_button_->SetEnabled(false); |
782 } | 789 } |
OLD | NEW |