| 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 16 matching lines...) Expand all Loading... |
| 27 case ACTION_UP: | 27 case ACTION_UP: |
| 28 return MotionEventAndroid::ACTION_UP; | 28 return MotionEventAndroid::ACTION_UP; |
| 29 case ACTION_MOVE: | 29 case ACTION_MOVE: |
| 30 return MotionEventAndroid::ACTION_MOVE; | 30 return MotionEventAndroid::ACTION_MOVE; |
| 31 case ACTION_CANCEL: | 31 case ACTION_CANCEL: |
| 32 return MotionEventAndroid::ACTION_CANCEL; | 32 return MotionEventAndroid::ACTION_CANCEL; |
| 33 case ACTION_POINTER_DOWN: | 33 case ACTION_POINTER_DOWN: |
| 34 return MotionEventAndroid::ACTION_POINTER_DOWN; | 34 return MotionEventAndroid::ACTION_POINTER_DOWN; |
| 35 case ACTION_POINTER_UP: | 35 case ACTION_POINTER_UP: |
| 36 return MotionEventAndroid::ACTION_POINTER_UP; | 36 return MotionEventAndroid::ACTION_POINTER_UP; |
| 37 case ACTION_HOVER_ENTER: |
| 38 return MotionEventAndroid::ACTION_HOVER_ENTER; |
| 39 case ACTION_HOVER_EXIT: |
| 40 return MotionEventAndroid::ACTION_HOVER_EXIT; |
| 41 case ACTION_HOVER_MOVE: |
| 42 return MotionEventAndroid::ACTION_HOVER_MOVE; |
| 43 case ACTION_BUTTON_PRESS: |
| 44 return MotionEventAndroid::ACTION_BUTTON_PRESS; |
| 45 case ACTION_BUTTON_RELEASE: |
| 46 return MotionEventAndroid::ACTION_BUTTON_RELEASE; |
| 37 default: | 47 default: |
| 38 NOTREACHED() << "Invalid Android MotionEvent type for gesture detection: " | 48 NOTREACHED() << "Invalid Android MotionEvent action: " << android_action; |
| 39 << android_action; | |
| 40 }; | 49 }; |
| 41 return MotionEventAndroid::ACTION_CANCEL; | 50 return MotionEventAndroid::ACTION_CANCEL; |
| 42 } | 51 } |
| 43 | 52 |
| 44 MotionEventAndroid::ToolType FromAndroidToolType(int android_tool_type) { | 53 MotionEventAndroid::ToolType FromAndroidToolType(int android_tool_type) { |
| 45 switch (android_tool_type) { | 54 switch (android_tool_type) { |
| 46 case TOOL_TYPE_UNKNOWN: | 55 case TOOL_TYPE_UNKNOWN: |
| 47 return MotionEventAndroid::TOOL_TYPE_UNKNOWN; | 56 return MotionEventAndroid::TOOL_TYPE_UNKNOWN; |
| 48 case TOOL_TYPE_FINGER: | 57 case TOOL_TYPE_FINGER: |
| 49 return MotionEventAndroid::TOOL_TYPE_FINGER; | 58 return MotionEventAndroid::TOOL_TYPE_FINGER; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 72 result |= MotionEventAndroid::BUTTON_SECONDARY; | 81 result |= MotionEventAndroid::BUTTON_SECONDARY; |
| 73 if ((button_state & BUTTON_TERTIARY) != 0) | 82 if ((button_state & BUTTON_TERTIARY) != 0) |
| 74 result |= MotionEventAndroid::BUTTON_TERTIARY; | 83 result |= MotionEventAndroid::BUTTON_TERTIARY; |
| 75 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0) | 84 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0) |
| 76 result |= MotionEventAndroid::BUTTON_STYLUS_PRIMARY; | 85 result |= MotionEventAndroid::BUTTON_STYLUS_PRIMARY; |
| 77 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0) | 86 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0) |
| 78 result |= MotionEventAndroid::BUTTON_STYLUS_SECONDARY; | 87 result |= MotionEventAndroid::BUTTON_STYLUS_SECONDARY; |
| 79 return result; | 88 return result; |
| 80 } | 89 } |
| 81 | 90 |
| 82 int FromAndroidMetaState(int meta_state) { | 91 int ToEventFlags(int meta_state, int button_state) { |
| 83 int flags = ui::EF_NONE; | 92 int flags = ui::EF_NONE; |
| 93 |
| 84 if ((meta_state & AMETA_SHIFT_ON) != 0) | 94 if ((meta_state & AMETA_SHIFT_ON) != 0) |
| 85 flags |= ui::EF_SHIFT_DOWN; | 95 flags |= ui::EF_SHIFT_DOWN; |
| 86 if ((meta_state & AMETA_CTRL_ON) != 0) | 96 if ((meta_state & AMETA_CTRL_ON) != 0) |
| 87 flags |= ui::EF_CONTROL_DOWN; | 97 flags |= ui::EF_CONTROL_DOWN; |
| 88 if ((meta_state & AMETA_ALT_ON) != 0) | 98 if ((meta_state & AMETA_ALT_ON) != 0) |
| 89 flags |= ui::EF_ALT_DOWN; | 99 flags |= ui::EF_ALT_DOWN; |
| 90 if ((meta_state & AMETA_META_ON) != 0) | 100 if ((meta_state & AMETA_META_ON) != 0) |
| 91 flags |= ui::EF_COMMAND_DOWN; | 101 flags |= ui::EF_COMMAND_DOWN; |
| 92 if ((meta_state & AMETA_CAPS_LOCK_ON) != 0) | 102 if ((meta_state & AMETA_CAPS_LOCK_ON) != 0) |
| 93 flags |= ui::EF_CAPS_LOCK_ON; | 103 flags |= ui::EF_CAPS_LOCK_ON; |
| 104 |
| 105 if ((button_state & BUTTON_BACK) != 0) |
| 106 flags |= ui::EF_BACK_MOUSE_BUTTON; |
| 107 if ((button_state & BUTTON_FORWARD) != 0) |
| 108 flags |= ui::EF_FORWARD_MOUSE_BUTTON; |
| 109 if ((button_state & BUTTON_PRIMARY) != 0) |
| 110 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 111 if ((button_state & BUTTON_SECONDARY) != 0) |
| 112 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 113 if ((button_state & BUTTON_TERTIARY) != 0) |
| 114 flags |= ui::EF_MIDDLE_MOUSE_BUTTON; |
| 115 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0) |
| 116 flags |= ui::EF_LEFT_MOUSE_BUTTON; |
| 117 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0) |
| 118 flags |= ui::EF_RIGHT_MOUSE_BUTTON; |
| 119 |
| 94 return flags; | 120 return flags; |
| 95 } | 121 } |
| 96 | 122 |
| 97 base::TimeTicks FromAndroidTime(int64_t time_ms) { | 123 base::TimeTicks FromAndroidTime(int64_t time_ms) { |
| 98 base::TimeTicks timestamp = | 124 base::TimeTicks timestamp = |
| 99 base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms); | 125 base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms); |
| 100 ValidateEventTimeClock(×tamp); | 126 ValidateEventTimeClock(×tamp); |
| 101 return timestamp; | 127 return timestamp; |
| 102 } | 128 } |
| 103 | 129 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 182 |
| 157 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, | 183 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, |
| 158 JNIEnv* env, | 184 JNIEnv* env, |
| 159 jobject event, | 185 jobject event, |
| 160 jlong time_ms, | 186 jlong time_ms, |
| 161 jint android_action, | 187 jint android_action, |
| 162 jint pointer_count, | 188 jint pointer_count, |
| 163 jint history_size, | 189 jint history_size, |
| 164 jint action_index, | 190 jint action_index, |
| 165 jint android_button_state, | 191 jint android_button_state, |
| 166 jint meta_state, | 192 jint android_meta_state, |
| 167 jfloat raw_offset_x_pixels, | 193 jfloat raw_offset_x_pixels, |
| 168 jfloat raw_offset_y_pixels, | 194 jfloat raw_offset_y_pixels, |
| 169 const Pointer& pointer0, | 195 const Pointer* const pointer0, |
| 170 const Pointer& pointer1) | 196 const Pointer* const pointer1) |
| 171 : pix_to_dip_(pix_to_dip), | 197 : pix_to_dip_(pix_to_dip), |
| 172 cached_time_(FromAndroidTime(time_ms)), | 198 cached_time_(FromAndroidTime(time_ms)), |
| 173 cached_action_(FromAndroidAction(android_action)), | 199 cached_action_(FromAndroidAction(android_action)), |
| 174 cached_pointer_count_(pointer_count), | 200 cached_pointer_count_(pointer_count), |
| 175 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), | 201 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), |
| 176 cached_action_index_(action_index), | 202 cached_action_index_(action_index), |
| 177 cached_button_state_(FromAndroidButtonState(android_button_state)), | 203 cached_button_state_(FromAndroidButtonState(android_button_state)), |
| 178 cached_flags_(FromAndroidMetaState(meta_state)), | 204 cached_flags_(ToEventFlags(android_meta_state, android_button_state)), |
| 179 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), | 205 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), |
| 180 ToDips(raw_offset_y_pixels)), | 206 ToDips(raw_offset_y_pixels)), |
| 181 unique_event_id_(ui::GetNextTouchEventId()) { | 207 unique_event_id_(ui::GetNextTouchEventId()) { |
| 182 DCHECK_GT(pointer_count, 0); | 208 DCHECK_GT(cached_pointer_count_, 0U); |
| 209 DCHECK(cached_pointer_count_ == 1 || pointer1); |
| 183 | 210 |
| 184 event_.Reset(env, event); | 211 event_.Reset(env, event); |
| 185 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) | 212 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) |
| 186 DCHECK(event_.obj()); | 213 DCHECK(event_.obj()); |
| 187 | 214 |
| 188 cached_pointers_[0] = FromAndroidPointer(pointer0); | 215 cached_pointers_[0] = FromAndroidPointer(*pointer0); |
| 189 cached_pointers_[1] = FromAndroidPointer(pointer1); | 216 if (cached_pointer_count_ > 1) |
| 217 cached_pointers_[1] = FromAndroidPointer(*pointer1); |
| 190 } | 218 } |
| 191 | 219 |
| 192 MotionEventAndroid::~MotionEventAndroid() { | 220 MotionEventAndroid::~MotionEventAndroid() { |
| 193 } | 221 } |
| 194 | 222 |
| 195 uint32_t MotionEventAndroid::GetUniqueEventId() const { | 223 uint32_t MotionEventAndroid::GetUniqueEventId() const { |
| 196 return unique_event_id_; | 224 return unique_event_id_; |
| 197 } | 225 } |
| 198 | 226 |
| 199 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { | 227 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); | 380 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); |
| 353 result.touch_major = ToDips(pointer.touch_major_pixels); | 381 result.touch_major = ToDips(pointer.touch_major_pixels); |
| 354 result.touch_minor = ToDips(pointer.touch_minor_pixels); | 382 result.touch_minor = ToDips(pointer.touch_minor_pixels); |
| 355 result.orientation = ToValidFloat(pointer.orientation_rad); | 383 result.orientation = ToValidFloat(pointer.orientation_rad); |
| 356 result.tilt = ToValidFloat(pointer.tilt_rad); | 384 result.tilt = ToValidFloat(pointer.tilt_rad); |
| 357 result.tool_type = FromAndroidToolType(pointer.tool_type); | 385 result.tool_type = FromAndroidToolType(pointer.tool_type); |
| 358 return result; | 386 return result; |
| 359 } | 387 } |
| 360 | 388 |
| 361 } // namespace content | 389 } // namespace content |
| OLD | NEW |