Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: content/renderer/mus/compositor_mus_connection.cc

Issue 2265393002: Refactor compositor event handling path to be callback-based (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dtapuska's review 2, use WeakPtr, tweak comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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);
132 ui::ScopedWebInputEvent web_event = ui::WebInputEventTraits::Clone(
tdresser 2016/09/01 16:58:45 Why do we need to clone the event now?
chongz 2016/09/01 20:13:13 Sorry I misused Clone. Fixed.
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(
140 &CompositorMusConnection::DidHandleWindowInputEventAndOverscroll,
141 this, base::Passed(&callback)));
142 }
143
144 void CompositorMusConnection::DidHandleWindowInputEventAndOverscroll(
145 std::unique_ptr<base::Callback<void(EventResult)>> ack_callback,
146 InputEventAckState ack_state,
147 ui::ScopedWebInputEvent web_event,
148 const ui::LatencyInfo& latency_info,
149 std::unique_ptr<ui::DidOverscrollParams>) {
135 // TODO(jonross): We probably need to ack the event based on the consumed 150 // TODO(jonross): We probably need to ack the event based on the consumed
136 // state. 151 // state.
137 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) 152 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) {
153 // We took the ownership of the callback, so we need to send the ack, and
154 // mark the event as not consumed to preserve existing behavior.
155 ack_callback->Run(EventResult::UNHANDLED);
138 return; 156 return;
157 }
139 base::Callback<void(EventResult)> ack = 158 base::Callback<void(EventResult)> ack =
140 base::Bind(&::DoNothingWithEventResult); 159 base::Bind(&::DoNothingWithEventResult);
141 const bool send_ack = 160 const bool send_ack =
142 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); 161 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event);
143 if (send_ack) { 162 if (send_ack) {
144 // Ultimately, this ACK needs to go back to the Mus client lib which is not 163 // 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 164 // 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 165 // to the main thread we pass them back to the compositor thread via
147 // OnWindowInputEventAckOnMainThread. 166 // OnWindowInputEventAckOnMainThread.
148 ack = 167 ack =
149 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, 168 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread,
150 this, *ack_callback->get()); 169 this, *ack_callback);
151 ack_callback->reset(); 170 } else {
171 // We took the ownership of the callback, so we need to send the ack, and
172 // mark the event as not consumed to preserve existing behavior.
173 ack_callback->Run(EventResult::UNHANDLED);
152 } 174 }
175 ack_callback.reset();
176
153 main_task_runner_->PostTask( 177 main_task_runner_->PostTask(
154 FROM_HERE, 178 FROM_HERE,
155 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, 179 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this,
156 base::Passed(std::move(web_event)), ack)); 180 base::Passed(&web_event), ack));
tdresser 2016/09/01 16:58:45 It isn't clear to me why this changed from std::mo
chongz 2016/09/01 20:13:13 Changed back to |std::move|. There is no actual d
157 } 181 }
158 182
159 } // namespace content 183 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698