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

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2696873002: Change OnWindowInputEvent to use display_id to find the host and update event root_location in WS. (Closed)
Patch Set: root window Created 3 years, 9 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
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 const gfx::Point host_location = 155 const gfx::Point host_location =
156 gfx::ConvertPointToDIP(display.device_scale_factor(), event->location()); 156 gfx::ConvertPointToDIP(display.device_scale_factor(), event->location());
157 event->set_location(host_location); 157 event->set_location(host_location);
158 const gfx::Point root_location = gfx::ConvertPointToDIP( 158 const gfx::Point root_location = gfx::ConvertPointToDIP(
159 display.device_scale_factor(), event->root_location()); 159 display.device_scale_factor(), event->root_location());
160 event->set_root_location(root_location); 160 event->set_root_location(root_location);
161 } 161 }
162 162
163 // Set the |target| to be the target window of this |event| and send it to 163 // Set the |target| to be the target window of this |event| and send it to
164 // the EventProcessor. 164 // the EventProcessor.
165 void DispatchEventToTarget(ui::Event* event, WindowMus* target) { 165 void DispatchEventToTarget(ui::Event* event,
166 ui::Event::DispatcherApi dispatch_helper(event); 166 WindowTreeHostMus* host,
167 dispatch_helper.set_target(target->GetWindow()); 167 WindowMus* target) {
168 GetWindowTreeHostMus(target)->SendEventToProcessor(event); 168 // Set the event target if target window is not null, otherwise leave the
169 // event target empty so we can look for target window starting from root in
170 // EventProcessor.
171 if (target) {
172 ui::Event::DispatcherApi dispatch_helper(event);
173 dispatch_helper.set_target(target->GetWindow());
174 }
175 host->SendEventToProcessor(event);
169 } 176 }
170 177
171 } // namespace 178 } // namespace
172 179
173 WindowTreeClient::WindowTreeClient( 180 WindowTreeClient::WindowTreeClient(
174 service_manager::Connector* connector, 181 service_manager::Connector* connector,
175 WindowTreeClientDelegate* delegate, 182 WindowTreeClientDelegate* delegate,
176 WindowManagerDelegate* window_manager_delegate, 183 WindowManagerDelegate* window_manager_delegate,
177 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, 184 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request,
178 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 185 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1131
1125 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, 1132 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
1126 Id window_id, 1133 Id window_id,
1127 int64_t display_id, 1134 int64_t display_id,
1128 std::unique_ptr<ui::Event> event, 1135 std::unique_ptr<ui::Event> event,
1129 bool matches_pointer_watcher) { 1136 bool matches_pointer_watcher) {
1130 DCHECK(event); 1137 DCHECK(event);
1131 1138
1132 WindowMus* window = GetWindowByServerId(window_id); // May be null. 1139 WindowMus* window = GetWindowByServerId(window_id); // May be null.
1133 1140
1134 if (event->IsKeyEvent()) {
1135 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events.
1136 if (!window || !window->GetWindow()->GetHost()) {
1137 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1138 return;
1139 }
1140 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method();
1141 input_method->DispatchKeyEvent(event->AsKeyEvent(),
1142 CreateEventResultCallback(event_id));
1143 return;
1144 }
1145
1146 if (matches_pointer_watcher && has_pointer_watcher_) { 1141 if (matches_pointer_watcher && has_pointer_watcher_) {
1147 DCHECK(event->IsPointerEvent()); 1142 DCHECK(event->IsPointerEvent());
1148 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); 1143 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event));
1149 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); 1144 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent());
1150 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), 1145 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(),
1151 window ? window->GetWindow() : nullptr); 1146 window ? window->GetWindow() : nullptr);
1152 } 1147 }
1153 1148
1154 // TODO: use |display_id| to find host and send there. 1149 // This |window| might have already been deleted by the time
1155 if (!window || !window->GetWindow()->GetHost()) { 1150 // OnWindowInputEvent is called, so we use the |display_id| to find the host
1151 // for event dispatching.
1152 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id);
1153 if (!host) {
1156 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1154 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1157 return; 1155 return;
1158 } 1156 }
1159 1157
1158 if (event->IsKeyEvent()) {
1159 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events.
1160 InputMethodMus* input_method = host->input_method();
1161 input_method->DispatchKeyEvent(event->AsKeyEvent(),
1162 CreateEventResultCallback(event_id));
1163 return;
1164 }
1165
1166 // If |window| has already been deleted, update event location to use its
1167 // root location and then find the next best target window starting from root
1168 // window to dispatch the event to.
1169 if (!window && event->IsLocatedEvent()) {
1170 event->AsLocatedEvent()->set_location(
1171 event->AsLocatedEvent()->root_location());
1172 }
1173
1160 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); 1174 EventAckHandler ack_handler(CreateEventResultCallback(event_id));
1161 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or 1175 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or
1162 // ui::TouchEvent once we have proper support for pointer events. 1176 // ui::TouchEvent once we have proper support for pointer events.
1163 if (event->IsMousePointerEvent()) { 1177 if (event->IsMousePointerEvent()) {
1164 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { 1178 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) {
1165 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); 1179 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent());
1166 DispatchEventToTarget(&mapped_event, window); 1180 DispatchEventToTarget(&mapped_event, host, window);
1167 } else { 1181 } else {
1168 ui::MouseEvent mapped_event(*event->AsPointerEvent()); 1182 ui::MouseEvent mapped_event(*event->AsPointerEvent());
1169 DispatchEventToTarget(&mapped_event, window); 1183 DispatchEventToTarget(&mapped_event, host, window);
1170 } 1184 }
1171 } else if (event->IsTouchPointerEvent()) { 1185 } else if (event->IsTouchPointerEvent()) {
1172 ui::TouchEvent mapped_event(*event->AsPointerEvent()); 1186 ui::TouchEvent mapped_event(*event->AsPointerEvent());
1173 DispatchEventToTarget(&mapped_event, window); 1187 DispatchEventToTarget(&mapped_event, host, window);
1174 } else { 1188 } else {
1175 DispatchEventToTarget(event.get(), window); 1189 DispatchEventToTarget(event.get(), host, window);
1176 } 1190 }
1177 ack_handler.set_handled(event->handled()); 1191 ack_handler.set_handled(event->handled());
1178 } 1192 }
1179 1193
1180 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, 1194 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event,
1181 uint32_t window_id, 1195 uint32_t window_id,
1182 int64_t display_id) { 1196 int64_t display_id) {
1183 DCHECK(event); 1197 DCHECK(event);
1184 DCHECK(event->IsPointerEvent()); 1198 DCHECK(event->IsPointerEvent());
1185 if (!has_pointer_watcher_) 1199 if (!has_pointer_watcher_)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 } 1337 }
1324 1338
1325 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, 1339 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display,
1326 ui::mojom::WindowDataPtr root_data, 1340 ui::mojom::WindowDataPtr root_data,
1327 bool parent_drawn) { 1341 bool parent_drawn) {
1328 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); 1342 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn);
1329 } 1343 }
1330 1344
1331 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { 1345 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) {
1332 DCHECK(window_manager_delegate_); 1346 DCHECK(window_manager_delegate_);
1333 for (WindowMus* root : roots_) { 1347 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id);
1334 DCHECK(root->GetWindow()->GetHost()); 1348 if (host) {
1335 WindowTreeHostMus* window_tree_host = 1349 window_manager_delegate_->OnWmDisplayRemoved(host);
1336 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); 1350 return;
1337 if (window_tree_host->display_id() == display_id) {
1338 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host);
1339 return;
1340 }
1341 } 1351 }
1342 } 1352 }
1343 1353
1344 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1354 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1345 DCHECK(window_manager_delegate_); 1355 DCHECK(window_manager_delegate_);
1346 // TODO(sky): this should likely route to WindowTreeHost. 1356 // TODO(sky): this should likely route to WindowTreeHost.
1347 window_manager_delegate_->OnWmDisplayModified(display); 1357 window_manager_delegate_->OnWmDisplayModified(display);
1348 } 1358 }
1349 1359
1350 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1360 void WindowTreeClient::WmSetBounds(uint32_t change_id,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { 1832 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) {
1823 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1833 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1824 this, capture_synchronizer_.get(), window)); 1834 this, capture_synchronizer_.get(), window));
1825 } 1835 }
1826 1836
1827 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1837 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1828 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1838 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1829 this, focus_synchronizer_.get(), window)); 1839 this, focus_synchronizer_.get(), window));
1830 } 1840 }
1831 1841
1842 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId(
kylechar 2017/03/13 15:08:14 It looks like tonikitoo/fwang have external mode s
riajiang 2017/03/13 21:08:27 Added a TODO to find the correct WTH in external m
1843 int64_t display_id) {
1844 for (WindowMus* root : roots_) {
1845 DCHECK(root->GetWindow()->GetHost());
1846 WindowTreeHostMus* window_tree_host =
1847 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost());
1848 if (window_tree_host->display_id() == display_id)
1849 return window_tree_host;
1850 }
1851 return nullptr;
1852 }
1853
1832 } // namespace aura 1854 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698