tab_drag_controller.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_
6#define CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_
7
8#include <vector>
9
10#include "base/memory/scoped_ptr.h"
11#include "base/memory/weak_ptr.h"
12#include "base/message_loop/message_loop.h"
13#include "base/timer/timer.h"
14#include "chrome/browser/ui/tabs/dock_info.h"
15#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
16#include "chrome/browser/ui/views/tabs/tab_strip_types.h"
17#include "content/public/browser/notification_observer.h"
18#include "content/public/browser/notification_registrar.h"
19#include "content/public/browser/web_contents_delegate.h"
20#include "ui/base/models/list_selection_model.h"
21#include "ui/gfx/rect.h"
22#include "ui/views/widget/widget_observer.h"
23
24namespace gfx {
25class Screen;
26}
27namespace ui {
28class ListSelectionModel;
29}
30namespace views {
31class View;
32}
33class Browser;
34class DraggedTabView;
35class Tab;
36struct TabRendererData;
37class TabStrip;
38class TabStripModel;
39
40// TabDragController is responsible for managing the tab dragging session. When
41// the user presses the mouse on a tab a new TabDragController is created and
42// Drag() is invoked as the mouse is dragged. If the mouse is dragged far enough
43// TabDragController starts a drag session. The drag session is completed when
44// EndDrag() is invoked (or the TabDragController is destroyed).
45//
46// While dragging within a tab strip TabDragController sets the bounds of the
47// tabs (this is referred to as attached). When the user drags far enough such
48// that the tabs should be moved out of the tab strip two possible things
49// can happen (this state is referred to as detached):
50// . If |detach_into_browser_| is true then a new Browser is created and
51//   RunMoveLoop() is invoked on the Widget to drag the browser around. This is
52//   the default on aura.
53// . If |detach_into_browser_| is false a small representation of the active tab
54//   is created and that is dragged around. This mode does not run a nested
55//   message loop.
56class TabDragController : public content::WebContentsDelegate,
57                          public content::NotificationObserver,
58                          public base::MessageLoopForUI::Observer,
59                          public views::WidgetObserver,
60                          public TabStripModelObserver {
61 public:
62  enum DetachBehavior {
63    DETACHABLE,
64    NOT_DETACHABLE
65  };
66
67  // What should happen as the mouse is dragged within the tabstrip.
68  enum MoveBehavior {
69    // Only the set of visible tabs should change. This is only applicable when
70    // using touch layout.
71    MOVE_VISIBILE_TABS,
72
73    // Typical behavior where tabs are dragged around.
74    REORDER
75  };
76
77  // Indicates the event source that initiated the drag.
78  enum EventSource {
79    EVENT_SOURCE_MOUSE,
80    EVENT_SOURCE_TOUCH,
81  };
82
83  // Amount above or below the tabstrip the user has to drag before detaching.
84  static const int kTouchVerticalDetachMagnetism;
85  static const int kVerticalDetachMagnetism;
86
87  TabDragController();
88  virtual ~TabDragController();
89
90  // Initializes TabDragController to drag the tabs in |tabs| originating from
91  // |source_tabstrip|. |source_tab| is the tab that initiated the drag and is
92  // contained in |tabs|.  |mouse_offset| is the distance of the mouse pointer
93  // from the origin of the first tab in |tabs| and |source_tab_offset| the
94  // offset from |source_tab|. |source_tab_offset| is the horizontal offset of
95  // |mouse_offset| relative to |source_tab|. |initial_selection_model| is the
96  // selection model before the drag started and is only non-empty if
97  // |source_tab| was not initially selected.
98  void Init(TabStrip* source_tabstrip,
99            Tab* source_tab,
100            const std::vector<Tab*>& tabs,
101            const gfx::Point& mouse_offset,
102            int source_tab_offset,
103            const ui::ListSelectionModel& initial_selection_model,
104            DetachBehavior detach_behavior,
105            MoveBehavior move_behavior,
106            EventSource event_source);
107
108  // Returns true if there is a drag underway and the drag is attached to
109  // |tab_strip|.
110  // NOTE: this returns false if the TabDragController is in the process of
111  // finishing the drag.
112  static bool IsAttachedTo(const TabStrip* tab_strip);
113
114  // Returns true if there is a drag underway.
115  static bool IsActive();
116
117  // Used to determine whether the tab drag controller detaches dragged tabs
118  // into new browser windows while the drag is in process.
119  static bool ShouldDetachIntoNewBrowser();
120
121  // Sets the move behavior. Has no effect if started_drag() is true.
122  void SetMoveBehavior(MoveBehavior behavior);
123  MoveBehavior move_behavior() const { return move_behavior_; }
124
125  EventSource event_source() const { return event_source_; }
126
127  // See description above fields for details on these.
128  bool active() const { return active_; }
129  const TabStrip* attached_tabstrip() const { return attached_tabstrip_; }
130
131  // Returns true if a drag started.
132  bool started_drag() const { return started_drag_; }
133
134  // Returns true if mutating the TabStripModel.
135  bool is_mutating() const { return is_mutating_; }
136
137  // Returns true if we've detached from a tabstrip and are running a nested
138  // move message loop.
139  bool is_dragging_window() const { return is_dragging_window_; }
140
141  // Invoked to drag to the new location, in screen coordinates.
142  void Drag(const gfx::Point& point_in_screen);
143
144  // Complete the current drag session.
145  void EndDrag(EndDragReason reason);
146
147 private:
148  class DockDisplayer;
149  friend class DockDisplayer;
150
151  typedef std::set<gfx::NativeView> DockWindows;
152
153  // Used to indicate the direction the mouse has moved when attached.
154  static const int kMovedMouseLeft  = 1 << 0;
155  static const int kMovedMouseRight = 1 << 1;
156
157  // Enumeration of the ways a drag session can end.
158  enum EndDragType {
159    // Drag session exited normally: the user released the mouse.
160    NORMAL,
161
162    // The drag session was canceled (alt-tab during drag, escape ...)
163    CANCELED,
164
165    // The tab (NavigationController) was destroyed during the drag.
166    TAB_DESTROYED
167  };
168
169  // Whether Detach() should release capture or not.
170  enum ReleaseCapture {
171    RELEASE_CAPTURE,
172    DONT_RELEASE_CAPTURE,
173  };
174
175  // Specifies what should happen when RunMoveLoop completes.
176  enum EndRunLoopBehavior {
177    // Indicates the drag should end.
178    END_RUN_LOOP_STOP_DRAGGING,
179
180    // Indicates the drag should continue.
181    END_RUN_LOOP_CONTINUE_DRAGGING
182  };
183
184  // Enumeration of the possible positions the detached tab may detach from.
185  enum DetachPosition {
186    DETACH_BEFORE,
187    DETACH_AFTER,
188    DETACH_ABOVE_OR_BELOW
189  };
190
191  // Indicates what should happen after invoking DragBrowserToNewTabStrip().
192  enum DragBrowserResultType {
193    // The caller should return immediately. This return value is used if a
194    // nested message loop was created or we're in a nested message loop and
195    // need to exit it.
196    DRAG_BROWSER_RESULT_STOP,
197
198    // The caller should continue.
199    DRAG_BROWSER_RESULT_CONTINUE,
200  };
201
202  // Stores the date associated with a single tab that is being dragged.
203  struct TabDragData {
204    TabDragData();
205    ~TabDragData();
206
207    // The WebContents being dragged.
208    content::WebContents* contents;
209
210    // content::WebContentsDelegate for |contents| before it was detached from
211    // the browser window. We store this so that we can forward certain delegate
212    // notifications back to it if we can't handle them locally.
213    content::WebContentsDelegate* original_delegate;
214
215    // This is the index of the tab in |source_tabstrip_| when the drag
216    // began. This is used to restore the previous state if the drag is aborted.
217    int source_model_index;
218
219    // If attached this is the tab in |attached_tabstrip_|.
220    Tab* attached_tab;
221
222    // Is the tab pinned?
223    bool pinned;
224  };
225
226  typedef std::vector<TabDragData> DragData;
227
228  // Sets |drag_data| from |tab|. This also registers for necessary
229  // notifications and resets the delegate of the WebContents.
230  void InitTabDragData(Tab* tab, TabDragData* drag_data);
231
232  // Overridden from content::WebContentsDelegate:
233  virtual content::WebContents* OpenURLFromTab(
234      content::WebContents* source,
235      const content::OpenURLParams& params) OVERRIDE;
236  virtual void NavigationStateChanged(const content::WebContents* source,
237                                      unsigned changed_flags) OVERRIDE;
238  virtual void AddNewContents(content::WebContents* source,
239                              content::WebContents* new_contents,
240                              WindowOpenDisposition disposition,
241                              const gfx::Rect& initial_pos,
242                              bool user_gesture,
243                              bool* was_blocked) OVERRIDE;
244  virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE;
245  virtual bool ShouldSuppressDialogs() OVERRIDE;
246  virtual content::JavaScriptDialogManager*
247      GetJavaScriptDialogManager() OVERRIDE;
248  virtual void RequestMediaAccessPermission(
249      content::WebContents* web_contents,
250      const content::MediaStreamRequest& request,
251      const content::MediaResponseCallback& callback) OVERRIDE;
252
253  // Overridden from content::NotificationObserver:
254  virtual void Observe(int type,
255                       const content::NotificationSource& source,
256                       const content::NotificationDetails& details) OVERRIDE;
257
258  // Overridden from MessageLoop::Observer:
259  virtual base::EventStatus WillProcessEvent(
260      const base::NativeEvent& event) OVERRIDE;
261  virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE;
262
263  // Overriden from views::WidgetObserver:
264  virtual void OnWidgetBoundsChanged(views::Widget* widget,
265                                     const gfx::Rect& new_bounds) OVERRIDE;
266
267  // Overriden from TabStripModelObserver:
268  virtual void TabStripEmpty() OVERRIDE;
269
270  // Initialize the offset used to calculate the position to create windows
271  // in |GetWindowCreatePoint|. This should only be invoked from |Init|.
272  void InitWindowCreatePoint();
273
274  // Returns the point where a detached window should be created given the
275  // current mouse position |origin|.
276  gfx::Point GetWindowCreatePoint(const gfx::Point& origin) const;
277
278  void UpdateDockInfo(const gfx::Point& point_in_screen);
279
280  // Saves focus in the window that the drag initiated from. Focus will be
281  // restored appropriately if the drag ends within this same window.
282  void SaveFocus();
283
284  // Restore focus to the View that had focus before the drag was started, if
285  // the drag ends within the same Window as it began.
286  void RestoreFocus();
287
288  // Tests whether |point_in_screen| is past a minimum elasticity threshold
289  // required to start a drag.
290  bool CanStartDrag(const gfx::Point& point_in_screen) const;
291
292  // Move the DraggedTabView according to the current mouse screen position,
293  // potentially updating the source and other TabStrips.
294  void ContinueDragging(const gfx::Point& point_in_screen);
295
296  // Transitions dragging from |attached_tabstrip_| to |target_tabstrip|.
297  // |target_tabstrip| is NULL if the mouse is not over a valid tab strip.  See
298  // DragBrowserResultType for details of the return type.
299  DragBrowserResultType DragBrowserToNewTabStrip(
300      TabStrip* target_tabstrip,
301      const gfx::Point& point_in_screen);
302
303  // Handles dragging for a touch tabstrip when the tabs are stacked. Doesn't
304  // actually reorder the tabs in anyway, just changes what's visible.
305  void DragActiveTabStacked(const gfx::Point& point_in_screen);
306
307  // Moves the active tab to the next/previous tab. Used when the next/previous
308  // tab is stacked.
309  void MoveAttachedToNextStackedIndex(const gfx::Point& point_in_screen);
310  void MoveAttachedToPreviousStackedIndex(const gfx::Point& point_in_screen);
311
312  // Handles dragging tabs while the tabs are attached.
313  void MoveAttached(const gfx::Point& point_in_screen);
314
315  // Handles dragging while the tabs are detached.
316  void MoveDetached(const gfx::Point& point_in_screen);
317
318  // If necessary starts the |move_stacked_timer_|. The timer is started if
319  // close enough to an edge with stacked tabs.
320  void StartMoveStackedTimerIfNecessary(
321      const gfx::Point& point_in_screen,
322      int delay_ms);
323
324  // Returns the TabStrip for the specified window, or NULL if one doesn't exist
325  // or isn't compatible.
326  TabStrip* GetTabStripForWindow(gfx::NativeWindow window);
327
328  // Returns the compatible TabStrip to drag to at the specified point (screen
329  // coordinates), or NULL if there is none.
330  TabStrip* GetTargetTabStripForPoint(const gfx::Point& point_in_screen);
331
332  // Returns true if |tabstrip| contains the specified point in screen
333  // coordinates.
334  bool DoesTabStripContain(TabStrip* tabstrip,
335                           const gfx::Point& point_in_screen) const;
336
337  // Returns the DetachPosition given the specified location in screen
338  // coordinates.
339  DetachPosition GetDetachPosition(const gfx::Point& point_in_screen);
340
341  DockInfo GetDockInfoAtPoint(const gfx::Point& point_in_screen);
342
343  // Attach the dragged Tab to the specified TabStrip.
344  void Attach(TabStrip* attached_tabstrip, const gfx::Point& point_in_screen);
345
346  // Detach the dragged Tab from the current TabStrip.
347  void Detach(ReleaseCapture release_capture);
348
349  // Detaches the tabs being dragged, creates a new Browser to contain them and
350  // runs a nested move loop.
351  void DetachIntoNewBrowserAndRunMoveLoop(const gfx::Point& point_in_screen);
352
353  // Runs a nested message loop that handles moving the current
354  // Browser. |drag_offset| is the offset from the window origin and is used in
355  // calculating the location of the window offset from the cursor while
356  // dragging.
357  void RunMoveLoop(const gfx::Vector2d& drag_offset);
358
359  // Determines the index to insert tabs at. |dragged_bounds| is the bounds of
360  // the tabs being dragged, |start| the index of the tab to start looking from
361  // and |delta| the amount to increment (1 or -1).
362  int GetInsertionIndexFrom(const gfx::Rect& dragged_bounds,
363                            int start,
364                            int delta) const;
365
366  // Returns the index where the dragged WebContents should be inserted into
367  // |attached_tabstrip_| given the DraggedTabView's bounds |dragged_bounds| in
368  // coordinates relative to |attached_tabstrip_| and has had the mirroring
369  // transformation applied.
370  // NOTE: this is invoked from Attach() before the tabs have been inserted.
371  int GetInsertionIndexForDraggedBounds(const gfx::Rect& dragged_bounds) const;
372
373  // Returns true if |dragged_bounds| is close enough to the next stacked tab
374  // so that the active tab should be dragged there.
375  bool ShouldDragToNextStackedTab(const gfx::Rect& dragged_bounds,
376                                  int index) const;
377
378  // Returns true if |dragged_bounds| is close enough to the previous stacked
379  // tab so that the active tab should be dragged there.
380  bool ShouldDragToPreviousStackedTab(const gfx::Rect& dragged_bounds,
381                                      int index) const;
382
383  // Used by GetInsertionIndexForDraggedBounds() when the tabstrip is stacked.
384  int GetInsertionIndexForDraggedBoundsStacked(
385      const gfx::Rect& dragged_bounds) const;
386
387  // Retrieve the bounds of the DraggedTabView relative to the attached
388  // TabStrip. |tab_strip_point| is in the attached TabStrip's coordinate
389  // system.
390  gfx::Rect GetDraggedViewTabStripBounds(const gfx::Point& tab_strip_point);
391
392  // Get the position of the dragged tab view relative to the attached tab
393  // strip with the mirroring transform applied.
394  gfx::Point GetAttachedDragPoint(const gfx::Point& point_in_screen);
395
396  // Finds the Tabs within the specified TabStrip that corresponds to the
397  // WebContents of the dragged tabs. Returns an empty vector if not attached.
398  std::vector<Tab*> GetTabsMatchingDraggedContents(TabStrip* tabstrip);
399
400  // Returns the bounds for the tabs based on the attached tab strip.
401  std::vector<gfx::Rect> CalculateBoundsForDraggedTabs();
402
403  // Does the work for EndDrag(). If we actually started a drag and |how_end| is
404  // not TAB_DESTROYED then one of EndDrag() or RevertDrag() is invoked.
405  void EndDragImpl(EndDragType how_end);
406
407  // Reverts a cancelled drag operation.
408  void RevertDrag();
409
410  // Reverts the tab at |drag_index| in |drag_data_|.
411  void RevertDragAt(size_t drag_index);
412
413  // Selects the dragged tabs in |model|. Does nothing if there are no longer
414  // any dragged contents (as happens when a WebContents is deleted out from
415  // under us).
416  void ResetSelection(TabStripModel* model);
417
418  // Finishes a succesful drag operation.
419  void CompleteDrag();
420
421  // Resets the delegates of the WebContents.
422  void ResetDelegates();
423
424  // Create the DraggedTabView.
425  void CreateDraggedView(const std::vector<TabRendererData>& data,
426                         const std::vector<gfx::Rect>& renderer_bounds);
427
428  // Returns the bounds (in screen coordinates) of the specified View.
429  gfx::Rect GetViewScreenBounds(views::View* tabstrip) const;
430
431  // Hides the frame for the window that contains the TabStrip the current
432  // drag session was initiated from.
433  void HideFrame();
434
435  // Closes a hidden frame at the end of a drag session.
436  void CleanUpHiddenFrame();
437
438  void DockDisplayerDestroyed(DockDisplayer* controller);
439
440  void BringWindowUnderPointToFront(const gfx::Point& point_in_screen);
441
442  // Convenience for getting the TabDragData corresponding to the tab the user
443  // started dragging.
444  TabDragData* source_tab_drag_data() {
445    return &(drag_data_[source_tab_index_]);
446  }
447
448  // Convenience for |source_tab_drag_data()->contents|.
449  content::WebContents* source_dragged_contents() {
450    return source_tab_drag_data()->contents;
451  }
452
453  // Returns the Widget of the currently attached TabStrip's BrowserView.
454  views::Widget* GetAttachedBrowserWidget();
455
456  // Returns true if the tabs were originality one after the other in
457  // |source_tabstrip_|.
458  bool AreTabsConsecutive();
459
460  // Calculates and returns new bounds for the dragged browser window.
461  // Takes into consideration current and restore bounds of |source| tab strip
462  // preventing the dragged size from being too small. Positions the new bounds
463  // such that the tab that was dragged remains under the |point_in_screen|.
464  // Offsets |drag_bounds| if necessary when dragging to the right from the
465  // source browser.
466  gfx::Rect CalculateDraggedBrowserBounds(TabStrip* source,
467                                          const gfx::Point& point_in_screen,
468                                          std::vector<gfx::Rect>* drag_bounds);
469
470  // Calculates scaled |drag_bounds| for dragged tabs and sets the tabs bounds.
471  // Layout of the tabstrip is performed and a new tabstrip width calculated.
472  // When |last_tabstrip_width| is larger than the new tabstrip width the tabs
473  // in attached tabstrip are scaled and the attached browser is positioned such
474  // that the tab that was dragged remains under the |point_in_screen|.
475  void AdjustBrowserAndTabBoundsForDrag(int last_tabstrip_width,
476                                        const gfx::Point& point_in_screen,
477                                        std::vector<gfx::Rect>* drag_bounds);
478
479  // Creates and returns a new Browser to handle the drag.
480  Browser* CreateBrowserForDrag(TabStrip* source,
481                                const gfx::Point& point_in_screen,
482                                gfx::Vector2d* drag_offset,
483                                std::vector<gfx::Rect>* drag_bounds);
484
485  // Returns the TabStripModel for the specified tabstrip.
486  TabStripModel* GetModel(TabStrip* tabstrip) const;
487
488  // Returns the location of the cursor. This is either the location of the
489  // mouse or the location of the current touch point.
490  gfx::Point GetCursorScreenPoint();
491
492  // Returns the offset from the top left corner of the window to
493  // |point_in_screen|.
494  gfx::Vector2d GetWindowOffset(const gfx::Point& point_in_screen);
495
496  // Returns true if moving the mouse only changes the visible tabs.
497  bool move_only() const {
498    return (move_behavior_ == MOVE_VISIBILE_TABS) != 0;
499  }
500
501  // If true detaching creates a new browser and enters a nested message loop.
502  bool detach_into_browser_;
503
504  // Handles registering for notifications.
505  content::NotificationRegistrar registrar_;
506
507  EventSource event_source_;
508
509  // The TabStrip the drag originated from.
510  TabStrip* source_tabstrip_;
511
512  // The TabStrip the dragged Tab is currently attached to, or NULL if the
513  // dragged Tab is detached.
514  TabStrip* attached_tabstrip_;
515
516  // The screen that this drag is associated with. Cached, because other UI
517  // elements are NULLd at various points during the lifetime of this object.
518  gfx::Screen* screen_;
519
520  // The desktop type that this drag is associated with. Cached, because other
521  // UI elements are NULLd at various points during the lifetime of this
522  // object.
523  chrome::HostDesktopType host_desktop_type_;
524
525  // The visual representation of the dragged Tab.
526  scoped_ptr<DraggedTabView> view_;
527
528  // The position of the mouse (in screen coordinates) at the start of the drag
529  // operation. This is used to calculate minimum elasticity before a
530  // DraggedTabView is constructed.
531  gfx::Point start_point_in_screen_;
532
533  // This is the offset of the mouse from the top left of the first Tab where
534  // dragging began. This is used to ensure that the dragged view is always
535  // positioned at the correct location during the drag, and to ensure that the
536  // detached window is created at the right location.
537  gfx::Point mouse_offset_;
538
539  // Ratio of the x-coordinate of the |source_tab_offset| to the width of the
540  // tab.
541  float offset_to_width_ratio_;
542
543  // A hint to use when positioning new windows created by detaching Tabs. This
544  // is the distance of the mouse from the top left of the dragged tab as if it
545  // were the distance of the mouse from the top left of the first tab in the
546  // attached TabStrip from the top left of the window.
547  gfx::Point window_create_point_;
548
549  // Location of the first tab in the source tabstrip in screen coordinates.
550  // This is used to calculate |window_create_point_|.
551  gfx::Point first_source_tab_point_;
552
553  // The bounds of the browser window before the last Tab was detached. When
554  // the last Tab is detached, rather than destroying the frame (which would
555  // abort the drag session), the frame is moved off-screen. If the drag is
556  // aborted (e.g. by the user pressing Esc, or capture being lost), the Tab is
557  // attached to the hidden frame and the frame moved back to these bounds.
558  gfx::Rect restore_bounds_;
559
560  // Storage ID in ViewStorage where the last view that had focus in the window
561  // containing |source_tab_| is saved. This is saved so that focus can be
562  // restored properly when a drag begins and ends within this same window.
563  const int old_focused_view_id_;
564
565  // The horizontal position of the mouse cursor in screen coordinates at the
566  // time of the last re-order event.
567  int last_move_screen_loc_;
568
569  DockInfo dock_info_;
570
571  DockWindows dock_windows_;
572
573  std::vector<DockDisplayer*> dock_controllers_;
574
575  // Timer used to bring the window under the cursor to front. If the user
576  // stops moving the mouse for a brief time over a browser window, it is
577  // brought to front.
578  base::OneShotTimer<TabDragController> bring_to_front_timer_;
579
580  // Timer used to move the stacked tabs. See comment aboue
581  // StartMoveStackedTimerIfNecessary().
582  base::OneShotTimer<TabDragController> move_stacked_timer_;
583
584  // Did the mouse move enough that we started a drag?
585  bool started_drag_;
586
587  // Is the drag active?
588  bool active_;
589
590  DragData drag_data_;
591
592  // Index of the source tab in |drag_data_|.
593  size_t source_tab_index_;
594
595  // True until MoveAttached() is first invoked.
596  bool initial_move_;
597
598  // The selection model before the drag started. See comment above Init() for
599  // details.
600  ui::ListSelectionModel initial_selection_model_;
601
602  // The selection model of |attached_tabstrip_| before the tabs were attached.
603  ui::ListSelectionModel selection_model_before_attach_;
604
605  // Initial x-coordinates of the tabs when the drag started. Only used for
606  // touch mode.
607  std::vector<int> initial_tab_positions_;
608
609  DetachBehavior detach_behavior_;
610  MoveBehavior move_behavior_;
611
612  // Updated as the mouse is moved when attached. Indicates whether the mouse
613  // has ever moved to the left or right. If the tabs are ever detached this
614  // is set to kMovedMouseRight | kMovedMouseLeft.
615  int mouse_move_direction_;
616
617  // Last location used in screen coordinates.
618  gfx::Point last_point_in_screen_;
619
620  // The following are needed when detaching into a browser
621  // (|detach_into_browser_| is true).
622
623  // See description above getter.
624  bool is_dragging_window_;
625
626  // True if |attached_tabstrip_| is in a browser specifically created for
627  // the drag.
628  bool is_dragging_new_browser_;
629
630  // True if |source_tabstrip_| was maximized before the drag.
631  bool was_source_maximized_;
632
633  // True if |source_tabstrip_| was in immersive fullscreen before the drag.
634  bool was_source_fullscreen_;
635
636  EndRunLoopBehavior end_run_loop_behavior_;
637
638  // If true, we're waiting for a move loop to complete.
639  bool waiting_for_run_loop_to_exit_;
640
641  // The TabStrip to attach to after the move loop completes.
642  TabStrip* tab_strip_to_attach_to_after_exit_;
643
644  // Non-null for the duration of RunMoveLoop.
645  views::Widget* move_loop_widget_;
646
647  // See description above getter.
648  bool is_mutating_;
649
650  // |attach_x_| and |attach_index_| are set to the x-coordinate of the mouse
651  // (in terms of the tabstrip) and the insertion index at the time tabs are
652  // dragged into a new browser (attached). They are used to ensure we don't
653  // shift the tabs around in the wrong direction. The two are only valid if
654  // |attach_index_| is not -1.
655  // See comment around use for more details.
656  int attach_x_;
657  int attach_index_;
658
659  base::WeakPtrFactory<TabDragController> weak_factory_;
660
661  DISALLOW_COPY_AND_ASSIGN(TabDragController);
662};
663
664#endif  // CHROME_BROWSER_UI_VIEWS_TABS_TAB_DRAG_CONTROLLER_H_
665