| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 | 167 |
| 168 // MotionEvent implementation for storing multiple events, with the most | 168 // MotionEvent implementation for storing multiple events, with the most |
| 169 // 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. |
| 170 class CompoundMotionEvent : public ui::MotionEvent { | 170 class CompoundMotionEvent : public ui::MotionEvent { |
| 171 public: | 171 public: |
| 172 explicit CompoundMotionEvent(MotionEventVector events) | 172 explicit CompoundMotionEvent(MotionEventVector events) |
| 173 : events_(events.Pass()) { | 173 : events_(events.Pass()) { |
| 174 DCHECK_GE(events_.size(), 1U); | 174 DCHECK_GE(events_.size(), 1U); |
| 175 } | 175 } |
| 176 virtual ~CompoundMotionEvent() {} | 176 ~CompoundMotionEvent() override {} |
| 177 | 177 |
| 178 virtual int GetId() const override { return latest().GetId(); } | 178 int GetId() const override { return latest().GetId(); } |
| 179 | 179 |
| 180 virtual Action GetAction() const override { return latest().GetAction(); } | 180 Action GetAction() const override { return latest().GetAction(); } |
| 181 | 181 |
| 182 virtual int GetActionIndex() const override { | 182 int GetActionIndex() const override { return latest().GetActionIndex(); } |
| 183 return latest().GetActionIndex(); | |
| 184 } | |
| 185 | 183 |
| 186 virtual size_t GetPointerCount() const override { | 184 size_t GetPointerCount() const override { return latest().GetPointerCount(); } |
| 187 return latest().GetPointerCount(); | |
| 188 } | |
| 189 | 185 |
| 190 virtual int GetPointerId(size_t pointer_index) const override { | 186 int GetPointerId(size_t pointer_index) const override { |
| 191 return latest().GetPointerId(pointer_index); | 187 return latest().GetPointerId(pointer_index); |
| 192 } | 188 } |
| 193 | 189 |
| 194 virtual float GetX(size_t pointer_index) const override { | 190 float GetX(size_t pointer_index) const override { |
| 195 return latest().GetX(pointer_index); | 191 return latest().GetX(pointer_index); |
| 196 } | 192 } |
| 197 | 193 |
| 198 virtual float GetY(size_t pointer_index) const override { | 194 float GetY(size_t pointer_index) const override { |
| 199 return latest().GetY(pointer_index); | 195 return latest().GetY(pointer_index); |
| 200 } | 196 } |
| 201 | 197 |
| 202 virtual float GetRawX(size_t pointer_index) const override { | 198 float GetRawX(size_t pointer_index) const override { |
| 203 return latest().GetRawX(pointer_index); | 199 return latest().GetRawX(pointer_index); |
| 204 } | 200 } |
| 205 | 201 |
| 206 virtual float GetRawY(size_t pointer_index) const override { | 202 float GetRawY(size_t pointer_index) const override { |
| 207 return latest().GetRawY(pointer_index); | 203 return latest().GetRawY(pointer_index); |
| 208 } | 204 } |
| 209 | 205 |
| 210 virtual float GetTouchMajor(size_t pointer_index) const override { | 206 float GetTouchMajor(size_t pointer_index) const override { |
| 211 return latest().GetTouchMajor(pointer_index); | 207 return latest().GetTouchMajor(pointer_index); |
| 212 } | 208 } |
| 213 | 209 |
| 214 virtual float GetTouchMinor(size_t pointer_index) const override { | 210 float GetTouchMinor(size_t pointer_index) const override { |
| 215 return latest().GetTouchMinor(pointer_index); | 211 return latest().GetTouchMinor(pointer_index); |
| 216 } | 212 } |
| 217 | 213 |
| 218 virtual float GetOrientation(size_t pointer_index) const override { | 214 float GetOrientation(size_t pointer_index) const override { |
| 219 return latest().GetOrientation(pointer_index); | 215 return latest().GetOrientation(pointer_index); |
| 220 } | 216 } |
| 221 | 217 |
| 222 virtual float GetPressure(size_t pointer_index) const override { | 218 float GetPressure(size_t pointer_index) const override { |
| 223 return latest().GetPressure(pointer_index); | 219 return latest().GetPressure(pointer_index); |
| 224 } | 220 } |
| 225 | 221 |
| 226 virtual ToolType GetToolType(size_t pointer_index) const override { | 222 ToolType GetToolType(size_t pointer_index) const override { |
| 227 return latest().GetToolType(pointer_index); | 223 return latest().GetToolType(pointer_index); |
| 228 } | 224 } |
| 229 | 225 |
| 230 virtual int GetButtonState() const override { | 226 int GetButtonState() const override { return latest().GetButtonState(); } |
| 231 return latest().GetButtonState(); | |
| 232 } | |
| 233 | 227 |
| 234 virtual int GetFlags() const override { return latest().GetFlags(); } | 228 int GetFlags() const override { return latest().GetFlags(); } |
| 235 | 229 |
| 236 virtual base::TimeTicks GetEventTime() const override { | 230 base::TimeTicks GetEventTime() const override { |
| 237 return latest().GetEventTime(); | 231 return latest().GetEventTime(); |
| 238 } | 232 } |
| 239 | 233 |
| 240 virtual size_t GetHistorySize() const override { return events_.size() - 1; } | 234 size_t GetHistorySize() const override { return events_.size() - 1; } |
| 241 | 235 |
| 242 virtual base::TimeTicks GetHistoricalEventTime( | 236 base::TimeTicks GetHistoricalEventTime( |
| 243 size_t historical_index) const override { | 237 size_t historical_index) const override { |
| 244 DCHECK_LT(historical_index, GetHistorySize()); | 238 DCHECK_LT(historical_index, GetHistorySize()); |
| 245 return events_[historical_index]->GetEventTime(); | 239 return events_[historical_index]->GetEventTime(); |
| 246 } | 240 } |
| 247 | 241 |
| 248 virtual float GetHistoricalTouchMajor( | 242 float GetHistoricalTouchMajor(size_t pointer_index, |
| 249 size_t pointer_index, | 243 size_t historical_index) const override { |
| 250 size_t historical_index) const override { | |
| 251 DCHECK_LT(historical_index, GetHistorySize()); | 244 DCHECK_LT(historical_index, GetHistorySize()); |
| 252 return events_[historical_index]->GetTouchMajor(); | 245 return events_[historical_index]->GetTouchMajor(); |
| 253 } | 246 } |
| 254 | 247 |
| 255 virtual float GetHistoricalX(size_t pointer_index, | 248 float GetHistoricalX(size_t pointer_index, |
| 256 size_t historical_index) const override { | 249 size_t historical_index) const override { |
| 257 DCHECK_LT(historical_index, GetHistorySize()); | 250 DCHECK_LT(historical_index, GetHistorySize()); |
| 258 return events_[historical_index]->GetX(pointer_index); | 251 return events_[historical_index]->GetX(pointer_index); |
| 259 } | 252 } |
| 260 | 253 |
| 261 virtual float GetHistoricalY(size_t pointer_index, | 254 float GetHistoricalY(size_t pointer_index, |
| 262 size_t historical_index) const override { | 255 size_t historical_index) const override { |
| 263 DCHECK_LT(historical_index, GetHistorySize()); | 256 DCHECK_LT(historical_index, GetHistorySize()); |
| 264 return events_[historical_index]->GetY(pointer_index); | 257 return events_[historical_index]->GetY(pointer_index); |
| 265 } | 258 } |
| 266 | 259 |
| 267 virtual scoped_ptr<MotionEvent> Clone() const override { | 260 scoped_ptr<MotionEvent> Clone() const override { |
| 268 MotionEventVector cloned_events; | 261 MotionEventVector cloned_events; |
| 269 cloned_events.reserve(events_.size()); | 262 cloned_events.reserve(events_.size()); |
| 270 for (size_t i = 0; i < events_.size(); ++i) | 263 for (size_t i = 0; i < events_.size(); ++i) |
| 271 cloned_events.push_back(events_[i]->Clone().release()); | 264 cloned_events.push_back(events_[i]->Clone().release()); |
| 272 return scoped_ptr<MotionEvent>( | 265 return scoped_ptr<MotionEvent>( |
| 273 new CompoundMotionEvent(cloned_events.Pass())); | 266 new CompoundMotionEvent(cloned_events.Pass())); |
| 274 } | 267 } |
| 275 | 268 |
| 276 virtual scoped_ptr<MotionEvent> Cancel() const override { | 269 scoped_ptr<MotionEvent> Cancel() const override { return latest().Cancel(); } |
| 277 return latest().Cancel(); | |
| 278 } | |
| 279 | 270 |
| 280 // Returns the new, resampled event, or NULL if none was created. | 271 // Returns the new, resampled event, or NULL if none was created. |
| 281 // TODO(jdduke): Revisit resampling to handle cases where alternating frames | 272 // TODO(jdduke): Revisit resampling to handle cases where alternating frames |
| 282 // are resampled or resampling is otherwise inconsistent, e.g., a 90hz input | 273 // are resampled or resampling is otherwise inconsistent, e.g., a 90hz input |
| 283 // and 60hz frame signal could phase-align such that even frames yield an | 274 // and 60hz frame signal could phase-align such that even frames yield an |
| 284 // extrapolated event and odd frames are not resampled, crbug.com/399381. | 275 // extrapolated event and odd frames are not resampled, crbug.com/399381. |
| 285 const MotionEvent* TryResample(base::TimeTicks resample_time, | 276 const MotionEvent* TryResample(base::TimeTicks resample_time, |
| 286 const ui::MotionEvent* next) { | 277 const ui::MotionEvent* next) { |
| 287 DCHECK_EQ(GetAction(), ACTION_MOVE); | 278 DCHECK_EQ(GetAction(), ACTION_MOVE); |
| 288 const ui::MotionEvent* event0 = NULL; | 279 const ui::MotionEvent* event0 = NULL; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 events.weak_clear(); | 446 events.weak_clear(); |
| 456 client_->ForwardMotionEvent(*event); | 447 client_->ForwardMotionEvent(*event); |
| 457 return; | 448 return; |
| 458 } | 449 } |
| 459 | 450 |
| 460 CompoundMotionEvent compound_event(events.Pass()); | 451 CompoundMotionEvent compound_event(events.Pass()); |
| 461 client_->ForwardMotionEvent(compound_event); | 452 client_->ForwardMotionEvent(compound_event); |
| 462 } | 453 } |
| 463 | 454 |
| 464 } // namespace ui | 455 } // namespace ui |
| OLD | NEW |