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