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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "examples/window_manager/debug_panel_host.mojom.h" | 7 #include "examples/window_manager/debug_panel_host.mojom.h" |
8 #include "examples/window_manager/window_manager.mojom.h" | 8 #include "examples/window_manager/window_manager.mojom.h" |
9 #include "mojo/application/application_runner_chromium.h" | 9 #include "mojo/application/application_runner_chromium.h" |
10 #include "mojo/converters/geometry/geometry_type_converters.h" | 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const Id content_view_id_; | 145 const Id content_view_id_; |
146 const Id launcher_ui_view_id_; | 146 const Id launcher_ui_view_id_; |
147 const Id control_panel_view_id_; | 147 const Id control_panel_view_id_; |
148 | 148 |
149 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); | 149 DISALLOW_COPY_AND_ASSIGN(RootLayoutManager); |
150 }; | 150 }; |
151 | 151 |
152 class Window : public InterfaceFactory<NavigatorHost> { | 152 class Window : public InterfaceFactory<NavigatorHost> { |
153 public: | 153 public: |
154 Window(WindowManager* window_manager, View* view) | 154 Window(WindowManager* window_manager, View* view) |
155 : window_manager_(window_manager), view_(view) {} | 155 : window_manager_(window_manager), view_(view) { |
| 156 exposed_services_impl_.AddService<NavigatorHost>(this); |
| 157 } |
156 | 158 |
157 virtual ~Window() {} | 159 virtual ~Window() {} |
158 | 160 |
159 View* view() const { return view_; } | 161 View* view() const { return view_; } |
160 | 162 |
161 void Embed(const std::string& url) { | 163 void Embed(const std::string& url) { |
162 scoped_ptr<ServiceProviderImpl> service_provider_impl( | 164 // TODO: Support embedding multiple times? |
163 new ServiceProviderImpl()); | 165 ServiceProviderPtr exposed_services; |
164 service_provider_impl->AddService<NavigatorHost>(this); | 166 exposed_services_impl_.Bind(GetProxy(&exposed_services)); |
165 view_->Embed(url, service_provider_impl.Pass()); | 167 view_->Embed(url, nullptr, exposed_services.Pass()); |
166 } | 168 } |
167 | 169 |
168 private: | 170 private: |
169 // InterfaceFactory<NavigatorHost> | 171 // InterfaceFactory<NavigatorHost> |
170 virtual void Create(ApplicationConnection* connection, | 172 virtual void Create(ApplicationConnection* connection, |
171 InterfaceRequest<NavigatorHost> request) override { | 173 InterfaceRequest<NavigatorHost> request) override { |
172 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()), | 174 BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()), |
173 &request); | 175 &request); |
174 } | 176 } |
175 | 177 |
176 WindowManager* window_manager_; | 178 WindowManager* window_manager_; |
177 View* view_; | 179 View* view_; |
| 180 ServiceProviderImpl exposed_services_impl_; |
178 }; | 181 }; |
179 | 182 |
180 class WindowManager : public ApplicationDelegate, | 183 class WindowManager : public ApplicationDelegate, |
181 public examples::DebugPanelHost, | 184 public examples::DebugPanelHost, |
182 public ViewManagerDelegate, | 185 public ViewManagerDelegate, |
183 public window_manager::WindowManagerDelegate, | 186 public window_manager::WindowManagerDelegate, |
184 public ui::EventHandler, | 187 public ui::EventHandler, |
185 public mojo::InterfaceFactory<examples::DebugPanelHost> { | 188 public mojo::InterfaceFactory<examples::DebugPanelHost> { |
186 public: | 189 public: |
187 WindowManager() | 190 WindowManager() |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 262 |
260 virtual bool ConfigureIncomingConnection( | 263 virtual bool ConfigureIncomingConnection( |
261 ApplicationConnection* connection) override { | 264 ApplicationConnection* connection) override { |
262 connection->AddService(&window_manager_factory_); | 265 connection->AddService(&window_manager_factory_); |
263 window_manager_app_->ConfigureIncomingConnection(connection); | 266 window_manager_app_->ConfigureIncomingConnection(connection); |
264 return true; | 267 return true; |
265 } | 268 } |
266 | 269 |
267 // Overridden from ViewManagerDelegate: | 270 // Overridden from ViewManagerDelegate: |
268 virtual void OnEmbed(View* root, | 271 virtual void OnEmbed(View* root, |
269 ServiceProviderImpl* exported_services, | 272 InterfaceRequest<ServiceProvider> services, |
270 scoped_ptr<ServiceProvider> imported_services) override { | 273 ServiceProviderPtr exposed_services) override { |
271 DCHECK(!view_manager_); | 274 DCHECK(!view_manager_); |
272 view_manager_ = root->view_manager(); | 275 view_manager_ = root->view_manager(); |
273 | 276 |
274 View* view = view_manager_->CreateView(); | 277 View* view = view_manager_->CreateView(); |
275 root->AddChild(view); | 278 root->AddChild(view); |
276 Rect rect; | 279 Rect rect; |
277 rect.width = root->bounds().width; | 280 rect.width = root->bounds().width; |
278 rect.height = root->bounds().height; | 281 rect.height = root->bounds().height; |
279 view->SetBounds(rect); | 282 view->SetBounds(rect); |
280 view->SetVisible(true); | 283 view->SetVisible(true); |
(...skipping 15 matching lines...) Expand all Loading... |
296 make_scoped_ptr(new window_manager::BasicFocusRules(root))); | 299 make_scoped_ptr(new window_manager::BasicFocusRules(root))); |
297 } | 300 } |
298 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 301 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { |
299 DCHECK_EQ(view_manager_, view_manager); | 302 DCHECK_EQ(view_manager_, view_manager); |
300 view_manager_ = NULL; | 303 view_manager_ = NULL; |
301 base::MessageLoop::current()->Quit(); | 304 base::MessageLoop::current()->Quit(); |
302 } | 305 } |
303 | 306 |
304 // Overridden from WindowManagerDelegate: | 307 // Overridden from WindowManagerDelegate: |
305 void Embed(const String& url, | 308 void Embed(const String& url, |
306 InterfaceRequest<ServiceProvider> service_provider) override { | 309 InterfaceRequest<ServiceProvider> services, |
| 310 ServiceProviderPtr exposed_services) override { |
307 const Id kInvalidSourceViewId = 0; | 311 const Id kInvalidSourceViewId = 0; |
308 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); | 312 OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url); |
309 } | 313 } |
310 | 314 |
311 // Overridden from ui::EventHandler: | 315 // Overridden from ui::EventHandler: |
312 virtual void OnEvent(ui::Event* event) override { | 316 virtual void OnEvent(ui::Event* event) override { |
313 View* view = | 317 View* view = |
314 static_cast<window_manager::ViewTarget*>(event->target())->view(); | 318 static_cast<window_manager::ViewTarget*>(event->target())->view(); |
315 if (event->type() == ui::ET_MOUSE_PRESSED) | 319 if (event->type() == ui::ET_MOUSE_PRESSED) |
316 view->SetFocus(); | 320 view->SetFocus(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 396 |
393 Rect bounds; | 397 Rect bounds; |
394 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset; | 398 bounds.x = root->bounds().width - kControlPanelWidth - kBorderInset; |
395 bounds.y = kBorderInset * 2 + kTextfieldHeight; | 399 bounds.y = kBorderInset * 2 + kTextfieldHeight; |
396 bounds.width = kControlPanelWidth; | 400 bounds.width = kControlPanelWidth; |
397 bounds.height = | 401 bounds.height = |
398 root->bounds().height - kBorderInset * 3 - kTextfieldHeight; | 402 root->bounds().height - kBorderInset * 3 - kTextfieldHeight; |
399 view->SetBounds(bounds); | 403 view->SetBounds(bounds); |
400 view->SetVisible(true); | 404 view->SetVisible(true); |
401 | 405 |
402 scoped_ptr<mojo::ServiceProviderImpl> exported_services( | 406 ServiceProviderPtr exposed_services; |
403 new mojo::ServiceProviderImpl()); | 407 control_panel_exposed_services_impl_.Bind(GetProxy(&exposed_services)); |
404 exported_services->AddService(this); | 408 control_panel_exposed_services_impl_.AddService(this); |
405 | 409 |
406 GURL frame_url = url_.Resolve("/examples/window_manager/debug_panel.sky"); | 410 GURL frame_url = url_.Resolve("/examples/window_manager/debug_panel.sky"); |
407 debug_panel_ = view->Embed(frame_url.spec(), exported_services.Pass()); | 411 view->Embed(frame_url.spec(), nullptr, exposed_services.Pass()); |
408 | 412 |
409 return view->id(); | 413 return view->id(); |
410 } | 414 } |
411 | 415 |
412 WindowVector::iterator GetWindowByViewId(Id view_id) { | 416 WindowVector::iterator GetWindowByViewId(Id view_id) { |
413 for (std::vector<Window*>::iterator iter = windows_.begin(); | 417 for (std::vector<Window*>::iterator iter = windows_.begin(); |
414 iter != windows_.end(); | 418 iter != windows_.end(); |
415 ++iter) { | 419 ++iter) { |
416 if ((*iter)->view()->id() == view_id) { | 420 if ((*iter)->view()->id() == view_id) { |
417 return iter; | 421 return iter; |
418 } | 422 } |
419 } | 423 } |
420 return windows_.end(); | 424 return windows_.end(); |
421 } | 425 } |
422 | 426 |
423 Shell* shell_; | 427 Shell* shell_; |
424 | 428 |
425 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> | 429 InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager> |
426 window_manager_factory_; | 430 window_manager_factory_; |
427 | 431 |
428 scoped_ptr<mojo::ServiceProvider> debug_panel_; | |
429 Window* launcher_ui_; | 432 Window* launcher_ui_; |
430 WindowVector windows_; | 433 WindowVector windows_; |
431 ViewManager* view_manager_; | 434 ViewManager* view_manager_; |
432 scoped_ptr<RootLayoutManager> root_layout_manager_; | 435 scoped_ptr<RootLayoutManager> root_layout_manager_; |
| 436 ServiceProviderImpl control_panel_exposed_services_impl_; |
433 | 437 |
434 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; | 438 scoped_ptr<window_manager::WindowManagerApp> window_manager_app_; |
435 | 439 |
436 // Id of the view most content is added to. | 440 // Id of the view most content is added to. |
437 Id content_view_id_; | 441 Id content_view_id_; |
438 | 442 |
439 // Id of the debug panel. | 443 // Id of the debug panel. |
440 Id control_panel_id_; | 444 Id control_panel_id_; |
441 | 445 |
442 GURL url_; | 446 GURL url_; |
(...skipping 18 matching lines...) Expand all Loading... |
461 window_manager_->RequestNavigate(view_id_, target, request.Pass()); | 465 window_manager_->RequestNavigate(view_id_, target, request.Pass()); |
462 } | 466 } |
463 | 467 |
464 } // namespace examples | 468 } // namespace examples |
465 } // namespace mojo | 469 } // namespace mojo |
466 | 470 |
467 MojoResult MojoMain(MojoHandle shell_handle) { | 471 MojoResult MojoMain(MojoHandle shell_handle) { |
468 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); | 472 mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager); |
469 return runner.Run(shell_handle); | 473 return runner.Run(shell_handle); |
470 } | 474 } |
OLD | NEW |