| 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..5677c539d7ebd90737ff316b2b3926140bd75967 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) {
|
| + for (auto last_event_iter = queue_.rbegin();
|
| + last_event_iter != queue_.rend(); ++last_event_iter) {
|
| + 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);
|
| };
|
|
|