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 #include "content/browser/renderer_host/input/motion_event_android.h" | 5 #include "content/browser/renderer_host/input/motion_event_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "jni/MotionEvent_jni.h" | 8 #include "jni/MotionEvent_jni.h" |
9 | 9 |
10 using base::android::AttachCurrentThread; | 10 using base::android::AttachCurrentThread; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)), | 71 cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)), |
72 cached_history_size_(Java_MotionEvent_getHistorySize(env, event)), | 72 cached_history_size_(Java_MotionEvent_getHistorySize(env, event)), |
73 cached_action_index_(Java_MotionEvent_getActionIndex(env, event)), | 73 cached_action_index_(Java_MotionEvent_getActionIndex(env, event)), |
74 cached_x_(Java_MotionEvent_getXF(env, event)), | 74 cached_x_(Java_MotionEvent_getXF(env, event)), |
75 cached_y_(Java_MotionEvent_getYF(env, event)), | 75 cached_y_(Java_MotionEvent_getYF(env, event)), |
76 should_recycle_(recycle) { | 76 should_recycle_(recycle) { |
77 event_.Reset(env, event); | 77 event_.Reset(env, event); |
78 DCHECK(event_.obj()); | 78 DCHECK(event_.obj()); |
79 } | 79 } |
80 | 80 |
81 MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& other, | 81 MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& other) |
82 bool clone) | 82 : event_(Obtain(other)), |
83 : cached_time_(other.cached_time_), | 83 cached_time_(other.cached_time_), |
84 cached_action_(other.cached_action_), | 84 cached_action_(other.cached_action_), |
85 cached_pointer_count_(other.cached_pointer_count_), | 85 cached_pointer_count_(other.cached_pointer_count_), |
86 cached_history_size_(other.cached_history_size_), | 86 cached_history_size_(other.cached_history_size_), |
87 cached_action_index_(other.cached_action_index_), | 87 cached_action_index_(other.cached_action_index_), |
88 cached_x_(other.cached_x_), | 88 cached_x_(other.cached_x_), |
89 cached_y_(other.cached_y_), | 89 cached_y_(other.cached_y_), |
90 should_recycle_(clone) { | 90 should_recycle_(true) { |
91 // An event with a pending recycle should never be copied (only cloned). | 91 DCHECK(event_.obj()); |
92 DCHECK(clone || !other.should_recycle_); | |
93 if (clone) | |
94 event_.Reset(Obtain(other)); | |
95 else | |
96 event_.Reset(other.event_); | |
97 } | 92 } |
98 | 93 |
99 MotionEventAndroid::~MotionEventAndroid() { | 94 MotionEventAndroid::~MotionEventAndroid() { |
100 if (should_recycle_) | 95 if (should_recycle_) |
101 Java_MotionEvent_recycle(AttachCurrentThread(), event_.obj()); | 96 Java_MotionEvent_recycle(AttachCurrentThread(), event_.obj()); |
102 } | 97 } |
103 | 98 |
104 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { | 99 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { |
105 return cached_action_; | 100 return cached_action_; |
106 } | 101 } |
(...skipping 27 matching lines...) Expand all Loading... |
134 return Java_MotionEvent_getYF_I( | 129 return Java_MotionEvent_getYF_I( |
135 AttachCurrentThread(), event_.obj(), pointer_index); | 130 AttachCurrentThread(), event_.obj(), pointer_index); |
136 } | 131 } |
137 | 132 |
138 float MotionEventAndroid::GetTouchMajor(size_t pointer_index) const { | 133 float MotionEventAndroid::GetTouchMajor(size_t pointer_index) const { |
139 DCHECK_LT(pointer_index, cached_pointer_count_); | 134 DCHECK_LT(pointer_index, cached_pointer_count_); |
140 return Java_MotionEvent_getTouchMajorF_I( | 135 return Java_MotionEvent_getTouchMajorF_I( |
141 AttachCurrentThread(), event_.obj(), pointer_index); | 136 AttachCurrentThread(), event_.obj(), pointer_index); |
142 } | 137 } |
143 | 138 |
| 139 float MotionEventAndroid::GetPressure(size_t pointer_index) const { |
| 140 DCHECK_LT(pointer_index, cached_pointer_count_); |
| 141 return Java_MotionEvent_getPressureF_I( |
| 142 AttachCurrentThread(), event_.obj(), pointer_index); |
| 143 } |
| 144 |
144 base::TimeTicks MotionEventAndroid::GetEventTime() const { | 145 base::TimeTicks MotionEventAndroid::GetEventTime() const { |
145 return cached_time_; | 146 return cached_time_; |
146 } | 147 } |
147 | 148 |
148 size_t MotionEventAndroid::GetHistorySize() const { | 149 size_t MotionEventAndroid::GetHistorySize() const { |
149 return cached_history_size_; | 150 return cached_history_size_; |
150 } | 151 } |
151 | 152 |
152 base::TimeTicks MotionEventAndroid::GetHistoricalEventTime( | 153 base::TimeTicks MotionEventAndroid::GetHistoricalEventTime( |
153 size_t historical_index) const { | 154 size_t historical_index) const { |
(...skipping 14 matching lines...) Expand all Loading... |
168 AttachCurrentThread(), event_.obj(), pointer_index, historical_index); | 169 AttachCurrentThread(), event_.obj(), pointer_index, historical_index); |
169 } | 170 } |
170 | 171 |
171 float MotionEventAndroid::GetHistoricalY(size_t pointer_index, | 172 float MotionEventAndroid::GetHistoricalY(size_t pointer_index, |
172 size_t historical_index) const { | 173 size_t historical_index) const { |
173 return Java_MotionEvent_getHistoricalYF_I_I( | 174 return Java_MotionEvent_getHistoricalYF_I_I( |
174 AttachCurrentThread(), event_.obj(), pointer_index, historical_index); | 175 AttachCurrentThread(), event_.obj(), pointer_index, historical_index); |
175 } | 176 } |
176 | 177 |
177 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Clone() const { | 178 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Clone() const { |
178 return scoped_ptr<MotionEvent>(new MotionEventAndroid(*this, true)); | 179 return scoped_ptr<MotionEvent>(new MotionEventAndroid(*this)); |
179 } | 180 } |
180 | 181 |
181 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const { | 182 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const { |
182 return scoped_ptr<MotionEvent>(new MotionEventAndroid( | 183 return scoped_ptr<MotionEvent>(new MotionEventAndroid( |
183 AttachCurrentThread(), | 184 AttachCurrentThread(), |
184 Obtain(GetDownTime(), | 185 Obtain(GetDownTime(), |
185 GetEventTime(), | 186 GetEventTime(), |
186 MotionEventAndroid::ACTION_CANCEL, | 187 MotionEventAndroid::ACTION_CANCEL, |
187 GetX(0), | 188 GetX(0), |
188 GetY(0)).obj(), | 189 GetY(0)).obj(), |
189 true)); | 190 true)); |
190 } | 191 } |
191 | 192 |
192 float MotionEventAndroid::GetPressure(size_t pointer_index) const { | |
193 return Java_MotionEvent_getPressureF_I( | |
194 AttachCurrentThread(), event_.obj(), pointer_index); | |
195 } | |
196 | |
197 float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const { | 193 float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const { |
198 return Java_MotionEvent_getTouchMinorF_I( | 194 return Java_MotionEvent_getTouchMinorF_I( |
199 AttachCurrentThread(), event_.obj(), pointer_index); | 195 AttachCurrentThread(), event_.obj(), pointer_index); |
200 } | 196 } |
201 | 197 |
202 float MotionEventAndroid::GetOrientation() const { | 198 float MotionEventAndroid::GetOrientation() const { |
203 return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj()); | 199 return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj()); |
204 } | 200 } |
205 | 201 |
206 base::TimeTicks MotionEventAndroid::GetDownTime() const { | 202 base::TimeTicks MotionEventAndroid::GetDownTime() const { |
(...skipping 23 matching lines...) Expand all Loading... |
230 return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(), | 226 return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(), |
231 ToAndroidTime(down_time), | 227 ToAndroidTime(down_time), |
232 ToAndroidTime(event_time), | 228 ToAndroidTime(event_time), |
233 ToAndroidAction(action), | 229 ToAndroidAction(action), |
234 x, | 230 x, |
235 y, | 231 y, |
236 0); | 232 0); |
237 } | 233 } |
238 | 234 |
239 } // namespace content | 235 } // namespace content |
OLD | NEW |