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); |
991 FOR_EACH_OBSERVER(WindowObserver, observers_, | 998 FOR_EACH_OBSERVER(WindowObserver, observers_, |
992 OnWindowVisibilityChanged(target, visible)); | 999 OnWindowVisibilityChanged(target, visible)); |
| 1000 return !destruction_observer.destroyed(); |
993 } | 1001 } |
994 | 1002 |
995 void Window::NotifyWindowVisibilityChangedDown(aura::Window* target, | 1003 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target, |
996 bool visible) { | 1004 bool visible) { |
997 NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1005 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) |
998 for (Window::Windows::const_iterator it = children_.begin(); | 1006 return false; // |this| was deleted. |
999 it != children_.end(); ++it) { | 1007 std::set<const Window*> child_already_processed; |
1000 (*it)->NotifyWindowVisibilityChangedDown(target, visible); | 1008 bool child_destroyed = false; |
1001 } | 1009 do { |
| 1010 child_destroyed = false; |
| 1011 for (Window::Windows::const_iterator it = children_.begin(); |
| 1012 it != children_.end(); ++it) { |
| 1013 if (!child_already_processed.insert(*it).second) |
| 1014 continue; |
| 1015 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible)) { |
| 1016 // |*it| was deleted, |it| is invalid and |children_| has changed. |
| 1017 // We exit the current for-loop and enter a new one. |
| 1018 child_destroyed = true; |
| 1019 break; |
| 1020 } |
| 1021 } |
| 1022 } while (child_destroyed); |
| 1023 return true; |
1002 } | 1024 } |
1003 | 1025 |
1004 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, | 1026 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, |
1005 bool visible) { | 1027 bool visible) { |
1006 for (Window* window = this; window; window = window->parent()) | 1028 for (Window* window = this; window; window = window->parent()) { |
1007 window->NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1029 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); |
| 1030 DCHECK(ret); |
| 1031 } |
1008 } | 1032 } |
1009 | 1033 |
1010 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, | 1034 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, |
1011 bool contained_mouse) { | 1035 bool contained_mouse) { |
1012 if (layout_manager_.get()) | 1036 if (layout_manager_.get()) |
1013 layout_manager_->OnWindowResized(); | 1037 layout_manager_->OnWindowResized(); |
1014 if (delegate_) | 1038 if (delegate_) |
1015 delegate_->OnBoundsChanged(old_bounds, bounds()); | 1039 delegate_->OnBoundsChanged(old_bounds, bounds()); |
1016 FOR_EACH_OBSERVER(WindowObserver, | 1040 FOR_EACH_OBSERVER(WindowObserver, |
1017 observers_, | 1041 observers_, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 bool contains_mouse = false; | 1091 bool contains_mouse = false; |
1068 if (IsVisible()) { | 1092 if (IsVisible()) { |
1069 RootWindow* root_window = GetRootWindow(); | 1093 RootWindow* root_window = GetRootWindow(); |
1070 contains_mouse = root_window && | 1094 contains_mouse = root_window && |
1071 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); | 1095 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); |
1072 } | 1096 } |
1073 return contains_mouse; | 1097 return contains_mouse; |
1074 } | 1098 } |
1075 | 1099 |
1076 } // namespace aura | 1100 } // namespace aura |
OLD | NEW |