| 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 "ui/events/blink/blink_event_util.h" |
| 11 #include "ui/events/blink/did_overscroll_params.h" | 11 #include "ui/events/blink/did_overscroll_params.h" |
| 12 #include "ui/events/blink/web_input_event.h" |
| 12 #include "ui/events/blink/web_input_event_traits.h" | 13 #include "ui/events/blink/web_input_event_traits.h" |
| 13 #include "ui/events/latency_info.h" | 14 #include "ui/events/latency_info.h" |
| 14 #include "ui/events/mojo/event.mojom.h" | 15 #include "ui/events/mojo/event.mojom.h" |
| 15 | 16 |
| 16 using ui::mojom::EventResult; | 17 using ui::mojom::EventResult; |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 void DoNothingWithEventResult(EventResult result) {} | 21 void DoNothingWithEventResult(EventResult result) {} |
| 21 | 22 |
| 23 gfx::Point GetScreenLocationFromEvent(const ui::LocatedEvent& event) { |
| 24 return event.root_location(); |
| 25 } |
| 26 |
| 22 } // namespace | 27 } // namespace |
| 23 | 28 |
| 24 namespace content { | 29 namespace content { |
| 25 | 30 |
| 26 CompositorMusConnection::CompositorMusConnection( | 31 CompositorMusConnection::CompositorMusConnection( |
| 27 int routing_id, | 32 int routing_id, |
| 28 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, | 33 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, |
| 29 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 34 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| 30 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, | 35 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request, |
| 31 InputHandlerManager* input_handler_manager) | 36 InputHandlerManager* input_handler_manager) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 connection->OnWindowInputEvent(std::move(web_event), ack); | 95 connection->OnWindowInputEvent(std::move(web_event), ack); |
| 91 } | 96 } |
| 92 | 97 |
| 93 void CompositorMusConnection::OnWindowInputEventAckOnMainThread( | 98 void CompositorMusConnection::OnWindowInputEventAckOnMainThread( |
| 94 const base::Callback<void(EventResult)>& ack, | 99 const base::Callback<void(EventResult)>& ack, |
| 95 EventResult result) { | 100 EventResult result) { |
| 96 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 101 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 97 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(ack, result)); | 102 compositor_task_runner_->PostTask(FROM_HERE, base::Bind(ack, result)); |
| 98 } | 103 } |
| 99 | 104 |
| 105 std::unique_ptr<blink::WebInputEvent> CompositorMusConnection::Convert( |
| 106 const ui::Event& event) { |
| 107 if (event.IsMousePointerEvent()) { |
| 108 const ui::MouseEvent mouse_event(*event.AsPointerEvent()); |
| 109 blink::WebMouseEvent blink_event = ui::MakeWebMouseEvent( |
| 110 mouse_event, base::Bind(&GetScreenLocationFromEvent)); |
| 111 return base::MakeUnique<blink::WebMouseEvent>(blink_event); |
| 112 } else if (event.IsTouchPointerEvent()) { |
| 113 ui::TouchEvent touch_event(*event.AsPointerEvent()); |
| 114 pointer_state_.OnTouch(touch_event); |
| 115 blink::WebTouchEvent blink_event = ui::CreateWebTouchEventFromMotionEvent( |
| 116 pointer_state_, touch_event.may_cause_scrolling()); |
| 117 pointer_state_.CleanupRemovedTouchPoints(touch_event); |
| 118 return base::MakeUnique<blink::WebTouchEvent>(blink_event); |
| 119 } else if (event.IsMouseWheelEvent()) { |
| 120 blink::WebMouseWheelEvent blink_event = ui::MakeWebMouseWheelEvent( |
| 121 *event.AsMouseWheelEvent(), base::Bind(&GetScreenLocationFromEvent)); |
| 122 return base::MakeUnique<blink::WebMouseWheelEvent>(blink_event); |
| 123 } else if (event.IsKeyEvent()) { |
| 124 blink::WebKeyboardEvent blink_event = |
| 125 ui::MakeWebKeyboardEvent(*event.AsKeyEvent()); |
| 126 return base::MakeUnique<blink::WebKeyboardEvent>(blink_event); |
| 127 } |
| 128 return nullptr; |
| 129 } |
| 130 |
| 100 void CompositorMusConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { | 131 void CompositorMusConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { |
| 101 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 132 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 102 main_task_runner_->PostTask( | 133 main_task_runner_->PostTask( |
| 103 FROM_HERE, | 134 FROM_HERE, |
| 104 base::Bind(&CompositorMusConnection::OnConnectionLostOnMainThread, this)); | 135 base::Bind(&CompositorMusConnection::OnConnectionLostOnMainThread, this)); |
| 105 } | 136 } |
| 106 | 137 |
| 107 void CompositorMusConnection::OnEmbed(ui::Window* root) { | 138 void CompositorMusConnection::OnEmbed(ui::Window* root) { |
| 108 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 139 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 109 root_ = root; | 140 root_ = root; |
| 110 root_->set_input_event_handler(this); | 141 root_->set_input_event_handler(this); |
| 111 if (window_surface_binding_) { | 142 if (window_surface_binding_) { |
| 112 root->AttachSurface(ui::mojom::SurfaceType::DEFAULT, | 143 root->AttachSurface(ui::mojom::SurfaceType::DEFAULT, |
| 113 std::move(window_surface_binding_)); | 144 std::move(window_surface_binding_)); |
| 114 } | 145 } |
| 115 } | 146 } |
| 116 | 147 |
| 117 void CompositorMusConnection::OnPointerEventObserved( | 148 void CompositorMusConnection::OnPointerEventObserved( |
| 118 const ui::PointerEvent& event, | 149 const ui::PointerEvent& event, |
| 119 ui::Window* target) { | 150 ui::Window* target) { |
| 120 // Compositor does not use StartPointerWatcher(). | 151 // Compositor does not use StartPointerWatcher(). |
| 121 } | 152 } |
| 122 | 153 |
| 123 void CompositorMusConnection::OnWindowInputEvent( | 154 void CompositorMusConnection::OnWindowInputEvent( |
| 124 ui::Window* window, | 155 ui::Window* window, |
| 125 const ui::Event& event, | 156 const ui::Event& event, |
| 126 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { | 157 std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) { |
| 127 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 158 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
| 128 std::unique_ptr<blink::WebInputEvent> web_event( | 159 std::unique_ptr<blink::WebInputEvent> web_event(Convert(event)); |
| 129 mojo::TypeConverter<std::unique_ptr<blink::WebInputEvent>, | |
| 130 ui::Event>::Convert(event)); | |
| 131 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | 160 // TODO(sad): We probably need to plumb LatencyInfo through Mus. |
| 132 ui::LatencyInfo info; | 161 ui::LatencyInfo info; |
| 133 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | 162 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( |
| 134 routing_id_, web_event.get(), &info); | 163 routing_id_, web_event.get(), &info); |
| 135 // TODO(jonross): We probably need to ack the event based on the consumed | 164 // TODO(jonross): We probably need to ack the event based on the consumed |
| 136 // state. | 165 // state. |
| 137 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | 166 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) |
| 138 return; | 167 return; |
| 139 base::Callback<void(EventResult)> ack = | 168 base::Callback<void(EventResult)> ack = |
| 140 base::Bind(&::DoNothingWithEventResult); | 169 base::Bind(&::DoNothingWithEventResult); |
| 141 const bool send_ack = | 170 const bool send_ack = |
| 142 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); | 171 ui::WebInputEventTraits::ShouldBlockEventStream(*web_event); |
| 143 if (send_ack) { | 172 if (send_ack) { |
| 144 // Ultimately, this ACK needs to go back to the Mus client lib which is not | 173 // 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 | 174 // 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 | 175 // to the main thread we pass them back to the compositor thread via |
| 147 // OnWindowInputEventAckOnMainThread. | 176 // OnWindowInputEventAckOnMainThread. |
| 148 ack = | 177 ack = |
| 149 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, | 178 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, |
| 150 this, *ack_callback->get()); | 179 this, *ack_callback->get()); |
| 151 ack_callback->reset(); | 180 ack_callback->reset(); |
| 152 } | 181 } |
| 153 main_task_runner_->PostTask( | 182 main_task_runner_->PostTask( |
| 154 FROM_HERE, | 183 FROM_HERE, |
| 155 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | 184 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
| 156 base::Passed(std::move(web_event)), ack)); | 185 base::Passed(std::move(web_event)), ack)); |
| 157 } | 186 } |
| 158 | 187 |
| 159 } // namespace content | 188 } // namespace content |
| OLD | NEW |