Chromium Code Reviews| Index: content/common/input/web_input_event_queue.h |
| diff --git a/content/common/input/web_input_event_queue.h b/content/common/input/web_input_event_queue.h |
| index eab05997a377c91bea57ba07bdb309b4fee21baf..a8f9d9b3d3013c9b15a7bfbfe2c52cecf7348dfe 100644 |
| --- a/content/common/input/web_input_event_queue.h |
| +++ b/content/common/input/web_input_event_queue.h |
| @@ -10,42 +10,30 @@ |
| namespace content { |
| -enum class WebInputEventQueueState { ITEM_PENDING, ITEM_NOT_PENDING }; |
| - |
| -// WebInputEventQueue is a coalescing queue with the addition of a state |
| -// variable that represents whether an item is pending to be processed. |
| -// The desired usage sending with this queue is: |
| -// if (queue.state() == WebInputEventQueueState::ITEM_PENDING) { |
| -// queue.Queue(T); |
| -// } else { |
| -// send T |
| -// queue.set_state(WebInputEventQueueState::ITEM_PENDING); |
| -// } |
| -// |
| -// Processing the event response: |
| -// if (!queue.empty()) { |
| -// T = queue.Pop(); |
| -// send T now |
| -// } else { |
| -// queue.set_state(WebInputEventQueueState::ITEM_NOT_PENDING); |
| -// } |
| -// |
| +// WebInputEventQueue is a coalescing queue. It will examine |
| +// the current events in the queue and will attempt to coalesce with |
| +// the last event of the same class type. |
| template <typename T> |
| class WebInputEventQueue { |
| public: |
| - WebInputEventQueue() : state_(WebInputEventQueueState::ITEM_NOT_PENDING) {} |
| + WebInputEventQueue() {} |
| // Adds an event to the queue. The event may be coalesced with previously |
| // queued events. |
| - void Queue(const T& event) { |
| - if (!queue_.empty()) { |
| - std::unique_ptr<T>& last_event = queue_.back(); |
| - if (last_event->CanCoalesceWith(event)) { |
| - last_event->CoalesceWith(event); |
| + void Queue(std::unique_ptr<T>&& event) { |
|
tdresser
2016/07/22 19:13:41
We're supposed to avoid passing rvalue references,
dtapuska
2016/07/22 20:14:07
Done.
|
| + for (auto last_event_iter = queue_.rbegin(); |
| + last_event_iter != queue_.rend(); ++last_event_iter) { |
|
tdresser
2016/07/22 19:13:41
Range based for?
dtapuska
2016/07/22 20:14:07
This is a reverse iterator; reverse range iterator
|
| + if (!(*last_event_iter)->event().isSameEventClass(event->event())) { |
| + continue; |
| + } |
| + |
| + if ((*last_event_iter)->CanCoalesceWith(*event.get())) { |
| + (*last_event_iter)->CoalesceWith(*event.get()); |
| return; |
| } |
| + break; |
| } |
| - queue_.emplace_back(std::unique_ptr<T>(new T(event))); |
| + queue_.emplace_back(std::move(event)); |
| } |
| std::unique_ptr<T> Pop() { |
| @@ -61,14 +49,9 @@ class WebInputEventQueue { |
| size_t size() const { return queue_.size(); } |
| - void set_state(WebInputEventQueueState state) { state_ = state; } |
| - |
| - WebInputEventQueueState state() const WARN_UNUSED_RESULT { return state_; } |
| - |
| private: |
| typedef std::deque<std::unique_ptr<T>> EventQueue; |
| EventQueue queue_; |
| - WebInputEventQueueState state_; |
| DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue); |
| }; |