OLD | NEW |
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 return; | 153 return; |
154 } | 154 } |
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| if it is not null, |
164 // the EventProcessor. | 164 // otherwise update event location and leave the event target empty, and send |
165 void DispatchEventToTarget(ui::Event* event, WindowMus* target) { | 165 // the |event| to the EventProcessor. |
166 ui::Event::DispatcherApi dispatch_helper(event); | 166 void DispatchEventToTarget(ui::Event* event, |
167 dispatch_helper.set_target(target->GetWindow()); | 167 WindowTreeHostMus* host, |
168 GetWindowTreeHostMus(target)->SendEventToProcessor(event); | 168 WindowMus* target) { |
| 169 if (target) { |
| 170 ui::Event::DispatcherApi dispatch_helper(event); |
| 171 dispatch_helper.set_target(target->GetWindow()); |
| 172 } else if (event->IsLocatedEvent()) { |
| 173 // The target window specified by the window server no longer exists. So it |
| 174 // is necessary to find the target using the local event targeters. For |
| 175 // that to work correctly, the event-location needs to be in the root |
| 176 // window's coordinate space. |
| 177 event->AsLocatedEvent()->set_location( |
| 178 event->AsLocatedEvent()->root_location()); |
| 179 } |
| 180 host->SendEventToProcessor(event); |
169 } | 181 } |
170 | 182 |
171 } // namespace | 183 } // namespace |
172 | 184 |
173 WindowTreeClient::WindowTreeClient( | 185 WindowTreeClient::WindowTreeClient( |
174 service_manager::Connector* connector, | 186 service_manager::Connector* connector, |
175 WindowTreeClientDelegate* delegate, | 187 WindowTreeClientDelegate* delegate, |
176 WindowManagerDelegate* window_manager_delegate, | 188 WindowManagerDelegate* window_manager_delegate, |
177 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, | 189 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, |
178 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 190 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 name, transport_data.has_value() ? &transport_data.value() : nullptr); | 1161 name, transport_data.has_value() ? &transport_data.value() : nullptr); |
1150 } | 1162 } |
1151 | 1163 |
1152 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1164 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
1153 Id window_id, | 1165 Id window_id, |
1154 int64_t display_id, | 1166 int64_t display_id, |
1155 std::unique_ptr<ui::Event> event, | 1167 std::unique_ptr<ui::Event> event, |
1156 bool matches_pointer_watcher) { | 1168 bool matches_pointer_watcher) { |
1157 DCHECK(event); | 1169 DCHECK(event); |
1158 | 1170 |
1159 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1171 // |window| may be null if it has already been deleted as OnWindowInputEvent |
1160 | 1172 // is being called asynchronously. |
1161 if (event->IsKeyEvent()) { | 1173 WindowMus* window = GetWindowByServerId(window_id); |
1162 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
1163 if (!window || !window->GetWindow()->GetHost()) { | |
1164 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
1165 return; | |
1166 } | |
1167 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); | |
1168 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1169 CreateEventResultCallback(event_id)); | |
1170 return; | |
1171 } | |
1172 | 1174 |
1173 if (matches_pointer_watcher && has_pointer_watcher_) { | 1175 if (matches_pointer_watcher && has_pointer_watcher_) { |
1174 DCHECK(event->IsPointerEvent()); | 1176 DCHECK(event->IsPointerEvent()); |
1175 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); | 1177 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
1176 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); | 1178 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); |
1177 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), | 1179 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), |
1178 window ? window->GetWindow() : nullptr); | 1180 window ? window->GetWindow() : nullptr); |
1179 } | 1181 } |
1180 | 1182 |
1181 // TODO: use |display_id| to find host and send there. | 1183 // Since this |window| might have already been deleted by the time |
1182 if (!window || !window->GetWindow()->GetHost()) { | 1184 // OnWindowInputEvent is called, we use the |display_id| to find the host |
| 1185 // for event dispatching. |
| 1186 WindowTreeHostMus* host = window |
| 1187 ? GetWindowTreeHostMus(window) |
| 1188 : GetWindowTreeHostMusWithDisplayId(display_id); |
| 1189 if (!host) { |
1183 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1190 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
1184 return; | 1191 return; |
1185 } | 1192 } |
1186 | 1193 |
| 1194 if (event->IsKeyEvent()) { |
| 1195 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| 1196 InputMethodMus* input_method = host->input_method(); |
| 1197 input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| 1198 CreateEventResultCallback(event_id)); |
| 1199 return; |
| 1200 } |
| 1201 |
1187 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); | 1202 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
1188 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or | 1203 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
1189 // ui::TouchEvent once we have proper support for pointer events. | 1204 // ui::TouchEvent once we have proper support for pointer events. |
1190 if (event->IsMousePointerEvent()) { | 1205 if (event->IsMousePointerEvent()) { |
1191 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1206 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
1192 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); | 1207 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
1193 DispatchEventToTarget(&mapped_event, window); | 1208 DispatchEventToTarget(&mapped_event, host, window); |
1194 } else { | 1209 } else { |
1195 ui::MouseEvent mapped_event(*event->AsPointerEvent()); | 1210 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
1196 DispatchEventToTarget(&mapped_event, window); | 1211 DispatchEventToTarget(&mapped_event, host, window); |
1197 } | 1212 } |
1198 } else if (event->IsTouchPointerEvent()) { | 1213 } else if (event->IsTouchPointerEvent()) { |
1199 ui::TouchEvent mapped_event(*event->AsPointerEvent()); | 1214 ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
1200 DispatchEventToTarget(&mapped_event, window); | 1215 DispatchEventToTarget(&mapped_event, host, window); |
1201 } else { | 1216 } else { |
1202 DispatchEventToTarget(event.get(), window); | 1217 DispatchEventToTarget(event.get(), host, window); |
1203 } | 1218 } |
1204 ack_handler.set_handled(event->handled()); | 1219 ack_handler.set_handled(event->handled()); |
1205 } | 1220 } |
1206 | 1221 |
1207 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, | 1222 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
1208 uint32_t window_id, | 1223 uint32_t window_id, |
1209 int64_t display_id) { | 1224 int64_t display_id) { |
1210 DCHECK(event); | 1225 DCHECK(event); |
1211 DCHECK(event->IsPointerEvent()); | 1226 DCHECK(event->IsPointerEvent()); |
1212 if (!has_pointer_watcher_) | 1227 if (!has_pointer_watcher_) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 } | 1364 } |
1350 | 1365 |
1351 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1366 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
1352 ui::mojom::WindowDataPtr root_data, | 1367 ui::mojom::WindowDataPtr root_data, |
1353 bool parent_drawn) { | 1368 bool parent_drawn) { |
1354 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1369 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
1355 } | 1370 } |
1356 | 1371 |
1357 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1372 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
1358 DCHECK(window_manager_delegate_); | 1373 DCHECK(window_manager_delegate_); |
1359 for (WindowMus* root : roots_) { | 1374 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
1360 DCHECK(root->GetWindow()->GetHost()); | 1375 if (host) |
1361 WindowTreeHostMus* window_tree_host = | 1376 window_manager_delegate_->OnWmDisplayRemoved(host); |
1362 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
1363 if (window_tree_host->display_id() == display_id) { | |
1364 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host); | |
1365 return; | |
1366 } | |
1367 } | |
1368 } | 1377 } |
1369 | 1378 |
1370 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1379 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
1371 DCHECK(window_manager_delegate_); | 1380 DCHECK(window_manager_delegate_); |
1372 // TODO(sky): this should likely route to WindowTreeHost. | 1381 // TODO(sky): this should likely route to WindowTreeHost. |
1373 window_manager_delegate_->OnWmDisplayModified(display); | 1382 window_manager_delegate_->OnWmDisplayModified(display); |
1374 } | 1383 } |
1375 | 1384 |
1376 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1385 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
1377 Id window_id, | 1386 Id window_id, |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1848 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1857 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
1849 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1858 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1850 this, capture_synchronizer_.get(), window)); | 1859 this, capture_synchronizer_.get(), window)); |
1851 } | 1860 } |
1852 | 1861 |
1853 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1862 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
1854 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1863 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
1855 this, focus_synchronizer_.get(), window)); | 1864 this, focus_synchronizer_.get(), window)); |
1856 } | 1865 } |
1857 | 1866 |
| 1867 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( |
| 1868 int64_t display_id) { |
| 1869 // TODO(riajiang): Figure out how to get the correct WindowTreeHost we need |
| 1870 // in external window mode. |
| 1871 for (WindowMus* root : roots_) { |
| 1872 DCHECK(root->GetWindow()->GetHost()); |
| 1873 WindowTreeHostMus* window_tree_host = |
| 1874 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); |
| 1875 if (window_tree_host->display_id() == display_id) |
| 1876 return window_tree_host; |
| 1877 } |
| 1878 return nullptr; |
| 1879 } |
| 1880 |
1858 } // namespace aura | 1881 } // namespace aura |
OLD | NEW |