Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / input / motion_event_android.h
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.
4
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_
7
8 #include <jni.h>
9
10 #include "base/android/scoped_java_ref.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13
14 namespace content {
15
16 // Utility wrapper class for Android's android.view.MotionEvent.
17 class MotionEventAndroid {
18  public:
19   // Note: These constants are taken directly from android.view.MotionEvent.
20   //       Do NOT under any circumstances change these values.
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
32   explicit MotionEventAndroid(jobject event);
33   ~MotionEventAndroid();
34
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;
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);
63
64   static scoped_ptr<MotionEventAndroid> Obtain(const MotionEventAndroid& event);
65   static scoped_ptr<MotionEventAndroid> Obtain(base::TimeTicks down_time,
66                                                base::TimeTicks event_time,
67                                                Action action,
68                                                float x,
69                                                float y);
70
71  private:
72   MotionEventAndroid(const base::android::ScopedJavaLocalRef<jobject>& event,
73                      bool should_recycle);
74
75   // The Java reference to the underlying MotionEvent.
76   base::android::ScopedJavaGlobalRef<jobject> event_;
77
78   // Whether |event_| should be recycled on destruction. This will only be true
79   // for those events generated via |Obtain(...)|.
80   bool should_recycle_;
81
82   DISALLOW_COPY_AND_ASSIGN(MotionEventAndroid);
83 };
84
85 }  // namespace content
86
87 #endif  // CONTENT_BROWSER_RENDERER_HOST_INPUT_MOTION_EVENT_ANDROID_H_