| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_VIEWS_TREE_NODE_MODEL_H__ | 5 #ifndef CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| 6 #define CHROME_VIEWS_TREE_NODE_MODEL_H__ | 6 #define CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Removes the node by index. This does NOT delete the specified node, it is | 85 // Removes the node by index. This does NOT delete the specified node, it is |
| 86 // up to the caller to delete it when done. | 86 // up to the caller to delete it when done. |
| 87 virtual NodeType* Remove(int index) { | 87 virtual NodeType* Remove(int index) { |
| 88 DCHECK(index >= 0 && index < GetChildCount()); | 88 DCHECK(index >= 0 && index < GetChildCount()); |
| 89 NodeType* node = GetChild(index); | 89 NodeType* node = GetChild(index); |
| 90 node->parent_ = NULL; | 90 node->parent_ = NULL; |
| 91 children_->erase(index + children_->begin()); | 91 children_->erase(index + children_->begin()); |
| 92 return node; | 92 return node; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Returns the children. | |
| 96 std::vector<NodeType*> GetChildren() { | |
| 97 return children_->v; | |
| 98 } | |
| 99 | |
| 100 // Returns the number of children. | 95 // Returns the number of children. |
| 101 int GetChildCount() { | 96 int GetChildCount() { |
| 102 return static_cast<int>(children_->size()); | 97 return static_cast<int>(children_->size()); |
| 103 } | 98 } |
| 104 | 99 |
| 105 // Returns a child by index. | 100 // Returns a child by index. |
| 106 NodeType* GetChild(int index) { | 101 NodeType* GetChild(int index) { |
| 107 DCHECK(index >= 0 && index < GetChildCount()); | 102 DCHECK(index >= 0 && index < GetChildCount()); |
| 108 return children_[index]; | 103 return children_[index]; |
| 109 } | 104 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 139 // Returns true if this == ancestor, or one of this nodes parents is | 134 // Returns true if this == ancestor, or one of this nodes parents is |
| 140 // ancestor. | 135 // ancestor. |
| 141 bool HasAncestor(NodeType* ancestor) const { | 136 bool HasAncestor(NodeType* ancestor) const { |
| 142 if (ancestor == this) | 137 if (ancestor == this) |
| 143 return true; | 138 return true; |
| 144 if (!ancestor) | 139 if (!ancestor) |
| 145 return false; | 140 return false; |
| 146 return parent_ ? parent_->HasAncestor(ancestor) : false; | 141 return parent_ ? parent_->HasAncestor(ancestor) : false; |
| 147 } | 142 } |
| 148 | 143 |
| 144 protected: |
| 145 std::vector<NodeType*>& children() { return children_.get(); } |
| 146 |
| 149 private: | 147 private: |
| 150 // Title displayed in the tree. | 148 // Title displayed in the tree. |
| 151 std::wstring title_; | 149 std::wstring title_; |
| 152 | 150 |
| 153 NodeType* parent_; | 151 NodeType* parent_; |
| 154 | 152 |
| 155 // Children. | 153 // Children. |
| 156 ScopedVector<NodeType> children_; | 154 ScopedVector<NodeType> children_; |
| 157 | 155 |
| 158 DISALLOW_COPY_AND_ASSIGN(TreeNode); | 156 DISALLOW_COPY_AND_ASSIGN(TreeNode); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 265 |
| 268 // The observer. | 266 // The observer. |
| 269 TreeModelObserver* observer_; | 267 TreeModelObserver* observer_; |
| 270 | 268 |
| 271 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); | 269 DISALLOW_COPY_AND_ASSIGN(TreeNodeModel); |
| 272 }; | 270 }; |
| 273 | 271 |
| 274 } // namespace views | 272 } // namespace views |
| 275 | 273 |
| 276 #endif // CHROME_VIEWS_TREE_NODE_MODEL_H__ | 274 #endif // CHROME_VIEWS_TREE_NODE_MODEL_H__ |
| 277 | |
| OLD | NEW |