| 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/application/service_provider.mojom.h" | 9 #include "mojo/public/interfaces/application/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_manager_service_impl.h" | 11 #include "mojo/services/view_manager/view_manager_service_impl.h" |
| 12 #include "ui/aura/client/focus_client.h" | |
| 13 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 14 | 13 |
| 15 namespace mojo { | 14 namespace mojo { |
| 16 namespace service { | 15 namespace service { |
| 17 | 16 |
| 18 RootNodeManager::ScopedChange::ScopedChange( | 17 RootNodeManager::ScopedChange::ScopedChange( |
| 19 ViewManagerServiceImpl* connection, | 18 ViewManagerServiceImpl* connection, |
| 20 RootNodeManager* root, | 19 RootNodeManager* root, |
| 21 bool is_delete_node) | 20 bool is_delete_node) |
| 22 : root_(root), | 21 : root_(root), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 next_connection_id_(1), | 45 next_connection_id_(1), |
| 47 root_view_manager_(app_connection, | 46 root_view_manager_(app_connection, |
| 48 this, | 47 this, |
| 49 view_manager_delegate, | 48 view_manager_delegate, |
| 50 native_viewport_closed_callback), | 49 native_viewport_closed_callback), |
| 51 root_(new Node(this, RootNodeId())), | 50 root_(new Node(this, RootNodeId())), |
| 52 current_change_(NULL) { | 51 current_change_(NULL) { |
| 53 } | 52 } |
| 54 | 53 |
| 55 RootNodeManager::~RootNodeManager() { | 54 RootNodeManager::~RootNodeManager() { |
| 56 aura::client::FocusClient* focus_client = | |
| 57 aura::client::GetFocusClient(root_->window()); | |
| 58 focus_client->RemoveObserver(this); | |
| 59 while (!connections_created_by_connect_.empty()) | 55 while (!connections_created_by_connect_.empty()) |
| 60 delete *(connections_created_by_connect_.begin()); | 56 delete *(connections_created_by_connect_.begin()); |
| 61 // All the connections should have been destroyed. | 57 // All the connections should have been destroyed. |
| 62 DCHECK(connection_map_.empty()); | 58 DCHECK(connection_map_.empty()); |
| 63 root_.reset(); | 59 root_.reset(); |
| 64 } | 60 } |
| 65 | 61 |
| 66 ConnectionSpecificId RootNodeManager::GetAndAdvanceNextConnectionId() { | 62 ConnectionSpecificId RootNodeManager::GetAndAdvanceNextConnectionId() { |
| 67 const ConnectionSpecificId id = next_connection_id_++; | 63 const ConnectionSpecificId id = next_connection_id_++; |
| 68 DCHECK_LT(id, next_connection_id_); | 64 DCHECK_LT(id, next_connection_id_); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const ViewManagerServiceImpl* RootNodeManager::GetConnectionWithRoot( | 141 const ViewManagerServiceImpl* RootNodeManager::GetConnectionWithRoot( |
| 146 const NodeId& id) const { | 142 const NodeId& id) const { |
| 147 for (ConnectionMap::const_iterator i = connection_map_.begin(); | 143 for (ConnectionMap::const_iterator i = connection_map_.begin(); |
| 148 i != connection_map_.end(); ++i) { | 144 i != connection_map_.end(); ++i) { |
| 149 if (i->second->HasRoot(id)) | 145 if (i->second->HasRoot(id)) |
| 150 return i->second; | 146 return i->second; |
| 151 } | 147 } |
| 152 return NULL; | 148 return NULL; |
| 153 } | 149 } |
| 154 | 150 |
| 155 void RootNodeManager::DispatchNodeInputEventToWindowManager( | 151 void RootNodeManager::DispatchNodeInputEventToWindowManager(EventPtr event) { |
| 156 const Node* node, | |
| 157 const ui::Event* event) { | |
| 158 // Input events are forwarded to the WindowManager. The WindowManager | 152 // Input events are forwarded to the WindowManager. The WindowManager |
| 159 // eventually calls back to us with DispatchOnViewInputEvent(). | 153 // eventually calls back to us with DispatchOnViewInputEvent(). |
| 160 ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection); | 154 ViewManagerServiceImpl* connection = GetConnection(kWindowManagerConnection); |
| 161 if (!connection) | 155 if (!connection) |
| 162 return; | 156 return; |
| 163 connection->client()->DispatchOnViewInputEvent( | 157 connection->client()->DispatchOnViewInputEvent(event.Pass()); |
| 164 NodeIdToTransportId(node->id()), | |
| 165 TypeConverter<EventPtr, ui::Event>::ConvertFrom(*event)); | |
| 166 } | 158 } |
| 167 | 159 |
| 168 void RootNodeManager::ProcessNodeBoundsChanged(const Node* node, | 160 void RootNodeManager::ProcessNodeBoundsChanged(const Node* node, |
| 169 const gfx::Rect& old_bounds, | 161 const gfx::Rect& old_bounds, |
| 170 const gfx::Rect& new_bounds) { | 162 const gfx::Rect& new_bounds) { |
| 171 for (ConnectionMap::iterator i = connection_map_.begin(); | 163 for (ConnectionMap::iterator i = connection_map_.begin(); |
| 172 i != connection_map_.end(); ++i) { | 164 i != connection_map_.end(); ++i) { |
| 173 i->second->ProcessNodeBoundsChanged(node, old_bounds, new_bounds, | 165 i->second->ProcessNodeBoundsChanged(node, old_bounds, new_bounds, |
| 174 IsChangeSource(i->first)); | 166 IsChangeSource(i->first)); |
| 175 } | 167 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 195 } | 187 } |
| 196 } | 188 } |
| 197 | 189 |
| 198 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { | 190 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { |
| 199 for (ConnectionMap::iterator i = connection_map_.begin(); | 191 for (ConnectionMap::iterator i = connection_map_.begin(); |
| 200 i != connection_map_.end(); ++i) { | 192 i != connection_map_.end(); ++i) { |
| 201 i->second->ProcessNodeDeleted(node, IsChangeSource(i->first)); | 193 i->second->ProcessNodeDeleted(node, IsChangeSource(i->first)); |
| 202 } | 194 } |
| 203 } | 195 } |
| 204 | 196 |
| 205 void RootNodeManager::OnWindowFocused(aura::Window* gained_focus, | |
| 206 aura::Window* lost_focus) { | |
| 207 Node* focused_node = gained_focus ? Node::NodeForWindow(gained_focus) : NULL; | |
| 208 Node* blurred_node = lost_focus ? Node::NodeForWindow(lost_focus) : NULL; | |
| 209 for (ConnectionMap::iterator i = connection_map_.begin(); | |
| 210 i != connection_map_.end(); ++i) { | |
| 211 i->second->ProcessFocusChanged(focused_node, blurred_node, | |
| 212 IsChangeSource(i->first)); | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 void RootNodeManager::PrepareForChange(ScopedChange* change) { | 197 void RootNodeManager::PrepareForChange(ScopedChange* change) { |
| 217 // Should only ever have one change in flight. | 198 // Should only ever have one change in flight. |
| 218 CHECK(!current_change_); | 199 CHECK(!current_change_); |
| 219 current_change_ = change; | 200 current_change_ = change; |
| 220 } | 201 } |
| 221 | 202 |
| 222 void RootNodeManager::FinishChange() { | 203 void RootNodeManager::FinishChange() { |
| 223 // PrepareForChange/FinishChange should be balanced. | 204 // PrepareForChange/FinishChange should be balanced. |
| 224 CHECK(current_change_); | 205 CHECK(current_change_); |
| 225 current_change_ = NULL; | 206 current_change_ = NULL; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 if (!root_view_manager_.in_setup()) | 247 if (!root_view_manager_.in_setup()) |
| 267 ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 248 ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
| 268 } | 249 } |
| 269 | 250 |
| 270 void RootNodeManager::OnNodeBoundsChanged(const Node* node, | 251 void RootNodeManager::OnNodeBoundsChanged(const Node* node, |
| 271 const gfx::Rect& old_bounds, | 252 const gfx::Rect& old_bounds, |
| 272 const gfx::Rect& new_bounds) { | 253 const gfx::Rect& new_bounds) { |
| 273 ProcessNodeBoundsChanged(node, old_bounds, new_bounds); | 254 ProcessNodeBoundsChanged(node, old_bounds, new_bounds); |
| 274 } | 255 } |
| 275 | 256 |
| 276 void RootNodeManager::OnNodeInputEvent(const Node* node, | |
| 277 const ui::Event* event) { | |
| 278 DispatchNodeInputEventToWindowManager(node, event); | |
| 279 } | |
| 280 | |
| 281 } // namespace service | 257 } // namespace service |
| 282 } // namespace mojo | 258 } // namespace mojo |
| OLD | NEW |