OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/android/touch_point.h" | 5 #include "content/browser/android/touch_point.h" |
6 | 6 |
7 #include "base/debug/debugger.h" | 7 #include "base/debug/debugger.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 | 10 |
11 #include "jni/TouchPoint_jni.h" | 11 #include "jni/TouchPoint_jni.h" |
12 | 12 |
13 using WebKit::WebTouchEvent; | 13 using blink::WebTouchEvent; |
14 using WebKit::WebTouchPoint; | 14 using blink::WebTouchPoint; |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void MaybeAddTouchPoint(JNIEnv* env, | 18 void MaybeAddTouchPoint(JNIEnv* env, |
19 jobject pt, | 19 jobject pt, |
20 float dpi_scale, | 20 float dpi_scale, |
21 WebKit::WebTouchEvent& event) { | 21 blink::WebTouchEvent& event) { |
22 WebTouchPoint::State state = static_cast<WebTouchPoint::State>( | 22 WebTouchPoint::State state = static_cast<WebTouchPoint::State>( |
23 Java_TouchPoint_getState(env, pt)); | 23 Java_TouchPoint_getState(env, pt)); |
24 if (state == WebTouchPoint::StateUndefined) | 24 if (state == WebTouchPoint::StateUndefined) |
25 return; | 25 return; |
26 | 26 |
27 // When generating a cancel event from an event of a different type, the | 27 // When generating a cancel event from an event of a different type, the |
28 // touch points are out of sync, so we ensure the points are marked as | 28 // touch points are out of sync, so we ensure the points are marked as |
29 // canceled as well. | 29 // canceled as well. |
30 if (event.type == WebTouchEvent::TouchCancel) | 30 if (event.type == WebTouchEvent::TouchCancel) |
31 state = WebTouchPoint::StateCancelled; | 31 state = WebTouchPoint::StateCancelled; |
32 | 32 |
33 // Record the current number of points in the WebTouchEvent | 33 // Record the current number of points in the WebTouchEvent |
34 const int idx = event.touchesLength; | 34 const int idx = event.touchesLength; |
35 DCHECK_LT(idx, WebKit::WebTouchEvent::touchesLengthCap); | 35 DCHECK_LT(idx, blink::WebTouchEvent::touchesLengthCap); |
36 | 36 |
37 WebTouchPoint wtp; | 37 WebTouchPoint wtp; |
38 wtp.id = Java_TouchPoint_getId(env, pt); | 38 wtp.id = Java_TouchPoint_getId(env, pt); |
39 wtp.state = state; | 39 wtp.state = state; |
40 wtp.position.x = Java_TouchPoint_getX(env, pt) / dpi_scale; | 40 wtp.position.x = Java_TouchPoint_getX(env, pt) / dpi_scale; |
41 wtp.position.y = Java_TouchPoint_getY(env, pt) / dpi_scale; | 41 wtp.position.y = Java_TouchPoint_getY(env, pt) / dpi_scale; |
42 // TODO(joth): Raw event co-ordinates. | 42 // TODO(joth): Raw event co-ordinates. |
43 wtp.screenPosition = wtp.position; | 43 wtp.screenPosition = wtp.position; |
44 wtp.force = Java_TouchPoint_getPressure(env, pt); | 44 wtp.force = Java_TouchPoint_getPressure(env, pt); |
45 | 45 |
(...skipping 19 matching lines...) Expand all Loading... |
65 | 65 |
66 } // namespace | 66 } // namespace |
67 | 67 |
68 namespace content { | 68 namespace content { |
69 | 69 |
70 void TouchPoint::BuildWebTouchEvent(JNIEnv* env, | 70 void TouchPoint::BuildWebTouchEvent(JNIEnv* env, |
71 jint type, | 71 jint type, |
72 jlong time_ms, | 72 jlong time_ms, |
73 float dpi_scale, | 73 float dpi_scale, |
74 jobjectArray pts, | 74 jobjectArray pts, |
75 WebKit::WebTouchEvent& event) { | 75 blink::WebTouchEvent& event) { |
76 event.type = static_cast<WebTouchEvent::Type>(type); | 76 event.type = static_cast<WebTouchEvent::Type>(type); |
77 event.timeStampSeconds = | 77 event.timeStampSeconds = |
78 static_cast<double>(time_ms) / base::Time::kMillisecondsPerSecond; | 78 static_cast<double>(time_ms) / base::Time::kMillisecondsPerSecond; |
79 int arrayLength = env->GetArrayLength(pts); | 79 int arrayLength = env->GetArrayLength(pts); |
80 // Loop until either all of the input points have been consumed or the output | 80 // Loop until either all of the input points have been consumed or the output |
81 // array has been filled | 81 // array has been filled |
82 for (int i = 0; i < arrayLength; i++) { | 82 for (int i = 0; i < arrayLength; i++) { |
83 jobject pt = env->GetObjectArrayElement(pts, i); | 83 jobject pt = env->GetObjectArrayElement(pts, i); |
84 MaybeAddTouchPoint(env, pt, dpi_scale, event); | 84 MaybeAddTouchPoint(env, pt, dpi_scale, event); |
85 if (event.touchesLength >= event.touchesLengthCap) | 85 if (event.touchesLength >= event.touchesLengthCap) |
86 break; | 86 break; |
87 } | 87 } |
88 DCHECK_GT(event.touchesLength, 0U); | 88 DCHECK_GT(event.touchesLength, 0U); |
89 } | 89 } |
90 | 90 |
91 static void RegisterConstants(JNIEnv* env) { | 91 static void RegisterConstants(JNIEnv* env) { |
92 Java_TouchPoint_initializeConstants( | 92 Java_TouchPoint_initializeConstants( |
93 env, | 93 env, |
94 WebKit::WebTouchEvent::TouchStart, | 94 blink::WebTouchEvent::TouchStart, |
95 WebKit::WebTouchEvent::TouchMove, | 95 blink::WebTouchEvent::TouchMove, |
96 WebKit::WebTouchEvent::TouchEnd, | 96 blink::WebTouchEvent::TouchEnd, |
97 WebKit::WebTouchEvent::TouchCancel, | 97 blink::WebTouchEvent::TouchCancel, |
98 WebKit::WebTouchPoint::StateUndefined, | 98 blink::WebTouchPoint::StateUndefined, |
99 WebKit::WebTouchPoint::StateReleased, | 99 blink::WebTouchPoint::StateReleased, |
100 WebKit::WebTouchPoint::StatePressed, | 100 blink::WebTouchPoint::StatePressed, |
101 WebKit::WebTouchPoint::StateMoved, | 101 blink::WebTouchPoint::StateMoved, |
102 WebKit::WebTouchPoint::StateStationary, | 102 blink::WebTouchPoint::StateStationary, |
103 WebKit::WebTouchPoint::StateCancelled); | 103 blink::WebTouchPoint::StateCancelled); |
104 } | 104 } |
105 | 105 |
106 bool RegisterTouchPoint(JNIEnv* env) { | 106 bool RegisterTouchPoint(JNIEnv* env) { |
107 if (!RegisterNativesImpl(env)) | 107 if (!RegisterNativesImpl(env)) |
108 return false; | 108 return false; |
109 | 109 |
110 RegisterConstants(env); | 110 RegisterConstants(env); |
111 | 111 |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 } // namespace content | 115 } // namespace content |
OLD | NEW |