OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 for (WindowObserver& observer : observers_) { | 117 for (WindowObserver& observer : observers_) { |
118 RemoveObserver(&observer); | 118 RemoveObserver(&observer); |
119 observer.OnWindowDestroyed(this); | 119 observer.OnWindowDestroyed(this); |
120 } | 120 } |
121 | 121 |
122 // Delete the LayoutManager before properties. This way if the LayoutManager | 122 // Delete the LayoutManager before properties. This way if the LayoutManager |
123 // depends upon properties existing the properties are still valid. | 123 // depends upon properties existing the properties are still valid. |
124 layout_manager_.reset(); | 124 layout_manager_.reset(); |
125 | 125 |
126 // Clear properties. | 126 // Clear properties. |
127 for (std::map<const void*, Value>::const_iterator iter = prop_map_.begin(); | 127 ClearProperties(); |
128 iter != prop_map_.end(); | |
129 ++iter) { | |
130 if (iter->second.deallocator) | |
131 (*iter->second.deallocator)(iter->second.value); | |
132 } | |
133 prop_map_.clear(); | |
134 | 128 |
135 // The layer will either be destroyed by |layer_owner_|'s dtor, or by whoever | 129 // The layer will either be destroyed by |layer_owner_|'s dtor, or by whoever |
136 // acquired it. | 130 // acquired it. |
137 layer()->set_delegate(NULL); | 131 layer()->set_delegate(NULL); |
138 DestroyLayer(); | 132 DestroyLayer(); |
139 } | 133 } |
140 | 134 |
141 void Window::Init(ui::LayerType layer_type) { | 135 void Window::Init(ui::LayerType layer_type) { |
142 if (!port_owner_) { | 136 if (!port_owner_) { |
143 port_owner_ = Env::GetInstance()->CreateWindowPort(this); | 137 port_owner_ = Env::GetInstance()->CreateWindowPort(this); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 if (!root_window) | 586 if (!root_window) |
593 return false; | 587 return false; |
594 client::CaptureClient* capture_client = client::GetCaptureClient(root_window); | 588 client::CaptureClient* capture_client = client::GetCaptureClient(root_window); |
595 return capture_client && capture_client->GetCaptureWindow() == this; | 589 return capture_client && capture_client->GetCaptureWindow() == this; |
596 } | 590 } |
597 | 591 |
598 void Window::SuppressPaint() { | 592 void Window::SuppressPaint() { |
599 layer()->SuppressPaint(); | 593 layer()->SuppressPaint(); |
600 } | 594 } |
601 | 595 |
| 596 /* |
602 std::set<const void*> Window::GetAllPropertKeys() const { | 597 std::set<const void*> Window::GetAllPropertKeys() const { |
603 std::set<const void*> keys; | 598 std::set<const void*> keys; |
604 for (auto& pair : prop_map_) | 599 for (auto& pair : prop_map_) |
605 keys.insert(pair.first); | 600 keys.insert(pair.first); |
606 return keys; | 601 return keys; |
607 } | 602 }*/ |
608 | 603 |
609 // {Set,Get,Clear}Property are implemented in window_property.h. | 604 // {Set,Get,Clear}Property are implemented in window_property.h. |
610 | 605 |
611 void Window::SetNativeWindowProperty(const char* key, void* value) { | 606 void Window::SetNativeWindowProperty(const char* key, void* value) { |
612 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0); | 607 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0); |
613 } | 608 } |
614 | 609 |
615 void* Window::GetNativeWindowProperty(const char* key) const { | 610 void* Window::GetNativeWindowProperty(const char* key) const { |
616 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); | 611 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); |
617 } | 612 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 children_.end()); | 649 children_.end()); |
655 } else { | 650 } else { |
656 // Even if we can't delete the child, we still need to remove it from the | 651 // Even if we can't delete the child, we still need to remove it from the |
657 // parent so that relevant bookkeeping (parent_ back-pointers etc) are | 652 // parent so that relevant bookkeeping (parent_ back-pointers etc) are |
658 // updated. | 653 // updated. |
659 RemoveChild(child); | 654 RemoveChild(child); |
660 } | 655 } |
661 } | 656 } |
662 } | 657 } |
663 | 658 |
| 659 std::unique_ptr<ui::PropertyData> Window::BeforePropertyChange( |
| 660 const void* key) { |
| 661 return port_ ? port_->OnWillChangeProperty(key) : nullptr; |
| 662 } |
| 663 |
| 664 void Window::AfterPropertyChange(const void* key, |
| 665 int64_t old_value, |
| 666 std::unique_ptr<ui::PropertyData> data) { |
| 667 if (port_) |
| 668 port_->OnPropertyChanged(key, std::move(data)); |
| 669 for (WindowObserver& observer : observers_) |
| 670 observer.OnWindowPropertyChanged(this, key, old_value); |
| 671 } |
| 672 |
664 /////////////////////////////////////////////////////////////////////////////// | 673 /////////////////////////////////////////////////////////////////////////////// |
665 // Window, private: | 674 // Window, private: |
666 | 675 |
667 int64_t Window::SetPropertyInternal(const void* key, | 676 int64_t Window::SetPropertyInternal(const void* key, |
668 const char* name, | 677 const char* name, |
669 PropertyDeallocator deallocator, | 678 ui::PropertyDeallocator deallocator, |
670 int64_t value, | 679 int64_t value, |
671 int64_t default_value) { | 680 int64_t default_value) { |
672 // This code may be called before |port_| has been created. | 681 return PropertyHandler::SetPropertyInternal(key, name, deallocator, value, |
673 std::unique_ptr<WindowPortPropertyData> data = | 682 default_value); |
674 port_ ? port_->OnWillChangeProperty(key) : nullptr; | |
675 int64_t old = GetPropertyInternal(key, default_value); | |
676 if (value == default_value) { | |
677 prop_map_.erase(key); | |
678 } else { | |
679 Value prop_value; | |
680 prop_value.name = name; | |
681 prop_value.value = value; | |
682 prop_value.deallocator = deallocator; | |
683 prop_map_[key] = prop_value; | |
684 } | |
685 if (port_) | |
686 port_->OnPropertyChanged(key, std::move(data)); | |
687 for (WindowObserver& observer : observers_) | |
688 observer.OnWindowPropertyChanged(this, key, old); | |
689 return old; | |
690 } | 683 } |
691 | 684 |
692 int64_t Window::GetPropertyInternal(const void* key, | 685 int64_t Window::GetPropertyInternal(const void* key, |
693 int64_t default_value) const { | 686 int64_t default_value) const { |
694 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | 687 return PropertyHandler::GetPropertyInternal(key, default_value); |
695 if (iter == prop_map_.end()) | |
696 return default_value; | |
697 return iter->second.value; | |
698 } | 688 } |
699 | 689 |
700 bool Window::HitTest(const gfx::Point& local_point) { | 690 bool Window::HitTest(const gfx::Point& local_point) { |
701 gfx::Rect local_bounds(bounds().size()); | 691 gfx::Rect local_bounds(bounds().size()); |
702 if (!delegate_ || !delegate_->HasHitTestMask()) | 692 if (!delegate_ || !delegate_->HasHitTestMask()) |
703 return local_bounds.Contains(local_point); | 693 return local_bounds.Contains(local_point); |
704 | 694 |
705 gfx::Path mask; | 695 gfx::Path mask; |
706 delegate_->GetHitTestMask(&mask); | 696 delegate_->GetHitTestMask(&mask); |
707 | 697 |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 layer_name = "Unnamed Window"; | 1108 layer_name = "Unnamed Window"; |
1119 | 1109 |
1120 if (id_ != -1) | 1110 if (id_ != -1) |
1121 layer_name += " " + base::IntToString(id_); | 1111 layer_name += " " + base::IntToString(id_); |
1122 | 1112 |
1123 layer()->set_name(layer_name); | 1113 layer()->set_name(layer_name); |
1124 #endif | 1114 #endif |
1125 } | 1115 } |
1126 | 1116 |
1127 } // namespace aura | 1117 } // namespace aura |
OLD | NEW |