OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_host/input/motion_event_android.h" | 5 #include "content/browser/renderer_host/input/motion_event_android.h" |
6 | 6 |
7 #include <android/input.h> | 7 #include <android/input.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 122 } |
123 | 123 |
124 } // namespace | 124 } // namespace |
125 | 125 |
126 MotionEventAndroid::Pointer::Pointer(jint id, | 126 MotionEventAndroid::Pointer::Pointer(jint id, |
127 jfloat pos_x_pixels, | 127 jfloat pos_x_pixels, |
128 jfloat pos_y_pixels, | 128 jfloat pos_y_pixels, |
129 jfloat touch_major_pixels, | 129 jfloat touch_major_pixels, |
130 jfloat touch_minor_pixels, | 130 jfloat touch_minor_pixels, |
131 jfloat orientation_rad, | 131 jfloat orientation_rad, |
| 132 jfloat tilt_rad, |
132 jint tool_type) | 133 jint tool_type) |
133 : id(id), | 134 : id(id), |
134 pos_x_pixels(pos_x_pixels), | 135 pos_x_pixels(pos_x_pixels), |
135 pos_y_pixels(pos_y_pixels), | 136 pos_y_pixels(pos_y_pixels), |
136 touch_major_pixels(touch_major_pixels), | 137 touch_major_pixels(touch_major_pixels), |
137 touch_minor_pixels(touch_minor_pixels), | 138 touch_minor_pixels(touch_minor_pixels), |
138 orientation_rad(orientation_rad), | 139 orientation_rad(orientation_rad), |
| 140 tilt_rad(tilt_rad), |
139 tool_type(tool_type) { | 141 tool_type(tool_type) { |
140 } | 142 } |
141 | 143 |
142 MotionEventAndroid::CachedPointer::CachedPointer() | 144 MotionEventAndroid::CachedPointer::CachedPointer() |
143 : id(0), | 145 : id(0), |
144 touch_major(0), | 146 touch_major(0), |
145 touch_minor(0), | 147 touch_minor(0), |
146 orientation(0), | 148 orientation(0), |
| 149 tilt(0), |
147 tool_type(TOOL_TYPE_UNKNOWN) { | 150 tool_type(TOOL_TYPE_UNKNOWN) { |
148 } | 151 } |
149 | 152 |
150 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, | 153 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, |
151 JNIEnv* env, | 154 JNIEnv* env, |
152 jobject event, | 155 jobject event, |
153 jlong time_ms, | 156 jlong time_ms, |
154 jint android_action, | 157 jint android_action, |
155 jint pointer_count, | 158 jint pointer_count, |
156 jint history_size, | 159 jint history_size, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 DCHECK_LT(pointer_index, cached_pointer_count_); | 269 DCHECK_LT(pointer_index, cached_pointer_count_); |
267 // Note that this early return is a special case exercised only in testing, as | 270 // Note that this early return is a special case exercised only in testing, as |
268 // caching the pressure values is not a worthwhile optimization (they're | 271 // caching the pressure values is not a worthwhile optimization (they're |
269 // accessed at most once per event instance). | 272 // accessed at most once per event instance). |
270 if (!event_.obj()) | 273 if (!event_.obj()) |
271 return 0.f; | 274 return 0.f; |
272 return Java_MotionEvent_getPressureF_I( | 275 return Java_MotionEvent_getPressureF_I( |
273 AttachCurrentThread(), event_.obj(), pointer_index); | 276 AttachCurrentThread(), event_.obj(), pointer_index); |
274 } | 277 } |
275 | 278 |
| 279 float MotionEventAndroid::GetTilt(size_t pointer_index) const { |
| 280 DCHECK_LT(pointer_index, cached_pointer_count_); |
| 281 if (pointer_index < MAX_POINTERS_TO_CACHE) |
| 282 return cached_pointers_[pointer_index].tilt; |
| 283 if (!event_.obj()) |
| 284 return 0.f; |
| 285 return ToValidFloat(Java_MotionEvent_getAxisValueF_I_I( |
| 286 AttachCurrentThread(), event_.obj(), AXIS_TILT, pointer_index)); |
| 287 } |
| 288 |
276 base::TimeTicks MotionEventAndroid::GetEventTime() const { | 289 base::TimeTicks MotionEventAndroid::GetEventTime() const { |
277 return cached_time_; | 290 return cached_time_; |
278 } | 291 } |
279 | 292 |
280 size_t MotionEventAndroid::GetHistorySize() const { | 293 size_t MotionEventAndroid::GetHistorySize() const { |
281 return cached_history_size_; | 294 return cached_history_size_; |
282 } | 295 } |
283 | 296 |
284 base::TimeTicks MotionEventAndroid::GetHistoricalEventTime( | 297 base::TimeTicks MotionEventAndroid::GetHistoricalEventTime( |
285 size_t historical_index) const { | 298 size_t historical_index) const { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 342 |
330 MotionEventAndroid::CachedPointer MotionEventAndroid::FromAndroidPointer( | 343 MotionEventAndroid::CachedPointer MotionEventAndroid::FromAndroidPointer( |
331 const Pointer& pointer) const { | 344 const Pointer& pointer) const { |
332 CachedPointer result; | 345 CachedPointer result; |
333 result.id = pointer.id; | 346 result.id = pointer.id; |
334 result.position = | 347 result.position = |
335 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); | 348 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); |
336 result.touch_major = ToDips(pointer.touch_major_pixels); | 349 result.touch_major = ToDips(pointer.touch_major_pixels); |
337 result.touch_minor = ToDips(pointer.touch_minor_pixels); | 350 result.touch_minor = ToDips(pointer.touch_minor_pixels); |
338 result.orientation = ToValidFloat(pointer.orientation_rad); | 351 result.orientation = ToValidFloat(pointer.orientation_rad); |
| 352 result.tilt = ToValidFloat(pointer.tilt_rad); |
339 result.tool_type = FromAndroidToolType(pointer.tool_type); | 353 result.tool_type = FromAndroidToolType(pointer.tool_type); |
340 return result; | 354 return result; |
341 } | 355 } |
342 | 356 |
343 // static | 357 // static |
344 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { | 358 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { |
345 return JNI_MotionEvent::RegisterNativesImpl(env); | 359 return JNI_MotionEvent::RegisterNativesImpl(env); |
346 } | 360 } |
347 | 361 |
348 } // namespace content | 362 } // namespace content |
OLD | NEW |