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

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

Issue 1147083005: Separate motion event touch geometry orientation from stylus orientation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Aura Created 5 years, 7 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 <cmath> 9 #include <cmath>
10 10
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 252
253 float MotionEventAndroid::GetOrientation(size_t pointer_index) const { 253 float MotionEventAndroid::GetOrientation(size_t pointer_index) const {
254 DCHECK_LT(pointer_index, cached_pointer_count_); 254 DCHECK_LT(pointer_index, cached_pointer_count_);
255 if (pointer_index < MAX_POINTERS_TO_CACHE) 255 if (pointer_index < MAX_POINTERS_TO_CACHE)
256 return cached_pointers_[pointer_index].orientation; 256 return cached_pointers_[pointer_index].orientation;
257 return ToValidFloat(Java_MotionEvent_getOrientationF_I( 257 return ToValidFloat(Java_MotionEvent_getOrientationF_I(
258 AttachCurrentThread(), event_.obj(), pointer_index)); 258 AttachCurrentThread(), event_.obj(), pointer_index));
259 } 259 }
260 260
261 float MotionEventAndroid::GetTouchOrientation(size_t pointer_index) const {
262 float orientation = GetOrientation(pointer_index);
263 // The meaning of the motion event orientation is overloaded on Android.
264 // * For a touch screen or pad, it's the orientation of the touch major axis
265 // clockwise from vertical. The value lies in [-PI/1, PI/2].
266 // * For a stylus, it indicates the direction in which the stylus is pointing
267 // clockwise from top. The value lies in [-PI, PI].
268 // Map to touch major axis orientation.
269 if (orientation <= -M_PI_2)
270 return orientation + M_PI;
271 if (orientation >= M_PI_2)
272 return orientation - M_PI;
273 return orientation;
274 }
275
261 float MotionEventAndroid::GetPressure(size_t pointer_index) const { 276 float MotionEventAndroid::GetPressure(size_t pointer_index) const {
262 DCHECK_LT(pointer_index, cached_pointer_count_); 277 DCHECK_LT(pointer_index, cached_pointer_count_);
263 // 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
264 // caching the pressure values is not a worthwhile optimization (they're 279 // caching the pressure values is not a worthwhile optimization (they're
265 // accessed at most once per event instance). 280 // accessed at most once per event instance).
266 if (!event_.obj()) 281 if (!event_.obj())
267 return 0.f; 282 return 0.f;
268 return Java_MotionEvent_getPressureF_I( 283 return Java_MotionEvent_getPressureF_I(
269 AttachCurrentThread(), event_.obj(), pointer_index); 284 AttachCurrentThread(), event_.obj(), pointer_index);
270 } 285 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 result.tool_type = FromAndroidToolType(pointer.tool_type); 350 result.tool_type = FromAndroidToolType(pointer.tool_type);
336 return result; 351 return result;
337 } 352 }
338 353
339 // static 354 // static
340 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { 355 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) {
341 return JNI_MotionEvent::RegisterNativesImpl(env); 356 return JNI_MotionEvent::RegisterNativesImpl(env);
342 } 357 }
343 358
344 } // namespace content 359 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698