Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: chrome/browser/tabs/tab_strip_model.cc

Issue 6933037: Multi-tab selection for Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing nits Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 false); 237 false);
238 } 238 }
239 } 239 }
240 } 240 }
241 return removed_contents; 241 return removed_contents;
242 } 242 }
243 243
244 void TabStripModel::ActivateTabAt(int index, bool user_gesture) { 244 void TabStripModel::ActivateTabAt(int index, bool user_gesture) {
245 DCHECK(ContainsIndex(index)); 245 DCHECK(ContainsIndex(index));
246 bool had_multi = selection_model_.selected_indices().size() > 1; 246 bool had_multi = selection_model_.selected_indices().size() > 1;
247 std::vector<int> old_selected_indices(selection_model().selected_indices());
247 TabContentsWrapper* old_contents = 248 TabContentsWrapper* old_contents =
248 (active_index() == TabStripSelectionModel::kUnselectedIndex) ? 249 (active_index() == TabStripSelectionModel::kUnselectedIndex) ?
249 NULL : GetSelectedTabContents(); 250 NULL : GetSelectedTabContents();
250 selection_model_.SetSelectedIndex(index); 251 selection_model_.SetSelectedIndex(index);
251 TabContentsWrapper* new_contents = GetContentsAt(index); 252 TabContentsWrapper* new_contents = GetContentsAt(index);
252 if (old_contents != new_contents && old_contents) { 253 if (old_contents != new_contents && old_contents) {
253 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 254 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
254 TabDeselected(old_contents)); 255 TabDeselected(old_contents));
255 } 256 }
256 if (old_contents != new_contents || had_multi) { 257 if (old_contents != new_contents || had_multi) {
257 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 258 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
258 ActiveTabChanged(old_contents, new_contents, 259 ActiveTabChanged(old_contents, new_contents,
259 active_index(), user_gesture)); 260 active_index(), user_gesture));
261 NotifySelectionChanged(old_selected_indices);
260 } 262 }
261 } 263 }
262 264
263 void TabStripModel::MoveTabContentsAt(int index, 265 void TabStripModel::MoveTabContentsAt(int index,
264 int to_position, 266 int to_position,
265 bool select_after_move) { 267 bool select_after_move) {
266 DCHECK(ContainsIndex(index)); 268 DCHECK(ContainsIndex(index));
267 if (index == to_position) 269 if (index == to_position)
268 return; 270 return;
269 271
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } 565 }
564 566
565 int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) { 567 int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) {
566 return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) : 568 return mini_tab ? std::min(std::max(0, index), IndexOfFirstNonMiniTab()) :
567 std::min(count(), std::max(index, IndexOfFirstNonMiniTab())); 569 std::min(count(), std::max(index, IndexOfFirstNonMiniTab()));
568 } 570 }
569 571
570 void TabStripModel::ExtendSelectionTo(int index) { 572 void TabStripModel::ExtendSelectionTo(int index) {
571 DCHECK(ContainsIndex(index)); 573 DCHECK(ContainsIndex(index));
572 int old_active = active_index(); 574 int old_active = active_index();
575 std::vector<int> old_selected_indices(selection_model().selected_indices());
573 selection_model_.SetSelectionFromAnchorTo(index); 576 selection_model_.SetSelectionFromAnchorTo(index);
574 // This may not have resulted in a change, but we assume it did. 577 // This may not have resulted in a change, but we assume it did.
575 NotifyActiveTabChanged(old_active); 578 NotifyActiveTabChanged(old_active);
579 NotifySelectionChanged(old_selected_indices);
576 } 580 }
577 581
578 void TabStripModel::ToggleSelectionAt(int index) { 582 void TabStripModel::ToggleSelectionAt(int index) {
579 DCHECK(ContainsIndex(index)); 583 DCHECK(ContainsIndex(index));
580 int old_active = active_index(); 584 int old_active = active_index();
585 std::vector<int> old_selected_indices(selection_model().selected_indices());
581 if (selection_model_.IsSelected(index)) { 586 if (selection_model_.IsSelected(index)) {
582 if (selection_model_.size() == 1) { 587 if (selection_model_.size() == 1) {
583 // One tab must be selected and this tab is currently selected so we can't 588 // One tab must be selected and this tab is currently selected so we can't
584 // unselect it. 589 // unselect it.
585 return; 590 return;
586 } 591 }
587 selection_model_.RemoveIndexFromSelection(index); 592 selection_model_.RemoveIndexFromSelection(index);
588 selection_model_.set_anchor(index); 593 selection_model_.set_anchor(index);
589 if (selection_model_.active() == TabStripSelectionModel::kUnselectedIndex) 594 if (selection_model_.active() == TabStripSelectionModel::kUnselectedIndex)
590 selection_model_.set_active(selection_model_.selected_indices()[0]); 595 selection_model_.set_active(selection_model_.selected_indices()[0]);
591 } else { 596 } else {
592 selection_model_.AddIndexToSelection(index); 597 selection_model_.AddIndexToSelection(index);
593 selection_model_.set_anchor(index); 598 selection_model_.set_anchor(index);
594 selection_model_.set_active(index); 599 selection_model_.set_active(index);
595 } 600 }
596 NotifyActiveTabChanged(old_active); 601 NotifyActiveTabChanged(old_active);
602 NotifySelectionChanged(old_selected_indices);
597 } 603 }
598 604
599 void TabStripModel::AddSelectionFromAnchorTo(int index) { 605 void TabStripModel::AddSelectionFromAnchorTo(int index) {
600 int old_active = active_index(); 606 int old_active = active_index();
607 std::vector<int> old_selected_indices(selection_model().selected_indices());
601 selection_model_.AddSelectionFromAnchorTo(index); 608 selection_model_.AddSelectionFromAnchorTo(index);
602 NotifyActiveTabChanged(old_active); 609 NotifyActiveTabChanged(old_active);
610 NotifySelectionChanged(old_selected_indices);
603 } 611 }
604 612
605 bool TabStripModel::IsTabSelected(int index) const { 613 bool TabStripModel::IsTabSelected(int index) const {
606 DCHECK(ContainsIndex(index)); 614 DCHECK(ContainsIndex(index));
607 return selection_model_.IsSelected(index); 615 return selection_model_.IsSelected(index);
608 } 616 }
609 617
610 void TabStripModel::SetSelectionFromModel( 618 void TabStripModel::SetSelectionFromModel(
611 const TabStripSelectionModel& source) { 619 const TabStripSelectionModel& source) {
612 DCHECK_NE(TabStripSelectionModel::kUnselectedIndex, source.active()); 620 DCHECK_NE(TabStripSelectionModel::kUnselectedIndex, source.active());
613 int old_active_index = active_index(); 621 int old_active_index = active_index();
622 std::vector<int> old_selected_indices(selection_model().selected_indices());
614 selection_model_.Copy(source); 623 selection_model_.Copy(source);
615 // This may not have resulted in a change, but we assume it did. 624 // This may not have resulted in a change, but we assume it did.
616 NotifyActiveTabChanged(old_active_index); 625 NotifyActiveTabChanged(old_active_index);
626 NotifySelectionChanged(old_selected_indices);
617 } 627 }
618 628
619 void TabStripModel::AddTabContents(TabContentsWrapper* contents, 629 void TabStripModel::AddTabContents(TabContentsWrapper* contents,
620 int index, 630 int index,
621 PageTransition::Type transition, 631 PageTransition::Type transition,
622 int add_types) { 632 int add_types) {
623 // If the newly-opened tab is part of the same task as the parent tab, we want 633 // If the newly-opened tab is part of the same task as the parent tab, we want
624 // to inherit the parent's "group" attribute, so that if this tab is then 634 // to inherit the parent's "group" attribute, so that if this tab is then
625 // closed we'll jump back to the parent tab. 635 // closed we'll jump back to the parent tab.
626 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; 636 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP;
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 TabContentsWrapper* old_tab = 1239 TabContentsWrapper* old_tab =
1230 old_active_index == TabStripSelectionModel::kUnselectedIndex ? 1240 old_active_index == TabStripSelectionModel::kUnselectedIndex ?
1231 NULL : GetTabContentsAt(old_active_index); 1241 NULL : GetTabContentsAt(old_active_index);
1232 TabContentsWrapper* new_tab = 1242 TabContentsWrapper* new_tab =
1233 active_index() == TabStripSelectionModel::kUnselectedIndex ? 1243 active_index() == TabStripSelectionModel::kUnselectedIndex ?
1234 NULL : GetTabContentsAt(active_index()); 1244 NULL : GetTabContentsAt(active_index());
1235 FOR_EACH_OBSERVER(TabStripModelObserver, observers_, 1245 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1236 ActiveTabChanged(old_tab, new_tab, active_index(), true)); 1246 ActiveTabChanged(old_tab, new_tab, active_index(), true));
1237 } 1247 }
1238 1248
1249 void TabStripModel::NotifySelectionChanged(
1250 const std::vector<int>& old_selected_indices) {
1251 FOR_EACH_OBSERVER(TabStripModelObserver, observers_,
1252 TabSelectionChanged(old_selected_indices,
1253 selection_model().selected_indices()));
1254 }
1255
1239 void TabStripModel::SelectRelativeTab(bool next) { 1256 void TabStripModel::SelectRelativeTab(bool next) {
1240 // This may happen during automated testing or if a user somehow buffers 1257 // This may happen during automated testing or if a user somehow buffers
1241 // many key accelerators. 1258 // many key accelerators.
1242 if (contents_data_.empty()) 1259 if (contents_data_.empty())
1243 return; 1260 return;
1244 1261
1245 int index = active_index(); 1262 int index = active_index();
1246 int delta = next ? 1 : -1; 1263 int delta = next ? 1 : -1;
1247 index = (index + count() + delta) % count(); 1264 index = (index + count() + delta) % count();
1248 ActivateTabAt(index, true); 1265 ActivateTabAt(index, true);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 void TabStripModel::ForgetOpenersAndGroupsReferencing( 1328 void TabStripModel::ForgetOpenersAndGroupsReferencing(
1312 const NavigationController* tab) { 1329 const NavigationController* tab) {
1313 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); 1330 for (TabContentsDataVector::const_iterator i = contents_data_.begin();
1314 i != contents_data_.end(); ++i) { 1331 i != contents_data_.end(); ++i) {
1315 if ((*i)->group == tab) 1332 if ((*i)->group == tab)
1316 (*i)->group = NULL; 1333 (*i)->group = NULL;
1317 if ((*i)->opener == tab) 1334 if ((*i)->opener == tab)
1318 (*i)->opener = NULL; 1335 (*i)->opener = NULL;
1319 } 1336 }
1320 } 1337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698