OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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_PASSTHROUGH_TOUCH_EVENT_QUEUE_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_PASSTHROUGH_TOUCH_EVENT_QUEUE_H_ |
| 7 |
| 8 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 9 |
| 10 #include <set> |
| 11 |
| 12 namespace content { |
| 13 |
| 14 class TouchTimeoutHandler; |
| 15 |
| 16 // A queue that processes a touch-event and forwards it on to the |
| 17 // renderer process immediately. This class assumes that queueing will |
| 18 // happen inside the renderer process. This class will hold onto the pending |
| 19 // events so that it can re-order the acks so that they appear in a |
| 20 // logical order to the rest of the browser process. Due to the threaded |
| 21 // model of the renderer it is possible that an ack for a touchend can |
| 22 // be sent before the corresponding ack for the touchstart. This class |
| 23 // corrects that state. |
| 24 class CONTENT_EXPORT PassthroughTouchEventQueue : public TouchEventQueue { |
| 25 public: |
| 26 PassthroughTouchEventQueue(TouchEventQueueClient* client, |
| 27 const Config& config); |
| 28 |
| 29 ~PassthroughTouchEventQueue() override; |
| 30 |
| 31 // TouchEventQueue overrides. |
| 32 void QueueEvent(const TouchEventWithLatencyInfo& event) override; |
| 33 |
| 34 void PrependTouchScrollNotification() override; |
| 35 |
| 36 void ProcessTouchAck(InputEventAckState ack_result, |
| 37 const ui::LatencyInfo& latency_info, |
| 38 const uint32_t unique_touch_event_id) override; |
| 39 void OnGestureScrollEvent( |
| 40 const GestureEventWithLatencyInfo& gesture_event) override; |
| 41 |
| 42 void OnGestureEventAck(const GestureEventWithLatencyInfo& event, |
| 43 InputEventAckState ack_result) override; |
| 44 |
| 45 void OnHasTouchEventHandlers(bool has_handlers) override; |
| 46 |
| 47 bool IsPendingAckTouchStart() const override; |
| 48 |
| 49 void SetAckTimeoutEnabled(bool enabled) override; |
| 50 |
| 51 void SetIsMobileOptimizedSite(bool mobile_optimized_site) override; |
| 52 |
| 53 bool IsAckTimeoutEnabled() const override; |
| 54 |
| 55 bool Empty() const override; |
| 56 |
| 57 protected: |
| 58 void SendTouchCancelEventForTouchEvent( |
| 59 const TouchEventWithLatencyInfo& event_to_cancel) override; |
| 60 void UpdateTouchConsumerStates(const blink::WebTouchEvent& event, |
| 61 InputEventAckState ack_result) override; |
| 62 // Empties the queue of touch events. This may result in any number of gesture |
| 63 // events being sent to the renderer. |
| 64 void FlushQueue() override; |
| 65 |
| 66 private: |
| 67 friend class PassthroughTouchEventQueueTest; |
| 68 |
| 69 class TouchEventWithLatencyInfoAndAckState |
| 70 : public TouchEventWithLatencyInfo { |
| 71 public: |
| 72 TouchEventWithLatencyInfoAndAckState(const TouchEventWithLatencyInfo&); |
| 73 bool operator<(const TouchEventWithLatencyInfoAndAckState&) const; |
| 74 InputEventAckState ack_state() const { return ack_state_; } |
| 75 void set_ack_state(InputEventAckState state) { ack_state_ = state; } |
| 76 |
| 77 private: |
| 78 InputEventAckState ack_state_; |
| 79 }; |
| 80 |
| 81 enum PreFilterResult { |
| 82 ACK_WITH_NO_CONSUMER_EXISTS, |
| 83 ACK_WITH_NOT_CONSUMED, |
| 84 FORWARD_TO_RENDERER, |
| 85 }; |
| 86 // Filter touches prior to forwarding to the renderer, e.g., if the renderer |
| 87 // has no touch handler. |
| 88 PreFilterResult FilterBeforeForwarding(const blink::WebTouchEvent& event); |
| 89 |
| 90 void AckTouchEventToClient(const TouchEventWithLatencyInfo& acked_event, |
| 91 InputEventAckState ack_result); |
| 92 |
| 93 void SendTouchEventImmediately(TouchEventWithLatencyInfo* touch, |
| 94 bool wait_for_ack); |
| 95 |
| 96 void AckCompletedEvents(); |
| 97 |
| 98 bool IsTimeoutRunningForTesting() const; |
| 99 const TouchEventWithLatencyInfo& GetLatestEventForTesting() const; |
| 100 size_t SizeForTesting() const; |
| 101 |
| 102 // Handles touch event forwarding and ack'ed event dispatch. |
| 103 TouchEventQueueClient* client_; |
| 104 |
| 105 // Whether the renderer has at least one touch handler. |
| 106 bool has_handlers_; |
| 107 |
| 108 // Whether any pointer in the touch sequence may have having a consumer. |
| 109 bool maybe_has_handler_for_current_sequence_; |
| 110 |
| 111 // Whether to allow any remaining touches for the current sequence. Note that |
| 112 // this is a stricter condition than an empty |touch_consumer_states_|, as it |
| 113 // also prevents forwarding of touchstart events for new pointers in the |
| 114 // current sequence. This is only used when the event is synthetically |
| 115 // cancelled after a touch timeout. |
| 116 bool drop_remaining_touches_in_sequence_; |
| 117 |
| 118 // Optional handler for timed-out touch event acks. |
| 119 std::unique_ptr<TouchTimeoutHandler> timeout_handler_; |
| 120 |
| 121 // Whether touch events should be sent as uncancelable or not. |
| 122 bool send_touch_events_async_; |
| 123 |
| 124 // Event is saved to compare pointer positions for new touchmove events. |
| 125 std::unique_ptr<blink::WebTouchEvent> last_sent_touchevent_; |
| 126 |
| 127 // Stores outstanding touches that have been sent to the renderer but have |
| 128 // not yet been ack'd by the renderer. The set is explicitly ordered based |
| 129 // on the unique touch event id. |
| 130 std::set<TouchEventWithLatencyInfoAndAckState> outstanding_touches_; |
| 131 |
| 132 DISALLOW_COPY_AND_ASSIGN(PassthroughTouchEventQueue); |
| 133 }; |
| 134 |
| 135 } // namespace content |
| 136 |
| 137 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_PASSTHROUGH_TOUCH_EVENT_QUEUE_H_ |
OLD | NEW |