OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 ASH_MUS_MOVE_EVENT_HANDLER_H_ | 5 #ifndef ASH_MUS_MOVE_EVENT_HANDLER_H_ |
6 #define ASH_MUS_MOVE_EVENT_HANDLER_H_ | 6 #define ASH_MUS_MOVE_EVENT_HANDLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/common/wm/wm_toplevel_window_event_handler.h" | 10 #include "ash/common/wm/wm_toplevel_window_event_handler.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "ui/aura/window_observer.h" | 12 #include "ui/aura/window_observer.h" |
13 #include "ui/events/event_handler.h" | 13 #include "ui/events/event_handler.h" |
14 | 14 |
15 namespace aura { | 15 namespace aura { |
16 class Window; | 16 class Window; |
| 17 class WindowManagerClient; |
17 } | 18 } |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 class CancelModeEvent; | 21 class CancelModeEvent; |
21 class Window; | |
22 class WindowManagerClient; | |
23 } | 22 } |
24 | 23 |
25 namespace ash { | 24 namespace ash { |
26 namespace mus { | 25 namespace mus { |
27 | 26 |
28 class WmWindowMus; | 27 class WmWindowMus; |
29 class WorkspaceEventHandlerMus; | 28 class WorkspaceEventHandlerMus; |
30 | 29 |
31 // EventHandler attached to windows that may be dragged and/or resized. This | 30 // EventHandler attached to windows that may be dragged and/or resized. This |
32 // forwards to WmToplevelWindowEventHandler to handle the actual drag/resize. | 31 // forwards to WmToplevelWindowEventHandler to handle the actual drag/resize. |
33 // | 32 // |
34 // TODO(sky): rename this class to better reflect that it handles redirecting | 33 // TODO(sky): rename this class to better reflect that it handles redirecting |
35 // events in addition to drag. | 34 // events in addition to drag. |
36 class MoveEventHandler : public ui::EventHandler, public aura::WindowObserver { | 35 class MoveEventHandler : public ui::EventHandler, public aura::WindowObserver { |
37 public: | 36 public: |
38 MoveEventHandler(ui::Window* mus_window, | 37 MoveEventHandler(aura::WindowManagerClient* window_manager_client, |
39 ui::WindowManagerClient* window_manager_client, | 38 aura::Window* window); |
40 aura::Window* aura_window); | |
41 ~MoveEventHandler() override; | 39 ~MoveEventHandler() override; |
42 | 40 |
43 // Retrieves the MoveEventHandler for an existing WmWindow. | 41 // Retrieves the MoveEventHandler for an existing WmWindow. |
44 static MoveEventHandler* GetForWindow(WmWindow* wm_window); | 42 static MoveEventHandler* GetForWindow(WmWindow* wm_window); |
45 | 43 |
46 // Attempts to start a drag if one is not already in progress. This passes | 44 // Attempts to start a drag if one is not already in progress. This passes |
47 // the call to the underlying WmToplevelWindowEventHandler. After the drag | 45 // the call to the underlying WmToplevelWindowEventHandler. After the drag |
48 // completes, |end_closure| will be called to return whether the drag was | 46 // completes, |end_closure| will be called to return whether the drag was |
49 // successfully completed. | 47 // successfully completed. |
50 void AttemptToStartDrag( | 48 void AttemptToStartDrag( |
51 const gfx::Point& point_in_parent, | 49 const gfx::Point& point_in_parent, |
52 int window_component, | 50 int window_component, |
53 aura::client::WindowMoveSource source, | 51 aura::client::WindowMoveSource source, |
54 const base::Callback<void(bool success)>& end_closure); | 52 const base::Callback<void(bool success)>& end_closure); |
55 | 53 |
56 // Returns whether we're in a drag. | 54 // Returns whether we're in a drag. |
57 bool IsDragInProgress(); | 55 bool IsDragInProgress(); |
58 | 56 |
59 // Reverts a manually started drag started with AttemptToStartDrag(). | 57 // Reverts a manually started drag started with AttemptToStartDrag(). |
60 void RevertDrag(); | 58 void RevertDrag(); |
61 | 59 |
62 private: | 60 private: |
63 // Removes observer and EventHandler installed on |root_window_|. | 61 // Removes observer and EventHandler. |
64 void Detach(); | 62 void Detach(); |
65 | 63 |
66 // Returns the WorkspaceEventHandlerMus, or null if the window is not in a | 64 // Returns the WorkspaceEventHandlerMus, or null if the window is not in a |
67 // workspace. | 65 // workspace. |
68 WorkspaceEventHandlerMus* GetWorkspaceEventHandlerMus(); | 66 WorkspaceEventHandlerMus* GetWorkspaceEventHandlerMus(); |
69 | 67 |
70 // Overridden from ui::EventHandler: | 68 // Overridden from ui::EventHandler: |
71 void OnMouseEvent(ui::MouseEvent* event) override; | 69 void OnMouseEvent(ui::MouseEvent* event) override; |
72 void OnGestureEvent(ui::GestureEvent* event) override; | 70 void OnGestureEvent(ui::GestureEvent* event) override; |
73 void OnCancelMode(ui::CancelModeEvent* event) override; | 71 void OnCancelMode(ui::CancelModeEvent* event) override; |
74 | 72 |
75 // Overridden from aura::WindowObserver: | 73 // Overridden from aura::WindowObserver: |
76 void OnWindowDestroying(aura::Window* window) override; | 74 void OnWindowDestroying(aura::Window* window) override; |
77 | 75 |
78 WmWindowMus* wm_window_; | 76 WmWindowMus* wm_window_; |
79 ui::WindowManagerClient* window_manager_client_; | 77 aura::WindowManagerClient* window_manager_client_; |
80 // The root window of the aura::Window supplied to the constructor. | |
81 // MoveEventHandler is added as a pre-target handler (and observer) of this. | |
82 aura::Window* root_window_; | |
83 wm::WmToplevelWindowEventHandler toplevel_window_event_handler_; | 78 wm::WmToplevelWindowEventHandler toplevel_window_event_handler_; |
84 | 79 |
85 DISALLOW_COPY_AND_ASSIGN(MoveEventHandler); | 80 DISALLOW_COPY_AND_ASSIGN(MoveEventHandler); |
86 }; | 81 }; |
87 | 82 |
88 } // namespace mus | 83 } // namespace mus |
89 } // namespace ash | 84 } // namespace ash |
90 | 85 |
91 #endif // ASH_MUS_MOVE_EVENT_HANDLER_H_ | 86 #endif // ASH_MUS_MOVE_EVENT_HANDLER_H_ |
OLD | NEW |