| 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/public/cpp/view_manager/node.h" | 5 #include "mojo/services/public/cpp/view_manager/node.h" |
| 6 | 6 |
| 7 #include "mojo/services/public/cpp/view_manager/lib/node_private.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_manager_client_impl.h" |
| 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 10 #include "mojo/services/public/cpp/view_manager/node_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/node_observer.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view.h" | 11 #include "mojo/services/public/cpp/view_manager/view.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 Node* receiver, | 19 Node* receiver, |
| 20 const NodeObserver::TreeChangeParams& params) { | 20 const NodeObserver::TreeChangeParams& params, |
| 21 bool change_applied) { |
| 21 NodeObserver::TreeChangeParams local_params = params; | 22 NodeObserver::TreeChangeParams local_params = params; |
| 22 local_params.receiver = receiver; | 23 local_params.receiver = receiver; |
| 23 FOR_EACH_OBSERVER(NodeObserver, | 24 if (change_applied) { |
| 24 *NodePrivate(receiver).observers(), | 25 FOR_EACH_OBSERVER(NodeObserver, |
| 25 OnTreeChange(local_params)); | 26 *NodePrivate(receiver).observers(), |
| 27 OnTreeChanged(local_params)); |
| 28 } else { |
| 29 FOR_EACH_OBSERVER(NodeObserver, |
| 30 *NodePrivate(receiver).observers(), |
| 31 OnTreeChanging(local_params)); |
| 32 } |
| 26 } | 33 } |
| 27 | 34 |
| 28 void NotifyViewTreeChangeUp( | 35 void NotifyViewTreeChangeUp( |
| 29 Node* start_at, | 36 Node* start_at, |
| 30 const NodeObserver::TreeChangeParams& params) { | 37 const NodeObserver::TreeChangeParams& params, |
| 38 bool change_applied) { |
| 31 for (Node* current = start_at; current; current = current->parent()) | 39 for (Node* current = start_at; current; current = current->parent()) |
| 32 NotifyViewTreeChangeAtReceiver(current, params); | 40 NotifyViewTreeChangeAtReceiver(current, params, change_applied); |
| 33 } | 41 } |
| 34 | 42 |
| 35 void NotifyViewTreeChangeDown( | 43 void NotifyViewTreeChangeDown( |
| 36 Node* start_at, | 44 Node* start_at, |
| 37 const NodeObserver::TreeChangeParams& params) { | 45 const NodeObserver::TreeChangeParams& params, |
| 38 NotifyViewTreeChangeAtReceiver(start_at, params); | 46 bool change_applied) { |
| 47 NotifyViewTreeChangeAtReceiver(start_at, params, change_applied); |
| 39 Node::Children::const_iterator it = start_at->children().begin(); | 48 Node::Children::const_iterator it = start_at->children().begin(); |
| 40 for (; it != start_at->children().end(); ++it) | 49 for (; it != start_at->children().end(); ++it) |
| 41 NotifyViewTreeChangeDown(*it, params); | 50 NotifyViewTreeChangeDown(*it, params, change_applied); |
| 42 } | 51 } |
| 43 | 52 |
| 44 void NotifyViewTreeChange( | 53 void NotifyViewTreeChange( |
| 45 const NodeObserver::TreeChangeParams& params) { | 54 const NodeObserver::TreeChangeParams& params, |
| 46 NotifyViewTreeChangeDown(params.target, params); | 55 bool change_applied) { |
| 56 NotifyViewTreeChangeDown(params.target, params, change_applied); |
| 47 if (params.old_parent) | 57 if (params.old_parent) |
| 48 NotifyViewTreeChangeUp(params.old_parent, params); | 58 NotifyViewTreeChangeUp(params.old_parent, params, change_applied); |
| 49 if (params.new_parent) | 59 if (params.new_parent) |
| 50 NotifyViewTreeChangeUp(params.new_parent, params); | 60 NotifyViewTreeChangeUp(params.new_parent, params, change_applied); |
| 51 } | 61 } |
| 52 | 62 |
| 53 class ScopedTreeNotifier { | 63 class ScopedTreeNotifier { |
| 54 public: | 64 public: |
| 55 ScopedTreeNotifier(Node* target, Node* old_parent, Node* new_parent) { | 65 ScopedTreeNotifier(Node* target, Node* old_parent, Node* new_parent) { |
| 56 params_.target = target; | 66 params_.target = target; |
| 57 params_.old_parent = old_parent; | 67 params_.old_parent = old_parent; |
| 58 params_.new_parent = new_parent; | 68 params_.new_parent = new_parent; |
| 59 NotifyViewTreeChange(params_); | 69 NotifyViewTreeChange(params_, false); |
| 60 } | 70 } |
| 61 ~ScopedTreeNotifier() { | 71 ~ScopedTreeNotifier() { |
| 62 params_.phase = NodeObserver::DISPOSITION_CHANGED; | 72 NotifyViewTreeChange(params_, true); |
| 63 NotifyViewTreeChange(params_); | |
| 64 } | 73 } |
| 65 | 74 |
| 66 private: | 75 private: |
| 67 NodeObserver::TreeChangeParams params_; | 76 NodeObserver::TreeChangeParams params_; |
| 68 | 77 |
| 69 DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier); | 78 DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier); |
| 70 }; | 79 }; |
| 71 | 80 |
| 72 void RemoveChildImpl(Node* child, Node::Children* children) { | 81 void RemoveChildImpl(Node* child, Node::Children* children) { |
| 73 Node::Children::iterator it = | 82 Node::Children::iterator it = |
| 74 std::find(children->begin(), children->end(), child); | 83 std::find(children->begin(), children->end(), child); |
| 75 if (it != children->end()) { | 84 if (it != children->end()) { |
| 76 children->erase(it); | 85 children->erase(it); |
| 77 NodePrivate(child).ClearParent(); | 86 NodePrivate(child).ClearParent(); |
| 78 } | 87 } |
| 79 } | 88 } |
| 80 | 89 |
| 81 class ScopedOrderChangedNotifier { | 90 class ScopedOrderChangedNotifier { |
| 82 public: | 91 public: |
| 83 ScopedOrderChangedNotifier(Node* node, | 92 ScopedOrderChangedNotifier(Node* node, |
| 84 Node* relative_node, | 93 Node* relative_node, |
| 85 OrderDirection direction) | 94 OrderDirection direction) |
| 86 : node_(node), | 95 : node_(node), |
| 87 relative_node_(relative_node), | 96 relative_node_(relative_node), |
| 88 direction_(direction) { | 97 direction_(direction) { |
| 89 FOR_EACH_OBSERVER( | 98 FOR_EACH_OBSERVER(NodeObserver, |
| 90 NodeObserver, | 99 *NodePrivate(node_).observers(), |
| 91 *NodePrivate(node_).observers(), | 100 OnNodeReordering(node_, relative_node_, direction_)); |
| 92 OnNodeReordered(node_, | |
| 93 relative_node_, | |
| 94 direction_, | |
| 95 NodeObserver::DISPOSITION_CHANGING)); | |
| 96 | |
| 97 } | 101 } |
| 98 ~ScopedOrderChangedNotifier() { | 102 ~ScopedOrderChangedNotifier() { |
| 99 FOR_EACH_OBSERVER( | 103 FOR_EACH_OBSERVER(NodeObserver, |
| 100 NodeObserver, | 104 *NodePrivate(node_).observers(), |
| 101 *NodePrivate(node_).observers(), | 105 OnNodeReordered(node_, relative_node_, direction_)); |
| 102 OnNodeReordered(node_, | |
| 103 relative_node_, | |
| 104 direction_, | |
| 105 NodeObserver::DISPOSITION_CHANGED)); | |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 Node* node_; | 109 Node* node_; |
| 110 Node* relative_node_; | 110 Node* relative_node_; |
| 111 OrderDirection direction_; | 111 OrderDirection direction_; |
| 112 | 112 |
| 113 DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); | 113 DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); |
| 114 }; | 114 }; |
| 115 | 115 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 143 | 143 |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 class ScopedSetActiveViewNotifier { | 147 class ScopedSetActiveViewNotifier { |
| 148 public: | 148 public: |
| 149 ScopedSetActiveViewNotifier(Node* node, View* old_view, View* new_view) | 149 ScopedSetActiveViewNotifier(Node* node, View* old_view, View* new_view) |
| 150 : node_(node), | 150 : node_(node), |
| 151 old_view_(old_view), | 151 old_view_(old_view), |
| 152 new_view_(new_view) { | 152 new_view_(new_view) { |
| 153 FOR_EACH_OBSERVER( | 153 FOR_EACH_OBSERVER(NodeObserver, |
| 154 NodeObserver, | 154 *NodePrivate(node).observers(), |
| 155 *NodePrivate(node).observers(), | 155 OnNodeActiveViewChanging(node_, old_view_, new_view_)); |
| 156 OnNodeActiveViewChange(node_, | |
| 157 old_view_, | |
| 158 new_view_, | |
| 159 NodeObserver::DISPOSITION_CHANGING)); | |
| 160 } | 156 } |
| 161 ~ScopedSetActiveViewNotifier() { | 157 ~ScopedSetActiveViewNotifier() { |
| 162 FOR_EACH_OBSERVER( | 158 FOR_EACH_OBSERVER(NodeObserver, |
| 163 NodeObserver, | 159 *NodePrivate(node_).observers(), |
| 164 *NodePrivate(node_).observers(), | 160 OnNodeActiveViewChanged(node_, old_view_, new_view_)); |
| 165 OnNodeActiveViewChange(node_, | |
| 166 old_view_, | |
| 167 new_view_, | |
| 168 NodeObserver::DISPOSITION_CHANGED)); | |
| 169 } | 161 } |
| 170 | 162 |
| 171 private: | 163 private: |
| 172 Node* node_; | 164 Node* node_; |
| 173 View* old_view_; | 165 View* old_view_; |
| 174 View* new_view_; | 166 View* new_view_; |
| 175 | 167 |
| 176 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); | 168 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); |
| 177 }; | 169 }; |
| 178 | 170 |
| 179 class ScopedSetBoundsNotifier { | 171 class ScopedSetBoundsNotifier { |
| 180 public: | 172 public: |
| 181 ScopedSetBoundsNotifier(Node* node, | 173 ScopedSetBoundsNotifier(Node* node, |
| 182 const gfx::Rect& old_bounds, | 174 const gfx::Rect& old_bounds, |
| 183 const gfx::Rect& new_bounds) | 175 const gfx::Rect& new_bounds) |
| 184 : node_(node), | 176 : node_(node), |
| 185 old_bounds_(old_bounds), | 177 old_bounds_(old_bounds), |
| 186 new_bounds_(new_bounds) { | 178 new_bounds_(new_bounds) { |
| 187 FOR_EACH_OBSERVER( | 179 FOR_EACH_OBSERVER(NodeObserver, |
| 188 NodeObserver, | 180 *NodePrivate(node_).observers(), |
| 189 *NodePrivate(node_).observers(), | 181 OnNodeBoundsChanging(node_, old_bounds_, new_bounds_)); |
| 190 OnNodeBoundsChange(node_, | |
| 191 old_bounds_, | |
| 192 new_bounds_, | |
| 193 NodeObserver::DISPOSITION_CHANGING)); | |
| 194 } | 182 } |
| 195 ~ScopedSetBoundsNotifier() { | 183 ~ScopedSetBoundsNotifier() { |
| 196 FOR_EACH_OBSERVER( | 184 FOR_EACH_OBSERVER(NodeObserver, |
| 197 NodeObserver, | 185 *NodePrivate(node_).observers(), |
| 198 *NodePrivate(node_).observers(), | 186 OnNodeBoundsChanged(node_, old_bounds_, new_bounds_)); |
| 199 OnNodeBoundsChange(node_, | |
| 200 old_bounds_, | |
| 201 new_bounds_, | |
| 202 NodeObserver::DISPOSITION_CHANGED)); | |
| 203 } | 187 } |
| 204 | 188 |
| 205 private: | 189 private: |
| 206 Node* node_; | 190 Node* node_; |
| 207 const gfx::Rect old_bounds_; | 191 const gfx::Rect old_bounds_; |
| 208 const gfx::Rect new_bounds_; | 192 const gfx::Rect new_bounds_; |
| 209 | 193 |
| 210 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); | 194 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 211 }; | 195 }; |
| 212 | 196 |
| 213 class ScopedDestructionNotifier { | 197 class ScopedDestructionNotifier { |
| 214 public: | 198 public: |
| 215 explicit ScopedDestructionNotifier(Node* node) | 199 explicit ScopedDestructionNotifier(Node* node) |
| 216 : node_(node) { | 200 : node_(node) { |
| 217 FOR_EACH_OBSERVER( | 201 FOR_EACH_OBSERVER(NodeObserver, |
| 218 NodeObserver, | 202 *NodePrivate(node_).observers(), |
| 219 *NodePrivate(node_).observers(), | 203 OnNodeDestroying(node_)); |
| 220 OnNodeDestroy(node_, NodeObserver::DISPOSITION_CHANGING)); | |
| 221 } | 204 } |
| 222 ~ScopedDestructionNotifier() { | 205 ~ScopedDestructionNotifier() { |
| 223 FOR_EACH_OBSERVER( | 206 FOR_EACH_OBSERVER(NodeObserver, |
| 224 NodeObserver, | 207 *NodePrivate(node_).observers(), |
| 225 *NodePrivate(node_).observers(), | 208 OnNodeDestroyed(node_)); |
| 226 OnNodeDestroy(node_, NodeObserver::DISPOSITION_CHANGED)); | |
| 227 } | 209 } |
| 228 | 210 |
| 229 private: | 211 private: |
| 230 Node* node_; | 212 Node* node_; |
| 231 | 213 |
| 232 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); | 214 DISALLOW_COPY_AND_ASSIGN(ScopedDestructionNotifier); |
| 233 }; | 215 }; |
| 234 | 216 |
| 235 // Some operations are only permitted in the connection that created the node. | 217 // Some operations are only permitted in the connection that created the node. |
| 236 bool OwnsNode(ViewManager* manager, Node* node) { | 218 bool OwnsNode(ViewManager* manager, Node* node) { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 | 410 |
| 429 void Node::LocalSetBounds(const gfx::Rect& old_bounds, | 411 void Node::LocalSetBounds(const gfx::Rect& old_bounds, |
| 430 const gfx::Rect& new_bounds) { | 412 const gfx::Rect& new_bounds) { |
| 431 DCHECK(old_bounds == bounds_); | 413 DCHECK(old_bounds == bounds_); |
| 432 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 414 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 433 bounds_ = new_bounds; | 415 bounds_ = new_bounds; |
| 434 } | 416 } |
| 435 | 417 |
| 436 } // namespace view_manager | 418 } // namespace view_manager |
| 437 } // namespace mojo | 419 } // namespace mojo |
| OLD | NEW |