Chromium Code Reviews| 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; | |
|
Ben Goodger (Google)
2013/03/19 18:13:17
I think the API would be a little cleaner here if
sschmitz
2013/03/19 18:36:50
Neat.
Done.
| |
| 998 AddObserver(&destruction_observer); | |
| 999 const Window* copy_this = this; | |
|
Ben Goodger (Google)
2013/03/19 18:13:17
then you wouldn't have to do things like this whic
sschmitz
2013/03/19 18:36:50
Done.
| |
| 991 FOR_EACH_OBSERVER(WindowObserver, observers_, | 1000 FOR_EACH_OBSERVER(WindowObserver, observers_, |
| 992 OnWindowVisibilityChanged(target, visible)); | 1001 OnWindowVisibilityChanged(target, visible)); |
| 1002 if (destruction_observer.was_destroyed(copy_this)) | |
| 1003 return false; // |this| has been deleted. | |
| 1004 RemoveObserver(&destruction_observer); | |
| 1005 return true; | |
| 993 } | 1006 } |
| 994 | 1007 |
| 995 void Window::NotifyWindowVisibilityChangedDown(aura::Window* target, | 1008 bool Window::NotifyWindowVisibilityChangedDown(aura::Window* target, |
| 996 bool visible) { | 1009 bool visible) { |
| 997 NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1010 if (!NotifyWindowVisibilityChangedAtReceiver(target, visible)) |
| 998 for (Window::Windows::const_iterator it = children_.begin(); | 1011 return false; // |this| was deleted. |
| 999 it != children_.end(); ++it) { | 1012 std::set<const Window*> child_already_processed; |
|
Ben Goodger (Google)
2013/03/19 18:13:17
you only fill this, but never actually use it.
sschmitz
2013/03/19 18:36:50
I'm using the fact that set<>::insert() returns a
| |
| 1000 (*it)->NotifyWindowVisibilityChangedDown(target, visible); | 1013 bool child_destroyed = false; |
| 1001 } | 1014 do { |
| 1015 child_destroyed = false; | |
| 1016 for (Window::Windows::const_iterator it = children_.begin(); | |
| 1017 it != children_.end(); ++it) { | |
| 1018 if (!child_already_processed.insert(*it).second) | |
| 1019 continue; | |
| 1020 if (!(*it)->NotifyWindowVisibilityChangedDown(target, visible)) { | |
| 1021 // |*it| was deleted, |it| is invalid and |children_| has changed. | |
| 1022 // We exit the current for-loop and enter a new one. | |
| 1023 child_destroyed = true; | |
| 1024 break; | |
| 1025 } | |
| 1026 } | |
| 1027 } while (child_destroyed); | |
| 1028 return true; | |
| 1002 } | 1029 } |
| 1003 | 1030 |
| 1004 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, | 1031 void Window::NotifyWindowVisibilityChangedUp(aura::Window* target, |
| 1005 bool visible) { | 1032 bool visible) { |
| 1006 for (Window* window = this; window; window = window->parent()) | 1033 for (Window* window = this; window; window = window->parent()) { |
| 1007 window->NotifyWindowVisibilityChangedAtReceiver(target, visible); | 1034 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target, visible); |
| 1035 DCHECK(ret); | |
| 1036 } | |
| 1008 } | 1037 } |
| 1009 | 1038 |
| 1010 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, | 1039 void Window::OnLayerBoundsChanged(const gfx::Rect& old_bounds, |
| 1011 bool contained_mouse) { | 1040 bool contained_mouse) { |
| 1012 if (layout_manager_.get()) | 1041 if (layout_manager_.get()) |
| 1013 layout_manager_->OnWindowResized(); | 1042 layout_manager_->OnWindowResized(); |
| 1014 if (delegate_) | 1043 if (delegate_) |
| 1015 delegate_->OnBoundsChanged(old_bounds, bounds()); | 1044 delegate_->OnBoundsChanged(old_bounds, bounds()); |
| 1016 FOR_EACH_OBSERVER(WindowObserver, | 1045 FOR_EACH_OBSERVER(WindowObserver, |
| 1017 observers_, | 1046 observers_, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1067 bool contains_mouse = false; | 1096 bool contains_mouse = false; |
| 1068 if (IsVisible()) { | 1097 if (IsVisible()) { |
| 1069 RootWindow* root_window = GetRootWindow(); | 1098 RootWindow* root_window = GetRootWindow(); |
| 1070 contains_mouse = root_window && | 1099 contains_mouse = root_window && |
| 1071 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); | 1100 ContainsPointInRoot(root_window->GetLastMouseLocationInRoot()); |
| 1072 } | 1101 } |
| 1073 return contains_mouse; | 1102 return contains_mouse; |
| 1074 } | 1103 } |
| 1075 | 1104 |
| 1076 } // namespace aura | 1105 } // namespace aura |
| OLD | NEW |