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/view_manager/root_node_manager.h" | 5 #include "mojo/services/view_manager/root_node_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/public/cpp/application/application_connection.h" | 8 #include "mojo/public/cpp/application/application_connection.h" |
9 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 9 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" | 10 #include "mojo/services/public/cpp/input_events/input_events_type_converters.h" |
11 #include "mojo/services/view_manager/view.h" | 11 #include "mojo/services/view_manager/view.h" |
12 #include "mojo/services/view_manager/view_manager_service_impl.h" | 12 #include "mojo/services/view_manager/view_manager_service_impl.h" |
13 #include "ui/aura/client/focus_client.h" | 13 #include "ui/aura/client/focus_client.h" |
14 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
15 | 15 |
16 namespace mojo { | 16 namespace mojo { |
17 namespace view_manager { | 17 namespace view_manager { |
18 namespace service { | 18 namespace service { |
19 | 19 |
20 RootNodeManager::ScopedChange::ScopedChange( | 20 RootNodeManager::ScopedChange::ScopedChange( |
21 ViewManagerServiceImpl* connection, | 21 ViewManagerServiceImpl* connection, |
22 RootNodeManager* root, | 22 RootNodeManager* root, |
23 RootNodeManager::ChangeType change_type, | |
24 bool is_delete_node) | 23 bool is_delete_node) |
25 : root_(root), | 24 : root_(root), |
26 connection_id_(connection->id()), | 25 connection_id_(connection->id()), |
27 change_type_(change_type), | |
28 is_delete_node_(is_delete_node) { | 26 is_delete_node_(is_delete_node) { |
29 root_->PrepareForChange(this); | 27 root_->PrepareForChange(this); |
30 } | 28 } |
31 | 29 |
32 RootNodeManager::ScopedChange::~ScopedChange() { | 30 RootNodeManager::ScopedChange::~ScopedChange() { |
33 root_->FinishChange(); | 31 root_->FinishChange(); |
34 } | 32 } |
35 | 33 |
36 void RootNodeManager::ScopedChange::SendServerChangeIdAdvanced() { | |
37 root_->SendServerChangeIdAdvanced(); | |
38 } | |
39 | |
40 RootNodeManager::Context::Context() { | 34 RootNodeManager::Context::Context() { |
41 // Pass in false as native viewport creates the PlatformEventSource. | 35 // Pass in false as native viewport creates the PlatformEventSource. |
42 aura::Env::CreateInstance(false); | 36 aura::Env::CreateInstance(false); |
43 } | 37 } |
44 | 38 |
45 RootNodeManager::Context::~Context() { | 39 RootNodeManager::Context::~Context() { |
46 aura::Env::DeleteInstance(); | 40 aura::Env::DeleteInstance(); |
47 } | 41 } |
48 | 42 |
49 RootNodeManager::RootNodeManager( | 43 RootNodeManager::RootNodeManager( |
50 ApplicationConnection* app_connection, | 44 ApplicationConnection* app_connection, |
51 RootViewManagerDelegate* view_manager_delegate, | 45 RootViewManagerDelegate* view_manager_delegate, |
52 const Callback<void()>& native_viewport_closed_callback) | 46 const Callback<void()>& native_viewport_closed_callback) |
53 : app_connection_(app_connection), | 47 : app_connection_(app_connection), |
54 next_connection_id_(1), | 48 next_connection_id_(1), |
55 next_server_change_id_(1), | |
56 root_view_manager_(app_connection, | 49 root_view_manager_(app_connection, |
57 this, | 50 this, |
58 view_manager_delegate, | 51 view_manager_delegate, |
59 native_viewport_closed_callback), | 52 native_viewport_closed_callback), |
60 root_(new Node(this, RootNodeId())), | 53 root_(new Node(this, RootNodeId())), |
61 current_change_(NULL) { | 54 current_change_(NULL) { |
62 } | 55 } |
63 | 56 |
64 RootNodeManager::~RootNodeManager() { | 57 RootNodeManager::~RootNodeManager() { |
65 aura::client::FocusClient* focus_client = | 58 aura::client::FocusClient* focus_client = |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 IsChangeSource(i->first)); | 170 IsChangeSource(i->first)); |
178 } | 171 } |
179 } | 172 } |
180 | 173 |
181 void RootNodeManager::ProcessNodeHierarchyChanged(const Node* node, | 174 void RootNodeManager::ProcessNodeHierarchyChanged(const Node* node, |
182 const Node* new_parent, | 175 const Node* new_parent, |
183 const Node* old_parent) { | 176 const Node* old_parent) { |
184 for (ConnectionMap::iterator i = connection_map_.begin(); | 177 for (ConnectionMap::iterator i = connection_map_.begin(); |
185 i != connection_map_.end(); ++i) { | 178 i != connection_map_.end(); ++i) { |
186 i->second->ProcessNodeHierarchyChanged( | 179 i->second->ProcessNodeHierarchyChanged( |
187 node, new_parent, old_parent, next_server_change_id_, | 180 node, new_parent, old_parent, IsChangeSource(i->first)); |
188 IsChangeSource(i->first)); | |
189 } | 181 } |
190 } | 182 } |
191 | 183 |
192 void RootNodeManager::ProcessNodeReorder(const Node* node, | 184 void RootNodeManager::ProcessNodeReorder(const Node* node, |
193 const Node* relative_node, | 185 const Node* relative_node, |
194 const OrderDirection direction) { | 186 const OrderDirection direction) { |
195 for (ConnectionMap::iterator i = connection_map_.begin(); | 187 for (ConnectionMap::iterator i = connection_map_.begin(); |
196 i != connection_map_.end(); ++i) { | 188 i != connection_map_.end(); ++i) { |
197 i->second->ProcessNodeReorder( | 189 i->second->ProcessNodeReorder( |
198 node, relative_node, direction, next_server_change_id_, | 190 node, relative_node, direction, IsChangeSource(i->first)); |
199 IsChangeSource(i->first)); | |
200 } | 191 } |
201 } | 192 } |
202 | 193 |
203 void RootNodeManager::ProcessNodeViewReplaced(const Node* node, | 194 void RootNodeManager::ProcessNodeViewReplaced(const Node* node, |
204 const View* new_view, | 195 const View* new_view, |
205 const View* old_view) { | 196 const View* old_view) { |
206 for (ConnectionMap::iterator i = connection_map_.begin(); | 197 for (ConnectionMap::iterator i = connection_map_.begin(); |
207 i != connection_map_.end(); ++i) { | 198 i != connection_map_.end(); ++i) { |
208 i->second->ProcessNodeViewReplaced(node, new_view, old_view, | 199 i->second->ProcessNodeViewReplaced(node, new_view, old_view, |
209 IsChangeSource(i->first)); | 200 IsChangeSource(i->first)); |
210 } | 201 } |
211 } | 202 } |
212 | 203 |
213 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { | 204 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { |
214 for (ConnectionMap::iterator i = connection_map_.begin(); | 205 for (ConnectionMap::iterator i = connection_map_.begin(); |
215 i != connection_map_.end(); ++i) { | 206 i != connection_map_.end(); ++i) { |
216 i->second->ProcessNodeDeleted(node, next_server_change_id_, | 207 i->second->ProcessNodeDeleted(node, IsChangeSource(i->first)); |
217 IsChangeSource(i->first)); | |
218 } | 208 } |
219 } | 209 } |
220 | 210 |
221 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { | 211 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { |
222 for (ConnectionMap::iterator i = connection_map_.begin(); | 212 for (ConnectionMap::iterator i = connection_map_.begin(); |
223 i != connection_map_.end(); ++i) { | 213 i != connection_map_.end(); ++i) { |
224 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); | 214 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); |
225 } | 215 } |
226 } | 216 } |
227 | 217 |
(...skipping 10 matching lines...) Expand all Loading... |
238 | 228 |
239 void RootNodeManager::PrepareForChange(ScopedChange* change) { | 229 void RootNodeManager::PrepareForChange(ScopedChange* change) { |
240 // Should only ever have one change in flight. | 230 // Should only ever have one change in flight. |
241 CHECK(!current_change_); | 231 CHECK(!current_change_); |
242 current_change_ = change; | 232 current_change_ = change; |
243 } | 233 } |
244 | 234 |
245 void RootNodeManager::FinishChange() { | 235 void RootNodeManager::FinishChange() { |
246 // PrepareForChange/FinishChange should be balanced. | 236 // PrepareForChange/FinishChange should be balanced. |
247 CHECK(current_change_); | 237 CHECK(current_change_); |
248 if (current_change_->change_type() == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) | |
249 next_server_change_id_++; | |
250 current_change_ = NULL; | 238 current_change_ = NULL; |
251 } | 239 } |
252 | 240 |
253 void RootNodeManager::SendServerChangeIdAdvanced() { | |
254 CHECK(current_change_); | |
255 for (ConnectionMap::iterator i = connection_map_.begin(); | |
256 i != connection_map_.end(); ++i) { | |
257 if (!DidConnectionMessageClient(i->first)) | |
258 i->second->client()->OnServerChangeIdAdvanced(next_server_change_id_ + 1); | |
259 } | |
260 } | |
261 | |
262 ViewManagerServiceImpl* RootNodeManager::EmbedImpl( | 241 ViewManagerServiceImpl* RootNodeManager::EmbedImpl( |
263 const ConnectionSpecificId creator_id, | 242 const ConnectionSpecificId creator_id, |
264 const String& url, | 243 const String& url, |
265 const NodeId& root_id) { | 244 const NodeId& root_id) { |
266 MessagePipe pipe; | 245 MessagePipe pipe; |
267 | 246 |
268 ServiceProvider* service_provider = | 247 ServiceProvider* service_provider = |
269 app_connection_->ConnectToApplication(url)->GetServiceProvider(); | 248 app_connection_->ConnectToApplication(url)->GetServiceProvider(); |
270 service_provider->ConnectToService( | 249 service_provider->ConnectToService( |
271 ViewManagerServiceImpl::Client::Name_, | 250 ViewManagerServiceImpl::Client::Name_, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 291 } |
313 | 292 |
314 void RootNodeManager::OnViewInputEvent(const View* view, | 293 void RootNodeManager::OnViewInputEvent(const View* view, |
315 const ui::Event* event) { | 294 const ui::Event* event) { |
316 DispatchViewInputEventToWindowManager(view, event); | 295 DispatchViewInputEventToWindowManager(view, event); |
317 } | 296 } |
318 | 297 |
319 } // namespace service | 298 } // namespace service |
320 } // namespace view_manager | 299 } // namespace view_manager |
321 } // namespace mojo | 300 } // namespace mojo |
OLD | NEW |