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 #include "ash/mus/frame/move_event_handler.h" | 5 #include "ash/mus/frame/move_event_handler.h" |
6 | 6 |
7 #include "ash/mus/bridge/wm_window_mus.h" | 7 #include "ash/mus/bridge/wm_window_mus.h" |
8 #include "base/lazy_instance.h" | |
8 #include "components/mus/public/cpp/window.h" | 9 #include "components/mus/public/cpp/window.h" |
9 #include "components/mus/public/cpp/window_manager_delegate.h" | 10 #include "components/mus/public/cpp/window_manager_delegate.h" |
10 #include "components/mus/public/interfaces/cursor.mojom.h" | 11 #include "components/mus/public/interfaces/cursor.mojom.h" |
11 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
12 #include "ui/base/hit_test.h" | 13 #include "ui/base/hit_test.h" |
13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
14 | 15 |
15 namespace ash { | 16 namespace ash { |
16 namespace mus { | 17 namespace mus { |
17 namespace { | 18 namespace { |
18 | 19 |
20 base::LazyInstance<std::map<WmWindow*, MoveEventHandler*>> g_live_handlers = | |
sky
2016/06/24 19:42:02
Use a local property on the window to track the Mo
| |
21 LAZY_INSTANCE_INITIALIZER; | |
22 | |
19 ::mus::mojom::Cursor CursorForWindowComponent(int window_component) { | 23 ::mus::mojom::Cursor CursorForWindowComponent(int window_component) { |
20 switch (window_component) { | 24 switch (window_component) { |
21 case HTBOTTOM: | 25 case HTBOTTOM: |
22 return ::mus::mojom::Cursor::SOUTH_RESIZE; | 26 return ::mus::mojom::Cursor::SOUTH_RESIZE; |
23 case HTBOTTOMLEFT: | 27 case HTBOTTOMLEFT: |
24 return ::mus::mojom::Cursor::SOUTH_WEST_RESIZE; | 28 return ::mus::mojom::Cursor::SOUTH_WEST_RESIZE; |
25 case HTBOTTOMRIGHT: | 29 case HTBOTTOMRIGHT: |
26 return ::mus::mojom::Cursor::SOUTH_EAST_RESIZE; | 30 return ::mus::mojom::Cursor::SOUTH_EAST_RESIZE; |
27 case HTLEFT: | 31 case HTLEFT: |
28 return ::mus::mojom::Cursor::WEST_RESIZE; | 32 return ::mus::mojom::Cursor::WEST_RESIZE; |
29 case HTRIGHT: | 33 case HTRIGHT: |
30 return ::mus::mojom::Cursor::EAST_RESIZE; | 34 return ::mus::mojom::Cursor::EAST_RESIZE; |
31 case HTTOP: | 35 case HTTOP: |
32 return ::mus::mojom::Cursor::NORTH_RESIZE; | 36 return ::mus::mojom::Cursor::NORTH_RESIZE; |
33 case HTTOPLEFT: | 37 case HTTOPLEFT: |
34 return ::mus::mojom::Cursor::NORTH_WEST_RESIZE; | 38 return ::mus::mojom::Cursor::NORTH_WEST_RESIZE; |
35 case HTTOPRIGHT: | 39 case HTTOPRIGHT: |
36 return ::mus::mojom::Cursor::NORTH_EAST_RESIZE; | 40 return ::mus::mojom::Cursor::NORTH_EAST_RESIZE; |
37 default: | 41 default: |
38 return ::mus::mojom::Cursor::CURSOR_NULL; | 42 return ::mus::mojom::Cursor::CURSOR_NULL; |
39 } | 43 } |
40 } | 44 } |
41 | 45 |
46 void OnMoveLoopCompleted(const base::Callback<void(bool success)>& end_closure, | |
47 wm::WmToplevelWindowEventHandler::DragResult result) { | |
48 end_closure.Run(result == | |
49 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS); | |
50 } | |
51 | |
42 } // namespace | 52 } // namespace |
43 | 53 |
44 MoveEventHandler::MoveEventHandler( | 54 MoveEventHandler::MoveEventHandler( |
45 ::mus::Window* mus_window, | 55 ::mus::Window* mus_window, |
46 ::mus::WindowManagerClient* window_manager_client, | 56 ::mus::WindowManagerClient* window_manager_client, |
47 aura::Window* aura_window) | 57 aura::Window* aura_window) |
48 : wm_window_(WmWindowMus::Get(mus_window)), | 58 : wm_window_(WmWindowMus::Get(mus_window)), |
49 window_manager_client_(window_manager_client), | 59 window_manager_client_(window_manager_client), |
50 root_window_(aura_window->GetRootWindow()), | 60 root_window_(aura_window->GetRootWindow()), |
51 toplevel_window_event_handler_(wm_window_->GetShell()) { | 61 toplevel_window_event_handler_(wm_window_->GetShell()) { |
52 root_window_->AddObserver(this); | 62 root_window_->AddObserver(this); |
53 root_window_->AddPreTargetHandler(this); | 63 root_window_->AddPreTargetHandler(this); |
64 | |
65 DCHECK(g_live_handlers.Get().find(wm_window_) == g_live_handlers.Get().end()); | |
66 g_live_handlers.Get()[wm_window_] = this; | |
54 } | 67 } |
55 | 68 |
56 MoveEventHandler::~MoveEventHandler() { | 69 MoveEventHandler::~MoveEventHandler() { |
57 Detach(); | 70 Detach(); |
58 } | 71 } |
59 | 72 |
73 // static | |
74 MoveEventHandler* MoveEventHandler::GetForWindow(WmWindow* wm_window) { | |
75 auto it = g_live_handlers.Get().find(wm_window); | |
76 if (it != g_live_handlers.Get().end()) | |
77 return it->second; | |
78 return nullptr; | |
79 } | |
80 | |
81 void MoveEventHandler::AttemptToStartDrag( | |
82 const gfx::Point& point_in_parent, | |
83 int window_component, | |
84 const base::Callback<void(bool success)>& end_closure) { | |
85 toplevel_window_event_handler_.AttemptToStartDrag( | |
86 wm_window_, point_in_parent, window_component, | |
87 aura::client::WINDOW_MOVE_SOURCE_MOUSE, | |
sky
2016/06/24 19:42:02
Might the source be touch?
| |
88 base::Bind(&OnMoveLoopCompleted, end_closure)); | |
89 } | |
90 | |
91 void MoveEventHandler::RevertDrag() { | |
92 toplevel_window_event_handler_.RevertDrag(); | |
93 } | |
94 | |
60 void MoveEventHandler::Detach() { | 95 void MoveEventHandler::Detach() { |
61 if (!root_window_) | 96 if (!root_window_) |
62 return; | 97 return; |
63 | 98 |
64 root_window_->RemoveObserver(this); | 99 root_window_->RemoveObserver(this); |
65 root_window_->RemovePreTargetHandler(this); | 100 root_window_->RemovePreTargetHandler(this); |
66 root_window_ = nullptr; | 101 root_window_ = nullptr; |
102 | |
103 g_live_handlers.Get().erase(wm_window_); | |
67 } | 104 } |
68 | 105 |
69 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { | 106 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
70 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_); | 107 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_); |
71 if (!toplevel_window_event_handler_.is_drag_in_progress() && | 108 if (!toplevel_window_event_handler_.is_drag_in_progress() && |
72 (event->type() == ui::ET_POINTER_MOVED || | 109 (event->type() == ui::ET_POINTER_MOVED || |
73 event->type() == ui::ET_MOUSE_MOVED)) { | 110 event->type() == ui::ET_MOUSE_MOVED)) { |
74 const int hit_test_location = | 111 const int hit_test_location = |
75 wm_window_->GetNonClientComponent(event->location()); | 112 wm_window_->GetNonClientComponent(event->location()); |
76 window_manager_client_->SetNonClientCursor( | 113 window_manager_client_->SetNonClientCursor( |
77 wm_window_->mus_window(), CursorForWindowComponent(hit_test_location)); | 114 wm_window_->mus_window(), CursorForWindowComponent(hit_test_location)); |
78 } | 115 } |
79 } | 116 } |
80 | 117 |
81 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) { | 118 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
82 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_); | 119 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_); |
83 } | 120 } |
84 | 121 |
85 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { | 122 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { |
86 toplevel_window_event_handler_.RevertDrag(); | 123 toplevel_window_event_handler_.RevertDrag(); |
87 } | 124 } |
88 | 125 |
89 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { | 126 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { |
90 DCHECK_EQ(root_window_, window); | 127 DCHECK_EQ(root_window_, window); |
91 Detach(); | 128 Detach(); |
92 } | 129 } |
93 | 130 |
94 } // namespace mus | 131 } // namespace mus |
95 } // namespace ash | 132 } // namespace ash |
OLD | NEW |