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