diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 02:12:28 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 02:12:28 +0000 |
commit | 7fadbfcd614041c2c4bd8fe0b16a96f4bcd74cf2 (patch) | |
tree | 8a43b5fefdf153006a2878308967cafa26b06c6b | |
parent | 48569688925a28c99ce3b92ffcd81b0c3f407c15 (diff) | |
download | chromium_src-7fadbfcd614041c2c4bd8fe0b16a96f4bcd74cf2.zip chromium_src-7fadbfcd614041c2c4bd8fe0b16a96f4bcd74cf2.tar.gz chromium_src-7fadbfcd614041c2c4bd8fe0b16a96f4bcd74cf2.tar.bz2 |
Makes it so that if you drag a tab to the left edge of the tab strip
and hold the mouse for a little bit, the tab is pinned.
BUG=16634
TEST=on linux with no tabs pinned drag until your close to the right
edge of the tab and wait a second. The tab should be pinned.
Review URL: http://codereview.chromium.org/155543
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc | 69 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h | 17 |
2 files changed, 76 insertions, 10 deletions
diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc index 37a5b0d..691bb95 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc @@ -29,6 +29,14 @@ const int kHorizontalPinnedMoveThreshold = 4; // pixels // How far a drag must pull a tab out of the tabstrip in order to detach it. const int kVerticalDetachMagnetism = 15; // pixels +// Amount, in pixels, from the edge of the tab strip that causes a non-pinned +// tab to be pinned. See description of pin_timer_ for details. +const int kHorizontalPinTabOffset = 16; + +// Delay, in ms, between when the user drags a tab to the edge of the tab strip +// and when the tab becomes pinned. See description of pin_timer_ for details. +const int kPinTabDelay = 300; + } // namespace DraggedTabControllerGtk::DraggedTabControllerGtk(TabGtk* source_tab, @@ -67,6 +75,7 @@ void DraggedTabControllerGtk::Drag() { return; bring_to_front_timer_.Stop(); + pin_timer_.Stop(); // Before we get to dragging anywhere, ensure that we consider ourselves // attached to the source tabstrip. @@ -288,12 +297,60 @@ void DraggedTabControllerGtk::MoveTab(const gfx::Point& screen_point) { attached_model->MoveTabContentsAt(from_index, to_index, true); } } + + StartPinTimerIfNecessary(screen_point); } // Move the dragged tab. There are no changes to the model if we're detached. dragged_tab_->MoveTo(dragged_tab_point); } +void DraggedTabControllerGtk::MakeDraggedTabPinned() { + MakeDraggedTabPinned(0); +} + +void DraggedTabControllerGtk::MakeDraggedTabPinned(int tab_index) { + DCHECK(dragged_tab_.get()); + DCHECK(!dragged_tab_->is_pinned()); + + // Mark the tab as pinned and update the model. + dragged_tab_->set_pinned(true); + attached_tabstrip_->model()->SetTabPinned(tab_index, true); + + // Reset the hotspot (mouse_offset_) for the dragged tab. Otherwise the + // dragged tab may be nowhere near the mouse. + mouse_offset_.set_x(TabGtk::GetPinnedWidth() / 2 - 1); + InitWindowCreatePoint(); + dragged_tab_->set_mouse_tab_offset(mouse_offset_); + + // Resize the dragged tab. + dragged_tab_->Resize(TabGtk::GetPinnedWidth()); +} + +void DraggedTabControllerGtk::StartPinTimerIfNecessary( + const gfx::Point& screen_point) { + if (dragged_tab_->is_pinned()) + return; + + TabStripModel* attached_model = attached_tabstrip_->model(); + int pinned_count = attached_model->IndexOfFirstNonPinnedTab(); + if (pinned_count > 0) + return; + + int index = attached_model->GetIndexOfTabContents(dragged_contents_); + if (index != 0) + return; + + gfx::Point local_point = + ConvertScreenPointToTabStripPoint(attached_tabstrip_, screen_point); + if (local_point.x() > kHorizontalPinTabOffset) + return; + + pin_timer_.Start( + base::TimeDelta::FromMilliseconds(kPinTabDelay), this, + &DraggedTabControllerGtk::MakeDraggedTabPinned); +} + void DraggedTabControllerGtk::AdjustDragPointForPinnedTabs( const gfx::Point& screen_point, int from_index, @@ -311,16 +368,7 @@ void DraggedTabControllerGtk::AdjustDragPointForPinnedTabs( if (local_point.x() <= pinned_threshold) { // The mouse was moved below the threshold that triggers the tab to be // pinned. - - // Mark the tab as pinned and update the model. - dragged_tab_->set_pinned(true); - attached_model->SetTabPinned(from_index, true); - - // Resize the dragged tab. - mouse_offset_.set_x(TabGtk::GetPinnedWidth() / 2 - 1); - InitWindowCreatePoint(); - dragged_tab_->set_mouse_tab_offset(mouse_offset_); - dragged_tab_->Resize(TabGtk::GetPinnedWidth()); + MakeDraggedTabPinned(from_index); // The dragged tab point was calculated using the old mouse_offset, which // we just reset. Recalculate it. @@ -632,6 +680,7 @@ bool DraggedTabControllerGtk::EndDragImpl(EndDragType type) { if (!dragged_tab_.get()) return true; + pin_timer_.Stop(); bring_to_front_timer_.Stop(); // WARNING: this may be invoked multiple times. In particular, if deletion diff --git a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h index 3d06a6f..704fe35 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h +++ b/chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h @@ -108,6 +108,17 @@ class DraggedTabControllerGtk : public NotificationObserver, // Handles moving the Tab within a TabStrip as well as updating the View. void MoveTab(const gfx::Point& screen_point); + // Cover for MakeDraggedTabPinned(0). This is invoked from the pin_timer_. + void MakeDraggedTabPinned(); + + // Changes the dragged tab from a normal tab to pinned, updating the + // necessary state. + void MakeDraggedTabPinned(int tab_index); + + // If |screen_point| is along the edge of the tab strip and there are no + // pinned tabs in the model, pin_timer_ is started. + void StartPinTimerIfNecessary(const gfx::Point& screen_point); + // Invoked from |MoveTab| to adjust |dragged_tab_point|. |screen_point| is // the location of the mouse and |from_index| the index the dragged tab is // at. @@ -269,6 +280,12 @@ class DraggedTabControllerGtk : public NotificationObserver, // brought to front. base::OneShotTimer<DraggedTabControllerGtk> bring_to_front_timer_; + // Timer used to pin the first tab. When the user drags a tab to the first + // tab in the tab strip this timer is started. If the user doesn't move the + // mouse, the tab is pinned. This timer invokes MakeDraggedTabPinned when it + // fires. + base::OneShotTimer<DraggedTabControllerGtk> pin_timer_; + DISALLOW_COPY_AND_ASSIGN(DraggedTabControllerGtk); }; |