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

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

Issue 338093008: Client side name cleanup (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"
11 #include "mojo/services/public/cpp/view_manager/node.h"
12 #include "mojo/services/public/cpp/view_manager/node_observer.h"
11 #include "mojo/services/public/cpp/view_manager/view.h" 13 #include "mojo/services/public/cpp/view_manager/view.h"
12 #include "mojo/services/public/cpp/view_manager/view_manager.h" 14 #include "mojo/services/public/cpp/view_manager/view_manager.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 15 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
14 #include "mojo/services/public/cpp/view_manager/view_observer.h" 16 #include "mojo/services/public/cpp/view_manager/view_observer.h"
15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
16 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
17 #include "ui/events/event_constants.h" 17 #include "ui/events/event_constants.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 using mojo::view_manager::Node;
21 using mojo::view_manager::NodeObserver;
20 using mojo::view_manager::View; 22 using mojo::view_manager::View;
21 using mojo::view_manager::ViewManager; 23 using mojo::view_manager::ViewManager;
22 using mojo::view_manager::ViewManagerDelegate; 24 using mojo::view_manager::ViewManagerDelegate;
23 using mojo::view_manager::ViewObserver; 25 using mojo::view_manager::ViewObserver;
24 using mojo::view_manager::ViewTreeNode;
25 using mojo::view_manager::ViewTreeNodeObserver;
26 26
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,
(...skipping 23 matching lines...) Expand all
59 }; 59 };
60 60
61 // Overridden from Application: 61 // Overridden from Application:
62 virtual void Initialize() MOJO_OVERRIDE { 62 virtual void Initialize() MOJO_OVERRIDE {
63 ViewManager::Create(this, this); 63 ViewManager::Create(this, this);
64 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_); 64 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
65 AddService<Navigator>(this); 65 AddService<Navigator>(this);
66 } 66 }
67 67
68 // Overridden from ViewManagerDelegate: 68 // Overridden from ViewManagerDelegate:
69 virtual void OnRootAdded(ViewManager* view_manager, 69 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
70 ViewTreeNode* root) OVERRIDE {
71 View* view = View::Create(view_manager); 70 View* view = View::Create(view_manager);
72 root->SetActiveView(view); 71 root->SetActiveView(view);
73 view->SetColor(SK_ColorCYAN); 72 view->SetColor(SK_ColorCYAN);
74 view->AddObserver(this); 73 view->AddObserver(this);
75 74
76 nested_ = ViewTreeNode::Create(view_manager); 75 nested_ = Node::Create(view_manager);
77 root->AddChild(nested_); 76 root->AddChild(nested_);
78 nested_->SetBounds(gfx::Rect(20, 20, 50, 50)); 77 nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
79 nested_->Embed(kEmbeddedAppURL); 78 nested_->Embed(kEmbeddedAppURL);
80 79
81 if (!navigator_.get()) 80 if (!navigator_.get())
82 ConnectTo(kEmbeddedAppURL, &navigator_); 81 ConnectTo(kEmbeddedAppURL, &navigator_);
83 82
84 NavigateChild(); 83 NavigateChild();
85 } 84 }
86 85
87 virtual void OnRootRemoved(ViewManager* view_manager, 86 virtual void OnRootRemoved(ViewManager* view_manager, Node* root) OVERRIDE {
88 ViewTreeNode* root) OVERRIDE {
89 // TODO(beng): reap views & child nodes. 87 // TODO(beng): reap views & child nodes.
90 nested_ = NULL; 88 nested_ = NULL;
91 } 89 }
92 90
93 // Overridden from ViewObserver: 91 // Overridden from ViewObserver:
94 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { 92 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
95 if (event->action == ui::ET_MOUSE_RELEASED) 93 if (event->action == ui::ET_MOUSE_RELEASED)
96 window_manager_->CloseWindow(view->node()->id()); 94 window_manager_->CloseWindow(view->node()->id());
97 } 95 }
98 96
99 void NavigateChild() { 97 void NavigateChild() {
100 if (!color_.empty() && nested_) { 98 if (!color_.empty() && nested_) {
101 navigation::NavigationDetailsPtr details( 99 navigation::NavigationDetailsPtr details(
102 navigation::NavigationDetails::New()); 100 navigation::NavigationDetails::New());
103 details->url = 101 details->url =
104 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str()); 102 base::StringPrintf("%s/%s", kEmbeddedAppURL, color_.c_str());
105 navigator_->Navigate(nested_->id(), details.Pass()); 103 navigator_->Navigate(nested_->id(), details.Pass());
106 } 104 }
107 } 105 }
108 106
109 std::string color_; 107 std::string color_;
110 ViewTreeNode* nested_; 108 Node* nested_;
111 navigation::NavigatorPtr navigator_; 109 navigation::NavigatorPtr navigator_;
112 IWindowManagerPtr window_manager_; 110 IWindowManagerPtr window_manager_;
113 111
114 DISALLOW_COPY_AND_ASSIGN(NestingApp); 112 DISALLOW_COPY_AND_ASSIGN(NestingApp);
115 }; 113 };
116 114
117 } // namespace examples 115 } // namespace examples
118 116
119 // static 117 // static
120 Application* Application::Create() { 118 Application* Application::Create() {
121 return new examples::NestingApp; 119 return new examples::NestingApp;
122 } 120 }
123 121
124 } // namespace mojo 122 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/image_viewer/image_viewer.cc ('k') | mojo/examples/window_manager/window_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698