| 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 #ifndef MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
| 6 #define MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 11 #include "mojo/services/view_manager/ids.h" | 12 #include "mojo/services/view_manager/ids.h" |
| 12 #include "mojo/services/view_manager/node.h" | 13 #include "mojo/services/view_manager/node.h" |
| 13 #include "mojo/services/view_manager/node_delegate.h" | 14 #include "mojo/services/view_manager/node_delegate.h" |
| 14 #include "mojo/services/view_manager/root_view_manager.h" | |
| 15 #include "mojo/services/view_manager/view_manager_export.h" | 15 #include "mojo/services/view_manager/view_manager_export.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 | |
| 19 class Shell; | |
| 20 | |
| 21 namespace services { | 18 namespace services { |
| 22 namespace view_manager { | 19 namespace view_manager { |
| 23 | 20 |
| 24 class View; | 21 class View; |
| 25 class ViewManagerConnection; | 22 class ViewManagerConnection; |
| 26 | 23 |
| 27 // RootNodeManager is responsible for managing the set of ViewManagerConnections | 24 // RootNodeManager is responsible for managing the set of ViewManagerConnections |
| 28 // as well as providing the root of the node hierarchy. | 25 // as well as providing the root of the node hierarchy. |
| 29 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { | 26 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager |
| 27 : public NativeViewportClient, |
| 28 public NodeDelegate { |
| 30 public: | 29 public: |
| 31 // Create when a ViewManagerConnection is about to make a change. Ensures | 30 // Create when a ViewManagerConnection is about to make a change. Ensures |
| 32 // clients are notified of the correct change id. | 31 // clients are notified of the correct change id. |
| 33 class ScopedChange { | 32 class ScopedChange { |
| 34 public: | 33 public: |
| 35 ScopedChange(ViewManagerConnection* connection, | 34 ScopedChange(ViewManagerConnection* connection, |
| 36 RootNodeManager* root, | 35 RootNodeManager* root, |
| 37 TransportChangeId change_id); | 36 TransportChangeId change_id); |
| 38 ~ScopedChange(); | 37 ~ScopedChange(); |
| 39 | 38 |
| 40 private: | 39 private: |
| 41 RootNodeManager* root_; | 40 RootNodeManager* root_; |
| 42 | 41 |
| 43 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 42 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
| 44 }; | 43 }; |
| 45 | 44 |
| 46 explicit RootNodeManager(Shell* shell); | 45 RootNodeManager(); |
| 47 virtual ~RootNodeManager(); | 46 virtual ~RootNodeManager(); |
| 48 | 47 |
| 49 // Returns the id for the next ViewManagerConnection. | 48 // Returns the id for the next ViewManagerConnection. |
| 50 TransportConnectionId GetAndAdvanceNextConnectionId(); | 49 TransportConnectionId GetAndAdvanceNextConnectionId(); |
| 51 | 50 |
| 52 void AddConnection(ViewManagerConnection* connection); | 51 void AddConnection(ViewManagerConnection* connection); |
| 53 void RemoveConnection(ViewManagerConnection* connection); | 52 void RemoveConnection(ViewManagerConnection* connection); |
| 54 | 53 |
| 55 // Returns the connection by id. | 54 // Returns the connection by id. |
| 56 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); | 55 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); |
| 57 | 56 |
| 58 // Returns the Node identified by |id|. | 57 // Returns the Node identified by |id|. |
| 59 Node* GetNode(const NodeId& id); | 58 Node* GetNode(const NodeId& id); |
| 60 | 59 |
| 61 // Returns the View identified by |id|. | 60 // Returns the View identified by |id|. |
| 62 View* GetView(const ViewId& id); | 61 View* GetView(const ViewId& id); |
| 63 | 62 |
| 64 Node* root() { return &root_; } | |
| 65 | |
| 66 // These functions trivially delegate to all ViewManagerConnections, which in | 63 // These functions trivially delegate to all ViewManagerConnections, which in |
| 67 // term notify their clients. | 64 // term notify their clients. |
| 68 void NotifyNodeHierarchyChanged(const NodeId& node, | 65 void NotifyNodeHierarchyChanged(const NodeId& node, |
| 69 const NodeId& new_parent, | 66 const NodeId& new_parent, |
| 70 const NodeId& old_parent); | 67 const NodeId& old_parent); |
| 71 void NotifyNodeViewReplaced(const NodeId& node, | 68 void NotifyNodeViewReplaced(const NodeId& node, |
| 72 const ViewId& new_view_id, | 69 const ViewId& new_view_id, |
| 73 const ViewId& old_view_id); | 70 const ViewId& old_view_id); |
| 74 | 71 |
| 75 private: | 72 private: |
| 76 // Used to setup any static state needed by RootNodeManager. | |
| 77 struct Context { | |
| 78 Context(); | |
| 79 ~Context(); | |
| 80 }; | |
| 81 | |
| 82 // Tracks a change. | 73 // Tracks a change. |
| 83 struct Change { | 74 struct Change { |
| 84 Change(TransportConnectionId connection_id, TransportChangeId change_id) | 75 Change(TransportConnectionId connection_id, TransportChangeId change_id) |
| 85 : connection_id(connection_id), | 76 : connection_id(connection_id), |
| 86 change_id(change_id) { | 77 change_id(change_id) { |
| 87 } | 78 } |
| 88 | 79 |
| 89 TransportConnectionId connection_id; | 80 TransportConnectionId connection_id; |
| 90 TransportChangeId change_id; | 81 TransportChangeId change_id; |
| 91 }; | 82 }; |
| 92 | 83 |
| 93 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; | 84 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; |
| 94 | 85 |
| 95 // Invoked when a particular connection is about to make a change. Records | 86 // Invoked when a particular connection is about to make a change. Records |
| 96 // the |change_id| so that it can be supplied to the clients by way of | 87 // the |change_id| so that it can be supplied to the clients by way of |
| 97 // OnNodeHierarchyChanged(). | 88 // OnNodeHierarchyChanged(). |
| 98 // Changes should never nest, meaning each PrepareForChange() must be | 89 // Changes should never nest, meaning each PrepareForChange() must be |
| 99 // balanced with a call to FinishChange() with no PrepareForChange() | 90 // balanced with a call to FinishChange() with no PrepareForChange() |
| 100 // in between. | 91 // in between. |
| 101 void PrepareForChange(ViewManagerConnection* connection, | 92 void PrepareForChange(ViewManagerConnection* connection, |
| 102 TransportChangeId change_id); | 93 TransportChangeId change_id); |
| 103 | 94 |
| 104 // Balances a call to PrepareForChange(). | 95 // Balances a call to PrepareForChange(). |
| 105 void FinishChange(); | 96 void FinishChange(); |
| 106 | 97 |
| 98 // Overridden from NativeViewportClient: |
| 99 virtual void OnCreated() OVERRIDE; |
| 100 virtual void OnDestroyed() OVERRIDE; |
| 101 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE; |
| 102 virtual void OnEvent(const Event& event, |
| 103 const mojo::Callback<void()>& callback) OVERRIDE; |
| 104 |
| 107 // Overriden from NodeDelegate: | 105 // Overriden from NodeDelegate: |
| 108 virtual void OnNodeHierarchyChanged(const NodeId& node, | 106 virtual void OnNodeHierarchyChanged(const NodeId& node, |
| 109 const NodeId& new_parent, | 107 const NodeId& new_parent, |
| 110 const NodeId& old_parent) OVERRIDE; | 108 const NodeId& old_parent) OVERRIDE; |
| 111 virtual void OnNodeViewReplaced(const NodeId& node, | 109 virtual void OnNodeViewReplaced(const NodeId& node, |
| 112 const ViewId& new_view_id, | 110 const ViewId& new_view_id, |
| 113 const ViewId& old_view_id) OVERRIDE; | 111 const ViewId& old_view_id) OVERRIDE; |
| 114 | 112 |
| 115 Context context_; | |
| 116 | |
| 117 // ID to use for next ViewManagerConnection. | 113 // ID to use for next ViewManagerConnection. |
| 118 TransportConnectionId next_connection_id_; | 114 TransportConnectionId next_connection_id_; |
| 119 | 115 |
| 120 // Set of ViewManagerConnections. | 116 // Set of ViewManagerConnections. |
| 121 ConnectionMap connection_map_; | 117 ConnectionMap connection_map_; |
| 122 | 118 |
| 119 // Root node. |
| 120 Node root_; |
| 121 |
| 123 // If non-null we're processing a change. | 122 // If non-null we're processing a change. |
| 124 scoped_ptr<Change> change_; | 123 scoped_ptr<Change> change_; |
| 125 | 124 |
| 126 RootViewManager root_view_manager_; | |
| 127 | |
| 128 // Root node. | |
| 129 Node root_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); | 125 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); |
| 132 }; | 126 }; |
| 133 | 127 |
| 134 } // namespace view_manager | 128 } // namespace view_manager |
| 135 } // namespace services | 129 } // namespace services |
| 136 } // namespace mojo | 130 } // namespace mojo |
| 137 | 131 |
| 138 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 132 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
| OLD | NEW |