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 "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/view.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::Node*); | 21 DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*); |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace { | 24 namespace { |
25 | 25 |
26 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL); | 26 DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL); |
27 | 27 |
28 Id GetIdForWindow(aura::Window* window) { | 28 Id GetIdForWindow(aura::Window* window) { |
29 return window ? window->GetProperty(kNodeKey)->id() : 0; | 29 return window ? window->GetProperty(kViewKey)->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: |
39 virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE { | 39 virtual bool IsToplevelWindow(aura::Window* window) const MOJO_OVERRIDE { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 : window_manager_service_factory_(this), | 74 : window_manager_service_factory_(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(&view_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 Id WindowManagerApp::OpenWindow() { | 101 Id WindowManagerApp::OpenWindow() { |
102 Node* node = Node::Create(view_manager_); | 102 View* view = View::Create(view_manager_); |
103 root_->AddChild(node); | 103 root_->AddChild(view); |
104 return node->id(); | 104 return view->id(); |
105 } | 105 } |
106 | 106 |
107 Id WindowManagerApp::OpenWindowWithURL(const String& url) { | 107 Id WindowManagerApp::OpenWindowWithURL(const String& url) { |
108 Node* node = Node::Create(view_manager_); | 108 View* view = View::Create(view_manager_); |
109 root_->AddChild(node); | 109 root_->AddChild(view); |
110 node->Embed(url); | 110 view->Embed(url); |
111 return node->id(); | 111 return view->id(); |
112 } | 112 } |
113 | 113 |
114 void WindowManagerApp::SetCapture(Id node) { | 114 void WindowManagerApp::SetCapture(Id view) { |
115 capture_client_->capture_client()->SetCapture(GetWindowForNodeId(node)); | 115 capture_client_->capture_client()->SetCapture(GetWindowForViewId(view)); |
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(Id node) { | 120 void WindowManagerApp::FocusWindow(Id view) { |
121 aura::Window* window = GetWindowForNodeId(node); | 121 aura::Window* window = GetWindowForViewId(view); |
122 DCHECK(window); | 122 DCHECK(window); |
123 focus_client_->FocusWindow(window); | 123 focus_client_->FocusWindow(window); |
124 } | 124 } |
125 | 125 |
126 void WindowManagerApp::ActivateWindow(Id node) { | 126 void WindowManagerApp::ActivateWindow(Id view) { |
127 aura::Window* window = GetWindowForNodeId(node); | 127 aura::Window* window = GetWindowForViewId(view); |
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(&window_manager_service_factory_); | 145 connection->AddService(&window_manager_service_factory_); |
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, ViewManagerDelegate implementation: | 151 // WindowManagerApp, ViewManagerDelegate implementation: |
152 | 152 |
153 void WindowManagerApp::OnEmbed(ViewManager* view_manager, | 153 void WindowManagerApp::OnEmbed(ViewManager* view_manager, |
154 Node* root, | 154 View* root, |
155 ServiceProviderImpl* exported_services, | 155 ServiceProviderImpl* exported_services, |
156 scoped_ptr<ServiceProvider> imported_services) { | 156 scoped_ptr<ServiceProvider> imported_services) { |
157 DCHECK(!view_manager_ && !root_); | 157 DCHECK(!view_manager_ && !root_); |
158 view_manager_ = view_manager; | 158 view_manager_ = view_manager; |
159 root_ = root; | 159 root_ = root; |
160 root_->AddObserver(this); | 160 root_->AddObserver(this); |
161 | 161 |
162 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); | 162 window_tree_host_.reset(new WindowTreeHostMojo(root_, this)); |
163 | 163 |
164 RegisterSubtree(root_->id(), window_tree_host_->window()); | 164 RegisterSubtree(root_->id(), window_tree_host_->window()); |
(...skipping 22 matching lines...) Expand all Loading... |
187 void WindowManagerApp::OnViewManagerDisconnected( | 187 void WindowManagerApp::OnViewManagerDisconnected( |
188 ViewManager* view_manager) { | 188 ViewManager* view_manager) { |
189 DCHECK_EQ(view_manager_, view_manager); | 189 DCHECK_EQ(view_manager_, view_manager); |
190 if (wrapped_delegate_) | 190 if (wrapped_delegate_) |
191 wrapped_delegate_->OnViewManagerDisconnected(view_manager); | 191 wrapped_delegate_->OnViewManagerDisconnected(view_manager); |
192 view_manager_ = NULL; | 192 view_manager_ = NULL; |
193 base::MessageLoop::current()->Quit(); | 193 base::MessageLoop::current()->Quit(); |
194 } | 194 } |
195 | 195 |
196 //////////////////////////////////////////////////////////////////////////////// | 196 //////////////////////////////////////////////////////////////////////////////// |
197 // WindowManagerApp, NodeObserver implementation: | 197 // WindowManagerApp, ViewObserver implementation: |
198 | 198 |
199 void WindowManagerApp::OnTreeChanged( | 199 void WindowManagerApp::OnTreeChanged( |
200 const NodeObserver::TreeChangeParams& params) { | 200 const ViewObserver::TreeChangeParams& params) { |
201 DCHECK_EQ(params.receiver, root_); | 201 DCHECK_EQ(params.receiver, root_); |
202 DCHECK(params.old_parent || params.new_parent); | 202 DCHECK(params.old_parent || params.new_parent); |
203 if (!params.target) | 203 if (!params.target) |
204 return; | 204 return; |
205 | 205 |
206 if (params.new_parent) { | 206 if (params.new_parent) { |
207 if (node_id_to_window_map_.find(params.target->id()) == | 207 if (view_id_to_window_map_.find(params.target->id()) == |
208 node_id_to_window_map_.end()) { | 208 view_id_to_window_map_.end()) { |
209 NodeIdToWindowMap::const_iterator it = | 209 ViewIdToWindowMap::const_iterator it = |
210 node_id_to_window_map_.find(params.new_parent->id()); | 210 view_id_to_window_map_.find(params.new_parent->id()); |
211 DCHECK(it != node_id_to_window_map_.end()); | 211 DCHECK(it != view_id_to_window_map_.end()); |
212 RegisterSubtree(params.target->id(), it->second); | 212 RegisterSubtree(params.target->id(), it->second); |
213 } | 213 } |
214 } else if (params.old_parent) { | 214 } else if (params.old_parent) { |
215 UnregisterSubtree(params.target->id()); | 215 UnregisterSubtree(params.target->id()); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 void WindowManagerApp::OnNodeDestroyed(Node* node) { | 219 void WindowManagerApp::OnViewDestroyed(View* view) { |
220 root_ = NULL; | 220 root_ = NULL; |
221 window_tree_host_.reset(); | 221 window_tree_host_.reset(); |
222 } | 222 } |
223 | 223 |
224 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
225 // WindowManagerApp, WindowTreeHostMojoDelegate implementation: | 225 // WindowManagerApp, WindowTreeHostMojoDelegate implementation: |
226 | 226 |
227 void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) { | 227 void WindowManagerApp::CompositorContentsChanged(const SkBitmap& bitmap) { |
228 // We draw nothing. | 228 // We draw nothing. |
229 NOTREACHED(); | 229 NOTREACHED(); |
230 } | 230 } |
231 | 231 |
232 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
233 // WindowManagerApp, aura::client::FocusChangeObserver implementation: | 233 // WindowManagerApp, aura::client::FocusChangeObserver implementation: |
234 | 234 |
235 void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus, | 235 void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus, |
236 aura::Window* lost_focus) { | 236 aura::Window* lost_focus) { |
237 for (Connections::const_iterator it = connections_.begin(); | 237 for (Connections::const_iterator it = connections_.begin(); |
238 it != connections_.end(); ++it) { | 238 it != connections_.end(); ++it) { |
239 (*it)->NotifyNodeFocused(GetIdForWindow(gained_focus), | 239 (*it)->NotifyViewFocused(GetIdForWindow(gained_focus), |
240 GetIdForWindow(lost_focus)); | 240 GetIdForWindow(lost_focus)); |
241 } | 241 } |
242 } | 242 } |
243 | 243 |
244 //////////////////////////////////////////////////////////////////////////////// | 244 //////////////////////////////////////////////////////////////////////////////// |
245 // WindowManagerApp, aura::client::ActivationChangeObserver implementation: | 245 // WindowManagerApp, aura::client::ActivationChangeObserver implementation: |
246 | 246 |
247 void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, | 247 void WindowManagerApp::OnWindowActivated(aura::Window* gained_active, |
248 aura::Window* lost_active) { | 248 aura::Window* lost_active) { |
249 for (Connections::const_iterator it = connections_.begin(); | 249 for (Connections::const_iterator it = connections_.begin(); |
250 it != connections_.end(); ++it) { | 250 it != connections_.end(); ++it) { |
251 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), | 251 (*it)->NotifyWindowActivated(GetIdForWindow(gained_active), |
252 GetIdForWindow(lost_active)); | 252 GetIdForWindow(lost_active)); |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 //////////////////////////////////////////////////////////////////////////////// | 256 //////////////////////////////////////////////////////////////////////////////// |
257 // WindowManagerApp, private: | 257 // WindowManagerApp, private: |
258 | 258 |
259 aura::Window* WindowManagerApp::GetWindowForNodeId( | 259 aura::Window* WindowManagerApp::GetWindowForViewId(Id view) const { |
260 Id node) const { | 260 ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view); |
261 NodeIdToWindowMap::const_iterator it = node_id_to_window_map_.find(node); | 261 return it != view_id_to_window_map_.end() ? it->second : NULL; |
262 return it != node_id_to_window_map_.end() ? it->second : NULL; | |
263 } | 262 } |
264 | 263 |
265 void WindowManagerApp::RegisterSubtree(Id id, | 264 void WindowManagerApp::RegisterSubtree(Id id, |
266 aura::Window* parent) { | 265 aura::Window* parent) { |
267 Node* node = view_manager_->GetNodeById(id); | 266 View* view = view_manager_->GetViewById(id); |
268 DCHECK(node_id_to_window_map_.find(id) == node_id_to_window_map_.end()); | 267 DCHECK(view_id_to_window_map_.find(id) == view_id_to_window_map_.end()); |
269 aura::Window* window = new aura::Window(NULL); | 268 aura::Window* window = new aura::Window(NULL); |
270 window->SetProperty(kNodeKey, node); | 269 window->SetProperty(kViewKey, view); |
271 parent->AddChild(window); | 270 parent->AddChild(window); |
272 node_id_to_window_map_[id] = window; | 271 view_id_to_window_map_[id] = window; |
273 Node::Children::const_iterator it = node->children().begin(); | 272 View::Children::const_iterator it = view->children().begin(); |
274 for (; it != node->children().end(); ++it) | 273 for (; it != view->children().end(); ++it) |
275 RegisterSubtree((*it)->id(), window); | 274 RegisterSubtree((*it)->id(), window); |
276 } | 275 } |
277 | 276 |
278 void WindowManagerApp::UnregisterSubtree(Id id) { | 277 void WindowManagerApp::UnregisterSubtree(Id id) { |
279 Node* node = view_manager_->GetNodeById(id); | 278 View* view = view_manager_->GetViewById(id); |
280 NodeIdToWindowMap::iterator it = node_id_to_window_map_.find(id); | 279 ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(id); |
281 DCHECK(it != node_id_to_window_map_.end()); | 280 DCHECK(it != view_id_to_window_map_.end()); |
282 scoped_ptr<aura::Window> window(it->second); | 281 scoped_ptr<aura::Window> window(it->second); |
283 node_id_to_window_map_.erase(it); | 282 view_id_to_window_map_.erase(it); |
284 Node::Children::const_iterator child = node->children().begin(); | 283 View::Children::const_iterator child = view->children().begin(); |
285 for (; child != node->children().end(); ++child) | 284 for (; child != view->children().end(); ++child) |
286 UnregisterSubtree((*child)->id()); | 285 UnregisterSubtree((*child)->id()); |
287 } | 286 } |
288 | 287 |
289 } // namespace mojo | 288 } // namespace mojo |
OLD | NEW |