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_PANELS_PANEL_DRAG_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
6 #define CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 6 #define CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "ui/gfx/point.h" | 11 #include "ui/gfx/point.h" |
12 | 12 |
13 class Panel; | 13 class Panel; |
| 14 class PanelManager; |
| 15 class PanelStrip; |
| 16 namespace gfx { |
| 17 class Rect; |
| 18 } |
14 | 19 |
15 // Responsible for handling drags initiated for all panels, including both | 20 // Responsible for handling drags initiated for all panels, including both |
16 // intra-strip and inter-strip drags. | 21 // intra-strip and inter-strip drags. |
17 class PanelDragController { | 22 class PanelDragController { |
18 public: | 23 public: |
19 PanelDragController(); | 24 explicit PanelDragController(PanelManager* panel_manager); |
20 ~PanelDragController(); | 25 ~PanelDragController(); |
21 | 26 |
22 // Drags the given panel. | 27 // Drags the given panel. |
23 // |mouse_location| is in screen coordinate system. | 28 // |mouse_location| is in screen coordinate system. |
24 void StartDragging(Panel* panel, const gfx::Point& mouse_location); | 29 void StartDragging(Panel* panel, const gfx::Point& mouse_location); |
25 void Drag(const gfx::Point& mouse_location); | 30 void Drag(const gfx::Point& mouse_location); |
26 void EndDragging(bool cancelled); | 31 void EndDragging(bool cancelled); |
27 | 32 |
28 // Asynchronous confirmation of panel having been closed. | 33 // Asynchronous confirmation of panel having been closed. |
29 void OnPanelClosed(Panel* panel); | 34 void OnPanelClosed(Panel* panel); |
30 | 35 |
31 bool IsDragging() const { return dragging_panel_ != NULL; } | 36 bool IsDragging() const { return dragging_panel_ != NULL; } |
32 | 37 |
33 Panel* dragging_panel() const { return dragging_panel_; } | 38 Panel* dragging_panel() const { return dragging_panel_; } |
34 gfx::Point dragging_panel_original_position() const { | 39 |
35 return dragging_panel_original_position_; | 40 #ifdef UNIT_TEST |
| 41 static int GetDetachDockedPanelThreshold() { |
| 42 return kDetachDockedPanelThreshold; |
36 } | 43 } |
37 | 44 |
| 45 static int GetDockDetachedPanelThreshold() { |
| 46 return kDockDetachedPanelThreshold; |
| 47 } |
| 48 #endif |
| 49 |
38 private: | 50 private: |
| 51 // Helper methods to figure out if the panel can be dragged to other strip. |
| 52 // Returns target strip/boolean flag, and |new_panel_bounds| if the panel |
| 53 // can enter other strip at |mouse_location|. |
| 54 PanelStrip* ComputeDragTargetStrip( |
| 55 const gfx::Point& mouse_location, gfx::Rect* new_panel_bounds) const; |
| 56 bool CanDragToDockedStrip( |
| 57 const gfx::Point& mouse_location, gfx::Rect* new_panel_bounds) const; |
| 58 bool CanDragToDetachedStrip( |
| 59 const gfx::Point& mouse_location, gfx::Rect* new_panel_bounds) const; |
| 60 |
| 61 PanelManager* panel_manager_; // Weak, owns us. |
| 62 |
39 // Panel currently being dragged. | 63 // Panel currently being dragged. |
40 Panel* dragging_panel_; | 64 Panel* dragging_panel_; |
41 | 65 |
42 // Original position, in screen coordinate system, of the panel being dragged. | 66 // The original panel strip when the drag is started. |
43 // This is used to get back to the original position when we cancel the | 67 PanelStrip* dragging_panel_original_strip_; |
44 // dragging. | |
45 gfx::Point dragging_panel_original_position_; | |
46 | 68 |
47 // The mouse location, in screen coordinates, when StartDragging or Drag was | 69 // The mouse location, in screen coordinates, when StartDragging or Drag was |
48 // pveviously called. | 70 // pveviously called. |
49 gfx::Point last_mouse_location_; | 71 gfx::Point last_mouse_location_; |
50 | 72 |
| 73 // The offset from mouse location to the panel position when the drag |
| 74 // starts. |
| 75 gfx::Point offset_from_mouse_location_on_drag_start_; |
| 76 |
| 77 // The minimum distance that the docked panel gets dragged up in order to |
| 78 // make it free-floating. |
| 79 static const int kDetachDockedPanelThreshold; |
| 80 |
| 81 // Indicates how close the bottom of the detached panel is to the bottom of |
| 82 // the docked area such that the detached panel becomes docked. |
| 83 static const int kDockDetachedPanelThreshold; |
| 84 |
51 DISALLOW_COPY_AND_ASSIGN(PanelDragController); | 85 DISALLOW_COPY_AND_ASSIGN(PanelDragController); |
52 }; | 86 }; |
53 | 87 |
54 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 88 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
OLD | NEW |