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

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

Issue 2422073002: Reduce FOR_EACH_OBSERVER usage in ui/ (Closed)
Patch Set: remove space Created 4 years, 2 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
« no previous file with comments | « ui/aura/test/test_focus_client.cc ('k') | ui/aura/window_tree_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 103
104 Window::~Window() { 104 Window::~Window() {
105 if (layer()->owner() == this) 105 if (layer()->owner() == this)
106 layer()->CompleteAllAnimations(); 106 layer()->CompleteAllAnimations();
107 layer()->SuppressPaint(); 107 layer()->SuppressPaint();
108 108
109 // Let the delegate know we're in the processing of destroying. 109 // Let the delegate know we're in the processing of destroying.
110 if (delegate_) 110 if (delegate_)
111 delegate_->OnWindowDestroying(this); 111 delegate_->OnWindowDestroying(this);
112 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); 112 for (WindowObserver& observer : observers_)
113 observer.OnWindowDestroying(this);
113 114
114 // While we are being destroyed, our target handler may also be in the 115 // While we are being destroyed, our target handler may also be in the
115 // process of destruction or already destroyed, so do not forward any 116 // process of destruction or already destroyed, so do not forward any
116 // input events at the ui::EP_TARGET phase. 117 // input events at the ui::EP_TARGET phase.
117 SetTargetHandler(nullptr); 118 SetTargetHandler(nullptr);
118 119
119 // TODO(beng): See comment in window_event_dispatcher.h. This shouldn't be 120 // TODO(beng): See comment in window_event_dispatcher.h. This shouldn't be
120 // necessary but unfortunately is right now due to ordering 121 // necessary but unfortunately is right now due to ordering
121 // peculiarities. WED must be notified _after_ other observers 122 // peculiarities. WED must be notified _after_ other observers
122 // are notified of pending teardown but before the hierarchy 123 // are notified of pending teardown but before the hierarchy
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void Window::SetName(const std::string& name) { 187 void Window::SetName(const std::string& name) {
187 name_ = name; 188 name_ = name;
188 if (layer()) 189 if (layer())
189 UpdateLayerName(); 190 UpdateLayerName();
190 } 191 }
191 192
192 void Window::SetTitle(const base::string16& title) { 193 void Window::SetTitle(const base::string16& title) {
193 if (title == title_) 194 if (title == title_)
194 return; 195 return;
195 title_ = title; 196 title_ = title;
196 FOR_EACH_OBSERVER(WindowObserver, 197 for (WindowObserver& observer : observers_)
197 observers_, 198 observer.OnWindowTitleChanged(this);
198 OnWindowTitleChanged(this));
199 } 199 }
200 200
201 void Window::SetTransparent(bool transparent) { 201 void Window::SetTransparent(bool transparent) {
202 transparent_ = transparent; 202 transparent_ = transparent;
203 if (layer()) 203 if (layer())
204 layer()->SetFillsBoundsOpaquely(!transparent_); 204 layer()->SetFillsBoundsOpaquely(!transparent_);
205 } 205 }
206 206
207 void Window::SetFillsBoundsCompletely(bool fills_bounds) { 207 void Window::SetFillsBoundsCompletely(bool fills_bounds) {
208 layer()->SetFillsBoundsCompletely(fills_bounds); 208 layer()->SetFillsBoundsCompletely(fills_bounds);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 if (screen_position_client) { 269 if (screen_position_client) {
270 gfx::Point origin = bounds.origin(); 270 gfx::Point origin = bounds.origin();
271 screen_position_client->ConvertPointToScreen(root, &origin); 271 screen_position_client->ConvertPointToScreen(root, &origin);
272 bounds.set_origin(origin); 272 bounds.set_origin(origin);
273 } 273 }
274 } 274 }
275 return bounds; 275 return bounds;
276 } 276 }
277 277
278 void Window::SetTransform(const gfx::Transform& transform) { 278 void Window::SetTransform(const gfx::Transform& transform) {
279 FOR_EACH_OBSERVER(WindowObserver, observers_, 279 for (WindowObserver& observer : observers_)
280 OnWindowTransforming(this)); 280 observer.OnWindowTransforming(this);
281 layer()->SetTransform(transform); 281 layer()->SetTransform(transform);
282 FOR_EACH_OBSERVER(WindowObserver, observers_, 282 for (WindowObserver& observer : observers_)
283 OnWindowTransformed(this)); 283 observer.OnWindowTransformed(this);
284 NotifyAncestorWindowTransformed(this); 284 NotifyAncestorWindowTransformed(this);
285 } 285 }
286 286
287 void Window::SetLayoutManager(LayoutManager* layout_manager) { 287 void Window::SetLayoutManager(LayoutManager* layout_manager) {
288 if (layout_manager == layout_manager_.get()) 288 if (layout_manager == layout_manager_.get())
289 return; 289 return;
290 layout_manager_.reset(layout_manager); 290 layout_manager_.reset(layout_manager);
291 if (!layout_manager) 291 if (!layout_manager)
292 return; 292 return;
293 // If we're changing to a new layout manager, ensure it is aware of all the 293 // If we're changing to a new layout manager, ensure it is aware of all the
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 children_.end()); 377 children_.end());
378 if (child->parent()) 378 if (child->parent())
379 child->parent()->RemoveChildImpl(child, this); 379 child->parent()->RemoveChildImpl(child, this);
380 380
381 child->parent_ = this; 381 child->parent_ = this;
382 layer()->Add(child->layer()); 382 layer()->Add(child->layer());
383 383
384 children_.push_back(child); 384 children_.push_back(child);
385 if (layout_manager_) 385 if (layout_manager_)
386 layout_manager_->OnWindowAddedToLayout(child); 386 layout_manager_->OnWindowAddedToLayout(child);
387 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowAdded(child)); 387 for (WindowObserver& observer : observers_)
388 observer.OnWindowAdded(child);
388 child->OnParentChanged(); 389 child->OnParentChanged();
389 390
390 Window* root_window = GetRootWindow(); 391 Window* root_window = GetRootWindow();
391 if (root_window && old_root != root_window) { 392 if (root_window && old_root != root_window) {
392 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child); 393 root_window->GetHost()->dispatcher()->OnWindowAddedToRootWindow(child);
393 child->NotifyAddedToRootWindow(); 394 child->NotifyAddedToRootWindow();
394 } 395 }
395 396
396 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED; 397 params.phase = WindowObserver::HierarchyChangeParams::HIERARCHY_CHANGED;
397 NotifyWindowHierarchyChange(params); 398 NotifyWindowHierarchyChange(params);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 int64_t old = GetPropertyInternal(key, default_value); 671 int64_t old = GetPropertyInternal(key, default_value);
671 if (value == default_value) { 672 if (value == default_value) {
672 prop_map_.erase(key); 673 prop_map_.erase(key);
673 } else { 674 } else {
674 Value prop_value; 675 Value prop_value;
675 prop_value.name = name; 676 prop_value.name = name;
676 prop_value.value = value; 677 prop_value.value = value;
677 prop_value.deallocator = deallocator; 678 prop_value.deallocator = deallocator;
678 prop_map_[key] = prop_value; 679 prop_map_[key] = prop_value;
679 } 680 }
680 FOR_EACH_OBSERVER(WindowObserver, observers_, 681 for (WindowObserver& observer : observers_)
681 OnWindowPropertyChanged(this, key, old)); 682 observer.OnWindowPropertyChanged(this, key, old);
682 return old; 683 return old;
683 } 684 }
684 685
685 int64_t Window::GetPropertyInternal(const void* key, 686 int64_t Window::GetPropertyInternal(const void* key,
686 int64_t default_value) const { 687 int64_t default_value) const {
687 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); 688 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
688 if (iter == prop_map_.end()) 689 if (iter == prop_map_.end())
689 return default_value; 690 return default_value;
690 return iter->second.value; 691 return iter->second.value;
691 } 692 }
(...skipping 25 matching lines...) Expand all
717 // changed notification from the layer (this typically happens after animating 718 // changed notification from the layer (this typically happens after animating
718 // hidden). We must notify ourselves. 719 // hidden). We must notify ourselves.
719 if (layer()->delegate() != this) 720 if (layer()->delegate() != this)
720 OnLayerBoundsChanged(old_bounds); 721 OnLayerBoundsChanged(old_bounds);
721 } 722 }
722 723
723 void Window::SetVisible(bool visible) { 724 void Window::SetVisible(bool visible) {
724 if (visible == layer()->GetTargetVisibility()) 725 if (visible == layer()->GetTargetVisibility())
725 return; // No change. 726 return; // No change.
726 727
727 FOR_EACH_OBSERVER(WindowObserver, observers_, 728 for (WindowObserver& observer : observers_)
728 OnWindowVisibilityChanging(this, visible)); 729 observer.OnWindowVisibilityChanging(this, visible);
729 730
730 client::VisibilityClient* visibility_client = 731 client::VisibilityClient* visibility_client =
731 client::GetVisibilityClient(this); 732 client::GetVisibilityClient(this);
732 if (visibility_client) 733 if (visibility_client)
733 visibility_client->UpdateLayerVisibility(this, visible); 734 visibility_client->UpdateLayerVisibility(this, visible);
734 else 735 else
735 layer()->SetVisible(visible); 736 layer()->SetVisible(visible);
736 visible_ = visible; 737 visible_ = visible;
737 SchedulePaint(); 738 SchedulePaint();
738 if (parent_ && parent_->layout_manager_) 739 if (parent_ && parent_->layout_manager_)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 if (match) 805 if (match)
805 return match; 806 return match;
806 } 807 }
807 808
808 return delegate_ ? this : NULL; 809 return delegate_ ? this : NULL;
809 } 810 }
810 811
811 void Window::RemoveChildImpl(Window* child, Window* new_parent) { 812 void Window::RemoveChildImpl(Window* child, Window* new_parent) {
812 if (layout_manager_) 813 if (layout_manager_)
813 layout_manager_->OnWillRemoveWindowFromLayout(child); 814 layout_manager_->OnWillRemoveWindowFromLayout(child);
814 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWillRemoveWindow(child)); 815 for (WindowObserver& observer : observers_)
816 observer.OnWillRemoveWindow(child);
815 Window* root_window = child->GetRootWindow(); 817 Window* root_window = child->GetRootWindow();
816 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL; 818 Window* new_root_window = new_parent ? new_parent->GetRootWindow() : NULL;
817 if (root_window && root_window != new_root_window) 819 if (root_window && root_window != new_root_window)
818 child->NotifyRemovingFromRootWindow(new_root_window); 820 child->NotifyRemovingFromRootWindow(new_root_window);
819 821
820 if (child->OwnsLayer()) 822 if (child->OwnsLayer())
821 layer()->Remove(child->layer()); 823 layer()->Remove(child->layer());
822 child->parent_ = NULL; 824 child->parent_ = NULL;
823 Windows::iterator i = std::find(children_.begin(), children_.end(), child); 825 Windows::iterator i = std::find(children_.begin(), children_.end(), child);
824 DCHECK(i != children_.end()); 826 DCHECK(i != children_.end());
825 children_.erase(i); 827 children_.erase(i);
826 child->OnParentChanged(); 828 child->OnParentChanged();
827 if (layout_manager_) 829 if (layout_manager_)
828 layout_manager_->OnWindowRemovedFromLayout(child); 830 layout_manager_->OnWindowRemovedFromLayout(child);
829 } 831 }
830 832
831 void Window::OnParentChanged() { 833 void Window::OnParentChanged() {
832 FOR_EACH_OBSERVER( 834 for (WindowObserver& observer : observers_)
833 WindowObserver, observers_, OnWindowParentChanged(this, parent_)); 835 observer.OnWindowParentChanged(this, parent_);
834 } 836 }
835 837
836 void Window::StackChildRelativeTo(Window* child, 838 void Window::StackChildRelativeTo(Window* child,
837 Window* target, 839 Window* target,
838 StackDirection direction) { 840 StackDirection direction) {
839 DCHECK_NE(child, target); 841 DCHECK_NE(child, target);
840 DCHECK(child); 842 DCHECK(child);
841 DCHECK(target); 843 DCHECK(target);
842 DCHECK_EQ(this, child->parent()); 844 DCHECK_EQ(this, child->parent());
843 DCHECK_EQ(this, target->parent()); 845 DCHECK_EQ(this, target->parent());
(...skipping 30 matching lines...) Expand all
874 Window* target, 876 Window* target,
875 StackDirection direction) { 877 StackDirection direction) {
876 DCHECK(layer() && child->layer() && target->layer()); 878 DCHECK(layer() && child->layer() && target->layer());
877 if (direction == STACK_ABOVE) 879 if (direction == STACK_ABOVE)
878 layer()->StackAbove(child->layer(), target->layer()); 880 layer()->StackAbove(child->layer(), target->layer());
879 else 881 else
880 layer()->StackBelow(child->layer(), target->layer()); 882 layer()->StackBelow(child->layer(), target->layer());
881 } 883 }
882 884
883 void Window::OnStackingChanged() { 885 void Window::OnStackingChanged() {
884 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowStackingChanged(this)); 886 for (WindowObserver& observer : observers_)
887 observer.OnWindowStackingChanged(this);
885 } 888 }
886 889
887 void Window::NotifyRemovingFromRootWindow(Window* new_root) { 890 void Window::NotifyRemovingFromRootWindow(Window* new_root) {
888 FOR_EACH_OBSERVER(WindowObserver, observers_, 891 for (WindowObserver& observer : observers_)
889 OnWindowRemovingFromRootWindow(this, new_root)); 892 observer.OnWindowRemovingFromRootWindow(this, new_root);
890 for (Window::Windows::const_iterator it = children_.begin(); 893 for (Window::Windows::const_iterator it = children_.begin();
891 it != children_.end(); ++it) { 894 it != children_.end(); ++it) {
892 (*it)->NotifyRemovingFromRootWindow(new_root); 895 (*it)->NotifyRemovingFromRootWindow(new_root);
893 } 896 }
894 } 897 }
895 898
896 void Window::NotifyAddedToRootWindow() { 899 void Window::NotifyAddedToRootWindow() {
897 FOR_EACH_OBSERVER(WindowObserver, observers_, 900 for (WindowObserver& observer : observers_)
898 OnWindowAddedToRootWindow(this)); 901 observer.OnWindowAddedToRootWindow(this);
899 for (Window::Windows::const_iterator it = children_.begin(); 902 for (Window::Windows::const_iterator it = children_.begin();
900 it != children_.end(); ++it) { 903 it != children_.end(); ++it) {
901 (*it)->NotifyAddedToRootWindow(); 904 (*it)->NotifyAddedToRootWindow();
902 } 905 }
903 } 906 }
904 907
905 void Window::NotifyWindowHierarchyChange( 908 void Window::NotifyWindowHierarchyChange(
906 const WindowObserver::HierarchyChangeParams& params) { 909 const WindowObserver::HierarchyChangeParams& params) {
907 params.target->NotifyWindowHierarchyChangeDown(params); 910 params.target->NotifyWindowHierarchyChangeDown(params);
908 switch (params.phase) { 911 switch (params.phase) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 NotifyWindowVisibilityChangedUp(target, visible); 959 NotifyWindowVisibilityChangedUp(target, visible);
957 } 960 }
958 961
959 bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, 962 bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target,
960 bool visible) { 963 bool visible) {
961 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one 964 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one
962 // of the observers. We create an local observer for that. In that case we 965 // of the observers. We create an local observer for that. In that case we
963 // exit without further access to any members. 966 // exit without further access to any members.
964 WindowTracker tracker; 967 WindowTracker tracker;
965 tracker.Add(this); 968 tracker.Add(this);
966 FOR_EACH_OBSERVER(WindowObserver, observers_, 969 for (WindowObserver& observer : observers_)
967 OnWindowVisibilityChanged(target, visible)); 970 observer.OnWindowVisibilityChanged(target, visible);
968 return tracker.Contains(this); 971 return tracker.Contains(this);
969 } 972 }
970 973
971 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target, 974 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target,
972 bool visible) { 975 bool visible) {
973 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) 976 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible))
974 return false; // |this| was deleted. 977 return false; // |this| was deleted.
975 std::set<const Window*> child_already_processed; 978 std::set<const Window*> child_already_processed;
976 bool child_destroyed = false; 979 bool child_destroyed = false;
977 do { 980 do {
(...skipping 17 matching lines...) Expand all
995 bool visible) { 998 bool visible) {
996 // Start with the parent as we already notified |this| 999 // Start with the parent as we already notified |this|
997 // in NotifyWindowVisibilityChangedDown. 1000 // in NotifyWindowVisibilityChangedDown.
998 for (Window* window = parent(); window; window = window->parent()) { 1001 for (Window* window = parent(); window; window = window->parent()) {
999 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); 1002 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible);
1000 DCHECK(ret); 1003 DCHECK(ret);
1001 } 1004 }
1002 } 1005 }
1003 1006
1004 void Window::NotifyAncestorWindowTransformed(Window* source) { 1007 void Window::NotifyAncestorWindowTransformed(Window* source) {
1005 FOR_EACH_OBSERVER(WindowObserver, observers_, 1008 for (WindowObserver& observer : observers_)
1006 OnAncestorWindowTransformed(source, this)); 1009 observer.OnAncestorWindowTransformed(source, this);
1007 for (Window::Windows::const_iterator it = children_.begin(); 1010 for (Window::Windows::const_iterator it = children_.begin();
1008 it != children_.end(); ++it) { 1011 it != children_.end(); ++it) {
1009 (*it)->NotifyAncestorWindowTransformed(source); 1012 (*it)->NotifyAncestorWindowTransformed(source);
1010 } 1013 }
1011 } 1014 }
1012 1015
1013 bool Window::CleanupGestureState() { 1016 bool Window::CleanupGestureState() {
1014 bool state_modified = false; 1017 bool state_modified = false;
1015 state_modified |= ui::GestureRecognizer::Get()->CancelActiveTouches(this); 1018 state_modified |= ui::GestureRecognizer::Get()->CancelActiveTouches(this);
1016 state_modified |= 1019 state_modified |=
1017 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this); 1020 ui::GestureRecognizer::Get()->CleanupStateForConsumer(this);
1018 for (Window::Windows::iterator iter = children_.begin(); 1021 for (Window::Windows::iterator iter = children_.begin();
1019 iter != children_.end(); 1022 iter != children_.end();
1020 ++iter) { 1023 ++iter) {
1021 state_modified |= (*iter)->CleanupGestureState(); 1024 state_modified |= (*iter)->CleanupGestureState();
1022 } 1025 }
1023 return state_modified; 1026 return state_modified;
1024 } 1027 }
1025 1028
1026 void Window::OnPaintLayer(const ui::PaintContext& context) { 1029 void Window::OnPaintLayer(const ui::PaintContext& context) {
1027 Paint(context); 1030 Paint(context);
1028 } 1031 }
1029 1032
1030 void Window::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { 1033 void Window::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) {
1031 DCHECK(layer()); 1034 DCHECK(layer());
1032 FOR_EACH_OBSERVER(WindowObserver, 1035 for (WindowObserver& observer : observers_)
1033 observers_, 1036 observer.OnDelegatedFrameDamage(this, damage_rect_in_dip);
1034 OnDelegatedFrameDamage(this, damage_rect_in_dip));
1035 } 1037 }
1036 1038
1037 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds) { 1039 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds) {
1038 bounds_ = layer()->bounds(); 1040 bounds_ = layer()->bounds();
1039 if (layout_manager_) 1041 if (layout_manager_)
1040 layout_manager_->OnWindowResized(); 1042 layout_manager_->OnWindowResized();
1041 if (delegate_) 1043 if (delegate_)
1042 delegate_->OnBoundsChanged(old_bounds, bounds_); 1044 delegate_->OnBoundsChanged(old_bounds, bounds_);
1043 for (auto& observer : observers_) 1045 for (auto& observer : observers_)
1044 observer.OnWindowBoundsChanged(this, old_bounds, bounds_); 1046 observer.OnWindowBoundsChanged(this, old_bounds, bounds_);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 layer_name = "Unnamed Window"; 1105 layer_name = "Unnamed Window";
1104 1106
1105 if (id_ != -1) 1107 if (id_ != -1)
1106 layer_name += " " + base::IntToString(id_); 1108 layer_name += " " + base::IntToString(id_);
1107 1109
1108 layer()->set_name(layer_name); 1110 layer()->set_name(layer_name);
1109 #endif 1111 #endif
1110 } 1112 }
1111 1113
1112 } // namespace aura 1114 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/test_focus_client.cc ('k') | ui/aura/window_tree_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698