Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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/time/time.h" | |
| 13 #include "base/timer/timer.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(InputQueueClient), | |
| 32 public NON_EXPORTED_BASE(InputRouter) { | |
| 33 public: | |
| 34 BufferedInputRouter(IPC::Sender* sender, | |
| 35 InputRouterClient* client, | |
| 36 InputAckHandler* ack_handler, | |
| 37 int routing_id); | |
| 38 virtual ~BufferedInputRouter(); | |
| 39 | |
| 40 // InputRouter | |
| 41 virtual void Flush() OVERRIDE; | |
| 42 virtual bool SendInput(scoped_ptr<IPC::Message> message) OVERRIDE; | |
| 43 virtual void SendMouseEvent( | |
| 
 
aelias_OOO_until_Jul13
2013/08/15 00:52:15
There should be a detailed comment here explaining
 
jdduke (slow)
2013/08/15 23:22:26
Done.
 
 | |
| 44 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; | |
| 45 virtual void SendWheelEvent( | |
| 46 const MouseWheelEventWithLatencyInfo& wheel_event) OVERRIDE; | |
| 47 virtual void SendKeyboardEvent( | |
| 48 const NativeWebKeyboardEvent& key_event, | |
| 49 const ui::LatencyInfo& latency_info) OVERRIDE; | |
| 50 virtual void SendGestureEvent( | |
| 51 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; | |
| 52 virtual void SendTouchEvent( | |
| 53 const TouchEventWithLatencyInfo& touch_event) OVERRIDE; | |
| 54 virtual void SendMouseEventImmediately( | |
| 55 const MouseEventWithLatencyInfo& mouse_event) OVERRIDE; | |
| 56 virtual void SendTouchEventImmediately( | |
| 57 const TouchEventWithLatencyInfo& touch_event) OVERRIDE; | |
| 58 virtual void SendGestureEventImmediately( | |
| 59 const GestureEventWithLatencyInfo& gesture_event) OVERRIDE; | |
| 60 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const OVERRIDE; | |
| 61 virtual bool ShouldForwardTouchEvent() const OVERRIDE; | |
| 62 virtual bool ShouldForwardGestureEvent( | |
| 63 const GestureEventWithLatencyInfo& gesture_event) const OVERRIDE; | |
| 64 virtual bool HasQueuedGestureEvents() const OVERRIDE; | |
| 65 | |
| 66 // InputQueueClient | |
| 67 virtual void Deliver(const EventPacket& packet) OVERRIDE; | |
| 68 virtual void DidFlush() OVERRIDE; | |
| 69 virtual void SetNeedsFlush() OVERRIDE; | |
| 70 virtual std::vector<InputEvent> OnInputEventAck( | |
| 71 const InputEvent& acked_event) OVERRIDE; | |
| 72 | |
| 73 // IPC::Receiver | |
| 74 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | |
| 75 | |
| 76 protected: | |
| 77 void OnInputEventAck(int64 event_id, | |
| 78 const WebKit::WebInputEvent& web_event, | |
| 79 const ui::LatencyInfo& latency_info, | |
| 80 InputEventAckState acked_result, | |
| 81 bool ack_from_input_queue); | |
| 82 void OnEventPacketAck(const EventPacket& acked_packet); | |
| 83 void OnHasTouchEventHandlers(bool has_handlers); | |
| 84 | |
| 85 // Returns the non-zero ID associated with the |InputEvent| added to the | |
| 86 // |input_queue_|. If the event was dropped or filtered, returns 0. | |
| 87 int64 QueueWebEvent(const WebKit::WebInputEvent& web_event, | |
| 88 const ui::LatencyInfo& latency_info, | |
| 89 bool is_keyboard_shortcut, | |
| 90 bool has_followup); | |
| 91 // Used by |QueueWebEvent()|; returns true if an event was filtered and should | |
| 92 // not be added to the |input_queue_|. | |
| 93 bool FilterWebEvent(const WebKit::WebInputEvent& web_event, | |
| 94 const ui::LatencyInfo& latency_info); | |
| 95 | |
| 96 // Generates a monotonically increasing sequences of id's, starting with 1. | |
| 97 int64 NextInputID(); | |
| 98 | |
| 99 const InputQueue* input_queue() const { return input_queue_.get(); } | |
| 100 | |
| 101 private: | |
| 102 InputRouterClient* client_; | |
| 103 InputAckHandler* ack_handler_; | |
| 104 IPC::Sender* sender_; | |
| 105 int routing_id_; | |
| 106 | |
| 107 scoped_ptr<InputQueue> input_queue_; | |
| 108 | |
| 109 // TODO(jdduke): Remove when we can properly serialize NativeWebKeyboardEvent. | |
| 110 // Alternatively, attach WebInputEvents to InputEvents but don't serialize. | |
| 111 typedef std::map<int64, NativeWebKeyboardEvent> KeyMap; | |
| 112 KeyMap queued_key_map_; | |
| 113 | |
| 114 // Necessary for |HasQueuedGestureEvents()|. | |
| 115 int queued_gesture_count_; | |
| 116 | |
| 117 // Necessary for |ShouldForwardTouchEvent()|. | |
| 118 bool has_touch_handler_; | |
| 119 int queued_touch_count_; | |
| 120 | |
| 121 // This is non-NULL ONLY in the scope of OnInputEventAck(event, injector). | |
| 122 std::vector<InputEvent>* input_queue_override_; | |
| 123 | |
| 124 // Used to assign unique ID's to each InputEvent that is generated. | |
| 125 int64 next_input_id_; | |
| 126 | |
| 127 // 0 if there no in-flight EventPacket. | |
| 128 int64 in_flight_packet_id_; | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(BufferedInputRouter); | |
| 131 }; | |
| 132 | |
| 133 } // namespace content | |
| 134 | |
| 135 #endif // CONTENT_BROWSER_INPUT_RENDERER_HOST_BUFFERED_INPUT_ROUTER_H_ | |
| OLD | NEW |