OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/window_manager/window_manager_app.h" | 5 #include "services/window_manager/window_manager_app.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/converters/geometry/geometry_type_converters.h" | 9 #include "mojo/converters/geometry/geometry_type_converters.h" |
10 #include "mojo/converters/input_events/input_events_type_converters.h" | 10 #include "mojo/converters/input_events/input_events_type_converters.h" |
11 #include "mojo/public/cpp/application/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/application_impl.h" | 12 #include "mojo/public/cpp/application/application_impl.h" |
13 #include "mojo/public/interfaces/application/shell.mojom.h" | 13 #include "mojo/public/interfaces/application/shell.mojom.h" |
14 #include "mojo/services/public/cpp/view_manager/view.h" | 14 #include "mojo/services/public/cpp/view_manager/view.h" |
15 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
16 #include "services/window_manager/focus_controller.h" | 16 #include "services/window_manager/focus_controller.h" |
17 #include "services/window_manager/focus_rules.h" | 17 #include "services/window_manager/focus_rules.h" |
18 #include "services/window_manager/view_event_dispatcher.h" | 18 #include "services/window_manager/view_event_dispatcher.h" |
19 #include "services/window_manager/view_target.h" | 19 #include "services/window_manager/view_target.h" |
20 #include "services/window_manager/view_targeter.h" | 20 #include "services/window_manager/view_targeter.h" |
21 #include "services/window_manager/window_manager_delegate.h" | 21 #include "services/window_manager/window_manager_delegate.h" |
22 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
23 | 23 |
24 namespace mojo { | 24 using mojo::ApplicationConnection; |
| 25 using mojo::Id; |
| 26 using mojo::ServiceProvider; |
| 27 using mojo::View; |
| 28 using mojo::WindowManager; |
| 29 |
| 30 namespace window_manager { |
25 | 31 |
26 namespace { | 32 namespace { |
27 | 33 |
28 Id GetIdForView(View* view) { | 34 Id GetIdForView(View* view) { |
29 return view ? view->id() : 0; | 35 return view ? view->id() : 0; |
30 } | 36 } |
31 | 37 |
32 } // namespace | 38 } // namespace |
33 | 39 |
34 // Used for calls to Embed() that occur before we've connected to the | 40 // Used for calls to Embed() that occur before we've connected to the |
35 // ViewManager. | 41 // ViewManager. |
36 struct WindowManagerApp::PendingEmbed { | 42 struct WindowManagerApp::PendingEmbed { |
37 String url; | 43 mojo::String url; |
38 InterfaceRequest<mojo::ServiceProvider> service_provider; | 44 mojo::InterfaceRequest<ServiceProvider> service_provider; |
39 }; | 45 }; |
40 | 46 |
41 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
42 // WindowManagerApp, public: | 48 // WindowManagerApp, public: |
43 | 49 |
44 WindowManagerApp::WindowManagerApp( | 50 WindowManagerApp::WindowManagerApp( |
45 ViewManagerDelegate* view_manager_delegate, | 51 ViewManagerDelegate* view_manager_delegate, |
46 WindowManagerDelegate* window_manager_delegate) | 52 WindowManagerDelegate* window_manager_delegate) |
47 : shell_(nullptr), | 53 : shell_(nullptr), |
48 native_viewport_event_dispatcher_factory_(this), | 54 native_viewport_event_dispatcher_factory_(this), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 void WindowManagerApp::ActivateWindow(Id view_id) { | 90 void WindowManagerApp::ActivateWindow(Id view_id) { |
85 View* view = view_manager_->GetViewById(view_id); | 91 View* view = view_manager_->GetViewById(view_id); |
86 DCHECK(view); | 92 DCHECK(view); |
87 focus_controller_->ActivateView(view); | 93 focus_controller_->ActivateView(view); |
88 } | 94 } |
89 | 95 |
90 bool WindowManagerApp::IsReady() const { | 96 bool WindowManagerApp::IsReady() const { |
91 return view_manager_ && root_; | 97 return view_manager_ && root_; |
92 } | 98 } |
93 | 99 |
94 void WindowManagerApp::InitFocus(scoped_ptr<mojo::FocusRules> rules) { | 100 void WindowManagerApp::InitFocus(scoped_ptr<FocusRules> rules) { |
95 focus_controller_.reset(new mojo::FocusController(rules.Pass())); | 101 focus_controller_.reset(new FocusController(rules.Pass())); |
96 focus_controller_->AddObserver(this); | 102 focus_controller_->AddObserver(this); |
97 | 103 |
98 DCHECK(root_); | 104 DCHECK(root_); |
99 SetFocusController(root_, focus_controller_.get()); | 105 SetFocusController(root_, focus_controller_.get()); |
100 } | 106 } |
101 | 107 |
102 void WindowManagerApp::Embed( | 108 void WindowManagerApp::Embed( |
103 const String& url, | 109 const mojo::String& url, |
104 InterfaceRequest<ServiceProvider> service_provider) { | 110 mojo::InterfaceRequest<ServiceProvider> service_provider) { |
105 if (view_manager_) { | 111 if (view_manager_) { |
106 window_manager_delegate_->Embed(url, service_provider.Pass()); | 112 window_manager_delegate_->Embed(url, service_provider.Pass()); |
107 return; | 113 return; |
108 } | 114 } |
109 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); | 115 scoped_ptr<PendingEmbed> pending_embed(new PendingEmbed); |
110 pending_embed->url = url; | 116 pending_embed->url = url; |
111 pending_embed->service_provider = service_provider.Pass(); | 117 pending_embed->service_provider = service_provider.Pass(); |
112 pending_embeds_.push_back(pending_embed.release()); | 118 pending_embeds_.push_back(pending_embed.release()); |
113 } | 119 } |
114 | 120 |
115 //////////////////////////////////////////////////////////////////////////////// | 121 //////////////////////////////////////////////////////////////////////////////// |
116 // WindowManagerApp, ApplicationDelegate implementation: | 122 // WindowManagerApp, ApplicationDelegate implementation: |
117 | 123 |
118 void WindowManagerApp::Initialize(ApplicationImpl* impl) { | 124 void WindowManagerApp::Initialize(mojo::ApplicationImpl* impl) { |
119 shell_ = impl->shell(); | 125 shell_ = impl->shell(); |
120 LaunchViewManager(impl); | 126 LaunchViewManager(impl); |
121 } | 127 } |
122 | 128 |
123 bool WindowManagerApp::ConfigureIncomingConnection( | 129 bool WindowManagerApp::ConfigureIncomingConnection( |
124 ApplicationConnection* connection) { | 130 ApplicationConnection* connection) { |
125 connection->AddService(static_cast<InterfaceFactory<WindowManager>*>(this)); | 131 connection->AddService(static_cast<InterfaceFactory<WindowManager>*>(this)); |
126 return true; | 132 return true; |
127 } | 133 } |
128 | 134 |
129 //////////////////////////////////////////////////////////////////////////////// | 135 //////////////////////////////////////////////////////////////////////////////// |
130 // WindowManagerApp, ViewManagerDelegate implementation: | 136 // WindowManagerApp, ViewManagerDelegate implementation: |
131 | 137 |
132 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 138 void WindowManagerApp::OnEmbed(mojo::ViewManager* view_manager, |
133 View* root, | 139 View* root, |
134 ServiceProviderImpl* exported_services, | 140 mojo::ServiceProviderImpl* exported_services, |
135 scoped_ptr<ServiceProvider> imported_services) { | 141 scoped_ptr<ServiceProvider> imported_services) { |
136 DCHECK(!view_manager_ && !root_); | 142 DCHECK(!view_manager_ && !root_); |
137 view_manager_ = view_manager; | 143 view_manager_ = view_manager; |
138 root_ = root; | 144 root_ = root; |
139 | 145 |
140 view_event_dispatcher_.reset(new ViewEventDispatcher()); | 146 view_event_dispatcher_.reset(new ViewEventDispatcher); |
141 | 147 |
142 RegisterSubtree(root_); | 148 RegisterSubtree(root_); |
143 | 149 |
144 // TODO(erg): Also move the capture client over. | 150 // TODO(erg): Also move the capture client over. |
145 // | 151 // |
146 // capture_client_.reset( | 152 // capture_client_.reset( |
147 // new wm::ScopedCaptureClient(window_tree_host_->window())); | 153 // new wm::ScopedCaptureClient(window_tree_host_->window())); |
148 | 154 |
149 if (wrapped_view_manager_delegate_) { | 155 if (wrapped_view_manager_delegate_) { |
150 wrapped_view_manager_delegate_->OnEmbed( | 156 wrapped_view_manager_delegate_->OnEmbed( |
151 view_manager, root, exported_services, imported_services.Pass()); | 157 view_manager, root, exported_services, imported_services.Pass()); |
152 } | 158 } |
153 | 159 |
154 for (PendingEmbed* pending_embed : pending_embeds_) | 160 for (PendingEmbed* pending_embed : pending_embeds_) |
155 Embed(pending_embed->url, pending_embed->service_provider.Pass()); | 161 Embed(pending_embed->url, pending_embed->service_provider.Pass()); |
156 pending_embeds_.clear(); | 162 pending_embeds_.clear(); |
157 } | 163 } |
158 | 164 |
159 void WindowManagerApp::OnViewManagerDisconnected( | 165 void WindowManagerApp::OnViewManagerDisconnected( |
160 ViewManager* view_manager) { | 166 mojo::ViewManager* view_manager) { |
161 DCHECK_EQ(view_manager_, view_manager); | 167 DCHECK_EQ(view_manager_, view_manager); |
162 if (wrapped_view_manager_delegate_) | 168 if (wrapped_view_manager_delegate_) |
163 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); | 169 wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager); |
164 view_manager_ = nullptr; | 170 view_manager_ = nullptr; |
165 base::MessageLoop::current()->Quit(); | 171 base::MessageLoop::current()->Quit(); |
166 } | 172 } |
167 | 173 |
168 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
169 // WindowManagerApp, ViewObserver implementation: | 175 // WindowManagerApp, ViewObserver implementation: |
170 | 176 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return; | 213 return; |
208 | 214 |
209 View* view = static_cast<ViewTarget*>(event->target())->view(); | 215 View* view = static_cast<ViewTarget*>(event->target())->view(); |
210 if (!view) | 216 if (!view) |
211 return; | 217 return; |
212 | 218 |
213 if (focus_controller_) | 219 if (focus_controller_) |
214 focus_controller_->OnEvent(event); | 220 focus_controller_->OnEvent(event); |
215 | 221 |
216 window_manager_client_->DispatchInputEventToView(view->id(), | 222 window_manager_client_->DispatchInputEventToView(view->id(), |
217 Event::From(*event)); | 223 mojo::Event::From(*event)); |
218 } | 224 } |
219 | 225 |
220 //////////////////////////////////////////////////////////////////////////////// | 226 //////////////////////////////////////////////////////////////////////////////// |
221 // WindowManagerApp, mojo::FocusControllerObserver implementation: | 227 // WindowManagerApp, mojo::FocusControllerObserver implementation: |
222 | 228 |
223 void WindowManagerApp::OnViewFocused(View* gained_focus, | 229 void WindowManagerApp::OnViewFocused(View* gained_focus, |
224 View* lost_focus) { | 230 View* lost_focus) { |
225 for (Connections::const_iterator it = connections_.begin(); | 231 for (Connections::const_iterator it = connections_.begin(); |
226 it != connections_.end(); ++it) { | 232 it != connections_.end(); ++it) { |
227 (*it)->NotifyViewFocused(GetIdForView(gained_focus), | 233 (*it)->NotifyViewFocused(GetIdForView(gained_focus), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 if (it == registered_view_id_set_.end()) { | 278 if (it == registered_view_id_set_.end()) { |
273 // Because we unregister in OnViewDestroying() we can still get a subsequent | 279 // Because we unregister in OnViewDestroying() we can still get a subsequent |
274 // OnTreeChanged for the same view. Ignore this one. | 280 // OnTreeChanged for the same view. Ignore this one. |
275 return; | 281 return; |
276 } | 282 } |
277 view->RemoveObserver(this); | 283 view->RemoveObserver(this); |
278 DCHECK(it != registered_view_id_set_.end()); | 284 DCHECK(it != registered_view_id_set_.end()); |
279 registered_view_id_set_.erase(it); | 285 registered_view_id_set_.erase(it); |
280 } | 286 } |
281 | 287 |
282 void WindowManagerApp::DispatchInputEventToView(View* view, EventPtr event) { | 288 void WindowManagerApp::DispatchInputEventToView(View* view, |
| 289 mojo::EventPtr event) { |
283 window_manager_client_->DispatchInputEventToView(view->id(), event.Pass()); | 290 window_manager_client_->DispatchInputEventToView(view->id(), event.Pass()); |
284 } | 291 } |
285 | 292 |
286 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { | 293 void WindowManagerApp::SetViewportSize(const gfx::Size& size) { |
287 window_manager_client_->SetViewportSize(Size::From(size)); | 294 window_manager_client_->SetViewportSize(mojo::Size::From(size)); |
288 } | 295 } |
289 | 296 |
290 void WindowManagerApp::LaunchViewManager(ApplicationImpl* app) { | 297 void WindowManagerApp::LaunchViewManager(mojo::ApplicationImpl* app) { |
291 // TODO(sky): figure out logic if this connection goes away. | 298 // TODO(sky): figure out logic if this connection goes away. |
292 view_manager_client_factory_.reset( | 299 view_manager_client_factory_.reset( |
293 new ViewManagerClientFactory(shell_, this)); | 300 new mojo::ViewManagerClientFactory(shell_, this)); |
294 | 301 |
295 MessagePipe pipe; | 302 mojo::MessagePipe pipe; |
296 ApplicationConnection* view_manager_app = | 303 ApplicationConnection* view_manager_app = |
297 app->ConnectToApplication("mojo:view_manager"); | 304 app->ConnectToApplication("mojo:view_manager"); |
298 ServiceProvider* view_manager_service_provider = | 305 ServiceProvider* view_manager_service_provider = |
299 view_manager_app->GetServiceProvider(); | 306 view_manager_app->GetServiceProvider(); |
300 view_manager_service_provider->ConnectToService(ViewManagerService::Name_, | 307 view_manager_service_provider->ConnectToService( |
301 pipe.handle1.Pass()); | 308 mojo::ViewManagerService::Name_, pipe.handle1.Pass()); |
302 view_manager_client_ = ViewManagerClientFactory::WeakBindViewManagerToPipe( | 309 view_manager_client_ = |
303 pipe.handle0.Pass(), shell_, this).Pass(); | 310 mojo::ViewManagerClientFactory::WeakBindViewManagerToPipe( |
| 311 pipe.handle0.Pass(), shell_, this).Pass(); |
304 | 312 |
305 view_manager_app->AddService(&native_viewport_event_dispatcher_factory_); | 313 view_manager_app->AddService(&native_viewport_event_dispatcher_factory_); |
306 view_manager_app->AddService( | 314 view_manager_app->AddService( |
307 static_cast<InterfaceFactory<WindowManagerInternal>*>(this)); | 315 static_cast<InterfaceFactory<WindowManagerInternal>*>(this)); |
308 | 316 |
309 view_manager_app->ConnectToService(&window_manager_client_); | 317 view_manager_app->ConnectToService(&window_manager_client_); |
310 } | 318 } |
311 | 319 |
312 void WindowManagerApp::Create(ApplicationConnection* connection, | 320 void WindowManagerApp::Create( |
313 InterfaceRequest<WindowManagerInternal> request) { | 321 ApplicationConnection* connection, |
| 322 mojo::InterfaceRequest<WindowManagerInternal> request) { |
314 if (wm_internal_binding_.get()) { | 323 if (wm_internal_binding_.get()) { |
315 VLOG(1) << | 324 VLOG(1) << |
316 "WindowManager allows only one WindowManagerInternal connection."; | 325 "WindowManager allows only one WindowManagerInternal connection."; |
317 return; | 326 return; |
318 } | 327 } |
319 wm_internal_binding_.reset( | 328 wm_internal_binding_.reset( |
320 new Binding<WindowManagerInternal>(this, request.Pass())); | 329 new mojo::Binding<WindowManagerInternal>(this, request.Pass())); |
321 } | 330 } |
322 | 331 |
323 void WindowManagerApp::Create(ApplicationConnection* connection, | 332 void WindowManagerApp::Create(ApplicationConnection* connection, |
324 InterfaceRequest<WindowManager> request) { | 333 mojo::InterfaceRequest<WindowManager> request) { |
325 WindowManagerImpl* wm = new WindowManagerImpl(this, false); | 334 WindowManagerImpl* wm = new WindowManagerImpl(this, false); |
326 wm->Bind(request.PassMessagePipe()); | 335 wm->Bind(request.PassMessagePipe()); |
327 // WindowManagerImpl is deleted when the connection has an error, or from our | 336 // WindowManagerImpl is deleted when the connection has an error, or from our |
328 // destructor. | 337 // destructor. |
329 } | 338 } |
330 | 339 |
331 void WindowManagerApp::CreateWindowManagerForViewManagerClient( | 340 void WindowManagerApp::CreateWindowManagerForViewManagerClient( |
332 uint16_t connection_id, | 341 uint16_t connection_id, |
333 ScopedMessagePipeHandle window_manager_pipe) { | 342 mojo::ScopedMessagePipeHandle window_manager_pipe) { |
334 WindowManagerImpl* wm = new WindowManagerImpl(this, true); | 343 WindowManagerImpl* wm = new WindowManagerImpl(this, true); |
335 wm->Bind(window_manager_pipe.Pass()); | 344 wm->Bind(window_manager_pipe.Pass()); |
336 // WindowManagerImpl is deleted when the connection has an error, or from our | 345 // WindowManagerImpl is deleted when the connection has an error, or from our |
337 // destructor. | 346 // destructor. |
338 } | 347 } |
339 | 348 |
340 } // namespace mojo | 349 } // namespace window_manager |
OLD | NEW |