| 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "ui/events/gesture_detection/motion_event.h" | 13 #include "ui/events/gesture_detection/motion_event.h" |
| 14 #include "ui/gfx/geometry/point_f.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 // Implementation of ui::MotionEvent wrapping a native Android MotionEvent. | 18 // Implementation of ui::MotionEvent wrapping a native Android MotionEvent. |
| 18 class MotionEventAndroid : public ui::MotionEvent { | 19 class MotionEventAndroid : public ui::MotionEvent { |
| 19 public: | 20 public: |
| 20 MotionEventAndroid(JNIEnv* env, jobject event, bool recycle); | 21 // Forcing the caller to provide all cached values upon construction |
| 22 // eliminates the need to perform a JNI call to retrieve values individually. |
| 23 MotionEventAndroid(JNIEnv* env, |
| 24 jobject event, |
| 25 jlong time_ms, |
| 26 jint android_action, |
| 27 jint pointer_count, |
| 28 jint history_size, |
| 29 jint action_index, |
| 30 jfloat pos_x_0, |
| 31 jfloat pos_y_0, |
| 32 jfloat pos_x_1, |
| 33 jfloat pos_y_1, |
| 34 jint pointer_id_0, |
| 35 jint pointer_id_1, |
| 36 jfloat touch_major_0, |
| 37 jfloat touch_major_1); |
| 21 virtual ~MotionEventAndroid(); | 38 virtual ~MotionEventAndroid(); |
| 22 | 39 |
| 23 // ui::MotionEvent methods. | 40 // ui::MotionEvent methods. |
| 24 virtual Action GetAction() const OVERRIDE; | 41 virtual Action GetAction() const OVERRIDE; |
| 25 virtual int GetActionIndex() const OVERRIDE; | 42 virtual int GetActionIndex() const OVERRIDE; |
| 26 virtual size_t GetPointerCount() const OVERRIDE; | 43 virtual size_t GetPointerCount() const OVERRIDE; |
| 27 virtual int GetPointerId(size_t pointer_index) const OVERRIDE; | 44 virtual int GetPointerId(size_t pointer_index) const OVERRIDE; |
| 28 virtual float GetX(size_t pointer_index) const OVERRIDE; | 45 virtual float GetX(size_t pointer_index) const OVERRIDE; |
| 29 virtual float GetY(size_t pointer_index) const OVERRIDE; | 46 virtual float GetY(size_t pointer_index) const OVERRIDE; |
| 30 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE; | 47 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 57 const MotionEventAndroid& event); | 74 const MotionEventAndroid& event); |
| 58 static base::android::ScopedJavaLocalRef<jobject> Obtain( | 75 static base::android::ScopedJavaLocalRef<jobject> Obtain( |
| 59 base::TimeTicks down_time, | 76 base::TimeTicks down_time, |
| 60 base::TimeTicks event_time, | 77 base::TimeTicks event_time, |
| 61 Action action, | 78 Action action, |
| 62 float x, | 79 float x, |
| 63 float y); | 80 float y); |
| 64 | 81 |
| 65 private: | 82 private: |
| 66 MotionEventAndroid(); | 83 MotionEventAndroid(); |
| 84 MotionEventAndroid(JNIEnv* env, jobject event); |
| 67 MotionEventAndroid(const MotionEventAndroid&); | 85 MotionEventAndroid(const MotionEventAndroid&); |
| 68 MotionEventAndroid& operator=(const MotionEventAndroid&); | 86 MotionEventAndroid& operator=(const MotionEventAndroid&); |
| 69 | 87 |
| 88 // Cache pointer coords, id's and major lengths for the most common |
| 89 // touch-related scenarios, i.e., scrolling and pinching. This prevents |
| 90 // redundant JNI fetches for the same bits. |
| 91 enum { MAX_POINTERS_TO_CACHE = 2 }; |
| 92 |
| 70 // The Java reference to the underlying MotionEvent. | 93 // The Java reference to the underlying MotionEvent. |
| 71 base::android::ScopedJavaGlobalRef<jobject> event_; | 94 base::android::ScopedJavaGlobalRef<jobject> event_; |
| 72 | 95 |
| 73 base::TimeTicks cached_time_; | 96 base::TimeTicks cached_time_; |
| 74 Action cached_action_; | 97 Action cached_action_; |
| 75 size_t cached_pointer_count_; | 98 size_t cached_pointer_count_; |
| 76 size_t cached_history_size_; | 99 size_t cached_history_size_; |
| 77 int cached_action_index_; | 100 int cached_action_index_; |
| 78 float cached_x_; | 101 gfx::PointF cached_positions_[MAX_POINTERS_TO_CACHE]; |
| 79 float cached_y_; | 102 int cached_pointer_ids_[MAX_POINTERS_TO_CACHE]; |
| 103 float cached_touch_majors_[MAX_POINTERS_TO_CACHE]; |
| 80 | 104 |
| 81 // Whether |event_| should be recycled on destruction. This will only be true | 105 // Whether |event_| should be recycled on destruction. This will only be true |
| 82 // for those events generated via |Obtain(...)|. | 106 // for those events generated via |Obtain(...)|. |
| 83 bool should_recycle_; | 107 bool should_recycle_; |
| 84 }; | 108 }; |
| 85 | 109 |
| 86 } // namespace content | 110 } // namespace content |
| 87 | 111 |
| 88 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ | 112 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ |
| OLD | NEW |