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/views/corewm/window_animations.h" | 5 #include "ui/views/corewm/window_animations.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <set> | |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/debug/crash_logging.h" | |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
16 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
18 #include "ui/aura/client/animation_host.h" | 20 #include "ui/aura/client/animation_host.h" |
19 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
21 #include "ui/aura/window_delegate.h" | 23 #include "ui/aura/window_delegate.h" |
22 #include "ui/aura/window_observer.h" | 24 #include "ui/aura/window_observer.h" |
23 #include "ui/aura/window_property.h" | 25 #include "ui/aura/window_property.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 // destroyed when the stack unwinds. To handle this case, we start the hide | 120 // destroyed when the stack unwinds. To handle this case, we start the hide |
119 // animation immediately when the window is hidden, then when the window is | 121 // animation immediately when the window is hidden, then when the window is |
120 // subsequently destroyed this object acquires ownership of the window's layer, | 122 // subsequently destroyed this object acquires ownership of the window's layer, |
121 // so that it can continue animating it until the animation completes. | 123 // so that it can continue animating it until the animation completes. |
122 // Regardless of whether or not the window is destroyed, this object deletes | 124 // Regardless of whether or not the window is destroyed, this object deletes |
123 // itself when the animation completes. | 125 // itself when the animation completes. |
124 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver, | 126 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver, |
125 public aura::WindowObserver { | 127 public aura::WindowObserver { |
126 public: | 128 public: |
127 explicit HidingWindowAnimationObserver(aura::Window* window) | 129 explicit HidingWindowAnimationObserver(aura::Window* window) |
128 : window_(window) { | 130 : topmost_window_(window) { |
129 window_->AddObserver(this); | 131 topmost_window_->AddObserver(this); |
132 observed_.insert(topmost_window_); | |
130 } | 133 } |
131 virtual ~HidingWindowAnimationObserver() { | 134 virtual ~HidingWindowAnimationObserver() { |
132 STLDeleteElements(&layers_); | 135 STLDeleteElements(&layers_); |
136 | |
137 #if defined(OS_CHROMEOS) | |
138 // |topmost_window_| should either be not destroyed or |topmost_window_| | |
139 // and all of its children should be destroyed. | |
140 // TODO(pkotwicz): Remove CHECK once it has been determined whether a child | |
141 // window outliving the end of |topmost_window_|'s animation is the source | |
142 // of the crash in crbug.com/338788 | |
143 if (!topmost_window_ && !observed_.empty()) { | |
144 aura::Window* first_observed = *observed_.begin(); | |
145 std::string name = first_observed->name(); | |
146 base::debug::SetCrashKeyValue("window_destroyed_layer", name); | |
147 CHECK_EQ(0u, observed_.size()); | |
sky
2014/02/06 00:49:38
Wouldn't CHECK(false) be clearer here?
pkotwicz
2014/02/06 02:24:22
Done.
| |
148 } | |
149 #endif // defined(OS_CHROMEOS) | |
150 | |
151 | |
152 for (std::set<aura::Window*>::const_iterator it = observed_.begin(); | |
153 it != observed_.end(); | |
154 ++it) { | |
155 (*it)->RemoveObserver(this); | |
156 } | |
133 } | 157 } |
134 | 158 |
135 private: | 159 private: |
136 // Overridden from ui::ImplicitAnimationObserver: | 160 // Overridden from ui::ImplicitAnimationObserver: |
137 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 161 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
138 // Window may have been destroyed by this point. | 162 // Window may have been destroyed by this point. |
139 if (window_) { | 163 if (topmost_window_) { |
140 aura::client::AnimationHost* animation_host = | 164 aura::client::AnimationHost* animation_host = |
141 aura::client::GetAnimationHost(window_); | 165 aura::client::GetAnimationHost(topmost_window_); |
142 if (animation_host) | 166 if (animation_host) |
143 animation_host->OnWindowHidingAnimationCompleted(); | 167 animation_host->OnWindowHidingAnimationCompleted(); |
144 window_->RemoveObserver(this); | |
145 } | 168 } |
146 delete this; | 169 delete this; |
147 } | 170 } |
148 | 171 |
149 // Overridden from aura::WindowObserver: | 172 // Overridden from aura::WindowObserver: |
150 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 173 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
151 DCHECK_EQ(window, window_); | 174 window->RemoveObserver(this); |
175 observed_.erase(window); | |
176 | |
177 if (window != topmost_window_) | |
178 return; | |
179 | |
180 // We acquire the layers of all of |topmost_window_|'s children with the | |
181 // assumption that they will be destroyed by the time that the animation | |
182 // terminates. Observe |topmost_window_|'s children to verify the | |
183 // assumption. | |
184 ObserveAllChildren(topmost_window_); | |
185 | |
152 DCHECK(layers_.empty()); | 186 DCHECK(layers_.empty()); |
153 AcquireAllLayers(window_); | 187 AcquireAllLayers(topmost_window_); |
154 | 188 |
155 // If the Widget has views with layers, then it is necessary to take | 189 // If the Widget has views with layers, then it is necessary to take |
156 // ownership of those layers too. | 190 // ownership of those layers too. |
157 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); | 191 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
192 topmost_window_); | |
158 const views::Widget* const_widget = widget; | 193 const views::Widget* const_widget = widget; |
159 if (widget && const_widget->GetRootView() && widget->GetContentsView()) | 194 if (widget && const_widget->GetRootView() && widget->GetContentsView()) |
160 AcquireAllViewLayers(widget->GetContentsView()); | 195 AcquireAllViewLayers(widget->GetContentsView()); |
161 window_->RemoveObserver(this); | 196 topmost_window_ = NULL; |
162 window_ = NULL; | 197 } |
198 | |
199 // Starts observing all of the windows in a subtree rooted at |window| | |
200 // excluding |window|. | |
201 void ObserveAllChildren(aura::Window* window) { | |
202 for (aura::Window::Windows::const_iterator it = window->children().begin(); | |
203 it != window->children().end(); | |
204 ++it) { | |
205 aura::Window* child = *it; | |
206 child->AddObserver(this); | |
207 observed_.insert(child); | |
208 ObserveAllChildren(child); | |
209 } | |
163 } | 210 } |
164 | 211 |
165 void AcquireAllLayers(aura::Window* window) { | 212 void AcquireAllLayers(aura::Window* window) { |
166 ui::Layer* layer = window->AcquireLayer(); | 213 ui::Layer* layer = window->AcquireLayer(); |
167 DCHECK(layer); | 214 DCHECK(layer); |
168 layers_.push_back(layer); | 215 layers_.push_back(layer); |
169 for (aura::Window::Windows::const_iterator it = window->children().begin(); | 216 for (aura::Window::Windows::const_iterator it = window->children().begin(); |
170 it != window->children().end(); | 217 it != window->children().end(); |
171 ++it) | 218 ++it) |
172 AcquireAllLayers(*it); | 219 AcquireAllLayers(*it); |
173 } | 220 } |
174 | 221 |
175 void AcquireAllViewLayers(views::View* view) { | 222 void AcquireAllViewLayers(views::View* view) { |
176 for (int i = 0; i < view->child_count(); ++i) | 223 for (int i = 0; i < view->child_count(); ++i) |
177 AcquireAllViewLayers(view->child_at(i)); | 224 AcquireAllViewLayers(view->child_at(i)); |
178 if (view->layer()) { | 225 if (view->layer()) { |
179 ui::Layer* layer = view->RecreateLayer(); | 226 ui::Layer* layer = view->RecreateLayer(); |
180 if (layer) { | 227 if (layer) { |
181 layer->SuppressPaint(); | 228 layer->SuppressPaint(); |
182 layers_.push_back(layer); | 229 layers_.push_back(layer); |
183 } | 230 } |
184 } | 231 } |
185 } | 232 } |
186 | 233 |
187 aura::Window* window_; | 234 aura::Window* topmost_window_; |
235 | |
236 // The set of windows observed by this class. | |
237 std::set<aura::Window*> observed_; | |
238 | |
188 std::vector<ui::Layer*> layers_; | 239 std::vector<ui::Layer*> layers_; |
189 | 240 |
190 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); | 241 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); |
191 }; | 242 }; |
192 | 243 |
193 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { | 244 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { |
194 const Layer* root = layer; | 245 const Layer* root = layer; |
195 while (root->parent()) | 246 while (root->parent()) |
196 root = root->parent(); | 247 root = root->parent(); |
197 layer->GetTargetTransformRelativeTo(root, transform); | 248 layer->GetTargetTransformRelativeTo(root, transform); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 | 620 |
570 bool WindowAnimationsDisabled(aura::Window* window) { | 621 bool WindowAnimationsDisabled(aura::Window* window) { |
571 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && | 622 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && |
572 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 623 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
573 CommandLine::ForCurrentProcess()->HasSwitch( | 624 CommandLine::ForCurrentProcess()->HasSwitch( |
574 switches::kWindowAnimationsDisabled)); | 625 switches::kWindowAnimationsDisabled)); |
575 } | 626 } |
576 | 627 |
577 } // namespace corewm | 628 } // namespace corewm |
578 } // namespace views | 629 } // namespace views |
OLD | NEW |