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

Side by Side Diff: content/public/common/input/web_input_event_traits.cc

Issue 1560553002: Framelet Prototype 2016 Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased + Applied Brett's Windows + Fixed security issue Created 4 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/common/input/web_input_event_traits.h" 5 #include "content/public/common/input/web_input_event_traits.h"
6 6
7 #include <bitset> 7 #include <bitset>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 12
13 using base::StringAppendF; 13 using base::StringAppendF;
14 using base::SStringPrintf; 14 using base::SStringPrintf;
15 using blink::WebGestureEvent; 15 using blink::WebGestureEvent;
16 using blink::WebInputEvent; 16 using blink::WebInputEvent;
17 using blink::WebKeyboardEvent; 17 using blink::WebKeyboardEvent;
18 using blink::WebMouseEvent; 18 using blink::WebMouseEvent;
19 using blink::WebMouseWheelEvent; 19 using blink::WebMouseWheelEvent;
20 using blink::WebTouchEvent; 20 using blink::WebTouchEvent;
21 using blink::WebTouchPoint; 21 using blink::WebTouchPoint;
22 using std::numeric_limits; 22 using std::numeric_limits;
23 23
24 namespace content { 24 namespace content {
25 namespace { 25 namespace {
26 26
27 const int kInvalidTouchIndex = -1; 27 const int kInvalidTouchIndex = -1;
28 28
29 void ApppendEventDetails(const WebKeyboardEvent& event, std::string* result) { 29 void ApppendEventDetails(const WebKeyboardEvent& event, std::string* result) {
30 StringAppendF(result, 30 StringAppendF(result,
31 "{\n WinCode: %d\n NativeCode: %d\n IsSystem: %d\n" 31 "{\n WinCode: %d\n NativeCode: %d\n IsSystem: %d\n"
32 " Text: %s\n UnmodifiedText: %s\n KeyIdentifier: %s\n}", 32 " Text: %s\n UnmodifiedText: %s\n KeyIdentifier: %s\n}",
33 event.windowsKeyCode, 33 event.windowsKeyCode, event.nativeKeyCode, event.isSystemKey,
34 event.nativeKeyCode,
35 event.isSystemKey,
36 reinterpret_cast<const char*>(event.text), 34 reinterpret_cast<const char*>(event.text),
37 reinterpret_cast<const char*>(event.unmodifiedText), 35 reinterpret_cast<const char*>(event.unmodifiedText),
38 reinterpret_cast<const char*>(event.keyIdentifier)); 36 reinterpret_cast<const char*>(event.keyIdentifier));
39 } 37 }
40 38
41 void ApppendEventDetails(const WebMouseEvent& event, std::string* result) { 39 void ApppendEventDetails(const WebMouseEvent& event, std::string* result) {
42 StringAppendF(result, 40 StringAppendF(result,
43 "{\n Button: %d\n Pos: (%d, %d)\n WindowPos: (%d, %d)\n" 41 "{\n Button: %d\n Pos: (%d, %d)\n WindowPos: (%d, %d)\n"
44 " GlobalPos: (%d, %d)\n Movement: (%d, %d)\n Clicks: %d\n}", 42 " GlobalPos: (%d, %d)\n Movement: (%d, %d)\n Clicks: %d\n}",
45 event.button, 43 event.button, event.x, event.y, event.windowX, event.windowY,
46 event.x, 44 event.globalX, event.globalY, event.movementX, event.movementY,
47 event.y,
48 event.windowX,
49 event.windowY,
50 event.globalX,
51 event.globalY,
52 event.movementX,
53 event.movementY,
54 event.clickCount); 45 event.clickCount);
55 } 46 }
56 47
57 void ApppendEventDetails(const WebMouseWheelEvent& event, std::string* result) { 48 void ApppendEventDetails(const WebMouseWheelEvent& event, std::string* result) {
58 StringAppendF(result, 49 StringAppendF(
59 "{\n Delta: (%f, %f)\n WheelTicks: (%f, %f)\n Accel: (%f, %f)\n" 50 result,
60 " ScrollByPage: %d\n HasPreciseScrollingDeltas: %d\n" 51 "{\n Delta: (%f, %f)\n WheelTicks: (%f, %f)\n Accel: (%f, %f)\n"
61 " Phase: (%d, %d)\n CanRubberband: (%d, %d)\n CanScroll: %d\n}", 52 " ScrollByPage: %d\n HasPreciseScrollingDeltas: %d\n"
62 event.deltaX, 53 " Phase: (%d, %d)\n CanRubberband: (%d, %d)\n CanScroll: %d\n}",
63 event.deltaY, 54 event.deltaX, event.deltaY, event.wheelTicksX, event.wheelTicksY,
64 event.wheelTicksX, 55 event.accelerationRatioX, event.accelerationRatioY, event.scrollByPage,
65 event.wheelTicksY, 56 event.hasPreciseScrollingDeltas, event.phase, event.momentumPhase,
66 event.accelerationRatioX, 57 event.canRubberbandLeft, event.canRubberbandRight, event.canScroll);
67 event.accelerationRatioY,
68 event.scrollByPage,
69 event.hasPreciseScrollingDeltas,
70 event.phase,
71 event.momentumPhase,
72 event.canRubberbandLeft,
73 event.canRubberbandRight,
74 event.canScroll);
75 } 58 }
76 59
77 void ApppendEventDetails(const WebGestureEvent& event, std::string* result) { 60 void ApppendEventDetails(const WebGestureEvent& event, std::string* result) {
78 StringAppendF(result, 61 StringAppendF(
79 "{\n Pos: (%d, %d)\n GlobalPos: (%d, %d)\n SourceDevice: %d\n" 62 result,
80 " RawData: (%f, %f, %f, %f, %d)\n}", 63 "{\n Pos: (%d, %d)\n GlobalPos: (%d, %d)\n SourceDevice: %d\n"
81 event.x, 64 " RawData: (%f, %f, %f, %f, %d)\n}",
82 event.y, 65 event.x, event.y, event.globalX, event.globalY, event.sourceDevice,
83 event.globalX, 66 event.data.scrollUpdate.deltaX, event.data.scrollUpdate.deltaY,
84 event.globalY, 67 event.data.scrollUpdate.velocityX, event.data.scrollUpdate.velocityY,
85 event.sourceDevice, 68 event.data.scrollUpdate.previousUpdateInSequencePrevented);
86 event.data.scrollUpdate.deltaX,
87 event.data.scrollUpdate.deltaY,
88 event.data.scrollUpdate.velocityX,
89 event.data.scrollUpdate.velocityY,
90 event.data.scrollUpdate.previousUpdateInSequencePrevented);
91 } 69 }
92 70
93 void ApppendTouchPointDetails(const WebTouchPoint& point, std::string* result) { 71 void ApppendTouchPointDetails(const WebTouchPoint& point, std::string* result) {
94 StringAppendF(result, 72 StringAppendF(result,
95 " (ID: %d, State: %d, ScreenPos: (%f, %f), Pos: (%f, %f)," 73 " (ID: %d, State: %d, ScreenPos: (%f, %f), Pos: (%f, %f),"
96 " Radius: (%f, %f), Rot: %f, Force: %f," 74 " Radius: (%f, %f), Rot: %f, Force: %f,"
97 " Tilt: (%d, %d)),\n", 75 " Tilt: (%d, %d)),\n",
98 point.id, 76 point.id, point.state, point.screenPosition.x,
99 point.state, 77 point.screenPosition.y, point.position.x, point.position.y,
100 point.screenPosition.x, 78 point.radiusX, point.radiusY, point.rotationAngle, point.force,
101 point.screenPosition.y, 79 point.tiltX, point.tiltY);
102 point.position.x,
103 point.position.y,
104 point.radiusX,
105 point.radiusY,
106 point.rotationAngle,
107 point.force,
108 point.tiltX,
109 point.tiltY);
110 } 80 }
111 81
112 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) { 82 void ApppendEventDetails(const WebTouchEvent& event, std::string* result) {
113 StringAppendF(result, 83 StringAppendF(result,
114 "{\n Touches: %u, Cancelable: %d, CausesScrolling: %d," 84 "{\n Touches: %u, Cancelable: %d, CausesScrolling: %d,"
115 " uniqueTouchEventId: %u\n[\n", 85 " uniqueTouchEventId: %u\n[\n",
116 event.touchesLength, event.cancelable, 86 event.touchesLength, event.cancelable,
117 event.causesScrollingIfUncanceled, event.uniqueTouchEventId); 87 event.causesScrollingIfUncanceled, event.uniqueTouchEventId);
118 for (unsigned i = 0; i < event.touchesLength; ++i) 88 for (unsigned i = 0; i < event.touchesLength; ++i)
119 ApppendTouchPointDetails(event.touches[i], result); 89 ApppendTouchPointDetails(event.touches[i], result);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 float GetAccelerationRatio(float accelerated_delta, float unaccelerated_delta) { 134 float GetAccelerationRatio(float accelerated_delta, float unaccelerated_delta) {
165 if (unaccelerated_delta == 0.f || accelerated_delta == 0.f) 135 if (unaccelerated_delta == 0.f || accelerated_delta == 0.f)
166 return 1.f; 136 return 1.f;
167 return unaccelerated_delta / accelerated_delta; 137 return unaccelerated_delta / accelerated_delta;
168 } 138 }
169 139
170 void Coalesce(const WebMouseWheelEvent& event_to_coalesce, 140 void Coalesce(const WebMouseWheelEvent& event_to_coalesce,
171 WebMouseWheelEvent* event) { 141 WebMouseWheelEvent* event) {
172 DCHECK(CanCoalesce(event_to_coalesce, *event)); 142 DCHECK(CanCoalesce(event_to_coalesce, *event));
173 float unaccelerated_x = 143 float unaccelerated_x =
174 GetUnacceleratedDelta(event->deltaX, 144 GetUnacceleratedDelta(event->deltaX, event->accelerationRatioX) +
175 event->accelerationRatioX) +
176 GetUnacceleratedDelta(event_to_coalesce.deltaX, 145 GetUnacceleratedDelta(event_to_coalesce.deltaX,
177 event_to_coalesce.accelerationRatioX); 146 event_to_coalesce.accelerationRatioX);
178 float unaccelerated_y = 147 float unaccelerated_y =
179 GetUnacceleratedDelta(event->deltaY, 148 GetUnacceleratedDelta(event->deltaY, event->accelerationRatioY) +
180 event->accelerationRatioY) +
181 GetUnacceleratedDelta(event_to_coalesce.deltaY, 149 GetUnacceleratedDelta(event_to_coalesce.deltaY,
182 event_to_coalesce.accelerationRatioY); 150 event_to_coalesce.accelerationRatioY);
183 event->deltaX += event_to_coalesce.deltaX; 151 event->deltaX += event_to_coalesce.deltaX;
184 event->deltaY += event_to_coalesce.deltaY; 152 event->deltaY += event_to_coalesce.deltaY;
185 event->wheelTicksX += event_to_coalesce.wheelTicksX; 153 event->wheelTicksX += event_to_coalesce.wheelTicksX;
186 event->wheelTicksY += event_to_coalesce.wheelTicksY; 154 event->wheelTicksY += event_to_coalesce.wheelTicksY;
187 event->accelerationRatioX = 155 event->accelerationRatioX =
188 GetAccelerationRatio(event->deltaX, unaccelerated_x); 156 GetAccelerationRatio(event->deltaX, unaccelerated_x);
189 event->accelerationRatioY = 157 event->accelerationRatioY =
190 GetAccelerationRatio(event->deltaY, unaccelerated_y); 158 GetAccelerationRatio(event->deltaY, unaccelerated_y);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 event.sourceDevice != event_to_coalesce.sourceDevice || 217 event.sourceDevice != event_to_coalesce.sourceDevice ||
250 event.modifiers != event_to_coalesce.modifiers) 218 event.modifiers != event_to_coalesce.modifiers)
251 return false; 219 return false;
252 220
253 if (event.type == WebInputEvent::GestureScrollUpdate) 221 if (event.type == WebInputEvent::GestureScrollUpdate)
254 return true; 222 return true;
255 223
256 // GesturePinchUpdate scales can be combined only if they share a focal point, 224 // GesturePinchUpdate scales can be combined only if they share a focal point,
257 // e.g., with double-tap drag zoom. 225 // e.g., with double-tap drag zoom.
258 if (event.type == WebInputEvent::GesturePinchUpdate && 226 if (event.type == WebInputEvent::GesturePinchUpdate &&
259 event.x == event_to_coalesce.x && 227 event.x == event_to_coalesce.x && event.y == event_to_coalesce.y)
260 event.y == event_to_coalesce.y)
261 return true; 228 return true;
262 229
263 return false; 230 return false;
264 } 231 }
265 232
266 void Coalesce(const WebGestureEvent& event_to_coalesce, 233 void Coalesce(const WebGestureEvent& event_to_coalesce,
267 WebGestureEvent* event) { 234 WebGestureEvent* event) {
268 DCHECK(CanCoalesce(event_to_coalesce, *event)); 235 DCHECK(CanCoalesce(event_to_coalesce, *event));
269 if (event->type == WebInputEvent::GestureScrollUpdate) { 236 if (event->type == WebInputEvent::GestureScrollUpdate) {
270 event->data.scrollUpdate.deltaX += 237 event->data.scrollUpdate.deltaX +=
(...skipping 12 matching lines...) Expand all
283 else if (event->data.pinchUpdate.scale > numeric_limits<float>::max()) 250 else if (event->data.pinchUpdate.scale > numeric_limits<float>::max())
284 event->data.pinchUpdate.scale = numeric_limits<float>::max(); 251 event->data.pinchUpdate.scale = numeric_limits<float>::max();
285 } 252 }
286 } 253 }
287 254
288 struct WebInputEventToString { 255 struct WebInputEventToString {
289 template <class EventType> 256 template <class EventType>
290 bool Execute(const WebInputEvent& event, std::string* result) const { 257 bool Execute(const WebInputEvent& event, std::string* result) const {
291 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n", 258 SStringPrintf(result, "%s (Time: %lf, Modifiers: %d)\n",
292 WebInputEventTraits::GetName(event.type), 259 WebInputEventTraits::GetName(event.type),
293 event.timeStampSeconds, 260 event.timeStampSeconds, event.modifiers);
294 event.modifiers);
295 const EventType& typed_event = static_cast<const EventType&>(event); 261 const EventType& typed_event = static_cast<const EventType&>(event);
296 ApppendEventDetails(typed_event, result); 262 ApppendEventDetails(typed_event, result);
297 return true; 263 return true;
298 } 264 }
299 }; 265 };
300 266
301 struct WebInputEventSize { 267 struct WebInputEventSize {
302 template <class EventType> 268 template <class EventType>
303 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const { 269 bool Execute(WebInputEvent::Type /* type */, size_t* type_size) const {
304 *type_size = sizeof(EventType); 270 *type_size = sizeof(EventType);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 else if (WebInputEvent::isGestureEventType(type)) 337 else if (WebInputEvent::isGestureEventType(type))
372 return op.template Execute<WebGestureEvent>(arg_in, arg_out); 338 return op.template Execute<WebGestureEvent>(arg_in, arg_out);
373 339
374 NOTREACHED() << "Unknown webkit event type " << type; 340 NOTREACHED() << "Unknown webkit event type " << type;
375 return false; 341 return false;
376 } 342 }
377 343
378 } // namespace 344 } // namespace
379 345
380 const char* WebInputEventTraits::GetName(WebInputEvent::Type type) { 346 const char* WebInputEventTraits::GetName(WebInputEvent::Type type) {
381 #define CASE_TYPE(t) case WebInputEvent::t: return #t 347 #define CASE_TYPE(t) \
382 switch(type) { 348 case WebInputEvent::t: \
349 return #t
350 switch (type) {
383 CASE_TYPE(Undefined); 351 CASE_TYPE(Undefined);
384 CASE_TYPE(MouseDown); 352 CASE_TYPE(MouseDown);
385 CASE_TYPE(MouseUp); 353 CASE_TYPE(MouseUp);
386 CASE_TYPE(MouseMove); 354 CASE_TYPE(MouseMove);
387 CASE_TYPE(MouseEnter); 355 CASE_TYPE(MouseEnter);
388 CASE_TYPE(MouseLeave); 356 CASE_TYPE(MouseLeave);
389 CASE_TYPE(ContextMenu); 357 CASE_TYPE(ContextMenu);
390 CASE_TYPE(MouseWheel); 358 CASE_TYPE(MouseWheel);
391 CASE_TYPE(RawKeyDown); 359 CASE_TYPE(RawKeyDown);
392 CASE_TYPE(KeyDown); 360 CASE_TYPE(KeyDown);
(...skipping 16 matching lines...) Expand all
409 CASE_TYPE(GesturePinchBegin); 377 CASE_TYPE(GesturePinchBegin);
410 CASE_TYPE(GesturePinchEnd); 378 CASE_TYPE(GesturePinchEnd);
411 CASE_TYPE(GesturePinchUpdate); 379 CASE_TYPE(GesturePinchUpdate);
412 CASE_TYPE(TouchStart); 380 CASE_TYPE(TouchStart);
413 CASE_TYPE(TouchMove); 381 CASE_TYPE(TouchMove);
414 CASE_TYPE(TouchEnd); 382 CASE_TYPE(TouchEnd);
415 CASE_TYPE(TouchCancel); 383 CASE_TYPE(TouchCancel);
416 default: 384 default:
417 // Must include default to let blink::WebInputEvent add new event types 385 // Must include default to let blink::WebInputEvent add new event types
418 // before they're added here. 386 // before they're added here.
419 DLOG(WARNING) << 387 DLOG(WARNING)
420 "Unhandled WebInputEvent type in WebInputEventTraits::GetName.\n"; 388 << "Unhandled WebInputEvent type in WebInputEventTraits::GetName.\n";
421 break; 389 break;
422 } 390 }
423 #undef CASE_TYPE 391 #undef CASE_TYPE
424 return ""; 392 return "";
425 } 393 }
426 394
427 std::string WebInputEventTraits::ToString(const WebInputEvent& event) { 395 std::string WebInputEventTraits::ToString(const WebInputEvent& event) {
428 std::string result; 396 std::string result;
429 Apply(WebInputEventToString(), event.type, event, &result); 397 Apply(WebInputEventToString(), event.type, event, &result);
430 return result; 398 return result;
(...skipping 16 matching lines...) Expand all
447 return; 415 return;
448 bool dummy_var = false; 416 bool dummy_var = false;
449 Apply(WebInputEventDelete(), event->type, event, &dummy_var); 417 Apply(WebInputEventDelete(), event->type, event, &dummy_var);
450 } 418 }
451 419
452 bool WebInputEventTraits::CanCoalesce(const WebInputEvent& event_to_coalesce, 420 bool WebInputEventTraits::CanCoalesce(const WebInputEvent& event_to_coalesce,
453 const WebInputEvent& event) { 421 const WebInputEvent& event) {
454 // Early out before casting. 422 // Early out before casting.
455 if (event_to_coalesce.type != event.type) 423 if (event_to_coalesce.type != event.type)
456 return false; 424 return false;
457 return Apply(WebInputEventCanCoalesce(), 425 return Apply(WebInputEventCanCoalesce(), event.type, event_to_coalesce,
458 event.type,
459 event_to_coalesce,
460 &event); 426 &event);
461 } 427 }
462 428
463 void WebInputEventTraits::Coalesce(const WebInputEvent& event_to_coalesce, 429 void WebInputEventTraits::Coalesce(const WebInputEvent& event_to_coalesce,
464 WebInputEvent* event) { 430 WebInputEvent* event) {
465 DCHECK(event); 431 DCHECK(event);
466 Apply(WebInputEventCoalesce(), event->type, event_to_coalesce, event); 432 Apply(WebInputEventCoalesce(), event->type, event_to_coalesce, event);
467 } 433 }
468 434
469 bool WebInputEventTraits::WillReceiveAckFromRenderer( 435 bool WebInputEventTraits::WillReceiveAckFromRenderer(
(...skipping 24 matching lines...) Expand all
494 460
495 uint32_t WebInputEventTraits::GetUniqueTouchEventId( 461 uint32_t WebInputEventTraits::GetUniqueTouchEventId(
496 const WebInputEvent& event) { 462 const WebInputEvent& event) {
497 if (WebInputEvent::isTouchEventType(event.type)) { 463 if (WebInputEvent::isTouchEventType(event.type)) {
498 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId; 464 return static_cast<const WebTouchEvent&>(event).uniqueTouchEventId;
499 } 465 }
500 return 0U; 466 return 0U;
501 } 467 }
502 468
503 } // namespace content 469 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/input/web_input_event_traits.h ('k') | content/public/common/input/web_touch_event_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698