Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: content/browser/renderer_host/input/motion_event_android.cc

Issue 755403006: Added experimental Touch.tilt, Touch.tiltDirection support for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added EventSender.SetTouchPointTilt() for tests Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 235 }
234 236
235 float MotionEventAndroid::GetOrientation(size_t pointer_index) const { 237 float MotionEventAndroid::GetOrientation(size_t pointer_index) const {
236 DCHECK_LT(pointer_index, cached_pointer_count_); 238 DCHECK_LT(pointer_index, cached_pointer_count_);
237 if (pointer_index < MAX_POINTERS_TO_CACHE) 239 if (pointer_index < MAX_POINTERS_TO_CACHE)
238 return cached_pointers_[pointer_index].orientation; 240 return cached_pointers_[pointer_index].orientation;
239 return ToValidFloat(Java_MotionEvent_getOrientationF_I( 241 return ToValidFloat(Java_MotionEvent_getOrientationF_I(
240 AttachCurrentThread(), event_.obj(), pointer_index)); 242 AttachCurrentThread(), event_.obj(), pointer_index));
241 } 243 }
242 244
245 float MotionEventAndroid::GetTilt(size_t pointer_index) const {
246 if (!event_.obj())
247 return std::numeric_limits<float>::quiet_NaN();
248
249 return Java_MotionEventUtil_getAxisValueOrNaN(
250 AttachCurrentThread(), event_.obj(), AXIS_TILT, pointer_index);
251 }
252
253 float MotionEventAndroid::GetTiltDirection(size_t pointer_index) const {
254 if (!event_.obj())
255 return std::numeric_limits<float>::quiet_NaN();
256
257 return Java_MotionEventUtil_getAxisValueOrNaN(
258 AttachCurrentThread(), event_.obj(), AXIS_ORIENTATION, pointer_index);
259 }
260
243 float MotionEventAndroid::GetPressure(size_t pointer_index) const { 261 float MotionEventAndroid::GetPressure(size_t pointer_index) const {
244 DCHECK_LT(pointer_index, cached_pointer_count_); 262 DCHECK_LT(pointer_index, cached_pointer_count_);
245 // Note that this early return is a special case exercised only in testing, as 263 // Note that this early return is a special case exercised only in testing, as
246 // caching the pressure values is not a worthwhile optimization (they're 264 // caching the pressure values is not a worthwhile optimization (they're
247 // accessed at most once per event instance). 265 // accessed at most once per event instance).
248 if (!event_.obj()) 266 if (!event_.obj())
249 return 0.f; 267 return 0.f;
250 return Java_MotionEvent_getPressureF_I( 268 return Java_MotionEvent_getPressureF_I(
251 AttachCurrentThread(), event_.obj(), pointer_index); 269 AttachCurrentThread(), event_.obj(), pointer_index);
252 } 270 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); 331 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels));
314 result.touch_major = ToDips(pointer.touch_major_pixels); 332 result.touch_major = ToDips(pointer.touch_major_pixels);
315 result.touch_minor = ToDips(pointer.touch_minor_pixels); 333 result.touch_minor = ToDips(pointer.touch_minor_pixels);
316 result.orientation = ToValidFloat(pointer.orientation_rad); 334 result.orientation = ToValidFloat(pointer.orientation_rad);
317 result.tool_type = FromAndroidToolType(pointer.tool_type); 335 result.tool_type = FromAndroidToolType(pointer.tool_type);
318 return result; 336 return result;
319 } 337 }
320 338
321 // static 339 // static
322 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { 340 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) {
323 return JNI_MotionEvent::RegisterNativesImpl(env); 341 return JNI_MotionEvent::RegisterNativesImpl(env)
342 && JNI_MotionEventUtil::RegisterNativesImpl(env);
324 } 343 }
325 344
326 } // namespace content 345 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698