Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Side by Side Diff: ui/aura/window.cc

Issue 2632543003: Refactor and push window properties up to class properties. (Closed)
Patch Set: More build fixes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ClearProperties();
127 for (std::map<const void*, Value>::const_iterator iter = prop_map_.begin();
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 127
135 // The layer will either be destroyed by |layer_owner_|'s dtor, or by whoever 128 // The layer will either be destroyed by |layer_owner_|'s dtor, or by whoever
136 // acquired it. 129 // acquired it.
137 layer()->set_delegate(NULL); 130 layer()->set_delegate(NULL);
138 DestroyLayer(); 131 DestroyLayer();
139 } 132 }
140 133
141 void Window::Init(ui::LayerType layer_type) { 134 void Window::Init(ui::LayerType layer_type) {
142 if (!port_owner_) { 135 if (!port_owner_) {
143 port_owner_ = Env::GetInstance()->CreateWindowPort(this); 136 port_owner_ = Env::GetInstance()->CreateWindowPort(this);
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 if (!root_window) 585 if (!root_window)
593 return false; 586 return false;
594 client::CaptureClient* capture_client = client::GetCaptureClient(root_window); 587 client::CaptureClient* capture_client = client::GetCaptureClient(root_window);
595 return capture_client && capture_client->GetCaptureWindow() == this; 588 return capture_client && capture_client->GetCaptureWindow() == this;
596 } 589 }
597 590
598 void Window::SuppressPaint() { 591 void Window::SuppressPaint() {
599 layer()->SuppressPaint(); 592 layer()->SuppressPaint();
600 } 593 }
601 594
602 std::set<const void*> Window::GetAllPropertKeys() const { 595 // {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 596
611 void Window::SetNativeWindowProperty(const char* key, void* value) { 597 void Window::SetNativeWindowProperty(const char* key, void* value) {
612 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0); 598 SetPropertyInternal(key, key, NULL, reinterpret_cast<int64_t>(value), 0);
613 } 599 }
614 600
615 void* Window::GetNativeWindowProperty(const char* key) const { 601 void* Window::GetNativeWindowProperty(const char* key) const {
616 return reinterpret_cast<void*>(GetPropertyInternal(key, 0)); 602 return reinterpret_cast<void*>(GetPropertyInternal(key, 0));
617 } 603 }
618 604
619 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) { 605 void Window::OnDeviceScaleFactorChanged(float device_scale_factor) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 children_.end()); 640 children_.end());
655 } else { 641 } else {
656 // Even if we can't delete the child, we still need to remove it from the 642 // 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 643 // parent so that relevant bookkeeping (parent_ back-pointers etc) are
658 // updated. 644 // updated.
659 RemoveChild(child); 645 RemoveChild(child);
660 } 646 }
661 } 647 }
662 } 648 }
663 649
650 std::unique_ptr<ui::PropertyData> Window::BeforePropertyChange(
651 const void* key) {
652 return port_ ? port_->OnWillChangeProperty(key) : nullptr;
653 }
654
655 void Window::AfterPropertyChange(const void* key,
656 int64_t old_value,
657 std::unique_ptr<ui::PropertyData> data) {
658 if (port_)
659 port_->OnPropertyChanged(key, std::move(data));
660 for (WindowObserver& observer : observers_)
661 observer.OnWindowPropertyChanged(this, key, old_value);
662 }
663
664 /////////////////////////////////////////////////////////////////////////////// 664 ///////////////////////////////////////////////////////////////////////////////
665 // Window, private: 665 // Window, private:
666 666
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) { 667 bool Window::HitTest(const gfx::Point& local_point) {
701 gfx::Rect local_bounds(bounds().size()); 668 gfx::Rect local_bounds(bounds().size());
702 if (!delegate_ || !delegate_->HasHitTestMask()) 669 if (!delegate_ || !delegate_->HasHitTestMask())
703 return local_bounds.Contains(local_point); 670 return local_bounds.Contains(local_point);
704 671
705 gfx::Path mask; 672 gfx::Path mask;
706 delegate_->GetHitTestMask(&mask); 673 delegate_->GetHitTestMask(&mask);
707 674
708 SkRegion clip_region; 675 SkRegion clip_region;
709 clip_region.setRect(local_bounds.x(), local_bounds.y(), 676 clip_region.setRect(local_bounds.x(), local_bounds.y(),
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 layer_name = "Unnamed Window"; 1085 layer_name = "Unnamed Window";
1119 1086
1120 if (id_ != -1) 1087 if (id_ != -1)
1121 layer_name += " " + base::IntToString(id_); 1088 layer_name += " " + base::IntToString(id_);
1122 1089
1123 layer()->set_name(layer_name); 1090 layer()->set_name(layer_name);
1124 #endif 1091 #endif
1125 } 1092 }
1126 1093
1127 } // namespace aura 1094 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.h ('k') | ui/aura/window_port.h » ('j') | ui/base/class_property.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698