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