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

Unified 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: Allow scrolling after longpress 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/gesture_event_queue.h
diff --git a/content/browser/renderer_host/input/gesture_event_queue.h b/content/browser/renderer_host/input/gesture_event_queue.h
new file mode 100644
index 0000000000000000000000000000000000000000..5e43a29bce67fa7abfcb75e014cafc506b0d01bc
--- /dev/null
+++ b/content/browser/renderer_host/input/gesture_event_queue.h
@@ -0,0 +1,97 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_
+#define CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_
+
+#include <deque>
+#include <queue>
+
+#include "base/callback.h"
+#include "content/browser/renderer_host/input/gesture_event_packet.h"
+#include "content/common/content_export.h"
+#include "content/port/common/input_event_ack_state.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+
+namespace content {
+
+class CONTENT_EXPORT GestureEventQueueClient {
+ public:
+ virtual void ForwardGestureEvent(const blink::WebGestureEvent&) = 0;
+ protected:
+ virtual ~GestureEventQueueClient() {}
+};
+
+// Handles forwarding of gestures created by the platform.
+// * Touch-derived gestures derived are forwarded or dropped depending on the
+// disposition of the generating touch sequence.
+// * Synthetic gestures are always forwarded, but will remain queued until all
+// preceding gestures have been dispatched.
+class CONTENT_EXPORT GestureEventQueue {
+ public:
+ explicit GestureEventQueue(GestureEventQueueClient* client);
+ ~GestureEventQueue();
+
+ // To be called upon receipt of gesture-related events. In particular,
+ // |packet| contains [0, n] gestures that correspond to a given event. That
+ // event may be a touch, a touch timeout, or some other synthetic source.
+ // It is imperative that a single packet is received for *each* touch event,
+ // even those that did not produce a gesture.
+ void OnGestureEventPacket(const GestureEventPacket& packet);
+
+ // To be called upon receipt of *all* touch event acks.
+ void OnTouchEventAck(InputEventAckState ack_state);
+
+ private:
+ typedef base::Callback<void(const GestureEventPacket& packet)> PacketSender;
+
+ // Utility class for tracking gesture events and dispositions for a single
+ // gesture sequence. A single sequence corresponds to all gestures created
+ // between the first finger down and the last finger up.
+ class GestureSequence {
+ public:
+ GestureSequence();
+ ~GestureSequence();
+
+ void Push(const GestureEventPacket& packet);
+ void OnTouchEventAck(InputEventAckState ack_state,
+ const PacketSender& packet_handler);
+ bool IsGesturePrevented() const;
+ bool IsEmpty() const;
+
+ private:
+ std::queue<GestureEventPacket> sequence_;
+ enum GestureHandlingState {
+ PENDING, // The sequence has yet to receive an ack.
+ ALLOWED_UNTIL_PREVENTED, // Gestures in the sequence are allowed until
+ // a source touch is preventDefault'ed.
+ ALWAYS_ALLOWED, // All remaining sequence gestures are forwarded.
+ ALWAYS_PREVENTED // All remaining sequence gestures are dropped.
+ };
+ GestureHandlingState state_;
+ };
+
+ void SendPacket(const GestureEventPacket& packet);
+ void SendGesture(const blink::WebGestureEvent& gesture);
+ void CancelTapIfNecessary();
+ void CancelFlingIfNecessary();
+ GestureSequence& Head();
+ GestureSequence& Tail();
+
+ GestureEventQueueClient* client_;
+ PacketSender packet_sender_;
+ std::queue<GestureSequence> sequences_;
+
+ // Bookkeeping for inserting synthetic Gesture{Tap,Fling}Cancel events
+ // when necessary, e.g., GestureTapCancel when scrolling begins, or
+ // GestureFlingCancel when a user taps following a GestureFlingStart.
+ bool needs_tap_ending_event_;
+ bool needs_fling_ending_event_;
+
+ DISALLOW_COPY_AND_ASSIGN(GestureEventQueue);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_GESTURE_EVENT_QUEUE_H_

Powered by Google App Engine
This is Rietveld 408576698