| 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 "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
| 11 #include "jni/MotionEventUtil_jni.h" |
| 11 #include "jni/MotionEvent_jni.h" | 12 #include "jni/MotionEvent_jni.h" |
| 12 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 13 | 14 |
| 14 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 15 using namespace JNI_MotionEvent; | 16 using namespace JNI_MotionEvent; |
| 17 using namespace JNI_MotionEventUtil; |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 MotionEventAndroid::Action FromAndroidAction(int android_action) { | 22 MotionEventAndroid::Action FromAndroidAction(int android_action) { |
| 21 switch (android_action) { | 23 switch (android_action) { |
| 22 case ACTION_DOWN: | 24 case ACTION_DOWN: |
| 23 return MotionEventAndroid::ACTION_DOWN; | 25 return MotionEventAndroid::ACTION_DOWN; |
| 24 case ACTION_UP: | 26 case ACTION_UP: |
| 25 return MotionEventAndroid::ACTION_UP; | 27 return MotionEventAndroid::ACTION_UP; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 250 } |
| 249 | 251 |
| 250 float MotionEventAndroid::GetOrientation(size_t pointer_index) const { | 252 float MotionEventAndroid::GetOrientation(size_t pointer_index) const { |
| 251 DCHECK_LT(pointer_index, cached_pointer_count_); | 253 DCHECK_LT(pointer_index, cached_pointer_count_); |
| 252 if (pointer_index < MAX_POINTERS_TO_CACHE) | 254 if (pointer_index < MAX_POINTERS_TO_CACHE) |
| 253 return cached_pointers_[pointer_index].orientation; | 255 return cached_pointers_[pointer_index].orientation; |
| 254 return ToValidFloat(Java_MotionEvent_getOrientationF_I( | 256 return ToValidFloat(Java_MotionEvent_getOrientationF_I( |
| 255 AttachCurrentThread(), event_.obj(), pointer_index)); | 257 AttachCurrentThread(), event_.obj(), pointer_index)); |
| 256 } | 258 } |
| 257 | 259 |
| 260 float MotionEventAndroid::GetTilt(size_t pointer_index) const { |
| 261 if (!event_.obj()) |
| 262 return std::numeric_limits<float>::quiet_NaN(); |
| 263 |
| 264 return Java_MotionEventUtil_getAxisValueOrNaN( |
| 265 AttachCurrentThread(), event_.obj(), AXIS_TILT, pointer_index); |
| 266 } |
| 267 |
| 268 float MotionEventAndroid::GetTiltDirection(size_t pointer_index) const { |
| 269 if (!event_.obj()) |
| 270 return std::numeric_limits<float>::quiet_NaN(); |
| 271 |
| 272 return Java_MotionEventUtil_getAxisValueOrNaN( |
| 273 AttachCurrentThread(), event_.obj(), AXIS_ORIENTATION, pointer_index); |
| 274 } |
| 275 |
| 258 float MotionEventAndroid::GetPressure(size_t pointer_index) const { | 276 float MotionEventAndroid::GetPressure(size_t pointer_index) const { |
| 259 DCHECK_LT(pointer_index, cached_pointer_count_); | 277 DCHECK_LT(pointer_index, cached_pointer_count_); |
| 260 // Note that this early return is a special case exercised only in testing, as | 278 // Note that this early return is a special case exercised only in testing, as |
| 261 // caching the pressure values is not a worthwhile optimization (they're | 279 // caching the pressure values is not a worthwhile optimization (they're |
| 262 // accessed at most once per event instance). | 280 // accessed at most once per event instance). |
| 263 if (!event_.obj()) | 281 if (!event_.obj()) |
| 264 return 0.f; | 282 return 0.f; |
| 265 return Java_MotionEvent_getPressureF_I( | 283 return Java_MotionEvent_getPressureF_I( |
| 266 AttachCurrentThread(), event_.obj(), pointer_index); | 284 AttachCurrentThread(), event_.obj(), pointer_index); |
| 267 } | 285 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); | 346 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); |
| 329 result.touch_major = ToDips(pointer.touch_major_pixels); | 347 result.touch_major = ToDips(pointer.touch_major_pixels); |
| 330 result.touch_minor = ToDips(pointer.touch_minor_pixels); | 348 result.touch_minor = ToDips(pointer.touch_minor_pixels); |
| 331 result.orientation = ToValidFloat(pointer.orientation_rad); | 349 result.orientation = ToValidFloat(pointer.orientation_rad); |
| 332 result.tool_type = FromAndroidToolType(pointer.tool_type); | 350 result.tool_type = FromAndroidToolType(pointer.tool_type); |
| 333 return result; | 351 return result; |
| 334 } | 352 } |
| 335 | 353 |
| 336 // static | 354 // static |
| 337 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { | 355 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { |
| 338 return JNI_MotionEvent::RegisterNativesImpl(env); | 356 return JNI_MotionEvent::RegisterNativesImpl(env) |
| 357 && JNI_MotionEventUtil::RegisterNativesImpl(env); |
| 339 } | 358 } |
| 340 | 359 |
| 341 } // namespace content | 360 } // namespace content |
| OLD | NEW |