OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ | 5 #ifndef CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ |
6 #define CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ | 6 #define CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <unordered_map> | 10 #include <unordered_map> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 namespace IPC { | 30 namespace IPC { |
31 class Listener; | 31 class Listener; |
32 class Sender; | 32 class Sender; |
33 } | 33 } |
34 | 34 |
35 // This class can be used to intercept InputMsg_HandleInputEvent messages | 35 // This class can be used to intercept InputMsg_HandleInputEvent messages |
36 // and have them be delivered to a target thread. Input events are filtered | 36 // and have them be delivered to a target thread. Input events are filtered |
37 // based on routing_id (see AddRoute and RemoveRoute). | 37 // based on routing_id (see AddRoute and RemoveRoute). |
38 // | 38 // |
39 // The user of this class provides an instance of InputEventFilter::Handler, | 39 // The user of this class provides an instance of InputHandlerManager via |
40 // which will be passed WebInputEvents on the target thread. | 40 // |SetInputHandlerManager|. The InputHandlerManager's |HandleInputEvent| |
| 41 // will be called on the target thread to process the WebInputEvents. |
41 // | 42 // |
42 | 43 |
43 namespace content { | 44 namespace content { |
44 | 45 |
45 class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient, | 46 class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient, |
46 public IPC::MessageFilter, | 47 public IPC::MessageFilter, |
47 public MainThreadEventQueueClient { | 48 public MainThreadEventQueueClient { |
48 public: | 49 public: |
49 InputEventFilter( | 50 InputEventFilter( |
50 const base::Callback<void(const IPC::Message&)>& main_listener, | 51 const base::Callback<void(const IPC::Message&)>& main_listener, |
51 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 52 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
52 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); | 53 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); |
53 | 54 |
54 // The |handler| is invoked on the thread associated with |target_loop| to | 55 // The |handler| is invoked on the thread associated with |target_loop| to |
55 // handle input events matching the filtered routes. | 56 // handle input events matching the filtered routes. |
56 // | 57 // |
57 // If INPUT_EVENT_ACK_STATE_NOT_CONSUMED is returned by the handler, | 58 // If INPUT_EVENT_ACK_STATE_NOT_CONSUMED is returned by the handler, |
58 // the original InputMsg_HandleInputEvent message will be delivered to | 59 // the original InputMsg_HandleInputEvent message will be delivered to |
59 // |main_listener| on the main thread. (The "main thread" in this context is | 60 // |main_listener| on the main thread. (The "main thread" in this context is |
60 // the thread where the InputEventFilter was constructed.) The responsibility | 61 // the thread where the InputEventFilter was constructed.) The responsibility |
61 // is left to the eventual handler to deliver the corresponding | 62 // is left to the eventual handler to deliver the corresponding |
62 // InputHostMsg_HandleInputEvent_ACK. | 63 // InputHostMsg_HandleInputEvent_ACK. |
63 // | 64 // |
64 void SetBoundHandler(const Handler& handler) override; | 65 void SetInputHandlerManager(InputHandlerManager*) override; |
65 void RegisterRoutingID(int routing_id) override; | 66 void RegisterRoutingID(int routing_id) override; |
66 void UnregisterRoutingID(int routing_id) override; | 67 void UnregisterRoutingID(int routing_id) override; |
67 void DidOverscroll(int routing_id, | 68 void DidOverscroll(int routing_id, |
68 const ui::DidOverscrollParams& params) override; | 69 const ui::DidOverscrollParams& params) override; |
69 void DidStartFlinging(int routing_id) override; | 70 void DidStartFlinging(int routing_id) override; |
70 void DidStopFlinging(int routing_id) override; | 71 void DidStopFlinging(int routing_id) override; |
71 void NotifyInputEventHandled(int routing_id, | 72 void NotifyInputEventHandled(int routing_id, |
72 blink::WebInputEvent::Type type, | 73 blink::WebInputEvent::Type type, |
73 InputEventAckState ack_result) override; | 74 InputEventAckState ack_result) override; |
| 75 void ProcessRafAlignedInput(int routing_id) override; |
74 | 76 |
75 // IPC::MessageFilter methods: | 77 // IPC::MessageFilter methods: |
76 void OnFilterAdded(IPC::Sender* sender) override; | 78 void OnFilterAdded(IPC::Sender* sender) override; |
77 void OnFilterRemoved() override; | 79 void OnFilterRemoved() override; |
78 void OnChannelClosing() override; | 80 void OnChannelClosing() override; |
79 bool OnMessageReceived(const IPC::Message& message) override; | 81 bool OnMessageReceived(const IPC::Message& message) override; |
80 | 82 |
81 // MainThreadEventQueueClient methods: | 83 // MainThreadEventQueueClient methods: |
82 void HandleEventOnMainThread(int routing_id, | 84 void HandleEventOnMainThread(int routing_id, |
83 const blink::WebInputEvent* event, | 85 const blink::WebInputEvent* event, |
84 const ui::LatencyInfo& latency, | 86 const ui::LatencyInfo& latency, |
85 InputEventDispatchType dispatch_type) override; | 87 InputEventDispatchType dispatch_type) override; |
86 // Send an InputEventAck IPC message. |touch_event_id| represents | 88 // Send an InputEventAck IPC message. |touch_event_id| represents |
87 // the unique event id for the original WebTouchEvent and should | 89 // the unique event id for the original WebTouchEvent and should |
88 // be 0 if otherwise. See WebInputEventTraits::GetUniqueTouchEventId. | 90 // be 0 if otherwise. See WebInputEventTraits::GetUniqueTouchEventId. |
89 void SendInputEventAck(int routing_id, | 91 void SendInputEventAck(int routing_id, |
90 blink::WebInputEvent::Type type, | 92 blink::WebInputEvent::Type type, |
91 InputEventAckState ack_result, | 93 InputEventAckState ack_result, |
92 uint32_t touch_event_id) override; | 94 uint32_t touch_event_id) override; |
93 | 95 |
| 96 void NeedsMainFrame(int routing_id) override; |
| 97 |
94 private: | 98 private: |
95 ~InputEventFilter() override; | 99 ~InputEventFilter() override; |
96 | 100 |
97 void ForwardToHandler(const IPC::Message& message); | 101 void ForwardToHandler(const IPC::Message& message); |
98 void SendMessage(std::unique_ptr<IPC::Message> message); | 102 void SendMessage(std::unique_ptr<IPC::Message> message); |
99 void SendMessageOnIOThread(std::unique_ptr<IPC::Message> message); | 103 void SendMessageOnIOThread(std::unique_ptr<IPC::Message> message); |
100 void SetIsFlingingInMainThreadEventQueue(int routing_id, bool is_flinging); | 104 void SetIsFlingingInMainThreadEventQueue(int routing_id, bool is_flinging); |
101 | 105 |
102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 106 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
103 base::Callback<void(const IPC::Message&)> main_listener_; | 107 base::Callback<void(const IPC::Message&)> main_listener_; |
104 | 108 |
105 // The sender_ only gets invoked on the thread corresponding to io_loop_. | 109 // The sender_ only gets invoked on the thread corresponding to io_loop_. |
106 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 110 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
107 IPC::Sender* sender_; | 111 IPC::Sender* sender_; |
108 | 112 |
109 // The handler_ only gets Run on the thread corresponding to target_loop_. | 113 // The |input_handler_manager_| should outlive this class and |
| 114 // should only be called back on the |target_task_runner_|. |
110 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; | 115 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; |
111 Handler handler_; | 116 InputHandlerManager* input_handler_manager_; |
112 | 117 |
113 // Protects access to routes_. | 118 // Protects access to routes_. |
114 base::Lock routes_lock_; | 119 base::Lock routes_lock_; |
115 | 120 |
116 // Indicates the routing_ids for which input events should be filtered. | 121 // Indicates the routing_ids for which input events should be filtered. |
117 std::set<int> routes_; | 122 std::set<int> routes_; |
118 | 123 |
119 using RouteQueueMap = | 124 using RouteQueueMap = |
120 std::unordered_map<int, scoped_refptr<MainThreadEventQueue>>; | 125 std::unordered_map<int, scoped_refptr<MainThreadEventQueue>>; |
121 RouteQueueMap route_queues_; | 126 RouteQueueMap route_queues_; |
122 | 127 |
123 // Used to intercept overscroll notifications while an event is being | 128 // Used to intercept overscroll notifications while an event is being |
124 // dispatched. If the event causes overscroll, the overscroll metadata can be | 129 // dispatched. If the event causes overscroll, the overscroll metadata can be |
125 // bundled in the event ack, saving an IPC. Note that we must continue | 130 // bundled in the event ack, saving an IPC. Note that we must continue |
126 // supporting overscroll IPC notifications due to fling animation updates. | 131 // supporting overscroll IPC notifications due to fling animation updates. |
127 std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_; | 132 std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_; |
128 blink::scheduler::RendererScheduler* renderer_scheduler_; | 133 blink::scheduler::RendererScheduler* renderer_scheduler_; |
129 }; | 134 }; |
130 | 135 |
131 } // namespace content | 136 } // namespace content |
132 | 137 |
133 #endif // CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ | 138 #endif // CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ |
OLD | NEW |