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

Side by Side Diff: mojo/examples/embedded_app/embedded_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
« no previous file with comments | « mojo/examples/browser/browser.cc ('k') | mojo/examples/html_viewer/html_viewer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "mojo/examples/window_manager/window_manager.mojom.h" 9 #include "mojo/examples/window_manager/window_manager.mojom.h"
10 #include "mojo/public/cpp/application/application.h" 10 #include "mojo/public/cpp/application/application.h"
11 #include "mojo/services/navigation/navigation.mojom.h" 11 #include "mojo/services/navigation/navigation.mojom.h"
12 #include "mojo/services/public/cpp/view_manager/node.h"
13 #include "mojo/services/public/cpp/view_manager/node_observer.h"
12 #include "mojo/services/public/cpp/view_manager/view.h" 14 #include "mojo/services/public/cpp/view_manager/view.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager.h" 15 #include "mojo/services/public/cpp/view_manager/view_manager.h"
14 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" 16 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
15 #include "mojo/services/public/cpp/view_manager/view_observer.h" 17 #include "mojo/services/public/cpp/view_manager/view_observer.h"
16 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
17 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
18 #include "ui/events/event_constants.h" 18 #include "ui/events/event_constants.h"
19 #include "url/gurl.h" 19 #include "url/gurl.h"
20 #include "url/url_util.h" 20 #include "url/url_util.h"
21 21
22 using mojo::view_manager::Node;
23 using mojo::view_manager::NodeObserver;
22 using mojo::view_manager::View; 24 using mojo::view_manager::View;
23 using mojo::view_manager::ViewManager; 25 using mojo::view_manager::ViewManager;
24 using mojo::view_manager::ViewManagerDelegate; 26 using mojo::view_manager::ViewManagerDelegate;
25 using mojo::view_manager::ViewObserver; 27 using mojo::view_manager::ViewObserver;
26 using mojo::view_manager::ViewTreeNode;
27 using mojo::view_manager::ViewTreeNodeObserver;
28 28
29 namespace mojo { 29 namespace mojo {
30 namespace examples { 30 namespace examples {
31 31
32 class EmbeddedApp : public Application, 32 class EmbeddedApp : public Application,
33 public ViewManagerDelegate, 33 public ViewManagerDelegate,
34 public ViewObserver, 34 public ViewObserver,
35 public ViewTreeNodeObserver { 35 public NodeObserver {
36 public: 36 public:
37 EmbeddedApp() : view_manager_(NULL) { 37 EmbeddedApp() : view_manager_(NULL) {
38 url::AddStandardScheme("mojo"); 38 url::AddStandardScheme("mojo");
39 } 39 }
40 virtual ~EmbeddedApp() {} 40 virtual ~EmbeddedApp() {}
41 41
42 void SetNodeColor(uint32 node_id, SkColor color) { 42 void SetNodeColor(uint32 node_id, SkColor color) {
43 pending_node_colors_[node_id] = color; 43 pending_node_colors_[node_id] = color;
44 ProcessPendingNodeColor(node_id); 44 ProcessPendingNodeColor(node_id);
45 } 45 }
(...skipping 26 matching lines...) Expand all
72 virtual void Initialize() MOJO_OVERRIDE { 72 virtual void Initialize() MOJO_OVERRIDE {
73 ViewManager::Create(this, this); 73 ViewManager::Create(this, this);
74 // TODO(aa): Weird for embeddee to talk to embedder by URL. Seems like 74 // TODO(aa): Weird for embeddee to talk to embedder by URL. Seems like
75 // embedder should be able to specify the SP embeddee receives, then 75 // embedder should be able to specify the SP embeddee receives, then
76 // communication can be anonymous. 76 // communication can be anonymous.
77 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_); 77 ConnectTo<IWindowManager>("mojo:mojo_window_manager", &window_manager_);
78 AddService<Navigator>(this); 78 AddService<Navigator>(this);
79 } 79 }
80 80
81 // Overridden from ViewManagerDelegate: 81 // Overridden from ViewManagerDelegate:
82 virtual void OnRootAdded(ViewManager* view_manager, 82 virtual void OnRootAdded(ViewManager* view_manager, Node* root) OVERRIDE {
83 ViewTreeNode* root) OVERRIDE {
84 View* view = View::Create(view_manager); 83 View* view = View::Create(view_manager);
85 view->AddObserver(this); 84 view->AddObserver(this);
86 root->SetActiveView(view); 85 root->SetActiveView(view);
87 root->AddObserver(this); 86 root->AddObserver(this);
88 87
89 roots_[root->id()] = root; 88 roots_[root->id()] = root;
90 ProcessPendingNodeColor(root->id()); 89 ProcessPendingNodeColor(root->id());
91 } 90 }
92 virtual void OnRootRemoved(ViewManager* view_manager, 91 virtual void OnRootRemoved(ViewManager* view_manager, Node* root) OVERRIDE {
93 ViewTreeNode* root) OVERRIDE {
94 roots_.erase(root->id()); 92 roots_.erase(root->id());
95 93
96 std::map<ViewTreeNode*, View*>::const_iterator it = 94 std::map<Node*, View*>::const_iterator it = views_to_reap_.find(root);
97 views_to_reap_.find(root);
98 if (it != views_to_reap_.end()) 95 if (it != views_to_reap_.end())
99 it->second->Destroy(); 96 it->second->Destroy();
100 } 97 }
101 98
102 // Overridden from ViewObserver: 99 // Overridden from ViewObserver:
103 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE { 100 virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
104 if (event->action == ui::ET_MOUSE_RELEASED) 101 if (event->action == ui::ET_MOUSE_RELEASED)
105 window_manager_->CloseWindow(view->node()->id()); 102 window_manager_->CloseWindow(view->node()->id());
106 } 103 }
107 104
108 // Overridden from ViewTreeNodeObserver: 105 // Overridden from NodeObserver:
109 virtual void OnNodeActiveViewChange( 106 virtual void OnNodeActiveViewChange(
110 ViewTreeNode* node, 107 Node* node,
111 View* old_view, 108 View* old_view,
112 View* new_view, 109 View* new_view,
113 ViewTreeNodeObserver::DispositionChangePhase phase) OVERRIDE { 110 NodeObserver::DispositionChangePhase phase) OVERRIDE {
114 if (new_view == 0) 111 if (new_view == 0)
115 views_to_reap_[node] = old_view; 112 views_to_reap_[node] = old_view;
116 } 113 }
117 114
118 void ProcessPendingNodeColor(uint32 node_id) { 115 void ProcessPendingNodeColor(uint32 node_id) {
119 RootMap::iterator root = roots_.find(node_id); 116 RootMap::iterator root = roots_.find(node_id);
120 if (root == roots_.end()) 117 if (root == roots_.end())
121 return; 118 return;
122 119
123 PendingNodeColors::iterator color = pending_node_colors_.find(node_id); 120 PendingNodeColors::iterator color = pending_node_colors_.find(node_id);
124 if (color == pending_node_colors_.end()) 121 if (color == pending_node_colors_.end())
125 return; 122 return;
126 123
127 root->second->active_view()->SetColor(color->second); 124 root->second->active_view()->SetColor(color->second);
128 pending_node_colors_.erase(color); 125 pending_node_colors_.erase(color);
129 } 126 }
130 127
131 128
132 view_manager::ViewManager* view_manager_; 129 view_manager::ViewManager* view_manager_;
133 IWindowManagerPtr window_manager_; 130 IWindowManagerPtr window_manager_;
134 std::map<ViewTreeNode*, View*> views_to_reap_; 131 std::map<Node*, View*> views_to_reap_;
135 132
136 typedef std::map<uint32, ViewTreeNode*> RootMap; 133 typedef std::map<uint32, Node*> RootMap;
137 RootMap roots_; 134 RootMap roots_;
138 135
139 // We can receive navigations for nodes we don't have yet. 136 // We can receive navigations for nodes we don't have yet.
140 typedef std::map<uint32, SkColor> PendingNodeColors; 137 typedef std::map<uint32, SkColor> PendingNodeColors;
141 PendingNodeColors pending_node_colors_; 138 PendingNodeColors pending_node_colors_;
142 139
143 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp); 140 DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
144 }; 141 };
145 142
146 } // namespace examples 143 } // namespace examples
147 144
148 // static 145 // static
149 Application* Application::Create() { 146 Application* Application::Create() {
150 return new examples::EmbeddedApp; 147 return new examples::EmbeddedApp;
151 } 148 }
152 149
153 } // namespace mojo 150 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/browser/browser.cc ('k') | mojo/examples/html_viewer/html_viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698