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_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ | 5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ |
6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ | 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 12 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 namespace services { | 15 namespace services { |
16 namespace view_manager { | 16 namespace view_manager { |
17 | 17 |
18 class ViewManager; | 18 class ViewManager; |
19 class ViewTreeNodeObserver; | 19 class ViewTreeNodeObserver; |
20 | 20 |
21 // ViewTreeNodes are owned by the ViewManager. | |
22 // TODO(beng): Right now, you'll have to implement a ViewTreeNodeObserver to | |
23 // track destruction and NULL any pointers you have. | |
24 // Investigate some kind of smart pointer or weak pointer for these. | |
25 class ViewTreeNode { | 21 class ViewTreeNode { |
26 public: | 22 public: |
27 typedef std::vector<ViewTreeNode*> Children; | 23 typedef std::vector<ViewTreeNode*> Children; |
28 | 24 |
29 static ViewTreeNode* Create(ViewManager* view_manager); | 25 explicit ViewTreeNode(ViewManager* manager); |
30 | 26 ViewTreeNode(); // Used for tests. |
31 // Destroys this node and all its children. | 27 ~ViewTreeNode(); |
32 void Destroy(); | |
33 | 28 |
34 // Configuration. | 29 // Configuration. |
35 TransportNodeId id() const { return id_; } | 30 TransportNodeId id() const { return id_; } |
| 31 void set_owned_by_parent(bool owned_by_parent) { |
| 32 owned_by_parent_ = owned_by_parent; |
| 33 } |
36 | 34 |
37 // Observation. | 35 // Observation. |
38 void AddObserver(ViewTreeNodeObserver* observer); | 36 void AddObserver(ViewTreeNodeObserver* observer); |
39 void RemoveObserver(ViewTreeNodeObserver* observer); | 37 void RemoveObserver(ViewTreeNodeObserver* observer); |
40 | 38 |
41 // Tree. | 39 // Tree. |
42 ViewTreeNode* parent() { return parent_; } | 40 ViewTreeNode* parent() { return parent_; } |
43 const ViewTreeNode* parent() const { return parent_; } | 41 const ViewTreeNode* parent() const { return parent_; } |
44 const Children& children() const { return children_; } | 42 const Children& children() const { return children_; } |
45 | 43 |
46 void AddChild(ViewTreeNode* child); | 44 void AddChild(ViewTreeNode* child); |
47 void RemoveChild(ViewTreeNode* child); | 45 void RemoveChild(ViewTreeNode* child); |
48 | 46 |
49 bool Contains(ViewTreeNode* child) const; | 47 bool Contains(ViewTreeNode* child) const; |
50 | 48 |
51 ViewTreeNode* GetChildById(TransportNodeId id); | 49 ViewTreeNode* GetChildById(TransportNodeId id); |
52 | 50 |
53 protected: | |
54 // This class is subclassed only by test classes that provide a public ctor. | |
55 ViewTreeNode(); | |
56 ~ViewTreeNode(); | |
57 | |
58 private: | 51 private: |
59 friend class ViewTreeNodePrivate; | 52 friend class ViewTreeNodePrivate; |
60 | 53 |
61 explicit ViewTreeNode(ViewManager* manager); | |
62 | |
63 void LocalDestroy(); | |
64 void LocalAddChild(ViewTreeNode* child); | 54 void LocalAddChild(ViewTreeNode* child); |
65 void LocalRemoveChild(ViewTreeNode* child); | 55 void LocalRemoveChild(ViewTreeNode* child); |
66 | 56 |
67 ViewManager* manager_; | 57 ViewManager* manager_; |
68 TransportNodeId id_; | 58 TransportNodeId id_; |
| 59 bool owned_by_parent_; |
69 ViewTreeNode* parent_; | 60 ViewTreeNode* parent_; |
70 Children children_; | 61 Children children_; |
71 | 62 |
72 ObserverList<ViewTreeNodeObserver> observers_; | 63 ObserverList<ViewTreeNodeObserver> observers_; |
73 | 64 |
74 DISALLOW_COPY_AND_ASSIGN(ViewTreeNode); | 65 DISALLOW_COPY_AND_ASSIGN(ViewTreeNode); |
75 }; | 66 }; |
76 | 67 |
77 } // namespace view_manager | 68 } // namespace view_manager |
78 } // namespace services | 69 } // namespace services |
79 } // namespace mojo | 70 } // namespace mojo |
80 | 71 |
81 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ | 72 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ |
OLD | NEW |