Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: mojo/examples/nesting_app/nesting_app.cc

Issue 341553002: Remove OnRootRemoved from ViewManagerDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/bind.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "mojo/examples/window_manager/window_manager.mojom.h" 8 #include "mojo/examples/window_manager/window_manager.mojom.h"
9 #include "mojo/public/cpp/application/application.h" 9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/services/navigation/navigation.mojom.h" 10 #include "mojo/services/navigation/navigation.mojom.h"
(...skipping 16 matching lines...) Expand all
27 namespace mojo { 27 namespace mojo {
28 namespace examples { 28 namespace examples {
29 29
30 namespace { 30 namespace {
31 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app"; 31 const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app";
32 } 32 }
33 33
34 // An app that embeds another app. 34 // An app that embeds another app.
35 class NestingApp : public Application, 35 class NestingApp : public Application,
36 public ViewManagerDelegate, 36 public ViewManagerDelegate,
37 public ViewObserver { 37 public ViewObserver,
38 public NodeObserver {
38 public: 39 public:
39 NestingApp() : nested_(NULL) {} 40 NestingApp() : nested_(NULL) {}
40 virtual ~NestingApp() {} 41 virtual ~NestingApp() {}
41 42
42 private: 43 private:
43 class Navigator : public InterfaceImpl<navigation::Navigator> { 44 class Navigator : public InterfaceImpl<navigation::Navigator> {
44 public: 45 public:
45 explicit Navigator(NestingApp* app) : app_(app) {} 46 explicit Navigator(NestingApp* app) : app_(app) {}
46 private: 47 private:
47 virtual void Navigate(uint32 node_id, 48 virtual void Navigate(uint32 node_id,
(...skipping 12 matching lines...) Expand all
60 61
61 // Overridden from Application: 62 // Overridden from Application:
62 virtual void Initialize() MOJO_OVERRIDE { 63 virtual void Initialize() MOJO_OVERRIDE {
63 ViewManager::Create(this, this); 64 ViewManager::Create(this, this);
64 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_); 65 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
65 AddService<Navigator>(this); 66 AddService<Navigator>(this);
66 } 67 }
67 68
68 // Overridden from ViewManagerDelegate: 69 // Overridden from ViewManagerDelegate:
69 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE { 70 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
71 root->AddObserver(this);
72
70 View* view = View::Create(view_manager); 73 View* view = View::Create(view_manager);
71 root->SetActiveView(view); 74 root->SetActiveView(view);
72 view->SetColor(SK_ColorCYAN); 75 view->SetColor(SK_ColorCYAN);
73 view->AddObserver(this); 76 view->AddObserver(this);
74 77
75 nested_ = Node::Create(view_manager); 78 nested_ = Node::Create(view_manager);
76 root->AddChild(nested_); 79 root->AddChild(nested_);
77 nested_->SetBounds(gfx::Rect(20, 20, 50, 50)); 80 nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
78 nested_->Embed(kEmbeddedAppURL); 81 nested_->Embed(kEmbeddedAppURL);
79 82
80 if (!navigator_.get()) 83 if (!navigator_.get())
81 ConnectTo(kEmbeddedAppURL, &navigator_); 84 ConnectTo(kEmbeddedAppURL, &navigator_);
82 85
83 NavigateChild(); 86 NavigateChild();
84 } 87 }
85 88
86 virtual void OnRootRemoved(ViewManager* view_manager, Node* root) OVERRIDE {
87 // TODO(beng): reap views & child nodes.
88 nested_ = NULL;
89 }
90
91 // Overridden from ViewObserver: 89 // Overridden from ViewObserver:
92 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { 90 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
93 if (event->action == ui::ET_MOUSE_RELEASED) 91 if (event->action == ui::ET_MOUSE_RELEASED)
94 window_manager_->CloseWindow(view->node()->id()); 92 window_manager_->CloseWindow(view->node()->id());
95 } 93 }
96 94
95 // Overridden from NodeObserver:
96 virtual void OnNodeDestroy(
97 Node* node,
98 NodeObserver::DispositionChangePhase phase) OVERRIDE {
99 if (phase != NodeObserver::DISPOSITION_CHANGED)
100 return;
101 // TODO(beng): reap views & child nodes.
102 nested_ = NULL;
103 }
104
105
sky 2014/06/17 16:56:53 nit: only one newline.
97 void NavigateChild() { 106 void NavigateChild() {
98 if (!color_.empty() && nested_) { 107 if (!color_.empty() && nested_) {
99 navigation::NavigationDetailsPtr details( 108 navigation::NavigationDetailsPtr details(
100 navigation::NavigationDetails::New()); 109 navigation::NavigationDetails::New());
101 details->url = 110 details->url =
102 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str()); 111 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str());
103 navigator_->Navigate(nested_->id(), details.Pass()); 112 navigator_->Navigate(nested_->id(), details.Pass());
104 } 113 }
105 } 114 }
106 115
107 std::string color_; 116 std::string color_;
108 Node* nested_; 117 Node* nested_;
109 navigation::NavigatorPtr navigator_; 118 navigation::NavigatorPtr navigator_;
110 IWindowManagerPtr window_manager_; 119 IWindowManagerPtr window_manager_;
111 120
112 DISALLOW_COPY_AND_ASSIGN(NestingApp); 121 DISALLOW_COPY_AND_ASSIGN(NestingApp);
113 }; 122 };
114 123
115 } // namespace examples 124 } // namespace examples
116 125
117 // static 126 // static
118 Application* Application::Create() { 127 Application* Application::Create() {
119 return new examples::NestingApp; 128 return new examples::NestingApp;
120 } 129 }
121 130
122 } // namespace mojo 131 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/embedded_app/embedded_app.cc ('k') | mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698