OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 } | 562 } |
563 | 563 |
564 int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) { | 564 int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) { |
565 return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) : | 565 return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) : |
566 std::min(count(), std::max(index, IndexOfFirstNonMiniTab())); | 566 std::min(count(), std::max(index, IndexOfFirstNonMiniTab())); |
567 } | 567 } |
568 | 568 |
569 void TabStripModel::ExtendSelectionTo(int index) { | 569 void TabStripModel::ExtendSelectionTo(int index) { |
570 DCHECK(ContainsIndex(index)); | 570 DCHECK(ContainsIndex(index)); |
571 int old_active = active_index(); | 571 int old_active = active_index(); |
572 std::vector<int> old_selected_indices( | |
James Hawkins
2011/05/18 18:03:10
nit: You use indices here and indexes in the Notif
dpapad
2011/06/01 18:05:41
Done.
| |
573 selection_model().selected_indices()); | |
572 selection_model_.SetSelectionFromAnchorTo(index); | 574 selection_model_.SetSelectionFromAnchorTo(index); |
573 // This may not have resulted in a change, but we assume it did. | 575 // This may not have resulted in a change, but we assume it did. |
576 NotifyMultipleSelectionChanged(old_selected_indices); | |
574 NotifySelectionChanged(old_active); | 577 NotifySelectionChanged(old_active); |
575 } | 578 } |
576 | 579 |
577 void TabStripModel::ToggleSelectionAt(int index) { | 580 void TabStripModel::ToggleSelectionAt(int index) { |
578 DCHECK(ContainsIndex(index)); | 581 DCHECK(ContainsIndex(index)); |
579 int old_active = active_index(); | 582 int old_active = active_index(); |
580 if (selection_model_.IsSelected(index)) { | 583 if (selection_model_.IsSelected(index)) { |
581 if (selection_model_.size() == 1) { | 584 if (selection_model_.size() == 1) { |
582 // One tab must be selected and this tab is currently selected so we can't | 585 // One tab must be selected and this tab is currently selected so we can't |
583 // unselect it. | 586 // unselect it. |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1228 TabContentsWrapper* old_tab = | 1231 TabContentsWrapper* old_tab = |
1229 old_selected_index == TabStripSelectionModel::kUnselectedIndex ? | 1232 old_selected_index == TabStripSelectionModel::kUnselectedIndex ? |
1230 NULL : GetTabContentsAt(old_selected_index); | 1233 NULL : GetTabContentsAt(old_selected_index); |
1231 TabContentsWrapper* new_tab = | 1234 TabContentsWrapper* new_tab = |
1232 active_index() == TabStripSelectionModel::kUnselectedIndex ? | 1235 active_index() == TabStripSelectionModel::kUnselectedIndex ? |
1233 NULL : GetTabContentsAt(active_index()); | 1236 NULL : GetTabContentsAt(active_index()); |
1234 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | 1237 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, |
1235 TabSelectedAt(old_tab, new_tab, active_index(), true)); | 1238 TabSelectedAt(old_tab, new_tab, active_index(), true)); |
1236 } | 1239 } |
1237 | 1240 |
1241 void TabStripModel::NotifyMultipleSelectionChanged( | |
1242 const std::vector<int>& old_selected_indices) { | |
1243 std::set<int> indices_affected; | |
1244 size_t i = 0; | |
1245 for (i = 0; i < old_selected_indices.size(); i++) { | |
1246 if (old_selected_indices[i] != TabStripSelectionModel::kUnselectedIndex) | |
1247 indices_affected.insert(old_selected_indices[i]); | |
1248 } | |
1249 for (i = 0; i < selection_model().selected_indices().size(); i++) | |
1250 indices_affected.insert(selection_model().selected_indices()[i]); | |
1251 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, | |
1252 TabSelectionChanged(indices_affected)); | |
1253 } | |
1254 | |
1238 void TabStripModel::SelectRelativeTab(bool next) { | 1255 void TabStripModel::SelectRelativeTab(bool next) { |
1239 // This may happen during automated testing or if a user somehow buffers | 1256 // This may happen during automated testing or if a user somehow buffers |
1240 // many key accelerators. | 1257 // many key accelerators. |
1241 if (contents_data_.empty()) | 1258 if (contents_data_.empty()) |
1242 return; | 1259 return; |
1243 | 1260 |
1244 int index = active_index(); | 1261 int index = active_index(); |
1245 int delta = next ? 1 : -1; | 1262 int delta = next ? 1 : -1; |
1246 index = (index + count() + delta) % count(); | 1263 index = (index + count() + delta) % count(); |
1247 ActivateTabAt(index, true); | 1264 ActivateTabAt(index, true); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1310 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1327 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
1311 const NavigationController* tab) { | 1328 const NavigationController* tab) { |
1312 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1329 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
1313 i != contents_data_.end(); ++i) { | 1330 i != contents_data_.end(); ++i) { |
1314 if ((*i)->group == tab) | 1331 if ((*i)->group == tab) |
1315 (*i)->group = NULL; | 1332 (*i)->group = NULL; |
1316 if ((*i)->opener == tab) | 1333 if ((*i)->opener == tab) |
1317 (*i)->opener = NULL; | 1334 (*i)->opener = NULL; |
1318 } | 1335 } |
1319 } | 1336 } |
OLD | NEW |