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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
16 // Utility wrapper class for Android's android.view.MotionEvent.
17 class MotionEventAndroid {
19 // Note: These constants are taken directly from android.view.MotionEvent.
20 // Do NOT under any circumstances change these values.
26 // Purposefully removed, as there is no analogous action in Chromium.
27 // ACTION_OUTSIDE = 4,
28 ACTION_POINTER_DOWN = 5,
32 explicit MotionEventAndroid(jobject event);
33 ~MotionEventAndroid();
35 Action GetActionMasked() const;
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); }
40 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(size_t pointer_index) const;
51 float GetOrientation() const;
52 base::TimeTicks GetEventTime() const;
53 base::TimeTicks GetDownTime() const;
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;
62 static bool RegisterMotionEventAndroid(JNIEnv* env);
64 static scoped_ptr<MotionEventAndroid> Obtain(const MotionEventAndroid& event);
65 static scoped_ptr<MotionEventAndroid> Obtain(base::TimeTicks down_time,
66 base::TimeTicks event_time,
72 MotionEventAndroid(const base::android::ScopedJavaLocalRef<jobject>& event,
75 // The Java reference to the underlying MotionEvent.
76 base::android::ScopedJavaGlobalRef<jobject> event_;
78 // Whether |event_| should be recycled on destruction. This will only be true
79 // for those events generated via |Obtain(...)|.
82 DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid);
85 } // namespace content
87 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_