| 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 |
| 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/base_event_utils.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_utils.h" |
| 15 | 16 |
| 16 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
| 17 using namespace JNI_MotionEvent; | 18 using namespace JNI_MotionEvent; |
| 18 | 19 |
| 19 namespace ui { | 20 namespace ui { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 MotionEventAndroid::Action FromAndroidAction(int android_action) { | 23 MotionEventAndroid::Action FromAndroidAction(int android_action) { |
| 23 switch (android_action) { | 24 switch (android_action) { |
| 24 case ACTION_DOWN: | 25 case ACTION_DOWN: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 if ((meta_state & AMETA_ALT_ON) != 0) | 88 if ((meta_state & AMETA_ALT_ON) != 0) |
| 88 flags |= ui::EF_ALT_DOWN; | 89 flags |= ui::EF_ALT_DOWN; |
| 89 if ((meta_state & AMETA_META_ON) != 0) | 90 if ((meta_state & AMETA_META_ON) != 0) |
| 90 flags |= ui::EF_COMMAND_DOWN; | 91 flags |= ui::EF_COMMAND_DOWN; |
| 91 if ((meta_state & AMETA_CAPS_LOCK_ON) != 0) | 92 if ((meta_state & AMETA_CAPS_LOCK_ON) != 0) |
| 92 flags |= ui::EF_CAPS_LOCK_ON; | 93 flags |= ui::EF_CAPS_LOCK_ON; |
| 93 return flags; | 94 return flags; |
| 94 } | 95 } |
| 95 | 96 |
| 96 base::TimeTicks FromAndroidTime(int64_t time_ms) { | 97 base::TimeTicks FromAndroidTime(int64_t time_ms) { |
| 97 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms); | 98 base::TimeTicks timestamp = |
| 99 base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms); |
| 100 ValidateEventTimeClock(×tamp); |
| 101 return timestamp; |
| 98 } | 102 } |
| 99 | 103 |
| 100 float ToValidFloat(float x) { | 104 float ToValidFloat(float x) { |
| 101 if (std::isnan(x)) | 105 if (std::isnan(x)) |
| 102 return 0.f; | 106 return 0.f; |
| 103 | 107 |
| 104 // Wildly large orientation values have been observed in the wild after device | 108 // Wildly large orientation values have been observed in the wild after device |
| 105 // rotation. There's not much we can do in that case other than simply | 109 // rotation. There's not much we can do in that case other than simply |
| 106 // sanitize results beyond an absurd and arbitrary threshold. | 110 // sanitize results beyond an absurd and arbitrary threshold. |
| 107 if (std::abs(x) > 1e5f) | 111 if (std::abs(x) > 1e5f) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); | 352 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); |
| 349 result.touch_major = ToDips(pointer.touch_major_pixels); | 353 result.touch_major = ToDips(pointer.touch_major_pixels); |
| 350 result.touch_minor = ToDips(pointer.touch_minor_pixels); | 354 result.touch_minor = ToDips(pointer.touch_minor_pixels); |
| 351 result.orientation = ToValidFloat(pointer.orientation_rad); | 355 result.orientation = ToValidFloat(pointer.orientation_rad); |
| 352 result.tilt = ToValidFloat(pointer.tilt_rad); | 356 result.tilt = ToValidFloat(pointer.tilt_rad); |
| 353 result.tool_type = FromAndroidToolType(pointer.tool_type); | 357 result.tool_type = FromAndroidToolType(pointer.tool_type); |
| 354 return result; | 358 return result; |
| 355 } | 359 } |
| 356 | 360 |
| 357 } // namespace content | 361 } // namespace content |
| OLD | NEW |