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; | |
14 | 16 |
15 // Responsible for handling drags initiated for all panels, including both | 17 // Responsible for handling drags initiated for all panels, including both |
16 // intra-strip and inter-strip drags. | 18 // intra-strip and inter-strip drags. |
17 class PanelDragController { | 19 class PanelDragController { |
18 public: | 20 public: |
19 PanelDragController(); | 21 explicit PanelDragController(PanelManager* panel_manager); |
20 ~PanelDragController(); | 22 ~PanelDragController(); |
21 | 23 |
22 void StartDragging(Panel* panel); | 24 // Drags the given panel. |
23 void Drag(int delta_x, int delta_y); | 25 // |mouse_location| is in screen coordinate system. |
26 void StartDragging(Panel* panel, const gfx::Point& mouse_location); | |
27 void Drag(const gfx::Point& mouse_location); | |
24 void EndDragging(bool cancelled); | 28 void EndDragging(bool cancelled); |
25 | 29 |
26 // Asynchronous confirmation of panel having been closed. | 30 // Asynchronous confirmation of panel having been closed. |
27 void OnPanelClosed(Panel* panel); | 31 void OnPanelClosed(Panel* panel); |
28 | 32 |
29 bool IsDragging() const { return dragging_panel_ != NULL; } | 33 bool IsDragging() const { return dragging_panel_ != NULL; } |
30 | 34 |
31 Panel* dragging_panel() const { return dragging_panel_; } | 35 Panel* dragging_panel() const { return dragging_panel_; } |
32 gfx::Point dragging_panel_original_position() const { | 36 |
33 return dragging_panel_original_position_; | 37 #ifdef UNIT_TEST |
38 static int GetDetachDockedPanelThreshold() { | |
39 return kDetachDockedPanelThreshold; | |
34 } | 40 } |
35 | 41 |
42 static int GetDockDetachedPanelThreshold() { | |
43 return kDockDetachedPanelThreshold; | |
44 } | |
45 #endif | |
46 | |
36 private: | 47 private: |
48 // Used to figure out if the panel can be dragged to other strip. | |
49 PanelStrip* ComputeDragTagetStrip( | |
50 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
51 bool CanDragToDockedStrip( | |
52 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
53 bool CanDragToDetachedStrip( | |
54 const gfx::Point& mouse_location, gfx::Point* new_panel_position) const; | |
55 | |
56 PanelManager* panel_manager_; // Weak, owns us. | |
57 | |
37 // Panel currently being dragged. | 58 // Panel currently being dragged. |
38 Panel* dragging_panel_; | 59 Panel* dragging_panel_; |
39 | 60 |
40 // Original position, in screen coordinate system, of the panel being dragged. | 61 // The original panel strip that the drag is initiated. |
jennb
2012/03/03 02:19:33
Fix grammar.
jianli
2012/03/07 19:14:31
Done.
| |
41 // This is used to get back to the original position when we cancel the | 62 PanelStrip* dragging_panel_original_strip_; |
42 // dragging. | 63 |
43 gfx::Point dragging_panel_original_position_; | 64 // The mouse location, in screen coordinates, when mouse press/drag event is |
65 // received last time. | |
jennb
2012/03/03 02:19:33
'last time' ?
jianli
2012/03/07 19:14:31
Done.
| |
66 gfx::Point last_mouse_location_; | |
67 | |
68 // The mouse location, in screen coordinates, when the drag starts at the | |
69 // docked strip. | |
70 gfx::Point mouse_location_on_docked_; | |
71 | |
72 // The threshold to detach a docked panel to make it free-floating. | |
jennb
2012/03/03 02:19:33
These comments simply repeat the var name. Explain
jianli
2012/03/07 19:14:31
Done.
| |
73 static const int kDetachDockedPanelThreshold; | |
74 | |
75 // The threshold to dock a detached panel. | |
76 static const int kDockDetachedPanelThreshold; | |
44 | 77 |
45 DISALLOW_COPY_AND_ASSIGN(PanelDragController); | 78 DISALLOW_COPY_AND_ASSIGN(PanelDragController); |
46 }; | 79 }; |
47 | 80 |
48 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 81 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
OLD | NEW |