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 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1129 | 1129 |
1130 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1130 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
1131 Id window_id, | 1131 Id window_id, |
1132 int64_t display_id, | 1132 int64_t display_id, |
1133 std::unique_ptr<ui::Event> event, | 1133 std::unique_ptr<ui::Event> event, |
1134 bool matches_pointer_watcher) { | 1134 bool matches_pointer_watcher) { |
1135 DCHECK(event); | 1135 DCHECK(event); |
1136 | 1136 |
1137 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1137 WindowMus* window = GetWindowByServerId(window_id); // May be null. |
1138 | 1138 |
1139 if (event->IsKeyEvent()) { | |
1140 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
1141 if (!window || !window->GetWindow()->GetHost()) { | |
1142 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
1143 return; | |
1144 } | |
1145 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); | |
1146 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1147 CreateEventResultCallback(event_id)); | |
1148 return; | |
1149 } | |
1150 | |
1151 if (matches_pointer_watcher && has_pointer_watcher_) { | 1139 if (matches_pointer_watcher && has_pointer_watcher_) { |
1152 DCHECK(event->IsPointerEvent()); | 1140 DCHECK(event->IsPointerEvent()); |
1153 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); | 1141 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
1154 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); | 1142 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); |
1155 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), | 1143 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), |
1156 window ? window->GetWindow() : nullptr); | 1144 window ? window->GetWindow() : nullptr); |
1157 } | 1145 } |
1158 | 1146 |
1159 // TODO: use |display_id| to find host and send there. | 1147 WindowTreeHostMus* host = nullptr; |
1160 if (!window || !window->GetWindow()->GetHost()) { | 1148 if (!window || !window->GetWindow()->GetHost()) { |
1161 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1149 // If |window| has already been deleted by the time OnWindowInputEvent is |
1150 // called, we fall back to use the |display_id| to find the window_tree_host | |
1151 // for event dispatching. | |
1152 host = GetWindowTreeHostMusWithDisplayId(display_id); | |
1153 if (!host) { | |
1154 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
1155 return; | |
1156 } | |
1157 window = WindowMus::Get(host->window()); | |
1158 } else { | |
1159 host = GetWindowTreeHostMus(window); | |
sky
2017/02/14 23:31:14
I don't think you're guaranteed the window has a h
riajiang
2017/02/15 19:35:05
Oh makes sense. I changed it to always lookup the
| |
1160 } | |
1161 DCHECK(host); | |
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)); | |
1162 return; | 1168 return; |
1163 } | 1169 } |
1164 | 1170 |
1165 WindowTreeHostMus* host = GetWindowTreeHostMus(window); | |
1166 DCHECK(host); | |
1167 | |
1168 // The location of the event is relative to |window|. As the event is handed | 1171 // The location of the event is relative to |window|. As the event is handed |
1169 // to WindowTreeHost we need it to be relative to WindowTreeHost. | 1172 // to WindowTreeHost we need it to be relative to WindowTreeHost. |
1170 if (event->IsLocatedEvent()) { | 1173 if (event->IsLocatedEvent()) { |
1171 gfx::Point host_location = event->AsLocatedEvent()->location(); | 1174 gfx::Point host_location = event->AsLocatedEvent()->location(); |
1172 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(), | 1175 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(), |
1173 &host_location); | 1176 &host_location); |
1174 event->AsLocatedEvent()->set_location(host_location); | 1177 event->AsLocatedEvent()->set_location(host_location); |
1175 } | 1178 } |
1176 | 1179 |
1177 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); | 1180 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1340 } | 1343 } |
1341 | 1344 |
1342 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1345 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
1343 ui::mojom::WindowDataPtr root_data, | 1346 ui::mojom::WindowDataPtr root_data, |
1344 bool parent_drawn) { | 1347 bool parent_drawn) { |
1345 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1348 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
1346 } | 1349 } |
1347 | 1350 |
1348 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1351 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
1349 DCHECK(window_manager_delegate_); | 1352 DCHECK(window_manager_delegate_); |
1350 for (WindowMus* root : roots_) { | 1353 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
1351 DCHECK(root->GetWindow()->GetHost()); | 1354 if (host) { |
1352 WindowTreeHostMus* window_tree_host = | 1355 window_manager_delegate_->OnWmDisplayRemoved(host); |
1353 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | 1356 return; |
1354 if (window_tree_host->display_id() == display_id) { | |
1355 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host); | |
1356 return; | |
1357 } | |
1358 } | 1357 } |
1359 } | 1358 } |
1360 | 1359 |
1361 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1360 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
1362 DCHECK(window_manager_delegate_); | 1361 DCHECK(window_manager_delegate_); |
1363 // TODO(sky): this should likely route to WindowTreeHost. | 1362 // TODO(sky): this should likely route to WindowTreeHost. |
1364 window_manager_delegate_->OnWmDisplayModified(display); | 1363 window_manager_delegate_->OnWmDisplayModified(display); |
1365 } | 1364 } |
1366 | 1365 |
1367 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1366 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1844 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1843 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
1845 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1844 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1846 this, capture_synchronizer_.get(), window)); | 1845 this, capture_synchronizer_.get(), window)); |
1847 } | 1846 } |
1848 | 1847 |
1849 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1848 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
1850 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1849 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
1851 this, focus_synchronizer_.get(), window)); | 1850 this, focus_synchronizer_.get(), window)); |
1852 } | 1851 } |
1853 | 1852 |
1853 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( | |
1854 int64_t display_id) { | |
1855 for (WindowMus* root : roots_) { | |
1856 DCHECK(root->GetWindow()->GetHost()); | |
1857 WindowTreeHostMus* window_tree_host = | |
1858 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
1859 if (window_tree_host->display_id() == display_id) | |
1860 return window_tree_host; | |
1861 } | |
1862 return nullptr; | |
1863 } | |
1864 | |
1854 } // namespace aura | 1865 } // namespace aura |
OLD | NEW |