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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 name, transport_data.has_value() ? &transport_data.value() : nullptr); | 1130 name, transport_data.has_value() ? &transport_data.value() : nullptr); |
1124 } | 1131 } |
1125 | 1132 |
1126 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1133 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
1127 Id window_id, | 1134 Id window_id, |
1128 int64_t display_id, | 1135 int64_t display_id, |
1129 std::unique_ptr<ui::Event> event, | 1136 std::unique_ptr<ui::Event> event, |
1130 bool matches_pointer_watcher) { | 1137 bool matches_pointer_watcher) { |
1131 DCHECK(event); | 1138 DCHECK(event); |
1132 | 1139 |
1133 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1140 WindowMus* window = GetWindowByServerId(window_id); // May be null. |
sadrul
2017/03/14 16:12:17
Update the comment to explain when this can be nul
riajiang
2017/03/14 19:03:26
Done.
| |
1134 | 1141 |
1135 if (event->IsKeyEvent()) { | |
1136 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
1137 if (!window || !window->GetWindow()->GetHost()) { | |
1138 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
1139 return; | |
1140 } | |
1141 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); | |
1142 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1143 CreateEventResultCallback(event_id)); | |
1144 return; | |
1145 } | |
1146 | |
1147 if (matches_pointer_watcher && has_pointer_watcher_) { | 1142 if (matches_pointer_watcher && has_pointer_watcher_) { |
1148 DCHECK(event->IsPointerEvent()); | 1143 DCHECK(event->IsPointerEvent()); |
1149 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); | 1144 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
1150 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); | 1145 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); |
1151 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), | 1146 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), |
1152 window ? window->GetWindow() : nullptr); | 1147 window ? window->GetWindow() : nullptr); |
1153 } | 1148 } |
1154 | 1149 |
1155 // TODO: use |display_id| to find host and send there. | 1150 // This |window| might have already been deleted by the time |
1156 if (!window || !window->GetWindow()->GetHost()) { | 1151 // OnWindowInputEvent is called, so we use the |display_id| to find the host |
1152 // for event dispatching. | |
1153 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); | |
1154 if (!host) { | |
1157 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1155 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
1158 return; | 1156 return; |
1159 } | 1157 } |
1160 | 1158 |
1159 if (event->IsKeyEvent()) { | |
1160 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
1161 InputMethodMus* input_method = host->input_method(); | |
1162 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1163 CreateEventResultCallback(event_id)); | |
1164 return; | |
1165 } | |
1166 | |
1167 // If |window| has already been deleted, update event location to use its | |
1168 // root location and then find the next best target window starting from root | |
1169 // window to dispatch the event to. | |
1170 if (!window && event->IsLocatedEvent()) { | |
1171 event->AsLocatedEvent()->set_location( | |
1172 event->AsLocatedEvent()->root_location()); | |
1173 } | |
sadrul
2017/03/14 16:12:16
Actually, can this happen in DispatchEventToTarget
riajiang
2017/03/14 19:03:26
Done.
| |
1174 | |
1161 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); | 1175 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
1162 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or | 1176 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
1163 // ui::TouchEvent once we have proper support for pointer events. | 1177 // ui::TouchEvent once we have proper support for pointer events. |
1164 if (event->IsMousePointerEvent()) { | 1178 if (event->IsMousePointerEvent()) { |
1165 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1179 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
1166 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); | 1180 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
1167 DispatchEventToTarget(&mapped_event, window); | 1181 DispatchEventToTarget(&mapped_event, host, window); |
1168 } else { | 1182 } else { |
1169 ui::MouseEvent mapped_event(*event->AsPointerEvent()); | 1183 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
1170 DispatchEventToTarget(&mapped_event, window); | 1184 DispatchEventToTarget(&mapped_event, host, window); |
1171 } | 1185 } |
1172 } else if (event->IsTouchPointerEvent()) { | 1186 } else if (event->IsTouchPointerEvent()) { |
1173 ui::TouchEvent mapped_event(*event->AsPointerEvent()); | 1187 ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
1174 DispatchEventToTarget(&mapped_event, window); | 1188 DispatchEventToTarget(&mapped_event, host, window); |
1175 } else { | 1189 } else { |
1176 DispatchEventToTarget(event.get(), window); | 1190 DispatchEventToTarget(event.get(), host, window); |
1177 } | 1191 } |
1178 ack_handler.set_handled(event->handled()); | 1192 ack_handler.set_handled(event->handled()); |
1179 } | 1193 } |
1180 | 1194 |
1181 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, | 1195 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
1182 uint32_t window_id, | 1196 uint32_t window_id, |
1183 int64_t display_id) { | 1197 int64_t display_id) { |
1184 DCHECK(event); | 1198 DCHECK(event); |
1185 DCHECK(event->IsPointerEvent()); | 1199 DCHECK(event->IsPointerEvent()); |
1186 if (!has_pointer_watcher_) | 1200 if (!has_pointer_watcher_) |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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; |
sadrul
2017/03/14 16:12:16
Don't need return. When it's removed, don't need t
riajiang
2017/03/14 19:03:26
Right! Done.
| |
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 Loading... | |
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( | |
1843 int64_t display_id) { | |
1844 // TODO(riajiang): Figure out how to get the correct WindowTreeHost we need | |
1845 // in external window mode. | |
1846 for (WindowMus* root : roots_) { | |
1847 DCHECK(root->GetWindow()->GetHost()); | |
1848 WindowTreeHostMus* window_tree_host = | |
1849 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
1850 if (window_tree_host->display_id() == display_id) | |
1851 return window_tree_host; | |
1852 } | |
1853 return nullptr; | |
1854 } | |
1855 | |
1832 } // namespace aura | 1856 } // namespace aura |
OLD | NEW |