summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/tabs/tab_strip_model.cc12
-rw-r--r--chrome/browser/tabs/tab_strip_model.h5
-rw-r--r--chrome/browser/tabs/tab_strip_model_unittest.cc18
-rw-r--r--chrome/browser/views/tabs/dragged_tab_controller.cc5
4 files changed, 33 insertions, 7 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();
}
diff --git a/chrome/browser/views/tabs/dragged_tab_controller.cc b/chrome/browser/views/tabs/dragged_tab_controller.cc
index fc5d0e1..95e2022 100644
--- a/chrome/browser/views/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/views/tabs/dragged_tab_controller.cc
@@ -584,7 +584,7 @@ void DraggedTabController::MoveTab(const gfx::Point& screen_point) {
to_index = NormalizeIndexToAttachedTabStrip(to_index);
if (from_index != to_index) {
last_move_screen_x_ = screen_point.x();
- attached_model->MoveTabContentsAt(from_index, to_index);
+ attached_model->MoveTabContentsAt(from_index, to_index, true);
}
}
}
@@ -923,7 +923,8 @@ void DraggedTabController::RevertDrag() {
} else {
// The Tab was moved within the TabStrip where the drag was initiated.
// Move it back to the starting location.
- source_tabstrip_->model()->MoveTabContentsAt(index, source_model_index_);
+ source_tabstrip_->model()->MoveTabContentsAt(index, source_model_index_,
+ true);
}
} else {
// TODO(beng): (Cleanup) seems like we should use Attach() for this