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
3 // found in the LICENSE file.
5 #include "mojo/public/cpp/application/application_delegate.h"
6 #include "mojo/public/cpp/application/service_provider_impl.h"
7 #include "mojo/services/public/cpp/view_manager/view_manager.h"
8 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
9 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h"
10 #include "mojo/services/window_manager/window_manager_app.h"
14 class SimpleWM : public mojo::ApplicationDelegate,
15 public mojo::ViewManagerDelegate,
16 public mojo::WindowManagerDelegate {
19 : window_manager_app_(new mojo::WindowManagerApp(this, this)),
22 window_container_(NULL),
23 next_window_origin_(10, 10) {}
24 virtual ~SimpleWM() {}
27 // Overridden from mojo::ApplicationDelegate:
28 virtual void Initialize(mojo::ApplicationImpl* impl) MOJO_OVERRIDE {
29 window_manager_app_->Initialize(impl);
31 virtual bool ConfigureIncomingConnection(
32 mojo::ApplicationConnection* connection) MOJO_OVERRIDE {
33 window_manager_app_->ConfigureIncomingConnection(connection);
37 // Overridden from mojo::ViewManagerDelegate:
39 mojo::ViewManager* view_manager,
41 mojo::ServiceProviderImpl* exported_services,
42 scoped_ptr<mojo::ServiceProvider> remote_service_provider) MOJO_OVERRIDE {
43 view_manager_ = view_manager;
46 window_container_ = mojo::View::Create(view_manager_);
47 window_container_->SetBounds(root_->bounds());
48 root_->AddChild(window_container_);
51 virtual void OnViewManagerDisconnected(
52 mojo::ViewManager* view_manager) MOJO_OVERRIDE {
57 // Overridden from mojo::WindowManagerDelegate:
59 const mojo::String& url,
60 mojo::InterfaceRequest<mojo::ServiceProvider> service_provider)
62 mojo::View* embed_view = mojo::View::Create(view_manager_);
63 embed_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
64 window_container_->AddChild(embed_view);
66 // TODO(beng): We're dropping the |service_provider| passed from the client
67 // on the floor here and passing our own. Seems like we should
68 // be sending both. I'm not yet sure how this sould work for
69 // N levels of proxying.
70 embed_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
71 new mojo::ServiceProviderImpl).Pass());
72 next_window_origin_.Offset(50, 50);
74 virtual void DispatchEvent(mojo::EventPtr event) MOJO_OVERRIDE {}
76 scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
78 mojo::ViewManager* view_manager_;
80 mojo::View* window_container_;
82 gfx::Point next_window_origin_;
84 DISALLOW_COPY_AND_ASSIGN(SimpleWM);
87 } // namespace examples
92 ApplicationDelegate* ApplicationDelegate::Create() {
93 return new examples::SimpleWM;