diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 14:26:53 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 14:26:53 +0000 |
commit | 4779dba9042e38f39b3e2ad9c31ab822315f86b8 (patch) | |
tree | 2d8a88842f35c1ee2afd913d17f7e85c10bb8692 /chrome/browser/tabs | |
parent | b82904599ac688f2df2ac5ec1e79813e7d470cc7 (diff) | |
download | chromium_src-4779dba9042e38f39b3e2ad9c31ab822315f86b8.zip chromium_src-4779dba9042e38f39b3e2ad9c31ab822315f86b8.tar.gz chromium_src-4779dba9042e38f39b3e2ad9c31ab822315f86b8.tar.bz2 |
Makes control-shift clicks on the tabstrip work. In particular
control-shift makes sure the tabs from the anchor to the index the
user clicked on are selected, but doesn't remove anything.
BUG=30572
TEST=none, just make sure tab selection isn't broken.
R=ben@chromium.org
Review URL: http://codereview.chromium.org/6709011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.cc | 6 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.h | 4 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_selection_model.cc | 18 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_selection_model.h | 4 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_selection_model_unittest.cc | 11 |
5 files changed, 40 insertions, 3 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc index e030167..6f87482 100644 --- a/chrome/browser/tabs/tab_strip_model.cc +++ b/chrome/browser/tabs/tab_strip_model.cc @@ -585,6 +585,12 @@ void TabStripModel::ToggleSelectionAt(int index) { NotifySelectionChanged(old_selection); } +void TabStripModel::AddSelectionFromAnchorTo(int index) { + int old_selection = selected_index(); + selection_model_.AddSelectionFromAnchorTo(index); + NotifySelectionChanged(old_selection); +} + bool TabStripModel::IsTabSelected(int index) const { DCHECK(ContainsIndex(index)); return selection_model_.IsSelected(index); diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h index 2b7fd95..9c481b2 100644 --- a/chrome/browser/tabs/tab_strip_model.h +++ b/chrome/browser/tabs/tab_strip_model.h @@ -375,6 +375,10 @@ class TabStripModel : public NotificationObserver { // and there are no other selected tabs. void ToggleSelectionAt(int index); + // Makes sure the tabs from the anchor to |index| are selected. This only + // adds to the selection. + void AddSelectionFromAnchorTo(int index); + // Returns true if the tab at |index| is selected. bool IsTabSelected(int index) const; diff --git a/chrome/browser/tabs/tab_strip_selection_model.cc b/chrome/browser/tabs/tab_strip_selection_model.cc index 0437e64..1164b28 100644 --- a/chrome/browser/tabs/tab_strip_selection_model.cc +++ b/chrome/browser/tabs/tab_strip_selection_model.cc @@ -83,9 +83,7 @@ void TabStripSelectionModel::RemoveIndexFromSelection(int index) { void TabStripSelectionModel::SetSelectionFromAnchorTo(int index) { if (anchor_ == kUnselectedIndex) { - anchor_ = index; - active_ = index; - std::sort(selected_indices_.begin(), selected_indices_.end()); + SetSelectedIndex(index); } else { int delta = std::abs(index - anchor_); SelectedIndices new_selection(delta + 1, 0); @@ -96,6 +94,20 @@ void TabStripSelectionModel::SetSelectionFromAnchorTo(int index) { } } +void TabStripSelectionModel::AddSelectionFromAnchorTo(int index) { + if (anchor_ == kUnselectedIndex) { + SetSelectedIndex(index); + } else { + for (int i = std::min(index, anchor_), end = std::max(index, anchor_); + i <= end; ++i) { + if (!IsSelected(i)) + selected_indices_.push_back(i); + } + std::sort(selected_indices_.begin(), selected_indices_.end()); + active_ = index; + } +} + void TabStripSelectionModel::Move(int from, int to) { DCHECK_NE(to, from); bool was_anchor = from == anchor_; diff --git a/chrome/browser/tabs/tab_strip_selection_model.h b/chrome/browser/tabs/tab_strip_selection_model.h index cb41f74..9ce7618 100644 --- a/chrome/browser/tabs/tab_strip_selection_model.h +++ b/chrome/browser/tabs/tab_strip_selection_model.h @@ -72,6 +72,10 @@ class TabStripSelectionModel { // this sets the anchor, selection and active indices to |index|. void SetSelectionFromAnchorTo(int index); + // Makes sure the indices from the anchor to |index| are selected. This only + // adds to the selection. + void AddSelectionFromAnchorTo(int index); + // Invoked when an item moves. |from| is the original index, and |to| the // target index. // NOTE: this matches the TabStripModel API. If moving to a greater index, diff --git a/chrome/browser/tabs/tab_strip_selection_model_unittest.cc b/chrome/browser/tabs/tab_strip_selection_model_unittest.cc index 78d898a..bf1ac87 100644 --- a/chrome/browser/tabs/tab_strip_selection_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_selection_model_unittest.cc @@ -139,3 +139,14 @@ TEST_F(TabStripSelectionModelTest, Copy) { model2.Copy(model); EXPECT_EQ("active=0 anchor=0 selection=0 4 10", StateAsString(model2)); } + +TEST_F(TabStripSelectionModelTest, AddSelectionFromAnchorTo) { + TabStripSelectionModel model; + model.SetSelectedIndex(2); + + model.AddSelectionFromAnchorTo(4); + EXPECT_EQ("active=4 anchor=2 selection=2 3 4", StateAsString(model)); + + model.AddSelectionFromAnchorTo(0); + EXPECT_EQ("active=0 anchor=2 selection=0 1 2 3 4", StateAsString(model)); +} |