Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: ui/aura/mus/window_tree_client.cc

Issue 2696873002: Change OnWindowInputEvent to use display_id to find the host and update event root_location in WS. (Closed)
Patch Set: host Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // This |window| might have already been deleted by the time
1160 if (!window || !window->GetWindow()->GetHost()) { 1148 // OnWindowInputEvent is called, so we use the |display_id| to find the host
1149 // for event dispatching.
1150 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id);
1151 if (!host) {
1161 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1152 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1162 return; 1153 return;
1163 } 1154 }
1155 if (!window)
1156 window = WindowMus::Get(host->window());
sky 2017/02/15 21:16:39 If this happens I think you need to reset the even
riajiang 2017/02/22 23:06:31 Done. And updated test.
1157 DCHECK(host);
1164 1158
1165 WindowTreeHostMus* host = GetWindowTreeHostMus(window); 1159 if (event->IsKeyEvent()) {
1166 DCHECK(host); 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 }
1167 1166
1168 // The location of the event is relative to |window|. As the event is handed 1167 // 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. 1168 // to WindowTreeHost we need it to be relative to WindowTreeHost.
1170 if (event->IsLocatedEvent()) { 1169 if (event->IsLocatedEvent()) {
1171 gfx::Point host_location = event->AsLocatedEvent()->location(); 1170 gfx::Point host_location = event->AsLocatedEvent()->location();
1172 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(), 1171 aura::Window::ConvertPointToTarget(window->GetWindow(), host->window(),
1173 &host_location); 1172 &host_location);
1174 event->AsLocatedEvent()->set_location(host_location); 1173 event->AsLocatedEvent()->set_location(host_location);
1175 } 1174 }
1176 1175
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1340 } 1339 }
1341 1340
1342 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, 1341 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display,
1343 ui::mojom::WindowDataPtr root_data, 1342 ui::mojom::WindowDataPtr root_data,
1344 bool parent_drawn) { 1343 bool parent_drawn) {
1345 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); 1344 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn);
1346 } 1345 }
1347 1346
1348 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { 1347 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) {
1349 DCHECK(window_manager_delegate_); 1348 DCHECK(window_manager_delegate_);
1350 for (WindowMus* root : roots_) { 1349 WindowTreeHostMus* host = GetWindowTreeHostMusWithDisplayId(display_id);
1351 DCHECK(root->GetWindow()->GetHost()); 1350 if (host) {
1352 WindowTreeHostMus* window_tree_host = 1351 window_manager_delegate_->OnWmDisplayRemoved(host);
1353 static_cast<WindowTreeHostMus*>(root->GetWindow()->GetHost()); 1352 return;
1354 if (window_tree_host->display_id() == display_id) {
1355 window_manager_delegate_->OnWmDisplayRemoved(window_tree_host);
1356 return;
1357 }
1358 } 1353 }
1359 } 1354 }
1360 1355
1361 void WindowTreeClient::WmDisplayModified(const display::Display& display) { 1356 void WindowTreeClient::WmDisplayModified(const display::Display& display) {
1362 DCHECK(window_manager_delegate_); 1357 DCHECK(window_manager_delegate_);
1363 // TODO(sky): this should likely route to WindowTreeHost. 1358 // TODO(sky): this should likely route to WindowTreeHost.
1364 window_manager_delegate_->OnWmDisplayModified(display); 1359 window_manager_delegate_->OnWmDisplayModified(display);
1365 } 1360 }
1366 1361
1367 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1362 void WindowTreeClient::WmSetBounds(uint32_t change_id,
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1839 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) { 1834 uint32_t WindowTreeClient::CreateChangeIdForCapture(WindowMus* window) {
1840 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1835 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1841 this, capture_synchronizer_.get(), window)); 1836 this, capture_synchronizer_.get(), window));
1842 } 1837 }
1843 1838
1844 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1839 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1845 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1840 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1846 this, focus_synchronizer_.get(), window)); 1841 this, focus_synchronizer_.get(), window));
1847 } 1842 }
1848 1843
1844 WindowTreeHostMus* WindowTreeClient::GetWindowTreeHostMusWithDisplayId(
1845 int64_t display_id) {
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
1849 } // namespace aura 1856 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698