| 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 "ui/events/android/motion_event_android.h" | 5 #include "ui/events/android/motion_event_android.h" |
| 6 | 6 |
| 7 #include <android/input.h> | 7 #include <android/input.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 | 10 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 174 |
| 175 MotionEventAndroid::CachedPointer::CachedPointer() | 175 MotionEventAndroid::CachedPointer::CachedPointer() |
| 176 : id(0), | 176 : id(0), |
| 177 touch_major(0), | 177 touch_major(0), |
| 178 touch_minor(0), | 178 touch_minor(0), |
| 179 orientation(0), | 179 orientation(0), |
| 180 tilt(0), | 180 tilt(0), |
| 181 tool_type(TOOL_TYPE_UNKNOWN) { | 181 tool_type(TOOL_TYPE_UNKNOWN) { |
| 182 } | 182 } |
| 183 | 183 |
| 184 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, | 184 MotionEventAndroid::MotionEventAndroid(JNIEnv* env, |
| 185 JNIEnv* env, | |
| 186 jobject event, | 185 jobject event, |
| 186 jfloat pix_to_dip, |
| 187 jfloat ticks_x, |
| 188 jfloat ticks_y, |
| 189 jfloat tick_multiplier, |
| 187 jlong time_ms, | 190 jlong time_ms, |
| 188 jint android_action, | 191 jint android_action, |
| 189 jint pointer_count, | 192 jint pointer_count, |
| 190 jint history_size, | 193 jint history_size, |
| 191 jint action_index, | 194 jint action_index, |
| 192 jint android_action_button, | 195 jint android_action_button, |
| 193 jint android_button_state, | 196 jint android_button_state, |
| 194 jint android_meta_state, | 197 jint android_meta_state, |
| 195 jfloat raw_offset_x_pixels, | 198 jfloat raw_offset_x_pixels, |
| 196 jfloat raw_offset_y_pixels, | 199 jfloat raw_offset_y_pixels, |
| 197 const Pointer* const pointer0, | 200 const Pointer* const pointer0, |
| 198 const Pointer* const pointer1) | 201 const Pointer* const pointer1) |
| 199 : pix_to_dip_(pix_to_dip), | 202 : pix_to_dip_(pix_to_dip), |
| 203 ticks_x_(ticks_x), |
| 204 ticks_y_(ticks_y), |
| 205 tick_multiplier_(tick_multiplier), |
| 206 time_sec_(time_ms / 1000), |
| 200 cached_time_(FromAndroidTime(time_ms)), | 207 cached_time_(FromAndroidTime(time_ms)), |
| 201 cached_action_(FromAndroidAction(android_action)), | 208 cached_action_(FromAndroidAction(android_action)), |
| 202 cached_pointer_count_(pointer_count), | 209 cached_pointer_count_(pointer_count), |
| 203 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), | 210 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), |
| 204 cached_action_index_(action_index), | 211 cached_action_index_(action_index), |
| 205 cached_action_button_(android_action_button), | 212 cached_action_button_(android_action_button), |
| 206 cached_button_state_(FromAndroidButtonState(android_button_state)), | 213 cached_button_state_(FromAndroidButtonState(android_button_state)), |
| 207 cached_flags_(ToEventFlags(android_meta_state, android_button_state)), | 214 cached_flags_(ToEventFlags(android_meta_state, android_button_state)), |
| 208 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), | 215 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), |
| 209 ToDips(raw_offset_y_pixels)), | 216 ToDips(raw_offset_y_pixels)), |
| 210 unique_event_id_(ui::GetNextTouchEventId()) { | 217 unique_event_id_(ui::GetNextTouchEventId()) { |
| 211 DCHECK_GT(cached_pointer_count_, 0U); | 218 DCHECK_GT(cached_pointer_count_, 0U); |
| 212 DCHECK(cached_pointer_count_ == 1 || pointer1); | 219 DCHECK(cached_pointer_count_ == 1 || pointer1); |
| 213 | 220 |
| 214 event_.Reset(env, event); | 221 event_.Reset(env, event); |
| 215 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) | 222 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) |
| 216 DCHECK(event_.obj()); | 223 DCHECK(event_.obj()); |
| 217 | 224 |
| 218 cached_pointers_[0] = FromAndroidPointer(*pointer0); | 225 cached_pointers_[0] = FromAndroidPointer(*pointer0); |
| 219 if (cached_pointer_count_ > 1) | 226 if (cached_pointer_count_ > 1) |
| 220 cached_pointers_[1] = FromAndroidPointer(*pointer1); | 227 cached_pointers_[1] = FromAndroidPointer(*pointer1); |
| 221 } | 228 } |
| 222 | 229 |
| 223 MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& e) | 230 MotionEventAndroid::MotionEventAndroid(const MotionEventAndroid& e) |
| 224 : event_(e.event_), | 231 : event_(e.event_), |
| 225 pix_to_dip_(e.pix_to_dip_), | 232 pix_to_dip_(e.pix_to_dip_), |
| 233 ticks_x_(e.ticks_x_), |
| 234 ticks_y_(e.ticks_y_), |
| 235 tick_multiplier_(e.tick_multiplier_), |
| 236 time_sec_(e.time_sec_), |
| 226 cached_time_(e.cached_time_), | 237 cached_time_(e.cached_time_), |
| 227 cached_action_(e.cached_action_), | 238 cached_action_(e.cached_action_), |
| 228 cached_pointer_count_(e.cached_pointer_count_), | 239 cached_pointer_count_(e.cached_pointer_count_), |
| 229 cached_history_size_(e.cached_history_size_), | 240 cached_history_size_(e.cached_history_size_), |
| 230 cached_action_index_(e.cached_action_index_), | 241 cached_action_index_(e.cached_action_index_), |
| 231 cached_action_button_(e.cached_action_button_), | 242 cached_action_button_(e.cached_action_button_), |
| 232 cached_button_state_(e.cached_button_state_), | 243 cached_button_state_(e.cached_button_state_), |
| 233 cached_flags_(e.cached_flags_), | 244 cached_flags_(e.cached_flags_), |
| 234 cached_raw_position_offset_(e.cached_raw_position_offset_), | 245 cached_raw_position_offset_(e.cached_raw_position_offset_), |
| 235 unique_event_id_(ui::GetNextTouchEventId()) { | 246 unique_event_id_(ui::GetNextTouchEventId()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 255 } | 266 } |
| 256 | 267 |
| 257 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { | 268 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { |
| 258 return cached_action_; | 269 return cached_action_; |
| 259 } | 270 } |
| 260 | 271 |
| 261 int MotionEventAndroid::GetActionButton() const { | 272 int MotionEventAndroid::GetActionButton() const { |
| 262 return cached_action_button_; | 273 return cached_action_button_; |
| 263 } | 274 } |
| 264 | 275 |
| 276 float MotionEventAndroid::GetTickMultiplier() const { |
| 277 return ToDips(tick_multiplier_); |
| 278 } |
| 279 |
| 265 ScopedJavaLocalRef<jobject> MotionEventAndroid::GetJavaObject() const { | 280 ScopedJavaLocalRef<jobject> MotionEventAndroid::GetJavaObject() const { |
| 266 return ScopedJavaLocalRef<jobject>(event_); | 281 return ScopedJavaLocalRef<jobject>(event_); |
| 267 } | 282 } |
| 268 | 283 |
| 269 int MotionEventAndroid::GetActionIndex() const { | 284 int MotionEventAndroid::GetActionIndex() const { |
| 270 DCHECK(cached_action_ == MotionEvent::ACTION_POINTER_UP || | 285 DCHECK(cached_action_ == MotionEvent::ACTION_POINTER_UP || |
| 271 cached_action_ == MotionEvent::ACTION_POINTER_DOWN) | 286 cached_action_ == MotionEvent::ACTION_POINTER_DOWN) |
| 272 << "Invalid action for GetActionIndex(): " << cached_action_; | 287 << "Invalid action for GetActionIndex(): " << cached_action_; |
| 273 DCHECK_GE(cached_action_index_, 0); | 288 DCHECK_GE(cached_action_index_, 0); |
| 274 DCHECK_LT(cached_action_index_, static_cast<int>(cached_pointer_count_)); | 289 DCHECK_LT(cached_action_index_, static_cast<int>(cached_pointer_count_)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 pointer.position.y() + ToDips(y)); | 451 pointer.position.y() + ToDips(y)); |
| 437 result.touch_major = pointer.touch_major; | 452 result.touch_major = pointer.touch_major; |
| 438 result.touch_minor = pointer.touch_minor; | 453 result.touch_minor = pointer.touch_minor; |
| 439 result.orientation = pointer.orientation; | 454 result.orientation = pointer.orientation; |
| 440 result.tilt = pointer.tilt; | 455 result.tilt = pointer.tilt; |
| 441 result.tool_type = pointer.tool_type; | 456 result.tool_type = pointer.tool_type; |
| 442 return result; | 457 return result; |
| 443 } | 458 } |
| 444 | 459 |
| 445 } // namespace ui | 460 } // namespace ui |
| OLD | NEW |