| 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/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" | 13 #include "chrome/browser/ui/host_desktop.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 15 #include "chrome/browser/ui/views/tabs/tab_strip_types.h" | 15 #include "chrome/browser/ui/views/tabs/tab_strip_types.h" |
| 16 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/web_contents_delegate.h" | |
| 19 #include "ui/base/models/list_selection_model.h" | 18 #include "ui/base/models/list_selection_model.h" |
| 20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 21 #include "ui/views/widget/widget_observer.h" | 20 #include "ui/views/widget/widget_observer.h" |
| 22 | 21 |
| 23 namespace gfx { | 22 namespace gfx { |
| 24 class Screen; | 23 class Screen; |
| 25 } | 24 } |
| 26 namespace ui { | 25 namespace ui { |
| 27 class EventHandler; | 26 class EventHandler; |
| 28 class ListSelectionModel; | 27 class ListSelectionModel; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 // the user presses the mouse on a tab a new TabDragController is created and | 39 // the user presses the mouse on a tab a new TabDragController is created and |
| 41 // Drag() is invoked as the mouse is dragged. If the mouse is dragged far enough | 40 // Drag() is invoked as the mouse is dragged. If the mouse is dragged far enough |
| 42 // TabDragController starts a drag session. The drag session is completed when | 41 // TabDragController starts a drag session. The drag session is completed when |
| 43 // EndDrag() is invoked (or the TabDragController is destroyed). | 42 // EndDrag() is invoked (or the TabDragController is destroyed). |
| 44 // | 43 // |
| 45 // While dragging within a tab strip TabDragController sets the bounds of the | 44 // While dragging within a tab strip TabDragController sets the bounds of the |
| 46 // tabs (this is referred to as attached). When the user drags far enough such | 45 // tabs (this is referred to as attached). When the user drags far enough such |
| 47 // that the tabs should be moved out of the tab strip a new Browser is created | 46 // that the tabs should be moved out of the tab strip a new Browser is created |
| 48 // and RunMoveLoop() is invoked on the Widget to drag the browser around. This | 47 // and RunMoveLoop() is invoked on the Widget to drag the browser around. This |
| 49 // is the default on aura. | 48 // is the default on aura. |
| 50 class TabDragController : public content::WebContentsDelegate, | 49 class TabDragController : public content::NotificationObserver, |
| 51 public content::NotificationObserver, | |
| 52 public views::WidgetObserver, | 50 public views::WidgetObserver, |
| 53 public TabStripModelObserver { | 51 public TabStripModelObserver { |
| 54 public: | 52 public: |
| 55 enum DetachBehavior { | |
| 56 DETACHABLE, | |
| 57 NOT_DETACHABLE | |
| 58 }; | |
| 59 | |
| 60 // What should happen as the mouse is dragged within the tabstrip. | 53 // What should happen as the mouse is dragged within the tabstrip. |
| 61 enum MoveBehavior { | 54 enum MoveBehavior { |
| 62 // Only the set of visible tabs should change. This is only applicable when | 55 // Only the set of visible tabs should change. This is only applicable when |
| 63 // using touch layout. | 56 // using touch layout. |
| 64 MOVE_VISIBILE_TABS, | 57 MOVE_VISIBILE_TABS, |
| 65 | 58 |
| 66 // Typical behavior where tabs are dragged around. | 59 // Typical behavior where tabs are dragged around. |
| 67 REORDER | 60 REORDER |
| 68 }; | 61 }; |
| 69 | 62 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 87 // offset from |source_tab|. |source_tab_offset| is the horizontal offset of | 80 // offset from |source_tab|. |source_tab_offset| is the horizontal offset of |
| 88 // |mouse_offset| relative to |source_tab|. |initial_selection_model| is the | 81 // |mouse_offset| relative to |source_tab|. |initial_selection_model| is the |
| 89 // selection model before the drag started and is only non-empty if | 82 // selection model before the drag started and is only non-empty if |
| 90 // |source_tab| was not initially selected. | 83 // |source_tab| was not initially selected. |
| 91 void Init(TabStrip* source_tabstrip, | 84 void Init(TabStrip* source_tabstrip, |
| 92 Tab* source_tab, | 85 Tab* source_tab, |
| 93 const std::vector<Tab*>& tabs, | 86 const std::vector<Tab*>& tabs, |
| 94 const gfx::Point& mouse_offset, | 87 const gfx::Point& mouse_offset, |
| 95 int source_tab_offset, | 88 int source_tab_offset, |
| 96 const ui::ListSelectionModel& initial_selection_model, | 89 const ui::ListSelectionModel& initial_selection_model, |
| 97 DetachBehavior detach_behavior, | |
| 98 MoveBehavior move_behavior, | 90 MoveBehavior move_behavior, |
| 99 EventSource event_source); | 91 EventSource event_source); |
| 100 | 92 |
| 101 // Returns true if there is a drag underway and the drag is attached to | 93 // Returns true if there is a drag underway and the drag is attached to |
| 102 // |tab_strip|. | 94 // |tab_strip|. |
| 103 // NOTE: this returns false if the TabDragController is in the process of | 95 // NOTE: this returns false if the TabDragController is in the process of |
| 104 // finishing the drag. | 96 // finishing the drag. |
| 105 static bool IsAttachedTo(const TabStrip* tab_strip); | 97 static bool IsAttachedTo(const TabStrip* tab_strip); |
| 106 | 98 |
| 107 // Returns true if there is a drag underway. | 99 // Returns true if there is a drag underway. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 }; | 176 }; |
| 185 | 177 |
| 186 // Stores the date associated with a single tab that is being dragged. | 178 // Stores the date associated with a single tab that is being dragged. |
| 187 struct TabDragData { | 179 struct TabDragData { |
| 188 TabDragData(); | 180 TabDragData(); |
| 189 ~TabDragData(); | 181 ~TabDragData(); |
| 190 | 182 |
| 191 // The WebContents being dragged. | 183 // The WebContents being dragged. |
| 192 content::WebContents* contents; | 184 content::WebContents* contents; |
| 193 | 185 |
| 194 // content::WebContentsDelegate for |contents| before it was detached from | |
| 195 // the browser window. We store this so that we can forward certain delegate | |
| 196 // notifications back to it if we can't handle them locally. | |
| 197 content::WebContentsDelegate* original_delegate; | |
| 198 | |
| 199 // This is the index of the tab in |source_tabstrip_| when the drag | 186 // This is the index of the tab in |source_tabstrip_| when the drag |
| 200 // began. This is used to restore the previous state if the drag is aborted. | 187 // began. This is used to restore the previous state if the drag is aborted. |
| 201 int source_model_index; | 188 int source_model_index; |
| 202 | 189 |
| 203 // If attached this is the tab in |attached_tabstrip_|. | 190 // If attached this is the tab in |attached_tabstrip_|. |
| 204 Tab* attached_tab; | 191 Tab* attached_tab; |
| 205 | 192 |
| 206 // Is the tab pinned? | 193 // Is the tab pinned? |
| 207 bool pinned; | 194 bool pinned; |
| 208 }; | 195 }; |
| 209 | 196 |
| 210 typedef std::vector<TabDragData> DragData; | 197 typedef std::vector<TabDragData> DragData; |
| 211 | 198 |
| 212 // Sets |drag_data| from |tab|. This also registers for necessary | 199 // Sets |drag_data| from |tab|. This also registers for necessary |
| 213 // notifications and resets the delegate of the WebContents. | 200 // notifications and resets the delegate of the WebContents. |
| 214 void InitTabDragData(Tab* tab, TabDragData* drag_data); | 201 void InitTabDragData(Tab* tab, TabDragData* drag_data); |
| 215 | 202 |
| 216 // Overridden from content::WebContentsDelegate: | |
| 217 virtual content::WebContents* OpenURLFromTab( | |
| 218 content::WebContents* source, | |
| 219 const content::OpenURLParams& params) OVERRIDE; | |
| 220 virtual void NavigationStateChanged(const content::WebContents* source, | |
| 221 unsigned changed_flags) OVERRIDE; | |
| 222 virtual void AddNewContents(content::WebContents* source, | |
| 223 content::WebContents* new_contents, | |
| 224 WindowOpenDisposition disposition, | |
| 225 const gfx::Rect& initial_pos, | |
| 226 bool user_gesture, | |
| 227 bool* was_blocked) OVERRIDE; | |
| 228 virtual bool ShouldSuppressDialogs() OVERRIDE; | |
| 229 virtual content::JavaScriptDialogManager* | |
| 230 GetJavaScriptDialogManager() OVERRIDE; | |
| 231 virtual void RequestMediaAccessPermission( | |
| 232 content::WebContents* web_contents, | |
| 233 const content::MediaStreamRequest& request, | |
| 234 const content::MediaResponseCallback& callback) OVERRIDE; | |
| 235 | |
| 236 // Overridden from content::NotificationObserver: | 203 // Overridden from content::NotificationObserver: |
| 237 virtual void Observe(int type, | 204 virtual void Observe(int type, |
| 238 const content::NotificationSource& source, | 205 const content::NotificationSource& source, |
| 239 const content::NotificationDetails& details) OVERRIDE; | 206 const content::NotificationDetails& details) OVERRIDE; |
| 240 | 207 |
| 241 // Overriden from views::WidgetObserver: | 208 // Overriden from views::WidgetObserver: |
| 242 virtual void OnWidgetBoundsChanged(views::Widget* widget, | 209 virtual void OnWidgetBoundsChanged(views::Widget* widget, |
| 243 const gfx::Rect& new_bounds) OVERRIDE; | 210 const gfx::Rect& new_bounds) OVERRIDE; |
| 244 | 211 |
| 245 // Overriden from TabStripModelObserver: | 212 // Overriden from TabStripModelObserver: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 360 |
| 394 // Restores |initial_selection_model_| to the |source_tabstrip_|. | 361 // Restores |initial_selection_model_| to the |source_tabstrip_|. |
| 395 void RestoreInitialSelection(); | 362 void RestoreInitialSelection(); |
| 396 | 363 |
| 397 // Finishes a succesful drag operation. | 364 // Finishes a succesful drag operation. |
| 398 void CompleteDrag(); | 365 void CompleteDrag(); |
| 399 | 366 |
| 400 // Maximizes the attached window. | 367 // Maximizes the attached window. |
| 401 void MaximizeAttachedWindow(); | 368 void MaximizeAttachedWindow(); |
| 402 | 369 |
| 403 // Resets the delegates of the WebContents. | |
| 404 void ResetDelegates(); | |
| 405 | |
| 406 // Returns the bounds (in screen coordinates) of the specified View. | 370 // Returns the bounds (in screen coordinates) of the specified View. |
| 407 gfx::Rect GetViewScreenBounds(views::View* tabstrip) const; | 371 gfx::Rect GetViewScreenBounds(views::View* tabstrip) const; |
| 408 | 372 |
| 409 // Hides the frame for the window that contains the TabStrip the current | 373 // Hides the frame for the window that contains the TabStrip the current |
| 410 // drag session was initiated from. | 374 // drag session was initiated from. |
| 411 void HideFrame(); | 375 void HideFrame(); |
| 412 | 376 |
| 413 // Closes a hidden frame at the end of a drag session. | |
| 414 void CleanUpHiddenFrame(); | |
| 415 | |
| 416 void BringWindowUnderPointToFront(const gfx::Point& point_in_screen); | 377 void BringWindowUnderPointToFront(const gfx::Point& point_in_screen); |
| 417 | 378 |
| 418 // Convenience for getting the TabDragData corresponding to the tab the user | 379 // Convenience for getting the TabDragData corresponding to the tab the user |
| 419 // started dragging. | 380 // started dragging. |
| 420 TabDragData* source_tab_drag_data() { | 381 TabDragData* source_tab_drag_data() { |
| 421 return &(drag_data_[source_tab_index_]); | 382 return &(drag_data_[source_tab_index_]); |
| 422 } | 383 } |
| 423 | 384 |
| 424 // Convenience for |source_tab_drag_data()->contents|. | 385 // Convenience for |source_tab_drag_data()->contents|. |
| 425 content::WebContents* source_dragged_contents() { | 386 content::WebContents* source_dragged_contents() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Returns true if moving the mouse only changes the visible tabs. | 433 // Returns true if moving the mouse only changes the visible tabs. |
| 473 bool move_only() const { | 434 bool move_only() const { |
| 474 return (move_behavior_ == MOVE_VISIBILE_TABS) != 0; | 435 return (move_behavior_ == MOVE_VISIBILE_TABS) != 0; |
| 475 } | 436 } |
| 476 | 437 |
| 477 // Returns the NativeWindow at the specified point. If |exclude_dragged_view| | 438 // Returns the NativeWindow at the specified point. If |exclude_dragged_view| |
| 478 // is true, then the dragged view is not considered. | 439 // is true, then the dragged view is not considered. |
| 479 gfx::NativeWindow GetLocalProcessWindow(const gfx::Point& screen_point, | 440 gfx::NativeWindow GetLocalProcessWindow(const gfx::Point& screen_point, |
| 480 bool exclude_dragged_view); | 441 bool exclude_dragged_view); |
| 481 | 442 |
| 482 // If true detaching creates a new browser and enters a nested message loop. | |
| 483 bool detach_into_browser_; | |
| 484 | |
| 485 // Handles registering for notifications. | 443 // Handles registering for notifications. |
| 486 content::NotificationRegistrar registrar_; | 444 content::NotificationRegistrar registrar_; |
| 487 | 445 |
| 488 EventSource event_source_; | 446 EventSource event_source_; |
| 489 | 447 |
| 490 // The TabStrip the drag originated from. | 448 // The TabStrip the drag originated from. |
| 491 TabStrip* source_tabstrip_; | 449 TabStrip* source_tabstrip_; |
| 492 | 450 |
| 493 // The TabStrip the dragged Tab is currently attached to, or NULL if the | 451 // The TabStrip the dragged Tab is currently attached to, or NULL if the |
| 494 // dragged Tab is detached. | 452 // dragged Tab is detached. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 525 // A hint to use when positioning new windows created by detaching Tabs. This | 483 // A hint to use when positioning new windows created by detaching Tabs. This |
| 526 // is the distance of the mouse from the top left of the dragged tab as if it | 484 // is the distance of the mouse from the top left of the dragged tab as if it |
| 527 // were the distance of the mouse from the top left of the first tab in the | 485 // were the distance of the mouse from the top left of the first tab in the |
| 528 // attached TabStrip from the top left of the window. | 486 // attached TabStrip from the top left of the window. |
| 529 gfx::Point window_create_point_; | 487 gfx::Point window_create_point_; |
| 530 | 488 |
| 531 // Location of the first tab in the source tabstrip in screen coordinates. | 489 // Location of the first tab in the source tabstrip in screen coordinates. |
| 532 // This is used to calculate |window_create_point_|. | 490 // This is used to calculate |window_create_point_|. |
| 533 gfx::Point first_source_tab_point_; | 491 gfx::Point first_source_tab_point_; |
| 534 | 492 |
| 535 // The bounds of the browser window before the last Tab was detached. When | |
| 536 // the last Tab is detached, rather than destroying the frame (which would | |
| 537 // abort the drag session), the frame is moved off-screen. If the drag is | |
| 538 // aborted (e.g. by the user pressing Esc, or capture being lost), the Tab is | |
| 539 // attached to the hidden frame and the frame moved back to these bounds. | |
| 540 gfx::Rect restore_bounds_; | |
| 541 | |
| 542 // Storage ID in ViewStorage where the last view that had focus in the window | 493 // Storage ID in ViewStorage where the last view that had focus in the window |
| 543 // containing |source_tab_| is saved. This is saved so that focus can be | 494 // containing |source_tab_| is saved. This is saved so that focus can be |
| 544 // restored properly when a drag begins and ends within this same window. | 495 // restored properly when a drag begins and ends within this same window. |
| 545 const int old_focused_view_id_; | 496 const int old_focused_view_id_; |
| 546 | 497 |
| 547 // The horizontal position of the mouse cursor in screen coordinates at the | 498 // The horizontal position of the mouse cursor in screen coordinates at the |
| 548 // time of the last re-order event. | 499 // time of the last re-order event. |
| 549 int last_move_screen_loc_; | 500 int last_move_screen_loc_; |
| 550 | 501 |
| 551 // Timer used to bring the window under the cursor to front. If the user | 502 // Timer used to bring the window under the cursor to front. If the user |
| (...skipping 23 matching lines...) Expand all Loading... |
| 575 // details. | 526 // details. |
| 576 ui::ListSelectionModel initial_selection_model_; | 527 ui::ListSelectionModel initial_selection_model_; |
| 577 | 528 |
| 578 // The selection model of |attached_tabstrip_| before the tabs were attached. | 529 // The selection model of |attached_tabstrip_| before the tabs were attached. |
| 579 ui::ListSelectionModel selection_model_before_attach_; | 530 ui::ListSelectionModel selection_model_before_attach_; |
| 580 | 531 |
| 581 // Initial x-coordinates of the tabs when the drag started. Only used for | 532 // Initial x-coordinates of the tabs when the drag started. Only used for |
| 582 // touch mode. | 533 // touch mode. |
| 583 std::vector<int> initial_tab_positions_; | 534 std::vector<int> initial_tab_positions_; |
| 584 | 535 |
| 585 DetachBehavior detach_behavior_; | |
| 586 MoveBehavior move_behavior_; | 536 MoveBehavior move_behavior_; |
| 587 | 537 |
| 588 // Updated as the mouse is moved when attached. Indicates whether the mouse | 538 // Updated as the mouse is moved when attached. Indicates whether the mouse |
| 589 // has ever moved to the left or right. If the tabs are ever detached this | 539 // has ever moved to the left or right. If the tabs are ever detached this |
| 590 // is set to kMovedMouseRight | kMovedMouseLeft. | 540 // is set to kMovedMouseRight | kMovedMouseLeft. |
| 591 int mouse_move_direction_; | 541 int mouse_move_direction_; |
| 592 | 542 |
| 593 // Last location used in screen coordinates. | 543 // Last location used in screen coordinates. |
| 594 gfx::Point last_point_in_screen_; | 544 gfx::Point last_point_in_screen_; |
| 595 | 545 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 int attach_index_; | 587 int attach_index_; |
| 638 | 588 |
| 639 scoped_ptr<ui::EventHandler> escape_tracker_; | 589 scoped_ptr<ui::EventHandler> escape_tracker_; |
| 640 | 590 |
| 641 base::WeakPtrFactory<TabDragController> weak_factory_; | 591 base::WeakPtrFactory<TabDragController> weak_factory_; |
| 642 | 592 |
| 643 DISALLOW_COPY_AND_ASSIGN(TabDragController); | 593 DISALLOW_COPY_AND_ASSIGN(TabDragController); |
| 644 }; | 594 }; |
| 645 | 595 |
| 646 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ | 596 #endif // CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_ |
| OLD | NEW |