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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
17 #include "ui/aura/client/event_client.h" | 17 #include "ui/aura/client/event_client.h" |
18 #include "ui/aura/client/screen_position_client.h" | 18 #include "ui/aura/client/screen_position_client.h" |
19 #include "ui/aura/client/stacking_client.h" | 19 #include "ui/aura/client/stacking_client.h" |
20 #include "ui/aura/client/visibility_client.h" | 20 #include "ui/aura/client/visibility_client.h" |
21 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
22 #include "ui/aura/focus_manager.h" | 22 #include "ui/aura/focus_manager.h" |
23 #include "ui/aura/layout_manager.h" | 23 #include "ui/aura/layout_manager.h" |
24 #include "ui/aura/root_window.h" | 24 #include "ui/aura/root_window.h" |
25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
26 #include "ui/aura/window_destruction_observer.h" | |
26 #include "ui/aura/window_observer.h" | 27 #include "ui/aura/window_observer.h" |
27 #include "ui/base/animation/multi_animation.h" | 28 #include "ui/base/animation/multi_animation.h" |
28 #include "ui/compositor/compositor.h" | 29 #include "ui/compositor/compositor.h" |
29 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
30 #include "ui/gfx/canvas.h" | 31 #include "ui/gfx/canvas.h" |
31 #include "ui/gfx/path.h" | 32 #include "ui/gfx/path.h" |
32 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
33 | 34 |
34 namespace aura { | 35 namespace aura { |
35 | 36 |
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 OnWindowHierarchyChanged(local_params)); | 976 OnWindowHierarchyChanged(local_params)); |
976 break; | 977 break; |
977 default: | 978 default: |
978 NOTREACHED(); | 979 NOTREACHED(); |
979 break; | 980 break; |
980 } | 981 } |
981 } | 982 } |
982 | 983 |
983 void Window::NotifyWindowVisibilityChanged(aura::Window* target, | 984 void Window::NotifyWindowVisibilityChanged(aura::Window* target, |
984 bool visible) { | 985 bool visible) { |
985 NotifyWindowVisibilityChangedDown(target, visible); | 986 if (!NotifyWindowVisibilityChangedDown(target, visible)) { |
987 return; // |this| has been deleted. | |
988 } | |
986 NotifyWindowVisibilityChangedUp(target, visible); | 989 NotifyWindowVisibilityChangedUp(target, visible); |
987 } | 990 } |
988 | 991 |
989 void Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, | 992 bool Window::NotifyWindowVisibilityChangedAtReceiver(aura::Window* target, |
990 bool visible) { | 993 bool visible) { |
994 // |this| may be deleted during a call to OnWindowVisibilityChanged | |
995 // on one of the observers. We create an local observer for that. In | |
996 // that case we exit without further access to any members. | |
997 WindowDestructionObserver destruction_observer(this); | |
998 AddObserver(&destruction_observer); | |
Ben Goodger (Google)
2013/03/19 21:21:41
WDO's ctor should just add the observer. Likewise
sschmitz
2013/03/19 22:12:13
Done.
| |
991 FOR_EACH_OBSERVER(WindowObserver, observers_, | 999 FOR_EACH_OBSERVER(WindowObserver, observers_, |
992 OnWindowVisibilityChanged(target, visible)); | 1000 OnWindowVisibilityChanged(target, visible)); |
1001 if (destruction_observer.destroyed()) | |
Ben Goodger (Google)
2013/03/19 21:21:41
... then the rest of this function is simply
retu
sschmitz
2013/03/19 22:12:13
Done.
| |
1002 return false; // |this| has been deleted. | |
1003 RemoveObserver(&destruction_observer); | |
1004 return true; | |
993 } | 1005 } |
994 | 1006 |
995 void Window::NotifyWindowVisibilityChangedDown(aura::Window* target, | 1007 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target, |
996 bool visible) { | 1008 bool visible) { |
997 NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1009 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) |
998 for (Window::Windows::const_iterator it = children_.begin(); | 1010 return false; // |this| was deleted. |
999 it != children_.end(); ++it) { | 1011 std::set<const Window*> child_already_processed; |
1000 (*it)->NotifyWindowVisibilityChangedDown(target, visible); | 1012 bool child_destroyed = false; |
1001 } | 1013 do { |
1014 child_destroyed = false; | |
1015 for (Window::Windows::const_iterator it = children_.begin(); | |
1016 it != children_.end(); ++it) { | |
1017 if (!child_already_processed.insert(*it).second) | |
1018 continue; | |
1019 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible)) { | |
1020 // |*it| was deleted, |it| is invalid and |children_| has changed. | |
1021 // We exit the current for-loop and enter a new one. | |
1022 child_destroyed = true; | |
1023 break; | |
1024 } | |
1025 } | |
1026 } while (child_destroyed); | |
1027 return true; | |
1002 } | 1028 } |
1003 | 1029 |
1004 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, | 1030 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, |
1005 bool visible) { | 1031 bool visible) { |
1006 for (Window* window = this; window; window = window->parent()) | 1032 for (Window* window = this; window; window = window->parent()) { |
1007 window->NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1033 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); |
1034 DCHECK(ret); | |
1035 } | |
1008 } | 1036 } |
1009 | 1037 |
1010 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, | 1038 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, |
1011 bool contained_mouse) { | 1039 bool contained_mouse) { |
1012 if (layout_manager_.get()) | 1040 if (layout_manager_.get()) |
1013 layout_manager_->OnWindowResized(); | 1041 layout_manager_->OnWindowResized(); |
1014 if (delegate_) | 1042 if (delegate_) |
1015 delegate_->OnBoundsChanged(old_bounds, bounds()); | 1043 delegate_->OnBoundsChanged(old_bounds, bounds()); |
1016 FOR_EACH_OBSERVER(WindowObserver, | 1044 FOR_EACH_OBSERVER(WindowObserver, |
1017 observers_, | 1045 observers_, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 bool contains_mouse = false; | 1095 bool contains_mouse = false; |
1068 if (IsVisible()) { | 1096 if (IsVisible()) { |
1069 RootWindow* root_window = GetRootWindow(); | 1097 RootWindow* root_window = GetRootWindow(); |
1070 contains_mouse = root_window && | 1098 contains_mouse = root_window && |
1071 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); | 1099 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); |
1072 } | 1100 } |
1073 return contains_mouse; | 1101 return contains_mouse; |
1074 } | 1102 } |
1075 | 1103 |
1076 } // namespace aura | 1104 } // namespace aura |
OLD | NEW |