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

Side by Side Diff: content/browser/renderer_host/input/motion_event_android.cc

Issue 999423003: Set the unique_event_id when converting from TouchEvent to WebTouchEvent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 "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"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK_GE(history_size, 0); 108 DCHECK_GE(history_size, 0);
109 // While the spec states that only ACTION_MOVE events should contain 109 // While the spec states that only ACTION_MOVE events should contain
110 // historical entries, it's possible that an embedder could repurpose an 110 // historical entries, it's possible that an embedder could repurpose an
111 // ACTION_MOVE event into a different kind of event. In that case, the 111 // ACTION_MOVE event into a different kind of event. In that case, the
112 // historical values are meaningless, and should not be exposed. 112 // historical values are meaningless, and should not be exposed.
113 if (action != ui::MotionEvent::ACTION_MOVE) 113 if (action != ui::MotionEvent::ACTION_MOVE)
114 return 0; 114 return 0;
115 return history_size; 115 return history_size;
116 } 116 }
117 117
118 uint64 get_next_event_id() {
119 // Set the first unique_id_ to 1 because we set id to 0 for other types
120 // of events.
121 static uint64 id = 1;
122 if (id==0)
123 id++;
124 DCHECK_NE(id, 0UL);
tdresser 2015/04/08 12:24:26 We can remove that DCHECK.
lanwei 2015/04/09 04:14:28 Done.
125 return id++;
126 }
127
118 } // namespace 128 } // namespace
119 129
120 MotionEventAndroid::Pointer::Pointer(jint id, 130 MotionEventAndroid::Pointer::Pointer(jint id,
121 jfloat pos_x_pixels, 131 jfloat pos_x_pixels,
122 jfloat pos_y_pixels, 132 jfloat pos_y_pixels,
123 jfloat touch_major_pixels, 133 jfloat touch_major_pixels,
124 jfloat touch_minor_pixels, 134 jfloat touch_minor_pixels,
125 jfloat orientation_rad, 135 jfloat orientation_rad,
126 jint tool_type) 136 jint tool_type)
127 : id(id), 137 : id(id),
(...skipping 29 matching lines...) Expand all
157 const Pointer& pointer1) 167 const Pointer& pointer1)
158 : pix_to_dip_(pix_to_dip), 168 : pix_to_dip_(pix_to_dip),
159 cached_time_(FromAndroidTime(time_ms)), 169 cached_time_(FromAndroidTime(time_ms)),
160 cached_action_(FromAndroidAction(android_action)), 170 cached_action_(FromAndroidAction(android_action)),
161 cached_pointer_count_(pointer_count), 171 cached_pointer_count_(pointer_count),
162 cached_history_size_(ToValidHistorySize(history_size, cached_action_)), 172 cached_history_size_(ToValidHistorySize(history_size, cached_action_)),
163 cached_action_index_(action_index), 173 cached_action_index_(action_index),
164 cached_button_state_(FromAndroidButtonState(android_button_state)), 174 cached_button_state_(FromAndroidButtonState(android_button_state)),
165 cached_flags_(FromAndroidMetaState(meta_state)), 175 cached_flags_(FromAndroidMetaState(meta_state)),
166 cached_raw_position_offset_(ToDips(raw_offset_x_pixels), 176 cached_raw_position_offset_(ToDips(raw_offset_x_pixels),
167 ToDips(raw_offset_y_pixels)) { 177 ToDips(raw_offset_y_pixels)),
178 unique_id_(get_next_event_id()) {
168 DCHECK_GT(pointer_count, 0); 179 DCHECK_GT(pointer_count, 0);
169 180
170 event_.Reset(env, event); 181 event_.Reset(env, event);
171 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0) 182 if (cached_pointer_count_ > MAX_POINTERS_TO_CACHE || cached_history_size_ > 0)
172 DCHECK(event_.obj()); 183 DCHECK(event_.obj());
173 184
174 cached_pointers_[0] = FromAndroidPointer(pointer0); 185 cached_pointers_[0] = FromAndroidPointer(pointer0);
175 cached_pointers_[1] = FromAndroidPointer(pointer1); 186 cached_pointers_[1] = FromAndroidPointer(pointer1);
176 } 187 }
177 188
178 MotionEventAndroid::~MotionEventAndroid() { 189 MotionEventAndroid::~MotionEventAndroid() {
179 } 190 }
180 191
181 int MotionEventAndroid::GetId() const { 192 int MotionEventAndroid::GetId() const {
182 return 0; 193 return 0;
183 } 194 }
184 195
196 uint64 MotionEventAndroid::GetUniqueId() const {
197 return unique_id_;
198 }
199
185 MotionEventAndroid::Action MotionEventAndroid::GetAction() const { 200 MotionEventAndroid::Action MotionEventAndroid::GetAction() const {
186 return cached_action_; 201 return cached_action_;
187 } 202 }
188 203
189 int MotionEventAndroid::GetActionIndex() const { 204 int MotionEventAndroid::GetActionIndex() const {
190 DCHECK(cached_action_ == ACTION_POINTER_UP || 205 DCHECK(cached_action_ == ACTION_POINTER_UP ||
191 cached_action_ == ACTION_POINTER_DOWN) 206 cached_action_ == ACTION_POINTER_DOWN)
192 << "Invalid action for GetActionIndex(): " << cached_action_; 207 << "Invalid action for GetActionIndex(): " << cached_action_;
193 DCHECK_GE(cached_action_index_, 0); 208 DCHECK_GE(cached_action_index_, 0);
194 DCHECK_LT(cached_action_index_, static_cast<int>(cached_pointer_count_)); 209 DCHECK_LT(cached_action_index_, static_cast<int>(cached_pointer_count_));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 result.tool_type = FromAndroidToolType(pointer.tool_type); 347 result.tool_type = FromAndroidToolType(pointer.tool_type);
333 return result; 348 return result;
334 } 349 }
335 350
336 // static 351 // static
337 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) { 352 bool MotionEventAndroid::RegisterMotionEventAndroid(JNIEnv* env) {
338 return JNI_MotionEvent::RegisterNativesImpl(env); 353 return JNI_MotionEvent::RegisterNativesImpl(env);
339 } 354 }
340 355
341 } // namespace content 356 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698