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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" |
6 #include "mojo/public/cpp/application/application.h" | 7 #include "mojo/public/cpp/application/application.h" |
7 #include "mojo/services/public/cpp/view_manager/view.h" | 8 #include "mojo/services/public/cpp/view_manager/view.h" |
8 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 9 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
9 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 10 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
10 | 11 |
11 namespace mojo { | 12 namespace mojo { |
12 namespace examples { | 13 namespace examples { |
13 | 14 |
14 class EmbeddedApp : public Application { | 15 class EmbeddedApp : public Application { |
15 public: | 16 public: |
16 EmbeddedApp() {} | 17 EmbeddedApp() : view_manager_(NULL) {} |
17 virtual ~EmbeddedApp() {} | 18 virtual ~EmbeddedApp() {} |
18 | 19 |
19 private: | 20 private: |
20 // Overridden from Application: | 21 // Overridden from Application: |
21 virtual void Initialize() MOJO_OVERRIDE { | 22 virtual void Initialize() MOJO_OVERRIDE { |
22 view_manager_ = view_manager::ViewManager::CreateBlocking(this); | 23 view_manager::ViewManager::Create(this, |
23 view_manager::View* view = view_manager::View::Create(view_manager_); | 24 base::Bind(&EmbeddedApp::OnRootAdded, base::Unretained(this))); |
24 view_manager_->tree()->SetActiveView(view); | 25 } |
25 view->SetColor(SK_ColorYELLOW); | 26 |
| 27 void OnRootAdded(view_manager::ViewManager* view_manager) { |
| 28 if (!view_manager_) |
| 29 view_manager_ = view_manager; |
| 30 DCHECK_EQ(view_manager_, view_manager); |
| 31 |
| 32 if (view_manager_->roots().size() == 1) { |
| 33 view_manager::View* view = view_manager::View::Create(view_manager_); |
| 34 view_manager_->roots().front()->SetActiveView(view); |
| 35 view->SetColor(SK_ColorYELLOW); |
| 36 } else { |
| 37 view_manager::View* view = view_manager::View::Create(view_manager_); |
| 38 view_manager_->roots().back()->SetActiveView(view); |
| 39 view->SetColor(SK_ColorRED); |
| 40 } |
26 } | 41 } |
27 | 42 |
28 view_manager::ViewManager* view_manager_; | 43 view_manager::ViewManager* view_manager_; |
29 | 44 |
30 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); | 45 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); |
31 }; | 46 }; |
32 | 47 |
33 } // namespace examples | 48 } // namespace examples |
34 | 49 |
35 // static | 50 // static |
36 Application* Application::Create() { | 51 Application* Application::Create() { |
37 return new examples::EmbeddedApp; | 52 return new examples::EmbeddedApp; |
38 } | 53 } |
39 | 54 |
40 } // namespace mojo | 55 } // namespace mojo |
OLD | NEW |