OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "content/renderer/mus/compositor_mus_connection.h" | 5 #include "content/renderer/mus/compositor_mus_connection.h" |
6 | 6 |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "content/renderer/input/input_handler_manager.h" | 8 #include "content/renderer/input/input_handler_manager.h" |
9 #include "content/renderer/mus/render_widget_mus_connection.h" | 9 #include "content/renderer/mus/render_widget_mus_connection.h" |
10 #include "ui/events/blink/blink_event_util.h" | 10 #include "ui/events/blink/blink_event_util.h" |
11 #include "ui/events/blink/did_overscroll_params.h" | |
12 #include "ui/events/blink/web_input_event.h" | 11 #include "ui/events/blink/web_input_event.h" |
13 #include "ui/events/blink/web_input_event_traits.h" | 12 #include "ui/events/blink/web_input_event_traits.h" |
14 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
15 #include "ui/events/mojo/event.mojom.h" | 14 #include "ui/events/mojo/event.mojom.h" |
16 | 15 |
17 using ui::mojom::EventResult; | 16 using ui::mojom::EventResult; |
18 | 17 |
19 namespace { | 18 namespace { |
20 | 19 |
21 void DoNothingWithEventResult(EventResult result) {} | 20 void DoNothingWithEventResult(EventResult result) {} |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void CompositorMusConnection::OnConnectionLostOnMainThread() { | 83 void CompositorMusConnection::OnConnectionLostOnMainThread() { |
85 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 84 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
86 RenderWidgetMusConnection* connection = | 85 RenderWidgetMusConnection* connection = |
87 RenderWidgetMusConnection::Get(routing_id_); | 86 RenderWidgetMusConnection::Get(routing_id_); |
88 if (!connection) | 87 if (!connection) |
89 return; | 88 return; |
90 connection->OnConnectionLost(); | 89 connection->OnConnectionLost(); |
91 } | 90 } |
92 | 91 |
93 void CompositorMusConnection::OnWindowInputEventOnMainThread( | 92 void CompositorMusConnection::OnWindowInputEventOnMainThread( |
94 std::unique_ptr<blink::WebInputEvent> web_event, | 93 ui::ScopedWebInputEvent web_event, |
95 const base::Callback<void(EventResult)>& ack) { | 94 const base::Callback<void(EventResult)>& ack) { |
96 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 95 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
97 RenderWidgetMusConnection* connection = | 96 RenderWidgetMusConnection* connection = |
98 RenderWidgetMusConnection::Get(routing_id_); | 97 RenderWidgetMusConnection::Get(routing_id_); |
99 if (!connection) { | 98 if (!connection) { |
100 ack.Run(EventResult::UNHANDLED); | 99 ack.Run(EventResult::UNHANDLED); |
101 return; | 100 return; |
102 } | 101 } |
103 connection->OnWindowInputEvent(std::move(web_event), ack); | 102 connection->OnWindowInputEvent(std::move(web_event), ack); |
104 } | 103 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 const ui::PointerEvent& event, | 169 const ui::PointerEvent& event, |
171 ui::Window* target) { | 170 ui::Window* target) { |
172 // Compositor does not use StartPointerWatcher(). | 171 // Compositor does not use StartPointerWatcher(). |
173 } | 172 } |
174 | 173 |
175 void CompositorMusConnection::OnWindowInputEvent( | 174 void CompositorMusConnection::OnWindowInputEvent( |
176 ui::Window* window, | 175 ui::Window* window, |
177 const ui::Event& event, | 176 const ui::Event& event, |
178 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 177 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
179 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 178 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
180 std::unique_ptr<blink::WebInputEvent> web_event(Convert(event)); | 179 |
| 180 // Take ownership of the callback, indicating that we will handle it. |
| 181 std::unique_ptr<base::Callback<void(EventResult)>> callback = |
| 182 std::move(*ack_callback); |
| 183 ui::ScopedWebInputEvent web_event(Convert(event).release()); |
181 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | 184 // TODO(sad): We probably need to plumb LatencyInfo through Mus. |
182 ui::LatencyInfo info; | 185 ui::LatencyInfo info; |
183 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | 186 input_handler_manager_->HandleInputEvent( |
184 routing_id_, web_event.get(), &info); | 187 routing_id_, std::move(web_event), info, |
| 188 base::Bind( |
| 189 &CompositorMusConnection::DidHandleWindowInputEventAndOverscroll, |
| 190 this, base::Passed(std::move(callback)))); |
| 191 } |
| 192 |
| 193 void CompositorMusConnection::DidHandleWindowInputEventAndOverscroll( |
| 194 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback, |
| 195 InputEventAckState ack_state, |
| 196 ui::ScopedWebInputEvent web_event, |
| 197 const ui::LatencyInfo& latency_info, |
| 198 std::unique_ptr<ui::DidOverscrollParams> overscroll_params) { |
185 // TODO(jonross): We probably need to ack the event based on the consumed | 199 // TODO(jonross): We probably need to ack the event based on the consumed |
186 // state. | 200 // state. |
187 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | 201 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) { |
| 202 // We took the ownership of the callback, so we need to send the ack, and |
| 203 // mark the event as not consumed to preserve existing behavior. |
| 204 ack_callback->Run(EventResult::UNHANDLED); |
188 return; | 205 return; |
| 206 } |
189 base::Callback<void(EventResult)> ack = | 207 base::Callback<void(EventResult)> ack = |
190 base::Bind(&::DoNothingWithEventResult); | 208 base::Bind(&::DoNothingWithEventResult); |
191 const bool send_ack = | 209 const bool send_ack = |
192 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); | 210 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); |
193 if (send_ack) { | 211 if (send_ack) { |
194 // Ultimately, this ACK needs to go back to the Mus client lib which is not | 212 // Ultimately, this ACK needs to go back to the Mus client lib which is not |
195 // thread-safe and lives on the compositor thread. For ACKs that are passed | 213 // thread-safe and lives on the compositor thread. For ACKs that are passed |
196 // to the main thread we pass them back to the compositor thread via | 214 // to the main thread we pass them back to the compositor thread via |
197 // OnWindowInputEventAckOnMainThread. | 215 // OnWindowInputEventAckOnMainThread. |
198 ack = | 216 ack = |
199 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, | 217 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, |
200 this, *ack_callback->get()); | 218 this, *ack_callback); |
201 ack_callback->reset(); | 219 } else { |
| 220 // We took the ownership of the callback, so we need to send the ack, and |
| 221 // mark the event as not consumed to preserve existing behavior. |
| 222 ack_callback->Run(EventResult::UNHANDLED); |
202 } | 223 } |
| 224 ack_callback.reset(); |
| 225 |
203 main_task_runner_->PostTask( | 226 main_task_runner_->PostTask( |
204 FROM_HERE, | 227 FROM_HERE, |
205 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | 228 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
206 base::Passed(std::move(web_event)), ack)); | 229 base::Passed(std::move(web_event)), ack)); |
207 } | 230 } |
208 | 231 |
209 } // namespace content | 232 } // namespace content |
OLD | NEW |