Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: chrome/browser/gtk/tabs/dragged_tab_controller_gtk.h

Issue 113532: Implement DraggedTabGtk, the object that handles rendering either a dragged t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 7
8 #include <gtk/gtk.h>
9
10 #include "base/scoped_ptr.h"
8 #include "base/timer.h" 11 #include "base/timer.h"
9 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 12 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
10 #include "chrome/common/notification_registrar.h" 13 #include "chrome/common/notification_registrar.h"
11 14
15 class DraggedTabGtk;
12 class TabGtk; 16 class TabGtk;
13 class TabStripGtk; 17 class TabStripGtk;
14 18
15 class DraggedTabControllerGtk : public NotificationObserver, 19 class DraggedTabControllerGtk : public NotificationObserver,
16 public TabContentsDelegate { 20 public TabContentsDelegate {
17 public: 21 public:
18 DraggedTabControllerGtk(TabGtk* source_tab, TabStripGtk* source_tabstrip); 22 DraggedTabControllerGtk(TabGtk* source_tab, TabStripGtk* source_tabstrip);
19 virtual ~DraggedTabControllerGtk(); 23 virtual ~DraggedTabControllerGtk();
20 24
21 // Capture information needed to be used during a drag session for this 25 // Capture information needed to be used during a drag session for this
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 virtual bool IsPopup(TabContents* source); 71 virtual bool IsPopup(TabContents* source);
68 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating); 72 virtual void ToolbarSizeChanged(TabContents* source, bool is_animating);
69 virtual void URLStarredChanged(TabContents* source, bool starred); 73 virtual void URLStarredChanged(TabContents* source, bool starred);
70 virtual void UpdateTargetURL(TabContents* source, const GURL& url); 74 virtual void UpdateTargetURL(TabContents* source, const GURL& url);
71 75
72 // Overridden from NotificationObserver: 76 // Overridden from NotificationObserver:
73 virtual void Observe(NotificationType type, 77 virtual void Observe(NotificationType type,
74 const NotificationSource& source, 78 const NotificationSource& source,
75 const NotificationDetails& details); 79 const NotificationDetails& details);
76 80
81 // Initialize the offset used to calculate the position to create windows
82 // in |GetWindowCreatePoint|.
83 void InitWindowCreatePoint();
84
77 // Sets the TabContents being dragged with the specified |new_contents|. 85 // Sets the TabContents being dragged with the specified |new_contents|.
78 void SetDraggedContents(TabContents* new_contents); 86 void SetDraggedContents(TabContents* new_contents);
79 87
80 // Move the DraggedTabView according to the current mouse screen position, 88 // Move the DraggedTabView according to the current mouse screen position,
81 // potentially updating the source and other TabStrips. 89 // potentially updating the source and other TabStrips.
82 void ContinueDragging(); 90 void ContinueDragging();
83 91
84 // Handles moving the Tab within a TabStrip as well as updating the View. 92 // Handles moving the Tab within a TabStrip as well as updating the View.
85 void MoveTab(const gfx::Point& screen_point); 93 void MoveTab(const gfx::Point& screen_point);
86 94
87 // Returns the compatible TabStrip that is under the specified point (screen 95 // Returns the compatible TabStrip that is under the specified point (screen
88 // coordinates), or NULL if there is none. 96 // coordinates), or NULL if there is none.
89 TabStripGtk* GetTabStripForPoint(const gfx::Point& screen_point); 97 TabStripGtk* GetTabStripForPoint(const gfx::Point& screen_point);
90 98
99 // Attach the dragged Tab to the specified TabStrip.
100 void Attach(TabStripGtk* attached_tabstrip, const gfx::Point& screen_point);
101
102 // Detach the dragged Tab from the current TabStrip.
103 void Detach();
104
105 // Converts a screen point to a point relative to the tab strip.
106 gfx::Point ConvertScreenPointToTabStripPoint(TabStripGtk* tabstrip,
107 const gfx::Point& screen_point);
108
109 // Retrieve the bounds of the DraggedTabGtk, relative to the attached
110 // TabStrip, given location of the dragged tab in screen coordinates.
111 gfx::Rect GetDraggedTabTabStripBounds(const gfx::Point& screen_point);
112
91 // Returns the index where the dragged TabContents should be inserted into 113 // Returns the index where the dragged TabContents should be inserted into
92 // the attached TabStripModel given the DraggedTabView's bounds 114 // the attached TabStripModel given the DraggedTabView's bounds
93 // |dragged_bounds| in coordinates relative to the attached TabStrip. 115 // |dragged_bounds| in coordinates relative to the attached TabStrip.
94 int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds) const; 116 int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds) const;
95 117
96 // Get the position of the dragged tab relative to the attached tab strip. 118 // Get the position of the dragged tab relative to the attached tab strip.
97 gfx::Point GetDraggedPoint(const gfx::Point& point); 119 gfx::Point GetDraggedTabPoint(const gfx::Point& screen_point);
98 120
99 // Finds the Tab within the specified TabStrip that corresponds to the 121 // Finds the Tab within the specified TabStrip that corresponds to the
100 // dragged TabContents. 122 // dragged TabContents.
101 TabGtk* GetTabMatchingDraggedContents(TabStripGtk* tabstrip) const; 123 TabGtk* GetTabMatchingDraggedContents(TabStripGtk* tabstrip) const;
102 124
103 // Does the work for EndDrag. Returns whether the tab has been destroyed. 125 // Does the work for EndDrag. Returns whether the tab has been destroyed.
104 bool EndDragImpl(EndDragType how_end); 126 bool EndDragImpl(EndDragType how_end);
105 127
106 // If the drag was aborted for some reason, this function is called to un-do 128 // If the drag was aborted for some reason, this function is called to un-do
107 // the changes made during the drag operation. 129 // the changes made during the drag operation.
108 void RevertDrag(); 130 void RevertDrag();
109 131
110 // Finishes the drag operation. Returns true if the drag controller should 132 // Finishes the drag operation. Returns true if the drag controller should
111 // be destroyed immediately, false otherwise. 133 // be destroyed immediately, false otherwise.
112 bool CompleteDrag(); 134 bool CompleteDrag();
113 135
136 // Create the DraggedTabGtk if it does not yet exist.
137 void EnsureDraggedTab();
138
114 // Utility for getting the mouse position in screen coordinates. 139 // Utility for getting the mouse position in screen coordinates.
115 gfx::Point GetCursorScreenPoint() const; 140 gfx::Point GetCursorScreenPoint() const;
116 141
142 // Gets the screen bounds of a tab.
143 static gfx::Rect GetTabScreenBounds(TabGtk* tab);
144
117 // Utility to convert the specified TabStripModel index to something valid 145 // Utility to convert the specified TabStripModel index to something valid
118 // for the attached TabStrip. 146 // for the attached TabStrip.
119 int NormalizeIndexToAttachedTabStrip(int index) const; 147 int NormalizeIndexToAttachedTabStrip(int index) const;
120 148
149 // Completes the drag session after the view has animated to its final
150 // position.
151 void OnAnimateToBoundsComplete();
152
153 // Activates whichever window is under the mouse.
121 void BringWindowUnderMouseToFront(); 154 void BringWindowUnderMouseToFront();
122 155
123 // Handles registering for notifications. 156 // Handles registering for notifications.
124 NotificationRegistrar registrar_; 157 NotificationRegistrar registrar_;
125 158
126 // The TabContents being dragged. 159 // The TabContents being dragged.
127 TabContents* dragged_contents_; 160 TabContents* dragged_contents_;
128 161
129 // The original TabContentsDelegate of |dragged_contents_|, before it was 162 // The original TabContentsDelegate of |dragged_contents_|, before it was
130 // detached from the browser window. We store this so that we can forward 163 // detached from the browser window. We store this so that we can forward
131 // certain delegate notifications back to it if we can't handle them locally. 164 // certain delegate notifications back to it if we can't handle them locally.
132 TabContentsDelegate* original_delegate_; 165 TabContentsDelegate* original_delegate_;
133 166
134 // The tab that initiated the drag session. 167 // The tab that initiated the drag session.
135 TabGtk* source_tab_; 168 TabGtk* source_tab_;
136 169
137 // The tab strip |source_tab_| originated from. 170 // The tab strip |source_tab_| originated from.
138 TabStripGtk* source_tabstrip_; 171 TabStripGtk* source_tabstrip_;
139 172
140 // This is the index of the |source_tab_| in |source_tabstrip_| when the drag 173 // This is the index of the |source_tab_| in |source_tabstrip_| when the drag
141 // began. This is used to restore the previous state if the drag is aborted. 174 // began. This is used to restore the previous state if the drag is aborted.
142 int source_model_index_; 175 int source_model_index_;
143 176
144 // The TabStrip the dragged Tab is currently attached to, or NULL if the 177 // The TabStrip the dragged Tab is currently attached to, or NULL if the
145 // dragged Tab is detached. 178 // dragged Tab is detached.
146 TabStripGtk* attached_tabstrip_; 179 TabStripGtk* attached_tabstrip_;
147 180
181 // The visual representation of the dragged Tab.
182 scoped_ptr<DraggedTabGtk> dragged_tab_;
183
148 // The position of the mouse (in screen coordinates) at the start of the drag 184 // The position of the mouse (in screen coordinates) at the start of the drag
149 // operation. This is used to calculate minimum elasticity before a 185 // operation. This is used to calculate minimum elasticity before a
150 // DraggedTabView is constructed. 186 // DraggedTabView is constructed.
151 gfx::Point start_screen_point_; 187 gfx::Point start_screen_point_;
152 188
153 // This is the offset of the mouse from the top left of the Tab where 189 // This is the offset of the mouse from the top left of the Tab where
154 // dragging begun. This is used to ensure that the dragged view is always 190 // dragging begun. This is used to ensure that the dragged view is always
155 // positioned at the correct location during the drag, and to ensure that the 191 // positioned at the correct location during the drag, and to ensure that the
156 // detached window is created at the right location. 192 // detached window is created at the right location.
157 gfx::Point mouse_offset_; 193 gfx::Point mouse_offset_;
158 194
195 // A hint to use when positioning new windows created by detaching Tabs. This
196 // is the distance of the mouse from the top left of the dragged tab as if it
197 // were the distance of the mouse from the top left of the first tab in the
198 // attached TabStrip from the top left of the window.
199 gfx::Point window_create_point_;
200
201 // Whether we're in the destructor or not. Makes sure we don't destroy the
202 // drag controller more than once.
203 bool in_destructor_;
204
159 // The horizontal position of the mouse cursor in screen coordinates at the 205 // The horizontal position of the mouse cursor in screen coordinates at the
160 // time of the last re-order event. 206 // time of the last re-order event.
161 int last_move_screen_x_; 207 int last_move_screen_x_;
162 208
163 // The last good tab bounds of the dragged tab. This is the position the tab
164 // will be snapped back to when the drag is released.
165 // TODO(jhawkins): We should not be moving the tab itself, but rather a
166 // stand-in renderer.
167 gfx::Rect snap_bounds_;
168
169 // Timer used to bring the window under the cursor to front. If the user 209 // Timer used to bring the window under the cursor to front. If the user
170 // stops moving the mouse for a brief time over a browser window, it is 210 // stops moving the mouse for a brief time over a browser window, it is
171 // brought to front. 211 // brought to front.
172 base::OneShotTimer<DraggedTabControllerGtk> bring_to_front_timer_; 212 base::OneShotTimer<DraggedTabControllerGtk> bring_to_front_timer_;
173 213
174 DISALLOW_COPY_AND_ASSIGN(DraggedTabControllerGtk); 214 DISALLOW_COPY_AND_ASSIGN(DraggedTabControllerGtk);
175 }; 215 };
176 216
177 #endif // CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_ 217 #endif // CHROME_BROWSER_GTK_TABS_DRAGGED_TAB_CONTROLLER_GTK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/gtk/tabs/dragged_tab_controller_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698