| OLD | NEW |
| (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_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ | |
| 6 #define CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/scoped_vector.h" | |
| 13 #include "content/browser/renderer_host/input/browser_input_event.h" | |
| 14 #include "content/browser/renderer_host/input/input_queue.h" | |
| 15 #include "content/browser/renderer_host/input/input_queue_client.h" | |
| 16 #include "content/browser/renderer_host/input/input_router.h" | |
| 17 | |
| 18 namespace IPC { | |
| 19 class Sender; | |
| 20 } | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 class InputAckHandler; | |
| 25 class RenderProcessHost; | |
| 26 class RenderWidgetHostImpl; | |
| 27 | |
| 28 // Batches input events into EventPackets using a general input queue. Packets | |
| 29 // are sent the renderer on |Flush()|, called in response to flush requests. | |
| 30 class CONTENT_EXPORT BufferedInputRouter | |
| 31 : public NON_EXPORTED_BASE(BrowserInputEventClient), | |
| 32 public NON_EXPORTED_BASE(InputQueueClient), | |
| 33 public NON_EXPORTED_BASE(InputRouter) { | |
| 34 public: | |
| 35 // |sender|, |client| and |ack_handler| must outlive the BufferedInputRouter. | |
| 36 BufferedInputRouter(IPC::Sender* sender, | |
| 37 InputRouterClient* client, | |
| 38 InputAckHandler* ack_handler, | |
| 39 int routing_id); | |
| 40 virtual ~BufferedInputRouter(); | |
| 41 | |
| 42 // InputRouter | |
| 43 virtual void Flush() OVERRIDE; | |
| 44 virtual bool SendInput(scoped_ptr<IPC::Message> message) OVERRIDE; | |
| 45 | |
| 46 // Certain unhandled input event acks may create follow-up events, e.g., | |
| 47 // TouchEvent -> GestureEvent. If these follow-up events are sent to the | |
| 48 // router synchronously from the original event's |OnDispatched()| ack, they | |
| 49 // will be inserted into the current input flush stream. | |
| 50 virtual void SendMouseEvent( | |
| 51 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; | |
| 52 virtual void SendWheelEvent( | |
| 53 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE; | |
| 54 virtual void SendKeyboardEvent(const NativeWebKeyboardEvent& key_event, | |
| 55 const ui::LatencyInfo& latency_info) OVERRIDE; | |
| 56 virtual void SendGestureEvent( | |
| 57 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; | |
| 58 virtual void SendTouchEvent( | |
| 59 const TouchEventWithLatencyInfo& touch_event) OVERRIDE; | |
| 60 virtual void SendMouseEventImmediately( | |
| 61 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; | |
| 62 virtual void SendTouchEventImmediately( | |
| 63 const TouchEventWithLatencyInfo& touch_event) OVERRIDE; | |
| 64 virtual void SendGestureEventImmediately( | |
| 65 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; | |
| 66 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE; | |
| 67 virtual bool ShouldForwardTouchEvent() const OVERRIDE; | |
| 68 virtual bool ShouldForwardGestureEvent( | |
| 69 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE; | |
| 70 | |
| 71 // InputQueueClient | |
| 72 virtual void Deliver(const EventPacket& packet) OVERRIDE; | |
| 73 virtual void DidFinishFlush() OVERRIDE; | |
| 74 virtual void SetNeedsFlush() OVERRIDE; | |
| 75 | |
| 76 // BrowserInputEventClient | |
| 77 virtual void OnDispatched(const BrowserInputEvent& event, | |
| 78 InputEventDisposition disposition) OVERRIDE; | |
| 79 // Events delivered to the router within the scope of | |
| 80 // |OnDispatched()| will be added to |followup|. | |
| 81 virtual void OnDispatched(const BrowserInputEvent& event, | |
| 82 InputEventDisposition disposition, | |
| 83 ScopedVector<BrowserInputEvent>* followup) OVERRIDE; | |
| 84 | |
| 85 // IPC::Receiver | |
| 86 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 87 | |
| 88 protected: | |
| 89 void OnWebInputEventAck(int64 event_id, | |
| 90 const WebKit::WebInputEvent& web_event, | |
| 91 const ui::LatencyInfo& latency_info, | |
| 92 InputEventAckState acked_result, | |
| 93 bool ack_from_input_queue); | |
| 94 void OnEventPacketAck(int64 packet_id, | |
| 95 const InputEventDispositions& dispositions); | |
| 96 void OnHasTouchEventHandlers(bool has_handlers); | |
| 97 | |
| 98 // Returns the non-zero ID associated with the |InputEvent| added to the | |
| 99 // |input_queue_|. If the event was dropped or filtered, returns 0. | |
| 100 int64 QueueWebEvent(const WebKit::WebInputEvent& web_event, | |
| 101 const ui::LatencyInfo& latency_info, | |
| 102 bool is_key_shortcut); | |
| 103 // Used by |QueueWebEvent()|; returns true if an event was filtered and should | |
| 104 // not be added to the |input_queue_|. | |
| 105 bool FilterWebEvent(const WebKit::WebInputEvent& web_event, | |
| 106 const ui::LatencyInfo& latency_info); | |
| 107 | |
| 108 // Generates a monotonically increasing sequences of id's, starting with 1. | |
| 109 int64 NextInputID(); | |
| 110 | |
| 111 const InputQueue* input_queue() const { return input_queue_.get(); } | |
| 112 | |
| 113 private: | |
| 114 InputRouterClient* client_; | |
| 115 InputAckHandler* ack_handler_; | |
| 116 IPC::Sender* sender_; | |
| 117 int routing_id_; | |
| 118 | |
| 119 scoped_ptr<InputQueue> input_queue_; | |
| 120 | |
| 121 // TODO(jdduke): Remove when we can properly serialize NativeWebKeyboardEvent. | |
| 122 // Alternatively, attach WebInputEvents to InputEvents but don't serialize. | |
| 123 typedef std::map<int64, NativeWebKeyboardEvent> KeyMap; | |
| 124 KeyMap queued_key_map_; | |
| 125 | |
| 126 // Necessary for |ShouldForwardTouchEvent()|. | |
| 127 bool has_touch_handler_; | |
| 128 int queued_touch_count_; | |
| 129 | |
| 130 // This is non-NULL ONLY in the scope of OnInputEventAck(event, injector). | |
| 131 ScopedVector<BrowserInputEvent>* input_queue_override_; | |
| 132 | |
| 133 // Used to assign unique ID's to each InputEvent that is generated. | |
| 134 int64 next_input_id_; | |
| 135 | |
| 136 // 0 if there no in-flight EventPacket. | |
| 137 int64 in_flight_packet_id_; | |
| 138 | |
| 139 DISALLOW_COPY_AND_ASSIGN(BufferedInputRouter); | |
| 140 }; | |
| 141 | |
| 142 } // namespace content | |
| 143 | |
| 144 #endif // CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ | |
| OLD | NEW |