| 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 <android/input.h> | 7 #include <android/input.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/float_util.h" | 10 #include "base/float_util.h" |
| 11 #include "jni/MotionEvent_jni.h" | 11 #include "jni/MotionEvent_jni.h" |
| 12 #include "ui/events/base_event_utils.h" |
| 12 #include "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
| 13 | 14 |
| 14 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 15 using namespace JNI_MotionEvent; | 16 using namespace JNI_MotionEvent; |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 MotionEventAndroid::Action FromAndroidAction(int android_action) { | 21 MotionEventAndroid::Action FromAndroidAction(int android_action) { |
| 21 switch (android_action) { | 22 switch (android_action) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 const Pointer& pointer1) | 158 const Pointer& pointer1) |
| 158 : pix_to_dip_(pix_to_dip), | 159 : pix_to_dip_(pix_to_dip), |
| 159 cached_time_(FromAndroidTime(time_ms)), | 160 cached_time_(FromAndroidTime(time_ms)), |
| 160 cached_action_(FromAndroidAction(android_action)), | 161 cached_action_(FromAndroidAction(android_action)), |
| 161 cached_pointer_count_(pointer_count), | 162 cached_pointer_count_(pointer_count), |
| 162 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), | 163 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), |
| 163 cached_action_index_(action_index), | 164 cached_action_index_(action_index), |
| 164 cached_button_state_(FromAndroidButtonState(android_button_state)), | 165 cached_button_state_(FromAndroidButtonState(android_button_state)), |
| 165 cached_flags_(FromAndroidMetaState(meta_state)), | 166 cached_flags_(FromAndroidMetaState(meta_state)), |
| 166 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), | 167 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), |
| 167 ToDips(raw_offset_y_pixels)) { | 168 ToDips(raw_offset_y_pixels)), |
| 169 unique_event_id_(ui::GetNextTouchEventId()) { |
| 168 DCHECK_GT(pointer_count, 0); | 170 DCHECK_GT(pointer_count, 0); |
| 169 | 171 |
| 170 event_.Reset(env, event); | 172 event_.Reset(env, event); |
| 171 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) | 173 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) |
| 172 DCHECK(event_.obj()); | 174 DCHECK(event_.obj()); |
| 173 | 175 |
| 174 cached_pointers_[0] = FromAndroidPointer(pointer0); | 176 cached_pointers_[0] = FromAndroidPointer(pointer0); |
| 175 cached_pointers_[1] = FromAndroidPointer(pointer1); | 177 cached_pointers_[1] = FromAndroidPointer(pointer1); |
| 176 } | 178 } |
| 177 | 179 |
| 178 MotionEventAndroid::~MotionEventAndroid() { | 180 MotionEventAndroid::~MotionEventAndroid() { |
| 179 } | 181 } |
| 180 | 182 |
| 181 int MotionEventAndroid::GetId() const { | 183 uint64 MotionEventAndroid::GetUniqueEventId() const { |
| 182 return 0; | 184 return unique_event_id_; |
| 183 } | 185 } |
| 184 | 186 |
| 185 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { | 187 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { |
| 186 return cached_action_; | 188 return cached_action_; |
| 187 } | 189 } |
| 188 | 190 |
| 189 int MotionEventAndroid::GetActionIndex() const { | 191 int MotionEventAndroid::GetActionIndex() const { |
| 190 DCHECK(cached_action_ == ACTION_POINTER_UP || | 192 DCHECK(cached_action_ == ACTION_POINTER_UP || |
| 191 cached_action_ == ACTION_POINTER_DOWN) | 193 cached_action_ == ACTION_POINTER_DOWN) |
| 192 << "Invalid action for GetActionIndex(): " << cached_action_; | 194 << "Invalid action for GetActionIndex(): " << cached_action_; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 result.tool_type = FromAndroidToolType(pointer.tool_type); | 334 result.tool_type = FromAndroidToolType(pointer.tool_type); |
| 333 return result; | 335 return result; |
| 334 } | 336 } |
| 335 | 337 |
| 336 // static | 338 // static |
| 337 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { | 339 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { |
| 338 return JNI_MotionEvent::RegisterNativesImpl(env); | 340 return JNI_MotionEvent::RegisterNativesImpl(env); |
| 339 } | 341 } |
| 340 | 342 |
| 341 } // namespace content | 343 } // namespace content |
| OLD | NEW |