Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: mojo/services/view_manager/node.cc

Issue 250633003: Adds more to viewmanager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: override Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/services/view_manager/node.h ('k') | mojo/services/view_manager/node_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/aura/window_property.h" 9 #include "ui/aura/window_property.h"
9 10
10 DECLARE_WINDOW_PROPERTY_TYPE(mojo::services::view_manager::Node*); 11 DECLARE_WINDOW_PROPERTY_TYPE(mojo::services::view_manager::Node*);
11 12
12 namespace mojo { 13 namespace mojo {
13 namespace services { 14 namespace services {
14 namespace view_manager { 15 namespace view_manager {
15 16
16 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL); 17 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL);
17 18
18 Node::Node(NodeDelegate* delegate, const NodeId& id) 19 Node::Node(NodeDelegate* delegate, const NodeId& id)
19 : delegate_(delegate), 20 : delegate_(delegate),
20 id_(id), 21 id_(id),
22 view_(NULL),
21 window_(NULL) { 23 window_(NULL) {
22 DCHECK(delegate); // Must provide a delegate. 24 DCHECK(delegate); // Must provide a delegate.
23 window_.set_owned_by_parent(false); 25 window_.set_owned_by_parent(false);
24 window_.AddObserver(this); 26 window_.AddObserver(this);
25 window_.SetProperty(kNodeKey, this); 27 window_.SetProperty(kNodeKey, this);
26 } 28 }
27 29
28 Node::~Node() { 30 Node::~Node() {
31 SetView(NULL);
29 } 32 }
30 33
31 Node* Node::GetParent() { 34 Node* Node::GetParent() {
32 if (!window_.parent()) 35 if (!window_.parent())
33 return NULL; 36 return NULL;
34 return window_.parent()->GetProperty(kNodeKey); 37 return window_.parent()->GetProperty(kNodeKey);
35 } 38 }
36 39
37 void Node::Add(Node* child) { 40 void Node::Add(Node* child) {
38 window_.AddChild(&child->window_); 41 window_.AddChild(&child->window_);
39 } 42 }
40 43
41 void Node::Remove(Node* child) { 44 void Node::Remove(Node* child) {
42 window_.RemoveChild(&child->window_); 45 window_.RemoveChild(&child->window_);
43 } 46 }
44 47
48 std::vector<Node*> Node::GetChildren() {
49 std::vector<Node*> children;
50 children.reserve(window_.children().size());
51 for (size_t i = 0; i < window_.children().size(); ++i)
52 children.push_back(window_.children()[i]->GetProperty(kNodeKey));
53 return children;
54 }
55
56 void Node::SetView(View* view) {
57 if (view == view_)
58 return;
59
60 // Detach view from existing node. This way notifications are sent out.
61 if (view && view->node())
62 view->node()->SetView(NULL);
63
64 ViewId old_view_id;
65 if (view_) {
66 view_->set_node(NULL);
67 old_view_id = view_->id();
68 }
69 view_ = view;
70 ViewId view_id;
71 if (view) {
72 view_id = view->id();
73 view->set_node(this);
74 }
75 delegate_->OnNodeViewReplaced(id_, view_id, old_view_id);
76 }
77
45 void Node::OnWindowHierarchyChanged( 78 void Node::OnWindowHierarchyChanged(
46 const aura::WindowObserver::HierarchyChangeParams& params) { 79 const aura::WindowObserver::HierarchyChangeParams& params) {
47 if (params.target != &window_ || params.receiver != &window_) 80 if (params.target != &window_ || params.receiver != &window_)
48 return; 81 return;
49 NodeId new_parent_id; 82 NodeId new_parent_id;
50 if (params.new_parent) 83 if (params.new_parent)
51 new_parent_id = params.new_parent->GetProperty(kNodeKey)->id(); 84 new_parent_id = params.new_parent->GetProperty(kNodeKey)->id();
52 NodeId old_parent_id; 85 NodeId old_parent_id;
53 if (params.old_parent) 86 if (params.old_parent)
54 old_parent_id = params.old_parent->GetProperty(kNodeKey)->id(); 87 old_parent_id = params.old_parent->GetProperty(kNodeKey)->id();
55 delegate_->OnNodeHierarchyChanged(id_, new_parent_id, old_parent_id); 88 delegate_->OnNodeHierarchyChanged(id_, new_parent_id, old_parent_id);
56 } 89 }
57 90
58 } // namespace view_manager 91 } // namespace view_manager
59 } // namespace services 92 } // namespace services
60 } // namespace mojo 93 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/node.h ('k') | mojo/services/view_manager/node_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698