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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
7 | 7 |
8 #include "ui/events/gestures/motion_event_aura.h" | 8 #include "ui/events/gestures/motion_event_aura.h" |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return active_touches_[pointer_index].pressure; | 166 return active_touches_[pointer_index].pressure; |
167 } | 167 } |
168 | 168 |
169 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { | 169 MotionEvent::ToolType MotionEventAura::GetToolType(size_t pointer_index) const { |
170 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. | 170 // TODO(jdduke): Plumb tool type from the platform, crbug.com/404128. |
171 DCHECK_LT(pointer_index, pointer_count_); | 171 DCHECK_LT(pointer_index, pointer_count_); |
172 return MotionEvent::TOOL_TYPE_UNKNOWN; | 172 return MotionEvent::TOOL_TYPE_UNKNOWN; |
173 } | 173 } |
174 | 174 |
175 int MotionEventAura::GetButtonState() const { | 175 int MotionEventAura::GetButtonState() const { |
176 NOTIMPLEMENTED(); | |
177 return 0; | 176 return 0; |
178 } | 177 } |
179 | 178 |
180 int MotionEventAura::GetFlags() const { | 179 int MotionEventAura::GetFlags() const { |
181 return flags_; | 180 return flags_; |
182 } | 181 } |
183 | 182 |
184 base::TimeTicks MotionEventAura::GetEventTime() const { | 183 base::TimeTicks MotionEventAura::GetEventTime() const { |
185 return last_touch_time_; | 184 return last_touch_time_; |
186 } | 185 } |
187 | 186 |
188 scoped_ptr<MotionEvent> MotionEventAura::Clone() const { | |
189 return scoped_ptr<MotionEvent>(new MotionEventAura(pointer_count_, | |
190 last_touch_time_, | |
191 cached_action_, | |
192 cached_action_index_, | |
193 flags_, | |
194 active_touches_)); | |
195 } | |
196 scoped_ptr<MotionEvent> MotionEventAura::Cancel() const { | |
197 return scoped_ptr<MotionEvent>(new MotionEventAura( | |
198 pointer_count_, last_touch_time_, ACTION_CANCEL, -1, 0, active_touches_)); | |
199 } | |
200 | |
201 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { | 187 void MotionEventAura::CleanupRemovedTouchPoints(const TouchEvent& event) { |
202 if (event.type() != ET_TOUCH_RELEASED && | 188 if (event.type() != ET_TOUCH_RELEASED && |
203 event.type() != ET_TOUCH_CANCELLED) { | 189 event.type() != ET_TOUCH_CANCELLED) { |
204 return; | 190 return; |
205 } | 191 } |
206 | 192 |
207 int index_to_delete = static_cast<int>(GetIndexFromId(event.touch_id())); | 193 DCHECK(pointer_count_); |
| 194 int index_to_delete = GetIndexFromId(event.touch_id()); |
| 195 cached_action_index_ = 0; |
208 pointer_count_--; | 196 pointer_count_--; |
209 active_touches_[index_to_delete] = active_touches_[pointer_count_]; | 197 active_touches_[index_to_delete] = active_touches_[pointer_count_]; |
210 } | 198 } |
211 | 199 |
212 MotionEventAura::PointData::PointData() | 200 MotionEventAura::PointData::PointData() |
213 : x(0), | 201 : x(0), |
214 y(0), | 202 y(0), |
215 raw_x(0), | 203 raw_x(0), |
216 raw_y(0), | 204 raw_y(0), |
217 touch_id(0), | 205 touch_id(0), |
(...skipping 24 matching lines...) Expand all Loading... |
242 } | 230 } |
243 | 231 |
244 void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) { | 232 void MotionEventAura::UpdateCachedAction(const TouchEvent& touch) { |
245 DCHECK(pointer_count_); | 233 DCHECK(pointer_count_); |
246 switch (touch.type()) { | 234 switch (touch.type()) { |
247 case ET_TOUCH_PRESSED: | 235 case ET_TOUCH_PRESSED: |
248 if (pointer_count_ == 1) { | 236 if (pointer_count_ == 1) { |
249 cached_action_ = ACTION_DOWN; | 237 cached_action_ = ACTION_DOWN; |
250 } else { | 238 } else { |
251 cached_action_ = ACTION_POINTER_DOWN; | 239 cached_action_ = ACTION_POINTER_DOWN; |
252 cached_action_index_ = | 240 cached_action_index_ = GetIndexFromId(touch.touch_id()); |
253 static_cast<int>(GetIndexFromId(touch.touch_id())); | |
254 } | 241 } |
255 break; | 242 break; |
256 case ET_TOUCH_RELEASED: | 243 case ET_TOUCH_RELEASED: |
257 if (pointer_count_ == 1) { | 244 if (pointer_count_ == 1) { |
258 cached_action_ = ACTION_UP; | 245 cached_action_ = ACTION_UP; |
259 } else { | 246 } else { |
260 cached_action_ = ACTION_POINTER_UP; | 247 cached_action_ = ACTION_POINTER_UP; |
261 cached_action_index_ = | 248 cached_action_index_ = GetIndexFromId(touch.touch_id()); |
262 static_cast<int>(GetIndexFromId(touch.touch_id())); | |
263 DCHECK_LT(cached_action_index_, static_cast<int>(pointer_count_)); | |
264 } | 249 } |
265 break; | 250 break; |
266 case ET_TOUCH_CANCELLED: | 251 case ET_TOUCH_CANCELLED: |
267 cached_action_ = ACTION_CANCEL; | 252 cached_action_ = ACTION_CANCEL; |
268 break; | 253 break; |
269 case ET_TOUCH_MOVED: | 254 case ET_TOUCH_MOVED: |
270 cached_action_ = ACTION_MOVE; | 255 cached_action_ = ACTION_MOVE; |
271 break; | 256 break; |
272 default: | 257 default: |
273 NOTREACHED(); | 258 NOTREACHED(); |
274 break; | 259 break; |
275 } | 260 } |
276 } | 261 } |
277 | 262 |
278 size_t MotionEventAura::GetIndexFromId(int id) const { | 263 int MotionEventAura::GetIndexFromId(int id) const { |
279 for (size_t i = 0; i < pointer_count_; ++i) { | 264 int index = FindPointerIndexOfId(id); |
280 if (active_touches_[i].touch_id == id) | 265 DCHECK_GE(index, 0); |
281 return i; | 266 DCHECK_LT(index, static_cast<int>(pointer_count_)); |
282 } | 267 return index; |
283 NOTREACHED(); | |
284 return 0; | |
285 } | 268 } |
286 | 269 |
287 } // namespace ui | 270 } // namespace ui |
OLD | NEW |