| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void SetMoveBehavior(MoveBehavior behavior); | 101 void SetMoveBehavior(MoveBehavior behavior); |
| 102 | 102 |
| 103 // See description above fields for details on these. | 103 // See description above fields for details on these. |
| 104 bool active() const { return active_; } | 104 bool active() const { return active_; } |
| 105 const TabStrip* attached_tabstrip() const { return attached_tabstrip_; } | 105 const TabStrip* attached_tabstrip() const { return attached_tabstrip_; } |
| 106 | 106 |
| 107 // Returns true if a drag started. | 107 // Returns true if a drag started. |
| 108 bool started_drag() const { return started_drag_; } | 108 bool started_drag() const { return started_drag_; } |
| 109 | 109 |
| 110 // Invoked to drag to the new location, in screen coordinates. | 110 // Invoked to drag to the new location, in screen coordinates. |
| 111 void Drag(const gfx::Point& screen_point); | 111 void Drag(const gfx::Point& point_in_screen); |
| 112 | 112 |
| 113 // Complete the current drag session. If the drag session was canceled | 113 // Complete the current drag session. If the drag session was canceled |
| 114 // because the user pressed escape or something interrupted it, |canceled| | 114 // because the user pressed escape or something interrupted it, |canceled| |
| 115 // is true and the drag is reverted. | 115 // is true and the drag is reverted. |
| 116 void EndDrag(bool canceled); | 116 void EndDrag(bool canceled); |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 class DockDisplayer; | 119 class DockDisplayer; |
| 120 friend class DockDisplayer; | 120 friend class DockDisplayer; |
| 121 | 121 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 virtual void TabStripEmpty() OVERRIDE; | 234 virtual void TabStripEmpty() OVERRIDE; |
| 235 | 235 |
| 236 // Initialize the offset used to calculate the position to create windows | 236 // Initialize the offset used to calculate the position to create windows |
| 237 // in |GetWindowCreatePoint|. This should only be invoked from |Init|. | 237 // in |GetWindowCreatePoint|. This should only be invoked from |Init|. |
| 238 void InitWindowCreatePoint(); | 238 void InitWindowCreatePoint(); |
| 239 | 239 |
| 240 // Returns the point where a detached window should be created given the | 240 // Returns the point where a detached window should be created given the |
| 241 // current mouse position |origin|. | 241 // current mouse position |origin|. |
| 242 gfx::Point GetWindowCreatePoint(const gfx::Point& origin) const; | 242 gfx::Point GetWindowCreatePoint(const gfx::Point& origin) const; |
| 243 | 243 |
| 244 void UpdateDockInfo(const gfx::Point& screen_point); | 244 void UpdateDockInfo(const gfx::Point& point_in_screen); |
| 245 | 245 |
| 246 // Saves focus in the window that the drag initiated from. Focus will be | 246 // Saves focus in the window that the drag initiated from. Focus will be |
| 247 // restored appropriately if the drag ends within this same window. | 247 // restored appropriately if the drag ends within this same window. |
| 248 void SaveFocus(); | 248 void SaveFocus(); |
| 249 | 249 |
| 250 // Restore focus to the View that had focus before the drag was started, if | 250 // Restore focus to the View that had focus before the drag was started, if |
| 251 // the drag ends within the same Window as it began. | 251 // the drag ends within the same Window as it began. |
| 252 void RestoreFocus(); | 252 void RestoreFocus(); |
| 253 | 253 |
| 254 // Tests whether |screen_point| is past a minimum elasticity threshold | 254 // Tests whether |point_in_screen| is past a minimum elasticity threshold |
| 255 // required to start a drag. | 255 // required to start a drag. |
| 256 bool CanStartDrag(const gfx::Point& screen_point) const; | 256 bool CanStartDrag(const gfx::Point& point_in_screen) const; |
| 257 | 257 |
| 258 // Move the DraggedTabView according to the current mouse screen position, | 258 // Move the DraggedTabView according to the current mouse screen position, |
| 259 // potentially updating the source and other TabStrips. | 259 // potentially updating the source and other TabStrips. |
| 260 void ContinueDragging(const gfx::Point& screen_point); | 260 void ContinueDragging(const gfx::Point& point_in_screen); |
| 261 | 261 |
| 262 // Transitions dragging from |attached_tabstrip_| to |target_tabstrip|. | 262 // Transitions dragging from |attached_tabstrip_| to |target_tabstrip|. |
| 263 // |target_tabstrip| is NULL if the mouse is not over a valid tab strip. See | 263 // |target_tabstrip| is NULL if the mouse is not over a valid tab strip. See |
| 264 // DragBrowserResultType for details of the return type. | 264 // DragBrowserResultType for details of the return type. |
| 265 DragBrowserResultType DragBrowserToNewTabStrip( | 265 DragBrowserResultType DragBrowserToNewTabStrip( |
| 266 TabStrip* target_tabstrip, | 266 TabStrip* target_tabstrip, |
| 267 const gfx::Point& screen_point); | 267 const gfx::Point& point_in_screen); |
| 268 | 268 |
| 269 // Handles dragging for a touch tabstrip when the tabs are stacked. Doesn't | 269 // Handles dragging for a touch tabstrip when the tabs are stacked. Doesn't |
| 270 // actually reorder the tabs in anyway, just changes what's visible. | 270 // actually reorder the tabs in anyway, just changes what's visible. |
| 271 void DragActiveTabStacked(const gfx::Point& screen_point); | 271 void DragActiveTabStacked(const gfx::Point& point_in_screen); |
| 272 | 272 |
| 273 // Moves the active tab to the next/previous tab. Used when the next/previous | 273 // Moves the active tab to the next/previous tab. Used when the next/previous |
| 274 // tab is stacked. | 274 // tab is stacked. |
| 275 void MoveAttachedToNextStackedIndex(const gfx::Point& screen_point); | 275 void MoveAttachedToNextStackedIndex(const gfx::Point& point_in_screen); |
| 276 void MoveAttachedToPreviousStackedIndex(const gfx::Point& screen_point); | 276 void MoveAttachedToPreviousStackedIndex(const gfx::Point& point_in_screen); |
| 277 | 277 |
| 278 // Handles dragging tabs while the tabs are attached. | 278 // Handles dragging tabs while the tabs are attached. |
| 279 void MoveAttached(const gfx::Point& screen_point); | 279 void MoveAttached(const gfx::Point& point_in_screen); |
| 280 | 280 |
| 281 // Handles dragging while the tabs are detached. | 281 // Handles dragging while the tabs are detached. |
| 282 void MoveDetached(const gfx::Point& screen_point); | 282 void MoveDetached(const gfx::Point& point_in_screen); |
| 283 | 283 |
| 284 // If necessary starts the |move_stacked_timer_|. The timer is started if | 284 // If necessary starts the |move_stacked_timer_|. The timer is started if |
| 285 // close enough to an edge with stacked tabs. | 285 // close enough to an edge with stacked tabs. |
| 286 void StartMoveStackedTimerIfNecessary( | 286 void StartMoveStackedTimerIfNecessary( |
| 287 const gfx::Point& screen_point, | 287 const gfx::Point& point_in_screen, |
| 288 int delay_ms); | 288 int delay_ms); |
| 289 | 289 |
| 290 // Returns the TabStrip for the specified window, or NULL if one doesn't exist | 290 // Returns the TabStrip for the specified window, or NULL if one doesn't exist |
| 291 // or isn't compatible. | 291 // or isn't compatible. |
| 292 TabStrip* GetTabStripForWindow(gfx::NativeWindow window); | 292 TabStrip* GetTabStripForWindow(gfx::NativeWindow window); |
| 293 | 293 |
| 294 // Returns the compatible TabStrip that is under the specified point (screen | 294 // Returns the compatible TabStrip that is under the specified point (screen |
| 295 // coordinates), or NULL if there is none. | 295 // coordinates), or NULL if there is none. |
| 296 TabStrip* GetTabStripForPoint(const gfx::Point& screen_point); | 296 TabStrip* GetTabStripForPoint(const gfx::Point& point_in_screen); |
| 297 | 297 |
| 298 // Returns true if |tabstrip| contains the specified point in screen | 298 // Returns true if |tabstrip| contains the specified point in screen |
| 299 // coordinates. | 299 // coordinates. |
| 300 bool DoesTabStripContain(TabStrip* tabstrip, | 300 bool DoesTabStripContain(TabStrip* tabstrip, |
| 301 const gfx::Point& screen_point) const; | 301 const gfx::Point& point_in_screen) const; |
| 302 | 302 |
| 303 // Returns the DetachPosition given the specified location in screen | 303 // Returns the DetachPosition given the specified location in screen |
| 304 // coordinates. | 304 // coordinates. |
| 305 DetachPosition GetDetachPosition(const gfx::Point& screen_point); | 305 DetachPosition GetDetachPosition(const gfx::Point& point_in_screen); |
| 306 | 306 |
| 307 DockInfo GetDockInfoAtPoint(const gfx::Point& screen_point); | 307 DockInfo GetDockInfoAtPoint(const gfx::Point& point_in_screen); |
| 308 | 308 |
| 309 // Attach the dragged Tab to the specified TabStrip. | 309 // Attach the dragged Tab to the specified TabStrip. |
| 310 void Attach(TabStrip* attached_tabstrip, const gfx::Point& screen_point); | 310 void Attach(TabStrip* attached_tabstrip, const gfx::Point& point_in_screen); |
| 311 | 311 |
| 312 // Detach the dragged Tab from the current TabStrip. | 312 // Detach the dragged Tab from the current TabStrip. |
| 313 void Detach(ReleaseCapture release_capture); | 313 void Detach(ReleaseCapture release_capture); |
| 314 | 314 |
| 315 // Detaches the tabs being dragged, creates a new Browser to contain them and | 315 // Detaches the tabs being dragged, creates a new Browser to contain them and |
| 316 // runs a nested move loop. | 316 // runs a nested move loop. |
| 317 void DetachIntoNewBrowserAndRunMoveLoop(const gfx::Point& screen_point); | 317 void DetachIntoNewBrowserAndRunMoveLoop(const gfx::Point& point_in_screen); |
| 318 | 318 |
| 319 // Runs a nested message loop that handles moving the current Browser. | 319 // Runs a nested message loop that handles moving the current Browser. |
| 320 void RunMoveLoop(); | 320 void RunMoveLoop(); |
| 321 | 321 |
| 322 // Determines the index to insert tabs at. |dragged_bounds| is the bounds of | 322 // Determines the index to insert tabs at. |dragged_bounds| is the bounds of |
| 323 // the tabs being dragged, |start| the index of the tab to start looking from | 323 // the tabs being dragged, |start| the index of the tab to start looking from |
| 324 // and |delta| the amount to increment (1 or -1). | 324 // and |delta| the amount to increment (1 or -1). |
| 325 int GetInsertionIndexFrom(const gfx::Rect& dragged_bounds, | 325 int GetInsertionIndexFrom(const gfx::Rect& dragged_bounds, |
| 326 int start, | 326 int start, |
| 327 int delta) const; | 327 int delta) const; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 347 int GetInsertionIndexForDraggedBoundsStacked( | 347 int GetInsertionIndexForDraggedBoundsStacked( |
| 348 const gfx::Rect& dragged_bounds) const; | 348 const gfx::Rect& dragged_bounds) const; |
| 349 | 349 |
| 350 // Retrieve the bounds of the DraggedTabView relative to the attached | 350 // Retrieve the bounds of the DraggedTabView relative to the attached |
| 351 // TabStrip. |tab_strip_point| is in the attached TabStrip's coordinate | 351 // TabStrip. |tab_strip_point| is in the attached TabStrip's coordinate |
| 352 // system. | 352 // system. |
| 353 gfx::Rect GetDraggedViewTabStripBounds(const gfx::Point& tab_strip_point); | 353 gfx::Rect GetDraggedViewTabStripBounds(const gfx::Point& tab_strip_point); |
| 354 | 354 |
| 355 // Get the position of the dragged tab view relative to the attached tab | 355 // Get the position of the dragged tab view relative to the attached tab |
| 356 // strip with the mirroring transform applied. | 356 // strip with the mirroring transform applied. |
| 357 gfx::Point GetAttachedDragPoint(const gfx::Point& screen_point); | 357 gfx::Point GetAttachedDragPoint(const gfx::Point& point_in_screen); |
| 358 | 358 |
| 359 // Finds the Tabs within the specified TabStrip that corresponds to the | 359 // Finds the Tabs within the specified TabStrip that corresponds to the |
| 360 // WebContents of the dragged tabs. Returns an empty vector if not attached. | 360 // WebContents of the dragged tabs. Returns an empty vector if not attached. |
| 361 std::vector<BaseTab*> GetTabsMatchingDraggedContents(TabStrip* tabstrip); | 361 std::vector<BaseTab*> GetTabsMatchingDraggedContents(TabStrip* tabstrip); |
| 362 | 362 |
| 363 // Returns the bounds for the tabs based on the attached tab strip. The | 363 // Returns the bounds for the tabs based on the attached tab strip. The |
| 364 // x-coordinate of each tab is offset by |x_offset|. | 364 // x-coordinate of each tab is offset by |x_offset|. |
| 365 std::vector<gfx::Rect> CalculateBoundsForDraggedTabs(int x_offset); | 365 std::vector<gfx::Rect> CalculateBoundsForDraggedTabs(int x_offset); |
| 366 | 366 |
| 367 // Does the work for EndDrag. If we actually started a drag and |how_end| is | 367 // Does the work for EndDrag. If we actually started a drag and |how_end| is |
| (...skipping 26 matching lines...) Expand all Loading... |
| 394 | 394 |
| 395 // Hides the frame for the window that contains the TabStrip the current | 395 // Hides the frame for the window that contains the TabStrip the current |
| 396 // drag session was initiated from. | 396 // drag session was initiated from. |
| 397 void HideFrame(); | 397 void HideFrame(); |
| 398 | 398 |
| 399 // Closes a hidden frame at the end of a drag session. | 399 // Closes a hidden frame at the end of a drag session. |
| 400 void CleanUpHiddenFrame(); | 400 void CleanUpHiddenFrame(); |
| 401 | 401 |
| 402 void DockDisplayerDestroyed(DockDisplayer* controller); | 402 void DockDisplayerDestroyed(DockDisplayer* controller); |
| 403 | 403 |
| 404 void BringWindowUnderPointToFront(const gfx::Point& screen_point); | 404 void BringWindowUnderPointToFront(const gfx::Point& point_in_screen); |
| 405 | 405 |
| 406 // Convenience for getting the TabDragData corresponding to the tab the user | 406 // Convenience for getting the TabDragData corresponding to the tab the user |
| 407 // started dragging. | 407 // started dragging. |
| 408 TabDragData* source_tab_drag_data() { | 408 TabDragData* source_tab_drag_data() { |
| 409 return &(drag_data_[source_tab_index_]); | 409 return &(drag_data_[source_tab_index_]); |
| 410 } | 410 } |
| 411 | 411 |
| 412 // Convenience for |source_tab_drag_data()->contents|. | 412 // Convenience for |source_tab_drag_data()->contents|. |
| 413 TabContents* source_dragged_contents() { | 413 TabContents* source_dragged_contents() { |
| 414 return source_tab_drag_data()->contents; | 414 return source_tab_drag_data()->contents; |
| 415 } | 415 } |
| 416 | 416 |
| 417 // Returns the Widget of the currently attached TabStrip's BrowserView. | 417 // Returns the Widget of the currently attached TabStrip's BrowserView. |
| 418 views::Widget* GetAttachedBrowserWidget(); | 418 views::Widget* GetAttachedBrowserWidget(); |
| 419 | 419 |
| 420 // Returns true if the tabs were originality one after the other in | 420 // Returns true if the tabs were originality one after the other in |
| 421 // |source_tabstrip_|. | 421 // |source_tabstrip_|. |
| 422 bool AreTabsConsecutive(); | 422 bool AreTabsConsecutive(); |
| 423 | 423 |
| 424 // Creates and returns a new Browser to handle the drag. | 424 // Creates and returns a new Browser to handle the drag. |
| 425 Browser* CreateBrowserForDrag(TabStrip* source, | 425 Browser* CreateBrowserForDrag(TabStrip* source, |
| 426 const gfx::Point& screen_point, | 426 const gfx::Point& point_in_screen, |
| 427 std::vector<gfx::Rect>* drag_bounds); | 427 std::vector<gfx::Rect>* drag_bounds); |
| 428 | 428 |
| 429 // Returns the TabStripModel for the specified tabstrip. | 429 // Returns the TabStripModel for the specified tabstrip. |
| 430 TabStripModel* GetModel(TabStrip* tabstrip) const; | 430 TabStripModel* GetModel(TabStrip* tabstrip) const; |
| 431 | 431 |
| 432 // Returns the location of the cursor. This is either the location of the | 432 // Returns the location of the cursor. This is either the location of the |
| 433 // mouse or the location of the current touch point. | 433 // mouse or the location of the current touch point. |
| 434 gfx::Point GetCursorScreenPoint(); | 434 gfx::Point GetCursorScreenPoint(); |
| 435 | 435 |
| 436 // Returns true if moving the mouse only changes the visible tabs. | 436 // Returns true if moving the mouse only changes the visible tabs. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 450 // The TabStrip the dragged Tab is currently attached to, or NULL if the | 450 // The TabStrip the dragged Tab is currently attached to, or NULL if the |
| 451 // dragged Tab is detached. | 451 // dragged Tab is detached. |
| 452 TabStrip* attached_tabstrip_; | 452 TabStrip* attached_tabstrip_; |
| 453 | 453 |
| 454 // The visual representation of the dragged Tab. | 454 // The visual representation of the dragged Tab. |
| 455 scoped_ptr<DraggedTabView> view_; | 455 scoped_ptr<DraggedTabView> view_; |
| 456 | 456 |
| 457 // The position of the mouse (in screen coordinates) at the start of the drag | 457 // The position of the mouse (in screen coordinates) at the start of the drag |
| 458 // operation. This is used to calculate minimum elasticity before a | 458 // operation. This is used to calculate minimum elasticity before a |
| 459 // DraggedTabView is constructed. | 459 // DraggedTabView is constructed. |
| 460 gfx::Point start_screen_point_; | 460 gfx::Point start_point_in_screen_; |
| 461 | 461 |
| 462 // This is the offset of the mouse from the top left of the Tab where | 462 // This is the offset of the mouse from the top left of the Tab where |
| 463 // dragging begun. This is used to ensure that the dragged view is always | 463 // dragging begun. This is used to ensure that the dragged view is always |
| 464 // positioned at the correct location during the drag, and to ensure that the | 464 // positioned at the correct location during the drag, and to ensure that the |
| 465 // detached window is created at the right location. | 465 // detached window is created at the right location. |
| 466 gfx::Point mouse_offset_; | 466 gfx::Point mouse_offset_; |
| 467 | 467 |
| 468 // Offset of the mouse relative to the source tab. | 468 // Offset of the mouse relative to the source tab. |
| 469 int source_tab_offset_; | 469 int source_tab_offset_; |
| 470 | 470 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 std::vector<int> initial_tab_positions_; | 539 std::vector<int> initial_tab_positions_; |
| 540 | 540 |
| 541 DetachBehavior detach_behavior_; | 541 DetachBehavior detach_behavior_; |
| 542 MoveBehavior move_behavior_; | 542 MoveBehavior move_behavior_; |
| 543 | 543 |
| 544 // Updated as the mouse is moved when attached. Indicates whether the mouse | 544 // Updated as the mouse is moved when attached. Indicates whether the mouse |
| 545 // has ever moved to the left or right. If the tabs are ever detached this | 545 // has ever moved to the left or right. If the tabs are ever detached this |
| 546 // is set to kMovedMouseRight | kMovedMouseLeft. | 546 // is set to kMovedMouseRight | kMovedMouseLeft. |
| 547 int mouse_move_direction_; | 547 int mouse_move_direction_; |
| 548 | 548 |
| 549 // Last location used. | 549 // Last location used in screen coordinates. |
| 550 gfx::Point last_screen_point_; | 550 gfx::Point last_point_in_screen_; |
| 551 | 551 |
| 552 // The following are needed when detaching into a browser | 552 // The following are needed when detaching into a browser |
| 553 // (|detach_into_browser_| is true). | 553 // (|detach_into_browser_| is true). |
| 554 | 554 |
| 555 // Set to true if we've detached from a tabstrip and are running a nested | 555 // Set to true if we've detached from a tabstrip and are running a nested |
| 556 // move message loop. | 556 // move message loop. |
| 557 bool is_dragging_window_; | 557 bool is_dragging_window_; |
| 558 | 558 |
| 559 EndRunLoopBehavior end_run_loop_behavior_; | 559 EndRunLoopBehavior end_run_loop_behavior_; |
| 560 | 560 |
| 561 // If true, we're waiting for a move loop to complete. | 561 // If true, we're waiting for a move loop to complete. |
| 562 bool waiting_for_run_loop_to_exit_; | 562 bool waiting_for_run_loop_to_exit_; |
| 563 | 563 |
| 564 // The TabStrip to attach to after the move loop completes. | 564 // The TabStrip to attach to after the move loop completes. |
| 565 TabStrip* tab_strip_to_attach_to_after_exit_; | 565 TabStrip* tab_strip_to_attach_to_after_exit_; |
| 566 | 566 |
| 567 // Non-null for the duration of RunMoveLoop. | 567 // Non-null for the duration of RunMoveLoop. |
| 568 views::Widget* move_loop_widget_; | 568 views::Widget* move_loop_widget_; |
| 569 | 569 |
| 570 // If non-null set to true from destructor. | 570 // If non-null set to true from destructor. |
| 571 bool* destroyed_; | 571 bool* destroyed_; |
| 572 | 572 |
| 573 DISALLOW_COPY_AND_ASSIGN(TabDragController); | 573 DISALLOW_COPY_AND_ASSIGN(TabDragController); |
| 574 }; | 574 }; |
| 575 | 575 |
| 576 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ | 576 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ |
| OLD | NEW |