| 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 #ifndef UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ |
| 6 #define UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "ui/events/gesture_detection/gesture_detection_export.h" | 11 #include "ui/events/gesture_detection/gesture_detection_export.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 class MotionEvent; | 15 class MotionEvent; |
| 16 class MotionEventGeneric; |
| 16 | 17 |
| 17 // Allows event forwarding and flush requests from a |MotionEventBuffer|. | 18 // Allows event forwarding and flush requests from a |MotionEventBuffer|. |
| 18 class MotionEventBufferClient { | 19 class MotionEventBufferClient { |
| 19 public: | 20 public: |
| 20 virtual ~MotionEventBufferClient() {} | 21 virtual ~MotionEventBufferClient() {} |
| 21 virtual void ForwardMotionEvent(const MotionEvent& event) = 0; | 22 virtual void ForwardMotionEvent(const MotionEvent& event) = 0; |
| 22 virtual void SetNeedsFlush() = 0; | 23 virtual void SetNeedsFlush() = 0; |
| 23 }; | 24 }; |
| 24 | 25 |
| 25 // Utility class for buffering streamed MotionEventVector until a given flush. | 26 // Utility class for buffering streamed MotionEventVector until a given flush. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 45 void OnMotionEvent(const MotionEvent& event); | 46 void OnMotionEvent(const MotionEvent& event); |
| 46 | 47 |
| 47 // Forward any buffered events, resampling if necessary (see |resample_|) | 48 // Forward any buffered events, resampling if necessary (see |resample_|) |
| 48 // according to the provided |frame_time|. This should be called in response | 49 // according to the provided |frame_time|. This should be called in response |
| 49 // to |SetNeedsFlush()| calls on the client. If the buffer is empty, no | 50 // to |SetNeedsFlush()| calls on the client. If the buffer is empty, no |
| 50 // events will be forwarded, and if another flush is necessary it will be | 51 // events will be forwarded, and if another flush is necessary it will be |
| 51 // requested. | 52 // requested. |
| 52 void Flush(base::TimeTicks frame_time); | 53 void Flush(base::TimeTicks frame_time); |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 typedef ScopedVector<MotionEvent> MotionEventVector; | 56 typedef ScopedVector<MotionEventGeneric> MotionEventVector; |
| 56 | 57 |
| 58 void FlushWithResampling(MotionEventVector events, |
| 59 base::TimeTicks resample_time); |
| 57 void FlushWithoutResampling(MotionEventVector events); | 60 void FlushWithoutResampling(MotionEventVector events); |
| 58 | 61 |
| 59 MotionEventBufferClient* const client_; | 62 MotionEventBufferClient* const client_; |
| 60 MotionEventVector buffered_events_; | 63 MotionEventVector buffered_events_; |
| 61 | 64 |
| 62 // Time of the most recently extrapolated event. This will be 0 if the | 65 // Time of the most recently extrapolated event. This will be 0 if the |
| 63 // last sent event was not extrapolated. Used internally to guard against | 66 // last sent event was not extrapolated. Used internally to guard against |
| 64 // conflicts between events received from the platfrom that may have an | 67 // conflicts between events received from the platform that may have an |
| 65 // earlier timestamp than that synthesized at the latest resample. | 68 // earlier timestamp than that synthesized at the latest resample. |
| 66 base::TimeTicks last_extrapolated_event_time_; | 69 base::TimeTicks last_extrapolated_event_time_; |
| 67 | 70 |
| 68 // Whether buffered events should be resampled upon |Flush()|. If true, short | 71 // Whether buffered events should be resampled upon |Flush()|. If true, short |
| 69 // horizon interpolation/extrapolation will be used to synthesize the | 72 // horizon interpolation/extrapolation will be used to synthesize the |
| 70 // forwarded event. Otherwise the most recently buffered event will be | 73 // forwarded event. Otherwise the most recently buffered event will be |
| 71 // forwarded, with preceding events as historical entries. Defaults to true. | 74 // forwarded, with preceding events as historical entries. Defaults to true. |
| 72 bool resample_; | 75 bool resample_; |
| 73 | 76 |
| 74 DISALLOW_COPY_AND_ASSIGN(MotionEventBuffer); | 77 DISALLOW_COPY_AND_ASSIGN(MotionEventBuffer); |
| 75 }; | 78 }; |
| 76 | 79 |
| 77 } // namespace ui | 80 } // namespace ui |
| 78 | 81 |
| 79 #endif // UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ | 82 #endif // UI_EVENTS_GESTURE_DETECTION_MOTION_EVENT_BUFFER_H_ |
| OLD | NEW |