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

Side by Side Diff: ui/events/mojo/event_struct_traits.cc

Issue 2301593002: Add POINTER_WHEEL_CHANGED event to mojo. (Closed)
Patch Set: rebase Created 4 years, 3 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/events/mojo/event_constants.mojom ('k') | ui/events/mojo/struct_traits_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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/events/mojo/event_struct_traits.h" 5 #include "ui/events/mojo/event_struct_traits.h"
6 6
7 #include "ui/events/event.h" 7 #include "ui/events/event.h"
8 #include "ui/events/event_utils.h" 8 #include "ui/events/event_utils.h"
9 #include "ui/events/keycodes/dom/keycode_converter.h" 9 #include "ui/events/keycodes/dom/keycode_converter.h"
10 #include "ui/events/mojo/event_constants.mojom.h" 10 #include "ui/events/mojo/event_constants.mojom.h"
11 11
12 namespace mojo { 12 namespace mojo {
13 namespace { 13 namespace {
14 14
15 ui::mojom::EventType UIEventTypeToMojo(ui::EventType type) { 15 ui::mojom::EventType UIEventTypeToMojo(ui::EventType type) {
16 switch (type) { 16 switch (type) {
17 case ui::ET_POINTER_DOWN: 17 case ui::ET_POINTER_DOWN:
18 return ui::mojom::EventType::POINTER_DOWN; 18 return ui::mojom::EventType::POINTER_DOWN;
19 19
20 case ui::ET_POINTER_MOVED: 20 case ui::ET_POINTER_MOVED:
21 return ui::mojom::EventType::POINTER_MOVE; 21 return ui::mojom::EventType::POINTER_MOVE;
22 22
23 case ui::ET_POINTER_EXITED: 23 case ui::ET_POINTER_EXITED:
24 return ui::mojom::EventType::MOUSE_EXIT; 24 return ui::mojom::EventType::MOUSE_EXIT;
25 25
26 case ui::ET_MOUSEWHEEL:
27 return ui::mojom::EventType::WHEEL;
28
29 case ui::ET_POINTER_UP: 26 case ui::ET_POINTER_UP:
30 return ui::mojom::EventType::POINTER_UP; 27 return ui::mojom::EventType::POINTER_UP;
31 28
32 case ui::ET_POINTER_CANCELLED: 29 case ui::ET_POINTER_CANCELLED:
33 return ui::mojom::EventType::POINTER_CANCEL; 30 return ui::mojom::EventType::POINTER_CANCEL;
34 31
32 case ui::ET_POINTER_WHEEL_CHANGED:
33 return ui::mojom::EventType::POINTER_WHEEL_CHANGED;
34
35 case ui::ET_KEY_PRESSED: 35 case ui::ET_KEY_PRESSED:
36 return ui::mojom::EventType::KEY_PRESSED; 36 return ui::mojom::EventType::KEY_PRESSED;
37 37
38 case ui::ET_KEY_RELEASED: 38 case ui::ET_KEY_RELEASED:
39 return ui::mojom::EventType::KEY_RELEASED; 39 return ui::mojom::EventType::KEY_RELEASED;
40 40
41 default: 41 default:
42 break; 42 break;
43 } 43 }
44 return ui::mojom::EventType::UNKNOWN; 44 return ui::mojom::EventType::UNKNOWN;
45 } 45 }
46 46
47 ui::EventType MojoPointerEventTypeToUIEvent(ui::mojom::EventType action) { 47 ui::EventType MojoPointerEventTypeToUIEvent(ui::mojom::EventType action) {
48 switch (action) { 48 switch (action) {
49 case ui::mojom::EventType::POINTER_DOWN: 49 case ui::mojom::EventType::POINTER_DOWN:
50 return ui::ET_POINTER_DOWN; 50 return ui::ET_POINTER_DOWN;
51 51
52 case ui::mojom::EventType::POINTER_UP: 52 case ui::mojom::EventType::POINTER_UP:
53 return ui::ET_POINTER_UP; 53 return ui::ET_POINTER_UP;
54 54
55 case ui::mojom::EventType::POINTER_MOVE: 55 case ui::mojom::EventType::POINTER_MOVE:
56 return ui::ET_POINTER_MOVED; 56 return ui::ET_POINTER_MOVED;
57 57
58 case ui::mojom::EventType::POINTER_CANCEL: 58 case ui::mojom::EventType::POINTER_CANCEL:
59 return ui::ET_POINTER_CANCELLED; 59 return ui::ET_POINTER_CANCELLED;
60 60
61 case ui::mojom::EventType::MOUSE_EXIT: 61 case ui::mojom::EventType::MOUSE_EXIT:
62 return ui::ET_POINTER_EXITED; 62 return ui::ET_POINTER_EXITED;
63 63
64 case ui::mojom::EventType::POINTER_WHEEL_CHANGED:
65 return ui::ET_POINTER_WHEEL_CHANGED;
66
64 default: 67 default:
65 NOTREACHED(); 68 NOTREACHED();
66 } 69 }
67 70
68 return ui::ET_UNKNOWN; 71 return ui::ET_UNKNOWN;
69 } 72 }
70 73
71 } // namespace 74 } // namespace
72 75
73 static_assert(ui::mojom::kEventFlagNone == static_cast<int32_t>(ui::EF_NONE), 76 static_assert(ui::mojom::kEventFlagNone == static_cast<int32_t>(ui::EF_NONE),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 key_event->GetLocatedWindowsKeyboardCode()); 154 key_event->GetLocatedWindowsKeyboardCode());
152 key_data->text = key_event->GetText(); 155 key_data->text = key_event->GetText();
153 key_data->unmodified_text = key_event->GetUnmodifiedText(); 156 key_data->unmodified_text = key_event->GetUnmodifiedText();
154 157
155 return key_data; 158 return key_data;
156 } 159 }
157 160
158 ui::mojom::PointerDataPtr 161 ui::mojom::PointerDataPtr
159 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::pointer_data( 162 StructTraits<ui::mojom::EventDataView, EventUniquePtr>::pointer_data(
160 const EventUniquePtr& event) { 163 const EventUniquePtr& event) {
161 if (!event->IsPointerEvent() && !event->IsMouseWheelEvent()) 164 if (!event->IsPointerEvent())
162 return nullptr; 165 return nullptr;
163 166
167 const ui::PointerEvent* pointer_event = event->AsPointerEvent();
164 ui::mojom::PointerDataPtr pointer_data(ui::mojom::PointerData::New()); 168 ui::mojom::PointerDataPtr pointer_data(ui::mojom::PointerData::New());
165 169 pointer_data->pointer_id = pointer_event->pointer_id();
166 const ui::PointerDetails* pointer_details = nullptr; 170 pointer_data->changed_button_flags = pointer_event->changed_button_flags();
167 if (event->IsPointerEvent()) { 171 const ui::PointerDetails* pointer_details = &pointer_event->pointer_details();
168 const ui::PointerEvent* pointer_event = event->AsPointerEvent();
169 pointer_data->pointer_id = pointer_event->pointer_id();
170 pointer_data->changed_button_flags = pointer_event->changed_button_flags();
171 pointer_details = &pointer_event->pointer_details();
172 } else {
173 const ui::MouseWheelEvent* wheel_event = event->AsMouseWheelEvent();
174 pointer_data->pointer_id = ui::PointerEvent::kMousePointerId;
175 pointer_details = &wheel_event->pointer_details();
176 }
177 172
178 switch (pointer_details->pointer_type) { 173 switch (pointer_details->pointer_type) {
179 case ui::EventPointerType::POINTER_TYPE_MOUSE: 174 case ui::EventPointerType::POINTER_TYPE_MOUSE:
180 pointer_data->kind = ui::mojom::PointerKind::MOUSE; 175 pointer_data->kind = ui::mojom::PointerKind::MOUSE;
181 break; 176 break;
182 case ui::EventPointerType::POINTER_TYPE_TOUCH: 177 case ui::EventPointerType::POINTER_TYPE_TOUCH:
183 pointer_data->kind = ui::mojom::PointerKind::TOUCH; 178 pointer_data->kind = ui::mojom::PointerKind::TOUCH;
184 break; 179 break;
185 default: 180 default:
186 NOTREACHED(); 181 NOTREACHED();
(...skipping 14 matching lines...) Expand all
201 // TODO(rjkroege): Adjust brush data appropriately for Android. 196 // TODO(rjkroege): Adjust brush data appropriately for Android.
202 197
203 ui::mojom::LocationDataPtr location_data(ui::mojom::LocationData::New()); 198 ui::mojom::LocationDataPtr location_data(ui::mojom::LocationData::New());
204 const ui::LocatedEvent* located_event = event->AsLocatedEvent(); 199 const ui::LocatedEvent* located_event = event->AsLocatedEvent();
205 location_data->x = located_event->location_f().x(); 200 location_data->x = located_event->location_f().x();
206 location_data->y = located_event->location_f().y(); 201 location_data->y = located_event->location_f().y();
207 location_data->screen_x = located_event->root_location_f().x(); 202 location_data->screen_x = located_event->root_location_f().x();
208 location_data->screen_y = located_event->root_location_f().y(); 203 location_data->screen_y = located_event->root_location_f().y();
209 pointer_data->location = std::move(location_data); 204 pointer_data->location = std::move(location_data);
210 205
211 if (event->IsMouseWheelEvent()) { 206 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) {
212 const ui::MouseWheelEvent* wheel_event = event->AsMouseWheelEvent();
213
214 ui::mojom::WheelDataPtr wheel_data(ui::mojom::WheelData::New()); 207 ui::mojom::WheelDataPtr wheel_data(ui::mojom::WheelData::New());
215 208
216 // TODO(rjkroege): Support page scrolling on windows by directly 209 // TODO(rjkroege): Support page scrolling on windows by directly
217 // cracking into a mojo event when the native event is available. 210 // cracking into a mojo event when the native event is available.
218 wheel_data->mode = ui::mojom::WheelMode::LINE; 211 wheel_data->mode = ui::mojom::WheelMode::LINE;
219 // TODO(rjkroege): Support precise scrolling deltas. 212 // TODO(rjkroege): Support precise scrolling deltas.
220 213
221 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 && 214 if ((event->flags() & ui::EF_SHIFT_DOWN) != 0 &&
222 wheel_event->x_offset() == 0) { 215 pointer_details->offset.x() == 0) {
223 wheel_data->delta_x = wheel_event->y_offset(); 216 wheel_data->delta_x = pointer_details->offset.y();
224 wheel_data->delta_y = 0; 217 wheel_data->delta_y = 0;
225 wheel_data->delta_z = 0; 218 wheel_data->delta_z = 0;
226 } else { 219 } else {
227 // TODO(rjkroege): support z in ui::Events. 220 // TODO(rjkroege): support z in ui::Events.
228 wheel_data->delta_x = wheel_event->x_offset(); 221 wheel_data->delta_x = pointer_details->offset.x();
229 wheel_data->delta_y = wheel_event->y_offset(); 222 wheel_data->delta_y = pointer_details->offset.y();
230 wheel_data->delta_z = 0; 223 wheel_data->delta_z = 0;
231 } 224 }
232 pointer_data->wheel_data = std::move(wheel_data); 225 pointer_data->wheel_data = std::move(wheel_data);
233 } 226 }
234 227
235 return pointer_data; 228 return pointer_data;
236 } 229 }
237 230
238 bool StructTraits<ui::mojom::EventDataView, EventUniquePtr>::Read( 231 bool StructTraits<ui::mojom::EventDataView, EventUniquePtr>::Read(
239 ui::mojom::EventDataView event, 232 ui::mojom::EventDataView event,
(...skipping 17 matching lines...) Expand all
257 : ui::ET_KEY_RELEASED, 250 : ui::ET_KEY_RELEASED,
258 251
259 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags())); 252 static_cast<ui::KeyboardCode>(key_data->key_code), event.flags()));
260 return true; 253 return true;
261 } 254 }
262 case ui::mojom::EventType::POINTER_DOWN: 255 case ui::mojom::EventType::POINTER_DOWN:
263 case ui::mojom::EventType::POINTER_UP: 256 case ui::mojom::EventType::POINTER_UP:
264 case ui::mojom::EventType::POINTER_MOVE: 257 case ui::mojom::EventType::POINTER_MOVE:
265 case ui::mojom::EventType::POINTER_CANCEL: 258 case ui::mojom::EventType::POINTER_CANCEL:
266 case ui::mojom::EventType::MOUSE_EXIT: 259 case ui::mojom::EventType::MOUSE_EXIT:
267 case ui::mojom::EventType::WHEEL: { 260 case ui::mojom::EventType::POINTER_WHEEL_CHANGED: {
268 ui::mojom::PointerDataPtr pointer_data; 261 ui::mojom::PointerDataPtr pointer_data;
269 if (!event.ReadPointerData<ui::mojom::PointerDataPtr>(&pointer_data)) 262 if (!event.ReadPointerData<ui::mojom::PointerDataPtr>(&pointer_data))
270 return false; 263 return false;
271 264
272 const gfx::Point location(pointer_data->location->x, 265 const gfx::Point location(pointer_data->location->x,
273 pointer_data->location->y); 266 pointer_data->location->y);
274 const gfx::Point screen_location(pointer_data->location->screen_x, 267 const gfx::Point screen_location(pointer_data->location->screen_x,
275 pointer_data->location->screen_y); 268 pointer_data->location->screen_y);
276 269
277 switch (pointer_data->kind) { 270 switch (pointer_data->kind) {
278 case ui::mojom::PointerKind::MOUSE: { 271 case ui::mojom::PointerKind::MOUSE: {
279 if (event.action() == ui::mojom::EventType::WHEEL) {
280 out->reset(new ui::MouseWheelEvent(
281 gfx::Vector2d(
282 static_cast<int>(pointer_data->wheel_data->delta_x),
283 static_cast<int>(pointer_data->wheel_data->delta_y)),
284 location, screen_location, ui::EventTimeForNow(),
285 ui::EventFlags(event.flags()), ui::EventFlags(event.flags())));
286 return true;
287 }
288 out->reset(new ui::PointerEvent( 272 out->reset(new ui::PointerEvent(
289 MojoPointerEventTypeToUIEvent(event.action()), location, 273 MojoPointerEventTypeToUIEvent(event.action()), location,
290 screen_location, event.flags(), ui::PointerEvent::kMousePointerId, 274 screen_location, event.flags(), ui::PointerEvent::kMousePointerId,
291 pointer_data->changed_button_flags, 275 pointer_data->changed_button_flags,
292 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), 276 event.action() == ui::mojom::EventType::POINTER_WHEEL_CHANGED
277 ? ui::PointerDetails(
278 ui::EventPointerType::POINTER_TYPE_MOUSE,
279 gfx::Vector2d(
280 static_cast<int>(pointer_data->wheel_data->delta_x),
281 static_cast<int>(
282 pointer_data->wheel_data->delta_y)))
283 : ui::PointerDetails(
284 ui::EventPointerType::POINTER_TYPE_MOUSE),
293 ui::EventTimeForNow())); 285 ui::EventTimeForNow()));
294 return true; 286 return true;
295 } 287 }
296 case ui::mojom::PointerKind::TOUCH: { 288 case ui::mojom::PointerKind::TOUCH: {
297 out->reset(new ui::PointerEvent( 289 out->reset(new ui::PointerEvent(
298 MojoPointerEventTypeToUIEvent(event.action()), location, 290 MojoPointerEventTypeToUIEvent(event.action()), location,
299 screen_location, event.flags(), pointer_data->pointer_id, 291 screen_location, event.flags(), pointer_data->pointer_id,
300 pointer_data->changed_button_flags, 292 pointer_data->changed_button_flags,
301 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 293 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH,
302 pointer_data->brush_data->width, 294 pointer_data->brush_data->width,
(...skipping 10 matching lines...) Expand all
313 } 305 }
314 } 306 }
315 case ui::mojom::EventType::UNKNOWN: 307 case ui::mojom::EventType::UNKNOWN:
316 return false; 308 return false;
317 } 309 }
318 310
319 return false; 311 return false;
320 } 312 }
321 313
322 } // namespace mojo 314 } // namespace mojo
OLDNEW
« no previous file with comments | « ui/events/mojo/event_constants.mojom ('k') | ui/events/mojo/struct_traits_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698