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/common/input/web_input_event_traits.h" | 8 #include "content/common/input/web_input_event_traits.h" |
9 #include "content/renderer/input/input_handler_manager.h" | 9 #include "content/renderer/input/input_handler_manager.h" |
10 #include "content/renderer/mus/render_widget_mus_connection.h" | 10 #include "content/renderer/mus/render_widget_mus_connection.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 compositor_task_runner_(compositor_task_runner), | 32 compositor_task_runner_(compositor_task_runner), |
33 input_handler_manager_(input_handler_manager) { | 33 input_handler_manager_(input_handler_manager) { |
34 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 34 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
35 compositor_task_runner_->PostTask( | 35 compositor_task_runner_->PostTask( |
36 FROM_HERE, base::Bind(&CompositorMusConnection:: | 36 FROM_HERE, base::Bind(&CompositorMusConnection:: |
37 CreateWindowTreeConnectionOnCompositorThread, | 37 CreateWindowTreeConnectionOnCompositorThread, |
38 this, base::Passed(std::move(request)))); | 38 this, base::Passed(std::move(request)))); |
39 } | 39 } |
40 | 40 |
41 void CompositorMusConnection::AttachSurfaceOnMainThread( | 41 void CompositorMusConnection::AttachSurfaceOnMainThread( |
42 scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { | 42 std::unique_ptr<mus::WindowSurfaceBinding> surface_binding) { |
43 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 43 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
44 compositor_task_runner_->PostTask( | 44 compositor_task_runner_->PostTask( |
45 FROM_HERE, | 45 FROM_HERE, |
46 base::Bind(&CompositorMusConnection::AttachSurfaceOnCompositorThread, | 46 base::Bind(&CompositorMusConnection::AttachSurfaceOnCompositorThread, |
47 this, base::Passed(std::move(surface_binding)))); | 47 this, base::Passed(std::move(surface_binding)))); |
48 } | 48 } |
49 | 49 |
50 CompositorMusConnection::~CompositorMusConnection() {} | 50 CompositorMusConnection::~CompositorMusConnection() {} |
51 | 51 |
52 void CompositorMusConnection::AttachSurfaceOnCompositorThread( | 52 void CompositorMusConnection::AttachSurfaceOnCompositorThread( |
53 scoped_ptr<mus::WindowSurfaceBinding> surface_binding) { | 53 std::unique_ptr<mus::WindowSurfaceBinding> surface_binding) { |
54 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 54 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
55 window_surface_binding_ = std::move(surface_binding); | 55 window_surface_binding_ = std::move(surface_binding); |
56 if (root_) { | 56 if (root_) { |
57 root_->AttachSurface(mus::mojom::SurfaceType::DEFAULT, | 57 root_->AttachSurface(mus::mojom::SurfaceType::DEFAULT, |
58 std::move(window_surface_binding_)); | 58 std::move(window_surface_binding_)); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void CompositorMusConnection::CreateWindowTreeConnectionOnCompositorThread( | 62 void CompositorMusConnection::CreateWindowTreeConnectionOnCompositorThread( |
63 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { | 63 mojo::InterfaceRequest<mus::mojom::WindowTreeClient> request) { |
64 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 64 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
65 mus::WindowTreeConnection::Create( | 65 mus::WindowTreeConnection::Create( |
66 this, std::move(request), | 66 this, std::move(request), |
67 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); | 67 mus::WindowTreeConnection::CreateType::DONT_WAIT_FOR_EMBED); |
68 } | 68 } |
69 | 69 |
70 void CompositorMusConnection::OnConnectionLostOnMainThread() { | 70 void CompositorMusConnection::OnConnectionLostOnMainThread() { |
71 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 71 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
72 RenderWidgetMusConnection* connection = | 72 RenderWidgetMusConnection* connection = |
73 RenderWidgetMusConnection::Get(routing_id_); | 73 RenderWidgetMusConnection::Get(routing_id_); |
74 if (!connection) | 74 if (!connection) |
75 return; | 75 return; |
76 connection->OnConnectionLost(); | 76 connection->OnConnectionLost(); |
77 } | 77 } |
78 | 78 |
79 void CompositorMusConnection::OnWindowInputEventOnMainThread( | 79 void CompositorMusConnection::OnWindowInputEventOnMainThread( |
80 scoped_ptr<blink::WebInputEvent> web_event, | 80 std::unique_ptr<blink::WebInputEvent> web_event, |
81 const base::Callback<void(bool)>& ack) { | 81 const base::Callback<void(bool)>& ack) { |
82 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 82 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
83 RenderWidgetMusConnection* connection = | 83 RenderWidgetMusConnection* connection = |
84 RenderWidgetMusConnection::Get(routing_id_); | 84 RenderWidgetMusConnection::Get(routing_id_); |
85 if (!connection) { | 85 if (!connection) { |
86 ack.Run(false); | 86 ack.Run(false); |
87 return; | 87 return; |
88 } | 88 } |
89 connection->OnWindowInputEvent(std::move(web_event), ack); | 89 connection->OnWindowInputEvent(std::move(web_event), ack); |
90 } | 90 } |
(...skipping 19 matching lines...) Expand all Loading... |
110 root_->set_input_event_handler(this); | 110 root_->set_input_event_handler(this); |
111 if (window_surface_binding_) { | 111 if (window_surface_binding_) { |
112 root->AttachSurface(mus::mojom::SurfaceType::DEFAULT, | 112 root->AttachSurface(mus::mojom::SurfaceType::DEFAULT, |
113 std::move(window_surface_binding_)); | 113 std::move(window_surface_binding_)); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 void CompositorMusConnection::OnWindowInputEvent( | 117 void CompositorMusConnection::OnWindowInputEvent( |
118 mus::Window* window, | 118 mus::Window* window, |
119 const ui::Event& event, | 119 const ui::Event& event, |
120 scoped_ptr<base::Callback<void(bool)>>* ack_callback) { | 120 std::unique_ptr<base::Callback<void(bool)>>* ack_callback) { |
121 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); | 121 DCHECK(compositor_task_runner_->BelongsToCurrentThread()); |
122 // TODO(moshayedi): Convert ui::Event directly to blink::WebInputEvent. | 122 // TODO(moshayedi): Convert ui::Event directly to blink::WebInputEvent. |
123 scoped_ptr<blink::WebInputEvent> web_event( | 123 std::unique_ptr<blink::WebInputEvent> web_event( |
124 mus::mojom::Event::From(event).To<scoped_ptr<blink::WebInputEvent>>()); | 124 mus::mojom::Event::From(event) |
| 125 .To<std::unique_ptr<blink::WebInputEvent>>()); |
125 // TODO(sad): We probably need to plumb LatencyInfo through Mus. | 126 // TODO(sad): We probably need to plumb LatencyInfo through Mus. |
126 ui::LatencyInfo info; | 127 ui::LatencyInfo info; |
127 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( | 128 InputEventAckState ack_state = input_handler_manager_->HandleInputEvent( |
128 routing_id_, web_event.get(), &info); | 129 routing_id_, web_event.get(), &info); |
129 // TODO(jonross): We probably need to ack the event based on the consumed | 130 // TODO(jonross): We probably need to ack the event based on the consumed |
130 // state. | 131 // state. |
131 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) | 132 if (ack_state != INPUT_EVENT_ACK_STATE_NOT_CONSUMED) |
132 return; | 133 return; |
133 base::Callback<void(bool)> ack = base::Bind(&::DoNothingBool); | 134 base::Callback<void(bool)> ack = base::Bind(&::DoNothingBool); |
134 const bool send_ack = WebInputEventTraits::ShouldBlockEventStream(*web_event); | 135 const bool send_ack = WebInputEventTraits::ShouldBlockEventStream(*web_event); |
135 if (send_ack) { | 136 if (send_ack) { |
136 // Ultimately, this ACK needs to go back to the Mus client lib which is not | 137 // Ultimately, this ACK needs to go back to the Mus client lib which is not |
137 // thread-safe and lives on the compositor thread. For ACKs that are passed | 138 // thread-safe and lives on the compositor thread. For ACKs that are passed |
138 // to the main thread we pass them back to the compositor thread via | 139 // to the main thread we pass them back to the compositor thread via |
139 // OnWindowInputEventAckOnMainThread. | 140 // OnWindowInputEventAckOnMainThread. |
140 ack = | 141 ack = |
141 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, | 142 base::Bind(&CompositorMusConnection::OnWindowInputEventAckOnMainThread, |
142 this, *ack_callback->get()); | 143 this, *ack_callback->get()); |
143 ack_callback->reset(); | 144 ack_callback->reset(); |
144 } | 145 } |
145 main_task_runner_->PostTask( | 146 main_task_runner_->PostTask( |
146 FROM_HERE, | 147 FROM_HERE, |
147 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, | 148 base::Bind(&CompositorMusConnection::OnWindowInputEventOnMainThread, this, |
148 base::Passed(std::move(web_event)), ack)); | 149 base::Passed(std::move(web_event)), ack)); |
149 } | 150 } |
150 | 151 |
151 } // namespace content | 152 } // namespace content |
OLD | NEW |