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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 delegate_->OnWindowDestroyed(this); | 116 delegate_->OnWindowDestroyed(this); |
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. |
sky
2017/01/24 18:45:37
Remove comment (it's obvious given the function yo
kylix_rd
2017/01/24 21:20:00
Done.
| |
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 |
602 std::set<const void*> Window::GetAllPropertKeys() const { | 596 // {Set,Get,Clear}Property are implemented in class_property.h. |
603 std::set<const void*> keys; | |
604 for (auto& pair : prop_map_) | |
605 keys.insert(pair.first); | |
606 return keys; | |
607 } | |
608 | |
609 // {Set,Get,Clear}Property are implemented in window_property.h. | |
610 | 597 |
611 void Window::SetNativeWindowProperty(const char* key, void* value) { | 598 void Window::SetNativeWindowProperty(const char* key, void* value) { |
612 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0); | 599 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0); |
613 } | 600 } |
614 | 601 |
615 void* Window::GetNativeWindowProperty(const char* key) const { | 602 void* Window::GetNativeWindowProperty(const char* key) const { |
616 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); | 603 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); |
617 } | 604 } |
618 | 605 |
619 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { | 606 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 children_.end()); | 641 children_.end()); |
655 } else { | 642 } else { |
656 // Even if we can't delete the child, we still need to remove it from the | 643 // 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 | 644 // parent so that relevant bookkeeping (parent_ back-pointers etc) are |
658 // updated. | 645 // updated. |
659 RemoveChild(child); | 646 RemoveChild(child); |
660 } | 647 } |
661 } | 648 } |
662 } | 649 } |
663 | 650 |
651 std::unique_ptr<ui::PropertyData> Window::BeforePropertyChange( | |
652 const void* key) { | |
653 return port_ ? port_->OnWillChangeProperty(key) : nullptr; | |
654 } | |
655 | |
656 void Window::AfterPropertyChange(const void* key, | |
657 int64_t old_value, | |
658 std::unique_ptr<ui::PropertyData> data) { | |
659 if (port_) | |
660 port_->OnPropertyChanged(key, std::move(data)); | |
661 for (WindowObserver& observer : observers_) | |
662 observer.OnWindowPropertyChanged(this, key, old_value); | |
663 } | |
664 | |
664 /////////////////////////////////////////////////////////////////////////////// | 665 /////////////////////////////////////////////////////////////////////////////// |
665 // Window, private: | 666 // Window, private: |
666 | 667 |
667 int64_t Window::SetPropertyInternal(const void* key, | |
668 const char* name, | |
669 PropertyDeallocator deallocator, | |
670 int64_t value, | |
671 int64_t default_value) { | |
672 // This code may be called before |port_| has been created. | |
673 std::unique_ptr<WindowPortPropertyData> data = | |
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 } | |
691 | |
692 int64_t Window::GetPropertyInternal(const void* key, | |
693 int64_t default_value) const { | |
694 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); | |
695 if (iter == prop_map_.end()) | |
696 return default_value; | |
697 return iter->second.value; | |
698 } | |
699 | |
700 bool Window::HitTest(const gfx::Point& local_point) { | 668 bool Window::HitTest(const gfx::Point& local_point) { |
701 gfx::Rect local_bounds(bounds().size()); | 669 gfx::Rect local_bounds(bounds().size()); |
702 if (!delegate_ || !delegate_->HasHitTestMask()) | 670 if (!delegate_ || !delegate_->HasHitTestMask()) |
703 return local_bounds.Contains(local_point); | 671 return local_bounds.Contains(local_point); |
704 | 672 |
705 gfx::Path mask; | 673 gfx::Path mask; |
706 delegate_->GetHitTestMask(&mask); | 674 delegate_->GetHitTestMask(&mask); |
707 | 675 |
708 SkRegion clip_region; | 676 SkRegion clip_region; |
709 clip_region.setRect(local_bounds.x(), local_bounds.y(), | 677 clip_region.setRect(local_bounds.x(), local_bounds.y(), |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1118 layer_name = "Unnamed Window"; | 1086 layer_name = "Unnamed Window"; |
1119 | 1087 |
1120 if (id_ != -1) | 1088 if (id_ != -1) |
1121 layer_name += " " + base::IntToString(id_); | 1089 layer_name += " " + base::IntToString(id_); |
1122 | 1090 |
1123 layer()->set_name(layer_name); | 1091 layer()->set_name(layer_name); |
1124 #endif | 1092 #endif |
1125 } | 1093 } |
1126 | 1094 |
1127 } // namespace aura | 1095 } // namespace aura |
OLD | NEW |