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

Side by Side Diff: ui/wm/core/window_animations.cc

Issue 180273025: Keep dedicated layers for hiding animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « ui/wm/core/window_animations.h ('k') | ui/wm/core/window_animations_unittest.cc » ('j') | 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 "ui/wm/core/window_animations.h" 5 #include "ui/wm/core/window_animations.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "ui/aura/client/animation_host.h" 18 #include "ui/aura/client/animation_host.h"
19 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
21 #include "ui/aura/window_delegate.h" 21 #include "ui/aura/window_delegate.h"
22 #include "ui/aura/window_observer.h" 22 #include "ui/aura/window_observer.h"
23 #include "ui/aura/window_property.h" 23 #include "ui/aura/window_property.h"
24 #include "ui/compositor/compositor_observer.h" 24 #include "ui/compositor/compositor_observer.h"
25 #include "ui/compositor/layer.h" 25 #include "ui/compositor/layer.h"
26 #include "ui/compositor/layer_animation_observer.h" 26 #include "ui/compositor/layer_animation_observer.h"
27 #include "ui/compositor/layer_animation_sequence.h" 27 #include "ui/compositor/layer_animation_sequence.h"
28 #include "ui/compositor/layer_animator.h" 28 #include "ui/compositor/layer_animator.h"
29 #include "ui/compositor/layer_tree_owner.h"
29 #include "ui/compositor/scoped_layer_animation_settings.h" 30 #include "ui/compositor/scoped_layer_animation_settings.h"
30 #include "ui/gfx/animation/animation.h" 31 #include "ui/gfx/animation/animation.h"
31 #include "ui/gfx/interpolated_transform.h" 32 #include "ui/gfx/interpolated_transform.h"
32 #include "ui/gfx/rect_conversions.h" 33 #include "ui/gfx/rect_conversions.h"
33 #include "ui/gfx/screen.h" 34 #include "ui/gfx/screen.h"
34 #include "ui/gfx/vector2d.h" 35 #include "ui/gfx/vector2d.h"
35 #include "ui/gfx/vector3d_f.h" 36 #include "ui/gfx/vector3d_f.h"
36 #include "ui/wm/core/window_util.h" 37 #include "ui/wm/core/window_util.h"
37 #include "ui/wm/core/wm_core_switches.h" 38 #include "ui/wm/core/wm_core_switches.h"
38 39
39 DECLARE_WINDOW_PROPERTY_TYPE(int) 40 DECLARE_WINDOW_PROPERTY_TYPE(int)
40 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) 41 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType)
41 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) 42 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition)
42 DECLARE_WINDOW_PROPERTY_TYPE(float) 43 DECLARE_WINDOW_PROPERTY_TYPE(float)
43 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(WM_CORE_EXPORT, bool) 44 DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(WM_CORE_EXPORT, bool)
44 45
45 using aura::Window;
46 using base::TimeDelta;
47 using ui::Layer;
48
49 namespace views { 46 namespace views {
50 namespace corewm { 47 namespace corewm {
51 namespace { 48 namespace {
52 const float kWindowAnimation_Vertical_TranslateY = 15.f; 49 const float kWindowAnimation_Vertical_TranslateY = 15.f;
53 } // namespace 50 } // namespace
54 51
55 DEFINE_WINDOW_PROPERTY_KEY(int, 52 DEFINE_WINDOW_PROPERTY_KEY(int,
56 kWindowVisibilityAnimationTypeKey, 53 kWindowVisibilityAnimationTypeKey,
57 WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); 54 WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT);
58 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowVisibilityAnimationDurationKey, 0); 55 DEFINE_WINDOW_PROPERTY_KEY(int, kWindowVisibilityAnimationDurationKey, 0);
(...skipping 17 matching lines...) Expand all
76 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; 73 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90;
77 const float kWindowAnimation_Rotate_TranslateY = -20.f; 74 const float kWindowAnimation_Rotate_TranslateY = -20.f;
78 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; 75 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f;
79 const float kWindowAnimation_Rotate_DegreesX = 5.f; 76 const float kWindowAnimation_Rotate_DegreesX = 5.f;
80 const float kWindowAnimation_Rotate_ScaleFactor = .99f; 77 const float kWindowAnimation_Rotate_ScaleFactor = .99f;
81 78
82 const float kWindowAnimation_Bounce_Scale = 1.02f; 79 const float kWindowAnimation_Bounce_Scale = 1.02f;
83 const int kWindowAnimation_Bounce_DurationMS = 180; 80 const int kWindowAnimation_Bounce_DurationMS = 180;
84 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; 81 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40;
85 82
83 class HidingWindowAnimationObserver;
84 DEFINE_WINDOW_PROPERTY_KEY(HidingWindowAnimationObserver*,
85 kHidingWindowAnimationObserverKey,
86 NULL);
87
86 base::TimeDelta GetWindowVisibilityAnimationDuration( 88 base::TimeDelta GetWindowVisibilityAnimationDuration(
87 const aura::Window& window) { 89 const aura::Window& window) {
88 int duration = 90 int duration =
89 window.GetProperty(kWindowVisibilityAnimationDurationKey); 91 window.GetProperty(kWindowVisibilityAnimationDurationKey);
90 if (duration == 0 && window.type() == ui::wm::WINDOW_TYPE_MENU) { 92 if (duration == 0 && window.type() == ui::wm::WINDOW_TYPE_MENU) {
91 return base::TimeDelta::FromMilliseconds( 93 return base::TimeDelta::FromMilliseconds(
92 kDefaultAnimationDurationForMenuMS); 94 kDefaultAnimationDurationForMenuMS);
93 } 95 }
94 return TimeDelta::FromInternalValue(duration); 96 return base::TimeDelta::FromInternalValue(duration);
95 } 97 }
96 98
97 // Gets/sets the WindowVisibilityAnimationType associated with a window. 99 // Gets/sets the WindowVisibilityAnimationType associated with a window.
98 // TODO(beng): redundant/fold into method on public api? 100 // TODO(beng): redundant/fold into method on public api?
99 int GetWindowVisibilityAnimationType(aura::Window* window) { 101 int GetWindowVisibilityAnimationType(aura::Window* window) {
100 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); 102 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey);
101 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) { 103 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) {
102 return (window->type() == ui::wm::WINDOW_TYPE_MENU || 104 return (window->type() == ui::wm::WINDOW_TYPE_MENU ||
103 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) 105 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP)
104 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE 106 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE
105 : WINDOW_VISIBILITY_ANIMATION_TYPE_DROP; 107 : WINDOW_VISIBILITY_ANIMATION_TYPE_DROP;
106 } 108 }
107 return type; 109 return type;
108 } 110 }
109 111
110 // Observes a hide animation. 112 // Observes a hide animation.
111 // A window can be hidden for a variety of reasons. Sometimes, Hide() will be 113 // A window can be hidden for a variety of reasons. Sometimes, Hide() will be
112 // called and life is simple. Sometimes, the window is actually bound to a 114 // called and life is simple. Sometimes, the window is actually bound to a
113 // views::Widget and that Widget is closed, and life is a little more 115 // views::Widget and that Widget is closed, and life is a little more
114 // complicated. When a Widget is closed the aura::Window* is actually not 116 // complicated. When a Widget is closed the aura::Window* is actually not
115 // destroyed immediately - it is actually just immediately hidden and then 117 // destroyed immediately - it is actually just immediately hidden and then
116 // destroyed when the stack unwinds. To handle this case, we start the hide 118 // destroyed when the stack unwinds. To handle this case, we start the hide
117 // animation immediately when the window is hidden, then when the window is 119 // animation immediately when the window is hidden, then when the window is
118 // subsequently destroyed this object acquires ownership of the window's layer, 120 // subsequently destroyed this object acquires ownership of the window's layer,
119 // so that it can continue animating it until the animation completes. 121 // so that it can continue animating it until the animation completes.
120 // Regardless of whether or not the window is destroyed, this object deletes 122 // Regardless of whether or not the window is destroyed, this object deletes
121 // itself when the animation completes. 123 // itself when the animation completes.
124 // In addition, a window being hidden can be hidden by a new focused/active
125 // window, in which case, a user may not see the hiding animation. This class
126 // also provides a method |DetachAndRecreateLayers| so that the animating
127 // layer can stay above the new active window while keeping the
128 // z-order of window and its layer in sync.
122 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver, 129 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
123 public aura::WindowObserver { 130 public aura::WindowObserver {
124 public: 131 public:
125 explicit HidingWindowAnimationObserver(aura::Window* window) 132 HidingWindowAnimationObserver(aura::Window* window,
133 ui::ScopedLayerAnimationSettings* settings)
126 : window_(window) { 134 : window_(window) {
127 window_->AddObserver(this); 135 window->SetProperty(kHidingWindowAnimationObserverKey, this);
128 } 136 window->AddObserver(this);
129 virtual ~HidingWindowAnimationObserver() { 137 if (settings)
130 STLDeleteElements(&layers_); 138 settings->AddObserver(this);
131 } 139 }
132 140
133 private: 141 virtual ~HidingWindowAnimationObserver() {
134 // Overridden from ui::ImplicitAnimationObserver: 142 }
143
144 // ui::ImplicitAnimationObserver:
135 virtual void OnImplicitAnimationsCompleted() OVERRIDE { 145 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
136 // Window may have been destroyed by this point. 146 // Window may have been destroyed by this point.
137 if (window_) { 147 if (window_) {
138 aura::client::AnimationHost* animation_host = 148 aura::client::AnimationHost* animation_host =
139 aura::client::GetAnimationHost(window_); 149 aura::client::GetAnimationHost(window_);
140 if (animation_host) 150 if (animation_host)
141 animation_host->OnWindowHidingAnimationCompleted(); 151 animation_host->OnWindowHidingAnimationCompleted();
142 window_->RemoveObserver(this); 152 window_->RemoveObserver(this);
153 window_->ClearProperty(kHidingWindowAnimationObserverKey);
143 } 154 }
144 delete this; 155 delete this;
145 } 156 }
146 157
147 // Overridden from aura::WindowObserver: 158 // aura::WindowObserver:
148 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { 159 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
149 DCHECK_EQ(window, window_); 160 DCHECK_EQ(window, window_);
150 DCHECK(layers_.empty()); 161 DCHECK(layers_.empty());
151 AcquireAllLayers(window_->layer()); 162 // No need to acquire layers if the animating layers have already
163 // been detached.
164 if (!layer_owner_)
165 AcquireAllLayers(window_->layer());
152 window_->RemoveObserver(this); 166 window_->RemoveObserver(this);
153 window_ = NULL; 167 window_ = NULL;
154 } 168 }
155 169
156 void AcquireAllLayers(ui::Layer* layer) { 170 void AcquireAllLayers(ui::Layer* layer) {
157 if (layer->owner()) { 171 if (layer->owner()) {
158 ui::Layer* released = layer->owner()->AcquireLayer(); 172 ui::Layer* released = layer->owner()->AcquireLayer();
159 DCHECK_EQ(layer, released); 173 DCHECK_EQ(layer, released);
160 layers_.push_back(released); 174 layers_.push_back(released);
161 } 175 }
162 std::vector<Layer*>::const_iterator it = layer->children().begin(); 176 std::vector<ui::Layer*>::const_iterator it = layer->children().begin();
163 for (; it != layer->children().end(); ++it) 177 for (; it != layer->children().end(); ++it)
164 AcquireAllLayers(*it); 178 AcquireAllLayers(*it);
165 } 179 }
166 180
181 void DetachAndRecreateLayers() {
182 layer_owner_ = RecreateLayers(window_);
183 // If the window has transient children, move above the top most
184 // transient child so that activation change does not put the
185 // window above the animating layer.
186 if(window_->parent()) {
187 const aura::Window::Windows& transient_children =
188 GetTransientChildren(window_);
189 aura::Window::Windows::const_iterator iter =
190 std::find(window_->parent()->children().begin(),
191 window_->parent()->children().end(),
192 window_);
193 DCHECK(iter != window_->parent()->children().end());
194 aura::Window* topmost_transient_child = NULL;
195 for (++iter; iter != window_->parent()->children().end(); ++iter) {
196 if (std::find(transient_children.begin(),
197 transient_children.end(),
198 *iter) !=
199 transient_children.end()) {
200 topmost_transient_child = *iter;
201 }
202 }
203 if (topmost_transient_child) {
204 window_->parent()->layer()->StackAbove(
205 layer_owner_->root(), topmost_transient_child->layer());
206 }
207 }
208
209 // TODO(sky): The recreated layer should have the target visibility of
210 // the original layer.
211 // Make the new layer invisible immediately.
212 window_->layer()->SetVisible(false);
213 window_->layer()->SetOpacity(0);
214 }
215
216 private:
167 aura::Window* window_; 217 aura::Window* window_;
168 std::vector<ui::Layer*> layers_; 218
219 // Stores acquired layers upon deletion.
220 ScopedVector<ui::Layer> layers_;
221
222 // The owner of detached layers.
223 scoped_ptr<ui::LayerTreeOwner> layer_owner_;
169 224
170 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); 225 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
171 }; 226 };
172 227
173 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { 228 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) {
174 const Layer* root = layer; 229 const ui::Layer* root = layer;
175 while (root->parent()) 230 while (root->parent())
176 root = root->parent(); 231 root = root->parent();
177 layer->GetTargetTransformRelativeTo(root, transform); 232 layer->GetTargetTransformRelativeTo(root, transform);
178 } 233 }
179 234
180 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer, 235 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer,
181 const gfx::Transform& transform) { 236 const gfx::Transform& transform) {
182 gfx::Transform in_world = transform; 237 gfx::Transform in_world = transform;
183 GetTransformRelativeToRoot(layer, &in_world); 238 GetTransformRelativeToRoot(layer, &in_world);
184 239
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 302 }
248 303
249 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 304 // Hides a window using an animation, animating its opacity from 1.f to 0.f,
250 // its visibility to false, and its transform to |end_transform|. 305 // its visibility to false, and its transform to |end_transform|.
251 void AnimateHideWindowCommon(aura::Window* window, 306 void AnimateHideWindowCommon(aura::Window* window,
252 const gfx::Transform& end_transform) { 307 const gfx::Transform& end_transform) {
253 AugmentWindowSize(window, end_transform); 308 AugmentWindowSize(window, end_transform);
254 window->layer()->set_delegate(NULL); 309 window->layer()->set_delegate(NULL);
255 310
256 // Property sets within this scope will be implicitly animated. 311 // Property sets within this scope will be implicitly animated.
257 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 312 ScopedHidingAnimationSettings hiding_settings(window);
258 settings.AddObserver(new HidingWindowAnimationObserver(window)); 313 hiding_settings.set_ensure_visible_after_focus_lost(true);
259 314
260 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window); 315 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window);
261 if (duration.ToInternalValue() > 0) 316 if (duration.ToInternalValue() > 0)
262 settings.SetTransitionDuration(duration); 317 hiding_settings.layer_animation_settings()->SetTransitionDuration(duration);
263 318
264 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 319 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
265 window->layer()->SetTransform(end_transform); 320 window->layer()->SetTransform(end_transform);
266 window->layer()->SetVisible(false); 321 window->layer()->SetVisible(false);
267 } 322 }
268 323
269 static gfx::Transform GetScaleForWindow(aura::Window* window) { 324 static gfx::Transform GetScaleForWindow(aura::Window* window) {
270 gfx::Rect bounds = window->bounds(); 325 gfx::Rect bounds = window->bounds();
271 gfx::Transform scale = gfx::GetScaleTransform( 326 gfx::Transform scale = gfx::GetScaleTransform(
272 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), 327 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 406 }
352 407
353 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 408 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
354 window->layer()->set_delegate(window); 409 window->layer()->set_delegate(window);
355 if (show) 410 if (show)
356 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 411 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
357 412
358 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 413 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
359 kWindowAnimation_Rotate_DurationMS); 414 kWindowAnimation_Rotate_DurationMS);
360 415
416 HidingWindowAnimationObserver* observer = NULL;
417
361 if (!show) { 418 if (!show) {
362 new HidingWindowAnimationObserver(window); 419 // TODO(oshima): Fix observer leak.
420 observer = new HidingWindowAnimationObserver(window, NULL);
363 window->layer()->GetAnimator()->SchedulePauseForProperties( 421 window->layer()->GetAnimator()->SchedulePauseForProperties(
364 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, 422 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100,
365 ui::LayerAnimationElement::OPACITY); 423 ui::LayerAnimationElement::OPACITY);
366 } 424 }
367 scoped_ptr<ui::LayerAnimationElement> opacity( 425 scoped_ptr<ui::LayerAnimationElement> opacity(
368 ui::LayerAnimationElement::CreateOpacityElement( 426 ui::LayerAnimationElement::CreateOpacityElement(
369 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, 427 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
370 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); 428 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
371 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); 429 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
372 window->layer()->GetAnimator()->ScheduleAnimation( 430 window->layer()->GetAnimator()->ScheduleAnimation(
(...skipping 27 matching lines...) Expand all
400 translation->SetChild(scale_about_pivot.release()); 458 translation->SetChild(scale_about_pivot.release());
401 rotation->SetChild(translation.release()); 459 rotation->SetChild(translation.release());
402 rotation->SetReversed(show); 460 rotation->SetReversed(show);
403 461
404 scoped_ptr<ui::LayerAnimationElement> transition( 462 scoped_ptr<ui::LayerAnimationElement> transition(
405 ui::LayerAnimationElement::CreateInterpolatedTransformElement( 463 ui::LayerAnimationElement::CreateInterpolatedTransformElement(
406 rotation.release(), duration)); 464 rotation.release(), duration));
407 465
408 window->layer()->GetAnimator()->ScheduleAnimation( 466 window->layer()->GetAnimator()->ScheduleAnimation(
409 new ui::LayerAnimationSequence(transition.release())); 467 new ui::LayerAnimationSequence(transition.release()));
468 if (observer)
469 observer->DetachAndRecreateLayers();
410 } 470 }
411 471
412 void AnimateShowWindow_Rotate(aura::Window* window) { 472 void AnimateShowWindow_Rotate(aura::Window* window) {
413 AddLayerAnimationsForRotate(window, true); 473 AddLayerAnimationsForRotate(window, true);
414 } 474 }
415 475
416 void AnimateHideWindow_Rotate(aura::Window* window) { 476 void AnimateHideWindow_Rotate(aura::Window* window) {
417 AddLayerAnimationsForRotate(window, false); 477 AddLayerAnimationsForRotate(window, false);
418 } 478 }
419 479
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 case WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE: 532 case WINDOW_VISIBILITY_ANIMATION_TYPE_ROTATE:
473 AnimateHideWindow_Rotate(window); 533 AnimateHideWindow_Rotate(window);
474 return true; 534 return true;
475 default: 535 default:
476 return false; 536 return false;
477 } 537 }
478 } 538 }
479 539
480 } // namespace 540 } // namespace
481 541
542 ScopedHidingAnimationSettings::ScopedHidingAnimationSettings(
543 aura::Window* window)
544 : window_(window),
545 ensure_visibility_after_focus_lost_(false),
546 layer_animation_settings_(window->layer()->GetAnimator()) {
547 new HidingWindowAnimationObserver(window, &layer_animation_settings_);
548 }
549
550 ScopedHidingAnimationSettings::~ScopedHidingAnimationSettings() {
551 HidingWindowAnimationObserver* observer =
sky 2014/03/13 22:34:05 Why isn't this a member?
552 window_->GetProperty(kHidingWindowAnimationObserverKey);
553 DCHECK(observer);
554 if (ensure_visibility_after_focus_lost_)
555 observer->DetachAndRecreateLayers();
556 }
557
482 //////////////////////////////////////////////////////////////////////////////// 558 ////////////////////////////////////////////////////////////////////////////////
483 // External interface 559 // External interface
484 560
485 void SetWindowVisibilityAnimationType(aura::Window* window, int type) { 561 void SetWindowVisibilityAnimationType(aura::Window* window, int type) {
486 window->SetProperty(kWindowVisibilityAnimationTypeKey, type); 562 window->SetProperty(kWindowVisibilityAnimationTypeKey, type);
487 } 563 }
488 564
489 int GetWindowVisibilityAnimationType(aura::Window* window) { 565 int GetWindowVisibilityAnimationType(aura::Window* window) {
490 return window->GetProperty(kWindowVisibilityAnimationTypeKey); 566 return window->GetProperty(kWindowVisibilityAnimationTypeKey);
491 } 567 }
492 568
493 void SetWindowVisibilityAnimationTransition( 569 void SetWindowVisibilityAnimationTransition(
494 aura::Window* window, 570 aura::Window* window,
495 WindowVisibilityAnimationTransition transition) { 571 WindowVisibilityAnimationTransition transition) {
496 window->SetProperty(kWindowVisibilityAnimationTransitionKey, transition); 572 window->SetProperty(kWindowVisibilityAnimationTransitionKey, transition);
497 } 573 }
498 574
499 bool HasWindowVisibilityAnimationTransition( 575 bool HasWindowVisibilityAnimationTransition(
500 aura::Window* window, 576 aura::Window* window,
501 WindowVisibilityAnimationTransition transition) { 577 WindowVisibilityAnimationTransition transition) {
502 WindowVisibilityAnimationTransition prop = window->GetProperty( 578 WindowVisibilityAnimationTransition prop = window->GetProperty(
503 kWindowVisibilityAnimationTransitionKey); 579 kWindowVisibilityAnimationTransitionKey);
504 return (prop & transition) != 0; 580 return (prop & transition) != 0;
505 } 581 }
506 582
507 void SetWindowVisibilityAnimationDuration(aura::Window* window, 583 void SetWindowVisibilityAnimationDuration(aura::Window* window,
508 const TimeDelta& duration) { 584 const base::TimeDelta& duration) {
509 window->SetProperty(kWindowVisibilityAnimationDurationKey, 585 window->SetProperty(kWindowVisibilityAnimationDurationKey,
510 static_cast<int>(duration.ToInternalValue())); 586 static_cast<int>(duration.ToInternalValue()));
511 } 587 }
512 588
513 base::TimeDelta GetWindowVisibilityAnimationDuration( 589 base::TimeDelta GetWindowVisibilityAnimationDuration(
514 const aura::Window& window) { 590 const aura::Window& window) {
515 return base::TimeDelta::FromInternalValue( 591 return base::TimeDelta::FromInternalValue(
516 window.GetProperty(kWindowVisibilityAnimationDurationKey)); 592 window.GetProperty(kWindowVisibilityAnimationDurationKey));
517 } 593 }
518 594
519 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, 595 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window,
520 float position) { 596 float position) {
521 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); 597 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position);
522 } 598 }
523 599
524 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
525 aura::Window* window) {
526 return new HidingWindowAnimationObserver(window);
527 }
528
529 bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) { 600 bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) {
530 if (WindowAnimationsDisabled(window)) 601 if (WindowAnimationsDisabled(window))
531 return false; 602 return false;
532 if (visible) 603 if (visible)
533 return AnimateShowWindow(window); 604 return AnimateShowWindow(window);
534 // Don't start hiding the window again if it's already being hidden. 605 // Don't start hiding the window again if it's already being hidden.
535 return window->layer()->GetTargetOpacity() != 0.0f && 606 return window->layer()->GetTargetOpacity() != 0.0f &&
536 AnimateHideWindow(window); 607 AnimateHideWindow(window);
537 } 608 }
538 609
(...skipping 10 matching lines...) Expand all
549 620
550 bool WindowAnimationsDisabled(aura::Window* window) { 621 bool WindowAnimationsDisabled(aura::Window* window) {
551 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && 622 return (!gfx::Animation::ShouldRenderRichAnimation() || (window &&
552 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 623 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
553 CommandLine::ForCurrentProcess()->HasSwitch( 624 CommandLine::ForCurrentProcess()->HasSwitch(
554 switches::kWindowAnimationsDisabled)); 625 switches::kWindowAnimationsDisabled));
555 } 626 }
556 627
557 } // namespace corewm 628 } // namespace corewm
558 } // namespace views 629 } // namespace views
OLDNEW
« no previous file with comments | « ui/wm/core/window_animations.h ('k') | ui/wm/core/window_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698