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/node.h" | 5 #include "mojo/services/view_manager/node.h" |
6 | 6 |
7 #include "mojo/services/view_manager/node_delegate.h" | 7 #include "mojo/services/view_manager/node_delegate.h" |
8 #include "mojo/services/view_manager/view.h" | 8 #include "mojo/services/view_manager/view.h" |
9 #include "ui/aura/window_property.h" | 9 #include "ui/aura/window_property.h" |
10 #include "ui/base/cursor/cursor.h" | 10 #include "ui/base/cursor/cursor.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 window_.Init(aura::WINDOW_LAYER_TEXTURED); | 33 window_.Init(aura::WINDOW_LAYER_TEXTURED); |
34 | 34 |
35 // TODO(sky): this likely needs to be false and add a visibility API. | 35 // TODO(sky): this likely needs to be false and add a visibility API. |
36 window_.Show(); | 36 window_.Show(); |
37 } | 37 } |
38 | 38 |
39 Node::~Node() { | 39 Node::~Node() { |
40 SetView(NULL); | 40 SetView(NULL); |
41 } | 41 } |
42 | 42 |
43 Node* Node::GetParent() { | 43 const Node* Node::GetParent() const { |
44 if (!window_.parent()) | 44 if (!window_.parent()) |
45 return NULL; | 45 return NULL; |
46 return window_.parent()->GetProperty(kNodeKey); | 46 return window_.parent()->GetProperty(kNodeKey); |
47 } | 47 } |
48 | 48 |
49 void Node::Add(Node* child) { | 49 void Node::Add(Node* child) { |
50 window_.AddChild(&child->window_); | 50 window_.AddChild(&child->window_); |
51 } | 51 } |
52 | 52 |
53 void Node::Remove(Node* child) { | 53 void Node::Remove(Node* child) { |
54 window_.RemoveChild(&child->window_); | 54 window_.RemoveChild(&child->window_); |
55 } | 55 } |
56 | 56 |
| 57 const Node* Node::GetRoot() const { |
| 58 const aura::Window* window = &window_; |
| 59 while (window && window->parent()) |
| 60 window = window->parent(); |
| 61 return window->GetProperty(kNodeKey); |
| 62 } |
| 63 |
57 std::vector<Node*> Node::GetChildren() { | 64 std::vector<Node*> Node::GetChildren() { |
58 std::vector<Node*> children; | 65 std::vector<Node*> children; |
59 children.reserve(window_.children().size()); | 66 children.reserve(window_.children().size()); |
60 for (size_t i = 0; i < window_.children().size(); ++i) | 67 for (size_t i = 0; i < window_.children().size(); ++i) |
61 children.push_back(window_.children()[i]->GetProperty(kNodeKey)); | 68 children.push_back(window_.children()[i]->GetProperty(kNodeKey)); |
62 return children; | 69 return children; |
63 } | 70 } |
64 | 71 |
| 72 bool Node::Contains(const Node* node) const { |
| 73 return node && window_.Contains(&(node->window_)); |
| 74 } |
| 75 |
65 void Node::SetView(View* view) { | 76 void Node::SetView(View* view) { |
66 if (view == view_) | 77 if (view == view_) |
67 return; | 78 return; |
68 | 79 |
69 // Detach view from existing node. This way notifications are sent out. | 80 // Detach view from existing node. This way notifications are sent out. |
70 if (view && view->node()) | 81 if (view && view->node()) |
71 view->node()->SetView(NULL); | 82 view->node()->SetView(NULL); |
72 | 83 |
73 ViewId old_view_id; | 84 ViewId old_view_id; |
74 if (view_) { | 85 if (view_) { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 bool Node::HasHitTestMask() const { | 163 bool Node::HasHitTestMask() const { |
153 return false; | 164 return false; |
154 } | 165 } |
155 | 166 |
156 void Node::GetHitTestMask(gfx::Path* mask) const { | 167 void Node::GetHitTestMask(gfx::Path* mask) const { |
157 } | 168 } |
158 | 169 |
159 } // namespace service | 170 } // namespace service |
160 } // namespace view_manager | 171 } // namespace view_manager |
161 } // namespace mojo | 172 } // namespace mojo |
OLD | NEW |