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..d8ccdd60a091cfca0a0530d0cb8cf5a1b5a4dee9 100644 |
| --- a/content/common/input/web_input_event_queue.h |
| +++ b/content/common/input/web_input_event_queue.h |
| @@ -10,17 +10,11 @@ |
| 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. |
| +// WebInputEventQueue is a coalescing queue. |
|
tdresser
2016/07/20 20:52:27
Could the changes in this file be made separately
dtapuska
2016/07/27 05:29:00
Done.
|
| // 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); |
| -// } |
| +// bool send_notification = queue.empty(); |
| +// queue.Queue(T); |
| +// send notification |
|
tdresser
2016/07/20 20:52:27
This is a somewhat odd pseudo-pseudo-code.
I'd pr
dtapuska
2016/07/27 05:29:00
Done.
|
| // |
| // Processing the event response: |
| // if (!queue.empty()) { |
| @@ -33,19 +27,24 @@ enum class WebInputEventQueueState { ITEM_PENDING, ITEM_NOT_PENDING }; |
| 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) { |
| + for (auto last_event_iter = queue_.rbegin(); |
| + last_event_iter != queue_.rend(); ++last_event_iter) { |
|
tdresser
2016/07/20 20:52:27
Range based for?
dtapuska
2016/07/27 05:29:00
It's a reverse iteration; so you can't do a revers
|
| + if (!(*last_event_iter)->event().isSameEventClass(event->event())) { |
| + continue; |
| + } |
| + |
| + if ((*last_event_iter)->CanCoalesceWith(*event.get())) { |
|
tdresser
2016/07/20 20:52:27
Could we get weird out of order coalescing happeni
dtapuska
2016/07/27 05:29:00
No because it should stop at the most recent gestu
|
| + (*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 +60,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); |
| }; |