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

Side by Side Diff: mojo/services/window_manager/window_manager_app.cc

Issue 418983002: Nukes view_manager namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: resolve merge Created 6 years, 4 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 "mojo/services/window_manager/window_manager_app.h" 5 #include "mojo/services/window_manager/window_manager_app.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "mojo/aura/aura_init.h" 9 #include "mojo/aura/aura_init.h"
10 #include "mojo/aura/window_tree_host_mojo.h" 10 #include "mojo/aura/window_tree_host_mojo.h"
11 #include "mojo/public/cpp/application/application_connection.h" 11 #include "mojo/public/cpp/application/application_connection.h"
12 #include "mojo/services/public/cpp/view_manager/node.h" 12 #include "mojo/services/public/cpp/view_manager/node.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager.h" 13 #include "mojo/services/public/cpp/view_manager/view_manager.h"
14 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
15 #include "ui/aura/window_property.h" 15 #include "ui/aura/window_property.h"
16 #include "ui/wm/core/capture_controller.h" 16 #include "ui/wm/core/capture_controller.h"
17 #include "ui/wm/core/focus_controller.h" 17 #include "ui/wm/core/focus_controller.h"
18 #include "ui/wm/core/focus_rules.h" 18 #include "ui/wm/core/focus_rules.h"
19 #include "ui/wm/public/activation_client.h" 19 #include "ui/wm/public/activation_client.h"
20 20
21 DECLARE_WINDOW_PROPERTY_TYPE(mojo::view_manager::Node*); 21 DECLARE_WINDOW_PROPERTY_TYPE(mojo::Node*);
22 22
23 namespace mojo { 23 namespace mojo {
24 namespace { 24 namespace {
25 25
26 DEFINE_WINDOW_PROPERTY_KEY(view_manager::Node*, kNodeKey, NULL); 26 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL);
27 27
28 view_manager::Id GetIdForWindow(aura::Window* window) { 28 Id GetIdForWindow(aura::Window* window) {
29 return window ? window->GetProperty(kNodeKey)->id() : 0; 29 return window ? window->GetProperty(kNodeKey)->id() : 0;
30 } 30 }
31 31
32 class WMFocusRules : public wm::FocusRules { 32 class WMFocusRules : public wm::FocusRules {
33 public: 33 public:
34 WMFocusRules() {} 34 WMFocusRules() {}
35 virtual ~WMFocusRules() {} 35 virtual ~WMFocusRules() {}
36 36
37 private: 37 private:
38 // Overridden from wm::FocusRules: 38 // Overridden from wm::FocusRules:
(...skipping 24 matching lines...) Expand all
63 } 63 }
64 64
65 DISALLOW_COPY_AND_ASSIGN(WMFocusRules); 65 DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
66 }; 66 };
67 67
68 } // namespace 68 } // namespace
69 69
70 //////////////////////////////////////////////////////////////////////////////// 70 ////////////////////////////////////////////////////////////////////////////////
71 // WindowManagerApp, public: 71 // WindowManagerApp, public:
72 72
73 WindowManagerApp::WindowManagerApp(view_manager::ViewManagerDelegate* delegate) 73 WindowManagerApp::WindowManagerApp(ViewManagerDelegate* delegate)
74 : InterfaceFactoryWithContext(this), 74 : InterfaceFactoryWithContext(this),
75 wrapped_delegate_(delegate), 75 wrapped_delegate_(delegate),
76 view_manager_(NULL), 76 view_manager_(NULL),
77 view_manager_client_factory_(this), 77 view_manager_client_factory_(this),
78 root_(NULL) { 78 root_(NULL) {
79 } 79 }
80 80
81 WindowManagerApp::~WindowManagerApp() { 81 WindowManagerApp::~WindowManagerApp() {
82 // TODO(beng): Figure out if this should be done in 82 // TODO(beng): Figure out if this should be done in
83 // OnViewManagerDisconnected(). 83 // OnViewManagerDisconnected().
84 STLDeleteValues(&node_id_to_window_map_); 84 STLDeleteValues(&node_id_to_window_map_);
85 if (focus_client_.get()) 85 if (focus_client_.get())
86 focus_client_->RemoveObserver(this); 86 focus_client_->RemoveObserver(this);
87 if (activation_client_) 87 if (activation_client_)
88 activation_client_->RemoveObserver(this); 88 activation_client_->RemoveObserver(this);
89 } 89 }
90 90
91 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) { 91 void WindowManagerApp::AddConnection(WindowManagerServiceImpl* connection) {
92 DCHECK(connections_.find(connection) == connections_.end()); 92 DCHECK(connections_.find(connection) == connections_.end());
93 connections_.insert(connection); 93 connections_.insert(connection);
94 } 94 }
95 95
96 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) { 96 void WindowManagerApp::RemoveConnection(WindowManagerServiceImpl* connection) {
97 DCHECK(connections_.find(connection) != connections_.end()); 97 DCHECK(connections_.find(connection) != connections_.end());
98 connections_.erase(connection); 98 connections_.erase(connection);
99 } 99 }
100 100
101 view_manager::Id WindowManagerApp::OpenWindow() { 101 Id WindowManagerApp::OpenWindow() {
102 view_manager::Node* node = view_manager::Node::Create(view_manager_); 102 Node* node = Node::Create(view_manager_);
103 root_->AddChild(node); 103 root_->AddChild(node);
104 return node->id(); 104 return node->id();
105 } 105 }
106 106
107 view_manager::Id WindowManagerApp::OpenWindowWithURL(const String& url) { 107 Id WindowManagerApp::OpenWindowWithURL(const String& url) {
108 view_manager::Node* node = view_manager::Node::Create(view_manager_); 108 Node* node = Node::Create(view_manager_);
109 root_->AddChild(node); 109 root_->AddChild(node);
110 node->Embed(url); 110 node->Embed(url);
111 return node->id(); 111 return node->id();
112 } 112 }
113 113
114 void WindowManagerApp::SetCapture(view_manager::Id node) { 114 void WindowManagerApp::SetCapture(Id node) {
115 capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node)); 115 capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node));
116 // TODO(beng): notify connected clients that capture has changed, probably 116 // TODO(beng): notify connected clients that capture has changed, probably
117 // by implementing some capture-client observer. 117 // by implementing some capture-client observer.
118 } 118 }
119 119
120 void WindowManagerApp::FocusWindow(view_manager::Id node) { 120 void WindowManagerApp::FocusWindow(Id node) {
121 aura::Window* window = GetWindowForNodeId(node); 121 aura::Window* window = GetWindowForNodeId(node);
122 DCHECK(window); 122 DCHECK(window);
123 focus_client_->FocusWindow(window); 123 focus_client_->FocusWindow(window);
124 } 124 }
125 125
126 void WindowManagerApp::ActivateWindow(view_manager::Id node) { 126 void WindowManagerApp::ActivateWindow(Id node) {
127 aura::Window* window = GetWindowForNodeId(node); 127 aura::Window* window = GetWindowForNodeId(node);
128 DCHECK(window); 128 DCHECK(window);
129 activation_client_->ActivateWindow(window); 129 activation_client_->ActivateWindow(window);
130 } 130 }
131 131
132 bool WindowManagerApp::IsReady() const { 132 bool WindowManagerApp::IsReady() const {
133 return view_manager_ && root_; 133 return view_manager_ && root_;
134 } 134 }
135 135
136 //////////////////////////////////////////////////////////////////////////////// 136 ////////////////////////////////////////////////////////////////////////////////
137 // WindowManagerApp, ApplicationDelegate implementation: 137 // WindowManagerApp, ApplicationDelegate implementation:
138 138
139 void WindowManagerApp::Initialize(ApplicationImpl* impl) { 139 void WindowManagerApp::Initialize(ApplicationImpl* impl) {
140 aura_init_.reset(new AuraInit); 140 aura_init_.reset(new AuraInit);
141 } 141 }
142 142
143 bool WindowManagerApp::ConfigureIncomingConnection( 143 bool WindowManagerApp::ConfigureIncomingConnection(
144 ApplicationConnection* connection) { 144 ApplicationConnection* connection) {
145 connection->AddService(this); 145 connection->AddService(this);
146 connection->AddService(&view_manager_client_factory_); 146 connection->AddService(&view_manager_client_factory_);
147 return true; 147 return true;
148 } 148 }
149 149
150 //////////////////////////////////////////////////////////////////////////////// 150 ////////////////////////////////////////////////////////////////////////////////
151 // WindowManagerApp, view_manager::ViewManagerDelegate implementation: 151 // WindowManagerApp, ViewManagerDelegate implementation:
152 152
153 void WindowManagerApp::OnRootAdded(view_manager::ViewManager* view_manager, 153 void WindowManagerApp::OnRootAdded(ViewManager* view_manager,
154 view_manager::Node* root) { 154 Node* root) {
155 DCHECK(!view_manager_ && !root_); 155 DCHECK(!view_manager_ && !root_);
156 view_manager_ = view_manager; 156 view_manager_ = view_manager;
157 root_ = root; 157 root_ = root;
158 root_->AddObserver(this); 158 root_->AddObserver(this);
159 159
160 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); 160 window_tree_host_.reset(new WindowTreeHostMojo(root_, this));
161 161
162 RegisterSubtree(root_->id(), window_tree_host_->window()); 162 RegisterSubtree(root_->id(), window_tree_host_->window());
163 163
164 capture_client_.reset( 164 capture_client_.reset(
165 new wm::ScopedCaptureClient(window_tree_host_->window())); 165 new wm::ScopedCaptureClient(window_tree_host_->window()));
166 wm::FocusController* focus_controller = 166 wm::FocusController* focus_controller =
167 new wm::FocusController(new WMFocusRules); 167 new wm::FocusController(new WMFocusRules);
168 activation_client_ = focus_controller; 168 activation_client_ = focus_controller;
169 focus_client_.reset(focus_controller); 169 focus_client_.reset(focus_controller);
170 170
171 focus_client_->AddObserver(this); 171 focus_client_->AddObserver(this);
172 activation_client_->AddObserver(this); 172 activation_client_->AddObserver(this);
173 173
174 wrapped_delegate_->OnRootAdded(view_manager, root); 174 wrapped_delegate_->OnRootAdded(view_manager, root);
175 175
176 for (Connections::const_iterator it = connections_.begin(); 176 for (Connections::const_iterator it = connections_.begin();
177 it != connections_.end(); ++it) { 177 it != connections_.end(); ++it) {
178 (*it)->NotifyReady(); 178 (*it)->NotifyReady();
179 } 179 }
180 } 180 }
181 181
182 void WindowManagerApp::OnViewManagerDisconnected( 182 void WindowManagerApp::OnViewManagerDisconnected(
183 view_manager::ViewManager* view_manager) { 183 ViewManager* view_manager) {
184 DCHECK_EQ(view_manager_, view_manager); 184 DCHECK_EQ(view_manager_, view_manager);
185 wrapped_delegate_->OnViewManagerDisconnected(view_manager); 185 wrapped_delegate_->OnViewManagerDisconnected(view_manager);
186 root_->RemoveObserver(this); 186 root_->RemoveObserver(this);
187 root_ = NULL; 187 root_ = NULL;
188 view_manager_ = NULL; 188 view_manager_ = NULL;
189 base::MessageLoop::current()->Quit(); 189 base::MessageLoop::current()->Quit();
190 } 190 }
191 191
192 //////////////////////////////////////////////////////////////////////////////// 192 ////////////////////////////////////////////////////////////////////////////////
193 // WindowManagerApp, view_manager::NodeObserver implementation: 193 // WindowManagerApp, NodeObserver implementation:
194 194
195 void WindowManagerApp::OnTreeChanged( 195 void WindowManagerApp::OnTreeChanged(
196 const view_manager::NodeObserver::TreeChangeParams& params) { 196 const NodeObserver::TreeChangeParams& params) {
197 DCHECK_EQ(params.receiver, root_); 197 DCHECK_EQ(params.receiver, root_);
198 DCHECK(params.old_parent || params.new_parent); 198 DCHECK(params.old_parent || params.new_parent);
199 if (!params.target) 199 if (!params.target)
200 return; 200 return;
201 201
202 if (params.new_parent) { 202 if (params.new_parent) {
203 if (node_id_to_window_map_.find(params.target->id()) == 203 if (node_id_to_window_map_.find(params.target->id()) ==
204 node_id_to_window_map_.end()) { 204 node_id_to_window_map_.end()) {
205 NodeIdToWindowMap::const_iterator it = 205 NodeIdToWindowMap::const_iterator it =
206 node_id_to_window_map_.find(params.new_parent->id()); 206 node_id_to_window_map_.find(params.new_parent->id());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 it != connections_.end(); ++it) { 241 it != connections_.end(); ++it) {
242 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), 242 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active),
243 GetIdForWindow(lost_active)); 243 GetIdForWindow(lost_active));
244 } 244 }
245 } 245 }
246 246
247 //////////////////////////////////////////////////////////////////////////////// 247 ////////////////////////////////////////////////////////////////////////////////
248 // WindowManagerApp, private: 248 // WindowManagerApp, private:
249 249
250 aura::Window* WindowManagerApp::GetWindowForNodeId( 250 aura::Window* WindowManagerApp::GetWindowForNodeId(
251 view_manager::Id node) const { 251 Id node) const {
252 NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(node); 252 NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(node);
253 return it != node_id_to_window_map_.end() ? it->second : NULL; 253 return it != node_id_to_window_map_.end() ? it->second : NULL;
254 } 254 }
255 255
256 void WindowManagerApp::RegisterSubtree(view_manager::Id id, 256 void WindowManagerApp::RegisterSubtree(Id id,
257 aura::Window* parent) { 257 aura::Window* parent) {
258 view_manager::Node* node = view_manager_->GetNodeById(id); 258 Node* node = view_manager_->GetNodeById(id);
259 DCHECK(node_id_to_window_map_.find(id) == node_id_to_window_map_.end()); 259 DCHECK(node_id_to_window_map_.find(id) == node_id_to_window_map_.end());
260 aura::Window* window = new aura::Window(NULL); 260 aura::Window* window = new aura::Window(NULL);
261 window->SetProperty(kNodeKey, node); 261 window->SetProperty(kNodeKey, node);
262 parent->AddChild(window); 262 parent->AddChild(window);
263 node_id_to_window_map_[id] = window; 263 node_id_to_window_map_[id] = window;
264 view_manager::Node::Children::const_iterator it = node->children().begin(); 264 Node::Children::const_iterator it = node->children().begin();
265 for (; it != node->children().end(); ++it) 265 for (; it != node->children().end(); ++it)
266 RegisterSubtree((*it)->id(), window); 266 RegisterSubtree((*it)->id(), window);
267 } 267 }
268 268
269 void WindowManagerApp::UnregisterSubtree(view_manager::Id id) { 269 void WindowManagerApp::UnregisterSubtree(Id id) {
270 view_manager::Node* node = view_manager_->GetNodeById(id); 270 Node* node = view_manager_->GetNodeById(id);
271 NodeIdToWindowMap::iterator it = node_id_to_window_map_.find(id); 271 NodeIdToWindowMap::iterator it = node_id_to_window_map_.find(id);
272 DCHECK(it != node_id_to_window_map_.end()); 272 DCHECK(it != node_id_to_window_map_.end());
273 scoped_ptr<aura::Window> window(it->second); 273 scoped_ptr<aura::Window> window(it->second);
274 node_id_to_window_map_.erase(it); 274 node_id_to_window_map_.erase(it);
275 view_manager::Node::Children::const_iterator child = node->children().begin(); 275 Node::Children::const_iterator child = node->children().begin();
276 for (; child != node->children().end(); ++child) 276 for (; child != node->children().end(); ++child)
277 UnregisterSubtree((*child)->id()); 277 UnregisterSubtree((*child)->id());
278 } 278 }
279 279
280 } // namespace mojo 280 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/window_manager/window_manager_app.h ('k') | mojo/services/window_manager/window_manager_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698