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

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

Issue 383763003: Trigger Node destruction notifications from Node's dtor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | « no previous file | 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 "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 19 matching lines...) Expand all
30 window_.set_owned_by_parent(false); 30 window_.set_owned_by_parent(false);
31 window_.AddObserver(this); 31 window_.AddObserver(this);
32 window_.SetProperty(kNodeKey, this); 32 window_.SetProperty(kNodeKey, this);
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);
41 // This is implicitly done during deletion of the window, but we do it here so 40 // This is implicitly done during deletion of the window, but we do it here so
42 // that we're in a known state. 41 // that we're in a known state.
43 if (window_.parent()) 42 if (window_.parent())
44 window_.parent()->RemoveChild(&window_); 43 window_.parent()->RemoveChild(&window_);
44
45 // This must be done *after* updating the hierarchy since the hierarchy change
46 // will remove the node from the connections that know about it, preventing
47 // this notification from being sent after the destruction notification.
48 SetView(NULL);
49
50 delegate_->OnNodeDestroyed(this);
45 } 51 }
46 52
47 // static 53 // static
48 Node* Node::NodeForWindow(aura::Window* window) { 54 Node* Node::NodeForWindow(aura::Window* window) {
49 return window->GetProperty(kNodeKey); 55 return window->GetProperty(kNodeKey);
50 } 56 }
51 57
52 const Node* Node::GetParent() const { 58 const Node* Node::GetParent() const {
53 if (!window_.parent()) 59 if (!window_.parent())
54 return NULL; 60 return NULL;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 132 }
127 133
128 void Node::OnWindowHierarchyChanged( 134 void Node::OnWindowHierarchyChanged(
129 const aura::WindowObserver::HierarchyChangeParams& params) { 135 const aura::WindowObserver::HierarchyChangeParams& params) {
130 if (params.target != &window_ || params.receiver != &window_) 136 if (params.target != &window_ || params.receiver != &window_)
131 return; 137 return;
132 const Node* new_parent = params.new_parent ? 138 const Node* new_parent = params.new_parent ?
133 params.new_parent->GetProperty(kNodeKey) : NULL; 139 params.new_parent->GetProperty(kNodeKey) : NULL;
134 const Node* old_parent = params.old_parent ? 140 const Node* old_parent = params.old_parent ?
135 params.old_parent->GetProperty(kNodeKey) : NULL; 141 params.old_parent->GetProperty(kNodeKey) : NULL;
136 delegate_->OnNodeHierarchyChanged(this, new_parent, old_parent); 142 // This check is needed because even the root Node's aura::Window has a
143 // parent, but the Node itself has no parent (so it's possible for us to
144 // receive this notification from aura when no logical Node hierarchy change
145 // has actually ocurred).
146 if (new_parent != old_parent)
147 delegate_->OnNodeHierarchyChanged(this, new_parent, old_parent);
137 } 148 }
138 149
139 gfx::Size Node::GetMinimumSize() const { 150 gfx::Size Node::GetMinimumSize() const {
140 return gfx::Size(); 151 return gfx::Size();
141 } 152 }
142 153
143 gfx::Size Node::GetMaximumSize() const { 154 gfx::Size Node::GetMaximumSize() const {
144 return gfx::Size(); 155 return gfx::Size();
145 } 156 }
146 157
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 208 }
198 209
199 void Node::OnEvent(ui::Event* event) { 210 void Node::OnEvent(ui::Event* event) {
200 if (view_) 211 if (view_)
201 delegate_->OnViewInputEvent(view_, event); 212 delegate_->OnViewInputEvent(view_, event);
202 } 213 }
203 214
204 } // namespace service 215 } // namespace service
205 } // namespace view_manager 216 } // namespace view_manager
206 } // namespace mojo 217 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/services/view_manager/node_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698