OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ |
6 #define CHROME_BROWSER_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ | 6 #define CHROME_BROWSER_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ |
7 | 7 |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/dock_info.h" | 10 #include "chrome/browser/dock_info.h" |
11 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 11 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
12 #include "chrome/common/notification_registrar.h" | 12 #include "chrome/common/notification_registrar.h" |
13 #include "gfx/rect.h" | 13 #include "gfx/rect.h" |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 class View; | 16 class View; |
17 } | 17 } |
| 18 class BaseTabRenderer; |
18 class BaseTabStrip; | 19 class BaseTabStrip; |
19 class DraggedTabView; | 20 class DraggedTabView; |
20 class NativeViewPhotobooth; | 21 class NativeViewPhotobooth; |
21 class Tab; | |
22 class TabStrip; | |
23 class TabStripModel; | 22 class TabStripModel; |
24 | 23 |
25 struct TabRendererData; | 24 struct TabRendererData; |
26 | 25 |
27 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
28 // | 27 // |
29 // DraggedTabController | 28 // DraggedTabController |
30 // | 29 // |
31 // An object that handles a drag session for an individual Tab within a | 30 // An object that handles a drag session for an individual Tab within a |
32 // TabStrip. This object is created whenever the mouse is pressed down on a | 31 // TabStrip. This object is created whenever the mouse is pressed down on a |
33 // Tab and destroyed when the mouse is released or the drag operation is | 32 // Tab and destroyed when the mouse is released or the drag operation is |
34 // aborted. The Tab that the user dragged (the "source tab") owns this object | 33 // aborted. The Tab that the user dragged (the "source tab") owns this object |
35 // and must be the only one to destroy it (via |DestroyDragController|). | 34 // and must be the only one to destroy it (via |DestroyDragController|). |
36 // | 35 // |
37 /////////////////////////////////////////////////////////////////////////////// | 36 /////////////////////////////////////////////////////////////////////////////// |
38 class DraggedTabController : public TabContentsDelegate, | 37 class DraggedTabController : public TabContentsDelegate, |
39 public NotificationObserver, | 38 public NotificationObserver, |
40 public MessageLoopForUI::Observer { | 39 public MessageLoopForUI::Observer { |
41 public: | 40 public: |
42 DraggedTabController(Tab* source_tab, TabStrip* source_tabstrip); | 41 DraggedTabController(BaseTabRenderer* source_tab, |
| 42 BaseTabStrip* source_tabstrip); |
43 virtual ~DraggedTabController(); | 43 virtual ~DraggedTabController(); |
44 | 44 |
45 // Capture information needed to be used during a drag session for this | 45 // Capture information needed to be used during a drag session for this |
46 // controller's associated source Tab and TabStrip. |mouse_offset| is the | 46 // controller's associated source tab and BaseTabStrip. |mouse_offset| is the |
47 // distance of the mouse pointer from the Tab's origin. | 47 // distance of the mouse pointer from the tab's origin. |
48 void CaptureDragInfo(Tab* tab, const gfx::Point& mouse_offset); | 48 void CaptureDragInfo(views::View* tab, const gfx::Point& mouse_offset); |
49 | 49 |
50 // Responds to drag events subsequent to StartDrag. If the mouse moves a | 50 // Responds to drag events subsequent to StartDrag. If the mouse moves a |
51 // sufficient distance before the mouse is released, a drag session is | 51 // sufficient distance before the mouse is released, a drag session is |
52 // initiated. | 52 // initiated. |
53 void Drag(); | 53 void Drag(); |
54 | 54 |
55 // Complete the current drag session. If the drag session was canceled | 55 // Complete the current drag session. If the drag session was canceled |
56 // because the user pressed Escape or something interrupted it, |canceled| | 56 // because the user pressed Escape or something interrupted it, |canceled| |
57 // is true so the helper can revert the state to the world before the drag | 57 // is true so the helper can revert the state to the world before the drag |
58 // begun. | 58 // begun. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // threshold required to start a drag. | 146 // threshold required to start a drag. |
147 bool CanStartDrag() const; | 147 bool CanStartDrag() const; |
148 | 148 |
149 // Move the DraggedTabView according to the current mouse screen position, | 149 // Move the DraggedTabView according to the current mouse screen position, |
150 // potentially updating the source and other TabStrips. | 150 // potentially updating the source and other TabStrips. |
151 void ContinueDragging(); | 151 void ContinueDragging(); |
152 | 152 |
153 // Handles dragging a tab while the tab is attached. | 153 // Handles dragging a tab while the tab is attached. |
154 void MoveAttachedTab(const gfx::Point& screen_point); | 154 void MoveAttachedTab(const gfx::Point& screen_point); |
155 | 155 |
| 156 // Adjusts the model as necessary for a move when the attached tab strip is |
| 157 // horizontal. |
| 158 void MoveAttachedTabHorizontalTabStrip(const gfx::Point& screen_point, |
| 159 TabStripModel* model, |
| 160 const gfx::Point& dragged_view_point, |
| 161 int from_index); |
| 162 |
| 163 // Adjusts the model as necessary for a move when the attached tab strip is |
| 164 // vertical. |
| 165 void MoveAttachedTabVerticalTabStrip(const gfx::Point& screen_point, |
| 166 TabStripModel* model, |
| 167 const gfx::Point& dragged_view_point, |
| 168 int from_index); |
| 169 |
156 // Handles dragging while the tab is detached. | 170 // Handles dragging while the tab is detached. |
157 void MoveDetachedTab(const gfx::Point& screen_point); | 171 void MoveDetachedTab(const gfx::Point& screen_point); |
158 | 172 |
159 // Returns the compatible TabStrip that is under the specified point (screen | 173 // Returns the compatible TabStrip that is under the specified point (screen |
160 // coordinates), or NULL if there is none. | 174 // coordinates), or NULL if there is none. |
161 TabStrip* GetTabStripForPoint(const gfx::Point& screen_point); | 175 BaseTabStrip* GetTabStripForPoint(const gfx::Point& screen_point); |
162 | 176 |
163 DockInfo GetDockInfoAtPoint(const gfx::Point& screen_point); | 177 DockInfo GetDockInfoAtPoint(const gfx::Point& screen_point); |
164 | 178 |
165 // Returns the specified |tabstrip| if it contains the specified point | 179 // Returns the specified |tabstrip| if it contains the specified point |
166 // (screen coordinates), NULL if it does not. | 180 // (screen coordinates), NULL if it does not. |
167 TabStrip* GetTabStripIfItContains(TabStrip* tabstrip, | 181 BaseTabStrip* GetTabStripIfItContains(BaseTabStrip* tabstrip, |
168 const gfx::Point& screen_point) const; | 182 const gfx::Point& screen_point) const; |
169 | 183 |
170 // Attach the dragged Tab to the specified TabStrip. | 184 // Attach the dragged Tab to the specified TabStrip. |
171 void Attach(TabStrip* attached_tabstrip, const gfx::Point& screen_point); | 185 void Attach(BaseTabStrip* attached_tabstrip, const gfx::Point& screen_point); |
172 | 186 |
173 // Detach the dragged Tab from the current TabStrip. | 187 // Detach the dragged Tab from the current TabStrip. |
174 void Detach(); | 188 void Detach(); |
175 | 189 |
176 // Returns the index where the dragged TabContents should be inserted into | 190 // Returns the index where the dragged TabContents should be inserted into |
177 // the attached TabStripModel given the DraggedTabView's bounds | 191 // the attached TabStripModel given the DraggedTabView's bounds |
178 // |dragged_bounds| in coordinates relative to the attached TabStrip. | 192 // |dragged_bounds| in coordinates relative to the attached TabStrip. |
179 // |is_tab_attached| is true if the tab has already been added. | 193 // |is_tab_attached| is true if the tab has already been added. |
180 int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds, | 194 int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds, |
181 bool is_tab_attached) const; | 195 bool is_tab_attached) const; |
182 | 196 |
183 // Retrieve the bounds of the DraggedTabView, relative to the attached | 197 // Retrieve the bounds of the DraggedTabView, relative to the attached |
184 // TabStrip, given location of the dragged tab in screen coordinates. | 198 // TabStrip, given location of the dragged tab in screen coordinates. |
185 gfx::Rect GetDraggedViewTabStripBounds(const gfx::Point& screen_point); | 199 gfx::Rect GetDraggedViewTabStripBounds(const gfx::Point& screen_point); |
186 | 200 |
187 // Get the position of the dragged tab view relative to the attached tab | 201 // Get the position of the dragged tab view relative to the attached tab |
188 // strip. | 202 // strip. |
189 gfx::Point GetAttachedTabDragPoint(const gfx::Point& screen_point); | 203 gfx::Point GetAttachedTabDragPoint(const gfx::Point& screen_point); |
190 | 204 |
191 // Finds the Tab within the specified TabStrip that corresponds to the | 205 // Finds the Tab within the specified TabStrip that corresponds to the |
192 // dragged TabContents. | 206 // dragged TabContents. |
193 Tab* GetTabMatchingDraggedContents(TabStrip* tabstrip) const; | 207 BaseTabRenderer* GetTabMatchingDraggedContents(BaseTabStrip* tabstrip) const; |
194 | 208 |
195 // Does the work for EndDrag. If we actually started a drag and |how_end| is | 209 // Does the work for EndDrag. If we actually started a drag and |how_end| is |
196 // not TAB_DESTROYED then one of EndDrag or RevertDrag is invoked. | 210 // not TAB_DESTROYED then one of EndDrag or RevertDrag is invoked. |
197 void EndDragImpl(EndDragType how_end); | 211 void EndDragImpl(EndDragType how_end); |
198 | 212 |
199 // Reverts a cancelled drag operation. | 213 // Reverts a cancelled drag operation. |
200 void RevertDrag(); | 214 void RevertDrag(); |
201 | 215 |
202 // Finishes a succesful drag operation. | 216 // Finishes a succesful drag operation. |
203 void CompleteDrag(); | 217 void CompleteDrag(); |
(...skipping 30 matching lines...) Expand all Loading... |
234 | 248 |
235 // The TabContents being dragged. | 249 // The TabContents being dragged. |
236 TabContents* dragged_contents_; | 250 TabContents* dragged_contents_; |
237 | 251 |
238 // The original TabContentsDelegate of |dragged_contents_|, before it was | 252 // The original TabContentsDelegate of |dragged_contents_|, before it was |
239 // detached from the browser window. We store this so that we can forward | 253 // detached from the browser window. We store this so that we can forward |
240 // certain delegate notifications back to it if we can't handle them locally. | 254 // certain delegate notifications back to it if we can't handle them locally. |
241 TabContentsDelegate* original_delegate_; | 255 TabContentsDelegate* original_delegate_; |
242 | 256 |
243 // The TabStrip |source_tab_| originated from. | 257 // The TabStrip |source_tab_| originated from. |
244 TabStrip* source_tabstrip_; | 258 BaseTabStrip* source_tabstrip_; |
245 | 259 |
246 // This is the index of the |source_tab_| in |source_tabstrip_| when the drag | 260 // This is the index of the |source_tab_| in |source_tabstrip_| when the drag |
247 // began. This is used to restore the previous state if the drag is aborted. | 261 // began. This is used to restore the previous state if the drag is aborted. |
248 int source_model_index_; | 262 int source_model_index_; |
249 | 263 |
250 // The TabStrip the dragged Tab is currently attached to, or NULL if the | 264 // The TabStrip the dragged Tab is currently attached to, or NULL if the |
251 // dragged Tab is detached. | 265 // dragged Tab is detached. |
252 TabStrip* attached_tabstrip_; | 266 BaseTabStrip* attached_tabstrip_; |
253 | 267 |
254 // If attached this is the tab we're dragging. | 268 // If attached this is the tab we're dragging. |
255 Tab* attached_tab_; | 269 BaseTabRenderer* attached_tab_; |
256 | 270 |
257 // The visual representation of the dragged Tab. | 271 // The visual representation of the dragged Tab. |
258 scoped_ptr<DraggedTabView> view_; | 272 scoped_ptr<DraggedTabView> view_; |
259 | 273 |
260 // The photo-booth the TabContents sits in when the Tab is detached, to | 274 // The photo-booth the TabContents sits in when the Tab is detached, to |
261 // obtain screen shots. | 275 // obtain screen shots. |
262 scoped_ptr<NativeViewPhotobooth> photobooth_; | 276 scoped_ptr<NativeViewPhotobooth> photobooth_; |
263 | 277 |
264 // The position of the mouse (in screen coordinates) at the start of the drag | 278 // The position of the mouse (in screen coordinates) at the start of the drag |
265 // operation. This is used to calculate minimum elasticity before a | 279 // operation. This is used to calculate minimum elasticity before a |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 // brought to front. | 334 // brought to front. |
321 base::OneShotTimer<DraggedTabController> bring_to_front_timer_; | 335 base::OneShotTimer<DraggedTabController> bring_to_front_timer_; |
322 | 336 |
323 // Did the mouse move enough that we started a drag? | 337 // Did the mouse move enough that we started a drag? |
324 bool started_drag_; | 338 bool started_drag_; |
325 | 339 |
326 DISALLOW_COPY_AND_ASSIGN(DraggedTabController); | 340 DISALLOW_COPY_AND_ASSIGN(DraggedTabController); |
327 }; | 341 }; |
328 | 342 |
329 #endif // CHROME_BROWSER_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ | 343 #endif // CHROME_BROWSER_VIEWS_TABS_DRAGGED_TAB_CONTROLLER_H_ |
OLD | NEW |