summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-28 16:36:13 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-28 16:36:13 +0000
commit92bc8147648e1b3c046685e710b133555bc00488 (patch)
treef0ae75150d5fb8c23b4477e9626070a98e67050e /chrome/browser
parent189f4be0be7bedd7962c8134fab9021671f61e2a (diff)
downloadchromium_src-92bc8147648e1b3c046685e710b133555bc00488.zip
chromium_src-92bc8147648e1b3c046685e710b133555bc00488.tar.gz
chromium_src-92bc8147648e1b3c046685e710b133555bc00488.tar.bz2
Fix some glitches dragging tabs.
- Fix what looks like an off-by-one in tab attaching (line 504 in diff) - Ensure ideal bounds are appropriately generated for dragging so that insertion index calculations work properly (line 452, 492) - Provide a threshold so that when dragging left and right a tab must be displaced by at least threshold before tabs are reordered again to prevent jittering. Default threshold is 16px for standard sized tabs, scaled down in the ratio of the unselected current tab size to the standard size depending on the number of tabs open. B=1285677 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/tabs/dragged_tab_controller.cc53
-rw-r--r--chrome/browser/tabs/dragged_tab_controller.h4
2 files changed, 48 insertions, 9 deletions
diff --git a/chrome/browser/tabs/dragged_tab_controller.cc b/chrome/browser/tabs/dragged_tab_controller.cc
index c5f2477..0a043e4 100644
--- a/chrome/browser/tabs/dragged_tab_controller.cc
+++ b/chrome/browser/tabs/dragged_tab_controller.cc
@@ -41,7 +41,7 @@
#include "chrome/views/event.h"
#include "skia/include/SkBitmap.h"
-static const int kSnapshotIntervalMs = 100;
+static const int kHorizontalMoveThreshold = 16; // pixels
namespace {
@@ -114,7 +114,8 @@ DraggedTabController::DraggedTabController(Tab* source_tab,
source_model_index_(source_tabstrip->GetIndexOfTab(source_tab)),
attached_tabstrip_(NULL),
old_focused_view_(NULL),
- in_destructor_(false) {
+ in_destructor_(false),
+ last_move_screen_x_(0) {
ChangeDraggedContents(
source_tabstrip_->model()->GetTabContentsAt(source_model_index_));
// Listen for Esc key presses.
@@ -377,14 +378,33 @@ void DraggedTabController::ContinueDragging() {
void DraggedTabController::MoveTab(const gfx::Point& screen_point) {
gfx::Point dragged_view_point = GetDraggedViewPoint(screen_point);
+
if (attached_tabstrip_) {
- TabStripModel* attached_model = attached_tabstrip_->model();
- int from_index = attached_model->GetIndexOfTabContents(dragged_contents_);
- gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point);
- int to_index = GetInsertionIndexForDraggedBounds(bounds);
- to_index = NormalizeIndexToAttachedTabStrip(to_index);
- attached_model->MoveTabContentsAt(from_index, to_index);
+ // Determine the horizontal move threshold. This is dependent on the width
+ // of tabs. The smaller the tabs compared to the standard size, the smaller
+ // the threshold.
+ double unselected, selected;
+ attached_tabstrip_->GetCurrentTabWidths(&unselected, &selected);
+ double ratio = unselected / Tab::GetStandardSize().width();
+ int threshold = static_cast<int>(ratio * kHorizontalMoveThreshold);
+
+ // Update the model, moving the TabContents from one index to another. Do
+ // this only if we have moved a minimum distance since the last reorder (to
+ // prevent jitter).
+ if (abs(screen_point.x() - last_move_screen_x_) > threshold) {
+ TabStripModel* attached_model = attached_tabstrip_->model();
+ int from_index =
+ attached_model->GetIndexOfTabContents(dragged_contents_);
+ gfx::Rect bounds = GetDraggedViewTabStripBounds(dragged_view_point);
+ int to_index = GetInsertionIndexForDraggedBounds(bounds);
+ to_index = NormalizeIndexToAttachedTabStrip(to_index);
+ if (from_index != to_index) {
+ last_move_screen_x_ = screen_point.x();
+ attached_model->MoveTabContentsAt(from_index, to_index);
+ }
+ }
}
+ // Move the View. There are no changes to the model if we're detached.
view_->MoveTo(dragged_view_point);
}
@@ -429,6 +449,7 @@ void DraggedTabController::Attach(TabStrip* attached_tabstrip,
const gfx::Point& screen_point) {
attached_tabstrip_ = attached_tabstrip;
InitWindowCreatePoint();
+ attached_tabstrip_->GenerateIdealBounds();
// We don't need the photo-booth while we're attached.
photobooth_.reset(NULL);
@@ -464,9 +485,23 @@ void DraggedTabController::Attach(TabStrip* attached_tabstrip,
// Return the TabContents' to normalcy.
dragged_contents_->DidCaptureContents();
+ // We need to ask the TabStrip we're attached to to ensure that the ideal
+ // bounds for all its tabs are correctly generated, because the calculation
+ // in GetInsertionIndexForDraggedBounds needs them to be to figure out the
+ // appropriate insertion index.
+ attached_tabstrip_->GenerateIdealBounds();
+
+ // Inserting counts as a move. We don't want the tabs to jitter when the
+ // user moves the tab immediately after attaching it.
+ last_move_screen_x_ = screen_point.x();
+
+ // Figure out where to insert the tab based on the bounds of the dragged
+ // representation and the ideal bounds of the other Tabs already in the
+ // strip. ("ideal bounds" are stable even if the Tabs' actual bounds are
+ // changing due to animation).
gfx::Rect bounds = GetDraggedViewTabStripBounds(screen_point);
int index = GetInsertionIndexForDraggedBounds(bounds);
- index = NormalizeIndexToAttachedTabStrip(index);
+ index = std::max(std::min(index, attached_tabstrip_->model()->count()), 0);
attached_tabstrip_->model()->InsertTabContentsAt(index, dragged_contents_,
true, false);
diff --git a/chrome/browser/tabs/dragged_tab_controller.h b/chrome/browser/tabs/dragged_tab_controller.h
index 610bb92..82fdb5a 100644
--- a/chrome/browser/tabs/dragged_tab_controller.h
+++ b/chrome/browser/tabs/dragged_tab_controller.h
@@ -296,6 +296,10 @@ class DraggedTabController : public TabContentsDelegate,
bool in_destructor_;
+ // The horizontal position of the mouse cursor in screen coordinates at the
+ // time of the last re-order event.
+ int last_move_screen_x_;
+
DISALLOW_EVIL_CONSTRUCTORS(DraggedTabController);
};