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. |
21 class ViewTreeNode { | 25 class ViewTreeNode { |
22 public: | 26 public: |
23 typedef std::vector<ViewTreeNode*> Children; | 27 typedef std::vector<ViewTreeNode*> Children; |
24 | 28 |
25 explicit ViewTreeNode(ViewManager* manager); | 29 static ViewTreeNode* Create(ViewManager* view_manager); |
26 ViewTreeNode(); // Used for tests. | 30 |
27 ~ViewTreeNode(); | 31 // Destroys this node and all its children. |
| 32 void Destroy(); |
28 | 33 |
29 // Configuration. | 34 // Configuration. |
30 TransportNodeId id() const { return id_; } | 35 TransportNodeId id() const { return id_; } |
31 void set_owned_by_parent(bool owned_by_parent) { | |
32 owned_by_parent_ = owned_by_parent; | |
33 } | |
34 | 36 |
35 // Observation. | 37 // Observation. |
36 void AddObserver(ViewTreeNodeObserver* observer); | 38 void AddObserver(ViewTreeNodeObserver* observer); |
37 void RemoveObserver(ViewTreeNodeObserver* observer); | 39 void RemoveObserver(ViewTreeNodeObserver* observer); |
38 | 40 |
39 // Tree. | 41 // Tree. |
40 ViewTreeNode* parent() { return parent_; } | 42 ViewTreeNode* parent() { return parent_; } |
41 const ViewTreeNode* parent() const { return parent_; } | 43 const ViewTreeNode* parent() const { return parent_; } |
42 const Children& children() const { return children_; } | 44 const Children& children() const { return children_; } |
43 | 45 |
44 void AddChild(ViewTreeNode* child); | 46 void AddChild(ViewTreeNode* child); |
45 void RemoveChild(ViewTreeNode* child); | 47 void RemoveChild(ViewTreeNode* child); |
46 | 48 |
47 bool Contains(ViewTreeNode* child) const; | 49 bool Contains(ViewTreeNode* child) const; |
48 | 50 |
49 ViewTreeNode* GetChildById(TransportNodeId id); | 51 ViewTreeNode* GetChildById(TransportNodeId id); |
50 | 52 |
| 53 protected: |
| 54 // This class is subclassed only by test classes that provide a public ctor. |
| 55 ViewTreeNode(); |
| 56 ~ViewTreeNode(); |
| 57 |
51 private: | 58 private: |
52 friend class ViewTreeNodePrivate; | 59 friend class ViewTreeNodePrivate; |
53 | 60 |
| 61 explicit ViewTreeNode(ViewManager* manager); |
| 62 |
| 63 void LocalDestroy(); |
54 void LocalAddChild(ViewTreeNode* child); | 64 void LocalAddChild(ViewTreeNode* child); |
55 void LocalRemoveChild(ViewTreeNode* child); | 65 void LocalRemoveChild(ViewTreeNode* child); |
56 | 66 |
57 ViewManager* manager_; | 67 ViewManager* manager_; |
58 TransportNodeId id_; | 68 TransportNodeId id_; |
59 bool owned_by_parent_; | |
60 ViewTreeNode* parent_; | 69 ViewTreeNode* parent_; |
61 Children children_; | 70 Children children_; |
62 | 71 |
63 ObserverList<ViewTreeNodeObserver> observers_; | 72 ObserverList<ViewTreeNodeObserver> observers_; |
64 | 73 |
65 DISALLOW_COPY_AND_ASSIGN(ViewTreeNode); | 74 DISALLOW_COPY_AND_ASSIGN(ViewTreeNode); |
66 }; | 75 }; |
67 | 76 |
68 } // namespace view_manager | 77 } // namespace view_manager |
69 } // namespace services | 78 } // namespace services |
70 } // namespace mojo | 79 } // namespace mojo |
71 | 80 |
72 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ | 81 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TREE_NODE_H_ |
OLD | NEW |