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 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 | 1110 |
1111 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1111 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
1112 Id window_id, | 1112 Id window_id, |
1113 int64_t display_id, | 1113 int64_t display_id, |
1114 std::unique_ptr<ui::Event> event, | 1114 std::unique_ptr<ui::Event> event, |
1115 bool matches_pointer_watcher) { | 1115 bool matches_pointer_watcher) { |
1116 DCHECK(event); | 1116 DCHECK(event); |
1117 | 1117 |
1118 WindowMus* window = GetWindowByServerId(window_id); // May be null. | 1118 WindowMus* window = GetWindowByServerId(window_id); // May be null. |
1119 | 1119 |
1120 if (event->IsKeyEvent()) { | |
1121 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
1122 if (!window || !window->GetWindow()->GetHost()) { | |
1123 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
1124 return; | |
1125 } | |
1126 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); | |
1127 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1128 CreateEventResultCallback(event_id)); | |
1129 return; | |
1130 } | |
1131 | |
1132 if (matches_pointer_watcher && has_pointer_watcher_) { | 1120 if (matches_pointer_watcher && has_pointer_watcher_) { |
1133 DCHECK(event->IsPointerEvent()); | 1121 DCHECK(event->IsPointerEvent()); |
1134 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); | 1122 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event)); |
1135 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); | 1123 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent()); |
1136 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), | 1124 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(), |
1137 window ? window->GetWindow() : nullptr); | 1125 window ? window->GetWindow() : nullptr); |
1138 } | 1126 } |
1139 | 1127 |
1140 // TODO: use |display_id| to find host and send there. | 1128 // This |window| might have already been deleted by the time |
1141 if (!window || !window->GetWindow()->GetHost()) { | 1129 // OnWindowInputEvent is called, so we use the |display_id| to find the host |
1130 // for event dispatching. | |
1131 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); | |
1132 if (!host) { | |
1142 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | 1133 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
1143 return; | 1134 return; |
1144 } | 1135 } |
1136 if (!window) { | |
1137 window = WindowMus::Get(host->window()); | |
1138 if (event->IsLocatedEvent()) { | |
1139 event->AsLocatedEvent()->set_location( | |
1140 event->AsLocatedEvent()->root_location()); | |
1141 } | |
1142 } | |
1143 DCHECK(host); | |
sky
2017/02/23 00:56:27
Remove this DCHECK given the conditional for !host
riajiang
2017/02/23 04:06:05
Done.
| |
1145 | 1144 |
1146 WindowTreeHostMus* host = GetWindowTreeHostMus(window); | 1145 if (event->IsKeyEvent()) { |
sky
2017/02/23 00:56:27
Move this above 1136 as the conditional on 1136 is
riajiang
2017/02/23 04:06:05
Done.
| |
1147 DCHECK(host); | 1146 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
1147 InputMethodMus* input_method = host->input_method(); | |
1148 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
1149 CreateEventResultCallback(event_id)); | |
1150 return; | |
1151 } | |
1148 | 1152 |
1149 // The location of the event is relative to |window|. As the event is handed | 1153 // The location of the event is relative to |window|. As the event is handed |
1150 // to WindowTreeHost we need it to be relative to WindowTreeHost. | 1154 // to WindowTreeHost we need it to be relative to WindowTreeHost. |
1151 if (event->IsLocatedEvent()) { | 1155 if (event->IsLocatedEvent()) { |
1152 gfx::Point host_location = event->AsLocatedEvent()->location(); | 1156 gfx::Point host_location = event->AsLocatedEvent()->location(); |
1153 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(), | 1157 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(), |
1154 &host_location); | 1158 &host_location); |
1155 event->AsLocatedEvent()->set_location(host_location); | 1159 event->AsLocatedEvent()->set_location(host_location); |
1156 } | 1160 } |
1157 | 1161 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1321 } | 1325 } |
1322 | 1326 |
1323 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1327 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
1324 ui::mojom::WindowDataPtr root_data, | 1328 ui::mojom::WindowDataPtr root_data, |
1325 bool parent_drawn) { | 1329 bool parent_drawn) { |
1326 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1330 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
1327 } | 1331 } |
1328 | 1332 |
1329 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1333 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
1330 DCHECK(window_manager_delegate_); | 1334 DCHECK(window_manager_delegate_); |
1331 for (WindowMus* root : roots_) { | 1335 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id); |
1332 DCHECK(root->GetWindow()->GetHost()); | 1336 if (host) { |
1333 WindowTreeHostMus* window_tree_host = | 1337 window_manager_delegate_->OnWmDisplayRemoved(host); |
1334 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | 1338 return; |
1335 if (window_tree_host->display_id() == display_id) { | |
1336 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host); | |
1337 return; | |
1338 } | |
1339 } | 1339 } |
1340 } | 1340 } |
1341 | 1341 |
1342 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1342 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
1343 DCHECK(window_manager_delegate_); | 1343 DCHECK(window_manager_delegate_); |
1344 // TODO(sky): this should likely route to WindowTreeHost. | 1344 // TODO(sky): this should likely route to WindowTreeHost. |
1345 window_manager_delegate_->OnWmDisplayModified(display); | 1345 window_manager_delegate_->OnWmDisplayModified(display); |
1346 } | 1346 } |
1347 | 1347 |
1348 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1348 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1820 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { | 1820 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { |
1821 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1821 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
1822 this, capture_synchronizer_.get(), window)); | 1822 this, capture_synchronizer_.get(), window)); |
1823 } | 1823 } |
1824 | 1824 |
1825 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1825 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
1826 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1826 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
1827 this, focus_synchronizer_.get(), window)); | 1827 this, focus_synchronizer_.get(), window)); |
1828 } | 1828 } |
1829 | 1829 |
1830 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId( | |
1831 int64_t display_id) { | |
1832 for (WindowMus* root : roots_) { | |
1833 DCHECK(root->GetWindow()->GetHost()); | |
1834 WindowTreeHostMus* window_tree_host = | |
1835 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); | |
1836 if (window_tree_host->display_id() == display_id) | |
1837 return window_tree_host; | |
1838 } | |
1839 return nullptr; | |
1840 } | |
1841 | |
1830 } // namespace aura | 1842 } // namespace aura |
OLD | NEW |