| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ | 5 #ifndef CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ |
| 6 #define CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ | 6 #define CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 // WebInputEventQueue is a coalescing queue. It will examine | 13 // WebInputEventQueue is a coalescing queue. It will examine |
| 14 // the current events in the queue and will attempt to coalesce with | 14 // the current events in the queue and will attempt to coalesce with |
| 15 // the last event of the same class type. | 15 // the last event of the same class type. |
| 16 template <typename T> | 16 template <typename T> |
| 17 class WebInputEventQueue { | 17 class WebInputEventQueue { |
| 18 public: | 18 public: |
| 19 WebInputEventQueue() {} | 19 WebInputEventQueue() {} |
| 20 | 20 |
| 21 // Adds an event to the queue. The event may be coalesced with previously | 21 // Adds an event to the queue. The event may be coalesced with previously |
| 22 // queued events. | 22 // queued events. |
| 23 void Queue(std::unique_ptr<T> event) { | 23 void Queue(std::unique_ptr<T> event) { |
| 24 for (auto last_event_iter = queue_.rbegin(); | 24 for (auto last_event_iter = queue_.rbegin(); |
| 25 last_event_iter != queue_.rend(); ++last_event_iter) { | 25 last_event_iter != queue_.rend(); ++last_event_iter) { |
| 26 if (!(*last_event_iter)->event().isSameEventClass(event->event())) { | 26 if (!(*last_event_iter) |
| 27 ->coalescedEvent() |
| 28 .event() |
| 29 .isSameEventClass(event->coalescedEvent().event())) { |
| 27 continue; | 30 continue; |
| 28 } | 31 } |
| 29 | 32 |
| 30 if ((*last_event_iter)->CanCoalesceWith(*event.get())) { | 33 if ((*last_event_iter)->CanCoalesceWith(*event.get())) { |
| 31 (*last_event_iter)->CoalesceWith(*event.get()); | 34 (*last_event_iter)->CoalesceWith(*event.get()); |
| 32 return; | 35 return; |
| 33 } | 36 } |
| 34 break; | 37 break; |
| 35 } | 38 } |
| 36 queue_.emplace_back(std::move(event)); | 39 queue_.emplace_back(std::move(event)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 55 private: | 58 private: |
| 56 typedef std::deque<std::unique_ptr<T>> EventQueue; | 59 typedef std::deque<std::unique_ptr<T>> EventQueue; |
| 57 EventQueue queue_; | 60 EventQueue queue_; |
| 58 | 61 |
| 59 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue); | 62 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue); |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 } // namespace content | 65 } // namespace content |
| 63 | 66 |
| 64 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ | 67 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_ |
| OLD | NEW |