Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Side by Side Diff: content/common/input/web_input_event_queue.h

Issue 1631963002: Plumb firing passive event listeners. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master_wheel_passive_listeners_2a
Patch Set: Fix last touch sequence start to be last touch start Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
6 #define CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
7
8 #include <deque>
9
10 #include "base/memory/scoped_ptr.h"
11
12 namespace content {
13
14 enum class WebInputEventQueueState { ITEM_PENDING, ITEM_NOT_PENDING };
15
16 // WebInputEventQueue is a coalescing queue with the addition of a state
17 // variable that represents whether an item is pending to be processed.
18 // The desired usage sending with this queue is:
19 // if (queue.state() == WebInputEventQueueState::ITEM_PENDING) {
20 // queue.Queue(T);
21 // } else {
22 // send T
23 // queue.set_state(WebInputEventQueueState::ITEM_PENDING);
24 // }
25 //
26 // Processing the event response:
27 // if (!queue.empty()) {
28 // T = queue.Pop();
29 // send T now
30 // } else {
31 // queue.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
32 // }
33 //
34 template <typename T>
35 class WebInputEventQueue {
36 public:
37 WebInputEventQueue() : state_(WebInputEventQueueState::ITEM_NOT_PENDING) {}
38
39 // Adds an event to the queue. The event may be coalesced with previously
40 // queued events.
41 void Queue(const T& event) {
42 if (!queue_.empty()) {
43 scoped_ptr<T>& last_event = queue_.back();
44 if (last_event->CanCoalesceWith(event)) {
45 last_event->CoalesceWith(event);
46 return;
47 }
48 }
49 queue_.emplace_back(scoped_ptr<T>(new T(event)));
50 }
51
52 scoped_ptr<T> Pop() {
53 scoped_ptr<T> result;
54 if (!queue_.empty()) {
55 result.reset(queue_.front().release());
56 queue_.pop_front();
57 }
58 return result;
59 }
60
61 bool empty() const { return queue_.empty(); }
62
63 size_t size() const { return queue_.size(); }
64
65 void set_state(WebInputEventQueueState state) { state_ = state; }
66
67 WebInputEventQueueState state() const WARN_UNUSED_RESULT { return state_; }
68
69 private:
70 typedef std::deque<scoped_ptr<T>> EventQueue;
71 EventQueue queue_;
72 WebInputEventQueueState state_;
73
74 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue);
75 };
76
77 } // namespace content
78
79 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698