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 InputEventFilter::Handler, |
tdresser
2016/08/24 13:42:59
Update comment.
| |
40 // which will be passed WebInputEvents on the target thread. | 40 // which will be passed WebInputEvents on the target thread. |
41 // | 41 // |
42 | 42 |
43 namespace content { | 43 namespace content { |
44 | 44 |
45 class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient, | 45 class CONTENT_EXPORT InputEventFilter : public InputHandlerManagerClient, |
46 public IPC::MessageFilter, | 46 public IPC::MessageFilter, |
47 public MainThreadEventQueueClient { | 47 public MainThreadEventQueueClient { |
48 public: | 48 public: |
49 InputEventFilter( | 49 InputEventFilter( |
50 const base::Callback<void(const IPC::Message&)>& main_listener, | 50 const base::Callback<void(const IPC::Message&)>& main_listener, |
51 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 51 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
52 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); | 52 const scoped_refptr<base::SingleThreadTaskRunner>& target_task_runner); |
53 | 53 |
54 // The |handler| is invoked on the thread associated with |target_loop| to | 54 // The |handler| is invoked on the thread associated with |target_loop| to |
55 // handle input events matching the filtered routes. | 55 // handle input events matching the filtered routes. |
56 // | 56 // |
57 // If INPUT_EVENT_ACK_STATE_NOT_CONSUMED is returned by the handler, | 57 // If INPUT_EVENT_ACK_STATE_NOT_CONSUMED is returned by the handler, |
58 // the original InputMsg_HandleInputEvent message will be delivered to | 58 // the original InputMsg_HandleInputEvent message will be delivered to |
59 // |main_listener| on the main thread. (The "main thread" in this context is | 59 // |main_listener| on the main thread. (The "main thread" in this context is |
60 // the thread where the InputEventFilter was constructed.) The responsibility | 60 // the thread where the InputEventFilter was constructed.) The responsibility |
61 // is left to the eventual handler to deliver the corresponding | 61 // is left to the eventual handler to deliver the corresponding |
62 // InputHostMsg_HandleInputEvent_ACK. | 62 // InputHostMsg_HandleInputEvent_ACK. |
63 // | 63 // |
64 void SetBoundHandler(const Handler& handler) override; | 64 void SetInputHandlerManager(InputHandlerManager*) override; |
65 void RegisterRoutingID(int routing_id) override; | 65 void RegisterRoutingID(int routing_id) override; |
66 void UnregisterRoutingID(int routing_id) override; | 66 void UnregisterRoutingID(int routing_id) override; |
67 void DidOverscroll(int routing_id, | 67 void DidOverscroll(int routing_id, |
68 const ui::DidOverscrollParams& params) override; | 68 const ui::DidOverscrollParams& params) override; |
69 void DidStartFlinging(int routing_id) override; | 69 void DidStartFlinging(int routing_id) override; |
70 void DidStopFlinging(int routing_id) override; | 70 void DidStopFlinging(int routing_id) override; |
71 void NotifyInputEventHandled(int routing_id, | 71 void NotifyInputEventHandled(int routing_id, |
72 blink::WebInputEvent::Type type, | 72 blink::WebInputEvent::Type type, |
73 InputEventAckState ack_result) override; | 73 InputEventAckState ack_result) override; |
74 void ProcessRafAlignedInput(int routing_id) override; | |
74 | 75 |
75 // IPC::MessageFilter methods: | 76 // IPC::MessageFilter methods: |
76 void OnFilterAdded(IPC::Sender* sender) override; | 77 void OnFilterAdded(IPC::Sender* sender) override; |
77 void OnFilterRemoved() override; | 78 void OnFilterRemoved() override; |
78 void OnChannelClosing() override; | 79 void OnChannelClosing() override; |
79 bool OnMessageReceived(const IPC::Message& message) override; | 80 bool OnMessageReceived(const IPC::Message& message) override; |
80 | 81 |
81 // MainThreadEventQueueClient methods: | 82 // MainThreadEventQueueClient methods: |
82 void HandleEventOnMainThread(int routing_id, | 83 void HandleEventOnMainThread(int routing_id, |
83 const blink::WebInputEvent* event, | 84 const blink::WebInputEvent* event, |
84 const ui::LatencyInfo& latency, | 85 const ui::LatencyInfo& latency, |
85 InputEventDispatchType dispatch_type) override; | 86 InputEventDispatchType dispatch_type) override; |
86 // Send an InputEventAck IPC message. |touch_event_id| represents | 87 // Send an InputEventAck IPC message. |touch_event_id| represents |
87 // the unique event id for the original WebTouchEvent and should | 88 // the unique event id for the original WebTouchEvent and should |
88 // be 0 if otherwise. See WebInputEventTraits::GetUniqueTouchEventId. | 89 // be 0 if otherwise. See WebInputEventTraits::GetUniqueTouchEventId. |
89 void SendInputEventAck(int routing_id, | 90 void SendInputEventAck(int routing_id, |
90 blink::WebInputEvent::Type type, | 91 blink::WebInputEvent::Type type, |
91 InputEventAckState ack_result, | 92 InputEventAckState ack_result, |
92 uint32_t touch_event_id) override; | 93 uint32_t touch_event_id) override; |
93 | 94 |
95 void NeedsMainFrame(int routing_id) override; | |
96 | |
94 private: | 97 private: |
95 ~InputEventFilter() override; | 98 ~InputEventFilter() override; |
96 | 99 |
97 void ForwardToHandler(const IPC::Message& message); | 100 void ForwardToHandler(const IPC::Message& message); |
98 void SendMessage(std::unique_ptr<IPC::Message> message); | 101 void SendMessage(std::unique_ptr<IPC::Message> message); |
99 void SendMessageOnIOThread(std::unique_ptr<IPC::Message> message); | 102 void SendMessageOnIOThread(std::unique_ptr<IPC::Message> message); |
100 void SetIsFlingingInMainThreadEventQueue(int routing_id, bool is_flinging); | 103 void SetIsFlingingInMainThreadEventQueue(int routing_id, bool is_flinging); |
101 | 104 |
102 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 105 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
103 base::Callback<void(const IPC::Message&)> main_listener_; | 106 base::Callback<void(const IPC::Message&)> main_listener_; |
104 | 107 |
105 // The sender_ only gets invoked on the thread corresponding to io_loop_. | 108 // The sender_ only gets invoked on the thread corresponding to io_loop_. |
106 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
107 IPC::Sender* sender_; | 110 IPC::Sender* sender_; |
108 | 111 |
109 // The handler_ only gets Run on the thread corresponding to target_loop_. | 112 // The handler_ only gets Run on the thread corresponding to target_loop_. |
tdresser
2016/08/24 13:42:59
Update comment.
dtapuska
2016/08/24 17:10:06
done
| |
110 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; | 113 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner_; |
111 Handler handler_; | 114 InputHandlerManager* input_handler_manager_; |
tdresser
2016/08/24 13:42:59
Add a comment about lifetime of the input_handler_
dtapuska
2016/08/24 17:10:06
done
| |
112 | 115 |
113 // Protects access to routes_. | 116 // Protects access to routes_. |
114 base::Lock routes_lock_; | 117 base::Lock routes_lock_; |
115 | 118 |
116 // Indicates the routing_ids for which input events should be filtered. | 119 // Indicates the routing_ids for which input events should be filtered. |
117 std::set<int> routes_; | 120 std::set<int> routes_; |
118 | 121 |
119 using RouteQueueMap = | 122 using RouteQueueMap = |
120 std::unordered_map<int, scoped_refptr<MainThreadEventQueue>>; | 123 std::unordered_map<int, scoped_refptr<MainThreadEventQueue>>; |
121 RouteQueueMap route_queues_; | 124 RouteQueueMap route_queues_; |
122 | 125 |
123 // Used to intercept overscroll notifications while an event is being | 126 // Used to intercept overscroll notifications while an event is being |
124 // dispatched. If the event causes overscroll, the overscroll metadata can be | 127 // 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 | 128 // bundled in the event ack, saving an IPC. Note that we must continue |
126 // supporting overscroll IPC notifications due to fling animation updates. | 129 // supporting overscroll IPC notifications due to fling animation updates. |
127 std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_; | 130 std::unique_ptr<ui::DidOverscrollParams>* current_overscroll_params_; |
128 blink::scheduler::RendererScheduler* renderer_scheduler_; | 131 blink::scheduler::RendererScheduler* renderer_scheduler_; |
129 }; | 132 }; |
130 | 133 |
131 } // namespace content | 134 } // namespace content |
132 | 135 |
133 #endif // CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ | 136 #endif // CONTENT_RENDERER_INPUT_INPUT_EVENT_FILTER_H_ |
OLD | NEW |