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

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

Issue 2685883003: chromeos: converts observed pointer events to DIPs (Closed)
Patch Set: merge 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 // Helper function to get the device_scale_factor() of the display::Display 140 // Helper function to get the device_scale_factor() of the display::Display
141 // nearest to |window|. 141 // nearest to |window|.
142 float ScaleFactorForDisplay(Window* window) { 142 float ScaleFactorForDisplay(Window* window) {
143 return display::Screen::GetScreen() 143 return display::Screen::GetScreen()
144 ->GetDisplayNearestWindow(window) 144 ->GetDisplayNearestWindow(window)
145 .device_scale_factor(); 145 .device_scale_factor();
146 } 146 }
147 147
148 void ConvertEventLocationToDip(int64_t display_id, ui::LocatedEvent* event) {
149 display::Screen* screen = display::Screen::GetScreen();
150 display::Display display;
151 if (!screen->GetDisplayWithDisplayId(display_id, &display) ||
152 display.device_scale_factor() == 1.f) {
153 return;
154 }
155 const gfx::Point host_location =
156 gfx::ConvertPointToDIP(display.device_scale_factor(), event->location());
157 event->set_location(host_location);
158 const gfx::Point root_location = gfx::ConvertPointToDIP(
159 display.device_scale_factor(), event->root_location());
160 event->set_root_location(root_location);
161 }
162
148 } // namespace 163 } // namespace
149 164
150 WindowTreeClient::WindowTreeClient( 165 WindowTreeClient::WindowTreeClient(
151 service_manager::Connector* connector, 166 service_manager::Connector* connector,
152 WindowTreeClientDelegate* delegate, 167 WindowTreeClientDelegate* delegate,
153 WindowManagerDelegate* window_manager_delegate, 168 WindowManagerDelegate* window_manager_delegate,
154 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, 169 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request,
155 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 170 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
156 : connector_(connector), 171 : connector_(connector),
157 client_id_(0), 172 client_id_(0),
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 InFlightPropertyChange new_change(window, name, std::move(data)); 1122 InFlightPropertyChange new_change(window, name, std::move(data));
1108 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1123 if (ApplyServerChangeToExistingInFlightChange(new_change))
1109 return; 1124 return;
1110 1125
1111 window->SetPropertyFromServer( 1126 window->SetPropertyFromServer(
1112 name, transport_data.has_value() ? &transport_data.value() : nullptr); 1127 name, transport_data.has_value() ? &transport_data.value() : nullptr);
1113 } 1128 }
1114 1129
1115 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, 1130 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
1116 Id window_id, 1131 Id window_id,
1132 int64_t display_id,
1117 std::unique_ptr<ui::Event> event, 1133 std::unique_ptr<ui::Event> event,
1118 bool matches_pointer_watcher) { 1134 bool matches_pointer_watcher) {
1119 DCHECK(event); 1135 DCHECK(event);
1120 1136
1121 WindowMus* window = GetWindowByServerId(window_id); // May be null. 1137 WindowMus* window = GetWindowByServerId(window_id); // May be null.
1122 1138
1123 if (event->IsKeyEvent()) { 1139 if (event->IsKeyEvent()) {
1124 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. 1140 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events.
1125 if (!window || !window->GetWindow()->GetHost()) { 1141 if (!window || !window->GetWindow()->GetHost()) {
1126 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1142 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1127 return; 1143 return;
1128 } 1144 }
1129 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method(); 1145 InputMethodMus* input_method = GetWindowTreeHostMus(window)->input_method();
1130 input_method->DispatchKeyEvent(event->AsKeyEvent(), 1146 input_method->DispatchKeyEvent(event->AsKeyEvent(),
1131 CreateEventResultCallback(event_id)); 1147 CreateEventResultCallback(event_id));
1132 return; 1148 return;
1133 } 1149 }
1134 1150
1135 if (matches_pointer_watcher && has_pointer_watcher_) { 1151 if (matches_pointer_watcher && has_pointer_watcher_) {
1136 DCHECK(event->IsPointerEvent()); 1152 DCHECK(event->IsPointerEvent());
1137 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), 1153 std::unique_ptr<ui::Event> event_in_dip(ui::Event::Clone(*event));
1154 ConvertEventLocationToDip(display_id, event_in_dip->AsLocatedEvent());
1155 delegate_->OnPointerEventObserved(*event_in_dip->AsPointerEvent(),
1138 window ? window->GetWindow() : nullptr); 1156 window ? window->GetWindow() : nullptr);
1139 } 1157 }
1140 1158
1141 // TODO: deal with no window or host here. This could happen if during 1159 // TODO: use |display_id| to find host and send there.
1142 // dispatch a window is deleted or moved. In either case we still need to
1143 // dispatch. Most likely need the display id.
1144 if (!window || !window->GetWindow()->GetHost()) { 1160 if (!window || !window->GetWindow()->GetHost()) {
1145 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); 1161 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED);
1146 return; 1162 return;
1147 } 1163 }
1148 1164
1149 WindowTreeHostMus* host = GetWindowTreeHostMus(window); 1165 WindowTreeHostMus* host = GetWindowTreeHostMus(window);
1150 DCHECK(host); 1166 DCHECK(host);
1151 1167
1152 // The location of the event is relative to |window|. As the event is handed 1168 // The location of the event is relative to |window|. As the event is handed
1153 // to WindowTreeHost we need it to be relative to WindowTreeHost. 1169 // to WindowTreeHost we need it to be relative to WindowTreeHost.
(...skipping 18 matching lines...) Expand all
1172 } else if (event->IsTouchPointerEvent()) { 1188 } else if (event->IsTouchPointerEvent()) {
1173 ui::TouchEvent mapped_event(*event->AsPointerEvent()); 1189 ui::TouchEvent mapped_event(*event->AsPointerEvent());
1174 host->SendEventToProcessor(&mapped_event); 1190 host->SendEventToProcessor(&mapped_event);
1175 } else { 1191 } else {
1176 host->SendEventToProcessor(event.get()); 1192 host->SendEventToProcessor(event.get());
1177 } 1193 }
1178 ack_handler.set_handled(event->handled()); 1194 ack_handler.set_handled(event->handled());
1179 } 1195 }
1180 1196
1181 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, 1197 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event,
1182 uint32_t window_id) { 1198 uint32_t window_id,
1199 int64_t display_id) {
1183 DCHECK(event); 1200 DCHECK(event);
1184 DCHECK(event->IsPointerEvent()); 1201 DCHECK(event->IsPointerEvent());
1185 if (!has_pointer_watcher_) 1202 if (!has_pointer_watcher_)
1186 return; 1203 return;
1187 1204
1205 ConvertEventLocationToDip(display_id, event->AsLocatedEvent());
1188 WindowMus* target_window = GetWindowByServerId(window_id); 1206 WindowMus* target_window = GetWindowByServerId(window_id);
1189 delegate_->OnPointerEventObserved( 1207 delegate_->OnPointerEventObserved(
1190 *event->AsPointerEvent(), 1208 *event->AsPointerEvent(),
1191 target_window ? target_window->GetWindow() : nullptr); 1209 target_window ? target_window->GetWindow() : nullptr);
1192 } 1210 }
1193 1211
1194 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { 1212 void WindowTreeClient::OnWindowFocused(Id focused_window_id) {
1195 WindowMus* focused_window = GetWindowByServerId(focused_window_id); 1213 WindowMus* focused_window = GetWindowByServerId(focused_window_id);
1196 InFlightFocusChange new_change(this, focus_synchronizer_.get(), 1214 InFlightFocusChange new_change(this, focus_synchronizer_.get(),
1197 focused_window); 1215 focused_window);
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( 1836 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>(
1819 this, capture_synchronizer_.get(), window)); 1837 this, capture_synchronizer_.get(), window));
1820 } 1838 }
1821 1839
1822 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { 1840 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) {
1823 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( 1841 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>(
1824 this, focus_synchronizer_.get(), window)); 1842 this, focus_synchronizer_.get(), window));
1825 } 1843 }
1826 1844
1827 } // namespace aura 1845 } // 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