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

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);
59 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition, 56 DEFINE_WINDOW_PROPERTY_KEY(WindowVisibilityAnimationTransition,
60 kWindowVisibilityAnimationTransitionKey, 57 kWindowVisibilityAnimationTransitionKey,
61 ANIMATE_BOTH); 58 ANIMATE_BOTH);
62 DEFINE_WINDOW_PROPERTY_KEY(float, 59 DEFINE_WINDOW_PROPERTY_KEY(float,
63 kWindowVisibilityAnimationVerticalPositionKey, 60 kWindowVisibilityAnimationVerticalPositionKey,
64 kWindowAnimation_Vertical_TranslateY); 61 kWindowAnimation_Vertical_TranslateY);
65 62
63 // An AnimationObserer which has two roles:
64 // 1) Notifies AnimatinoHost the end of hiding animation.
sky 2014/03/14 14:32:13 'AnimatinoHost the end of'->'AnimationHost at the
oshima 2014/03/14 16:35:25 Done.
65 // 2) Detaches the window's layers for hiding animation and delete
sky 2014/03/14 14:32:13 delete->deletes
oshima 2014/03/14 16:35:25 Done.
66 // them upon completion of the animation. This is necessary to a)
67 // ensure that the animation continues in the even of the window being
sky 2014/03/14 14:32:13 even->event
oshima 2014/03/14 16:35:25 Done.
68 // deleted, and b) to ensure that the animation is visible even if the
69 // window gets restacked below other wndows when focus or activation
sky 2014/03/14 14:32:13 wndows->windows
oshima 2014/03/14 16:35:25 Done.
70 // changes.
71 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
72 public aura::WindowObserver {
73 public:
74 HidingWindowAnimationObserver(aura::Window* window,
75 ui::ScopedLayerAnimationSettings* settings);
76 virtual ~HidingWindowAnimationObserver() {}
77
78 // ui::ImplicitAnimationObserver:
79 virtual void OnImplicitAnimationsCompleted() OVERRIDE;
80
81 // aura::WindowObserver:
82 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
83
84 // Detach the current layers and create new layers for |window_|.
85 // Stack the origina layers above |window_| and its transient children.
sky 2014/03/14 14:32:13 origina->original
sky 2014/03/14 14:32:13 Since you describe restacking here I think the com
oshima 2014/03/14 16:35:25 Done.
oshima 2014/03/14 16:35:25 Done.
86 void DetachAndRecreateLayers();
87
88 private:
89 aura::Window* window_;
90
91 // The owner of detached layers.
92 scoped_ptr<ui::LayerTreeOwner> layer_owner_;
93
94 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
95 };
96
66 namespace { 97 namespace {
67 98
68 const int kDefaultAnimationDurationForMenuMS = 150; 99 const int kDefaultAnimationDurationForMenuMS = 150;
69 100
70 const float kWindowAnimation_HideOpacity = 0.f; 101 const float kWindowAnimation_HideOpacity = 0.f;
71 const float kWindowAnimation_ShowOpacity = 1.f; 102 const float kWindowAnimation_ShowOpacity = 1.f;
72 const float kWindowAnimation_TranslateFactor = 0.5f; 103 const float kWindowAnimation_TranslateFactor = 0.5f;
73 const float kWindowAnimation_ScaleFactor = .95f; 104 const float kWindowAnimation_ScaleFactor = .95f;
74 105
75 const int kWindowAnimation_Rotate_DurationMS = 180; 106 const int kWindowAnimation_Rotate_DurationMS = 180;
76 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90; 107 const int kWindowAnimation_Rotate_OpacityDurationPercent = 90;
77 const float kWindowAnimation_Rotate_TranslateY = -20.f; 108 const float kWindowAnimation_Rotate_TranslateY = -20.f;
78 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f; 109 const float kWindowAnimation_Rotate_PerspectiveDepth = 500.f;
79 const float kWindowAnimation_Rotate_DegreesX = 5.f; 110 const float kWindowAnimation_Rotate_DegreesX = 5.f;
80 const float kWindowAnimation_Rotate_ScaleFactor = .99f; 111 const float kWindowAnimation_Rotate_ScaleFactor = .99f;
81 112
82 const float kWindowAnimation_Bounce_Scale = 1.02f; 113 const float kWindowAnimation_Bounce_Scale = 1.02f;
83 const int kWindowAnimation_Bounce_DurationMS = 180; 114 const int kWindowAnimation_Bounce_DurationMS = 180;
84 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40; 115 const int kWindowAnimation_Bounce_GrowShrinkDurationPercent = 40;
85 116
86 base::TimeDelta GetWindowVisibilityAnimationDuration( 117 base::TimeDelta GetWindowVisibilityAnimationDuration(
87 const aura::Window& window) { 118 const aura::Window& window) {
88 int duration = 119 int duration =
89 window.GetProperty(kWindowVisibilityAnimationDurationKey); 120 window.GetProperty(kWindowVisibilityAnimationDurationKey);
90 if (duration == 0 && window.type() == ui::wm::WINDOW_TYPE_MENU) { 121 if (duration == 0 && window.type() == ui::wm::WINDOW_TYPE_MENU) {
91 return base::TimeDelta::FromMilliseconds( 122 return base::TimeDelta::FromMilliseconds(
92 kDefaultAnimationDurationForMenuMS); 123 kDefaultAnimationDurationForMenuMS);
93 } 124 }
94 return TimeDelta::FromInternalValue(duration); 125 return base::TimeDelta::FromInternalValue(duration);
95 } 126 }
96 127
97 // Gets/sets the WindowVisibilityAnimationType associated with a window. 128 // Gets/sets the WindowVisibilityAnimationType associated with a window.
98 // TODO(beng): redundant/fold into method on public api? 129 // TODO(beng): redundant/fold into method on public api?
99 int GetWindowVisibilityAnimationType(aura::Window* window) { 130 int GetWindowVisibilityAnimationType(aura::Window* window) {
100 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey); 131 int type = window->GetProperty(kWindowVisibilityAnimationTypeKey);
101 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) { 132 if (type == WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT) {
102 return (window->type() == ui::wm::WINDOW_TYPE_MENU || 133 return (window->type() == ui::wm::WINDOW_TYPE_MENU ||
103 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP) 134 window->type() == ui::wm::WINDOW_TYPE_TOOLTIP)
104 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE 135 ? WINDOW_VISIBILITY_ANIMATION_TYPE_FADE
105 : WINDOW_VISIBILITY_ANIMATION_TYPE_DROP; 136 : WINDOW_VISIBILITY_ANIMATION_TYPE_DROP;
106 } 137 }
107 return type; 138 return type;
108 } 139 }
109 140
110 // Observes a hide animation.
111 // 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
113 // 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
115 // destroyed immediately - it is actually just immediately hidden and then
116 // 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
118 // subsequently destroyed this object acquires ownership of the window's layer,
119 // so that it can continue animating it until the animation completes.
120 // Regardless of whether or not the window is destroyed, this object deletes
121 // itself when the animation completes.
122 class HidingWindowAnimationObserver : public ui::ImplicitAnimationObserver,
123 public aura::WindowObserver {
124 public:
125 explicit HidingWindowAnimationObserver(aura::Window* window)
126 : window_(window) {
127 window_->AddObserver(this);
128 }
129 virtual ~HidingWindowAnimationObserver() {
130 STLDeleteElements(&layers_);
131 }
132
133 private:
134 // Overridden from ui::ImplicitAnimationObserver:
135 virtual void OnImplicitAnimationsCompleted() OVERRIDE {
136 // Window may have been destroyed by this point.
137 if (window_) {
138 aura::client::AnimationHost* animation_host =
139 aura::client::GetAnimationHost(window_);
140 if (animation_host)
141 animation_host->OnWindowHidingAnimationCompleted();
142 window_->RemoveObserver(this);
143 }
144 delete this;
145 }
146
147 // Overridden from aura::WindowObserver:
148 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {
149 DCHECK_EQ(window, window_);
150 DCHECK(layers_.empty());
151 AcquireAllLayers(window_->layer());
152 window_->RemoveObserver(this);
153 window_ = NULL;
154 }
155
156 void AcquireAllLayers(ui::Layer* layer) {
157 if (layer->owner()) {
158 ui::Layer* released = layer->owner()->AcquireLayer();
159 DCHECK_EQ(layer, released);
160 layers_.push_back(released);
161 }
162 std::vector<Layer*>::const_iterator it = layer->children().begin();
163 for (; it != layer->children().end(); ++it)
164 AcquireAllLayers(*it);
165 }
166
167 aura::Window* window_;
168 std::vector<ui::Layer*> layers_;
169
170 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver);
171 };
172
173 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { 141 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) {
174 const Layer* root = layer; 142 const ui::Layer* root = layer;
175 while (root->parent()) 143 while (root->parent())
176 root = root->parent(); 144 root = root->parent();
177 layer->GetTargetTransformRelativeTo(root, transform); 145 layer->GetTargetTransformRelativeTo(root, transform);
178 } 146 }
179 147
180 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer, 148 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer,
181 const gfx::Transform& transform) { 149 const gfx::Transform& transform) {
182 gfx::Transform in_world = transform; 150 gfx::Transform in_world = transform;
183 GetTransformRelativeToRoot(layer, &in_world); 151 GetTransformRelativeToRoot(layer, &in_world);
184 152
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 215 }
248 216
249 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 217 // 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|. 218 // its visibility to false, and its transform to |end_transform|.
251 void AnimateHideWindowCommon(aura::Window* window, 219 void AnimateHideWindowCommon(aura::Window* window,
252 const gfx::Transform& end_transform) { 220 const gfx::Transform& end_transform) {
253 AugmentWindowSize(window, end_transform); 221 AugmentWindowSize(window, end_transform);
254 window->layer()->set_delegate(NULL); 222 window->layer()->set_delegate(NULL);
255 223
256 // Property sets within this scope will be implicitly animated. 224 // Property sets within this scope will be implicitly animated.
257 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 225 ScopedHidingAnimationSettings hiding_settings(window);
258 settings.AddObserver(new HidingWindowAnimationObserver(window));
259
260 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window); 226 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(*window);
261 if (duration.ToInternalValue() > 0) 227 if (duration.ToInternalValue() > 0)
262 settings.SetTransitionDuration(duration); 228 hiding_settings.layer_animation_settings()->SetTransitionDuration(duration);
263 229
264 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 230 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
265 window->layer()->SetTransform(end_transform); 231 window->layer()->SetTransform(end_transform);
266 window->layer()->SetVisible(false); 232 window->layer()->SetVisible(false);
267 } 233 }
268 234
269 static gfx::Transform GetScaleForWindow(aura::Window* window) { 235 static gfx::Transform GetScaleForWindow(aura::Window* window) {
270 gfx::Rect bounds = window->bounds(); 236 gfx::Rect bounds = window->bounds();
271 gfx::Transform scale = gfx::GetScaleTransform( 237 gfx::Transform scale = gfx::GetScaleTransform(
272 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), 238 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 317 }
352 318
353 void AddLayerAnimationsForRotate(aura::Window* window, bool show) { 319 void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
354 window->layer()->set_delegate(window); 320 window->layer()->set_delegate(window);
355 if (show) 321 if (show)
356 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 322 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
357 323
358 base::TimeDelta duration = base::TimeDelta::FromMilliseconds( 324 base::TimeDelta duration = base::TimeDelta::FromMilliseconds(
359 kWindowAnimation_Rotate_DurationMS); 325 kWindowAnimation_Rotate_DurationMS);
360 326
327 HidingWindowAnimationObserver* observer = NULL;
328
361 if (!show) { 329 if (!show) {
362 new HidingWindowAnimationObserver(window); 330 // TODO(oshima): Fix observer leak.
331 observer = new HidingWindowAnimationObserver(window, NULL);
363 window->layer()->GetAnimator()->SchedulePauseForProperties( 332 window->layer()->GetAnimator()->SchedulePauseForProperties(
364 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100, 333 duration * (100 - kWindowAnimation_Rotate_OpacityDurationPercent) / 100,
365 ui::LayerAnimationElement::OPACITY); 334 ui::LayerAnimationElement::OPACITY);
366 } 335 }
367 scoped_ptr<ui::LayerAnimationElement> opacity( 336 scoped_ptr<ui::LayerAnimationElement> opacity(
368 ui::LayerAnimationElement::CreateOpacityElement( 337 ui::LayerAnimationElement::CreateOpacityElement(
369 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity, 338 show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
370 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100)); 339 duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
371 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT); 340 opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
372 window->layer()->GetAnimator()->ScheduleAnimation( 341 window->layer()->GetAnimator()->ScheduleAnimation(
(...skipping 27 matching lines...) Expand all
400 translation->SetChild(scale_about_pivot.release()); 369 translation->SetChild(scale_about_pivot.release());
401 rotation->SetChild(translation.release()); 370 rotation->SetChild(translation.release());
402 rotation->SetReversed(show); 371 rotation->SetReversed(show);
403 372
404 scoped_ptr<ui::LayerAnimationElement> transition( 373 scoped_ptr<ui::LayerAnimationElement> transition(
405 ui::LayerAnimationElement::CreateInterpolatedTransformElement( 374 ui::LayerAnimationElement::CreateInterpolatedTransformElement(
406 rotation.release(), duration)); 375 rotation.release(), duration));
407 376
408 window->layer()->GetAnimator()->ScheduleAnimation( 377 window->layer()->GetAnimator()->ScheduleAnimation(
409 new ui::LayerAnimationSequence(transition.release())); 378 new ui::LayerAnimationSequence(transition.release()));
379 if (observer)
380 observer->DetachAndRecreateLayers();
410 } 381 }
411 382
412 void AnimateShowWindow_Rotate(aura::Window* window) { 383 void AnimateShowWindow_Rotate(aura::Window* window) {
413 AddLayerAnimationsForRotate(window, true); 384 AddLayerAnimationsForRotate(window, true);
414 } 385 }
415 386
416 void AnimateHideWindow_Rotate(aura::Window* window) { 387 void AnimateHideWindow_Rotate(aura::Window* window) {
417 AddLayerAnimationsForRotate(window, false); 388 AddLayerAnimationsForRotate(window, false);
418 } 389 }
419 390
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 AnimateHideWindow_Rotate(window); 444 AnimateHideWindow_Rotate(window);
474 return true; 445 return true;
475 default: 446 default:
476 return false; 447 return false;
477 } 448 }
478 } 449 }
479 450
480 } // namespace 451 } // namespace
481 452
482 //////////////////////////////////////////////////////////////////////////////// 453 ////////////////////////////////////////////////////////////////////////////////
454 // HidingWindowAnimationObserver
455
456 HidingWindowAnimationObserver::HidingWindowAnimationObserver(
457 aura::Window* window,
458 ui::ScopedLayerAnimationSettings* settings)
459 : window_(window) {
460 window->AddObserver(this);
461 if (settings)
462 settings->AddObserver(this);
463 }
464
465 void HidingWindowAnimationObserver::OnImplicitAnimationsCompleted() {
466 // Window may have been destroyed by this point.
467 if (window_) {
468 aura::client::AnimationHost* animation_host =
469 aura::client::GetAnimationHost(window_);
470 if (animation_host)
471 animation_host->OnWindowHidingAnimationCompleted();
472 window_->RemoveObserver(this);
473 }
474 delete this;
475 }
476
477 void HidingWindowAnimationObserver::OnWindowDestroying(aura::Window* window) {
478 DCHECK_EQ(window, window_);
479 window_->RemoveObserver(this);
480 window_ = NULL;
481 }
482
483 void HidingWindowAnimationObserver::DetachAndRecreateLayers() {
484 layer_owner_ = RecreateLayers(window_);
485 // If the window has transient children, move above the top most
486 // transient child so that activation change does not put the
487 // window above the animating layer.
488 if(window_->parent()) {
sky 2014/03/14 14:32:13 'if(window'->'if (window'
oshima 2014/03/14 16:35:25 Done.
489 const aura::Window::Windows& transient_children =
490 GetTransientChildren(window_);
491 aura::Window::Windows::const_iterator iter =
492 std::find(window_->parent()->children().begin(),
493 window_->parent()->children().end(),
494 window_);
495 DCHECK(iter != window_->parent()->children().end());
496 aura::Window* topmost_transient_child = NULL;
497 for (++iter; iter != window_->parent()->children().end(); ++iter) {
498 if (std::find(transient_children.begin(),
499 transient_children.end(),
500 *iter) !=
501 transient_children.end()) {
502 topmost_transient_child = *iter;
503 }
504 }
505 if (topmost_transient_child) {
506 window_->parent()->layer()->StackAbove(
507 layer_owner_->root(), topmost_transient_child->layer());
508 }
509 }
510
511 // TODO(sky): The recreated layer should have the target visibility of
512 // the original layer.
513 // Make the new layer invisible immediately.
514 window_->layer()->SetVisible(false);
515 window_->layer()->SetOpacity(0);
516 }
517
518 ////////////////////////////////////////////////////////////////////////////////
519 // ScopedHidingAnimationSettings
520
521 ScopedHidingAnimationSettings::ScopedHidingAnimationSettings(
522 aura::Window* window)
523 : layer_animation_settings_(window->layer()->GetAnimator()),
524 observer_(new HidingWindowAnimationObserver(
525 window, &layer_animation_settings_)) {
526 }
527
528 ScopedHidingAnimationSettings::~ScopedHidingAnimationSettings() {
529 observer_->DetachAndRecreateLayers();
530 }
531
532 ////////////////////////////////////////////////////////////////////////////////
483 // External interface 533 // External interface
484 534
485 void SetWindowVisibilityAnimationType(aura::Window* window, int type) { 535 void SetWindowVisibilityAnimationType(aura::Window* window, int type) {
486 window->SetProperty(kWindowVisibilityAnimationTypeKey, type); 536 window->SetProperty(kWindowVisibilityAnimationTypeKey, type);
487 } 537 }
488 538
489 int GetWindowVisibilityAnimationType(aura::Window* window) { 539 int GetWindowVisibilityAnimationType(aura::Window* window) {
490 return window->GetProperty(kWindowVisibilityAnimationTypeKey); 540 return window->GetProperty(kWindowVisibilityAnimationTypeKey);
491 } 541 }
492 542
493 void SetWindowVisibilityAnimationTransition( 543 void SetWindowVisibilityAnimationTransition(
494 aura::Window* window, 544 aura::Window* window,
495 WindowVisibilityAnimationTransition transition) { 545 WindowVisibilityAnimationTransition transition) {
496 window->SetProperty(kWindowVisibilityAnimationTransitionKey, transition); 546 window->SetProperty(kWindowVisibilityAnimationTransitionKey, transition);
497 } 547 }
498 548
499 bool HasWindowVisibilityAnimationTransition( 549 bool HasWindowVisibilityAnimationTransition(
500 aura::Window* window, 550 aura::Window* window,
501 WindowVisibilityAnimationTransition transition) { 551 WindowVisibilityAnimationTransition transition) {
502 WindowVisibilityAnimationTransition prop = window->GetProperty( 552 WindowVisibilityAnimationTransition prop = window->GetProperty(
503 kWindowVisibilityAnimationTransitionKey); 553 kWindowVisibilityAnimationTransitionKey);
504 return (prop & transition) != 0; 554 return (prop & transition) != 0;
505 } 555 }
506 556
507 void SetWindowVisibilityAnimationDuration(aura::Window* window, 557 void SetWindowVisibilityAnimationDuration(aura::Window* window,
508 const TimeDelta& duration) { 558 const base::TimeDelta& duration) {
509 window->SetProperty(kWindowVisibilityAnimationDurationKey, 559 window->SetProperty(kWindowVisibilityAnimationDurationKey,
510 static_cast<int>(duration.ToInternalValue())); 560 static_cast<int>(duration.ToInternalValue()));
511 } 561 }
512 562
513 base::TimeDelta GetWindowVisibilityAnimationDuration( 563 base::TimeDelta GetWindowVisibilityAnimationDuration(
514 const aura::Window& window) { 564 const aura::Window& window) {
515 return base::TimeDelta::FromInternalValue( 565 return base::TimeDelta::FromInternalValue(
516 window.GetProperty(kWindowVisibilityAnimationDurationKey)); 566 window.GetProperty(kWindowVisibilityAnimationDurationKey));
517 } 567 }
518 568
519 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window, 569 void SetWindowVisibilityAnimationVerticalPosition(aura::Window* window,
520 float position) { 570 float position) {
521 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position); 571 window->SetProperty(kWindowVisibilityAnimationVerticalPositionKey, position);
522 } 572 }
523 573
524 ui::ImplicitAnimationObserver* CreateHidingWindowAnimationObserver(
525 aura::Window* window) {
526 return new HidingWindowAnimationObserver(window);
527 }
528
529 bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) { 574 bool AnimateOnChildWindowVisibilityChanged(aura::Window* window, bool visible) {
530 if (WindowAnimationsDisabled(window)) 575 if (WindowAnimationsDisabled(window))
531 return false; 576 return false;
532 if (visible) 577 if (visible)
533 return AnimateShowWindow(window); 578 return AnimateShowWindow(window);
534 // Don't start hiding the window again if it's already being hidden. 579 // Don't start hiding the window again if it's already being hidden.
535 return window->layer()->GetTargetOpacity() != 0.0f && 580 return window->layer()->GetTargetOpacity() != 0.0f &&
536 AnimateHideWindow(window); 581 AnimateHideWindow(window);
537 } 582 }
538 583
(...skipping 10 matching lines...) Expand all
549 594
550 bool WindowAnimationsDisabled(aura::Window* window) { 595 bool WindowAnimationsDisabled(aura::Window* window) {
551 return (!gfx::Animation::ShouldRenderRichAnimation() || (window && 596 return (!gfx::Animation::ShouldRenderRichAnimation() || (window &&
552 window->GetProperty(aura::client::kAnimationsDisabledKey)) || 597 window->GetProperty(aura::client::kAnimationsDisabledKey)) ||
553 CommandLine::ForCurrentProcess()->HasSwitch( 598 CommandLine::ForCurrentProcess()->HasSwitch(
554 switches::kWindowAnimationsDisabled)); 599 switches::kWindowAnimationsDisabled));
555 } 600 }
556 601
557 } // namespace corewm 602 } // namespace corewm
558 } // namespace views 603 } // 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