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

Side by Side Diff: services/ui/public/cpp/window.cc

Issue 2424613002: Remove usage of FOR_EACH_OBSERVER macro in services/ (Closed)
Patch Set: 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
OLDNEW
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 "services/ui/public/cpp/window.h" 5 #include "services/ui/public/cpp/window.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 19 matching lines...) Expand all
30 30
31 namespace { 31 namespace {
32 32
33 void NotifyWindowTreeChangeAtReceiver( 33 void NotifyWindowTreeChangeAtReceiver(
34 Window* receiver, 34 Window* receiver,
35 const WindowObserver::TreeChangeParams& params, 35 const WindowObserver::TreeChangeParams& params,
36 bool change_applied) { 36 bool change_applied) {
37 WindowObserver::TreeChangeParams local_params = params; 37 WindowObserver::TreeChangeParams local_params = params;
38 local_params.receiver = receiver; 38 local_params.receiver = receiver;
39 if (change_applied) { 39 if (change_applied) {
40 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(receiver).observers(), 40 for (auto& observer : *WindowPrivate(receiver).observers())
41 OnTreeChanged(local_params)); 41 observer.OnTreeChanged(local_params);
42 } else { 42 } else {
43 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(receiver).observers(), 43 for (auto& observer : *WindowPrivate(receiver).observers())
44 OnTreeChanging(local_params)); 44 observer.OnTreeChanging(local_params);
45 } 45 }
46 } 46 }
47 47
48 void NotifyWindowTreeChangeUp(Window* start_at, 48 void NotifyWindowTreeChangeUp(Window* start_at,
49 const WindowObserver::TreeChangeParams& params, 49 const WindowObserver::TreeChangeParams& params,
50 bool change_applied) { 50 bool change_applied) {
51 for (Window* current = start_at; current; current = current->parent()) 51 for (Window* current = start_at; current; current = current->parent())
52 NotifyWindowTreeChangeAtReceiver(current, params, change_applied); 52 NotifyWindowTreeChangeAtReceiver(current, params, change_applied);
53 } 53 }
54 54
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 OrderChangedNotifier(Window* window, 100 OrderChangedNotifier(Window* window,
101 Window* relative_window, 101 Window* relative_window,
102 mojom::OrderDirection direction) 102 mojom::OrderDirection direction)
103 : window_(window), 103 : window_(window),
104 relative_window_(relative_window), 104 relative_window_(relative_window),
105 direction_(direction) {} 105 direction_(direction) {}
106 106
107 ~OrderChangedNotifier() {} 107 ~OrderChangedNotifier() {}
108 108
109 void NotifyWindowReordering() { 109 void NotifyWindowReordering() {
110 FOR_EACH_OBSERVER( 110 for (auto& observer : *WindowPrivate(window_).observers())
111 WindowObserver, *WindowPrivate(window_).observers(), 111 observer.OnWindowReordering(window_, relative_window_, direction_);
112 OnWindowReordering(window_, relative_window_, direction_));
113 } 112 }
114 113
115 void NotifyWindowReordered() { 114 void NotifyWindowReordered() {
116 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window_).observers(), 115 for (auto& observer : *WindowPrivate(window_).observers())
117 OnWindowReordered(window_, relative_window_, direction_)); 116 observer.OnWindowReordered(window_, relative_window_, direction_);
118 } 117 }
119 118
120 private: 119 private:
121 Window* window_; 120 Window* window_;
122 Window* relative_window_; 121 Window* relative_window_;
123 mojom::OrderDirection direction_; 122 mojom::OrderDirection direction_;
124 123
125 DISALLOW_COPY_AND_ASSIGN(OrderChangedNotifier); 124 DISALLOW_COPY_AND_ASSIGN(OrderChangedNotifier);
126 }; 125 };
127 126
128 class ScopedSetBoundsNotifier { 127 class ScopedSetBoundsNotifier {
129 public: 128 public:
130 ScopedSetBoundsNotifier(Window* window, 129 ScopedSetBoundsNotifier(Window* window,
131 const gfx::Rect& old_bounds, 130 const gfx::Rect& old_bounds,
132 const gfx::Rect& new_bounds) 131 const gfx::Rect& new_bounds)
133 : window_(window), old_bounds_(old_bounds), new_bounds_(new_bounds) { 132 : window_(window), old_bounds_(old_bounds), new_bounds_(new_bounds) {
134 FOR_EACH_OBSERVER( 133 for (auto& observer : *WindowPrivate(window_).observers())
135 WindowObserver, *WindowPrivate(window_).observers(), 134 observer.OnWindowBoundsChanging(window_, old_bounds_, new_bounds_);
136 OnWindowBoundsChanging(window_, old_bounds_, new_bounds_));
137 } 135 }
138 ~ScopedSetBoundsNotifier() { 136 ~ScopedSetBoundsNotifier() {
139 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window_).observers(), 137 for (auto& observer : *WindowPrivate(window_).observers())
140 OnWindowBoundsChanged(window_, old_bounds_, new_bounds_)); 138 observer.OnWindowBoundsChanged(window_, old_bounds_, new_bounds_);
141 } 139 }
142 140
143 private: 141 private:
144 Window* window_; 142 Window* window_;
145 const gfx::Rect old_bounds_; 143 const gfx::Rect old_bounds_;
146 const gfx::Rect new_bounds_; 144 const gfx::Rect new_bounds_;
147 145
148 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); 146 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
149 }; 147 };
150 148
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 509
512 return std::string(); 510 return std::string();
513 } 511 }
514 512
515 //////////////////////////////////////////////////////////////////////////////// 513 ////////////////////////////////////////////////////////////////////////////////
516 // Window, protected: 514 // Window, protected:
517 515
518 Window::Window() : Window(nullptr, static_cast<Id>(-1)) {} 516 Window::Window() : Window(nullptr, static_cast<Id>(-1)) {}
519 517
520 Window::~Window() { 518 Window::~Window() {
521 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); 519 for (auto& observer : observers_)
520 observer.OnWindowDestroying(this);
522 if (client_) 521 if (client_)
523 client_->OnWindowDestroying(this); 522 client_->OnWindowDestroying(this);
524 523
525 if (HasFocus()) { 524 if (HasFocus()) {
526 // The focused window is being removed. When this happens the server 525 // The focused window is being removed. When this happens the server
527 // advances focus. We don't want to randomly pick a Window to get focus, so 526 // advances focus. We don't want to randomly pick a Window to get focus, so
528 // we update local state only, and wait for the next focus change from the 527 // we update local state only, and wait for the next focus change from the
529 // server. 528 // server.
530 client_->LocalSetFocus(nullptr); 529 client_->LocalSetFocus(nullptr);
531 } 530 }
(...skipping 20 matching lines...) Expand all
552 551
553 // We may still have children. This can happen if the embedder destroys the 552 // We may still have children. This can happen if the embedder destroys the
554 // root while we're still alive. 553 // root while we're still alive.
555 while (!children_.empty()) { 554 while (!children_.empty()) {
556 Window* child = children_.front(); 555 Window* child = children_.front();
557 LocalRemoveChild(child); 556 LocalRemoveChild(child);
558 DCHECK(children_.empty() || children_.front() != child); 557 DCHECK(children_.empty() || children_.front() != child);
559 } 558 }
560 559
561 // Notify observers before clearing properties (order matches aura::Window). 560 // Notify observers before clearing properties (order matches aura::Window).
562 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); 561 for (auto& observer : observers_)
562 observer.OnWindowDestroyed(this);
563 563
564 // Clear properties. 564 // Clear properties.
565 for (auto& pair : prop_map_) { 565 for (auto& pair : prop_map_) {
566 if (pair.second.deallocator) 566 if (pair.second.deallocator)
567 (*pair.second.deallocator)(pair.second.value); 567 (*pair.second.deallocator)(pair.second.value);
568 } 568 }
569 prop_map_.clear(); 569 prop_map_.clear();
570 570
571 // Invoke after observers so that can clean up any internal state observers 571 // Invoke after observers so that can clean up any internal state observers
572 // may have changed. 572 // may have changed.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 int64_t old = GetLocalPropertyInternal(key, default_value); 620 int64_t old = GetLocalPropertyInternal(key, default_value);
621 if (value == default_value) { 621 if (value == default_value) {
622 prop_map_.erase(key); 622 prop_map_.erase(key);
623 } else { 623 } else {
624 Value prop_value; 624 Value prop_value;
625 prop_value.name = name; 625 prop_value.name = name;
626 prop_value.value = value; 626 prop_value.value = value;
627 prop_value.deallocator = deallocator; 627 prop_value.deallocator = deallocator;
628 prop_map_[key] = prop_value; 628 prop_map_[key] = prop_value;
629 } 629 }
630 FOR_EACH_OBSERVER(WindowObserver, observers_, 630 for (auto& observer : observers_)
631 OnWindowLocalPropertyChanged(this, key, old)); 631 observer.OnWindowLocalPropertyChanged(this, key, old);
632 return old; 632 return old;
633 } 633 }
634 634
635 int64_t Window::GetLocalPropertyInternal(const void* key, 635 int64_t Window::GetLocalPropertyInternal(const void* key,
636 int64_t default_value) const { 636 int64_t default_value) const {
637 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key); 637 std::map<const void*, Value>::const_iterator iter = prop_map_.find(key);
638 if (iter == prop_map_.end()) 638 if (iter == prop_map_.end())
639 return default_value; 639 return default_value;
640 return iter->second.value; 640 return iter->second.value;
641 } 641 }
(...skipping 22 matching lines...) Expand all
664 RemoveTransientWindowImpl(transient_window); 664 RemoveTransientWindowImpl(transient_window);
665 transient_children_.push_back(transient_window); 665 transient_children_.push_back(transient_window);
666 transient_window->transient_parent_ = this; 666 transient_window->transient_parent_ = this;
667 667
668 // Restack |transient_window| properly above its transient parent, if they 668 // Restack |transient_window| properly above its transient parent, if they
669 // share the same parent. 669 // share the same parent.
670 if (transient_window->parent() == parent()) 670 if (transient_window->parent() == parent())
671 RestackTransientDescendants(this, &GetStackingTarget, 671 RestackTransientDescendants(this, &GetStackingTarget,
672 &ReorderWithoutNotification); 672 &ReorderWithoutNotification);
673 673
674 FOR_EACH_OBSERVER(WindowObserver, observers_, 674 for (auto& observer : observers_)
675 OnTransientChildAdded(this, transient_window)); 675 observer.OnTransientChildAdded(this, transient_window);
676 } 676 }
677 677
678 void Window::LocalRemoveTransientWindow(Window* transient_window) { 678 void Window::LocalRemoveTransientWindow(Window* transient_window) {
679 DCHECK_EQ(this, transient_window->transient_parent()); 679 DCHECK_EQ(this, transient_window->transient_parent());
680 RemoveTransientWindowImpl(transient_window); 680 RemoveTransientWindowImpl(transient_window);
681 FOR_EACH_OBSERVER(WindowObserver, observers_, 681 for (auto& observer : observers_)
682 OnTransientChildRemoved(this, transient_window)); 682 observer.OnTransientChildRemoved(this, transient_window);
683 } 683 }
684 684
685 void Window::LocalSetModal() { 685 void Window::LocalSetModal() {
686 is_modal_ = true; 686 is_modal_ = true;
687 } 687 }
688 688
689 bool Window::LocalReorder(Window* relative, mojom::OrderDirection direction) { 689 bool Window::LocalReorder(Window* relative, mojom::OrderDirection direction) {
690 OrderChangedNotifier notifier(this, relative, direction); 690 OrderChangedNotifier notifier(this, relative, direction);
691 return ReorderImpl(this, relative, direction, &notifier); 691 return ReorderImpl(this, relative, direction, &notifier);
692 } 692 }
693 693
694 void Window::LocalSetBounds(const gfx::Rect& old_bounds, 694 void Window::LocalSetBounds(const gfx::Rect& old_bounds,
695 const gfx::Rect& new_bounds) { 695 const gfx::Rect& new_bounds) {
696 // If this client owns the window, then it should be the only one to change 696 // If this client owns the window, then it should be the only one to change
697 // the bounds. 697 // the bounds.
698 DCHECK(!WasCreatedByThisClient() || old_bounds == bounds_); 698 DCHECK(!WasCreatedByThisClient() || old_bounds == bounds_);
699 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); 699 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds);
700 bounds_ = new_bounds; 700 bounds_ = new_bounds;
701 } 701 }
702 702
703 void Window::LocalSetClientArea( 703 void Window::LocalSetClientArea(
704 const gfx::Insets& new_client_area, 704 const gfx::Insets& new_client_area,
705 const std::vector<gfx::Rect>& additional_client_areas) { 705 const std::vector<gfx::Rect>& additional_client_areas) {
706 const std::vector<gfx::Rect> old_additional_client_areas = 706 const std::vector<gfx::Rect> old_additional_client_areas =
707 additional_client_areas_; 707 additional_client_areas_;
708 const gfx::Insets old_client_area = client_area_; 708 const gfx::Insets old_client_area = client_area_;
709 client_area_ = new_client_area; 709 client_area_ = new_client_area;
710 additional_client_areas_ = additional_client_areas; 710 additional_client_areas_ = additional_client_areas;
711 FOR_EACH_OBSERVER(WindowObserver, observers_, 711 for (auto& observer : observers_) {
712 OnWindowClientAreaChanged(this, old_client_area, 712 observer.OnWindowClientAreaChanged(this, old_client_area,
713 old_additional_client_areas)); 713 old_additional_client_areas);
714 }
714 } 715 }
715 716
716 void Window::LocalSetDisplay(int64_t display_id) { 717 void Window::LocalSetDisplay(int64_t display_id) {
717 display_id_ = display_id; 718 display_id_ = display_id;
718 // TODO(sad): Notify observers (of this window, and of the descendant windows) 719 // TODO(sad): Notify observers (of this window, and of the descendant windows)
719 // when a window moves from one display into another. https://crbug.com/614887 720 // when a window moves from one display into another. https://crbug.com/614887
720 } 721 }
721 722
722 void Window::LocalSetParentDrawn(bool value) { 723 void Window::LocalSetParentDrawn(bool value) {
723 if (parent_drawn_ == value) 724 if (parent_drawn_ == value)
724 return; 725 return;
725 726
726 // As IsDrawn() is derived from |visible_| and |parent_drawn_|, only send 727 // As IsDrawn() is derived from |visible_| and |parent_drawn_|, only send
727 // drawn notification is the value of IsDrawn() is really changing. 728 // drawn notification is the value of IsDrawn() is really changing.
728 if (IsDrawn() == value) { 729 if (IsDrawn() == value) {
729 parent_drawn_ = value; 730 parent_drawn_ = value;
730 return; 731 return;
731 } 732 }
732 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanging(this)); 733 for (auto& observer : observers_)
734 observer.OnWindowDrawnChanging(this);
733 parent_drawn_ = value; 735 parent_drawn_ = value;
734 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanged(this)); 736 for (auto& observer : observers_)
737 observer.OnWindowDrawnChanged(this);
735 } 738 }
736 739
737 void Window::LocalSetVisible(bool visible) { 740 void Window::LocalSetVisible(bool visible) {
738 if (visible_ == visible) 741 if (visible_ == visible)
739 return; 742 return;
740 743
741 FOR_EACH_OBSERVER(WindowObserver, observers_, 744 for (auto& observer : observers_)
742 OnWindowVisibilityChanging(this, visible)); 745 observer.OnWindowVisibilityChanging(this, visible);
743 visible_ = visible; 746 visible_ = visible;
744 if (parent_) { 747 if (parent_) {
745 FOR_EACH_OBSERVER(WindowObserver, parent_->observers_, 748 for (auto& observer : parent_->observers_)
746 OnChildWindowVisibilityChanged(this, visible)); 749 observer.OnChildWindowVisibilityChanged(this, visible);
747 } 750 }
748 751
749 NotifyWindowVisibilityChanged(this, visible); 752 NotifyWindowVisibilityChanged(this, visible);
750 } 753 }
751 754
752 void Window::LocalSetOpacity(float opacity) { 755 void Window::LocalSetOpacity(float opacity) {
753 if (opacity_ == opacity) 756 if (opacity_ == opacity)
754 return; 757 return;
755 758
756 float old_opacity = opacity_; 759 float old_opacity = opacity_;
757 opacity_ = opacity; 760 opacity_ = opacity;
758 FOR_EACH_OBSERVER(WindowObserver, observers_, 761 for (auto& observer : observers_)
759 OnWindowOpacityChanged(this, old_opacity, opacity_)); 762 observer.OnWindowOpacityChanged(this, old_opacity, opacity_);
760 } 763 }
761 764
762 void Window::LocalSetPredefinedCursor(mojom::Cursor cursor_id) { 765 void Window::LocalSetPredefinedCursor(mojom::Cursor cursor_id) {
763 if (cursor_id_ == cursor_id) 766 if (cursor_id_ == cursor_id)
764 return; 767 return;
765 768
766 cursor_id_ = cursor_id; 769 cursor_id_ = cursor_id;
767 FOR_EACH_OBSERVER(WindowObserver, observers_, 770 for (auto& observer : observers_)
768 OnWindowPredefinedCursorChanged(this, cursor_id)); 771 observer.OnWindowPredefinedCursorChanged(this, cursor_id);
769 } 772 }
770 773
771 void Window::LocalSetSharedProperty(const std::string& name, 774 void Window::LocalSetSharedProperty(const std::string& name,
772 const std::vector<uint8_t>* value) { 775 const std::vector<uint8_t>* value) {
773 std::vector<uint8_t> old_value; 776 std::vector<uint8_t> old_value;
774 std::vector<uint8_t>* old_value_ptr = nullptr; 777 std::vector<uint8_t>* old_value_ptr = nullptr;
775 auto it = properties_.find(name); 778 auto it = properties_.find(name);
776 if (it != properties_.end()) { 779 if (it != properties_.end()) {
777 old_value = it->second; 780 old_value = it->second;
778 old_value_ptr = &old_value; 781 old_value_ptr = &old_value;
779 782
780 if (value && old_value == *value) 783 if (value && old_value == *value)
781 return; 784 return;
782 } else if (!value) { 785 } else if (!value) {
783 // This property isn't set in |properties_| and |value| is nullptr, so 786 // This property isn't set in |properties_| and |value| is nullptr, so
784 // there's no change. 787 // there's no change.
785 return; 788 return;
786 } 789 }
787 790
788 if (value) { 791 if (value) {
789 properties_[name] = *value; 792 properties_[name] = *value;
790 } else if (it != properties_.end()) { 793 } else if (it != properties_.end()) {
791 properties_.erase(it); 794 properties_.erase(it);
792 } 795 }
793 796
794 FOR_EACH_OBSERVER( 797 for (auto& observer : observers_)
795 WindowObserver, observers_, 798 observer.OnWindowSharedPropertyChanged(this, name, old_value_ptr, value);
796 OnWindowSharedPropertyChanged(this, name, old_value_ptr, value));
797 } 799 }
798 800
799 void Window::LocalSetSurfaceId(std::unique_ptr<SurfaceInfo> surface_info) { 801 void Window::LocalSetSurfaceId(std::unique_ptr<SurfaceInfo> surface_info) {
800 if (surface_info_) { 802 if (surface_info_) {
801 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id; 803 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id;
802 if (!existing_surface_id.is_null() && 804 if (!existing_surface_id.is_null() &&
803 existing_surface_id != surface_info->surface_id) { 805 existing_surface_id != surface_info->surface_id) {
804 // Return the existing surface sequence. 806 // Return the existing surface sequence.
805 if (client_) { 807 if (client_) {
806 client_->OnWindowSurfaceDetached(server_id_, 808 client_->OnWindowSurfaceDetached(server_id_,
(...skipping 28 matching lines...) Expand all
835 NotifyWindowVisibilityChangedUp(target, visible); 837 NotifyWindowVisibilityChangedUp(target, visible);
836 } 838 }
837 839
838 bool Window::NotifyWindowVisibilityChangedAtReceiver(Window* target, 840 bool Window::NotifyWindowVisibilityChangedAtReceiver(Window* target,
839 bool visible) { 841 bool visible) {
840 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one 842 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one
841 // of the observers. We create an local observer for that. In that case we 843 // of the observers. We create an local observer for that. In that case we
842 // exit without further access to any members. 844 // exit without further access to any members.
843 WindowTracker tracker; 845 WindowTracker tracker;
844 tracker.Add(this); 846 tracker.Add(this);
845 FOR_EACH_OBSERVER(WindowObserver, observers_, 847 for (auto& observer : observers_)
846 OnWindowVisibilityChanged(target, visible)); 848 observer.OnWindowVisibilityChanged(target, visible);
847 return tracker.Contains(this); 849 return tracker.Contains(this);
848 } 850 }
849 851
850 bool Window::NotifyWindowVisibilityChangedDown(Window* target, bool visible) { 852 bool Window::NotifyWindowVisibilityChangedDown(Window* target, bool visible) {
851 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) 853 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible))
852 return false; // |this| was deleted. 854 return false; // |this| was deleted.
853 std::set<const Window*> child_already_processed; 855 std::set<const Window*> child_already_processed;
854 bool child_destroyed = false; 856 bool child_destroyed = false;
855 do { 857 do {
856 child_destroyed = false; 858 child_destroyed = false;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 notifier->NotifyWindowReordered(); 956 notifier->NotifyWindowReordered();
955 957
956 return true; 958 return true;
957 } 959 }
958 960
959 // static 961 // static
960 Window** Window::GetStackingTarget(Window* window) { 962 Window** Window::GetStackingTarget(Window* window) {
961 return &window->stacking_target_; 963 return &window->stacking_target_;
962 } 964 }
963 } // namespace ui 965 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/input_devices/input_device_client.cc ('k') | services/ui/public/cpp/window_tree_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698