Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: ash/mus/move_event_handler.cc

Issue 2539363005: Converts ash to use aura-mus (Closed)
Patch Set: merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/move_event_handler.h" 5 #include "ash/mus/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 "ash/mus/bridge/workspace_event_handler_mus.h" 8 #include "ash/mus/bridge/workspace_event_handler_mus.h"
9 #include "services/ui/public/cpp/window.h"
10 #include "services/ui/public/cpp/window_manager_delegate.h"
11 #include "services/ui/public/cpp/window_property.h"
12 #include "services/ui/public/interfaces/cursor.mojom.h" 9 #include "services/ui/public/interfaces/cursor.mojom.h"
10 #include "ui/aura/mus/window_manager_delegate.h"
13 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/aura/window_property.h"
14 #include "ui/base/hit_test.h" 13 #include "ui/base/hit_test.h"
15 #include "ui/events/event.h" 14 #include "ui/events/event.h"
16 15
17 MUS_DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::MoveEventHandler*) 16 DECLARE_WINDOW_PROPERTY_TYPE(ash::mus::MoveEventHandler*);
18 17
19 namespace { 18 namespace {
20 19
21 // Key used for storing identifier sent to clients for windows. 20 // Key used for storing identifier sent to clients for windows.
22 MUS_DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ash::mus::MoveEventHandler*, 21 DEFINE_WINDOW_PROPERTY_KEY(ash::mus::MoveEventHandler*,
23 kWmMoveEventHandler, 22 kWmMoveEventHandler,
24 nullptr); 23 nullptr);
25 24
26 } // namespace 25 } // namespace
27 26
28 namespace ash { 27 namespace ash {
29 namespace mus { 28 namespace mus {
30 namespace { 29 namespace {
31 30
32 ui::mojom::Cursor CursorForWindowComponent(int window_component) { 31 ui::mojom::Cursor CursorForWindowComponent(int window_component) {
33 switch (window_component) { 32 switch (window_component) {
34 case HTBOTTOM: 33 case HTBOTTOM:
(...skipping 19 matching lines...) Expand all
54 53
55 void OnMoveLoopCompleted(const base::Callback<void(bool success)>& end_closure, 54 void OnMoveLoopCompleted(const base::Callback<void(bool success)>& end_closure,
56 wm::WmToplevelWindowEventHandler::DragResult result) { 55 wm::WmToplevelWindowEventHandler::DragResult result) {
57 end_closure.Run(result == 56 end_closure.Run(result ==
58 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS); 57 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS);
59 } 58 }
60 59
61 } // namespace 60 } // namespace
62 61
63 MoveEventHandler::MoveEventHandler( 62 MoveEventHandler::MoveEventHandler(
64 ui::Window* mus_window, 63 aura::WindowManagerClient* window_manager_client,
65 ui::WindowManagerClient* window_manager_client, 64 aura::Window* window)
66 aura::Window* aura_window) 65 : wm_window_(WmWindowMus::Get(window)),
67 : wm_window_(WmWindowMus::Get(mus_window)),
68 window_manager_client_(window_manager_client), 66 window_manager_client_(window_manager_client),
69 root_window_(aura_window->GetRootWindow()),
70 toplevel_window_event_handler_(wm_window_->GetShell()) { 67 toplevel_window_event_handler_(wm_window_->GetShell()) {
71 root_window_->AddObserver(this); 68 window->AddObserver(this);
72 root_window_->AddPreTargetHandler(this); 69 window->AddPreTargetHandler(this);
73 70
74 mus_window->SetLocalProperty(kWmMoveEventHandler, this); 71 window->SetProperty(kWmMoveEventHandler, this);
75 } 72 }
76 73
77 MoveEventHandler::~MoveEventHandler() { 74 MoveEventHandler::~MoveEventHandler() {
78 Detach(); 75 Detach();
79 } 76 }
80 77
81 // static 78 // static
82 MoveEventHandler* MoveEventHandler::GetForWindow(WmWindow* wm_window) { 79 MoveEventHandler* MoveEventHandler::GetForWindow(WmWindow* wm_window) {
83 return WmWindowMus::GetMusWindow(wm_window)->GetLocalProperty( 80 return WmWindowMus::GetAuraWindow(wm_window)->GetProperty(
84 kWmMoveEventHandler); 81 kWmMoveEventHandler);
85 } 82 }
86 83
87 void MoveEventHandler::AttemptToStartDrag( 84 void MoveEventHandler::AttemptToStartDrag(
88 const gfx::Point& point_in_parent, 85 const gfx::Point& point_in_parent,
89 int window_component, 86 int window_component,
90 aura::client::WindowMoveSource source, 87 aura::client::WindowMoveSource source,
91 const base::Callback<void(bool success)>& end_closure) { 88 const base::Callback<void(bool success)>& end_closure) {
92 toplevel_window_event_handler_.AttemptToStartDrag( 89 toplevel_window_event_handler_.AttemptToStartDrag(
93 wm_window_, point_in_parent, window_component, source, 90 wm_window_, point_in_parent, window_component, source,
94 base::Bind(&OnMoveLoopCompleted, end_closure)); 91 base::Bind(&OnMoveLoopCompleted, end_closure));
95 } 92 }
96 93
97 bool MoveEventHandler::IsDragInProgress() { 94 bool MoveEventHandler::IsDragInProgress() {
98 return toplevel_window_event_handler_.is_drag_in_progress(); 95 return toplevel_window_event_handler_.is_drag_in_progress();
99 } 96 }
100 97
101 void MoveEventHandler::RevertDrag() { 98 void MoveEventHandler::RevertDrag() {
102 toplevel_window_event_handler_.RevertDrag(); 99 toplevel_window_event_handler_.RevertDrag();
103 } 100 }
104 101
105 void MoveEventHandler::Detach() { 102 void MoveEventHandler::Detach() {
106 if (!root_window_) 103 if (!wm_window_)
107 return; 104 return;
108 105
109 root_window_->RemoveObserver(this); 106 wm_window_->aura_window()->RemoveObserver(this);
110 root_window_->RemovePreTargetHandler(this); 107 wm_window_->aura_window()->RemovePreTargetHandler(this);
111 root_window_ = nullptr; 108 wm_window_->aura_window()->ClearProperty(kWmMoveEventHandler);
109 wm_window_ = nullptr;
112 } 110 }
113 111
114 WorkspaceEventHandlerMus* MoveEventHandler::GetWorkspaceEventHandlerMus() { 112 WorkspaceEventHandlerMus* MoveEventHandler::GetWorkspaceEventHandlerMus() {
115 if (!wm_window_->GetParent()) 113 if (!wm_window_->GetParent())
116 return nullptr; 114 return nullptr;
117 115
118 return WorkspaceEventHandlerMus::Get(wm_window_->mus_window()->parent()); 116 return WorkspaceEventHandlerMus::Get(wm_window_->aura_window()->parent());
119 } 117 }
120 118
121 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { 119 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) {
122 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_); 120 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_);
123 if (!toplevel_window_event_handler_.is_drag_in_progress() && 121 if (!toplevel_window_event_handler_.is_drag_in_progress() &&
124 (event->type() == ui::ET_POINTER_MOVED || 122 (event->type() == ui::ET_POINTER_MOVED ||
125 event->type() == ui::ET_MOUSE_MOVED)) { 123 event->type() == ui::ET_MOUSE_MOVED)) {
126 const int hit_test_location = 124 const int hit_test_location =
127 wm_window_->GetNonClientComponent(event->location()); 125 wm_window_->GetNonClientComponent(event->location());
128 window_manager_client_->SetNonClientCursor( 126 window_manager_client_->SetNonClientCursor(
129 wm_window_->mus_window(), CursorForWindowComponent(hit_test_location)); 127 wm_window_->aura_window(), CursorForWindowComponent(hit_test_location));
130 } 128 }
131 129
132 WorkspaceEventHandlerMus* workspace_event_handler = 130 WorkspaceEventHandlerMus* workspace_event_handler =
133 GetWorkspaceEventHandlerMus(); 131 GetWorkspaceEventHandlerMus();
134 if (workspace_event_handler) 132 if (workspace_event_handler)
135 workspace_event_handler->OnMouseEvent(event, wm_window_); 133 workspace_event_handler->OnMouseEvent(event, wm_window_);
136 } 134 }
137 135
138 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) { 136 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) {
139 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_); 137 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_);
140 138
141 WorkspaceEventHandlerMus* workspace_event_handler = 139 WorkspaceEventHandlerMus* workspace_event_handler =
142 GetWorkspaceEventHandlerMus(); 140 GetWorkspaceEventHandlerMus();
143 if (workspace_event_handler) 141 if (workspace_event_handler)
144 workspace_event_handler->OnGestureEvent(event, wm_window_); 142 workspace_event_handler->OnGestureEvent(event, wm_window_);
145 } 143 }
146 144
147 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { 145 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) {
148 toplevel_window_event_handler_.RevertDrag(); 146 toplevel_window_event_handler_.RevertDrag();
149 } 147 }
150 148
151 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { 149 void MoveEventHandler::OnWindowDestroying(aura::Window* window) {
152 DCHECK_EQ(root_window_, window); 150 DCHECK_EQ(wm_window_->aura_window(), window);
153 Detach(); 151 Detach();
154 } 152 }
155 153
156 } // namespace mus 154 } // namespace mus
157 } // namespace ash 155 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698