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/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 <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.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "ui/aura/client/animation_host.h" | |
| 18 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_delegate.h" | |
| 20 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
| 21 #include "ui/aura/window_property.h" | 23 #include "ui/aura/window_property.h" |
| 22 #include "ui/compositor/compositor_observer.h" | 24 #include "ui/compositor/compositor_observer.h" |
| 23 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
| 24 #include "ui/compositor/layer_animation_observer.h" | 26 #include "ui/compositor/layer_animation_observer.h" |
| 25 #include "ui/compositor/layer_animation_sequence.h" | 27 #include "ui/compositor/layer_animation_sequence.h" |
| 26 #include "ui/compositor/layer_animator.h" | 28 #include "ui/compositor/layer_animator.h" |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" | 29 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 28 #include "ui/gfx/interpolated_transform.h" | 30 #include "ui/gfx/interpolated_transform.h" |
| 31 #include "ui/gfx/rect_conversions.h" | |
| 29 #include "ui/gfx/screen.h" | 32 #include "ui/gfx/screen.h" |
| 30 #include "ui/gfx/vector3d_f.h" | 33 #include "ui/gfx/vector3d_f.h" |
| 31 #include "ui/views/corewm/corewm_switches.h" | 34 #include "ui/views/corewm/corewm_switches.h" |
| 32 #include "ui/views/corewm/window_util.h" | 35 #include "ui/views/corewm/window_util.h" |
| 33 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
| 34 #include "ui/views/widget/widget.h" | 37 #include "ui/views/widget/widget.h" |
| 35 | 38 |
| 36 DECLARE_WINDOW_PROPERTY_TYPE(int) | 39 DECLARE_WINDOW_PROPERTY_TYPE(int) |
| 37 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) | 40 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) |
| 38 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) | 41 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 window_->AddObserver(this); | 126 window_->AddObserver(this); |
| 124 } | 127 } |
| 125 virtual ~HidingWindowAnimationObserver() { | 128 virtual ~HidingWindowAnimationObserver() { |
| 126 STLDeleteElements(&layers_); | 129 STLDeleteElements(&layers_); |
| 127 } | 130 } |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 // Overridden from ui::ImplicitAnimationObserver: | 133 // Overridden from ui::ImplicitAnimationObserver: |
| 131 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 134 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 132 // Window may have been destroyed by this point. | 135 // Window may have been destroyed by this point. |
| 133 if (window_) | 136 if (window_) { |
| 137 aura::client::AnimationHost* animation_host = | |
| 138 aura::client::GetAnimationHost(window_); | |
| 139 if (animation_host) | |
| 140 animation_host->OnWindowHidingAnimationCompleted(); | |
| 134 window_->RemoveObserver(this); | 141 window_->RemoveObserver(this); |
| 142 } | |
| 135 delete this; | 143 delete this; |
| 136 } | 144 } |
| 137 | 145 |
| 138 // Overridden from aura::WindowObserver: | 146 // Overridden from aura::WindowObserver: |
| 139 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 147 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| 140 DCHECK_EQ(window, window_); | 148 DCHECK_EQ(window, window_); |
| 141 DCHECK(layers_.empty()); | 149 DCHECK(layers_.empty()); |
| 142 AcquireAllLayers(window_); | 150 AcquireAllLayers(window_); |
| 143 | 151 |
| 144 // If the Widget has views with layers, then it is necessary to take | 152 // If the Widget has views with layers, then it is necessary to take |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 } | 180 } |
| 173 } | 181 } |
| 174 } | 182 } |
| 175 | 183 |
| 176 aura::Window* window_; | 184 aura::Window* window_; |
| 177 std::vector<ui::Layer*> layers_; | 185 std::vector<ui::Layer*> layers_; |
| 178 | 186 |
| 179 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); | 187 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); |
| 180 }; | 188 }; |
| 181 | 189 |
| 190 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { | |
| 191 const Layer* root = layer; | |
| 192 while (root->parent()) | |
| 193 root = root->parent(); | |
| 194 layer->GetTargetTransformRelativeTo(root, transform); | |
| 195 } | |
| 196 | |
| 197 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer, | |
| 198 const gfx::Transform& transform) { | |
| 199 gfx::Transform in_world = transform; | |
| 200 GetTransformRelativeToRoot(layer, &in_world); | |
| 201 | |
| 202 gfx::RectF transformed = layer->bounds(); | |
| 203 in_world.TransformRect(&transformed); | |
| 204 | |
| 205 return gfx::ToEnclosingRect(transformed); | |
| 206 } | |
| 207 | |
| 208 // Augment the host window so that the enclosing bounds of the full | |
| 209 // animation will fit inside of it. | |
| 210 void AugmentWindowSize(aura::Window* window, | |
| 211 const gfx::Transform& start_transform, | |
| 212 const gfx::Transform& end_transform) { | |
| 213 gfx::Rect world_at_start = | |
|
sky
2013/03/18 15:49:42
Can you early out here if animation_host is NULL?
scottmg
2013/03/18 21:47:48
Done.
| |
| 214 GetLayerWorldBoundsAfterTransform(window->layer(), start_transform); | |
| 215 gfx::Rect world_at_end = | |
| 216 GetLayerWorldBoundsAfterTransform(window->layer(), end_transform); | |
| 217 gfx::Rect union_in_window_space = | |
| 218 gfx::UnionRects(world_at_start, world_at_end); | |
| 219 gfx::Rect current_bounds = window->bounds(); | |
| 220 gfx::Rect result(union_in_window_space.x() - current_bounds.x(), | |
| 221 union_in_window_space.y() - current_bounds.y(), | |
| 222 union_in_window_space.width() - current_bounds.width(), | |
| 223 union_in_window_space.height() - current_bounds.height()); | |
| 224 | |
| 225 aura::client::AnimationHost* animation_host = | |
| 226 aura::client::GetAnimationHost(window); | |
| 227 if (animation_host) | |
| 228 animation_host->SetHostTransitionBounds(result); | |
| 229 } | |
| 230 | |
| 182 // Shows a window using an animation, animating its opacity from 0.f to 1.f, | 231 // Shows a window using an animation, animating its opacity from 0.f to 1.f, |
| 183 // its visibility to true, and its transform from |start_transform| to | 232 // its visibility to true, and its transform from |start_transform| to |
| 184 // |end_transform|. | 233 // |end_transform|. |
| 185 void AnimateShowWindowCommon(aura::Window* window, | 234 void AnimateShowWindowCommon(aura::Window* window, |
| 186 const gfx::Transform& start_transform, | 235 const gfx::Transform& start_transform, |
| 187 const gfx::Transform& end_transform) { | 236 const gfx::Transform& end_transform) { |
| 188 window->layer()->set_delegate(window); | 237 window->layer()->set_delegate(window); |
| 238 | |
| 239 AugmentWindowSize(window, start_transform, end_transform); | |
| 240 | |
| 189 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 241 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
| 190 window->layer()->SetTransform(start_transform); | 242 window->layer()->SetTransform(start_transform); |
| 191 window->layer()->SetVisible(true); | 243 window->layer()->SetVisible(true); |
| 192 | 244 |
| 193 { | 245 { |
| 194 // Property sets within this scope will be implicitly animated. | 246 // Property sets within this scope will be implicitly animated. |
| 195 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 247 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 196 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 248 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); |
| 197 if (duration.ToInternalValue() > 0) | 249 if (duration.ToInternalValue() > 0) |
| 198 settings.SetTransitionDuration(duration); | 250 settings.SetTransitionDuration(duration); |
| 199 | 251 |
| 200 window->layer()->SetTransform(end_transform); | 252 window->layer()->SetTransform(end_transform); |
| 201 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); | 253 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
| 202 } | 254 } |
| 203 } | 255 } |
| 204 | 256 |
| 205 // Hides a window using an animation, animating its opacity from 1.f to 0.f, | 257 // Hides a window using an animation, animating its opacity from 1.f to 0.f, |
| 206 // its visibility to false, and its transform to |end_transform|. | 258 // its visibility to false, and its transform to |end_transform|. |
| 207 void AnimateHideWindowCommon(aura::Window* window, | 259 void AnimateHideWindowCommon(aura::Window* window, |
| 208 const gfx::Transform& end_transform) { | 260 const gfx::Transform& end_transform) { |
| 261 AugmentWindowSize(window, gfx::Transform(), end_transform); | |
| 209 window->layer()->set_delegate(NULL); | 262 window->layer()->set_delegate(NULL); |
| 210 | 263 |
| 211 // Property sets within this scope will be implicitly animated. | 264 // Property sets within this scope will be implicitly animated. |
| 212 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 265 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 213 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 266 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
| 214 | 267 |
| 215 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 268 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); |
| 216 if (duration.ToInternalValue() > 0) | 269 if (duration.ToInternalValue() > 0) |
| 217 settings.SetTransitionDuration(duration); | 270 settings.SetTransitionDuration(duration); |
| 218 | 271 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 | 538 |
| 486 bool WindowAnimationsDisabled(aura::Window* window) { | 539 bool WindowAnimationsDisabled(aura::Window* window) { |
| 487 return (window && | 540 return (window && |
| 488 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 541 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
| 489 CommandLine::ForCurrentProcess()->HasSwitch( | 542 CommandLine::ForCurrentProcess()->HasSwitch( |
| 490 switches::kWindowAnimationsDisabled); | 543 switches::kWindowAnimationsDisabled); |
| 491 } | 544 } |
| 492 | 545 |
| 493 } // namespace corewm | 546 } // namespace corewm |
| 494 } // namespace views | 547 } // namespace views |
| OLD | NEW |