| 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 "components/view_manager/public/cpp/view.h" | 5 #include "components/mus/public/cpp/view.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "components/view_manager/public/cpp/lib/view_private.h" | 11 #include "components/mus/public/cpp/lib/view_private.h" |
| 12 #include "components/view_manager/public/cpp/lib/view_tree_client_impl.h" | 12 #include "components/mus/public/cpp/lib/view_tree_client_impl.h" |
| 13 #include "components/view_manager/public/cpp/view_observer.h" | 13 #include "components/mus/public/cpp/view_observer.h" |
| 14 #include "components/view_manager/public/cpp/view_surface.h" | 14 #include "components/mus/public/cpp/view_surface.h" |
| 15 #include "components/view_manager/public/cpp/view_tracker.h" | 15 #include "components/mus/public/cpp/view_tracker.h" |
| 16 #include "mojo/application/public/cpp/service_provider_impl.h" | 16 #include "mojo/application/public/cpp/service_provider_impl.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 void NotifyViewTreeChangeAtReceiver( | 22 void NotifyViewTreeChangeAtReceiver( |
| 23 View* receiver, | 23 View* receiver, |
| 24 const ViewObserver::TreeChangeParams& params, | 24 const ViewObserver::TreeChangeParams& params, |
| 25 bool change_applied) { | 25 bool change_applied) { |
| 26 ViewObserver::TreeChangeParams local_params = params; | 26 ViewObserver::TreeChangeParams local_params = params; |
| 27 local_params.receiver = receiver; | 27 local_params.receiver = receiver; |
| 28 if (change_applied) { | 28 if (change_applied) { |
| 29 FOR_EACH_OBSERVER(ViewObserver, | 29 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(receiver).observers(), |
| 30 *ViewPrivate(receiver).observers(), | |
| 31 OnTreeChanged(local_params)); | 30 OnTreeChanged(local_params)); |
| 32 } else { | 31 } else { |
| 33 FOR_EACH_OBSERVER(ViewObserver, | 32 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(receiver).observers(), |
| 34 *ViewPrivate(receiver).observers(), | |
| 35 OnTreeChanging(local_params)); | 33 OnTreeChanging(local_params)); |
| 36 } | 34 } |
| 37 } | 35 } |
| 38 | 36 |
| 39 void NotifyViewTreeChangeUp( | 37 void NotifyViewTreeChangeUp(View* start_at, |
| 40 View* start_at, | 38 const ViewObserver::TreeChangeParams& params, |
| 41 const ViewObserver::TreeChangeParams& params, | 39 bool change_applied) { |
| 42 bool change_applied) { | |
| 43 for (View* current = start_at; current; current = current->parent()) | 40 for (View* current = start_at; current; current = current->parent()) |
| 44 NotifyViewTreeChangeAtReceiver(current, params, change_applied); | 41 NotifyViewTreeChangeAtReceiver(current, params, change_applied); |
| 45 } | 42 } |
| 46 | 43 |
| 47 void NotifyViewTreeChangeDown( | 44 void NotifyViewTreeChangeDown(View* start_at, |
| 48 View* start_at, | 45 const ViewObserver::TreeChangeParams& params, |
| 49 const ViewObserver::TreeChangeParams& params, | 46 bool change_applied) { |
| 50 bool change_applied) { | |
| 51 NotifyViewTreeChangeAtReceiver(start_at, params, change_applied); | 47 NotifyViewTreeChangeAtReceiver(start_at, params, change_applied); |
| 52 View::Children::const_iterator it = start_at->children().begin(); | 48 View::Children::const_iterator it = start_at->children().begin(); |
| 53 for (; it != start_at->children().end(); ++it) | 49 for (; it != start_at->children().end(); ++it) |
| 54 NotifyViewTreeChangeDown(*it, params, change_applied); | 50 NotifyViewTreeChangeDown(*it, params, change_applied); |
| 55 } | 51 } |
| 56 | 52 |
| 57 void NotifyViewTreeChange( | 53 void NotifyViewTreeChange(const ViewObserver::TreeChangeParams& params, |
| 58 const ViewObserver::TreeChangeParams& params, | 54 bool change_applied) { |
| 59 bool change_applied) { | |
| 60 NotifyViewTreeChangeDown(params.target, params, change_applied); | 55 NotifyViewTreeChangeDown(params.target, params, change_applied); |
| 61 if (params.old_parent) | 56 if (params.old_parent) |
| 62 NotifyViewTreeChangeUp(params.old_parent, params, change_applied); | 57 NotifyViewTreeChangeUp(params.old_parent, params, change_applied); |
| 63 if (params.new_parent) | 58 if (params.new_parent) |
| 64 NotifyViewTreeChangeUp(params.new_parent, params, change_applied); | 59 NotifyViewTreeChangeUp(params.new_parent, params, change_applied); |
| 65 } | 60 } |
| 66 | 61 |
| 67 class ScopedTreeNotifier { | 62 class ScopedTreeNotifier { |
| 68 public: | 63 public: |
| 69 ScopedTreeNotifier(View* target, View* old_parent, View* new_parent) { | 64 ScopedTreeNotifier(View* target, View* old_parent, View* new_parent) { |
| 70 params_.target = target; | 65 params_.target = target; |
| 71 params_.old_parent = old_parent; | 66 params_.old_parent = old_parent; |
| 72 params_.new_parent = new_parent; | 67 params_.new_parent = new_parent; |
| 73 NotifyViewTreeChange(params_, false); | 68 NotifyViewTreeChange(params_, false); |
| 74 } | 69 } |
| 75 ~ScopedTreeNotifier() { | 70 ~ScopedTreeNotifier() { NotifyViewTreeChange(params_, true); } |
| 76 NotifyViewTreeChange(params_, true); | |
| 77 } | |
| 78 | 71 |
| 79 private: | 72 private: |
| 80 ViewObserver::TreeChangeParams params_; | 73 ViewObserver::TreeChangeParams params_; |
| 81 | 74 |
| 82 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier); | 75 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTreeNotifier); |
| 83 }; | 76 }; |
| 84 | 77 |
| 85 void RemoveChildImpl(View* child, View::Children* children) { | 78 void RemoveChildImpl(View* child, View::Children* children) { |
| 86 View::Children::iterator it = | 79 View::Children::iterator it = |
| 87 std::find(children->begin(), children->end(), child); | 80 std::find(children->begin(), children->end(), child); |
| 88 if (it != children->end()) { | 81 if (it != children->end()) { |
| 89 children->erase(it); | 82 children->erase(it); |
| 90 ViewPrivate(child).ClearParent(); | 83 ViewPrivate(child).ClearParent(); |
| 91 } | 84 } |
| 92 } | 85 } |
| 93 | 86 |
| 94 class ScopedOrderChangedNotifier { | 87 class ScopedOrderChangedNotifier { |
| 95 public: | 88 public: |
| 96 ScopedOrderChangedNotifier(View* view, | 89 ScopedOrderChangedNotifier(View* view, |
| 97 View* relative_view, | 90 View* relative_view, |
| 98 OrderDirection direction) | 91 OrderDirection direction) |
| 99 : view_(view), | 92 : view_(view), relative_view_(relative_view), direction_(direction) { |
| 100 relative_view_(relative_view), | 93 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view_).observers(), |
| 101 direction_(direction) { | |
| 102 FOR_EACH_OBSERVER(ViewObserver, | |
| 103 *ViewPrivate(view_).observers(), | |
| 104 OnViewReordering(view_, relative_view_, direction_)); | 94 OnViewReordering(view_, relative_view_, direction_)); |
| 105 } | 95 } |
| 106 ~ScopedOrderChangedNotifier() { | 96 ~ScopedOrderChangedNotifier() { |
| 107 FOR_EACH_OBSERVER(ViewObserver, | 97 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view_).observers(), |
| 108 *ViewPrivate(view_).observers(), | |
| 109 OnViewReordered(view_, relative_view_, direction_)); | 98 OnViewReordered(view_, relative_view_, direction_)); |
| 110 } | 99 } |
| 111 | 100 |
| 112 private: | 101 private: |
| 113 View* view_; | 102 View* view_; |
| 114 View* relative_view_; | 103 View* relative_view_; |
| 115 OrderDirection direction_; | 104 OrderDirection direction_; |
| 116 | 105 |
| 117 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); | 106 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedOrderChangedNotifier); |
| 118 }; | 107 }; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 145 children->insert(children->begin() + dest_i, view); | 134 children->insert(children->begin() + dest_i, view); |
| 146 | 135 |
| 147 return true; | 136 return true; |
| 148 } | 137 } |
| 149 | 138 |
| 150 class ScopedSetBoundsNotifier { | 139 class ScopedSetBoundsNotifier { |
| 151 public: | 140 public: |
| 152 ScopedSetBoundsNotifier(View* view, | 141 ScopedSetBoundsNotifier(View* view, |
| 153 const Rect& old_bounds, | 142 const Rect& old_bounds, |
| 154 const Rect& new_bounds) | 143 const Rect& new_bounds) |
| 155 : view_(view), | 144 : view_(view), old_bounds_(old_bounds), new_bounds_(new_bounds) { |
| 156 old_bounds_(old_bounds), | 145 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view_).observers(), |
| 157 new_bounds_(new_bounds) { | |
| 158 FOR_EACH_OBSERVER(ViewObserver, | |
| 159 *ViewPrivate(view_).observers(), | |
| 160 OnViewBoundsChanging(view_, old_bounds_, new_bounds_)); | 146 OnViewBoundsChanging(view_, old_bounds_, new_bounds_)); |
| 161 } | 147 } |
| 162 ~ScopedSetBoundsNotifier() { | 148 ~ScopedSetBoundsNotifier() { |
| 163 FOR_EACH_OBSERVER(ViewObserver, | 149 FOR_EACH_OBSERVER(ViewObserver, *ViewPrivate(view_).observers(), |
| 164 *ViewPrivate(view_).observers(), | |
| 165 OnViewBoundsChanged(view_, old_bounds_, new_bounds_)); | 150 OnViewBoundsChanged(view_, old_bounds_, new_bounds_)); |
| 166 } | 151 } |
| 167 | 152 |
| 168 private: | 153 private: |
| 169 View* view_; | 154 View* view_; |
| 170 const Rect old_bounds_; | 155 const Rect old_bounds_; |
| 171 const Rect new_bounds_; | 156 const Rect new_bounds_; |
| 172 | 157 |
| 173 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); | 158 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 174 }; | 159 }; |
| 175 | 160 |
| 176 // Some operations are only permitted in the connection that created the view. | 161 // Some operations are only permitted in the connection that created the view. |
| 177 bool OwnsView(ViewTreeConnection* connection, View* view) { | 162 bool OwnsView(ViewTreeConnection* connection, View* view) { |
| 178 return !connection || | 163 return !connection || |
| 179 static_cast<ViewTreeClientImpl*>(connection)->OwnsView(view->id()); | 164 static_cast<ViewTreeClientImpl*>(connection)->OwnsView(view->id()); |
| 180 } | 165 } |
| 181 | 166 |
| 182 void EmptyEmbedCallback(bool result, ConnectionSpecificId connection_id) {} | 167 void EmptyEmbedCallback(bool result, ConnectionSpecificId connection_id) {} |
| 183 | 168 |
| 184 } // namespace | 169 } // namespace |
| 185 | 170 |
| 186 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
| 187 // View, public: | 172 // View, public: |
| 188 | 173 |
| 189 void View::Destroy() { | 174 void View::Destroy() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 209 |
| 225 if (connection_) | 210 if (connection_) |
| 226 static_cast<ViewTreeClientImpl*>(connection_)->SetVisible(id_, value); | 211 static_cast<ViewTreeClientImpl*>(connection_)->SetVisible(id_, value); |
| 227 LocalSetVisible(value); | 212 LocalSetVisible(value); |
| 228 } | 213 } |
| 229 | 214 |
| 230 scoped_ptr<mojo::ViewSurface> View::RequestSurface() { | 215 scoped_ptr<mojo::ViewSurface> View::RequestSurface() { |
| 231 mojo::SurfacePtr surface; | 216 mojo::SurfacePtr surface; |
| 232 mojo::SurfaceClientPtr client; | 217 mojo::SurfaceClientPtr client; |
| 233 mojo::InterfaceRequest<SurfaceClient> client_request = GetProxy(&client); | 218 mojo::InterfaceRequest<SurfaceClient> client_request = GetProxy(&client); |
| 234 static_cast<ViewTreeClientImpl*>(connection_)->RequestSurface( | 219 static_cast<ViewTreeClientImpl*>(connection_) |
| 235 id_, GetProxy(&surface), client.Pass()); | 220 ->RequestSurface(id_, GetProxy(&surface), client.Pass()); |
| 236 return make_scoped_ptr(new mojo::ViewSurface(surface.PassInterface(), | 221 return make_scoped_ptr( |
| 237 client_request.Pass())); | 222 new mojo::ViewSurface(surface.PassInterface(), client_request.Pass())); |
| 238 } | 223 } |
| 239 | 224 |
| 240 void View::SetSharedProperty(const std::string& name, | 225 void View::SetSharedProperty(const std::string& name, |
| 241 const std::vector<uint8_t>* value) { | 226 const std::vector<uint8_t>* value) { |
| 242 std::vector<uint8_t> old_value; | 227 std::vector<uint8_t> old_value; |
| 243 std::vector<uint8_t>* old_value_ptr = nullptr; | 228 std::vector<uint8_t>* old_value_ptr = nullptr; |
| 244 auto it = properties_.find(name); | 229 auto it = properties_.find(name); |
| 245 if (it != properties_.end()) { | 230 if (it != properties_.end()) { |
| 246 old_value = it->second; | 231 old_value = it->second; |
| 247 old_value_ptr = &old_value; | 232 old_value_ptr = &old_value; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 261 } | 246 } |
| 262 | 247 |
| 263 // TODO: add test coverage of this (450303). | 248 // TODO: add test coverage of this (450303). |
| 264 if (connection_) { | 249 if (connection_) { |
| 265 Array<uint8_t> transport_value; | 250 Array<uint8_t> transport_value; |
| 266 if (value) { | 251 if (value) { |
| 267 transport_value.resize(value->size()); | 252 transport_value.resize(value->size()); |
| 268 if (value->size()) | 253 if (value->size()) |
| 269 memcpy(&transport_value.front(), &(value->front()), value->size()); | 254 memcpy(&transport_value.front(), &(value->front()), value->size()); |
| 270 } | 255 } |
| 271 static_cast<ViewTreeClientImpl*>(connection_)->SetProperty( | 256 static_cast<ViewTreeClientImpl*>(connection_) |
| 272 id_, name, transport_value.Pass()); | 257 ->SetProperty(id_, name, transport_value.Pass()); |
| 273 } | 258 } |
| 274 | 259 |
| 275 FOR_EACH_OBSERVER( | 260 FOR_EACH_OBSERVER( |
| 276 ViewObserver, observers_, | 261 ViewObserver, observers_, |
| 277 OnViewSharedPropertyChanged(this, name, old_value_ptr, value)); | 262 OnViewSharedPropertyChanged(this, name, old_value_ptr, value)); |
| 278 } | 263 } |
| 279 | 264 |
| 280 bool View::IsDrawn() const { | 265 bool View::IsDrawn() const { |
| 281 if (!visible_) | 266 if (!visible_) |
| 282 return false; | 267 return false; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 static_cast<ViewTreeClientImpl*>(connection_)->AddChild(child->id(), id_); | 300 static_cast<ViewTreeClientImpl*>(connection_)->AddChild(child->id(), id_); |
| 316 } | 301 } |
| 317 | 302 |
| 318 void View::RemoveChild(View* child) { | 303 void View::RemoveChild(View* child) { |
| 319 // TODO(beng): not necessarily valid to all connections, but possibly to the | 304 // TODO(beng): not necessarily valid to all connections, but possibly to the |
| 320 // embeddee in an embedder-embeddee relationship. | 305 // embeddee in an embedder-embeddee relationship. |
| 321 if (connection_) | 306 if (connection_) |
| 322 CHECK_EQ(child->connection(), connection_); | 307 CHECK_EQ(child->connection(), connection_); |
| 323 LocalRemoveChild(child); | 308 LocalRemoveChild(child); |
| 324 if (connection_) { | 309 if (connection_) { |
| 325 static_cast<ViewTreeClientImpl*>(connection_)->RemoveChild(child->id(), | 310 static_cast<ViewTreeClientImpl*>(connection_) |
| 326 id_); | 311 ->RemoveChild(child->id(), id_); |
| 327 } | 312 } |
| 328 } | 313 } |
| 329 | 314 |
| 330 void View::MoveToFront() { | 315 void View::MoveToFront() { |
| 331 if (!parent_ || parent_->children_.back() == this) | 316 if (!parent_ || parent_->children_.back() == this) |
| 332 return; | 317 return; |
| 333 Reorder(parent_->children_.back(), ORDER_DIRECTION_ABOVE); | 318 Reorder(parent_->children_.back(), ORDER_DIRECTION_ABOVE); |
| 334 } | 319 } |
| 335 | 320 |
| 336 void View::MoveToBack() { | 321 void View::MoveToBack() { |
| 337 if (!parent_ || parent_->children_.front() == this) | 322 if (!parent_ || parent_->children_.front() == this) |
| 338 return; | 323 return; |
| 339 Reorder(parent_->children_.front(), ORDER_DIRECTION_BELOW); | 324 Reorder(parent_->children_.front(), ORDER_DIRECTION_BELOW); |
| 340 } | 325 } |
| 341 | 326 |
| 342 void View::Reorder(View* relative, OrderDirection direction) { | 327 void View::Reorder(View* relative, OrderDirection direction) { |
| 343 if (!LocalReorder(relative, direction)) | 328 if (!LocalReorder(relative, direction)) |
| 344 return; | 329 return; |
| 345 if (connection_) { | 330 if (connection_) { |
| 346 static_cast<ViewTreeClientImpl*>(connection_)->Reorder(id_, relative->id(), | 331 static_cast<ViewTreeClientImpl*>(connection_) |
| 347 direction); | 332 ->Reorder(id_, relative->id(), direction); |
| 348 } | 333 } |
| 349 } | 334 } |
| 350 | 335 |
| 351 bool View::Contains(View* child) const { | 336 bool View::Contains(View* child) const { |
| 352 if (!child) | 337 if (!child) |
| 353 return false; | 338 return false; |
| 354 if (child == this) | 339 if (child == this) |
| 355 return true; | 340 return true; |
| 356 if (connection_) | 341 if (connection_) |
| 357 CHECK_EQ(child->connection(), connection_); | 342 CHECK_EQ(child->connection(), connection_); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 } | 412 } |
| 428 | 413 |
| 429 } // namespace | 414 } // namespace |
| 430 | 415 |
| 431 View::View() | 416 View::View() |
| 432 : connection_(NULL), | 417 : connection_(NULL), |
| 433 id_(static_cast<Id>(-1)), | 418 id_(static_cast<Id>(-1)), |
| 434 parent_(NULL), | 419 parent_(NULL), |
| 435 viewport_metrics_(CreateEmptyViewportMetrics()), | 420 viewport_metrics_(CreateEmptyViewportMetrics()), |
| 436 visible_(true), | 421 visible_(true), |
| 437 drawn_(false) { | 422 drawn_(false) {} |
| 438 } | |
| 439 | 423 |
| 440 View::~View() { | 424 View::~View() { |
| 441 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); | 425 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); |
| 442 if (parent_) | 426 if (parent_) |
| 443 parent_->LocalRemoveChild(this); | 427 parent_->LocalRemoveChild(this); |
| 444 | 428 |
| 445 // We may still have children. This can happen if the embedder destroys the | 429 // We may still have children. This can happen if the embedder destroys the |
| 446 // root while we're still alive. | 430 // root while we're still alive. |
| 447 while (!children_.empty()) { | 431 while (!children_.empty()) { |
| 448 View* child = children_.front(); | 432 View* child = children_.front(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 470 | 454 |
| 471 //////////////////////////////////////////////////////////////////////////////// | 455 //////////////////////////////////////////////////////////////////////////////// |
| 472 // View, private: | 456 // View, private: |
| 473 | 457 |
| 474 View::View(ViewTreeConnection* connection, Id id) | 458 View::View(ViewTreeConnection* connection, Id id) |
| 475 : connection_(connection), | 459 : connection_(connection), |
| 476 id_(id), | 460 id_(id), |
| 477 parent_(nullptr), | 461 parent_(nullptr), |
| 478 viewport_metrics_(CreateEmptyViewportMetrics()), | 462 viewport_metrics_(CreateEmptyViewportMetrics()), |
| 479 visible_(false), | 463 visible_(false), |
| 480 drawn_(false) { | 464 drawn_(false) {} |
| 481 } | |
| 482 | 465 |
| 483 int64 View::SetLocalPropertyInternal(const void* key, | 466 int64 View::SetLocalPropertyInternal(const void* key, |
| 484 const char* name, | 467 const char* name, |
| 485 PropertyDeallocator deallocator, | 468 PropertyDeallocator deallocator, |
| 486 int64 value, | 469 int64 value, |
| 487 int64 default_value) { | 470 int64 default_value) { |
| 488 int64 old = GetLocalPropertyInternal(key, default_value); | 471 int64 old = GetLocalPropertyInternal(key, default_value); |
| 489 if (value == default_value) { | 472 if (value == default_value) { |
| 490 prop_map_.erase(key); | 473 prop_map_.erase(key); |
| 491 } else { | 474 } else { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 void View::LocalRemoveChild(View* child) { | 506 void View::LocalRemoveChild(View* child) { |
| 524 DCHECK_EQ(this, child->parent()); | 507 DCHECK_EQ(this, child->parent()); |
| 525 ScopedTreeNotifier notifier(child, this, NULL); | 508 ScopedTreeNotifier notifier(child, this, NULL); |
| 526 RemoveChildImpl(child, &children_); | 509 RemoveChildImpl(child, &children_); |
| 527 } | 510 } |
| 528 | 511 |
| 529 bool View::LocalReorder(View* relative, OrderDirection direction) { | 512 bool View::LocalReorder(View* relative, OrderDirection direction) { |
| 530 return ReorderImpl(&parent_->children_, this, relative, direction); | 513 return ReorderImpl(&parent_->children_, this, relative, direction); |
| 531 } | 514 } |
| 532 | 515 |
| 533 void View::LocalSetBounds(const Rect& old_bounds, | 516 void View::LocalSetBounds(const Rect& old_bounds, const Rect& new_bounds) { |
| 534 const Rect& new_bounds) { | |
| 535 DCHECK(old_bounds.x == bounds_.x); | 517 DCHECK(old_bounds.x == bounds_.x); |
| 536 DCHECK(old_bounds.y == bounds_.y); | 518 DCHECK(old_bounds.y == bounds_.y); |
| 537 DCHECK(old_bounds.width == bounds_.width); | 519 DCHECK(old_bounds.width == bounds_.width); |
| 538 DCHECK(old_bounds.height == bounds_.height); | 520 DCHECK(old_bounds.height == bounds_.height); |
| 539 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 521 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 540 bounds_ = new_bounds; | 522 bounds_ = new_bounds; |
| 541 } | 523 } |
| 542 | 524 |
| 543 void View::LocalSetViewportMetrics(const ViewportMetrics& old_metrics, | 525 void View::LocalSetViewportMetrics(const ViewportMetrics& old_metrics, |
| 544 const ViewportMetrics& new_metrics) { | 526 const ViewportMetrics& new_metrics) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 568 if (visible_ == visible) | 550 if (visible_ == visible) |
| 569 return; | 551 return; |
| 570 | 552 |
| 571 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanging(this)); | 553 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanging(this)); |
| 572 visible_ = visible; | 554 visible_ = visible; |
| 573 NotifyViewVisibilityChanged(this); | 555 NotifyViewVisibilityChanged(this); |
| 574 } | 556 } |
| 575 | 557 |
| 576 void View::NotifyViewVisibilityChanged(View* target) { | 558 void View::NotifyViewVisibilityChanged(View* target) { |
| 577 if (!NotifyViewVisibilityChangedDown(target)) { | 559 if (!NotifyViewVisibilityChangedDown(target)) { |
| 578 return; // |this| has been deleted. | 560 return; // |this| has been deleted. |
| 579 } | 561 } |
| 580 NotifyViewVisibilityChangedUp(target); | 562 NotifyViewVisibilityChangedUp(target); |
| 581 } | 563 } |
| 582 | 564 |
| 583 bool View::NotifyViewVisibilityChangedAtReceiver(View* target) { | 565 bool View::NotifyViewVisibilityChangedAtReceiver(View* target) { |
| 584 // |this| may be deleted during a call to OnViewVisibilityChanged() on one | 566 // |this| may be deleted during a call to OnViewVisibilityChanged() on one |
| 585 // of the observers. We create an local observer for that. In that case we | 567 // of the observers. We create an local observer for that. In that case we |
| 586 // exit without further access to any members. | 568 // exit without further access to any members. |
| 587 ViewTracker tracker; | 569 ViewTracker tracker; |
| 588 tracker.Add(this); | 570 tracker.Add(this); |
| 589 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(target)); | 571 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(target)); |
| 590 return tracker.Contains(this); | 572 return tracker.Contains(this); |
| 591 } | 573 } |
| 592 | 574 |
| 593 bool View::NotifyViewVisibilityChangedDown(View* target) { | 575 bool View::NotifyViewVisibilityChangedDown(View* target) { |
| 594 if (!NotifyViewVisibilityChangedAtReceiver(target)) | 576 if (!NotifyViewVisibilityChangedAtReceiver(target)) |
| 595 return false; // |this| was deleted. | 577 return false; // |this| was deleted. |
| 596 std::set<const View*> child_already_processed; | 578 std::set<const View*> child_already_processed; |
| 597 bool child_destroyed = false; | 579 bool child_destroyed = false; |
| 598 do { | 580 do { |
| 599 child_destroyed = false; | 581 child_destroyed = false; |
| 600 for (View::Children::const_iterator it = children_.begin(); | 582 for (View::Children::const_iterator it = children_.begin(); |
| 601 it != children_.end(); ++it) { | 583 it != children_.end(); ++it) { |
| 602 if (!child_already_processed.insert(*it).second) | 584 if (!child_already_processed.insert(*it).second) |
| 603 continue; | 585 continue; |
| 604 if (!(*it)->NotifyViewVisibilityChangedDown(target)) { | 586 if (!(*it)->NotifyViewVisibilityChangedDown(target)) { |
| 605 // |*it| was deleted, |it| is invalid and |children_| has changed. We | 587 // |*it| was deleted, |it| is invalid and |children_| has changed. We |
| (...skipping 20 matching lines...) Expand all Loading... |
| 626 !static_cast<ViewTreeClientImpl*>(connection_)->is_embed_root()) { | 608 !static_cast<ViewTreeClientImpl*>(connection_)->is_embed_root()) { |
| 627 return false; | 609 return false; |
| 628 } | 610 } |
| 629 | 611 |
| 630 while (!children_.empty()) | 612 while (!children_.empty()) |
| 631 RemoveChild(children_[0]); | 613 RemoveChild(children_[0]); |
| 632 return true; | 614 return true; |
| 633 } | 615 } |
| 634 | 616 |
| 635 } // namespace mojo | 617 } // namespace mojo |
| OLD | NEW |