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

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

Issue 2765583002: Teach main thread event queue about closures. (Closed)
Patch Set: Fix typo Created 3 years, 8 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
« no previous file with comments | « content/common/BUILD.gn ('k') | content/renderer/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <memory>
10
11 namespace content {
12
13 // WebInputEventQueue is a coalescing queue. It will examine
14 // the current events in the queue and will attempt to coalesce with
15 // the last event of the same class type.
16 template <typename T>
17 class WebInputEventQueue {
18 public:
19 WebInputEventQueue() {}
20
21 // Adds an event to the queue. The event may be coalesced with previously
22 // queued events.
23 void Queue(std::unique_ptr<T> event) {
24 for (auto last_event_iter = queue_.rbegin();
25 last_event_iter != queue_.rend(); ++last_event_iter) {
26 if (!(*last_event_iter)->event().isSameEventClass(event->event())) {
27 continue;
28 }
29
30 if ((*last_event_iter)->CanCoalesceWith(*event.get())) {
31 (*last_event_iter)->CoalesceWith(*event.get());
32 return;
33 }
34 break;
35 }
36 queue_.emplace_back(std::move(event));
37 }
38
39 const std::unique_ptr<T>& front() const { return queue_.front(); }
40 const std::unique_ptr<T>& at(size_t pos) const { return queue_.at(pos); }
41
42 std::unique_ptr<T> Pop() {
43 std::unique_ptr<T> result;
44 if (!queue_.empty()) {
45 result.reset(queue_.front().release());
46 queue_.pop_front();
47 }
48 return result;
49 }
50
51 bool empty() const { return queue_.empty(); }
52
53 size_t size() const { return queue_.size(); }
54
55 private:
56 typedef std::deque<std::unique_ptr<T>> EventQueue;
57 EventQueue queue_;
58
59 DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue);
60 };
61
62 } // namespace content
63
64 #endif // CONTENT_COMMON_INPUT_WEB_INPUT_EVENT_QUEUE_H_
OLDNEW
« no previous file with comments | « content/common/BUILD.gn ('k') | content/renderer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698