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/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
18 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
19 #include "ui/events/gesture_detection/gesture_event_data.h" | 19 #include "ui/events/gesture_detection/gesture_event_data.h" |
20 #include "ui/events/gesture_detection/motion_event.h" | 20 #include "ui/events/gesture_detection/motion_event.h" |
21 #include "ui/events/gesture_event_details.h" | 21 #include "ui/events/gesture_event_details.h" |
22 #include "ui/gfx/geometry/safe_integer_conversions.h" | 22 #include "ui/gfx/geometry/safe_integer_conversions.h" |
23 | 23 |
24 using blink::WebGestureEvent; | 24 using blink::WebGestureEvent; |
25 using blink::WebInputEvent; | 25 using blink::WebInputEvent; |
| 26 using blink::WebPointerProperties; |
26 using blink::WebTouchEvent; | 27 using blink::WebTouchEvent; |
27 using blink::WebTouchPoint; | 28 using blink::WebTouchPoint; |
28 | 29 |
29 namespace ui { | 30 namespace ui { |
30 namespace { | 31 namespace { |
31 | 32 |
32 WebInputEvent::Type ToWebInputEventType(MotionEvent::Action action) { | 33 WebInputEvent::Type ToWebInputEventType(MotionEvent::Action action) { |
33 switch (action) { | 34 switch (action) { |
34 case MotionEvent::ACTION_DOWN: | 35 case MotionEvent::ACTION_DOWN: |
35 return WebInputEvent::TouchStart; | 36 return WebInputEvent::TouchStart; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 ? WebTouchPoint::StateReleased | 75 ? WebTouchPoint::StateReleased |
75 : WebTouchPoint::StateStationary; | 76 : WebTouchPoint::StateStationary; |
76 case MotionEvent::ACTION_NONE: | 77 case MotionEvent::ACTION_NONE: |
77 NOTREACHED(); | 78 NOTREACHED(); |
78 return WebTouchPoint::StateUndefined; | 79 return WebTouchPoint::StateUndefined; |
79 } | 80 } |
80 NOTREACHED() << "Invalid MotionEvent::Action."; | 81 NOTREACHED() << "Invalid MotionEvent::Action."; |
81 return WebTouchPoint::StateUndefined; | 82 return WebTouchPoint::StateUndefined; |
82 } | 83 } |
83 | 84 |
84 WebTouchPoint::PointerType ToWebTouchPointPointerType(const MotionEvent& event, | |
85 size_t pointer_index) { | |
86 switch (event.GetToolType(pointer_index)) { | |
87 case MotionEvent::TOOL_TYPE_UNKNOWN: | |
88 return WebTouchPoint::PointerType::Unknown; | |
89 case MotionEvent::TOOL_TYPE_FINGER: | |
90 return WebTouchPoint::PointerType::Touch; | |
91 case MotionEvent::TOOL_TYPE_STYLUS: | |
92 return WebTouchPoint::PointerType::Pen; | |
93 case MotionEvent::TOOL_TYPE_MOUSE: | |
94 return WebTouchPoint::PointerType::Mouse; | |
95 case MotionEvent::TOOL_TYPE_ERASER: | |
96 return WebTouchPoint::PointerType::Unknown; | |
97 } | |
98 NOTREACHED() << "Invalid MotionEvent::ToolType = " | |
99 << event.GetToolType(pointer_index); | |
100 return WebTouchPoint::PointerType::Unknown; | |
101 } | |
102 | |
103 WebTouchPoint CreateWebTouchPoint(const MotionEvent& event, | 85 WebTouchPoint CreateWebTouchPoint(const MotionEvent& event, |
104 size_t pointer_index) { | 86 size_t pointer_index) { |
105 WebTouchPoint touch; | 87 WebTouchPoint touch; |
106 touch.id = event.GetPointerId(pointer_index); | 88 touch.id = event.GetPointerId(pointer_index); |
107 touch.pointerType = ToWebTouchPointPointerType(event, pointer_index); | 89 touch.pointerType = ToWebPointerType(event.GetToolType(pointer_index)); |
108 touch.state = ToWebTouchPointState(event, pointer_index); | 90 touch.state = ToWebTouchPointState(event, pointer_index); |
109 touch.position.x = event.GetX(pointer_index); | 91 touch.position.x = event.GetX(pointer_index); |
110 touch.position.y = event.GetY(pointer_index); | 92 touch.position.y = event.GetY(pointer_index); |
111 touch.screenPosition.x = event.GetRawX(pointer_index); | 93 touch.screenPosition.x = event.GetRawX(pointer_index); |
112 touch.screenPosition.y = event.GetRawY(pointer_index); | 94 touch.screenPosition.y = event.GetRawY(pointer_index); |
113 | 95 |
114 // A note on touch ellipse specifications: | 96 // A note on touch ellipse specifications: |
115 // | 97 // |
116 // Android MotionEvent provides the major and minor axes of the touch ellipse, | 98 // Android MotionEvent provides the major and minor axes of the touch ellipse, |
117 // as well as the orientation of the major axis clockwise from vertical, in | 99 // as well as the orientation of the major axis clockwise from vertical, in |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 break; | 437 break; |
456 | 438 |
457 // TODO(oshima): Find out if ContextMenu needs to be scaled. | 439 // TODO(oshima): Find out if ContextMenu needs to be scaled. |
458 default: | 440 default: |
459 break; | 441 break; |
460 } | 442 } |
461 } | 443 } |
462 return scaled_event; | 444 return scaled_event; |
463 } | 445 } |
464 | 446 |
| 447 WebPointerProperties::PointerType ToWebPointerType( |
| 448 MotionEvent::ToolType tool_type) { |
| 449 switch (tool_type) { |
| 450 case MotionEvent::TOOL_TYPE_UNKNOWN: |
| 451 return WebPointerProperties::PointerType::Unknown; |
| 452 case MotionEvent::TOOL_TYPE_FINGER: |
| 453 return WebPointerProperties::PointerType::Touch; |
| 454 case MotionEvent::TOOL_TYPE_STYLUS: |
| 455 return WebPointerProperties::PointerType::Pen; |
| 456 case MotionEvent::TOOL_TYPE_MOUSE: |
| 457 return WebPointerProperties::PointerType::Mouse; |
| 458 case MotionEvent::TOOL_TYPE_ERASER: |
| 459 return WebPointerProperties::PointerType::Unknown; |
| 460 } |
| 461 NOTREACHED() << "Invalid MotionEvent::ToolType = " << tool_type; |
| 462 return WebPointerProperties::PointerType::Unknown; |
| 463 } |
| 464 |
465 } // namespace ui | 465 } // namespace ui |
OLD | NEW |