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

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: More testing Created 6 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 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 "content/browser/renderer_host/input/gesture_event_packet.h"
12 #include "content/common/content_export.h"
13 #include "content/port/common/input_event_ack_state.h"
14 #include "third_party/WebKit/public/web/WebInputEvent.h"
15
16 namespace content {
17
18 // Interface with which the |GestureEventQueue| forwards gestures for a given
19 // touch event.
20 class CONTENT_EXPORT GestureEventQueueClient {
21 public:
22 virtual void ForwardGestureEvent(const blink::WebGestureEvent&) = 0;
23 };
24
25 // Handles dispatch of touch-derived gestures created by the platform.
26 // Gestures are forwarded or dropped depending on the ack dispositions of the
27 // generating touch sequence.
28 class CONTENT_EXPORT GestureEventQueue {
29 public:
30 explicit GestureEventQueue(GestureEventQueueClient* client);
31 ~GestureEventQueue();
32
33 // To be called upon receipt of gesture-related events. In particular,
34 // |packet| contains [0, n] gestures that correspond to a given event. That
35 // event may be a touch, or a touch timeout for certain stationary gestures.
36 // It is imperative that a single packet is received for *each* touch event,
37 // even those that did not produce a gesture.
38 void OnGestureEventPacket(const GestureEventPacket& packet);
39
40 // To be called upon receipt of *all* touch event acks.
41 void OnTouchEventAck(InputEventAckState ack_state);
42
43 private:
44 // Utility class for tracking gesture events and dispositions for a single
45 // gesture sequence. A single sequence corresponds to all gestures created
46 // between the first finger down and the last finger up, including gestures
47 // generated by timeouts from a statinoary finger.
48 class GestureSequence {
49 public:
50 GestureSequence();
51 ~GestureSequence();
52
53 void Push(const GestureEventPacket& packet);
54 void Pop();
55 const GestureEventPacket& Front() const;
56 void UpdateState(InputEventAckState ack_state);
57 bool IsGesturePrevented() const;
58 bool IsEmpty() const;
59
60 private:
61 std::queue<GestureEventPacket> packets_;
62 enum GestureHandlingState {
63 PENDING, // The sequence has yet to receive an ack.
64 ALLOWED_UNTIL_PREVENTED, // Gestures in the sequence are allowed until
65 // a source touch is preventDefault'ed.
66 ALWAYS_ALLOWED, // All remaining sequence gestures are forwarded.
67 ALWAYS_PREVENTED // All remaining sequence gestures are dropped.
68 };
69 GestureHandlingState state_;
70 };
71 void UpdateAndDispatchPackets(GestureSequence* sequence,
72 InputEventAckState ack_result);
73 void SendPacket(const GestureEventPacket& packet);
74 void SendGesture(const blink::WebGestureEvent& gesture);
75 void CancelTapIfNecessary();
76 void CancelFlingIfNecessary();
77 GestureSequence& Head();
78 GestureSequence& Tail();
79
80 GestureEventQueueClient* client_;
81 std::queue<GestureSequence> sequences_;
82
83 // Bookkeeping for inserting synthetic Gesture{Tap,Fling}Cancel events
84 // when necessary, e.g., GestureTapCancel when scrolling begins, or
85 // GestureFlingCancel when a user taps following a GestureFlingStart.
86 bool needs_tap_ending_event_;
87 bool needs_fling_ending_event_;
88
89 DISALLOW_COPY_AND_ASSIGN(GestureEventQueue);
90 };
91
92 } // namespace content
93
94 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698