| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 window_.RemoveChild(&child->window_); | 54 window_.RemoveChild(&child->window_); |
| 55 } | 55 } |
| 56 | 56 |
| 57 const Node* Node::GetRoot() const { | 57 const Node* Node::GetRoot() const { |
| 58 const aura::Window* window = &window_; | 58 const aura::Window* window = &window_; |
| 59 while (window && window->parent()) | 59 while (window && window->parent()) |
| 60 window = window->parent(); | 60 window = window->parent(); |
| 61 return window->GetProperty(kNodeKey); | 61 return window->GetProperty(kNodeKey); |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::vector<const Node*> Node::GetChildren() const { |
| 65 std::vector<const Node*> children; |
| 66 children.reserve(window_.children().size()); |
| 67 for (size_t i = 0; i < window_.children().size(); ++i) |
| 68 children.push_back(window_.children()[i]->GetProperty(kNodeKey)); |
| 69 return children; |
| 70 } |
| 71 |
| 64 std::vector<Node*> Node::GetChildren() { | 72 std::vector<Node*> Node::GetChildren() { |
| 65 std::vector<Node*> children; | 73 std::vector<Node*> children; |
| 66 children.reserve(window_.children().size()); | 74 children.reserve(window_.children().size()); |
| 67 for (size_t i = 0; i < window_.children().size(); ++i) | 75 for (size_t i = 0; i < window_.children().size(); ++i) |
| 68 children.push_back(window_.children()[i]->GetProperty(kNodeKey)); | 76 children.push_back(window_.children()[i]->GetProperty(kNodeKey)); |
| 69 return children; | 77 return children; |
| 70 } | 78 } |
| 71 | 79 |
| 72 bool Node::Contains(const Node* node) const { | 80 bool Node::Contains(const Node* node) const { |
| 73 return node && window_.Contains(&(node->window_)); | 81 return node && window_.Contains(&(node->window_)); |
| 74 } | 82 } |
| 75 | 83 |
| 76 void Node::SetView(View* view) { | 84 void Node::SetView(View* view) { |
| 77 if (view == view_) | 85 if (view == view_) |
| 78 return; | 86 return; |
| 79 | 87 |
| 80 // Detach view from existing node. This way notifications are sent out. | 88 // Detach view from existing node. This way notifications are sent out. |
| 81 if (view && view->node()) | 89 if (view && view->node()) |
| 82 view->node()->SetView(NULL); | 90 view->node()->SetView(NULL); |
| 83 | 91 |
| 84 ViewId old_view_id; | 92 View* old_view = view_; |
| 85 if (view_) { | 93 if (view_) |
| 86 view_->set_node(NULL); | 94 view_->set_node(NULL); |
| 87 old_view_id = view_->id(); | |
| 88 } | |
| 89 view_ = view; | 95 view_ = view; |
| 90 ViewId view_id; | 96 if (view) |
| 91 if (view) { | |
| 92 view_id = view->id(); | |
| 93 view->set_node(this); | 97 view->set_node(this); |
| 94 } | 98 delegate_->OnNodeViewReplaced(this, view, old_view); |
| 95 delegate_->OnNodeViewReplaced(id_, view_id, old_view_id); | |
| 96 } | 99 } |
| 97 | 100 |
| 98 void Node::OnWindowHierarchyChanged( | 101 void Node::OnWindowHierarchyChanged( |
| 99 const aura::WindowObserver::HierarchyChangeParams& params) { | 102 const aura::WindowObserver::HierarchyChangeParams& params) { |
| 100 if (params.target != &window_ || params.receiver != &window_) | 103 if (params.target != &window_ || params.receiver != &window_) |
| 101 return; | 104 return; |
| 102 NodeId new_parent_id; | 105 const Node* new_parent = params.new_parent ? |
| 103 if (params.new_parent && params.new_parent->GetProperty(kNodeKey)) | 106 params.new_parent->GetProperty(kNodeKey) : NULL; |
| 104 new_parent_id = params.new_parent->GetProperty(kNodeKey)->id(); | 107 const Node* old_parent = params.old_parent ? |
| 105 NodeId old_parent_id; | 108 params.old_parent->GetProperty(kNodeKey) : NULL; |
| 106 if (params.old_parent && params.old_parent->GetProperty(kNodeKey)) | 109 delegate_->OnNodeHierarchyChanged(this, new_parent, old_parent); |
| 107 old_parent_id = params.old_parent->GetProperty(kNodeKey)->id(); | |
| 108 delegate_->OnNodeHierarchyChanged(id_, new_parent_id, old_parent_id); | |
| 109 } | 110 } |
| 110 | 111 |
| 111 gfx::Size Node::GetMinimumSize() const { | 112 gfx::Size Node::GetMinimumSize() const { |
| 112 return gfx::Size(); | 113 return gfx::Size(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 gfx::Size Node::GetMaximumSize() const { | 116 gfx::Size Node::GetMaximumSize() const { |
| 116 return gfx::Size(); | 117 return gfx::Size(); |
| 117 } | 118 } |
| 118 | 119 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 bool Node::HasHitTestMask() const { | 164 bool Node::HasHitTestMask() const { |
| 164 return false; | 165 return false; |
| 165 } | 166 } |
| 166 | 167 |
| 167 void Node::GetHitTestMask(gfx::Path* mask) const { | 168 void Node::GetHitTestMask(gfx::Path* mask) const { |
| 168 } | 169 } |
| 169 | 170 |
| 170 } // namespace service | 171 } // namespace service |
| 171 } // namespace view_manager | 172 } // namespace view_manager |
| 172 } // namespace mojo | 173 } // namespace mojo |
| OLD | NEW |