OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_BROWSER_RENDERER_HOST_INPUT_WHEEL_EVENT_QUEUE_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_WHEEL_EVENT_QUEUE_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/timer/timer.h" | |
12 #include "content/browser/renderer_host/event_with_latency_info.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/common/input/input_event_ack_state.h" | |
15 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
16 | |
17 namespace content { | |
18 | |
19 // Interface with which the WheelEventQueue can forward wheel events, and | |
20 // dispatch wheel event responses. | |
21 class CONTENT_EXPORT WheelEventQueueClient { | |
22 public: | |
23 virtual ~WheelEventQueueClient() {} | |
24 | |
25 virtual void SendWheelEventImmediately( | |
26 const MouseWheelEventWithLatencyInfo& event) = 0; | |
27 | |
28 virtual void OnWheelEventAck(const MouseWheelEventWithLatencyInfo& event, | |
29 InputEventAckState ack_result) = 0; | |
30 | |
31 virtual void SetNeedsFlush() = 0; | |
32 }; | |
33 | |
34 class CONTENT_EXPORT WheelEventQueue { | |
35 public: | |
36 // |client| must outlive the WheelEventQueue. | |
37 WheelEventQueue(WheelEventQueueClient* client, bool buffer_until_flush); | |
38 ~WheelEventQueue(); | |
39 | |
40 // Adds a wheel event to the queue, forwarding if appropriate. | |
41 void QueueEvent(const MouseWheelEventWithLatencyInfo& wheel_event); | |
42 | |
43 // Indicates that the caller has received an acknowledgement from the renderer | |
44 // with state |ack_result| and event |type|. May send wheel events if the | |
45 // queue is not empty. | |
46 void ProcessWheelAck(InputEventAckState ack_result, | |
47 const ui::LatencyInfo& latency); | |
48 | |
49 // Called in response to a flush request made through the client. | |
50 void Flush(); | |
51 | |
52 bool empty() const { | |
53 return mouse_wheel_pending_ || coalesced_wheel_events_.empty(); | |
tdresser
2015/10/22 13:53:53
Why does mouse_wheel_pending_ imply that the queue
jdduke (slow)
2015/10/22 15:15:05
It doesn't, this is a bug :)
| |
54 } | |
55 | |
56 private: | |
57 void SendEvent(const MouseWheelEventWithLatencyInfo& wheel_event); | |
58 | |
59 WheelEventQueueClient* const client_; | |
60 | |
61 // Whether to buffer wheel events until a call to |FlushInput()|. | |
62 const bool buffer_until_flush_; | |
63 | |
64 // True if a wheel event was sent and we are waiting for a corresponding ack. | |
65 bool mouse_wheel_pending_; | |
66 MouseWheelEventWithLatencyInfo current_wheel_event_; | |
67 | |
68 // Whether we're inside a call to |Flush()|. | |
69 bool flushing_; | |
70 | |
71 // The next mouse wheel events to send. Mouse wheel events received while one | |
72 // is pending are coalesced (by accumulating deltas) if they match the | |
73 // previous event in modifiers. On the Mac, in particular, mouse wheel events | |
74 // are received at a high rate; not waiting for the ack results in jankiness, | |
75 // and using the same mechanism as for mouse moves (just dropping old events | |
76 // when multiple ones/ would be queued) results in very slow scrolling. | |
77 std::deque<MouseWheelEventWithLatencyInfo> coalesced_wheel_events_; | |
78 | |
79 DISALLOW_COPY_AND_ASSIGN(WheelEventQueue); | |
80 }; | |
81 | |
82 } // namespace content | |
83 | |
84 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_WHEEL_EVENT_QUEUE_H_ | |
OLD | NEW |