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

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

Issue 2905893002: chromeos: convert more ash/wm code to aura::Window (Closed)
Patch Set: moar cleanup Created 3 years, 7 months 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/workspace_event_handler_mus.h" 7 #include "ash/mus/bridge/workspace_event_handler_mus.h"
8 #include "ash/wm_window.h" 8 #include "ash/wm/window_util.h"
9 #include "services/ui/public/interfaces/cursor/cursor.mojom.h" 9 #include "services/ui/public/interfaces/cursor/cursor.mojom.h"
10 #include "ui/aura/mus/window_manager_delegate.h" 10 #include "ui/aura/mus/window_manager_delegate.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/aura/window_delegate.h"
12 #include "ui/base/class_property.h" 13 #include "ui/base/class_property.h"
13 #include "ui/base/cursor/cursor.h" 14 #include "ui/base/cursor/cursor.h"
14 #include "ui/base/hit_test.h" 15 #include "ui/base/hit_test.h"
15 #include "ui/events/event.h" 16 #include "ui/events/event.h"
16 17
17 DECLARE_UI_CLASS_PROPERTY_TYPE(ash::mus::MoveEventHandler*); 18 DECLARE_UI_CLASS_PROPERTY_TYPE(ash::mus::MoveEventHandler*);
18 19
19 namespace { 20 namespace {
20 21
21 // Key used for storing identifier sent to clients for windows. 22 // Key used for storing identifier sent to clients for windows.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 wm::WmToplevelWindowEventHandler::DragResult result) { 57 wm::WmToplevelWindowEventHandler::DragResult result) {
57 end_closure.Run(result == 58 end_closure.Run(result ==
58 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS); 59 wm::WmToplevelWindowEventHandler::DragResult::SUCCESS);
59 } 60 }
60 61
61 } // namespace 62 } // namespace
62 63
63 MoveEventHandler::MoveEventHandler( 64 MoveEventHandler::MoveEventHandler(
64 aura::WindowManagerClient* window_manager_client, 65 aura::WindowManagerClient* window_manager_client,
65 aura::Window* window) 66 aura::Window* window)
66 : wm_window_(WmWindow::Get(window)), 67 : window_(window), window_manager_client_(window_manager_client) {
67 window_manager_client_(window_manager_client) {
68 window->AddObserver(this); 68 window->AddObserver(this);
69 window->AddPreTargetHandler(this); 69 window->AddPreTargetHandler(this);
70 70
71 window->SetProperty(kWmMoveEventHandler, this); 71 window->SetProperty(kWmMoveEventHandler, this);
72 } 72 }
73 73
74 MoveEventHandler::~MoveEventHandler() { 74 MoveEventHandler::~MoveEventHandler() {
75 Detach(); 75 Detach();
76 } 76 }
77 77
78 // static 78 // static
79 MoveEventHandler* MoveEventHandler::GetForWindow(WmWindow* wm_window) { 79 MoveEventHandler* MoveEventHandler::GetForWindow(aura::Window* window) {
80 return WmWindow::GetAuraWindow(wm_window)->GetProperty(kWmMoveEventHandler); 80 return window->GetProperty(kWmMoveEventHandler);
81 } 81 }
82 82
83 void MoveEventHandler::AttemptToStartDrag( 83 void MoveEventHandler::AttemptToStartDrag(
84 const gfx::Point& point_in_parent, 84 const gfx::Point& point_in_parent,
85 int window_component, 85 int window_component,
86 aura::client::WindowMoveSource source, 86 aura::client::WindowMoveSource source,
87 const base::Callback<void(bool success)>& end_closure) { 87 const base::Callback<void(bool success)>& end_closure) {
88 toplevel_window_event_handler_.AttemptToStartDrag( 88 toplevel_window_event_handler_.AttemptToStartDrag(
89 wm_window_, point_in_parent, window_component, source, 89 window_, point_in_parent, window_component, source,
90 base::Bind(&OnMoveLoopCompleted, end_closure)); 90 base::Bind(&OnMoveLoopCompleted, end_closure));
91 } 91 }
92 92
93 bool MoveEventHandler::IsDragInProgress() { 93 bool MoveEventHandler::IsDragInProgress() {
94 return toplevel_window_event_handler_.is_drag_in_progress(); 94 return toplevel_window_event_handler_.is_drag_in_progress();
95 } 95 }
96 96
97 void MoveEventHandler::RevertDrag() { 97 void MoveEventHandler::RevertDrag() {
98 toplevel_window_event_handler_.RevertDrag(); 98 toplevel_window_event_handler_.RevertDrag();
99 } 99 }
100 100
101 void MoveEventHandler::Detach() { 101 void MoveEventHandler::Detach() {
102 if (!wm_window_) 102 if (!window_)
103 return; 103 return;
104 104
105 wm_window_->aura_window()->RemoveObserver(this); 105 window_->RemoveObserver(this);
106 wm_window_->aura_window()->RemovePreTargetHandler(this); 106 window_->RemovePreTargetHandler(this);
107 wm_window_->aura_window()->ClearProperty(kWmMoveEventHandler); 107 window_->ClearProperty(kWmMoveEventHandler);
108 wm_window_ = nullptr; 108 window_ = nullptr;
109 } 109 }
110 110
111 WorkspaceEventHandlerMus* MoveEventHandler::GetWorkspaceEventHandlerMus() { 111 WorkspaceEventHandlerMus* MoveEventHandler::GetWorkspaceEventHandlerMus() {
112 if (!wm_window_->GetParent()) 112 if (!window_->parent())
113 return nullptr; 113 return nullptr;
114 114
115 return WorkspaceEventHandlerMus::Get(wm_window_->aura_window()->parent()); 115 return WorkspaceEventHandlerMus::Get(window_->parent());
116 } 116 }
117 117
118 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) { 118 void MoveEventHandler::OnMouseEvent(ui::MouseEvent* event) {
119 toplevel_window_event_handler_.OnMouseEvent(event, wm_window_); 119 toplevel_window_event_handler_.OnMouseEvent(event, window_);
120 if (!toplevel_window_event_handler_.is_drag_in_progress() && 120 if (!toplevel_window_event_handler_.is_drag_in_progress() &&
121 (event->type() == ui::ET_POINTER_MOVED || 121 (event->type() == ui::ET_POINTER_MOVED ||
122 event->type() == ui::ET_MOUSE_MOVED)) { 122 event->type() == ui::ET_MOUSE_MOVED)) {
123 const int hit_test_location = 123 const int hit_test_location =
124 wm_window_->GetNonClientComponent(event->location()); 124 wm::GetNonClientComponent(window_, event->location());
125 window_manager_client_->SetNonClientCursor( 125 window_manager_client_->SetNonClientCursor(
126 wm_window_->aura_window(), 126 window_, ui::CursorData(CursorForWindowComponent(hit_test_location)));
127 ui::CursorData(CursorForWindowComponent(hit_test_location)));
128 } 127 }
129 128
130 WorkspaceEventHandlerMus* workspace_event_handler = 129 WorkspaceEventHandlerMus* workspace_event_handler =
131 GetWorkspaceEventHandlerMus(); 130 GetWorkspaceEventHandlerMus();
132 if (workspace_event_handler) 131 if (workspace_event_handler)
133 workspace_event_handler->OnMouseEvent(event, wm_window_); 132 workspace_event_handler->OnMouseEvent(event, window_);
134 } 133 }
135 134
136 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) { 135 void MoveEventHandler::OnGestureEvent(ui::GestureEvent* event) {
137 toplevel_window_event_handler_.OnGestureEvent(event, wm_window_); 136 toplevel_window_event_handler_.OnGestureEvent(event, window_);
138 137
139 WorkspaceEventHandlerMus* workspace_event_handler = 138 WorkspaceEventHandlerMus* workspace_event_handler =
140 GetWorkspaceEventHandlerMus(); 139 GetWorkspaceEventHandlerMus();
141 if (workspace_event_handler) 140 if (workspace_event_handler)
142 workspace_event_handler->OnGestureEvent(event, wm_window_); 141 workspace_event_handler->OnGestureEvent(event, window_);
143 } 142 }
144 143
145 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) { 144 void MoveEventHandler::OnCancelMode(ui::CancelModeEvent* event) {
146 toplevel_window_event_handler_.RevertDrag(); 145 toplevel_window_event_handler_.RevertDrag();
147 } 146 }
148 147
149 void MoveEventHandler::OnWindowDestroying(aura::Window* window) { 148 void MoveEventHandler::OnWindowDestroying(aura::Window* window) {
150 DCHECK_EQ(wm_window_->aura_window(), window); 149 DCHECK_EQ(window_, window);
151 Detach(); 150 Detach();
152 } 151 }
153 152
154 } // namespace mus 153 } // namespace mus
155 } // namespace ash 154 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698