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 "mojo/converters/blink/blink_input_events_type_converters.h" | 10 #include "mojo/converters/blink/blink_input_events_type_converters.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 void CompositorMusConnection::OnConnectionLostOnMainThread() { | 71 void CompositorMusConnection::OnConnectionLostOnMainThread() { |
72 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 72 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
73 RenderWidgetMusConnection* connection = | 73 RenderWidgetMusConnection* connection = |
74 RenderWidgetMusConnection::Get(routing_id_); | 74 RenderWidgetMusConnection::Get(routing_id_); |
75 if (!connection) | 75 if (!connection) |
76 return; | 76 return; |
77 connection->OnConnectionLost(); | 77 connection->OnConnectionLost(); |
78 } | 78 } |
79 | 79 |
80 void CompositorMusConnection::OnWindowInputEventOnMainThread( | 80 void CompositorMusConnection::OnWindowInputEventOnMainThread( |
81 std::unique_ptr<blink::WebInputEvent> web_event, | 81 ui::ScopedWebInputEvent web_event, |
82 const base::Callback<void(EventResult)>& ack) { | 82 const base::Callback<void(EventResult)>& ack) { |
83 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 83 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
84 RenderWidgetMusConnection* connection = | 84 RenderWidgetMusConnection* connection = |
85 RenderWidgetMusConnection::Get(routing_id_); | 85 RenderWidgetMusConnection::Get(routing_id_); |
86 if (!connection) { | 86 if (!connection) { |
87 ack.Run(EventResult::UNHANDLED); | 87 ack.Run(EventResult::UNHANDLED); |
88 return; | 88 return; |
89 } | 89 } |
90 connection->OnWindowInputEvent(std::move(web_event), ack); | 90 connection->OnWindowInputEvent(std::move(web_event), ack); |
91 } | 91 } |
(...skipping 26 matching lines...) Expand all Loading... | |
118 const ui::PointerEvent& event, | 118 const ui::PointerEvent& event, |
119 ui::Window* target) { | 119 ui::Window* target) { |
120 // Compositor does not use StartPointerWatcher(). | 120 // Compositor does not use StartPointerWatcher(). |
121 } | 121 } |
122 | 122 |
123 void CompositorMusConnection::OnWindowInputEvent( | 123 void CompositorMusConnection::OnWindowInputEvent( |
124 ui::Window* window, | 124 ui::Window* window, |
125 const ui::Event& event, | 125 const ui::Event& event, |
126 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 126 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
127 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 127 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
128 std::unique_ptr<blink::WebInputEvent> web_event( | 128 |
129 mojo::TypeConverter<std::unique_ptr<blink::WebInputEvent>, | 129 // Take ownership of the callback, indicating that we will handle it. |
130 ui::Event>::Convert(event)); | 130 std::unique_ptr<base::Callback<void(EventResult)>> callback = |
131 std::move(*ack_callback); | |
chongz
2016/08/23 04:35:24
Original implementation only takes ownership if we
| |
132 ui::ScopedWebInputEvent web_event = ui::WebInputEventTraits::Clone( | |
133 *mojo::TypeConverter<std::unique_ptr<blink::WebInputEvent>, | |
134 ui::Event>::Convert(event)); | |
131 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | 135 // TODO(sad): We probably need to plumb LatencyInfo through Mus. |
132 ui::LatencyInfo info; | 136 ui::LatencyInfo info; |
133 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | 137 input_handler_manager_->HandleInputEvent( |
134 routing_id_, web_event.get(), &info); | 138 routing_id_, std::move(web_event), info, |
139 base::Bind(&CompositorMusConnection::DidHandleWindowInputEvent, this, | |
140 base::Passed(&callback))); | |
141 } | |
142 | |
143 void CompositorMusConnection::DidHandleWindowInputEvent( | |
144 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback, | |
145 InputEventAckState ack_state, | |
146 ui::ScopedWebInputEvent web_event, | |
147 const ui::LatencyInfo& latency_info, | |
148 std::unique_ptr<ui::DidOverscrollParams>) { | |
135 // TODO(jonross): We probably need to ack the event based on the consumed | 149 // TODO(jonross): We probably need to ack the event based on the consumed |
136 // state. | 150 // state. |
137 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | 151 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) { |
152 // We took the ownership of the callback, so we need to send the ack, and | |
153 // mark the event as not consumed to preserve existing behavior. | |
154 ack_callback->Run(EventResult::UNHANDLED); | |
138 return; | 155 return; |
156 } | |
139 base::Callback<void(EventResult)> ack = | 157 base::Callback<void(EventResult)> ack = |
140 base::Bind(&::DoNothingWithEventResult); | 158 base::Bind(&::DoNothingWithEventResult); |
141 const bool send_ack = | 159 const bool send_ack = |
142 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); | 160 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); |
143 if (send_ack) { | 161 if (send_ack) { |
144 // Ultimately, this ACK needs to go back to the Mus client lib which is not | 162 // Ultimately, this ACK needs to go back to the Mus client lib which is not |
145 // thread-safe and lives on the compositor thread. For ACKs that are passed | 163 // thread-safe and lives on the compositor thread. For ACKs that are passed |
146 // to the main thread we pass them back to the compositor thread via | 164 // to the main thread we pass them back to the compositor thread via |
147 // OnWindowInputEventAckOnMainThread. | 165 // OnWindowInputEventAckOnMainThread. |
148 ack = | 166 ack = |
149 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, | 167 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, |
150 this, *ack_callback->get()); | 168 this, *ack_callback); |
151 ack_callback->reset(); | 169 } else { |
170 // We took the ownership of the callback, so we need to send the ack, and | |
171 // mark the event as not consumed to preserve existing behavior. | |
172 ack_callback->Run(EventResult::UNHANDLED); | |
152 } | 173 } |
174 ack_callback.reset(); | |
175 | |
153 main_task_runner_->PostTask( | 176 main_task_runner_->PostTask( |
154 FROM_HERE, | 177 FROM_HERE, |
155 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | 178 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
156 base::Passed(std::move(web_event)), ack)); | 179 base::Passed(&web_event), ack)); |
157 } | 180 } |
158 | 181 |
159 } // namespace content | 182 } // namespace content |
OLD | NEW |