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

Side by Side Diff: mojo/services/public/cpp/view_manager/lib/node.cc

Issue 338093008: Client side name cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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
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/public/cpp/view_manager/view_tree_node.h" 5 #include "mojo/services/public/cpp/view_manager/node.h"
6 6
7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" 7 #include "mojo/services/public/cpp/view_manager/lib/node_private.h"
8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h"
8 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h"
9 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" 10 #include "mojo/services/public/cpp/view_manager/node_observer.h"
10 #include "mojo/services/public/cpp/view_manager/view.h" 11 #include "mojo/services/public/cpp/view_manager/view.h"
11 #include "mojo/services/public/cpp/view_manager/view_tree_node_observer.h"
12 12
13 namespace mojo { 13 namespace mojo {
14 namespace view_manager { 14 namespace view_manager {
15 15
16 namespace { 16 namespace {
17 17
18 void NotifyViewTreeChangeAtReceiver( 18 void NotifyViewTreeChangeAtReceiver(
19 ViewTreeNode* receiver, 19 Node* receiver,
20 const ViewTreeNodeObserver::TreeChangeParams& params) { 20 const NodeObserver::TreeChangeParams& params) {
21 ViewTreeNodeObserver::TreeChangeParams local_params = params; 21 NodeObserver::TreeChangeParams local_params = params;
22 local_params.receiver = receiver; 22 local_params.receiver = receiver;
23 FOR_EACH_OBSERVER(ViewTreeNodeObserver, 23 FOR_EACH_OBSERVER(NodeObserver,
24 *ViewTreeNodePrivate(receiver).observers(), 24 *NodePrivate(receiver).observers(),
25 OnTreeChange(local_params)); 25 OnTreeChange(local_params));
26 } 26 }
27 27
28 void NotifyViewTreeChangeUp( 28 void NotifyViewTreeChangeUp(
29 ViewTreeNode* start_at, 29 Node* start_at,
30 const ViewTreeNodeObserver::TreeChangeParams& params) { 30 const NodeObserver::TreeChangeParams& params) {
31 for (ViewTreeNode* current = start_at; current; current = current->parent()) 31 for (Node* current = start_at; current; current = current->parent())
32 NotifyViewTreeChangeAtReceiver(current, params); 32 NotifyViewTreeChangeAtReceiver(current, params);
33 } 33 }
34 34
35 void NotifyViewTreeChangeDown( 35 void NotifyViewTreeChangeDown(
36 ViewTreeNode* start_at, 36 Node* start_at,
37 const ViewTreeNodeObserver::TreeChangeParams& params) { 37 const NodeObserver::TreeChangeParams& params) {
38 NotifyViewTreeChangeAtReceiver(start_at, params); 38 NotifyViewTreeChangeAtReceiver(start_at, params);
39 ViewTreeNode::Children::const_iterator it = start_at->children().begin(); 39 Node::Children::const_iterator it = start_at->children().begin();
40 for (; it != start_at->children().end(); ++it) 40 for (; it != start_at->children().end(); ++it)
41 NotifyViewTreeChangeDown(*it, params); 41 NotifyViewTreeChangeDown(*it, params);
42 } 42 }
43 43
44 void NotifyViewTreeChange( 44 void NotifyViewTreeChange(
45 const ViewTreeNodeObserver::TreeChangeParams& params) { 45 const NodeObserver::TreeChangeParams& params) {
46 NotifyViewTreeChangeDown(params.target, params); 46 NotifyViewTreeChangeDown(params.target, params);
47 if (params.old_parent) 47 if (params.old_parent)
48 NotifyViewTreeChangeUp(params.old_parent, params); 48 NotifyViewTreeChangeUp(params.old_parent, params);
49 if (params.new_parent) 49 if (params.new_parent)
50 NotifyViewTreeChangeUp(params.new_parent, params); 50 NotifyViewTreeChangeUp(params.new_parent, params);
51 } 51 }
52 52
53 class ScopedTreeNotifier { 53 class ScopedTreeNotifier {
54 public: 54 public:
55 ScopedTreeNotifier(ViewTreeNode* target, 55 ScopedTreeNotifier(Node* target, Node* old_parent, Node* new_parent) {
56 ViewTreeNode* old_parent,
57 ViewTreeNode* new_parent) {
58 params_.target = target; 56 params_.target = target;
59 params_.old_parent = old_parent; 57 params_.old_parent = old_parent;
60 params_.new_parent = new_parent; 58 params_.new_parent = new_parent;
61 NotifyViewTreeChange(params_); 59 NotifyViewTreeChange(params_);
62 } 60 }
63 ~ScopedTreeNotifier() { 61 ~ScopedTreeNotifier() {
64 params_.phase = ViewTreeNodeObserver::DISPOSITION_CHANGED; 62 params_.phase = NodeObserver::DISPOSITION_CHANGED;
65 NotifyViewTreeChange(params_); 63 NotifyViewTreeChange(params_);
66 } 64 }
67 65
68 private: 66 private:
69 ViewTreeNodeObserver::TreeChangeParams params_; 67 NodeObserver::TreeChangeParams params_;
70 68
71 DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier); 69 DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier);
72 }; 70 };
73 71
74 void RemoveChildImpl(ViewTreeNode* child, ViewTreeNode::Children* children) { 72 void RemoveChildImpl(Node* child, Node::Children* children) {
75 ViewTreeNode::Children::iterator it = 73 Node::Children::iterator it =
76 std::find(children->begin(), children->end(), child); 74 std::find(children->begin(), children->end(), child);
77 if (it != children->end()) { 75 if (it != children->end()) {
78 children->erase(it); 76 children->erase(it);
79 ViewTreeNodePrivate(child).ClearParent(); 77 NodePrivate(child).ClearParent();
80 } 78 }
81 } 79 }
82 80
83 class ScopedOrderChangedNotifier { 81 class ScopedOrderChangedNotifier {
84 public: 82 public:
85 ScopedOrderChangedNotifier(ViewTreeNode* node, 83 ScopedOrderChangedNotifier(Node* node,
86 ViewTreeNode* relative_node, 84 Node* relative_node,
87 OrderDirection direction) 85 OrderDirection direction)
88 : node_(node), 86 : node_(node),
89 relative_node_(relative_node), 87 relative_node_(relative_node),
90 direction_(direction) { 88 direction_(direction) {
91 FOR_EACH_OBSERVER( 89 FOR_EACH_OBSERVER(
92 ViewTreeNodeObserver, 90 NodeObserver,
93 *ViewTreeNodePrivate(node_).observers(), 91 *NodePrivate(node_).observers(),
94 OnNodeReordered(node_, 92 OnNodeReordered(node_,
95 relative_node_, 93 relative_node_,
96 direction_, 94 direction_,
97 ViewTreeNodeObserver::DISPOSITION_CHANGING)); 95 NodeObserver::DISPOSITION_CHANGING));
98 96
99 } 97 }
100 ~ScopedOrderChangedNotifier() { 98 ~ScopedOrderChangedNotifier() {
101 FOR_EACH_OBSERVER( 99 FOR_EACH_OBSERVER(
102 ViewTreeNodeObserver, 100 NodeObserver,
103 *ViewTreeNodePrivate(node_).observers(), 101 *NodePrivate(node_).observers(),
104 OnNodeReordered(node_, 102 OnNodeReordered(node_,
105 relative_node_, 103 relative_node_,
106 direction_, 104 direction_,
107 ViewTreeNodeObserver::DISPOSITION_CHANGED)); 105 NodeObserver::DISPOSITION_CHANGED));
108 } 106 }
109 107
110 private: 108 private:
111 ViewTreeNode* node_; 109 Node* node_;
112 ViewTreeNode* relative_node_; 110 Node* relative_node_;
113 OrderDirection direction_; 111 OrderDirection direction_;
114 112
115 DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); 113 DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier);
116 }; 114 };
117 115
118 // Returns true if the order actually changed. 116 // Returns true if the order actually changed.
119 bool ReorderImpl(ViewTreeNode::Children* children, 117 bool ReorderImpl(Node::Children* children,
120 ViewTreeNode* node, 118 Node* node,
121 ViewTreeNode* relative, 119 Node* relative,
122 OrderDirection direction) { 120 OrderDirection direction) {
123 DCHECK(relative); 121 DCHECK(relative);
124 DCHECK_NE(node, relative); 122 DCHECK_NE(node, relative);
125 DCHECK_EQ(node->parent(), relative->parent()); 123 DCHECK_EQ(node->parent(), relative->parent());
126 124
127 const size_t child_i = 125 const size_t child_i =
128 std::find(children->begin(), children->end(), node) - children->begin(); 126 std::find(children->begin(), children->end(), node) - children->begin();
129 const size_t target_i = 127 const size_t target_i =
130 std::find(children->begin(), children->end(), relative) - 128 std::find(children->begin(), children->end(), relative) -
131 children->begin(); 129 children->begin();
132 if ((direction == ORDER_ABOVE && child_i == target_i + 1) || 130 if ((direction == ORDER_ABOVE && child_i == target_i + 1) ||
133 (direction == ORDER_BELOW && child_i + 1 == target_i)) { 131 (direction == ORDER_BELOW && child_i + 1 == target_i)) {
134 return false; 132 return false;
135 } 133 }
136 134
137 ScopedOrderChangedNotifier notifier(node, relative, direction); 135 ScopedOrderChangedNotifier notifier(node, relative, direction);
138 136
139 const size_t dest_i = 137 const size_t dest_i =
140 direction == ORDER_ABOVE ? 138 direction == ORDER_ABOVE ?
141 (child_i < target_i ? target_i : target_i + 1) : 139 (child_i < target_i ? target_i : target_i + 1) :
142 (child_i < target_i ? target_i - 1 : target_i); 140 (child_i < target_i ? target_i - 1 : target_i);
143 children->erase(children->begin() + child_i); 141 children->erase(children->begin() + child_i);
144 children->insert(children->begin() + dest_i, node); 142 children->insert(children->begin() + dest_i, node);
145 143
146 return true; 144 return true;
147 } 145 }
148 146
149 class ScopedSetActiveViewNotifier { 147 class ScopedSetActiveViewNotifier {
150 public: 148 public:
151 ScopedSetActiveViewNotifier(ViewTreeNode* node, 149 ScopedSetActiveViewNotifier(Node* node, View* old_view, View* new_view)
152 View* old_view,
153 View* new_view)
154 : node_(node), 150 : node_(node),
155 old_view_(old_view), 151 old_view_(old_view),
156 new_view_(new_view) { 152 new_view_(new_view) {
157 FOR_EACH_OBSERVER( 153 FOR_EACH_OBSERVER(
158 ViewTreeNodeObserver, 154 NodeObserver,
159 *ViewTreeNodePrivate(node).observers(), 155 *NodePrivate(node).observers(),
160 OnNodeActiveViewChange(node_, 156 OnNodeActiveViewChange(node_,
161 old_view_, 157 old_view_,
162 new_view_, 158 new_view_,
163 ViewTreeNodeObserver::DISPOSITION_CHANGING)); 159 NodeObserver::DISPOSITION_CHANGING));
164 } 160 }
165 ~ScopedSetActiveViewNotifier() { 161 ~ScopedSetActiveViewNotifier() {
166 FOR_EACH_OBSERVER( 162 FOR_EACH_OBSERVER(
167 ViewTreeNodeObserver, 163 NodeObserver,
168 *ViewTreeNodePrivate(node_).observers(), 164 *NodePrivate(node_).observers(),
169 OnNodeActiveViewChange(node_, 165 OnNodeActiveViewChange(node_,
170 old_view_, 166 old_view_,
171 new_view_, 167 new_view_,
172 ViewTreeNodeObserver::DISPOSITION_CHANGED)); 168 NodeObserver::DISPOSITION_CHANGED));
173 } 169 }
174 170
175 private: 171 private:
176 ViewTreeNode* node_; 172 Node* node_;
177 View* old_view_; 173 View* old_view_;
178 View* new_view_; 174 View* new_view_;
179 175
180 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); 176 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier);
181 }; 177 };
182 178
183 class ScopedSetBoundsNotifier { 179 class ScopedSetBoundsNotifier {
184 public: 180 public:
185 ScopedSetBoundsNotifier(ViewTreeNode* node, 181 ScopedSetBoundsNotifier(Node* node,
186 const gfx::Rect& old_bounds, 182 const gfx::Rect& old_bounds,
187 const gfx::Rect& new_bounds) 183 const gfx::Rect& new_bounds)
188 : node_(node), 184 : node_(node),
189 old_bounds_(old_bounds), 185 old_bounds_(old_bounds),
190 new_bounds_(new_bounds) { 186 new_bounds_(new_bounds) {
191 FOR_EACH_OBSERVER( 187 FOR_EACH_OBSERVER(
192 ViewTreeNodeObserver, 188 NodeObserver,
193 *ViewTreeNodePrivate(node_).observers(), 189 *NodePrivate(node_).observers(),
194 OnNodeBoundsChange(node_, 190 OnNodeBoundsChange(node_,
195 old_bounds_, 191 old_bounds_,
196 new_bounds_, 192 new_bounds_,
197 ViewTreeNodeObserver::DISPOSITION_CHANGING)); 193 NodeObserver::DISPOSITION_CHANGING));
198 } 194 }
199 ~ScopedSetBoundsNotifier() { 195 ~ScopedSetBoundsNotifier() {
200 FOR_EACH_OBSERVER( 196 FOR_EACH_OBSERVER(
201 ViewTreeNodeObserver, 197 NodeObserver,
202 *ViewTreeNodePrivate(node_).observers(), 198 *NodePrivate(node_).observers(),
203 OnNodeBoundsChange(node_, 199 OnNodeBoundsChange(node_,
204 old_bounds_, 200 old_bounds_,
205 new_bounds_, 201 new_bounds_,
206 ViewTreeNodeObserver::DISPOSITION_CHANGED)); 202 NodeObserver::DISPOSITION_CHANGED));
207 } 203 }
208 204
209 private: 205 private:
210 ViewTreeNode* node_; 206 Node* node_;
211 const gfx::Rect old_bounds_; 207 const gfx::Rect old_bounds_;
212 const gfx::Rect new_bounds_; 208 const gfx::Rect new_bounds_;
213 209
214 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); 210 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
215 }; 211 };
216 212
217 class ScopedDestructionNotifier { 213 class ScopedDestructionNotifier {
218 public: 214 public:
219 explicit ScopedDestructionNotifier(ViewTreeNode* node) 215 explicit ScopedDestructionNotifier(Node* node)
220 : node_(node) { 216 : node_(node) {
221 FOR_EACH_OBSERVER( 217 FOR_EACH_OBSERVER(
222 ViewTreeNodeObserver, 218 NodeObserver,
223 *ViewTreeNodePrivate(node_).observers(), 219 *NodePrivate(node_).observers(),
224 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGING)); 220 OnNodeDestroy(node_, NodeObserver::DISPOSITION_CHANGING));
225 } 221 }
226 ~ScopedDestructionNotifier() { 222 ~ScopedDestructionNotifier() {
227 FOR_EACH_OBSERVER( 223 FOR_EACH_OBSERVER(
228 ViewTreeNodeObserver, 224 NodeObserver,
229 *ViewTreeNodePrivate(node_).observers(), 225 *NodePrivate(node_).observers(),
230 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGED)); 226 OnNodeDestroy(node_, NodeObserver::DISPOSITION_CHANGED));
231 } 227 }
232 228
233 private: 229 private:
234 ViewTreeNode* node_; 230 Node* node_;
235 231
236 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); 232 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier);
237 }; 233 };
238 234
239 // Some operations are only permitted in the connection that created the node. 235 // Some operations are only permitted in the connection that created the node.
240 bool OwnsNode(ViewManager* manager, ViewTreeNode* node) { 236 bool OwnsNode(ViewManager* manager, Node* node) {
241 return !manager || 237 return !manager ||
242 static_cast<ViewManagerSynchronizer*>(manager)->OwnsNode(node->id()); 238 static_cast<ViewManagerClientImpl*>(manager)->OwnsNode(node->id());
243 } 239 }
244 240
245 } // namespace 241 } // namespace
246 242
247 //////////////////////////////////////////////////////////////////////////////// 243 ////////////////////////////////////////////////////////////////////////////////
248 // ViewTreeNode, public: 244 // Node, public:
249 245
250 // static 246 // static
251 ViewTreeNode* ViewTreeNode::Create(ViewManager* view_manager) { 247 Node* Node::Create(ViewManager* view_manager) {
252 ViewTreeNode* node = new ViewTreeNode(view_manager); 248 Node* node = new Node(view_manager);
253 static_cast<ViewManagerSynchronizer*>(view_manager)->AddNode(node); 249 static_cast<ViewManagerClientImpl*>(view_manager)->AddNode(node);
254 return node; 250 return node;
255 } 251 }
256 252
257 void ViewTreeNode::Destroy() { 253 void Node::Destroy() {
258 if (!OwnsNode(manager_, this)) 254 if (!OwnsNode(manager_, this))
259 return; 255 return;
260 256
261 if (manager_) 257 if (manager_)
262 static_cast<ViewManagerSynchronizer*>(manager_)->DestroyViewTreeNode(id_); 258 static_cast<ViewManagerClientImpl*>(manager_)->DestroyNode(id_);
263 while (!children_.empty()) 259 while (!children_.empty())
264 children_.front()->Destroy(); 260 children_.front()->Destroy();
265 LocalDestroy(); 261 LocalDestroy();
266 } 262 }
267 263
268 void ViewTreeNode::SetBounds(const gfx::Rect& bounds) { 264 void Node::SetBounds(const gfx::Rect& bounds) {
269 if (!OwnsNode(manager_, this)) 265 if (!OwnsNode(manager_, this))
270 return; 266 return;
271 267
272 if (manager_) 268 if (manager_)
273 static_cast<ViewManagerSynchronizer*>(manager_)->SetBounds(id_, bounds); 269 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds);
274 LocalSetBounds(bounds_, bounds); 270 LocalSetBounds(bounds_, bounds);
275 } 271 }
276 272
277 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { 273 void Node::AddObserver(NodeObserver* observer) {
278 observers_.AddObserver(observer); 274 observers_.AddObserver(observer);
279 } 275 }
280 276
281 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { 277 void Node::RemoveObserver(NodeObserver* observer) {
282 observers_.RemoveObserver(observer); 278 observers_.RemoveObserver(observer);
283 } 279 }
284 280
285 void ViewTreeNode::AddChild(ViewTreeNode* child) { 281 void Node::AddChild(Node* child) {
286 // TODO(beng): not necessarily valid to all connections, but possibly to the 282 // TODO(beng): not necessarily valid to all connections, but possibly to the
287 // embeddee in an embedder-embeddee relationship. 283 // embeddee in an embedder-embeddee relationship.
288 if (manager_) 284 if (manager_)
289 CHECK_EQ(ViewTreeNodePrivate(child).view_manager(), manager_); 285 CHECK_EQ(NodePrivate(child).view_manager(), manager_);
290 LocalAddChild(child); 286 LocalAddChild(child);
291 if (manager_) 287 if (manager_)
292 static_cast<ViewManagerSynchronizer*>(manager_)->AddChild(child->id(), id_); 288 static_cast<ViewManagerClientImpl*>(manager_)->AddChild(child->id(), id_);
293 } 289 }
294 290
295 void ViewTreeNode::RemoveChild(ViewTreeNode* child) { 291 void Node::RemoveChild(Node* child) {
296 // TODO(beng): not necessarily valid to all connections, but possibly to the 292 // TODO(beng): not necessarily valid to all connections, but possibly to the
297 // embeddee in an embedder-embeddee relationship. 293 // embeddee in an embedder-embeddee relationship.
298 if (manager_) 294 if (manager_)
299 CHECK_EQ(ViewTreeNodePrivate(child).view_manager(), manager_); 295 CHECK_EQ(NodePrivate(child).view_manager(), manager_);
300 LocalRemoveChild(child); 296 LocalRemoveChild(child);
301 if (manager_) { 297 if (manager_) {
302 static_cast<ViewManagerSynchronizer*>(manager_)->RemoveChild(child->id(), 298 static_cast<ViewManagerClientImpl*>(manager_)->RemoveChild(child->id(),
303 id_); 299 id_);
304 } 300 }
305 } 301 }
306 302
307 void ViewTreeNode::MoveToFront() { 303 void Node::MoveToFront() {
308 Reorder(parent_->children_.back(), ORDER_ABOVE); 304 Reorder(parent_->children_.back(), ORDER_ABOVE);
309 } 305 }
310 306
311 void ViewTreeNode::MoveToBack() { 307 void Node::MoveToBack() {
312 Reorder(parent_->children_.front(), ORDER_BELOW); 308 Reorder(parent_->children_.front(), ORDER_BELOW);
313 } 309 }
314 310
315 void ViewTreeNode::Reorder(ViewTreeNode* relative, OrderDirection direction) { 311 void Node::Reorder(Node* relative, OrderDirection direction) {
316 if (!LocalReorder(relative, direction)) 312 if (!LocalReorder(relative, direction))
317 return; 313 return;
318 if (manager_) { 314 if (manager_) {
319 static_cast<ViewManagerSynchronizer*>(manager_)->Reorder(id_, 315 static_cast<ViewManagerClientImpl*>(manager_)->Reorder(id_,
320 relative->id(), 316 relative->id(),
321 direction); 317 direction);
322 } 318 }
323 } 319 }
324 320
325 bool ViewTreeNode::Contains(ViewTreeNode* child) const { 321 bool Node::Contains(Node* child) const {
326 if (manager_) 322 if (manager_)
327 CHECK_EQ(ViewTreeNodePrivate(child).view_manager(), manager_); 323 CHECK_EQ(NodePrivate(child).view_manager(), manager_);
328 for (ViewTreeNode* p = child->parent(); p; p = p->parent()) { 324 for (Node* p = child->parent(); p; p = p->parent()) {
329 if (p == this) 325 if (p == this)
330 return true; 326 return true;
331 } 327 }
332 return false; 328 return false;
333 } 329 }
334 330
335 ViewTreeNode* ViewTreeNode::GetChildById(Id id) { 331 Node* Node::GetChildById(Id id) {
336 if (id == id_) 332 if (id == id_)
337 return this; 333 return this;
338 // TODO(beng): this could be improved depending on how we decide to own nodes. 334 // TODO(beng): this could be improved depending on how we decide to own nodes.
339 Children::const_iterator it = children_.begin(); 335 Children::const_iterator it = children_.begin();
340 for (; it != children_.end(); ++it) { 336 for (; it != children_.end(); ++it) {
341 ViewTreeNode* node = (*it)->GetChildById(id); 337 Node* node = (*it)->GetChildById(id);
342 if (node) 338 if (node)
343 return node; 339 return node;
344 } 340 }
345 return NULL; 341 return NULL;
346 } 342 }
347 343
348 void ViewTreeNode::SetActiveView(View* view) { 344 void Node::SetActiveView(View* view) {
349 // TODO(beng): not necessarily valid to all connections, but possibly to the 345 // TODO(beng): not necessarily valid to all connections, but possibly to the
350 // embeddee in an embedder-embeddee relationship. 346 // embeddee in an embedder-embeddee relationship.
351 if (manager_) 347 if (manager_)
352 CHECK_EQ(ViewPrivate(view).view_manager(), manager_); 348 CHECK_EQ(ViewPrivate(view).view_manager(), manager_);
353 LocalSetActiveView(view); 349 LocalSetActiveView(view);
354 if (manager_) { 350 if (manager_) {
355 static_cast<ViewManagerSynchronizer*>(manager_)->SetActiveView( 351 static_cast<ViewManagerClientImpl*>(manager_)->SetActiveView(
356 id_, active_view_->id()); 352 id_, active_view_->id());
357 } 353 }
358 } 354 }
359 355
360 void ViewTreeNode::SetFocus() { 356 void Node::SetFocus() {
361 if (manager_) 357 if (manager_)
362 static_cast<ViewManagerSynchronizer*>(manager_)->SetFocus(id_); 358 static_cast<ViewManagerClientImpl*>(manager_)->SetFocus(id_);
363 } 359 }
364 360
365 void ViewTreeNode::Embed(const String& url) { 361 void Node::Embed(const String& url) {
366 static_cast<ViewManagerSynchronizer*>(manager_)->Embed(url, id_); 362 static_cast<ViewManagerClientImpl*>(manager_)->Embed(url, id_);
367 } 363 }
368 364
369 //////////////////////////////////////////////////////////////////////////////// 365 ////////////////////////////////////////////////////////////////////////////////
370 // ViewTreeNode, protected: 366 // Node, protected:
371 367
372 ViewTreeNode::ViewTreeNode() 368 Node::Node()
373 : manager_(NULL), 369 : manager_(NULL),
374 id_(-1), 370 id_(-1),
375 parent_(NULL), 371 parent_(NULL),
376 active_view_(NULL) {} 372 active_view_(NULL) {}
377 373
378 ViewTreeNode::~ViewTreeNode() { 374 Node::~Node() {
379 ScopedDestructionNotifier notifier(this); 375 ScopedDestructionNotifier notifier(this);
380 if (parent_) 376 if (parent_)
381 parent_->LocalRemoveChild(this); 377 parent_->LocalRemoveChild(this);
382 // TODO(beng): It'd be better to do this via a destruction observer in the 378 // TODO(beng): It'd be better to do this via a destruction observer in the
383 // synchronizer. 379 // ViewManagerClientImpl.
384 if (manager_) 380 if (manager_)
385 static_cast<ViewManagerSynchronizer*>(manager_)->RemoveNode(id_); 381 static_cast<ViewManagerClientImpl*>(manager_)->RemoveNode(id_);
386 } 382 }
387 383
388 //////////////////////////////////////////////////////////////////////////////// 384 ////////////////////////////////////////////////////////////////////////////////
389 // ViewTreeNode, private: 385 // Node, private:
390 386
391 ViewTreeNode::ViewTreeNode(ViewManager* manager) 387 Node::Node(ViewManager* manager)
392 : manager_(manager), 388 : manager_(manager),
393 id_(static_cast<ViewManagerSynchronizer*>( 389 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateNode()),
394 manager_)->CreateViewTreeNode()),
395 parent_(NULL), 390 parent_(NULL),
396 active_view_(NULL) {} 391 active_view_(NULL) {}
397 392
398 void ViewTreeNode::LocalDestroy() { 393 void Node::LocalDestroy() {
399 delete this; 394 delete this;
400 } 395 }
401 396
402 void ViewTreeNode::LocalAddChild(ViewTreeNode* child) { 397 void Node::LocalAddChild(Node* child) {
403 ScopedTreeNotifier notifier(child, child->parent(), this); 398 ScopedTreeNotifier notifier(child, child->parent(), this);
404 if (child->parent()) 399 if (child->parent())
405 RemoveChildImpl(child, &child->parent_->children_); 400 RemoveChildImpl(child, &child->parent_->children_);
406 children_.push_back(child); 401 children_.push_back(child);
407 child->parent_ = this; 402 child->parent_ = this;
408 } 403 }
409 404
410 void ViewTreeNode::LocalRemoveChild(ViewTreeNode* child) { 405 void Node::LocalRemoveChild(Node* child) {
411 DCHECK_EQ(this, child->parent()); 406 DCHECK_EQ(this, child->parent());
412 ScopedTreeNotifier notifier(child, this, NULL); 407 ScopedTreeNotifier notifier(child, this, NULL);
413 RemoveChildImpl(child, &children_); 408 RemoveChildImpl(child, &children_);
414 } 409 }
415 410
416 bool ViewTreeNode::LocalReorder(ViewTreeNode* relative, 411 bool Node::LocalReorder(Node* relative, OrderDirection direction) {
417 OrderDirection direction) {
418 return ReorderImpl(&parent_->children_, this, relative, direction); 412 return ReorderImpl(&parent_->children_, this, relative, direction);
419 } 413 }
420 414
421 void ViewTreeNode::LocalSetActiveView(View* view) { 415 void Node::LocalSetActiveView(View* view) {
422 ScopedSetActiveViewNotifier notifier(this, active_view_, view); 416 ScopedSetActiveViewNotifier notifier(this, active_view_, view);
423 if (active_view_) 417 if (active_view_)
424 ViewPrivate(active_view_).set_node(NULL); 418 ViewPrivate(active_view_).set_node(NULL);
425 active_view_ = view; 419 active_view_ = view;
426 if (active_view_) 420 if (active_view_)
427 ViewPrivate(active_view_).set_node(this); 421 ViewPrivate(active_view_).set_node(this);
428 } 422 }
429 423
430 void ViewTreeNode::LocalSetBounds(const gfx::Rect& old_bounds, 424 void Node::LocalSetBounds(const gfx::Rect& old_bounds,
431 const gfx::Rect& new_bounds) { 425 const gfx::Rect& new_bounds) {
432 DCHECK(old_bounds == bounds_); 426 DCHECK(old_bounds == bounds_);
433 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); 427 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds);
434 bounds_ = new_bounds; 428 bounds_ = new_bounds;
435 } 429 }
436 430
437 } // namespace view_manager 431 } // namespace view_manager
438 } // namespace mojo 432 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/launcher/launcher.cc ('k') | mojo/services/public/cpp/view_manager/lib/node_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698