Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(890)

Side by Side Diff: ash/wm/window_animations.cc

Issue 9233044: Acquire all layers when hiding window gets destroyed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: dcheck Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/window_animations.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/wm/window_animations.h" 5 #include "ash/wm/window_animations.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h"
11 #include "base/time.h"
10 #include "ui/aura/client/aura_constants.h" 12 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
12 #include "ui/aura/window_observer.h" 14 #include "ui/aura/window_observer.h"
13 #include "ui/gfx/compositor/layer_animation_observer.h" 15 #include "ui/gfx/compositor/layer_animation_observer.h"
14 #include "ui/gfx/compositor/scoped_layer_animation_settings.h" 16 #include "ui/gfx/compositor/scoped_layer_animation_settings.h"
15 17
16 namespace ash { 18 namespace ash {
17 namespace internal { 19 namespace internal {
18 const char kWindowVisibilityAnimationTypeKey[] = 20 const char kWindowVisibilityAnimationTypeKey[] =
19 "WindowVisibilityAnimationType"; 21 "WindowVisibilityAnimationType";
22
23 const char kWindowVisibilityAnimationDurationKey[] =
24 "WindowVisibilityAnimationDuration";
25
26 const char kWindowVisibilityAnimationTransitionKey[] =
27 "WindowVisibilityAnimationTransition";
20 } // namespace internal 28 } // namespace internal
21 29
22 void SetWindowVisibilityAnimationType(aura::Window* window, 30 void SetWindowVisibilityAnimationType(aura::Window* window,
23 WindowVisibilityAnimationType type) { 31 WindowVisibilityAnimationType type) {
24 window->SetIntProperty(internal::kWindowVisibilityAnimationTypeKey, type); 32 window->SetIntProperty(internal::kWindowVisibilityAnimationTypeKey, type);
25 } 33 }
26 34
35 void SetWindowVisibilityAnimationTransition(
36 aura::Window* window,
37 WindowVisibilityAnimationTransition transition) {
38 window->SetIntProperty(internal::kWindowVisibilityAnimationTransitionKey,
39 transition);
40 }
41
42 void SetWindowVisibilityAnimationDuration(aura::Window* window,
43 const base::TimeDelta& duration) {
44 window->SetIntProperty(internal::kWindowVisibilityAnimationDurationKey,
45 static_cast<int>(duration.ToInternalValue()));
46 }
47
48 bool HasWindowVisibilityAnimationTransition(
49 aura::Window* window,
50 WindowVisibilityAnimationTransition transition) {
51 int prop = window->GetIntProperty(
52 internal::kWindowVisibilityAnimationTransitionKey);
53 return !prop || (prop & transition) != 0;
54 }
55
27 namespace internal { 56 namespace internal {
28 namespace { 57 namespace {
29 58
30 const float kWindowAnimation_HideOpacity = 0.f; 59 const float kWindowAnimation_HideOpacity = 0.f;
31 const float kWindowAnimation_ShowOpacity = 1.f; 60 const float kWindowAnimation_ShowOpacity = 1.f;
32 const float kWindowAnimation_TranslateFactor = -0.025f; 61 const float kWindowAnimation_TranslateFactor = -0.025f;
33 const float kWindowAnimation_ScaleFactor = 1.05f; 62 const float kWindowAnimation_ScaleFactor = 1.05f;
34 63
35 const float kWindowAnimation_Vertical_TranslateY = 15.f; 64 const float kWindowAnimation_Vertical_TranslateY = 15.f;
36 65
(...skipping 23 matching lines...) Expand all
60 // so that it can continue animating it until the animation completes. 89 // so that it can continue animating it until the animation completes.
61 // Regardless of whether or not the window is destroyed, this object deletes 90 // Regardless of whether or not the window is destroyed, this object deletes
62 // itself when the animation completes. 91 // itself when the animation completes.
63 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver, 92 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
64 public aura::WindowObserver { 93 public aura::WindowObserver {
65 public: 94 public:
66 explicit HidingWindowAnimationObserver(aura::Window* window) 95 explicit HidingWindowAnimationObserver(aura::Window* window)
67 : window_(window) { 96 : window_(window) {
68 window_->AddObserver(this); 97 window_->AddObserver(this);
69 } 98 }
70 virtual ~HidingWindowAnimationObserver() {} 99 virtual ~HidingWindowAnimationObserver() {
100 STLDeleteElements(&layers_);
101 }
71 102
72 private: 103 private:
73 // Overridden from ui::ImplicitAnimationObserver: 104 // Overridden from ui::ImplicitAnimationObserver:
74 virtual void OnImplicitAnimationsCompleted() OVERRIDE { 105 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
75 // Restore the correct visibility value (overridden for the duration of the 106 // Restore the correct visibility value (overridden for the duration of the
76 // animation in AnimateHideWindow()). 107 // animation in AnimateHideWindow()).
77 layer()->SetVisible(false); 108 layer()->SetVisible(false);
78 // Window may have been destroyed by this point. 109 // Window may have been destroyed by this point.
79 if (window_) 110 if (window_)
80 window_->RemoveObserver(this); 111 window_->RemoveObserver(this);
81 MessageLoop::current()->DeleteSoon(FROM_HERE, this); 112 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
82 } 113 }
83 114
84 // Overridden from aura::WindowObserver: 115 // Overridden from aura::WindowObserver:
85 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 116 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
86 DCHECK_EQ(window, window_); 117 DCHECK_EQ(window, window_);
87 layer_.reset(window_->AcquireLayer()); 118 DCHECK(layers_.empty());
119 AcquireAllLayers(window_);
88 window_->RemoveObserver(this); 120 window_->RemoveObserver(this);
89 window_ = NULL; 121 window_ = NULL;
90 } 122 }
91 123
92 ui::Layer* layer() { return window_ ? window_->layer() : layer_.get(); } 124 void AcquireAllLayers(aura::Window* window) {
125 ui::Layer* layer = window->AcquireLayer();
126 DCHECK(layer);
127 layers_.push_back(layer);
128 for (aura::Window::Windows::const_iterator it = window->children().begin();
129 it != window->children().end();
130 ++it)
131 AcquireAllLayers(*it);
132 }
133
134 ui::Layer* layer() { return window_ ? window_->layer() : layers_[0]; }
93 135
94 aura::Window* window_; 136 aura::Window* window_;
95 scoped_ptr<ui::Layer> layer_; 137 std::vector<ui::Layer*> layers_;
96 138
97 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); 139 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
98 }; 140 };
99 141
100 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and 142 // Shows a window using an animation, animating its opacity from 0.f to 1.f, and
101 // its transform from |start_transform| to |end_transform|. 143 // its transform from |start_transform| to |end_transform|.
102 void AnimateShowWindowCommon(aura::Window* window, 144 void AnimateShowWindowCommon(aura::Window* window,
103 const ui::Transform& start_transform, 145 const ui::Transform& start_transform,
104 const ui::Transform& end_transform) { 146 const ui::Transform& end_transform) {
105 window->layer()->set_delegate(window); 147 window->layer()->set_delegate(window);
106 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 148 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
107 window->layer()->SetTransform(start_transform); 149 window->layer()->SetTransform(start_transform);
108 150
109 { 151 {
110 // Property sets within this scope will be implicitly animated. 152 // Property sets within this scope will be implicitly animated.
111 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 153 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
154 int duration =
155 window->GetIntProperty(internal::kWindowVisibilityAnimationDurationKey);
156 if (duration > 0) {
157 settings.SetTransitionDuration(
158 base::TimeDelta::FromInternalValue(duration));
159 }
160
112 window->layer()->SetTransform(end_transform); 161 window->layer()->SetTransform(end_transform);
113 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 162 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
114 } 163 }
115 } 164 }
116 165
117 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and 166 // Hides a window using an animation, animating its opacity from 1.f to 0.f, and
118 // its transform to |end_transform|. 167 // its transform to |end_transform|.
119 void AnimateHideWindowCommon(aura::Window* window, 168 void AnimateHideWindowCommon(aura::Window* window,
120 const ui::Transform& end_transform) { 169 const ui::Transform& end_transform) {
121 window->layer()->set_delegate(NULL); 170 window->layer()->set_delegate(NULL);
122 171
123 // Property sets within this scope will be implicitly animated. 172 // Property sets within this scope will be implicitly animated.
124 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 173 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
125 settings.AddImplicitObserver(new HidingWindowAnimationObserver(window)); 174 settings.AddImplicitObserver(new HidingWindowAnimationObserver(window));
175 int duration =
176 window->GetIntProperty(internal::kWindowVisibilityAnimationDurationKey);
177 if (duration > 0) {
178 settings.SetTransitionDuration(
179 base::TimeDelta::FromInternalValue(duration));
180 }
126 181
127 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 182 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
128 window->layer()->SetTransform(end_transform); 183 window->layer()->SetTransform(end_transform);
129 } 184 }
130 185
131 // Show/Hide windows using a shrink animation. 186 // Show/Hide windows using a shrink animation.
132 void AnimateShowWindow_Drop(aura::Window* window) { 187 void AnimateShowWindow_Drop(aura::Window* window) {
133 ui::Transform transform; 188 ui::Transform transform;
134 transform.ConcatScale(kWindowAnimation_ScaleFactor, 189 transform.ConcatScale(kWindowAnimation_ScaleFactor,
135 kWindowAnimation_ScaleFactor); 190 kWindowAnimation_ScaleFactor);
(...skipping 28 matching lines...) Expand all
164 219
165 // Show/Hide windows using a fade. 220 // Show/Hide windows using a fade.
166 void AnimateShowWindow_Fade(aura::Window* window) { 221 void AnimateShowWindow_Fade(aura::Window* window) {
167 AnimateShowWindowCommon(window, ui::Transform(), ui::Transform()); 222 AnimateShowWindowCommon(window, ui::Transform(), ui::Transform());
168 } 223 }
169 224
170 void AnimateHideWindow_Fade(aura::Window* window) { 225 void AnimateHideWindow_Fade(aura::Window* window) {
171 AnimateHideWindowCommon(window, ui::Transform()); 226 AnimateHideWindowCommon(window, ui::Transform());
172 } 227 }
173 228
174 void AnimateShowWindow(aura::Window* window) { 229 bool AnimateShowWindow(aura::Window* window) {
230 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_SHOW))
231 return false;
232
175 switch (GetWindowVisibilityAnimationType(window)) { 233 switch (GetWindowVisibilityAnimationType(window)) {
176 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: 234 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP:
177 AnimateShowWindow_Drop(window); 235 AnimateShowWindow_Drop(window);
178 break; 236 return true;
179 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: 237 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL:
180 AnimateShowWindow_Vertical(window); 238 AnimateShowWindow_Vertical(window);
181 break; 239 return true;
182 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: 240 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE:
183 AnimateShowWindow_Fade(window); 241 AnimateShowWindow_Fade(window);
184 break; 242 return true;
185 default: 243 default:
186 NOTREACHED(); 244 NOTREACHED();
187 break; 245 return false;
188 } 246 }
189 } 247 }
190 248
191 void AnimateHideWindow(aura::Window* window) { 249 bool AnimateHideWindow(aura::Window* window) {
250 if (!HasWindowVisibilityAnimationTransition(window, ANIMATE_HIDE))
251 return false;
252
192 switch (GetWindowVisibilityAnimationType(window)) { 253 switch (GetWindowVisibilityAnimationType(window)) {
193 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP: 254 case WINDOW_VISIBILITY_ANIMATION_TYPE_DROP:
194 AnimateHideWindow_Drop(window); 255 AnimateHideWindow_Drop(window);
195 break; 256 return true;
196 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL: 257 case WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL:
197 AnimateHideWindow_Vertical(window); 258 AnimateHideWindow_Vertical(window);
198 break; 259 return true;
199 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE: 260 case WINDOW_VISIBILITY_ANIMATION_TYPE_FADE:
200 AnimateHideWindow_Fade(window); 261 AnimateHideWindow_Fade(window);
201 break; 262 return true;
202 default: 263 default:
203 NOTREACHED(); 264 NOTREACHED();
204 break; 265 return false;
205 } 266 }
206 } 267 }
207 268
208 } // namespace 269 } // namespace
209 270
210 //////////////////////////////////////////////////////////////////////////////// 271 ////////////////////////////////////////////////////////////////////////////////
211 // WindowAnimation, public: 272 // WindowAnimation, public:
212 273
213 void AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) { 274 bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) {
214 if (window->GetIntProperty(aura::client::kAnimationsDisabledKey) == 1) 275 if (window->GetIntProperty(aura::client::kAnimationsDisabledKey) == 1)
215 return; 276 return false;
216 if (visible) { 277 if (visible) {
217 AnimateShowWindow(window); 278 return AnimateShowWindow(window);
218 } else { 279 } else {
219 // Don't start hiding the window again if it's already being hidden. 280 // Don't start hiding the window again if it's already being hidden.
220 if (window->layer()->GetTargetOpacity() != 0.0f) 281 return window->layer()->GetTargetOpacity() != 0.0f &&
221 AnimateHideWindow(window); 282 AnimateHideWindow(window);
222 } 283 }
223 } 284 }
224 285
225 } // namespace internal 286 } // namespace internal
226 } // namespace ash 287 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_animations.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698