| 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 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 // Utility wrapper class for Android's android.view.MotionEvent. | 17 // Implementation of ui::MotionEvent wrapping a native Android MotionEvent. |
| 17 class MotionEventAndroid { | 18 class MotionEventAndroid : public ui::MotionEvent { |
| 18 public: | 19 public: |
| 19 // Note: These constants are taken directly from android.view.MotionEvent. | 20 MotionEventAndroid(JNIEnv* env, jobject event, bool recycle); |
| 20 // Do NOT under any circumstances change these values. | 21 virtual ~MotionEventAndroid(); |
| 21 enum Action { | |
| 22 ACTION_DOWN = 0, | |
| 23 ACTION_UP = 1, | |
| 24 ACTION_MOVE = 2, | |
| 25 ACTION_CANCEL = 3, | |
| 26 // Purposefully removed, as there is no analogous action in Chromium. | |
| 27 // ACTION_OUTSIDE = 4, | |
| 28 ACTION_POINTER_DOWN = 5, | |
| 29 ACTION_POINTER_UP = 6 | |
| 30 }; | |
| 31 | 22 |
| 32 explicit MotionEventAndroid(jobject event); | 23 // ui::MotionEvent methods. |
| 33 ~MotionEventAndroid(); | 24 virtual Action GetAction() const OVERRIDE; |
| 25 virtual int GetActionIndex() const OVERRIDE; |
| 26 virtual size_t GetPointerCount() const OVERRIDE; |
| 27 virtual int GetPointerId(size_t pointer_index) const OVERRIDE; |
| 28 virtual float GetX(size_t pointer_index) const OVERRIDE; |
| 29 virtual float GetY(size_t pointer_index) const OVERRIDE; |
| 30 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE; |
| 31 virtual base::TimeTicks GetEventTime() const OVERRIDE; |
| 32 virtual size_t GetHistorySize() const OVERRIDE; |
| 33 virtual base::TimeTicks GetHistoricalEventTime( |
| 34 size_t historical_index) const OVERRIDE; |
| 35 virtual float GetHistoricalTouchMajor( |
| 36 size_t pointer_index, |
| 37 size_t historical_index) const OVERRIDE; |
| 38 virtual float GetHistoricalX( |
| 39 size_t pointer_index, |
| 40 size_t historical_index) const OVERRIDE; |
| 41 virtual float GetHistoricalY( |
| 42 size_t pointer_index, |
| 43 size_t historical_index) const OVERRIDE; |
| 44 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE; |
| 45 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE; |
| 34 | 46 |
| 35 Action GetActionMasked() const; | 47 // Additional Android MotionEvent methods. |
| 36 size_t GetActionIndex() const; | |
| 37 size_t GetPointerCount() const; | |
| 38 int GetPointerId(size_t pointer_index) const; | |
| 39 float GetPressure() const { return GetPressure(0); } | 48 float GetPressure() const { return GetPressure(0); } |
| 40 float GetPressure(size_t pointer_index) const; | 49 float GetPressure(size_t pointer_index) const; |
| 41 float GetX() const { return GetX(0); } | |
| 42 float GetY() const { return GetY(0); } | |
| 43 float GetX(size_t pointer_index) const; | |
| 44 float GetY(size_t pointer_index) const; | |
| 45 float GetRawX() const { return GetX(); } | |
| 46 float GetRawY() const { return GetY(); } | |
| 47 float GetTouchMajor() const { return GetTouchMajor(0); } | |
| 48 float GetTouchMajor(size_t pointer_index) const; | |
| 49 float GetTouchMinor() const { return GetTouchMinor(0); } | 50 float GetTouchMinor() const { return GetTouchMinor(0); } |
| 50 float GetTouchMinor(size_t pointer_index) const; | 51 float GetTouchMinor(size_t pointer_index) const; |
| 51 float GetOrientation() const; | 52 float GetOrientation() const; |
| 52 base::TimeTicks GetEventTime() const; | |
| 53 base::TimeTicks GetDownTime() const; | 53 base::TimeTicks GetDownTime() const; |
| 54 | 54 |
| 55 size_t GetHistorySize() const; | |
| 56 base::TimeTicks GetHistoricalEventTime(size_t historical_index) const; | |
| 57 float GetHistoricalTouchMajor(size_t pointer_index, | |
| 58 size_t historical_index) const; | |
| 59 float GetHistoricalX(size_t pointer_index, size_t historical_index) const; | |
| 60 float GetHistoricalY(size_t pointer_index, size_t historical_index) const; | |
| 61 | |
| 62 static bool RegisterMotionEventAndroid(JNIEnv* env); | 55 static bool RegisterMotionEventAndroid(JNIEnv* env); |
| 63 | 56 |
| 64 static scoped_ptr<MotionEventAndroid> Obtain(const MotionEventAndroid& event); | 57 static base::android::ScopedJavaLocalRef<jobject> Obtain( |
| 65 static scoped_ptr<MotionEventAndroid> Obtain(base::TimeTicks down_time, | 58 const MotionEventAndroid& event); |
| 66 base::TimeTicks event_time, | 59 static base::android::ScopedJavaLocalRef<jobject> Obtain( |
| 67 Action action, | 60 base::TimeTicks down_time, |
| 68 float x, | 61 base::TimeTicks event_time, |
| 69 float y); | 62 Action action, |
| 63 float x, |
| 64 float y); |
| 70 | 65 |
| 71 private: | 66 private: |
| 72 MotionEventAndroid(const base::android::ScopedJavaLocalRef<jobject>& event, | 67 MotionEventAndroid(const MotionEventAndroid& other, bool clone); |
| 73 bool should_recycle); | |
| 74 | 68 |
| 75 // The Java reference to the underlying MotionEvent. | 69 // The Java reference to the underlying MotionEvent. |
| 76 base::android::ScopedJavaGlobalRef<jobject> event_; | 70 base::android::ScopedJavaGlobalRef<jobject> event_; |
| 77 | 71 |
| 72 base::TimeTicks cached_time_; |
| 73 Action cached_action_; |
| 74 size_t cached_pointer_count_; |
| 75 size_t cached_history_size_; |
| 76 int cached_action_index_; |
| 77 float cached_x_; |
| 78 float cached_y_; |
| 79 |
| 78 // Whether |event_| should be recycled on destruction. This will only be true | 80 // Whether |event_| should be recycled on destruction. This will only be true |
| 79 // for those events generated via |Obtain(...)|. | 81 // for those events generated via |Obtain(...)|. |
| 80 bool should_recycle_; | 82 bool should_recycle_; |
| 81 | 83 |
| 82 DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid); | 84 DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid); |
| 83 }; | 85 }; |
| 84 | 86 |
| 85 } // namespace content | 87 } // namespace content |
| 86 | 88 |
| 87 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ | 89 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_ |
| OLD | NEW |