| 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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "examples/bitmap_uploader/bitmap_uploader.h" | 9 #include "examples/bitmap_uploader/bitmap_uploader.h" |
| 10 #include "examples/window_manager/window_manager.mojom.h" | 10 #include "examples/window_manager/window_manager.mojom.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 class NestingApp; | 32 class NestingApp; |
| 33 | 33 |
| 34 // An app that embeds another app. | 34 // An app that embeds another app. |
| 35 // TODO(davemoore): Is this the right name? | 35 // TODO(davemoore): Is this the right name? |
| 36 class NestingApp | 36 class NestingApp |
| 37 : public ApplicationDelegate, | 37 : public ApplicationDelegate, |
| 38 public ViewManagerDelegate, | 38 public ViewManagerDelegate, |
| 39 public ViewObserver { | 39 public ViewObserver { |
| 40 public: | 40 public: |
| 41 NestingApp() : nested_(nullptr), shell_(nullptr) {} | 41 NestingApp() : nested_(nullptr), shell_(nullptr) {} |
| 42 virtual ~NestingApp() {} | 42 ~NestingApp() override {} |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 // Overridden from ApplicationDelegate: | 45 // Overridden from ApplicationDelegate: |
| 46 virtual void Initialize(ApplicationImpl* app) override { | 46 void Initialize(ApplicationImpl* app) override { |
| 47 shell_ = app->shell(); | 47 shell_ = app->shell(); |
| 48 view_manager_client_factory_.reset( | 48 view_manager_client_factory_.reset( |
| 49 new ViewManagerClientFactory(app->shell(), this)); | 49 new ViewManagerClientFactory(app->shell(), this)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Overridden from ApplicationImpl: | 52 // Overridden from ApplicationImpl: |
| 53 virtual bool ConfigureIncomingConnection( | 53 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
| 54 ApplicationConnection* connection) override { | |
| 55 connection->ConnectToService(&window_manager_); | 54 connection->ConnectToService(&window_manager_); |
| 56 connection->AddService(view_manager_client_factory_.get()); | 55 connection->AddService(view_manager_client_factory_.get()); |
| 57 return true; | 56 return true; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // Overridden from ViewManagerDelegate: | 59 // Overridden from ViewManagerDelegate: |
| 61 virtual void OnEmbed(View* root, | 60 void OnEmbed(View* root, |
| 62 InterfaceRequest<ServiceProvider> services, | 61 InterfaceRequest<ServiceProvider> services, |
| 63 ServiceProviderPtr exposed_services) override { | 62 ServiceProviderPtr exposed_services) override { |
| 64 root->AddObserver(this); | 63 root->AddObserver(this); |
| 65 bitmap_uploader_.reset(new BitmapUploader(root)); | 64 bitmap_uploader_.reset(new BitmapUploader(root)); |
| 66 bitmap_uploader_->Init(shell_); | 65 bitmap_uploader_->Init(shell_); |
| 67 bitmap_uploader_->SetColor(SK_ColorCYAN); | 66 bitmap_uploader_->SetColor(SK_ColorCYAN); |
| 68 | 67 |
| 69 nested_ = root->view_manager()->CreateView(); | 68 nested_ = root->view_manager()->CreateView(); |
| 70 root->AddChild(nested_); | 69 root->AddChild(nested_); |
| 71 Rect rect; | 70 Rect rect; |
| 72 rect.x = rect.y = 20; | 71 rect.x = rect.y = 20; |
| 73 rect.width = rect.height = 50; | 72 rect.width = rect.height = 50; |
| 74 nested_->SetBounds(rect); | 73 nested_->SetBounds(rect); |
| 75 nested_->SetVisible(true); | 74 nested_->SetVisible(true); |
| 76 nested_->Embed(kEmbeddedAppURL); | 75 nested_->Embed(kEmbeddedAppURL); |
| 77 } | 76 } |
| 78 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 77 void OnViewManagerDisconnected(ViewManager* view_manager) override { |
| 79 base::MessageLoop::current()->Quit(); | 78 base::MessageLoop::current()->Quit(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 // Overridden from ViewObserver: | 81 // Overridden from ViewObserver: |
| 83 virtual void OnViewDestroyed(View* view) override { | 82 void OnViewDestroyed(View* view) override { |
| 84 // TODO(beng): reap views & child Views. | 83 // TODO(beng): reap views & child Views. |
| 85 nested_ = NULL; | 84 nested_ = NULL; |
| 86 } | 85 } |
| 87 virtual void OnViewInputEvent(View* view, const EventPtr& event) override { | 86 void OnViewInputEvent(View* view, const EventPtr& event) override { |
| 88 if (event->action == EVENT_TYPE_MOUSE_RELEASED) | 87 if (event->action == EVENT_TYPE_MOUSE_RELEASED) |
| 89 window_manager_->CloseWindow(view->id()); | 88 window_manager_->CloseWindow(view->id()); |
| 90 } | 89 } |
| 91 | 90 |
| 92 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; | 91 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_; |
| 93 | 92 |
| 94 View* nested_; | 93 View* nested_; |
| 95 Shell* shell_; | 94 Shell* shell_; |
| 96 IWindowManagerPtr window_manager_; | 95 IWindowManagerPtr window_manager_; |
| 97 scoped_ptr<BitmapUploader> bitmap_uploader_; | 96 scoped_ptr<BitmapUploader> bitmap_uploader_; |
| 98 | 97 |
| 99 DISALLOW_COPY_AND_ASSIGN(NestingApp); | 98 DISALLOW_COPY_AND_ASSIGN(NestingApp); |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 } // namespace examples | 101 } // namespace examples |
| 103 } // namespace mojo | 102 } // namespace mojo |
| 104 | 103 |
| 105 MojoResult MojoMain(MojoHandle shell_handle) { | 104 MojoResult MojoMain(MojoHandle shell_handle) { |
| 106 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp); | 105 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp); |
| 107 return runner.Run(shell_handle); | 106 return runner.Run(shell_handle); |
| 108 } | 107 } |
| OLD | NEW |