Chromium Code Reviews| 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" | |
| 11 #include "ui/events/blink/did_overscroll_params.h" | 10 #include "ui/events/blink/did_overscroll_params.h" |
| 11 #include "ui/events/blink/web_input_event.h" | |
| 12 #include "ui/events/blink/web_input_event_traits.h" | 12 #include "ui/events/blink/web_input_event_traits.h" |
| 13 #include "ui/events/latency_info.h" | 13 #include "ui/events/latency_info.h" |
| 14 #include "ui/events/mojo/event.mojom.h" | 14 #include "ui/events/mojo/event.mojom.h" |
| 15 | 15 |
| 16 using ui::mojom::EventResult; | 16 using ui::mojom::EventResult; |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 void DoNothingWithEventResult(EventResult result) {} | 20 void DoNothingWithEventResult(EventResult result) {} |
| 21 | 21 |
| 22 gfx::Point GetScreenLocationFromEvent(const ui::LocatedEvent& event) { | |
| 23 return event.root_location(); | |
| 24 } | |
| 25 | |
| 26 std::unique_ptr<blink::WebInputEvent> Convert(const ui::Event& event) { | |
| 27 if (event.IsMousePointerEvent()) { | |
| 28 const ui::MouseEvent mouse_event(*event.AsPointerEvent()); | |
| 29 blink::WebMouseEvent blink_event = ui::MakeWebMouseEvent( | |
| 30 mouse_event, base::Bind(&GetScreenLocationFromEvent)); | |
| 31 return base::WrapUnique(new blink::WebMouseEvent(blink_event)); | |
| 32 } else if (event.IsTouchPointerEvent()) { | |
| 33 blink::WebTouchEvent blink_event = ui::MakeWebTouchEvent( | |
| 34 *event.AsPointerEvent(), base::Bind(&GetScreenLocationFromEvent)); | |
| 35 return base::WrapUnique(new blink::WebTouchEvent(blink_event)); | |
| 36 } else if (event.IsMouseWheelEvent()) { | |
| 37 blink::WebMouseWheelEvent blink_event = ui::MakeWebMouseWheelEvent( | |
| 38 *event.AsMouseWheelEvent(), base::Bind(&GetScreenLocationFromEvent)); | |
| 39 return base::WrapUnique(new blink::WebMouseWheelEvent(blink_event)); | |
| 40 } else if (event.IsKeyEvent()) { | |
| 41 blink::WebKeyboardEvent blink_event = | |
| 42 ui::MakeWebKeyboardEvent(*event.AsKeyEvent()); | |
| 43 return base::WrapUnique(new blink::WebKeyboardEvent(blink_event)); | |
| 44 } else { | |
| 45 return nullptr; | |
| 46 } | |
| 47 } | |
| 48 | |
| 22 } // namespace | 49 } // namespace |
| 23 | 50 |
| 24 namespace content { | 51 namespace content { |
| 25 | 52 |
| 26 CompositorMusConnection::CompositorMusConnection( | 53 CompositorMusConnection::CompositorMusConnection( |
| 27 int routing_id, | 54 int routing_id, |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 55 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 29 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 56 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| 30 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, | 57 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, |
| 31 InputHandlerManager* input_handler_manager) | 58 InputHandlerManager* input_handler_manager) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 const ui::PointerEvent& event, | 145 const ui::PointerEvent& event, |
| 119 ui::Window* target) { | 146 ui::Window* target) { |
| 120 // Compositor does not use StartPointerWatcher(). | 147 // Compositor does not use StartPointerWatcher(). |
| 121 } | 148 } |
| 122 | 149 |
| 123 void CompositorMusConnection::OnWindowInputEvent( | 150 void CompositorMusConnection::OnWindowInputEvent( |
| 124 ui::Window* window, | 151 ui::Window* window, |
| 125 const ui::Event& event, | 152 const ui::Event& event, |
| 126 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 153 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
| 127 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 154 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 128 std::unique_ptr<blink::WebInputEvent> web_event( | 155 std::unique_ptr<blink::WebInputEvent> web_event(Convert(event)); |
|
sadrul
2016/08/24 18:05:36
Can the WebInputEvent be created on the stack inst
jonross
2016/08/24 21:42:04
The unique_ptr is used here to preserve and pass t
sadrul
2016/08/24 21:47:14
Copying should be OK, yeah.
jonross
2016/08/25 15:11:59
As discussed offline, differing object sizes led t
| |
| 129 mojo::TypeConverter<std::unique_ptr<blink::WebInputEvent>, | |
| 130 ui::Event>::Convert(event)); | |
| 131 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | 156 // TODO(sad): We probably need to plumb LatencyInfo through Mus. |
| 132 ui::LatencyInfo info; | 157 ui::LatencyInfo info; |
| 133 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | 158 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( |
| 134 routing_id_, web_event.get(), &info); | 159 routing_id_, web_event.get(), &info); |
| 135 // TODO(jonross): We probably need to ack the event based on the consumed | 160 // TODO(jonross): We probably need to ack the event based on the consumed |
| 136 // state. | 161 // state. |
| 137 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | 162 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) |
| 138 return; | 163 return; |
| 139 base::Callback<void(EventResult)> ack = | 164 base::Callback<void(EventResult)> ack = |
| 140 base::Bind(&::DoNothingWithEventResult); | 165 base::Bind(&::DoNothingWithEventResult); |
| 141 const bool send_ack = | 166 const bool send_ack = |
| 142 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); | 167 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); |
| 143 if (send_ack) { | 168 if (send_ack) { |
| 144 // Ultimately, this ACK needs to go back to the Mus client lib which is not | 169 // 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 | 170 // 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 | 171 // to the main thread we pass them back to the compositor thread via |
| 147 // OnWindowInputEventAckOnMainThread. | 172 // OnWindowInputEventAckOnMainThread. |
| 148 ack = | 173 ack = |
| 149 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, | 174 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, |
| 150 this, *ack_callback->get()); | 175 this, *ack_callback->get()); |
| 151 ack_callback->reset(); | 176 ack_callback->reset(); |
| 152 } | 177 } |
| 153 main_task_runner_->PostTask( | 178 main_task_runner_->PostTask( |
| 154 FROM_HERE, | 179 FROM_HERE, |
| 155 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | 180 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
| 156 base::Passed(std::move(web_event)), ack)); | 181 base::Passed(std::move(web_event)), ack)); |
| 157 } | 182 } |
| 158 | 183 |
| 159 } // namespace content | 184 } // namespace content |
| OLD | NEW |