| 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/view_tree_node.h" | 5 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 6 | 6 |
| 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" | 7 #include "mojo/services/public/cpp/view_manager/lib/view_manager_private.h" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.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/lib/view_tree_node_private.h" | 10 #include "mojo/services/public/cpp/view_manager/lib/view_tree_node_private.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 ViewTreeNode* node_; | 120 ViewTreeNode* node_; |
| 121 View* old_view_; | 121 View* old_view_; |
| 122 View* new_view_; | 122 View* new_view_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); | 124 DISALLOW_COPY_AND_ASSIGN(ScopedSetActiveViewNotifier); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 class ScopedSetBoundsNotifier { |
| 128 public: |
| 129 ScopedSetBoundsNotifier(ViewTreeNode* node, |
| 130 const gfx::Rect& old_bounds, |
| 131 const gfx::Rect& new_bounds) |
| 132 : node_(node), |
| 133 old_bounds_(old_bounds), |
| 134 new_bounds_(new_bounds) { |
| 135 FOR_EACH_OBSERVER( |
| 136 ViewTreeNodeObserver, |
| 137 *ViewTreeNodePrivate(node_).observers(), |
| 138 OnNodeBoundsChange(node_, |
| 139 old_bounds_, |
| 140 new_bounds_, |
| 141 ViewTreeNodeObserver::DISPOSITION_CHANGING)); |
| 142 } |
| 143 ~ScopedSetBoundsNotifier() { |
| 144 FOR_EACH_OBSERVER( |
| 145 ViewTreeNodeObserver, |
| 146 *ViewTreeNodePrivate(node_).observers(), |
| 147 OnNodeBoundsChange(node_, |
| 148 old_bounds_, |
| 149 new_bounds_, |
| 150 ViewTreeNodeObserver::DISPOSITION_CHANGED)); |
| 151 } |
| 152 |
| 153 private: |
| 154 ViewTreeNode* node_; |
| 155 const gfx::Rect old_bounds_; |
| 156 const gfx::Rect new_bounds_; |
| 157 |
| 158 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 159 }; |
| 160 |
| 127 class ScopedDestructionNotifier { | 161 class ScopedDestructionNotifier { |
| 128 public: | 162 public: |
| 129 explicit ScopedDestructionNotifier(ViewTreeNode* node) | 163 explicit ScopedDestructionNotifier(ViewTreeNode* node) |
| 130 : node_(node) { | 164 : node_(node) { |
| 131 FOR_EACH_OBSERVER( | 165 FOR_EACH_OBSERVER( |
| 132 ViewTreeNodeObserver, | 166 ViewTreeNodeObserver, |
| 133 *ViewTreeNodePrivate(node_).observers(), | 167 *ViewTreeNodePrivate(node_).observers(), |
| 134 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGING)); | 168 OnNodeDestroy(node_, ViewTreeNodeObserver::DISPOSITION_CHANGING)); |
| 135 } | 169 } |
| 136 ~ScopedDestructionNotifier() { | 170 ~ScopedDestructionNotifier() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 159 } | 193 } |
| 160 | 194 |
| 161 void ViewTreeNode::Destroy() { | 195 void ViewTreeNode::Destroy() { |
| 162 if (manager_) | 196 if (manager_) |
| 163 ViewManagerPrivate(manager_).synchronizer()->DestroyViewTreeNode(id_); | 197 ViewManagerPrivate(manager_).synchronizer()->DestroyViewTreeNode(id_); |
| 164 while (!children_.empty()) | 198 while (!children_.empty()) |
| 165 children_.front()->Destroy(); | 199 children_.front()->Destroy(); |
| 166 LocalDestroy(); | 200 LocalDestroy(); |
| 167 } | 201 } |
| 168 | 202 |
| 203 void ViewTreeNode::SetBounds(const gfx::Rect& bounds) { |
| 204 if (manager_) |
| 205 ViewManagerPrivate(manager_).synchronizer()->SetBounds(id_, bounds); |
| 206 LocalSetBounds(bounds_, bounds); |
| 207 } |
| 208 |
| 169 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { | 209 void ViewTreeNode::AddObserver(ViewTreeNodeObserver* observer) { |
| 170 observers_.AddObserver(observer); | 210 observers_.AddObserver(observer); |
| 171 } | 211 } |
| 172 | 212 |
| 173 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { | 213 void ViewTreeNode::RemoveObserver(ViewTreeNodeObserver* observer) { |
| 174 observers_.RemoveObserver(observer); | 214 observers_.RemoveObserver(observer); |
| 175 } | 215 } |
| 176 | 216 |
| 177 void ViewTreeNode::AddChild(ViewTreeNode* child) { | 217 void ViewTreeNode::AddChild(ViewTreeNode* child) { |
| 178 if (manager_) | 218 if (manager_) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 309 |
| 270 void ViewTreeNode::LocalSetActiveView(View* view) { | 310 void ViewTreeNode::LocalSetActiveView(View* view) { |
| 271 ScopedSetActiveViewNotifier notifier(this, active_view_, view); | 311 ScopedSetActiveViewNotifier notifier(this, active_view_, view); |
| 272 if (active_view_) | 312 if (active_view_) |
| 273 ViewPrivate(active_view_).set_node(NULL); | 313 ViewPrivate(active_view_).set_node(NULL); |
| 274 active_view_ = view; | 314 active_view_ = view; |
| 275 if (active_view_) | 315 if (active_view_) |
| 276 ViewPrivate(active_view_).set_node(this); | 316 ViewPrivate(active_view_).set_node(this); |
| 277 } | 317 } |
| 278 | 318 |
| 319 void ViewTreeNode::LocalSetBounds(const gfx::Rect& old_bounds, |
| 320 const gfx::Rect& new_bounds) { |
| 321 DCHECK(old_bounds == bounds_); |
| 322 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 323 bounds_ = new_bounds; |
| 324 } |
| 325 |
| 279 } // namespace view_manager | 326 } // namespace view_manager |
| 280 } // namespace mojo | 327 } // namespace mojo |
| 281 | 328 |
| OLD | NEW |