Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ui/events/android/motion_event_android.cc

Issue 2054193002: Android mouse events shouldn't appear as TouchEvents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added meta_state plumbing. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 result |= MotionEventAndroid::BUTTON_SECONDARY; 71 result |= MotionEventAndroid::BUTTON_SECONDARY;
72 if ((button_state & BUTTON_TERTIARY) != 0) 72 if ((button_state & BUTTON_TERTIARY) != 0)
73 result |= MotionEventAndroid::BUTTON_TERTIARY; 73 result |= MotionEventAndroid::BUTTON_TERTIARY;
74 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0) 74 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0)
75 result |= MotionEventAndroid::BUTTON_STYLUS_PRIMARY; 75 result |= MotionEventAndroid::BUTTON_STYLUS_PRIMARY;
76 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0) 76 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0)
77 result |= MotionEventAndroid::BUTTON_STYLUS_SECONDARY; 77 result |= MotionEventAndroid::BUTTON_STYLUS_SECONDARY;
78 return result; 78 return result;
79 } 79 }
80 80
81 int FromAndroidMetaState(int meta_state) { 81 int ToEventFlags(int meta_state, int button_state) {
82 int flags = ui::EF_NONE; 82 int flags = ui::EF_NONE;
83
83 if ((meta_state & AMETA_SHIFT_ON) != 0) 84 if ((meta_state & AMETA_SHIFT_ON) != 0)
84 flags |= ui::EF_SHIFT_DOWN; 85 flags |= ui::EF_SHIFT_DOWN;
85 if ((meta_state & AMETA_CTRL_ON) != 0) 86 if ((meta_state & AMETA_CTRL_ON) != 0)
86 flags |= ui::EF_CONTROL_DOWN; 87 flags |= ui::EF_CONTROL_DOWN;
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;
94
95 if ((button_state & BUTTON_BACK) != 0)
96 flags |= ui::EF_BACK_MOUSE_BUTTON;
97 if ((button_state & BUTTON_FORWARD) != 0)
98 flags |= ui::EF_FORWARD_MOUSE_BUTTON;
99 if ((button_state & BUTTON_PRIMARY) != 0)
100 flags |= ui::EF_LEFT_MOUSE_BUTTON;
101 if ((button_state & BUTTON_SECONDARY) != 0)
102 flags |= ui::EF_RIGHT_MOUSE_BUTTON;
103 if ((button_state & BUTTON_TERTIARY) != 0)
104 flags |= ui::EF_MIDDLE_MOUSE_BUTTON;
105 if ((button_state & BUTTON_STYLUS_PRIMARY) != 0)
106 flags |= ui::EF_LEFT_MOUSE_BUTTON;
107 if ((button_state & BUTTON_STYLUS_SECONDARY) != 0)
108 flags |= ui::EF_RIGHT_MOUSE_BUTTON;
109
93 return flags; 110 return flags;
94 } 111 }
95 112
96 base::TimeTicks FromAndroidTime(int64_t time_ms) { 113 base::TimeTicks FromAndroidTime(int64_t time_ms) {
97 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms); 114 return base::TimeTicks() + base::TimeDelta::FromMilliseconds(time_ms);
98 } 115 }
99 116
100 float ToValidFloat(float x) { 117 float ToValidFloat(float x) {
101 if (std::isnan(x)) 118 if (std::isnan(x))
102 return 0.f; 119 return 0.f;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 169
153 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, 170 MotionEventAndroid::MotionEventAndroid(float pix_to_dip,
154 JNIEnv* env, 171 JNIEnv* env,
155 jobject event, 172 jobject event,
156 jlong time_ms, 173 jlong time_ms,
157 jint android_action, 174 jint android_action,
158 jint pointer_count, 175 jint pointer_count,
159 jint history_size, 176 jint history_size,
160 jint action_index, 177 jint action_index,
161 jint android_button_state, 178 jint android_button_state,
162 jint meta_state, 179 jint android_meta_state,
163 jfloat raw_offset_x_pixels, 180 jfloat raw_offset_x_pixels,
164 jfloat raw_offset_y_pixels, 181 jfloat raw_offset_y_pixels,
165 const Pointer& pointer0, 182 const Pointer* const pointer0,
166 const Pointer& pointer1) 183 const Pointer* const pointer1)
167 : pix_to_dip_(pix_to_dip), 184 : pix_to_dip_(pix_to_dip),
168 cached_time_(FromAndroidTime(time_ms)), 185 cached_time_(FromAndroidTime(time_ms)),
169 cached_action_(FromAndroidAction(android_action)), 186 cached_action_(FromAndroidAction(android_action)),
170 cached_pointer_count_(pointer_count), 187 cached_pointer_count_(pointer_count),
171 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), 188 cached_history_size_(ToValidHistorySize(history_size, cached_action_)),
172 cached_action_index_(action_index), 189 cached_action_index_(action_index),
173 cached_button_state_(FromAndroidButtonState(android_button_state)), 190 cached_button_state_(FromAndroidButtonState(android_button_state)),
174 cached_flags_(FromAndroidMetaState(meta_state)), 191 cached_flags_(ToEventFlags(android_meta_state, android_button_state)),
175 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), 192 cached_raw_position_offset_(ToDips(raw_offset_x_pixels),
176 ToDips(raw_offset_y_pixels)), 193 ToDips(raw_offset_y_pixels)),
177 unique_event_id_(ui::GetNextTouchEventId()) { 194 unique_event_id_(ui::GetNextTouchEventId()) {
178 DCHECK_GT(pointer_count, 0); 195 DCHECK_GT(cached_pointer_count_, 0U);
196 DCHECK(cached_pointer_count_ == 1 || pointer1);
179 197
180 event_.Reset(env, event); 198 event_.Reset(env, event);
181 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) 199 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0)
182 DCHECK(event_.obj()); 200 DCHECK(event_.obj());
183 201
184 cached_pointers_[0] = FromAndroidPointer(pointer0); 202 cached_pointers_[0] = FromAndroidPointer(*pointer0);
185 cached_pointers_[1] = FromAndroidPointer(pointer1); 203 if (cached_pointer_count_ > 1)
aelias_OOO_until_Jul13 2016/10/20 23:26:29 This looks kind of weird (I understand you expect
mustaq 2016/10/21 19:19:08 Just realized that the name is a bit confusing her
aelias_OOO_until_Jul13 2016/10/21 21:26:54 OK then, fine as is.
204 cached_pointers_[1] = FromAndroidPointer(*pointer1);
186 } 205 }
187 206
188 MotionEventAndroid::~MotionEventAndroid() { 207 MotionEventAndroid::~MotionEventAndroid() {
189 } 208 }
190 209
191 uint32_t MotionEventAndroid::GetUniqueEventId() const { 210 uint32_t MotionEventAndroid::GetUniqueEventId() const {
192 return unique_event_id_; 211 return unique_event_id_;
193 } 212 }
194 213
195 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { 214 MotionEventAndroid::Action MotionEventAndroid::GetAction() const {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels)); 367 gfx::PointF(ToDips(pointer.pos_x_pixels), ToDips(pointer.pos_y_pixels));
349 result.touch_major = ToDips(pointer.touch_major_pixels); 368 result.touch_major = ToDips(pointer.touch_major_pixels);
350 result.touch_minor = ToDips(pointer.touch_minor_pixels); 369 result.touch_minor = ToDips(pointer.touch_minor_pixels);
351 result.orientation = ToValidFloat(pointer.orientation_rad); 370 result.orientation = ToValidFloat(pointer.orientation_rad);
352 result.tilt = ToValidFloat(pointer.tilt_rad); 371 result.tilt = ToValidFloat(pointer.tilt_rad);
353 result.tool_type = FromAndroidToolType(pointer.tool_type); 372 result.tool_type = FromAndroidToolType(pointer.tool_type);
354 return result; 373 return result;
355 } 374 }
356 375
357 } // namespace content 376 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698