| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 
| 6 #define CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 6 #define CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 
| 7 #pragma once | 7 #pragma once | 
| 8 | 8 | 
| 9 #include <gtk/gtk.h> | 9 #include "chrome/browser/ui/gtk/tabs/dragged_tab_controller_gtk.h" | 
| 10 | 10 // TODO(msw): remove this file once all includes have been updated. | 
| 11 #include <set> |  | 
| 12 |  | 
| 13 #include "app/x11_util.h" |  | 
| 14 #include "base/scoped_ptr.h" |  | 
| 15 #include "base/timer.h" |  | 
| 16 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |  | 
| 17 #include "chrome/browser/ui/tabs/dock_info.h" |  | 
| 18 #include "chrome/common/notification_observer.h" |  | 
| 19 #include "chrome/common/notification_registrar.h" |  | 
| 20 |  | 
| 21 class DraggedTabGtk; |  | 
| 22 class TabGtk; |  | 
| 23 class TabStripGtk; |  | 
| 24 class TabContentsWrapper; |  | 
| 25 |  | 
| 26 class DraggedTabControllerGtk : public NotificationObserver, |  | 
| 27                                 public TabContentsDelegate { |  | 
| 28  public: |  | 
| 29   DraggedTabControllerGtk(TabGtk* source_tab, TabStripGtk* source_tabstrip); |  | 
| 30   virtual ~DraggedTabControllerGtk(); |  | 
| 31 |  | 
| 32   // Capture information needed to be used during a drag session for this |  | 
| 33   // controller's associated source Tab and TabStrip. |mouse_offset| is the |  | 
| 34   // distance of the mouse pointer from the Tab's origin. |  | 
| 35   void CaptureDragInfo(const gfx::Point& mouse_offset); |  | 
| 36 |  | 
| 37   // Responds to drag events subsequent to StartDrag. If the mouse moves a |  | 
| 38   // sufficient distance before the mouse is released, a drag session is |  | 
| 39   // initiated. |  | 
| 40   void Drag(); |  | 
| 41 |  | 
| 42   // Complete the current drag session. If the drag session was canceled |  | 
| 43   // because the user pressed Escape or something interrupted it, |canceled| |  | 
| 44   // is true so the helper can revert the state to the world before the drag |  | 
| 45   // begun. Returns whether the tab has been destroyed. |  | 
| 46   bool EndDrag(bool canceled); |  | 
| 47 |  | 
| 48   // Retrieve the source tab if the TabContents specified matches the one being |  | 
| 49   // dragged by this controller, or NULL if the specified TabContents is not |  | 
| 50   // the same as the one being dragged. |  | 
| 51   TabGtk* GetDragSourceTabForContents(TabContents* contents) const; |  | 
| 52 |  | 
| 53   // Returns true if the specified tab matches the tab being dragged. |  | 
| 54   bool IsDragSourceTab(const TabGtk* tab) const; |  | 
| 55 |  | 
| 56   // Returns true if the specified tab is detached. |  | 
| 57   bool IsTabDetached(const TabGtk* tab) const; |  | 
| 58 |  | 
| 59  private: |  | 
| 60   // Enumeration of the ways a drag session can end. |  | 
| 61   enum EndDragType { |  | 
| 62     // Drag session exited normally: the user released the mouse. |  | 
| 63     NORMAL, |  | 
| 64 |  | 
| 65     // The drag session was canceled (alt-tab during drag, escape ...) |  | 
| 66     CANCELED, |  | 
| 67 |  | 
| 68     // The tab (NavigationController) was destroyed during the drag. |  | 
| 69     TAB_DESTROYED |  | 
| 70   }; |  | 
| 71 |  | 
| 72   // Overridden from TabContentsDelegate: |  | 
| 73   virtual void OpenURLFromTab(TabContents* source, |  | 
| 74                               const GURL& url, |  | 
| 75                               const GURL& referrer, |  | 
| 76                               WindowOpenDisposition disposition, |  | 
| 77                               PageTransition::Type transition); |  | 
| 78   virtual void NavigationStateChanged(const TabContents* source, |  | 
| 79                                       unsigned changed_flags); |  | 
| 80   virtual void AddNewContents(TabContents* source, |  | 
| 81                               TabContents* new_contents, |  | 
| 82                               WindowOpenDisposition disposition, |  | 
| 83                               const gfx::Rect& initial_pos, |  | 
| 84                               bool user_gesture); |  | 
| 85   virtual void ActivateContents(TabContents* contents); |  | 
| 86   virtual void DeactivateContents(TabContents* contents); |  | 
| 87   virtual void LoadingStateChanged(TabContents* source); |  | 
| 88   virtual void CloseContents(TabContents* source); |  | 
| 89   virtual void MoveContents(TabContents* source, const gfx::Rect& pos); |  | 
| 90   virtual bool IsPopup(TabContents* source); |  | 
| 91   virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); |  | 
| 92   virtual void URLStarredChanged(TabContents* source, bool starred); |  | 
| 93   virtual void UpdateTargetURL(TabContents* source, const GURL& url); |  | 
| 94 |  | 
| 95   // Overridden from NotificationObserver: |  | 
| 96   virtual void Observe(NotificationType type, |  | 
| 97                        const NotificationSource& source, |  | 
| 98                        const NotificationDetails& details); |  | 
| 99 |  | 
| 100   // Initialize the offset used to calculate the position to create windows |  | 
| 101   // in |GetWindowCreatePoint|. |  | 
| 102   void InitWindowCreatePoint(); |  | 
| 103 |  | 
| 104   // Returns the point where a detached window should be created given the |  | 
| 105   // current mouse position. |  | 
| 106   gfx::Point GetWindowCreatePoint() const; |  | 
| 107 |  | 
| 108   // Sets the TabContents being dragged with the specified |new_contents|. |  | 
| 109   void SetDraggedContents(TabContentsWrapper* new_contents); |  | 
| 110 |  | 
| 111   // Move the DraggedTabView according to the current mouse screen position, |  | 
| 112   // potentially updating the source and other TabStrips. |  | 
| 113   void ContinueDragging(); |  | 
| 114 |  | 
| 115   // Handles moving the Tab within a TabStrip as well as updating the View. |  | 
| 116   void MoveTab(const gfx::Point& screen_point); |  | 
| 117 |  | 
| 118   // Returns the compatible TabStrip that is under the specified point (screen |  | 
| 119   // coordinates), or NULL if there is none. |  | 
| 120   TabStripGtk* GetTabStripForPoint(const gfx::Point& screen_point); |  | 
| 121 |  | 
| 122   // Returns the specified |tabstrip| if it contains the specified point |  | 
| 123   // (screen coordinates), NULL if it does not. |  | 
| 124   TabStripGtk* GetTabStripIfItContains(TabStripGtk* tabstrip, |  | 
| 125                                        const gfx::Point& screen_point) const; |  | 
| 126 |  | 
| 127   // Attach the dragged Tab to the specified TabStrip. |  | 
| 128   void Attach(TabStripGtk* attached_tabstrip, const gfx::Point& screen_point); |  | 
| 129 |  | 
| 130   // Detach the dragged Tab from the current TabStrip. |  | 
| 131   void Detach(); |  | 
| 132 |  | 
| 133   // Converts a screen point to a point relative to the tab strip. |  | 
| 134   gfx::Point ConvertScreenPointToTabStripPoint(TabStripGtk* tabstrip, |  | 
| 135                                                const gfx::Point& screen_point); |  | 
| 136 |  | 
| 137   // Retrieve the bounds of the DraggedTabGtk, relative to the attached |  | 
| 138   // TabStrip, given location of the dragged tab in screen coordinates. |  | 
| 139   gfx::Rect GetDraggedTabTabStripBounds(const gfx::Point& screen_point); |  | 
| 140 |  | 
| 141   // Returns the index where the dragged TabContents should be inserted into |  | 
| 142   // the attached TabStripModel given the DraggedTabView's bounds |  | 
| 143   // |dragged_bounds| in coordinates relative to the attached TabStrip. |  | 
| 144   // |is_tab_attached| is true if the tab has already been added. |  | 
| 145   int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds, |  | 
| 146                                         bool is_tab_attached) const; |  | 
| 147 |  | 
| 148   // Get the position of the dragged tab relative to the attached tab strip. |  | 
| 149   gfx::Point GetDraggedTabPoint(const gfx::Point& screen_point); |  | 
| 150 |  | 
| 151   // Finds the Tab within the specified TabStrip that corresponds to the |  | 
| 152   // dragged TabContents. |  | 
| 153   TabGtk* GetTabMatchingDraggedContents(TabStripGtk* tabstrip) const; |  | 
| 154 |  | 
| 155   // Does the work for EndDrag. Returns whether the tab has been destroyed. |  | 
| 156   bool EndDragImpl(EndDragType how_end); |  | 
| 157 |  | 
| 158   // If the drag was aborted for some reason, this function is called to un-do |  | 
| 159   // the changes made during the drag operation. |  | 
| 160   void RevertDrag(); |  | 
| 161 |  | 
| 162   // Finishes the drag operation. Returns true if the drag controller should |  | 
| 163   // be destroyed immediately, false otherwise. |  | 
| 164   bool CompleteDrag(); |  | 
| 165 |  | 
| 166   // Create the DraggedTabGtk if it does not yet exist. |  | 
| 167   void EnsureDraggedTab(); |  | 
| 168 |  | 
| 169   // Utility for getting the mouse position in screen coordinates. |  | 
| 170   gfx::Point GetCursorScreenPoint() const; |  | 
| 171 |  | 
| 172   // Gets the screen bounds of a tab. |  | 
| 173   static gfx::Rect GetTabScreenBounds(TabGtk* tab); |  | 
| 174 |  | 
| 175   // Utility to convert the specified TabStripModel index to something valid |  | 
| 176   // for the attached TabStrip. |  | 
| 177   int NormalizeIndexToAttachedTabStrip(int index) const; |  | 
| 178 |  | 
| 179   // Hides the window that contains the tab strip the current drag session was |  | 
| 180   // initiated from. |  | 
| 181   void HideWindow(); |  | 
| 182 |  | 
| 183   // Presents the window that was hidden by HideWindow. |  | 
| 184   void ShowWindow(); |  | 
| 185 |  | 
| 186   // Closes a hidden frame at the end of a drag session. |  | 
| 187   void CleanUpHiddenFrame(); |  | 
| 188 |  | 
| 189   // Cleans up a source tab that is no longer used. |  | 
| 190   void CleanUpSourceTab(); |  | 
| 191 |  | 
| 192   // Completes the drag session after the view has animated to its final |  | 
| 193   // position. |  | 
| 194   void OnAnimateToBoundsComplete(); |  | 
| 195 |  | 
| 196   // Activates whichever window is under the mouse. |  | 
| 197   void BringWindowUnderMouseToFront(); |  | 
| 198 |  | 
| 199   // Handles registering for notifications. |  | 
| 200   NotificationRegistrar registrar_; |  | 
| 201 |  | 
| 202   // The TabContents being dragged. |  | 
| 203   TabContentsWrapper* dragged_contents_; |  | 
| 204 |  | 
| 205   // The original TabContentsDelegate of |dragged_contents_|, before it was |  | 
| 206   // detached from the browser window. We store this so that we can forward |  | 
| 207   // certain delegate notifications back to it if we can't handle them locally. |  | 
| 208   TabContentsDelegate* original_delegate_; |  | 
| 209 |  | 
| 210   // The tab that initiated the drag session. |  | 
| 211   TabGtk* source_tab_; |  | 
| 212 |  | 
| 213   // The tab strip |source_tab_| originated from. |  | 
| 214   TabStripGtk* source_tabstrip_; |  | 
| 215 |  | 
| 216   // This is the index of the |source_tab_| in |source_tabstrip_| when the drag |  | 
| 217   // began. This is used to restore the previous state if the drag is aborted. |  | 
| 218   int source_model_index_; |  | 
| 219 |  | 
| 220   // The TabStrip the dragged Tab is currently attached to, or NULL if the |  | 
| 221   // dragged Tab is detached. |  | 
| 222   TabStripGtk* attached_tabstrip_; |  | 
| 223 |  | 
| 224   // The visual representation of the dragged Tab. |  | 
| 225   scoped_ptr<DraggedTabGtk> dragged_tab_; |  | 
| 226 |  | 
| 227   // The position of the mouse (in screen coordinates) at the start of the drag |  | 
| 228   // operation. This is used to calculate minimum elasticity before a |  | 
| 229   // DraggedTabView is constructed. |  | 
| 230   gfx::Point start_screen_point_; |  | 
| 231 |  | 
| 232   // This is the offset of the mouse from the top left of the Tab where |  | 
| 233   // dragging begun. This is used to ensure that the dragged view is always |  | 
| 234   // positioned at the correct location during the drag, and to ensure that the |  | 
| 235   // detached window is created at the right location. |  | 
| 236   gfx::Point mouse_offset_; |  | 
| 237 |  | 
| 238   // A hint to use when positioning new windows created by detaching Tabs. This |  | 
| 239   // is the distance of the mouse from the top left of the dragged tab as if it |  | 
| 240   // were the distance of the mouse from the top left of the first tab in the |  | 
| 241   // attached TabStrip from the top left of the window. |  | 
| 242   gfx::Point window_create_point_; |  | 
| 243 |  | 
| 244   // Whether we're in the destructor or not.  Makes sure we don't destroy the |  | 
| 245   // drag controller more than once. |  | 
| 246   bool in_destructor_; |  | 
| 247 |  | 
| 248   // The horizontal position of the mouse cursor in screen coordinates at the |  | 
| 249   // time of the last re-order event. |  | 
| 250   int last_move_screen_x_; |  | 
| 251 |  | 
| 252   // DockInfo for the tabstrip. |  | 
| 253   DockInfo dock_info_; |  | 
| 254 |  | 
| 255   typedef std::set<GtkWidget*> DockWindows; |  | 
| 256   DockWindows dock_windows_; |  | 
| 257 |  | 
| 258   // Is the tab mini? |  | 
| 259   const bool mini_; |  | 
| 260 |  | 
| 261   // Is the tab pinned? |  | 
| 262   const bool pinned_; |  | 
| 263 |  | 
| 264   // Timer used to bring the window under the cursor to front. If the user |  | 
| 265   // stops moving the mouse for a brief time over a browser window, it is |  | 
| 266   // brought to front. |  | 
| 267   base::OneShotTimer<DraggedTabControllerGtk> bring_to_front_timer_; |  | 
| 268 |  | 
| 269   DISALLOW_COPY_AND_ASSIGN(DraggedTabControllerGtk); |  | 
| 270 }; |  | 
| 271 | 11 | 
| 272 #endif  // CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 12 #endif  // CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ | 
| OLD | NEW | 
|---|