diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-16 01:27:13 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-16 01:27:13 +0000 |
commit | f606747ffb21e9d0c6d55c9b57d42445503728f1 (patch) | |
tree | ff33aa2756665de01a8cb608d06fcdbcbb2e0263 /chrome/browser/tabs | |
parent | 6b2ebf86a61169856aa3e650c294fd3511da5ee3 (diff) | |
download | chromium_src-f606747ffb21e9d0c6d55c9b57d42445503728f1.zip chromium_src-f606747ffb21e9d0c6d55c9b57d42445503728f1.tar.gz chromium_src-f606747ffb21e9d0c6d55c9b57d42445503728f1.tar.bz2 |
ad an argument to MoveTabContentsAt() that switches whether the moved tab is set as the selected tab, or if the selected tab is left selected (but possibly moved).
Review URL: http://codereview.chromium.org/63153
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tabs')
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.cc | 12 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.h | 5 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model_unittest.cc | 18 |
3 files changed, 30 insertions, 5 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc index c4b5ecd..5882705 100644 --- a/chrome/browser/tabs/tab_strip_model.cc +++ b/chrome/browser/tabs/tab_strip_model.cc @@ -153,7 +153,8 @@ void TabStripModel::SelectTabContentsAt(int index, bool user_gesture) { ChangeSelectedContentsFrom(GetSelectedTabContents(), index, user_gesture); } -void TabStripModel::MoveTabContentsAt(int index, int to_position) { +void TabStripModel::MoveTabContentsAt(int index, int to_position, + bool select_after_move) { DCHECK(ContainsIndex(index)); if (index == to_position) return; @@ -162,7 +163,14 @@ void TabStripModel::MoveTabContentsAt(int index, int to_position) { contents_data_.erase(contents_data_.begin() + index); contents_data_.insert(contents_data_.begin() + to_position, moved_data); - selected_index_ = to_position; + // if !select_after_move, keep the same tab selected as was selected before. + if (select_after_move || index == selected_index_) { + selected_index_ = to_position; + } else if (index < selected_index_ && to_position >= selected_index_) { + selected_index_--; + } else if (index > selected_index_ && to_position <= selected_index_) { + selected_index_++; + } FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabMoved(moved_data->contents, index, to_position)); diff --git a/chrome/browser/tabs/tab_strip_model.h b/chrome/browser/tabs/tab_strip_model.h index c6b7c76..bb9b2c5 100644 --- a/chrome/browser/tabs/tab_strip_model.h +++ b/chrome/browser/tabs/tab_strip_model.h @@ -285,7 +285,10 @@ class TabStripModel : public NotificationObserver { // Move the TabContents at the specified index to another index. This method // does NOT send Detached/Attached notifications, rather it moves the // TabContents inline and sends a Moved notification instead. - void MoveTabContentsAt(int index, int to_position); + // If |select_after_move| is false, whatever tab was selected before the move + // will still be selected, but it's index may have incremented or decremented + // one slot. + void MoveTabContentsAt(int index, int to_position, bool select_after_move); // Returns the currently selected TabContents, or NULL if there is none. TabContents* GetSelectedTabContents() const; diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index f5b7028..6b1f3d0 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -328,14 +328,28 @@ TEST_F(TabStripModelTest, TestBasicAPI) { observer.ClearStates(); } - // Test MoveTabContentsAt + // Test MoveTabContentsAt, select_after_move == true { - tabstrip.MoveTabContentsAt(1, 0); + tabstrip.MoveTabContentsAt(1, 0, true); EXPECT_EQ(1, observer.GetStateCount()); State s1(contents2, 0, MockTabStripModelObserver::MOVE); s1.src_index = 1; EXPECT_TRUE(observer.StateEquals(0, s1)); + EXPECT_EQ(0, tabstrip.selected_index()); + observer.ClearStates(); + } + + // Test MoveTabContentsAt, select_after_move == false + { + tabstrip.MoveTabContentsAt(1, 0, false); + EXPECT_EQ(1, observer.GetStateCount()); + State s1(contents1, 0, MockTabStripModelObserver::MOVE); + s1.src_index = 1; + EXPECT_TRUE(observer.StateEquals(0, s1)); + EXPECT_EQ(1, tabstrip.selected_index()); + + tabstrip.MoveTabContentsAt(0, 1, false); observer.ClearStates(); } |