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 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/gfx/point.h" | 9 #include "chrome/browser/ui/panels/panel_collection.h" |
10 #include "ui/gfx/vector2d.h" | 10 #include "ui/gfx/vector2d.h" |
11 | 11 |
12 class Panel; | 12 class Panel; |
13 class PanelCollection; | 13 class PanelCollection; |
14 class PanelManager; | 14 class PanelManager; |
| 15 namespace gfx { |
| 16 class Point; |
| 17 class Rect; |
| 18 } |
15 | 19 |
16 // Controls all the drags initiated for all panels, including detaching, | 20 // Controls all the drags initiated for all panels, including detaching, |
17 // docking, stacking, snapping and intra-collection dragging. | 21 // docking, stacking, snapping and intra-collection dragging. |
18 class PanelDragController { | 22 class PanelDragController { |
19 public: | 23 public: |
20 explicit PanelDragController(PanelManager* panel_manager); | 24 explicit PanelDragController(PanelManager* panel_manager); |
21 ~PanelDragController(); | 25 ~PanelDragController(); |
22 | 26 |
23 // Drags the given panel. | 27 // Drags the given panel. |
24 // |mouse_location| is in screen coordinate system. | 28 // |mouse_location| is in screen coordinate system. |
25 void StartDragging(Panel* panel, const gfx::Point& mouse_location); | 29 void StartDragging(Panel* panel, const gfx::Point& mouse_location); |
26 void Drag(const gfx::Point& mouse_location); | 30 void Drag(const gfx::Point& mouse_location); |
27 void EndDragging(bool cancelled); | 31 void EndDragging(bool cancelled); |
28 | 32 |
29 // Asynchronous confirmation of panel having been closed. | 33 // Asynchronous confirmation of panel having been closed. |
30 void OnPanelClosed(Panel* panel); | 34 void OnPanelClosed(Panel* panel); |
31 | 35 |
32 bool is_dragging() const { return dragging_panel_ != NULL; } | 36 bool is_dragging() const { return dragging_panel_ != NULL; } |
33 Panel* dragging_panel() const { return dragging_panel_; } | 37 Panel* dragging_panel() const { return dragging_panel_; } |
34 | 38 |
35 // For testing. | 39 // For testing. |
36 static int GetDetachDockedPanelThresholdForTesting(); | 40 static int GetDetachDockedPanelThresholdForTesting(); |
37 static int GetDockDetachedPanelThresholdForTesting(); | 41 static int GetDockDetachedPanelThresholdForTesting(); |
| 42 static int GetGluePanelDistanceThresholdForTesting(); |
| 43 static int GetGluePanelOverlapThresholdForTesting(); |
38 | 44 |
39 private: | 45 private: |
| 46 enum GlueAction { |
| 47 STACK, |
| 48 SNAP |
| 49 }; |
| 50 |
| 51 enum GlueEdge { |
| 52 TOP_EDGE, |
| 53 BOTTOM_EDGE, |
| 54 LEFT_EDGE, |
| 55 RIGHT_EDGE |
| 56 }; |
| 57 |
40 gfx::Point GetPanelPositionForMouseLocation( | 58 gfx::Point GetPanelPositionForMouseLocation( |
41 const gfx::Point& mouse_location) const; | 59 const gfx::Point& mouse_location) const; |
42 | 60 |
43 // |target_position| is in screen coordinate systems. It contains the proposed | 61 // |target_position| is in screen coordinate systems. It contains the proposed |
44 // panel origin to move to. Returns true if the request has been performed. | 62 // panel origin to move to. Returns true if the request has been performed. |
45 bool TryDetach(const gfx::Point& target_position); | 63 void TryDetach(const gfx::Point& target_position); |
46 bool TryDock(const gfx::Point& target_position); | 64 void TryDock(const gfx::Point& target_position); |
| 65 void TryStack(const gfx::Point& target_position); |
| 66 bool TryUnstackFromTop(const gfx::Point& target_position); |
| 67 bool TryUnstackFromBottom(const gfx::Point& target_position); |
| 68 void TrySnap(gfx::Point* target_position); |
| 69 |
| 70 // Finds the panel that the dragging panel with |potential_position| could |
| 71 // snap to or stack with. If such panel is found, |target_bounds| contains the |
| 72 // new bounds for the dragging panel and |target_edge| contains the matched |
| 73 // edge. |
| 74 Panel* FindPanelToGlue(const gfx::Point& potential_position, |
| 75 GlueAction action, |
| 76 gfx::Rect* target_bounds, |
| 77 GlueEdge* target_edge) const; |
| 78 |
| 79 // Moves the |panel| (and all panels below if it is in a stack) to a different |
| 80 // collection. |
| 81 void MovePanelAndBelowToCollection( |
| 82 Panel* panel, |
| 83 PanelCollection* target_collection, |
| 84 PanelCollection::PositioningMask positioning_mask) const; |
47 | 85 |
48 PanelManager* panel_manager_; // Weak, owns us. | 86 PanelManager* panel_manager_; // Weak, owns us. |
| 87 bool panel_stacking_enabled_; |
49 | 88 |
50 // Panel currently being dragged. | 89 // Panel currently being dragged. |
51 Panel* dragging_panel_; | 90 Panel* dragging_panel_; |
52 | 91 |
53 // The original panel collection when the drag is started. | 92 // The original panel collection when the drag is started. |
54 PanelCollection* dragging_panel_original_collection_; | 93 PanelCollection* dragging_panel_original_collection_; |
55 | 94 |
56 // The offset from mouse location to the panel position when the drag | 95 // The offset from mouse location to the panel position when the drag |
57 // starts. | 96 // starts. |
58 gfx::Vector2d offset_from_mouse_location_on_drag_start_; | 97 gfx::Vector2d offset_from_mouse_location_on_drag_start_; |
59 | 98 |
60 DISALLOW_COPY_AND_ASSIGN(PanelDragController); | 99 DISALLOW_COPY_AND_ASSIGN(PanelDragController); |
61 }; | 100 }; |
62 | 101 |
63 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ | 102 #endif // CHROME_BROWSER_UI_PANELS_PANEL_DRAG_CONTROLLER_H_ |
OLD | NEW |