OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/events/blink/blink_event_util.h" | 8 #include "ui/events/blink/blink_event_util.h" |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <cmath> | 13 #include <cmath> |
14 | 14 |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
18 #include "ui/events/base_event_utils.h" | 18 #include "ui/events/base_event_utils.h" |
19 #include "ui/events/event_constants.h" | 19 #include "ui/events/event_constants.h" |
20 #include "ui/events/gesture_detection/gesture_event_data.h" | 20 #include "ui/events/gesture_detection/gesture_event_data.h" |
21 #include "ui/events/gesture_detection/motion_event.h" | 21 #include "ui/events/gesture_detection/motion_event.h" |
22 #include "ui/events/gesture_event_details.h" | 22 #include "ui/events/gesture_event_details.h" |
23 #include "ui/events/keycodes/dom/keycode_converter.h" | 23 #include "ui/events/keycodes/dom/keycode_converter.h" |
24 #include "ui/gfx/geometry/safe_integer_conversions.h" | 24 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 25 #include "ui/gfx/geometry/vector2d.h" |
25 | 26 |
26 using blink::WebGestureEvent; | 27 using blink::WebGestureEvent; |
27 using blink::WebInputEvent; | 28 using blink::WebInputEvent; |
28 using blink::WebPointerProperties; | 29 using blink::WebPointerProperties; |
29 using blink::WebTouchEvent; | 30 using blink::WebTouchEvent; |
30 using blink::WebTouchPoint; | 31 using blink::WebTouchPoint; |
31 | 32 |
32 namespace ui { | 33 namespace ui { |
33 namespace { | 34 namespace { |
34 | 35 |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 const GestureEventData& data) { | 356 const GestureEventData& data) { |
356 return CreateWebGestureEvent(data.details, data.time, | 357 return CreateWebGestureEvent(data.details, data.time, |
357 gfx::PointF(data.x, data.y), | 358 gfx::PointF(data.x, data.y), |
358 gfx::PointF(data.raw_x, data.raw_y), data.flags, | 359 gfx::PointF(data.raw_x, data.raw_y), data.flags, |
359 data.unique_touch_event_id); | 360 data.unique_touch_event_id); |
360 } | 361 } |
361 | 362 |
362 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent( | 363 std::unique_ptr<blink::WebInputEvent> ScaleWebInputEvent( |
363 const blink::WebInputEvent& event, | 364 const blink::WebInputEvent& event, |
364 float scale) { | 365 float scale) { |
| 366 return TranslateAndScaleWebInputEvent(event, gfx::Vector2d(0, 0), scale); |
| 367 } |
| 368 |
| 369 std::unique_ptr<blink::WebInputEvent> TranslateAndScaleWebInputEvent( |
| 370 const blink::WebInputEvent& event, |
| 371 const gfx::Vector2d& delta, |
| 372 float scale) { |
365 std::unique_ptr<blink::WebInputEvent> scaled_event; | 373 std::unique_ptr<blink::WebInputEvent> scaled_event; |
366 if (scale == 1.f) | 374 if (scale == 1.f && delta.IsZero()) |
367 return scaled_event; | 375 return scaled_event; |
368 if (event.type == blink::WebMouseEvent::MouseWheel) { | 376 if (event.type == blink::WebMouseEvent::MouseWheel) { |
369 blink::WebMouseWheelEvent* wheel_event = new blink::WebMouseWheelEvent; | 377 blink::WebMouseWheelEvent* wheel_event = new blink::WebMouseWheelEvent; |
370 scaled_event.reset(wheel_event); | 378 scaled_event.reset(wheel_event); |
371 *wheel_event = static_cast<const blink::WebMouseWheelEvent&>(event); | 379 *wheel_event = static_cast<const blink::WebMouseWheelEvent&>(event); |
| 380 wheel_event->x += delta.x(); |
| 381 wheel_event->y += delta.y(); |
372 wheel_event->x *= scale; | 382 wheel_event->x *= scale; |
373 wheel_event->y *= scale; | 383 wheel_event->y *= scale; |
374 wheel_event->deltaX *= scale; | 384 wheel_event->deltaX *= scale; |
375 wheel_event->deltaY *= scale; | 385 wheel_event->deltaY *= scale; |
376 wheel_event->wheelTicksX *= scale; | 386 wheel_event->wheelTicksX *= scale; |
377 wheel_event->wheelTicksY *= scale; | 387 wheel_event->wheelTicksY *= scale; |
378 } else if (blink::WebInputEvent::isMouseEventType(event.type)) { | 388 } else if (blink::WebInputEvent::isMouseEventType(event.type)) { |
379 blink::WebMouseEvent* mouse_event = new blink::WebMouseEvent; | 389 blink::WebMouseEvent* mouse_event = new blink::WebMouseEvent; |
380 scaled_event.reset(mouse_event); | 390 scaled_event.reset(mouse_event); |
381 *mouse_event = static_cast<const blink::WebMouseEvent&>(event); | 391 *mouse_event = static_cast<const blink::WebMouseEvent&>(event); |
| 392 mouse_event->x += delta.x(); |
| 393 mouse_event->y += delta.y(); |
382 mouse_event->x *= scale; | 394 mouse_event->x *= scale; |
383 mouse_event->y *= scale; | 395 mouse_event->y *= scale; |
384 mouse_event->windowX = mouse_event->x; | 396 mouse_event->windowX = mouse_event->x; |
385 mouse_event->windowY = mouse_event->y; | 397 mouse_event->windowY = mouse_event->y; |
386 mouse_event->movementX *= scale; | 398 mouse_event->movementX *= scale; |
387 mouse_event->movementY *= scale; | 399 mouse_event->movementY *= scale; |
388 } else if (blink::WebInputEvent::isTouchEventType(event.type)) { | 400 } else if (blink::WebInputEvent::isTouchEventType(event.type)) { |
389 blink::WebTouchEvent* touch_event = new blink::WebTouchEvent; | 401 blink::WebTouchEvent* touch_event = new blink::WebTouchEvent; |
390 scaled_event.reset(touch_event); | 402 scaled_event.reset(touch_event); |
391 *touch_event = static_cast<const blink::WebTouchEvent&>(event); | 403 *touch_event = static_cast<const blink::WebTouchEvent&>(event); |
392 for (unsigned i = 0; i < touch_event->touchesLength; i++) { | 404 for (unsigned i = 0; i < touch_event->touchesLength; i++) { |
| 405 touch_event->touches[i].position.x += delta.x(); |
| 406 touch_event->touches[i].position.y += delta.y(); |
393 touch_event->touches[i].position.x *= scale; | 407 touch_event->touches[i].position.x *= scale; |
394 touch_event->touches[i].position.y *= scale; | 408 touch_event->touches[i].position.y *= scale; |
395 touch_event->touches[i].radiusX *= scale; | 409 touch_event->touches[i].radiusX *= scale; |
396 touch_event->touches[i].radiusY *= scale; | 410 touch_event->touches[i].radiusY *= scale; |
397 } | 411 } |
398 } else if (blink::WebInputEvent::isGestureEventType(event.type)) { | 412 } else if (blink::WebInputEvent::isGestureEventType(event.type)) { |
399 blink::WebGestureEvent* gesture_event = new blink::WebGestureEvent; | 413 blink::WebGestureEvent* gesture_event = new blink::WebGestureEvent; |
400 scaled_event.reset(gesture_event); | 414 scaled_event.reset(gesture_event); |
401 *gesture_event = static_cast<const blink::WebGestureEvent&>(event); | 415 *gesture_event = static_cast<const blink::WebGestureEvent&>(event); |
| 416 gesture_event->x += delta.x(); |
| 417 gesture_event->y += delta.y(); |
402 gesture_event->x *= scale; | 418 gesture_event->x *= scale; |
403 gesture_event->y *= scale; | 419 gesture_event->y *= scale; |
404 switch (gesture_event->type) { | 420 switch (gesture_event->type) { |
405 case blink::WebInputEvent::GestureScrollUpdate: | 421 case blink::WebInputEvent::GestureScrollUpdate: |
406 gesture_event->data.scrollUpdate.deltaX *= scale; | 422 gesture_event->data.scrollUpdate.deltaX *= scale; |
407 gesture_event->data.scrollUpdate.deltaY *= scale; | 423 gesture_event->data.scrollUpdate.deltaY *= scale; |
408 break; | 424 break; |
409 case blink::WebInputEvent::GestureScrollBegin: | 425 case blink::WebInputEvent::GestureScrollBegin: |
410 gesture_event->data.scrollBegin.deltaXHint *= scale; | 426 gesture_event->data.scrollBegin.deltaXHint *= scale; |
411 gesture_event->data.scrollBegin.deltaYHint *= scale; | 427 gesture_event->data.scrollBegin.deltaYHint *= scale; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 return blink::WebInputEvent::IsRight; | 535 return blink::WebInputEvent::IsRight; |
520 case DomKeyLocation::NUMPAD: | 536 case DomKeyLocation::NUMPAD: |
521 return blink::WebInputEvent::IsKeyPad; | 537 return blink::WebInputEvent::IsKeyPad; |
522 case DomKeyLocation::STANDARD: | 538 case DomKeyLocation::STANDARD: |
523 break; | 539 break; |
524 } | 540 } |
525 return static_cast<blink::WebInputEvent::Modifiers>(0); | 541 return static_cast<blink::WebInputEvent::Modifiers>(0); |
526 } | 542 } |
527 | 543 |
528 } // namespace ui | 544 } // namespace ui |
OLD | NEW |