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