Chromium Code Reviews| 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 const gfx::Point host_location = | 153 const gfx::Point host_location = |
| 154 gfx::ConvertPointToDIP(display.device_scale_factor(), event->location()); | 154 gfx::ConvertPointToDIP(display.device_scale_factor(), event->location()); |
| 155 event->set_location(host_location); | 155 event->set_location(host_location); |
| 156 const gfx::Point root_location = gfx::ConvertPointToDIP( | 156 const gfx::Point root_location = gfx::ConvertPointToDIP( |
| 157 display.device_scale_factor(), event->root_location()); | 157 display.device_scale_factor(), event->root_location()); |
| 158 event->set_root_location(root_location); | 158 event->set_root_location(root_location); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // Set the |target| to be the target window of this |event| and send it to | 161 // Set the |target| to be the target window of this |event| and send it to |
| 162 // the EventProcessor. | 162 // the EventProcessor. |
| 163 void DispatchEventToTarget(ui::Event* event, WindowMus* target) { | 163 void DispatchEventToTarget(ui::Event* event, |
| 164 ui::Event::DispatcherApi dispatch_helper(event); | 164 WindowTreeHostMus* host, |
| 165 dispatch_helper.set_target(target->GetWindow()); | 165 WindowMus* target) { |
| 166 GetWindowTreeHostMus(target)->SendEventToProcessor(event); | 166 // Set the event target if target window is not null, otherwise update event |
| 167 // location to use its root location and leave the event target empty so we | |
| 168 // can find the next best target window starting from root window to dispatch | |
| 169 // the event to in EventProcessor. | |
|
sadrul
2017/03/15 01:21:17
Merge this with the comment in 161:162
riajiang
2017/03/15 15:35:57
Done.
| |
| 170 if (target) { | |
| 171 ui::Event::DispatcherApi dispatch_helper(event); | |
| 172 dispatch_helper.set_target(target->GetWindow()); | |
| 173 } else if (event->IsLocatedEvent()) { | |
| 174 event->AsLocatedEvent()->set_location( | |
|
sadrul
2017/03/15 01:21:17
Actually, move the comment about changing the even
riajiang
2017/03/15 15:35:57
Done.
| |
| 175 event->AsLocatedEvent()->root_location()); | |
| 176 } | |
| 177 host->SendEventToProcessor(event); | |
| 167 } | 178 } |
| 168 | 179 |
| 169 } // namespace | 180 } // namespace |
| 170 | 181 |
| 171 WindowTreeClient::WindowTreeClient( | 182 WindowTreeClient::WindowTreeClient( |
| 172 service_manager::Connector* connector, | 183 service_manager::Connector* connector, |
| 173 WindowTreeClientDelegate* delegate, | 184 WindowTreeClientDelegate* delegate, |
| 174 WindowManagerDelegate* window_manager_delegate, | 185 WindowManagerDelegate* window_manager_delegate, |
| 175 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, | 186 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, |
| 176 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 187 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| (...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1121 name, transport_data.has_value() ? &transport_data.value() : nullptr); | 1132 name, transport_data.has_value() ? &transport_data.value() : nullptr); |
| 1122 } | 1133 } |
| 1123 | 1134 |
| 1124 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1135 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| 1125 Id window_id, | 1136 Id window_id, |
| 1126 int64_t display_id, | 1137 int64_t display_id, |
| 1127 std::unique_ptr<ui::Event> event, | 1138 std::unique_ptr<ui::Event> event, |
| 1128 bool matches_pointer_watcher) { | 1139 bool matches_pointer_watcher) { |
| 1129 DCHECK(event); | 1140 DCHECK(event); |
| 1130 | 1141 |
| 1131 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1142 // |window| may be null if it has already been deleted as OnWindowInputEvent |
| 1132 | 1143 // is being called asynchronously. |
| 1133 if (event->IsKeyEvent()) { | 1144 WindowMus* window = GetWindowByServerId(window_id); |
| 1134 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
| 1135 if (!window || !window->GetWindow()->GetHost()) { | |
| 1136 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
| 1137 return; | |
| 1138 } | |
| 1139 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); | |
| 1140 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
| 1141 CreateEventResultCallback(event_id)); | |
| 1142 return; | |
| 1143 } | |
| 1144 | 1145 |
| 1145 if (matches_pointer_watcher && has_pointer_watcher_) { | 1146 if (matches_pointer_watcher && has_pointer_watcher_) { |
| 1146 DCHECK(event->IsPointerEvent()); | 1147 DCHECK(event->IsPointerEvent()); |
| 1147 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); | 1148 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
| 1148 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); | 1149 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); |
| 1149 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), | 1150 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), |
| 1150 window ? window->GetWindow() : nullptr); | 1151 window ? window->GetWindow() : nullptr); |
| 1151 } | 1152 } |
| 1152 | 1153 |
| 1153 // TODO: use |display_id| to find host and send there. | 1154 // Since this |window| might have already been deleted by the time |
| 1154 if (!window || !window->GetWindow()->GetHost()) { | 1155 // OnWindowInputEvent is called, so we use the |display_id| to find the host |
|
sadrul
2017/03/15 01:21:17
s/so//
riajiang
2017/03/15 15:35:57
Done.
| |
| 1156 // for event dispatching. | |
| 1157 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); | |
|
sadrul
2017/03/15 01:21:17
Should this be:
host = window ? window->GetHost
riajiang
2017/03/15 15:35:57
Done.
| |
| 1158 if (!host) { | |
| 1155 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1159 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| 1156 return; | 1160 return; |
| 1157 } | 1161 } |
| 1158 | 1162 |
| 1163 if (event->IsKeyEvent()) { | |
| 1164 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
| 1165 InputMethodMus* input_method = host->input_method(); | |
| 1166 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
| 1167 CreateEventResultCallback(event_id)); | |
| 1168 return; | |
| 1169 } | |
| 1170 | |
| 1159 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); | 1171 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| 1160 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or | 1172 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| 1161 // ui::TouchEvent once we have proper support for pointer events. | 1173 // ui::TouchEvent once we have proper support for pointer events. |
| 1162 if (event->IsMousePointerEvent()) { | 1174 if (event->IsMousePointerEvent()) { |
| 1163 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1175 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| 1164 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); | 1176 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| 1165 DispatchEventToTarget(&mapped_event, window); | 1177 DispatchEventToTarget(&mapped_event, host, window); |
| 1166 } else { | 1178 } else { |
| 1167 ui::MouseEvent mapped_event(*event->AsPointerEvent()); | 1179 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| 1168 DispatchEventToTarget(&mapped_event, window); | 1180 DispatchEventToTarget(&mapped_event, host, window); |
| 1169 } | 1181 } |
| 1170 } else if (event->IsTouchPointerEvent()) { | 1182 } else if (event->IsTouchPointerEvent()) { |
| 1171 ui::TouchEvent mapped_event(*event->AsPointerEvent()); | 1183 ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
| 1172 DispatchEventToTarget(&mapped_event, window); | 1184 DispatchEventToTarget(&mapped_event, host, window); |
| 1173 } else { | 1185 } else { |
| 1174 DispatchEventToTarget(event.get(), window); | 1186 DispatchEventToTarget(event.get(), host, window); |
| 1175 } | 1187 } |
| 1176 ack_handler.set_handled(event->handled()); | 1188 ack_handler.set_handled(event->handled()); |
| 1177 } | 1189 } |
| 1178 | 1190 |
| 1179 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, | 1191 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
| 1180 uint32_t window_id, | 1192 uint32_t window_id, |
| 1181 int64_t display_id) { | 1193 int64_t display_id) { |
| 1182 DCHECK(event); | 1194 DCHECK(event); |
| 1183 DCHECK(event->IsPointerEvent()); | 1195 DCHECK(event->IsPointerEvent()); |
| 1184 if (!has_pointer_watcher_) | 1196 if (!has_pointer_watcher_) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1321 } | 1333 } |
| 1322 | 1334 |
| 1323 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1335 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
| 1324 ui::mojom::WindowDataPtr root_data, | 1336 ui::mojom::WindowDataPtr root_data, |
| 1325 bool parent_drawn) { | 1337 bool parent_drawn) { |
| 1326 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1338 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
| 1327 } | 1339 } |
| 1328 | 1340 |
| 1329 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1341 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
| 1330 DCHECK(window_manager_delegate_); | 1342 DCHECK(window_manager_delegate_); |
| 1331 for (WindowMus* root : roots_) { | 1343 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
| 1332 DCHECK(root->GetWindow()->GetHost()); | 1344 if (host) |
| 1333 WindowTreeHostMus* window_tree_host = | 1345 window_manager_delegate_->OnWmDisplayRemoved(host); |
| 1334 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
| 1335 if (window_tree_host->display_id() == display_id) { | |
| 1336 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host); | |
| 1337 return; | |
| 1338 } | |
| 1339 } | |
| 1340 } | 1346 } |
| 1341 | 1347 |
| 1342 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1348 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1343 DCHECK(window_manager_delegate_); | 1349 DCHECK(window_manager_delegate_); |
| 1344 // TODO(sky): this should likely route to WindowTreeHost. | 1350 // TODO(sky): this should likely route to WindowTreeHost. |
| 1345 window_manager_delegate_->OnWmDisplayModified(display); | 1351 window_manager_delegate_->OnWmDisplayModified(display); |
| 1346 } | 1352 } |
| 1347 | 1353 |
| 1348 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1354 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1349 Id window_id, | 1355 Id window_id, |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1820 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1826 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
| 1821 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1827 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1822 this, capture_synchronizer_.get(), window)); | 1828 this, capture_synchronizer_.get(), window)); |
| 1823 } | 1829 } |
| 1824 | 1830 |
| 1825 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1831 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1826 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1832 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1827 this, focus_synchronizer_.get(), window)); | 1833 this, focus_synchronizer_.get(), window)); |
| 1828 } | 1834 } |
| 1829 | 1835 |
| 1836 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( | |
| 1837 int64_t display_id) { | |
| 1838 // TODO(riajiang): Figure out how to get the correct WindowTreeHost we need | |
| 1839 // in external window mode. | |
| 1840 for (WindowMus* root : roots_) { | |
| 1841 DCHECK(root->GetWindow()->GetHost()); | |
| 1842 WindowTreeHostMus* window_tree_host = | |
| 1843 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
| 1844 if (window_tree_host->display_id() == display_id) | |
| 1845 return window_tree_host; | |
| 1846 } | |
| 1847 return nullptr; | |
| 1848 } | |
| 1849 | |
| 1830 } // namespace aura | 1850 } // namespace aura |
| OLD | NEW |