OLD | NEW |
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanging(this)); | 725 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanging(this)); |
726 parent_drawn_ = value; | 726 parent_drawn_ = value; |
727 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanged(this)); | 727 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDrawnChanged(this)); |
728 } | 728 } |
729 | 729 |
730 void Window::LocalSetVisible(bool visible) { | 730 void Window::LocalSetVisible(bool visible) { |
731 if (visible_ == visible) | 731 if (visible_ == visible) |
732 return; | 732 return; |
733 | 733 |
734 FOR_EACH_OBSERVER(WindowObserver, observers_, | 734 FOR_EACH_OBSERVER(WindowObserver, observers_, |
735 OnWindowVisibilityChanging(this)); | 735 OnWindowVisibilityChanging(this, visible)); |
736 visible_ = visible; | 736 visible_ = visible; |
737 NotifyWindowVisibilityChanged(this); | 737 if (parent_) { |
| 738 FOR_EACH_OBSERVER(WindowObserver, parent_->observers_, |
| 739 OnChildWindowVisibilityChanged(this, visible)); |
| 740 } |
| 741 |
| 742 NotifyWindowVisibilityChanged(this, visible); |
738 } | 743 } |
739 | 744 |
740 void Window::LocalSetOpacity(float opacity) { | 745 void Window::LocalSetOpacity(float opacity) { |
741 if (opacity_ == opacity) | 746 if (opacity_ == opacity) |
742 return; | 747 return; |
743 | 748 |
744 float old_opacity = opacity_; | 749 float old_opacity = opacity_; |
745 opacity_ = opacity; | 750 opacity_ = opacity; |
746 FOR_EACH_OBSERVER(WindowObserver, observers_, | 751 FOR_EACH_OBSERVER(WindowObserver, observers_, |
747 OnWindowOpacityChanged(this, old_opacity, opacity_)); | 752 OnWindowOpacityChanged(this, old_opacity, opacity_)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 parent()->children().begin(), parent()->children().end(), this); | 795 parent()->children().begin(), parent()->children().end(), this); |
791 DCHECK(window_i != parent()->children().end()); | 796 DCHECK(window_i != parent()->children().end()); |
792 if (window_i != parent()->children().begin() && | 797 if (window_i != parent()->children().begin() && |
793 (*(window_i - 1) == stacking_target_)) | 798 (*(window_i - 1) == stacking_target_)) |
794 return; | 799 return; |
795 } | 800 } |
796 RestackTransientDescendants(this, &GetStackingTarget, | 801 RestackTransientDescendants(this, &GetStackingTarget, |
797 &ReorderWithoutNotification); | 802 &ReorderWithoutNotification); |
798 } | 803 } |
799 | 804 |
800 void Window::NotifyWindowVisibilityChanged(Window* target) { | 805 void Window::NotifyWindowVisibilityChanged(Window* target, bool visible) { |
801 if (!NotifyWindowVisibilityChangedDown(target)) { | 806 if (!NotifyWindowVisibilityChangedDown(target, visible)) |
802 return; // |this| has been deleted. | 807 return; // |this| has been deleted. |
803 } | 808 |
804 NotifyWindowVisibilityChangedUp(target); | 809 NotifyWindowVisibilityChangedUp(target, visible); |
805 } | 810 } |
806 | 811 |
807 bool Window::NotifyWindowVisibilityChangedAtReceiver(Window* target) { | 812 bool Window::NotifyWindowVisibilityChangedAtReceiver(Window* target, |
| 813 bool visible) { |
808 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one | 814 // |this| may be deleted during a call to OnWindowVisibilityChanged() on one |
809 // of the observers. We create an local observer for that. In that case we | 815 // of the observers. We create an local observer for that. In that case we |
810 // exit without further access to any members. | 816 // exit without further access to any members. |
811 WindowTracker tracker; | 817 WindowTracker tracker; |
812 tracker.Add(this); | 818 tracker.Add(this); |
813 FOR_EACH_OBSERVER(WindowObserver, observers_, | 819 FOR_EACH_OBSERVER(WindowObserver, observers_, |
814 OnWindowVisibilityChanged(target)); | 820 OnWindowVisibilityChanged(target, visible)); |
815 return tracker.Contains(this); | 821 return tracker.Contains(this); |
816 } | 822 } |
817 | 823 |
818 bool Window::NotifyWindowVisibilityChangedDown(Window* target) { | 824 bool Window::NotifyWindowVisibilityChangedDown(Window* target, bool visible) { |
819 if (!NotifyWindowVisibilityChangedAtReceiver(target)) | 825 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) |
820 return false; // |this| was deleted. | 826 return false; // |this| was deleted. |
821 std::set<const Window*> child_already_processed; | 827 std::set<const Window*> child_already_processed; |
822 bool child_destroyed = false; | 828 bool child_destroyed = false; |
823 do { | 829 do { |
824 child_destroyed = false; | 830 child_destroyed = false; |
825 for (Window::Children::const_iterator it = children_.begin(); | 831 for (Window::Children::const_iterator it = children_.begin(); |
826 it != children_.end(); ++it) { | 832 it != children_.end(); ++it) { |
827 if (!child_already_processed.insert(*it).second) | 833 if (!child_already_processed.insert(*it).second) |
828 continue; | 834 continue; |
829 if (!(*it)->NotifyWindowVisibilityChangedDown(target)) { | 835 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible)) { |
830 // |*it| was deleted, |it| is invalid and |children_| has changed. We | 836 // |*it| was deleted, |it| is invalid and |children_| has changed. We |
831 // exit the current for-loop and enter a new one. | 837 // exit the current for-loop and enter a new one. |
832 child_destroyed = true; | 838 child_destroyed = true; |
833 break; | 839 break; |
834 } | 840 } |
835 } | 841 } |
836 } while (child_destroyed); | 842 } while (child_destroyed); |
837 return true; | 843 return true; |
838 } | 844 } |
839 | 845 |
840 void Window::NotifyWindowVisibilityChangedUp(Window* target) { | 846 void Window::NotifyWindowVisibilityChangedUp(Window* target, bool visible) { |
841 // Start with the parent as we already notified |this| | 847 // Start with the parent as we already notified |this| |
842 // in NotifyWindowVisibilityChangedDown. | 848 // in NotifyWindowVisibilityChangedDown. |
843 for (Window* window = parent(); window; window = window->parent()) { | 849 for (Window* window = parent(); window; window = window->parent()) { |
844 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target); | 850 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); |
845 DCHECK(ret); | 851 DCHECK(ret); |
846 } | 852 } |
847 } | 853 } |
848 | 854 |
849 bool Window::PrepareForEmbed() { | 855 bool Window::PrepareForEmbed() { |
850 if (!WasCreatedByThisClient()) | 856 if (!WasCreatedByThisClient()) |
851 return false; | 857 return false; |
852 | 858 |
853 while (!children_.empty()) | 859 while (!children_.empty()) |
854 RemoveChild(children_[0]); | 860 RemoveChild(children_[0]); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 notifier->NotifyWindowReordered(); | 929 notifier->NotifyWindowReordered(); |
924 | 930 |
925 return true; | 931 return true; |
926 } | 932 } |
927 | 933 |
928 // static | 934 // static |
929 Window** Window::GetStackingTarget(Window* window) { | 935 Window** Window::GetStackingTarget(Window* window) { |
930 return &window->stacking_target_; | 936 return &window->stacking_target_; |
931 } | 937 } |
932 } // namespace ui | 938 } // namespace ui |
OLD | NEW |