| 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/gesture_detection/motion_event_buffer.h" | 5 #include "ui/events/gesture_detection/motion_event_buffer.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "ui/events/gesture_detection/motion_event.h" | 8 #include "ui/events/gesture_detection/motion_event.h" |
| 9 #include "ui/events/gesture_detection/motion_event_generic.h" | 9 #include "ui/events/gesture_detection/motion_event_generic.h" |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 size_t pointer_index) { | 90 size_t pointer_index) { |
| 91 PointerProperties result; | 91 PointerProperties result; |
| 92 result.id = event.GetPointerId(pointer_index); | 92 result.id = event.GetPointerId(pointer_index); |
| 93 result.tool_type = event.GetToolType(pointer_index); | 93 result.tool_type = event.GetToolType(pointer_index); |
| 94 result.x = event.GetX(pointer_index); | 94 result.x = event.GetX(pointer_index); |
| 95 result.y = event.GetY(pointer_index); | 95 result.y = event.GetY(pointer_index); |
| 96 result.raw_x = event.GetRawX(pointer_index); | 96 result.raw_x = event.GetRawX(pointer_index); |
| 97 result.raw_y = event.GetRawY(pointer_index); | 97 result.raw_y = event.GetRawY(pointer_index); |
| 98 result.pressure = event.GetPressure(pointer_index); | 98 result.pressure = event.GetPressure(pointer_index); |
| 99 result.touch_major = event.GetTouchMajor(pointer_index); | 99 result.touch_major = event.GetTouchMajor(pointer_index); |
| 100 result.touch_minor = event.GetTouchMinor(pointer_index); |
| 101 result.orientation = event.GetOrientation(pointer_index); |
| 100 return result; | 102 return result; |
| 101 } | 103 } |
| 102 | 104 |
| 103 PointerProperties ResamplePointer(const MotionEvent& event0, | 105 PointerProperties ResamplePointer(const MotionEvent& event0, |
| 104 const MotionEvent& event1, | 106 const MotionEvent& event1, |
| 105 size_t event0_pointer_index, | 107 size_t event0_pointer_index, |
| 106 size_t event1_pointer_index, | 108 size_t event1_pointer_index, |
| 107 float alpha) { | 109 float alpha) { |
| 108 DCHECK_EQ(event0.GetPointerId(event0_pointer_index), | 110 DCHECK_EQ(event0.GetPointerId(event0_pointer_index), |
| 109 event1.GetPointerId(event1_pointer_index)); | 111 event1.GetPointerId(event1_pointer_index)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 // recent event used as the base event, and prior events used as the history. | 169 // recent event used as the base event, and prior events used as the history. |
| 168 class CompoundMotionEvent : public ui::MotionEvent { | 170 class CompoundMotionEvent : public ui::MotionEvent { |
| 169 public: | 171 public: |
| 170 explicit CompoundMotionEvent(MotionEventVector events) | 172 explicit CompoundMotionEvent(MotionEventVector events) |
| 171 : events_(events.Pass()) { | 173 : events_(events.Pass()) { |
| 172 DCHECK_GE(events_.size(), 1U); | 174 DCHECK_GE(events_.size(), 1U); |
| 173 } | 175 } |
| 174 virtual ~CompoundMotionEvent() {} | 176 virtual ~CompoundMotionEvent() {} |
| 175 | 177 |
| 176 virtual int GetId() const OVERRIDE { return latest().GetId(); } | 178 virtual int GetId() const OVERRIDE { return latest().GetId(); } |
| 179 |
| 177 virtual Action GetAction() const OVERRIDE { return latest().GetAction(); } | 180 virtual Action GetAction() const OVERRIDE { return latest().GetAction(); } |
| 181 |
| 178 virtual int GetActionIndex() const OVERRIDE { | 182 virtual int GetActionIndex() const OVERRIDE { |
| 179 return latest().GetActionIndex(); | 183 return latest().GetActionIndex(); |
| 180 } | 184 } |
| 185 |
| 181 virtual size_t GetPointerCount() const OVERRIDE { | 186 virtual size_t GetPointerCount() const OVERRIDE { |
| 182 return latest().GetPointerCount(); | 187 return latest().GetPointerCount(); |
| 183 } | 188 } |
| 189 |
| 184 virtual int GetPointerId(size_t pointer_index) const OVERRIDE { | 190 virtual int GetPointerId(size_t pointer_index) const OVERRIDE { |
| 185 return latest().GetPointerId(pointer_index); | 191 return latest().GetPointerId(pointer_index); |
| 186 } | 192 } |
| 193 |
| 187 virtual float GetX(size_t pointer_index) const OVERRIDE { | 194 virtual float GetX(size_t pointer_index) const OVERRIDE { |
| 188 return latest().GetX(pointer_index); | 195 return latest().GetX(pointer_index); |
| 189 } | 196 } |
| 197 |
| 190 virtual float GetY(size_t pointer_index) const OVERRIDE { | 198 virtual float GetY(size_t pointer_index) const OVERRIDE { |
| 191 return latest().GetY(pointer_index); | 199 return latest().GetY(pointer_index); |
| 192 } | 200 } |
| 201 |
| 193 virtual float GetRawX(size_t pointer_index) const OVERRIDE { | 202 virtual float GetRawX(size_t pointer_index) const OVERRIDE { |
| 194 return latest().GetRawX(pointer_index); | 203 return latest().GetRawX(pointer_index); |
| 195 } | 204 } |
| 205 |
| 196 virtual float GetRawY(size_t pointer_index) const OVERRIDE { | 206 virtual float GetRawY(size_t pointer_index) const OVERRIDE { |
| 197 return latest().GetRawY(pointer_index); | 207 return latest().GetRawY(pointer_index); |
| 198 } | 208 } |
| 209 |
| 199 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE { | 210 virtual float GetTouchMajor(size_t pointer_index) const OVERRIDE { |
| 200 return latest().GetTouchMajor(pointer_index); | 211 return latest().GetTouchMajor(pointer_index); |
| 201 } | 212 } |
| 213 |
| 214 virtual float GetTouchMinor(size_t pointer_index) const OVERRIDE { |
| 215 return latest().GetTouchMinor(pointer_index); |
| 216 } |
| 217 |
| 218 virtual float GetOrientation(size_t pointer_index) const OVERRIDE { |
| 219 return latest().GetOrientation(pointer_index); |
| 220 } |
| 221 |
| 202 virtual float GetPressure(size_t pointer_index) const OVERRIDE { | 222 virtual float GetPressure(size_t pointer_index) const OVERRIDE { |
| 203 return latest().GetPressure(pointer_index); | 223 return latest().GetPressure(pointer_index); |
| 204 } | 224 } |
| 225 |
| 205 virtual ToolType GetToolType(size_t pointer_index) const OVERRIDE { | 226 virtual ToolType GetToolType(size_t pointer_index) const OVERRIDE { |
| 206 return latest().GetToolType(pointer_index); | 227 return latest().GetToolType(pointer_index); |
| 207 } | 228 } |
| 229 |
| 208 virtual int GetButtonState() const OVERRIDE { | 230 virtual int GetButtonState() const OVERRIDE { |
| 209 return latest().GetButtonState(); | 231 return latest().GetButtonState(); |
| 210 } | 232 } |
| 233 |
| 211 virtual base::TimeTicks GetEventTime() const OVERRIDE { | 234 virtual base::TimeTicks GetEventTime() const OVERRIDE { |
| 212 return latest().GetEventTime(); | 235 return latest().GetEventTime(); |
| 213 } | 236 } |
| 237 |
| 214 virtual size_t GetHistorySize() const OVERRIDE { return events_.size() - 1; } | 238 virtual size_t GetHistorySize() const OVERRIDE { return events_.size() - 1; } |
| 239 |
| 215 virtual base::TimeTicks GetHistoricalEventTime( | 240 virtual base::TimeTicks GetHistoricalEventTime( |
| 216 size_t historical_index) const OVERRIDE { | 241 size_t historical_index) const OVERRIDE { |
| 217 DCHECK_LT(historical_index, GetHistorySize()); | 242 DCHECK_LT(historical_index, GetHistorySize()); |
| 218 return events_[historical_index]->GetEventTime(); | 243 return events_[historical_index]->GetEventTime(); |
| 219 } | 244 } |
| 245 |
| 220 virtual float GetHistoricalTouchMajor( | 246 virtual float GetHistoricalTouchMajor( |
| 221 size_t pointer_index, | 247 size_t pointer_index, |
| 222 size_t historical_index) const OVERRIDE { | 248 size_t historical_index) const OVERRIDE { |
| 223 DCHECK_LT(historical_index, GetHistorySize()); | 249 DCHECK_LT(historical_index, GetHistorySize()); |
| 224 return events_[historical_index]->GetTouchMajor(); | 250 return events_[historical_index]->GetTouchMajor(); |
| 225 } | 251 } |
| 252 |
| 226 virtual float GetHistoricalX(size_t pointer_index, | 253 virtual float GetHistoricalX(size_t pointer_index, |
| 227 size_t historical_index) const OVERRIDE { | 254 size_t historical_index) const OVERRIDE { |
| 228 DCHECK_LT(historical_index, GetHistorySize()); | 255 DCHECK_LT(historical_index, GetHistorySize()); |
| 229 return events_[historical_index]->GetX(pointer_index); | 256 return events_[historical_index]->GetX(pointer_index); |
| 230 } | 257 } |
| 258 |
| 231 virtual float GetHistoricalY(size_t pointer_index, | 259 virtual float GetHistoricalY(size_t pointer_index, |
| 232 size_t historical_index) const OVERRIDE { | 260 size_t historical_index) const OVERRIDE { |
| 233 DCHECK_LT(historical_index, GetHistorySize()); | 261 DCHECK_LT(historical_index, GetHistorySize()); |
| 234 return events_[historical_index]->GetY(pointer_index); | 262 return events_[historical_index]->GetY(pointer_index); |
| 235 } | 263 } |
| 264 |
| 236 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE { | 265 virtual scoped_ptr<MotionEvent> Clone() const OVERRIDE { |
| 237 MotionEventVector cloned_events; | 266 MotionEventVector cloned_events; |
| 238 cloned_events.reserve(events_.size()); | 267 cloned_events.reserve(events_.size()); |
| 239 for (size_t i = 0; i < events_.size(); ++i) | 268 for (size_t i = 0; i < events_.size(); ++i) |
| 240 cloned_events.push_back(events_[i]->Clone().release()); | 269 cloned_events.push_back(events_[i]->Clone().release()); |
| 241 return scoped_ptr<MotionEvent>( | 270 return scoped_ptr<MotionEvent>( |
| 242 new CompoundMotionEvent(cloned_events.Pass())); | 271 new CompoundMotionEvent(cloned_events.Pass())); |
| 243 } | 272 } |
| 273 |
| 244 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE { | 274 virtual scoped_ptr<MotionEvent> Cancel() const OVERRIDE { |
| 245 return latest().Cancel(); | 275 return latest().Cancel(); |
| 246 } | 276 } |
| 247 | 277 |
| 248 // Returns the new, resampled event, or NULL if none was created. | 278 // Returns the new, resampled event, or NULL if none was created. |
| 249 // TODO(jdduke): Revisit resampling to handle cases where alternating frames | 279 // TODO(jdduke): Revisit resampling to handle cases where alternating frames |
| 250 // are resampled or resampling is otherwise inconsistent, e.g., a 90hz input | 280 // are resampled or resampling is otherwise inconsistent, e.g., a 90hz input |
| 251 // and 60hz frame signal could phase-align such that even frames yield an | 281 // and 60hz frame signal could phase-align such that even frames yield an |
| 252 // extrapolated event and odd frames are not resampled, crbug.com/399381. | 282 // extrapolated event and odd frames are not resampled, crbug.com/399381. |
| 253 const MotionEvent* TryResample(base::TimeTicks resample_time, | 283 const MotionEvent* TryResample(base::TimeTicks resample_time, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 events.weak_clear(); | 453 events.weak_clear(); |
| 424 client_->ForwardMotionEvent(*event); | 454 client_->ForwardMotionEvent(*event); |
| 425 return; | 455 return; |
| 426 } | 456 } |
| 427 | 457 |
| 428 CompoundMotionEvent compound_event(events.Pass()); | 458 CompoundMotionEvent compound_event(events.Pass()); |
| 429 client_->ForwardMotionEvent(compound_event); | 459 client_->ForwardMotionEvent(compound_event); |
| 430 } | 460 } |
| 431 | 461 |
| 432 } // namespace ui | 462 } // namespace ui |
| OLD | NEW |