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

Side by Side Diff: content/browser/renderer_host/input/gesture_event_queue.h

Issue 120513005: [Android] Perform eager gesture recognition on MotionEvents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review and test cleanup Created 6 years, 11 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 2013 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_GESTURE_EVENT_QUEUE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_
7
8 #include <deque>
9 #include <queue>
10
11 #include "base/callback.h"
12 #include "content/browser/renderer_host/input/gesture_event_packet.h"
13 #include "content/common/content_export.h"
14 #include "content/port/common/input_event_ack_state.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h"
16
17 namespace content {
18
19 class CONTENT_EXPORT GestureEventQueueClient {
20 public:
21 virtual void ForwardGestureEvent(const blink::WebGestureEvent&) = 0;
22 protected:
23 virtual ~GestureEventQueueClient() {}
24 };
25
26 // Handles forwarding of gestures created by the platform.
27 // * Touch-derived gestures derived are forwarded or dropped depending on the
28 // disposition of the generating touch sequence.
29 // * Synthetic gestures are always forwarded, but will remain queued until all
30 // preceding gestures have been dispatched.
31 class CONTENT_EXPORT GestureEventQueue {
32 public:
33 explicit GestureEventQueue(GestureEventQueueClient* client);
34 ~GestureEventQueue();
35
36 // To be called upon receipt of gesture-related events. In particular,
37 // |packet| contains [0, n] gestures that correspond to a given event. That
38 // event may be a touch, a touch timeout, or some other synthetic source.
39 // It is imperative that a single packet is received for *each* touch event,
40 // even those that did not produce a gesture.
41 void OnGestureEventPacket(const GestureEventPacket& packet);
42
43 // To be called upon receipt of *all* touch event acks.
44 void OnTouchEventAck(InputEventAckState ack_state);
45
46 private:
47 typedef base::Callback<void(const GestureEventPacket& packet)> PacketSender;
48
49 // Utility class for tracking gesture events and dispositions for a single
50 // gesture sequence. A single sequence corresponds to all gestures created
51 // between the first finger down and the last finger up.
52 class GestureSequence {
53 public:
54 GestureSequence();
55 ~GestureSequence();
56
57 void Push(const GestureEventPacket& packet);
58 void OnTouchEventAck(InputEventAckState ack_state,
59 const PacketSender& packet_handler);
60 bool IsGesturePrevented() const;
61 bool IsEmpty() const;
62
63 private:
64 std::queue<GestureEventPacket> sequence_;
65 enum GestureHandlingState {
66 PENDING, // The sequence has yet to receive an ack.
67 ALLOWED_UNTIL_PREVENTED, // Gestures in the sequence are allowed until
68 // a source touch is preventDefault'ed.
69 ALWAYS_ALLOWED, // All remaining sequence gestures are forwarded.
70 ALWAYS_PREVENTED // All remaining sequence gestures are dropped.
71 };
72 GestureHandlingState state_;
73 };
74
75 void SendPacket(const GestureEventPacket& packet);
76 void SendGesture(const blink::WebGestureEvent& gesture);
77 void CancelTapIfNecessary();
78 void CancelFlingIfNecessary();
79 GestureSequence& Head();
80 GestureSequence& Tail();
81
82 GestureEventQueueClient* client_;
83 PacketSender packet_sender_;
84 std::queue<GestureSequence> sequences_;
85
86 // Bookkeeping for inserting synthetic Gesture{Tap,Fling}Cancel events
87 // when necessary, e.g., GestureTapCancel when scrolling begins, or
88 // GestureFlingCancel when a user taps following a GestureFlingStart.
89 bool needs_tap_ending_event_;
90 bool needs_fling_ending_event_;
91
92 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue);
93 };
94
95 } // namespace content
96
97 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698