Chromium Code Reviews| 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 UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ | 5 #ifndef UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ |
| 6 #define UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ | 6 #define UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 // Forcing the caller to provide all cached values upon construction | 47 // Forcing the caller to provide all cached values upon construction |
| 48 // eliminates the need to perform a JNI call to retrieve values individually. | 48 // eliminates the need to perform a JNI call to retrieve values individually. |
| 49 MotionEventAndroid(float pix_to_dip, | 49 MotionEventAndroid(float pix_to_dip, |
| 50 JNIEnv* env, | 50 JNIEnv* env, |
| 51 jobject event, | 51 jobject event, |
| 52 jlong time_ms, | 52 jlong time_ms, |
| 53 jint android_action, | 53 jint android_action, |
| 54 jint pointer_count, | 54 jint pointer_count, |
| 55 jint history_size, | 55 jint history_size, |
| 56 jint action_index, | 56 jint action_index, |
| 57 jint android_action_button, | |
| 57 jint android_button_state, | 58 jint android_button_state, |
| 58 jint meta_state, | 59 jint meta_state, |
| 59 jfloat raw_offset_x_pixels, | 60 jfloat raw_offset_x_pixels, |
| 60 jfloat raw_offset_y_pixels, | 61 jfloat raw_offset_y_pixels, |
| 61 const Pointer* const pointer0, | 62 const Pointer* const pointer0, |
| 62 const Pointer* const pointer1); | 63 const Pointer* const pointer1); |
| 63 ~MotionEventAndroid() override; | 64 ~MotionEventAndroid() override; |
| 64 | 65 |
| 66 MotionEventAndroid(const MotionEventAndroid& e, float x, float y); | |
|
boliu
2017/03/03 22:01:32
can we just have an offset(x,y) method that return
Jinsuk Kim
2017/03/06 04:07:34
Done this way since copy/Assign is disallowed. See
boliu
2017/03/06 22:08:04
oh is it because the return by value is a copy? Pa
Jinsuk Kim
2017/03/07 05:02:23
Added |Offset| that returns std::unique_ptr, and a
| |
| 67 | |
| 65 // ui::MotionEvent methods. | 68 // ui::MotionEvent methods. |
| 66 uint32_t GetUniqueEventId() const override; | 69 uint32_t GetUniqueEventId() const override; |
| 67 Action GetAction() const override; | 70 Action GetAction() const override; |
| 68 int GetActionIndex() const override; | 71 int GetActionIndex() const override; |
| 69 size_t GetPointerCount() const override; | 72 size_t GetPointerCount() const override; |
| 70 int GetPointerId(size_t pointer_index) const override; | 73 int GetPointerId(size_t pointer_index) const override; |
| 71 float GetX(size_t pointer_index) const override; | 74 float GetX(size_t pointer_index) const override; |
| 72 float GetY(size_t pointer_index) const override; | 75 float GetY(size_t pointer_index) const override; |
| 73 float GetRawX(size_t pointer_index) const override; | 76 float GetRawX(size_t pointer_index) const override; |
| 74 float GetRawY(size_t pointer_index) const override; | 77 float GetRawY(size_t pointer_index) const override; |
| 75 float GetTouchMajor(size_t pointer_index) const override; | 78 float GetTouchMajor(size_t pointer_index) const override; |
| 76 float GetTouchMinor(size_t pointer_index) const override; | 79 float GetTouchMinor(size_t pointer_index) const override; |
| 77 float GetOrientation(size_t pointer_index) const override; | 80 float GetOrientation(size_t pointer_index) const override; |
| 78 float GetPressure(size_t pointer_index) const override; | 81 float GetPressure(size_t pointer_index) const override; |
| 79 float GetTilt(size_t pointer_index) const override; | 82 float GetTilt(size_t pointer_index) const override; |
| 80 base::TimeTicks GetEventTime() const override; | 83 base::TimeTicks GetEventTime() const override; |
| 81 size_t GetHistorySize() const override; | 84 size_t GetHistorySize() const override; |
| 82 base::TimeTicks GetHistoricalEventTime( | 85 base::TimeTicks GetHistoricalEventTime( |
| 83 size_t historical_index) const override; | 86 size_t historical_index) const override; |
| 84 float GetHistoricalTouchMajor(size_t pointer_index, | 87 float GetHistoricalTouchMajor(size_t pointer_index, |
| 85 size_t historical_index) const override; | 88 size_t historical_index) const override; |
| 86 float GetHistoricalX(size_t pointer_index, | 89 float GetHistoricalX(size_t pointer_index, |
| 87 size_t historical_index) const override; | 90 size_t historical_index) const override; |
| 88 float GetHistoricalY(size_t pointer_index, | 91 float GetHistoricalY(size_t pointer_index, |
| 89 size_t historical_index) const override; | 92 size_t historical_index) const override; |
| 90 ToolType GetToolType(size_t pointer_index) const override; | 93 ToolType GetToolType(size_t pointer_index) const override; |
| 91 int GetButtonState() const override; | 94 int GetButtonState() const override; |
| 92 int GetFlags() const override; | 95 int GetFlags() const override; |
| 93 | 96 |
| 97 int GetActionButton() const; | |
| 98 base::android::ScopedJavaLocalRef<jobject> GetJavaObject() const; | |
| 99 | |
| 94 private: | 100 private: |
| 95 struct CachedPointer; | 101 struct CachedPointer; |
| 96 | 102 |
| 97 float ToDips(float pixels) const; | 103 float ToDips(float pixels) const; |
| 98 CachedPointer FromAndroidPointer(const Pointer& pointer) const; | 104 CachedPointer FromAndroidPointer(const Pointer& pointer) const; |
| 105 CachedPointer FromCachedPointer(const CachedPointer& pointer, | |
| 106 float x, | |
| 107 float y) const; | |
| 99 | 108 |
| 100 // Cache pointer coords, id's and major lengths for the most common | 109 // Cache pointer coords, id's and major lengths for the most common |
| 101 // touch-related scenarios, i.e., scrolling and pinching. This prevents | 110 // touch-related scenarios, i.e., scrolling and pinching. This prevents |
| 102 // redundant JNI fetches for the same bits. | 111 // redundant JNI fetches for the same bits. |
| 103 enum { MAX_POINTERS_TO_CACHE = 2 }; | 112 enum { MAX_POINTERS_TO_CACHE = 2 }; |
| 104 | 113 |
| 105 // The Java reference to the underlying MotionEvent. | 114 // The Java reference to the underlying MotionEvent. |
| 106 base::android::ScopedJavaGlobalRef<jobject> event_; | 115 base::android::ScopedJavaGlobalRef<jobject> event_; |
| 107 | 116 |
| 108 // Used to convert pixel coordinates from the Java-backed MotionEvent to | 117 // Used to convert pixel coordinates from the Java-backed MotionEvent to |
| 109 // DIP coordinates cached/returned by the MotionEventAndroid. | 118 // DIP coordinates cached/returned by the MotionEventAndroid. |
| 110 const float pix_to_dip_; | 119 const float pix_to_dip_; |
| 111 | 120 |
| 112 const base::TimeTicks cached_time_; | 121 const base::TimeTicks cached_time_; |
| 113 const Action cached_action_; | 122 const Action cached_action_; |
| 114 const size_t cached_pointer_count_; | 123 const size_t cached_pointer_count_; |
| 115 const size_t cached_history_size_; | 124 const size_t cached_history_size_; |
| 116 const int cached_action_index_; | 125 const int cached_action_index_; |
| 126 const int cached_action_button_; | |
| 117 const int cached_button_state_; | 127 const int cached_button_state_; |
| 118 const int cached_flags_; | 128 const int cached_flags_; |
| 119 const gfx::Vector2dF cached_raw_position_offset_; | 129 const gfx::Vector2dF cached_raw_position_offset_; |
| 120 struct CachedPointer { | 130 struct CachedPointer { |
| 121 CachedPointer(); | 131 CachedPointer(); |
| 122 int id; | 132 int id; |
| 123 gfx::PointF position; | 133 gfx::PointF position; |
| 124 float touch_major; | 134 float touch_major; |
| 125 float touch_minor; | 135 float touch_minor; |
| 126 float orientation; | 136 float orientation; |
| 127 float tilt; | 137 float tilt; |
| 128 ToolType tool_type; | 138 ToolType tool_type; |
| 129 } cached_pointers_[MAX_POINTERS_TO_CACHE]; | 139 } cached_pointers_[MAX_POINTERS_TO_CACHE]; |
| 130 | 140 |
| 131 // A unique identifier for the Android motion event. | 141 // A unique identifier for the Android motion event. |
| 132 const uint32_t unique_event_id_; | 142 const uint32_t unique_event_id_; |
| 133 | 143 |
| 134 DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid); | 144 DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid); |
| 135 }; | 145 }; |
| 136 | 146 |
| 137 } // namespace content | 147 } // namespace content |
| 138 | 148 |
| 139 #endif // UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ | 149 #endif // UI_EVENTS_ANDROID_MOTION_EVENT_ANDROID_H_ |
| OLD | NEW |