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