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