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.h" | 5 #include "mojo/services/public/cpp/view_manager/view.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/service_provider_impl.h" | 7 #include "mojo/public/cpp/application/service_provider_impl.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/view_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 } | 379 } |
380 | 380 |
381 View::~View() { | 381 View::~View() { |
382 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); | 382 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); |
383 if (parent_) | 383 if (parent_) |
384 parent_->LocalRemoveChild(this); | 384 parent_->LocalRemoveChild(this); |
385 // TODO(beng): It'd be better to do this via a destruction observer in the | 385 // TODO(beng): It'd be better to do this via a destruction observer in the |
386 // ViewManagerClientImpl. | 386 // ViewManagerClientImpl. |
387 if (manager_) | 387 if (manager_) |
388 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); | 388 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); |
389 | |
390 // Clear properties. | |
391 for (std::map<const void*, Value>::const_iterator iter = prop_map_.begin(); | |
sky
2014/11/14 23:11:27
enhanced for loop? auto?
| |
392 iter != prop_map_.end(); | |
393 ++iter) { | |
394 if (iter->second.deallocator) | |
395 (*iter->second.deallocator)(iter->second.value); | |
396 } | |
397 prop_map_.clear(); | |
398 | |
389 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); | 399 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); |
390 } | 400 } |
391 | 401 |
392 //////////////////////////////////////////////////////////////////////////////// | 402 //////////////////////////////////////////////////////////////////////////////// |
393 // View, private: | 403 // View, private: |
394 | 404 |
395 View::View(ViewManager* manager) | 405 View::View(ViewManager* manager) |
396 : manager_(manager), | 406 : manager_(manager), |
397 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateView()), | 407 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateView()), |
398 parent_(NULL), | 408 parent_(NULL), |
399 visible_(true), | 409 visible_(true), |
400 drawn_(false) { | 410 drawn_(false) { |
401 } | 411 } |
402 | 412 |
413 int64 View::SetLocalPropertyInternal(const void* key, | |
414 const char* name, | |
415 PropertyDeallocator deallocator, | |
416 int64 value, | |
417 int64 default_value) { | |
418 int64 old = GetLocalPropertyInternal(key, default_value); | |
419 if (value == default_value) { | |
420 prop_map_.erase(key); | |
421 } else { | |
422 Value prop_value; | |
423 prop_value.name = name; | |
424 prop_value.value = value; | |
425 prop_value.deallocator = deallocator; | |
426 prop_map_[key] = prop_value; | |
427 } | |
428 // FOR_EACH_OBSERVER(WindowObserver, observers_, | |
sky
2014/11/14 23:11:27
Seems reasonable to notify observers when the prop
| |
429 // OnWindowPropertyChanged(this, key, old)); | |
430 return old; | |
431 } | |
432 | |
433 int64 View::GetLocalPropertyInternal(const void* key, | |
434 int64 default_value) const { | |
435 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | |
436 if (iter == prop_map_.end()) | |
437 return default_value; | |
438 return iter->second.value; | |
439 } | |
440 | |
403 void View::LocalDestroy() { | 441 void View::LocalDestroy() { |
404 delete this; | 442 delete this; |
405 } | 443 } |
406 | 444 |
407 void View::LocalAddChild(View* child) { | 445 void View::LocalAddChild(View* child) { |
408 ScopedTreeNotifier notifier(child, child->parent(), this); | 446 ScopedTreeNotifier notifier(child, child->parent(), this); |
409 if (child->parent()) | 447 if (child->parent()) |
410 RemoveChildImpl(child, &child->parent_->children_); | 448 RemoveChildImpl(child, &child->parent_->children_); |
411 children_.push_back(child); | 449 children_.push_back(child); |
412 child->parent_ = this; | 450 child->parent_ = this; |
(...skipping 28 matching lines...) Expand all Loading... | |
441 if (IsDrawn() == value) { | 479 if (IsDrawn() == value) { |
442 drawn_ = value; | 480 drawn_ = value; |
443 return; | 481 return; |
444 } | 482 } |
445 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); | 483 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); |
446 drawn_ = value; | 484 drawn_ = value; |
447 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); | 485 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); |
448 } | 486 } |
449 | 487 |
450 } // namespace mojo | 488 } // namespace mojo |
OLD | NEW |