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/basictypes.h" |
| 6 #include "base/bind.h" |
| 7 #include "mojo/examples/window_manager/window_manager.mojom.h" |
| 8 #include "mojo/public/cpp/application/application.h" |
| 9 #include "mojo/services/public/cpp/view_manager/view.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 12 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 13 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 14 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h" |
| 15 #include "ui/events/event_constants.h" |
| 16 |
| 17 using mojo::view_manager::View; |
| 18 using mojo::view_manager::ViewManager; |
| 19 using mojo::view_manager::ViewManagerDelegate; |
| 20 using mojo::view_manager::ViewObserver; |
| 21 using mojo::view_manager::ViewTreeNode; |
| 22 using mojo::view_manager::ViewTreeNodeObserver; |
| 23 |
| 24 namespace mojo { |
| 25 namespace examples { |
| 26 |
| 27 // An app that embeds another app. |
| 28 class NestingApp : public Application, |
| 29 public ViewManagerDelegate, |
| 30 public ViewObserver { |
| 31 public: |
| 32 NestingApp() {} |
| 33 virtual ~NestingApp() {} |
| 34 |
| 35 private: |
| 36 // Overridden from Application: |
| 37 virtual void Initialize() MOJO_OVERRIDE { |
| 38 ViewManager::Create(this, this); |
| 39 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_); |
| 40 } |
| 41 |
| 42 // Overridden from ViewManagerDelegate: |
| 43 virtual void OnRootAdded(ViewManager* view_manager, |
| 44 ViewTreeNode* root) OVERRIDE { |
| 45 View* view = View::Create(view_manager); |
| 46 root->SetActiveView(view); |
| 47 view->SetColor(SK_ColorCYAN); |
| 48 view->AddObserver(this); |
| 49 |
| 50 ViewTreeNode* nested = ViewTreeNode::Create(view_manager); |
| 51 root->AddChild(nested); |
| 52 nested->SetBounds(gfx::Rect(20, 20, 50, 50)); |
| 53 nested->Embed("mojo:mojo_embedded_app"); |
| 54 } |
| 55 virtual void OnRootRemoved(ViewManager* view_manager, |
| 56 ViewTreeNode* root) OVERRIDE { |
| 57 // TODO(beng): reap views & child nodes. |
| 58 } |
| 59 |
| 60 // Overridden from ViewObserver: |
| 61 virtual void OnViewInputEvent(View* view, EventPtr event) OVERRIDE { |
| 62 if (event->action == ui::ET_MOUSE_RELEASED) |
| 63 window_manager_->CloseWindow(view->node()->id()); |
| 64 } |
| 65 |
| 66 IWindowManagerPtr window_manager_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(NestingApp); |
| 69 }; |
| 70 |
| 71 } // namespace examples |
| 72 |
| 73 // static |
| 74 Application* Application::Create() { |
| 75 return new examples::NestingApp; |
| 76 } |
| 77 |
| 78 } // namespace mojo |
OLD | NEW |