| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/memory/scoped_ptr.h" | |
| 6 #include "components/view_manager/public/cpp/view_manager.h" | |
| 7 #include "components/view_manager/public/cpp/view_manager_delegate.h" | |
| 8 #include "components/window_manager/window_manager_app.h" | |
| 9 #include "components/window_manager/window_manager_delegate.h" | |
| 10 #include "mojo/application/application_runner_chromium.h" | |
| 11 #include "mojo/application/public/cpp/application_delegate.h" | |
| 12 #include "mojo/application/public/cpp/service_provider_impl.h" | |
| 13 #include "mojo/common/tracing_impl.h" | |
| 14 #include "third_party/mojo/src/mojo/public/c/system/main.h" | |
| 15 | |
| 16 // ApplicationDelegate implementation file for WindowManager users (e.g. | |
| 17 // core window manager tests) that do not want to provide their own | |
| 18 // ApplicationDelegate::Create(). | |
| 19 | |
| 20 using mojo::View; | |
| 21 using mojo::ViewManager; | |
| 22 | |
| 23 namespace window_manager { | |
| 24 | |
| 25 class DefaultWindowManager : public mojo::ApplicationDelegate, | |
| 26 public mojo::ViewManagerDelegate, | |
| 27 public WindowManagerDelegate { | |
| 28 public: | |
| 29 DefaultWindowManager() | |
| 30 : window_manager_app_(new WindowManagerApp(this, this)), | |
| 31 root_(nullptr), | |
| 32 window_offset_(10) { | |
| 33 } | |
| 34 ~DefaultWindowManager() override {} | |
| 35 | |
| 36 private: | |
| 37 // Overridden from mojo::ApplicationDelegate: | |
| 38 void Initialize(mojo::ApplicationImpl* impl) override { | |
| 39 window_manager_app_->Initialize(impl); | |
| 40 tracing_.Initialize(impl); | |
| 41 } | |
| 42 bool ConfigureIncomingConnection( | |
| 43 mojo::ApplicationConnection* connection) override { | |
| 44 window_manager_app_->ConfigureIncomingConnection(connection); | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 // Overridden from ViewManagerDelegate: | |
| 49 void OnEmbed(View* root, | |
| 50 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
| 51 mojo::ServiceProviderPtr exposed_services) override { | |
| 52 root_ = root; | |
| 53 } | |
| 54 void OnViewManagerDisconnected(ViewManager* view_manager) override {} | |
| 55 | |
| 56 // Overridden from WindowManagerDelegate: | |
| 57 void Embed(const mojo::String& url, | |
| 58 mojo::InterfaceRequest<mojo::ServiceProvider> services, | |
| 59 mojo::ServiceProviderPtr exposed_services) override { | |
| 60 DCHECK(root_); | |
| 61 View* view = root_->view_manager()->CreateView(); | |
| 62 root_->AddChild(view); | |
| 63 | |
| 64 mojo::Rect rect; | |
| 65 rect.x = rect.y = window_offset_; | |
| 66 rect.width = rect.height = 100; | |
| 67 view->SetBounds(rect); | |
| 68 window_offset_ += 10; | |
| 69 | |
| 70 view->SetVisible(true); | |
| 71 view->Embed(url, services.Pass(), exposed_services.Pass()); | |
| 72 } | |
| 73 | |
| 74 scoped_ptr<WindowManagerApp> window_manager_app_; | |
| 75 | |
| 76 View* root_; | |
| 77 int window_offset_; | |
| 78 mojo::TracingImpl tracing_; | |
| 79 | |
| 80 MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager); | |
| 81 }; | |
| 82 | |
| 83 } // namespace window_manager | |
| 84 | |
| 85 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 86 mojo::ApplicationRunnerChromium runner( | |
| 87 new window_manager::DefaultWindowManager); | |
| 88 return runner.Run(shell_handle); | |
| 89 } | |
| OLD | NEW |