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/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_delegate.h" | |
| 20 #include "ui/aura/window_observer.h" | 21 #include "ui/aura/window_observer.h" |
| 21 #include "ui/aura/window_property.h" | 22 #include "ui/aura/window_property.h" |
| 22 #include "ui/compositor/compositor_observer.h" | 23 #include "ui/compositor/compositor_observer.h" |
| 23 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
| 24 #include "ui/compositor/layer_animation_observer.h" | 25 #include "ui/compositor/layer_animation_observer.h" |
| 25 #include "ui/compositor/layer_animation_sequence.h" | 26 #include "ui/compositor/layer_animation_sequence.h" |
| 26 #include "ui/compositor/layer_animator.h" | 27 #include "ui/compositor/layer_animator.h" |
| 27 #include "ui/compositor/scoped_layer_animation_settings.h" | 28 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 28 #include "ui/gfx/interpolated_transform.h" | 29 #include "ui/gfx/interpolated_transform.h" |
| 30 #include "ui/gfx/rect_conversions.h" | |
| 29 #include "ui/gfx/screen.h" | 31 #include "ui/gfx/screen.h" |
| 30 #include "ui/gfx/vector3d_f.h" | 32 #include "ui/gfx/vector3d_f.h" |
| 31 #include "ui/views/corewm/corewm_switches.h" | 33 #include "ui/views/corewm/corewm_switches.h" |
| 32 #include "ui/views/corewm/window_util.h" | 34 #include "ui/views/corewm/window_util.h" |
| 33 #include "ui/views/view.h" | 35 #include "ui/views/view.h" |
| 34 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 35 | 37 |
| 36 DECLARE_WINDOW_PROPERTY_TYPE(int) | 38 DECLARE_WINDOW_PROPERTY_TYPE(int) |
| 37 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) | 39 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationType) |
| 38 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) | 40 DECLARE_WINDOW_PROPERTY_TYPE(views::corewm::WindowVisibilityAnimationTransition) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 window_->AddObserver(this); | 125 window_->AddObserver(this); |
| 124 } | 126 } |
| 125 virtual ~HidingWindowAnimationObserver() { | 127 virtual ~HidingWindowAnimationObserver() { |
| 126 STLDeleteElements(&layers_); | 128 STLDeleteElements(&layers_); |
| 127 } | 129 } |
| 128 | 130 |
| 129 private: | 131 private: |
| 130 // Overridden from ui::ImplicitAnimationObserver: | 132 // Overridden from ui::ImplicitAnimationObserver: |
| 131 virtual void OnImplicitAnimationsCompleted() OVERRIDE { | 133 virtual void OnImplicitAnimationsCompleted() OVERRIDE { |
| 132 // Window may have been destroyed by this point. | 134 // Window may have been destroyed by this point. |
| 133 if (window_) | 135 if (window_) { |
| 136 if (window_->delegate()) | |
| 137 window_->delegate()->OnWindowHidingAnimationCompleted(); | |
|
sky
2013/03/14 20:06:37
Add a test for coverage of this.
scottmg
2013/03/14 22:51:53
ui/views/corewm/window_animations_unittest.cc wasn
| |
| 134 window_->RemoveObserver(this); | 138 window_->RemoveObserver(this); |
| 139 } | |
| 135 delete this; | 140 delete this; |
| 136 } | 141 } |
| 137 | 142 |
| 138 // Overridden from aura::WindowObserver: | 143 // Overridden from aura::WindowObserver: |
| 139 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 144 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
| 140 DCHECK_EQ(window, window_); | 145 DCHECK_EQ(window, window_); |
| 141 DCHECK(layers_.empty()); | 146 DCHECK(layers_.empty()); |
| 142 AcquireAllLayers(window_); | 147 AcquireAllLayers(window_); |
| 143 | 148 |
| 144 // If the Widget has views with layers, then it is necessary to take | 149 // If the Widget has views with layers, then it is necessary to take |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 172 } | 177 } |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 | 180 |
| 176 aura::Window* window_; | 181 aura::Window* window_; |
| 177 std::vector<ui::Layer*> layers_; | 182 std::vector<ui::Layer*> layers_; |
| 178 | 183 |
| 179 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); | 184 DISALLOW_COPY_AND_ASSIGN(HidingWindowAnimationObserver); |
| 180 }; | 185 }; |
| 181 | 186 |
| 187 void GetTransformRelativeToRoot(ui::Layer* layer, gfx::Transform* transform) { | |
| 188 const Layer* p = layer; | |
|
sky
2013/03/14 20:06:37
This use Layer::GetTargetTransformRelativeTo (that
scottmg
2013/03/14 22:51:53
Done.
| |
| 189 for (; p->parent(); p = p->parent()) { | |
| 190 gfx::Transform translation; | |
| 191 translation.Translate(static_cast<float>(p->bounds().x()), | |
| 192 static_cast<float>(p->bounds().y())); | |
| 193 // Use target transform so that result will be correct once animation is | |
| 194 // finished. | |
| 195 if (!p->GetTargetTransform().IsIdentity()) | |
| 196 transform->ConcatTransform(p->GetTargetTransform()); | |
| 197 transform->ConcatTransform(translation); | |
| 198 } | |
| 199 } | |
| 200 gfx::Rect GetLayerWorldBoundsAfterTransform(ui::Layer* layer, | |
|
sky
2013/03/14 20:06:37
nit: newline between 199/200.
scottmg
2013/03/14 22:51:53
Done.
| |
| 201 const gfx::Transform& transform) { | |
| 202 gfx::Transform in_world = transform; | |
| 203 GetTransformRelativeToRoot(layer, &in_world); | |
| 204 | |
| 205 gfx::RectF transformed = layer->bounds(); | |
| 206 transform.TransformRect(&transformed); | |
| 207 | |
| 208 return gfx::ToEnclosingRect(transformed); | |
| 209 } | |
| 210 | |
| 211 // Augment the host window so that the enclosing bounds of the full | |
| 212 // animation will fit inside of it. | |
| 213 void AugmentWindowSize(aura::Window* window, | |
| 214 const gfx::Transform& start_transform, | |
| 215 const gfx::Transform& end_transform) { | |
| 216 gfx::Rect world_at_start = | |
| 217 GetLayerWorldBoundsAfterTransform(window->layer(), start_transform); | |
| 218 gfx::Rect world_at_end = | |
| 219 GetLayerWorldBoundsAfterTransform(window->layer(), end_transform); | |
| 220 gfx::Rect union_in_window_space = | |
| 221 gfx::UnionRects(world_at_start, world_at_end); | |
| 222 gfx::Rect current_bounds = window->bounds(); | |
| 223 gfx::Rect result(union_in_window_space.x() - current_bounds.x(), | |
| 224 union_in_window_space.y() - current_bounds.y(), | |
| 225 union_in_window_space.width() - current_bounds.width(), | |
| 226 union_in_window_space.height() - current_bounds.height()); | |
| 227 if (window->delegate()) | |
| 228 window->delegate()->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); | |
|
sky
2013/03/14 20:06:37
Don't we only need to do this for some windows? Fo
scottmg
2013/03/14 22:51:53
That's right. It's ignored by the delegate in thos
| |
| 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 | |
| 200 window->layer()->SetTransform(end_transform); | 251 window->layer()->SetTransform(end_transform); |
| 201 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); | 252 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); |
| 202 } | 253 } |
| 203 } | 254 } |
| 204 | 255 |
| 205 // Hides a window using an animation, animating its opacity from 1.f to 0.f, | 256 // 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|. | 257 // its visibility to false, and its transform to |end_transform|. |
| 207 void AnimateHideWindowCommon(aura::Window* window, | 258 void AnimateHideWindowCommon(aura::Window* window, |
| 208 const gfx::Transform& end_transform) { | 259 const gfx::Transform& end_transform) { |
| 260 AugmentWindowSize(window, gfx::Transform(), end_transform); | |
| 209 window->layer()->set_delegate(NULL); | 261 window->layer()->set_delegate(NULL); |
| 210 | 262 |
| 211 // Property sets within this scope will be implicitly animated. | 263 // Property sets within this scope will be implicitly animated. |
| 212 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 264 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 213 settings.AddObserver(new HidingWindowAnimationObserver(window)); | 265 settings.AddObserver(new HidingWindowAnimationObserver(window)); |
| 214 | 266 |
| 215 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); | 267 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); |
| 216 if (duration.ToInternalValue() > 0) | 268 if (duration.ToInternalValue() > 0) |
| 217 settings.SetTransitionDuration(duration); | 269 settings.SetTransitionDuration(duration); |
| 218 | |
| 219 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); | 270 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); |
| 220 window->layer()->SetTransform(end_transform); | 271 window->layer()->SetTransform(end_transform); |
| 221 window->layer()->SetVisible(false); | 272 window->layer()->SetVisible(false); |
| 222 } | 273 } |
| 223 | 274 |
| 224 static gfx::Transform GetScaleForWindow(aura::Window* window) { | 275 static gfx::Transform GetScaleForWindow(aura::Window* window) { |
| 225 gfx::Rect bounds = window->bounds(); | 276 gfx::Rect bounds = window->bounds(); |
| 226 gfx::Transform scale = gfx::GetScaleTransform( | 277 gfx::Transform scale = gfx::GetScaleTransform( |
| 227 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), | 278 gfx::Point(kWindowAnimation_TranslateFactor * bounds.width(), |
| 228 kWindowAnimation_TranslateFactor * bounds.height()), | 279 kWindowAnimation_TranslateFactor * bounds.height()), |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 | 536 |
| 486 bool WindowAnimationsDisabled(aura::Window* window) { | 537 bool WindowAnimationsDisabled(aura::Window* window) { |
| 487 return (window && | 538 return (window && |
| 488 window->GetProperty(aura::client::kAnimationsDisabledKey)) || | 539 window->GetProperty(aura::client::kAnimationsDisabledKey)) || |
| 489 CommandLine::ForCurrentProcess()->HasSwitch( | 540 CommandLine::ForCurrentProcess()->HasSwitch( |
| 490 switches::kWindowAnimationsDisabled); | 541 switches::kWindowAnimationsDisabled); |
| 491 } | 542 } |
| 492 | 543 |
| 493 } // namespace corewm | 544 } // namespace corewm |
| 494 } // namespace views | 545 } // namespace views |
| OLD | NEW |