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

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

Issue 11087093: Migrate ui::Transform to gfx::Transform (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Should pass trybots this time Created 8 years, 2 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
« no previous file with comments | « ash/wm/session_state_animator.cc ('k') | ash/wm/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 "ash/wm/window_animations.h" 5 #include "ash/wm/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>
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 ui::Layer* layer_; 230 ui::Layer* layer_;
231 231
232 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver); 232 DISALLOW_COPY_AND_ASSIGN(WorkspaceHidingWindowAnimationObserver);
233 }; 233 };
234 234
235 // Shows a window using an animation, animating its opacity from 0.f to 1.f, 235 // Shows a window using an animation, animating its opacity from 0.f to 1.f,
236 // its visibility to true, and its transform from |start_transform| to 236 // its visibility to true, and its transform from |start_transform| to
237 // |end_transform|. 237 // |end_transform|.
238 void AnimateShowWindowCommon(aura::Window* window, 238 void AnimateShowWindowCommon(aura::Window* window,
239 const ui::Transform& start_transform, 239 const gfx::Transform& start_transform,
240 const ui::Transform& end_transform) { 240 const gfx::Transform& end_transform) {
241 window->layer()->set_delegate(window); 241 window->layer()->set_delegate(window);
242 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 242 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
243 window->layer()->SetTransform(start_transform); 243 window->layer()->SetTransform(start_transform);
244 244
245 { 245 {
246 // Property sets within this scope will be implicitly animated. 246 // Property sets within this scope will be implicitly animated.
247 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 247 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
248 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 248 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
249 if (duration.ToInternalValue() > 0) 249 if (duration.ToInternalValue() > 0)
250 settings.SetTransitionDuration(duration); 250 settings.SetTransitionDuration(duration);
251 251
252 window->layer()->SetVisible(true); 252 window->layer()->SetVisible(true);
253 window->layer()->SetTransform(end_transform); 253 window->layer()->SetTransform(end_transform);
254 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity); 254 window->layer()->SetOpacity(kWindowAnimation_ShowOpacity);
255 } 255 }
256 } 256 }
257 257
258 // Hides a window using an animation, animating its opacity from 1.f to 0.f, 258 // Hides a window using an animation, animating its opacity from 1.f to 0.f,
259 // its visibility to false, and its transform to |end_transform|. 259 // its visibility to false, and its transform to |end_transform|.
260 void AnimateHideWindowCommon(aura::Window* window, 260 void AnimateHideWindowCommon(aura::Window* window,
261 const ui::Transform& end_transform) { 261 const gfx::Transform& end_transform) {
262 window->layer()->set_delegate(NULL); 262 window->layer()->set_delegate(NULL);
263 263
264 // Property sets within this scope will be implicitly animated. 264 // Property sets within this scope will be implicitly animated.
265 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 265 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
266 settings.AddObserver(new HidingWindowAnimationObserver(window)); 266 settings.AddObserver(new HidingWindowAnimationObserver(window));
267 267
268 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window); 268 base::TimeDelta duration = GetWindowVisibilityAnimationDuration(window);
269 if (duration.ToInternalValue() > 0) 269 if (duration.ToInternalValue() > 0)
270 settings.SetTransitionDuration(duration); 270 settings.SetTransitionDuration(duration);
271 271
272 window->layer()->SetOpacity(kWindowAnimation_HideOpacity); 272 window->layer()->SetOpacity(kWindowAnimation_HideOpacity);
273 window->layer()->SetTransform(end_transform); 273 window->layer()->SetTransform(end_transform);
274 window->layer()->SetVisible(false); 274 window->layer()->SetVisible(false);
275 } 275 }
276 276
277 // Show/Hide windows using a shrink animation. 277 // Show/Hide windows using a shrink animation.
278 void AnimateShowWindow_Drop(aura::Window* window) { 278 void AnimateShowWindow_Drop(aura::Window* window) {
279 ui::Transform transform; 279 gfx::Transform transform;
280 transform.ConcatScale(kWindowAnimation_ScaleFactor, 280 transform.ConcatScale(kWindowAnimation_ScaleFactor,
281 kWindowAnimation_ScaleFactor); 281 kWindowAnimation_ScaleFactor);
282 gfx::Rect bounds = window->bounds(); 282 gfx::Rect bounds = window->bounds();
283 transform.ConcatTranslate( 283 transform.ConcatTranslate(
284 kWindowAnimation_TranslateFactor * bounds.width(), 284 kWindowAnimation_TranslateFactor * bounds.width(),
285 kWindowAnimation_TranslateFactor * bounds.height()); 285 kWindowAnimation_TranslateFactor * bounds.height());
286 AnimateShowWindowCommon(window, transform, ui::Transform()); 286 AnimateShowWindowCommon(window, transform, gfx::Transform());
287 } 287 }
288 288
289 void AnimateHideWindow_Drop(aura::Window* window) { 289 void AnimateHideWindow_Drop(aura::Window* window) {
290 ui::Transform transform; 290 gfx::Transform transform;
291 transform.ConcatScale(kWindowAnimation_ScaleFactor, 291 transform.ConcatScale(kWindowAnimation_ScaleFactor,
292 kWindowAnimation_ScaleFactor); 292 kWindowAnimation_ScaleFactor);
293 gfx::Rect bounds = window->bounds(); 293 gfx::Rect bounds = window->bounds();
294 transform.ConcatTranslate( 294 transform.ConcatTranslate(
295 kWindowAnimation_TranslateFactor * bounds.width(), 295 kWindowAnimation_TranslateFactor * bounds.width(),
296 kWindowAnimation_TranslateFactor * bounds.height()); 296 kWindowAnimation_TranslateFactor * bounds.height());
297 AnimateHideWindowCommon(window, transform); 297 AnimateHideWindowCommon(window, transform);
298 } 298 }
299 299
300 // Show/Hide windows using a vertical Glenimation. 300 // Show/Hide windows using a vertical Glenimation.
301 void AnimateShowWindow_Vertical(aura::Window* window) { 301 void AnimateShowWindow_Vertical(aura::Window* window) {
302 ui::Transform transform; 302 gfx::Transform transform;
303 transform.ConcatTranslate(0, window->GetProperty( 303 transform.ConcatTranslate(0, window->GetProperty(
304 kWindowVisibilityAnimationVerticalPositionKey)); 304 kWindowVisibilityAnimationVerticalPositionKey));
305 AnimateShowWindowCommon(window, transform, ui::Transform()); 305 AnimateShowWindowCommon(window, transform, gfx::Transform());
306 } 306 }
307 307
308 void AnimateHideWindow_Vertical(aura::Window* window) { 308 void AnimateHideWindow_Vertical(aura::Window* window) {
309 ui::Transform transform; 309 gfx::Transform transform;
310 transform.ConcatTranslate(0, window->GetProperty( 310 transform.ConcatTranslate(0, window->GetProperty(
311 kWindowVisibilityAnimationVerticalPositionKey)); 311 kWindowVisibilityAnimationVerticalPositionKey));
312 AnimateHideWindowCommon(window, transform); 312 AnimateHideWindowCommon(window, transform);
313 } 313 }
314 314
315 // Show/Hide windows using a fade. 315 // Show/Hide windows using a fade.
316 void AnimateShowWindow_Fade(aura::Window* window) { 316 void AnimateShowWindow_Fade(aura::Window* window) {
317 AnimateShowWindowCommon(window, ui::Transform(), ui::Transform()); 317 AnimateShowWindowCommon(window, gfx::Transform(), gfx::Transform());
318 } 318 }
319 319
320 void AnimateHideWindow_Fade(aura::Window* window) { 320 void AnimateHideWindow_Fade(aura::Window* window) {
321 AnimateHideWindowCommon(window, ui::Transform()); 321 AnimateHideWindowCommon(window, gfx::Transform());
322 } 322 }
323 323
324 // Builds the transform used when switching workspaces for the specified 324 // Builds the transform used when switching workspaces for the specified
325 // window. 325 // window.
326 ui::Transform BuildWorkspaceSwitchTransform(aura::Window* window, float scale) { 326 gfx::Transform BuildWorkspaceSwitchTransform(aura::Window* window,
327 float scale) {
327 // Animations for transitioning workspaces scale all windows. To give the 328 // Animations for transitioning workspaces scale all windows. To give the
328 // effect of scaling from the center of the screen the windows are translated. 329 // effect of scaling from the center of the screen the windows are translated.
329 gfx::Rect bounds = window->bounds(); 330 gfx::Rect bounds = window->bounds();
330 gfx::Rect parent_bounds(window->parent()->bounds()); 331 gfx::Rect parent_bounds(window->parent()->bounds());
331 332
332 float mid_x = static_cast<float>(parent_bounds.width()) / 2.0f; 333 float mid_x = static_cast<float>(parent_bounds.width()) / 2.0f;
333 float initial_x = 334 float initial_x =
334 (static_cast<float>(bounds.x()) - mid_x) * scale + mid_x; 335 (static_cast<float>(bounds.x()) - mid_x) * scale + mid_x;
335 float mid_y = static_cast<float>(parent_bounds.height()) / 2.0f; 336 float mid_y = static_cast<float>(parent_bounds.height()) / 2.0f;
336 float initial_y = 337 float initial_y =
337 (static_cast<float>(bounds.y()) - mid_y) * scale + mid_y; 338 (static_cast<float>(bounds.y()) - mid_y) * scale + mid_y;
338 339
339 ui::Transform transform; 340 gfx::Transform transform;
340 transform.ConcatTranslate( 341 transform.ConcatTranslate(
341 initial_x - static_cast<float>(bounds.x()), 342 initial_x - static_cast<float>(bounds.x()),
342 initial_y - static_cast<float>(bounds.y())); 343 initial_y - static_cast<float>(bounds.y()));
343 transform.ConcatScale(scale, scale); 344 transform.ConcatScale(scale, scale);
344 return transform; 345 return transform;
345 } 346 }
346 347
347 void AnimateShowWindow_Workspace(aura::Window* window) { 348 void AnimateShowWindow_Workspace(aura::Window* window) {
348 ui::Transform transform( 349 gfx::Transform transform(
349 BuildWorkspaceSwitchTransform(window, kWorkspaceScale)); 350 BuildWorkspaceSwitchTransform(window, kWorkspaceScale));
350 // When we call SetOpacity here, if a hide sequence is already running, 351 // When we call SetOpacity here, if a hide sequence is already running,
351 // the default animation preemption strategy fast forwards the hide sequence 352 // the default animation preemption strategy fast forwards the hide sequence
352 // to completion and notifies the WorkspaceHidingWindowAnimationObserver to 353 // to completion and notifies the WorkspaceHidingWindowAnimationObserver to
353 // set the layer to be invisible. We should call SetVisible after SetOpacity 354 // set the layer to be invisible. We should call SetVisible after SetOpacity
354 // to ensure our layer is visible again. 355 // to ensure our layer is visible again.
355 window->layer()->SetOpacity(0.0f); 356 window->layer()->SetOpacity(0.0f);
356 window->layer()->SetTransform(transform); 357 window->layer()->SetTransform(transform);
357 window->layer()->SetVisible(true); 358 window->layer()->SetVisible(true);
358 359
359 { 360 {
360 // Property sets within this scope will be implicitly animated. 361 // Property sets within this scope will be implicitly animated.
361 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 362 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
362 363
363 window->layer()->SetTransform(ui::Transform()); 364 window->layer()->SetTransform(gfx::Transform());
364 // Opacity animates only during the first half of the animation. 365 // Opacity animates only during the first half of the animation.
365 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2); 366 settings.SetTransitionDuration(settings.GetTransitionDuration() / 2);
366 window->layer()->SetOpacity(1.0f); 367 window->layer()->SetOpacity(1.0f);
367 } 368 }
368 } 369 }
369 370
370 void AnimateHideWindow_Workspace(aura::Window* window) { 371 void AnimateHideWindow_Workspace(aura::Window* window) {
371 ui::Transform transform( 372 gfx::Transform transform(
372 BuildWorkspaceSwitchTransform(window, kWorkspaceScale)); 373 BuildWorkspaceSwitchTransform(window, kWorkspaceScale));
373 window->layer()->SetOpacity(1.0f); 374 window->layer()->SetOpacity(1.0f);
374 window->layer()->SetTransform(ui::Transform()); 375 window->layer()->SetTransform(gfx::Transform());
375 376
376 // Opacity animates from 1 to 0 only over the second half of the animation. To 377 // Opacity animates from 1 to 0 only over the second half of the animation. To
377 // get this functionality two animations are schedule for opacity, the first 378 // get this functionality two animations are schedule for opacity, the first
378 // from 1 to 1 (which effectively does nothing) the second from 1 to 0. 379 // from 1 to 1 (which effectively does nothing) the second from 1 to 0.
379 // Because we're scheduling two animations of the same property we need to 380 // Because we're scheduling two animations of the same property we need to
380 // change the preemption strategy. 381 // change the preemption strategy.
381 ui::LayerAnimator* animator = window->layer()->GetAnimator(); 382 ui::LayerAnimator* animator = window->layer()->GetAnimator();
382 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 383 animator->set_preemption_strategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
383 { 384 {
384 // Property sets within this scope will be implicitly animated. 385 // Property sets within this scope will be implicitly animated.
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 704
704 // Scale up the old layer while translating to new position. 705 // Scale up the old layer while translating to new position.
705 { 706 {
706 old_layer->GetAnimator()->StopAnimating(); 707 old_layer->GetAnimator()->StopAnimating();
707 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator()); 708 ui::ScopedLayerAnimationSettings settings(old_layer->GetAnimator());
708 709
709 // Animation observer owns the old layer and deletes itself. 710 // Animation observer owns the old layer and deletes itself.
710 settings.AddObserver(new internal::CrossFadeObserver(window, old_layer)); 711 settings.AddObserver(new internal::CrossFadeObserver(window, old_layer));
711 settings.SetTransitionDuration(duration); 712 settings.SetTransitionDuration(duration);
712 settings.SetTweenType(tween_type); 713 settings.SetTweenType(tween_type);
713 ui::Transform out_transform; 714 gfx::Transform out_transform;
714 float scale_x = static_cast<float>(new_bounds.width()) / 715 float scale_x = static_cast<float>(new_bounds.width()) /
715 static_cast<float>(old_bounds.width()); 716 static_cast<float>(old_bounds.width());
716 float scale_y = static_cast<float>(new_bounds.height()) / 717 float scale_y = static_cast<float>(new_bounds.height()) /
717 static_cast<float>(old_bounds.height()); 718 static_cast<float>(old_bounds.height());
718 out_transform.ConcatScale(scale_x, scale_y); 719 out_transform.ConcatScale(scale_x, scale_y);
719 out_transform.ConcatTranslate(new_bounds.x() - old_bounds.x(), 720 out_transform.ConcatTranslate(new_bounds.x() - old_bounds.x(),
720 new_bounds.y() - old_bounds.y()); 721 new_bounds.y() - old_bounds.y());
721 old_layer->SetTransform(out_transform); 722 old_layer->SetTransform(out_transform);
722 if (old_on_top) { 723 if (old_on_top) {
723 // The old layer is on top, and should fade out. The new layer below will 724 // The old layer is on top, and should fade out. The new layer below will
724 // stay opaque to block the desktop. 725 // stay opaque to block the desktop.
725 old_layer->SetOpacity(0.f); 726 old_layer->SetOpacity(0.f);
726 } 727 }
727 // In tests |old_layer| is deleted here, as animations have zero duration. 728 // In tests |old_layer| is deleted here, as animations have zero duration.
728 old_layer = NULL; 729 old_layer = NULL;
729 } 730 }
730 731
731 // Set the new layer's current transform, such that the user sees a scaled 732 // Set the new layer's current transform, such that the user sees a scaled
732 // version of the window with the original bounds at the original position. 733 // version of the window with the original bounds at the original position.
733 ui::Transform in_transform; 734 gfx::Transform in_transform;
734 const float scale_x = static_cast<float>(old_bounds.width()) / 735 const float scale_x = static_cast<float>(old_bounds.width()) /
735 static_cast<float>(new_bounds.width()); 736 static_cast<float>(new_bounds.width());
736 const float scale_y = static_cast<float>(old_bounds.height()) / 737 const float scale_y = static_cast<float>(old_bounds.height()) /
737 static_cast<float>(new_bounds.height()); 738 static_cast<float>(new_bounds.height());
738 in_transform.ConcatScale(scale_x, scale_y); 739 in_transform.ConcatScale(scale_x, scale_y);
739 in_transform.ConcatTranslate(old_bounds.x() - new_bounds.x(), 740 in_transform.ConcatTranslate(old_bounds.x() - new_bounds.x(),
740 old_bounds.y() - new_bounds.y()); 741 old_bounds.y() - new_bounds.y());
741 window->layer()->SetTransform(in_transform); 742 window->layer()->SetTransform(in_transform);
742 if (!old_on_top) { 743 if (!old_on_top) {
743 // The new layer is on top and should fade in. The old layer below will 744 // The new layer is on top and should fade in. The old layer below will
744 // stay opaque and block the desktop. 745 // stay opaque and block the desktop.
745 window->layer()->SetOpacity(0.f); 746 window->layer()->SetOpacity(0.f);
746 } 747 }
747 { 748 {
748 // Animate the new layer to the identity transform, so the window goes to 749 // Animate the new layer to the identity transform, so the window goes to
749 // its newly set bounds. 750 // its newly set bounds.
750 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 751 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
751 settings.SetTransitionDuration(duration); 752 settings.SetTransitionDuration(duration);
752 settings.SetTweenType(tween_type); 753 settings.SetTweenType(tween_type);
753 window->layer()->SetTransform(ui::Transform()); 754 window->layer()->SetTransform(gfx::Transform());
754 if (!old_on_top) { 755 if (!old_on_top) {
755 // New layer is on top, fade it in. 756 // New layer is on top, fade it in.
756 window->layer()->SetOpacity(1.f); 757 window->layer()->SetOpacity(1.f);
757 } 758 }
758 } 759 }
759 return duration; 760 return duration;
760 } 761 }
761 762
762 } // namespace 763 } // namespace
763 764
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 return AnimateShowWindow(window); 876 return AnimateShowWindow(window);
876 } else { 877 } else {
877 // Don't start hiding the window again if it's already being hidden. 878 // Don't start hiding the window again if it's already being hidden.
878 return window->layer()->GetTargetOpacity() != 0.0f && 879 return window->layer()->GetTargetOpacity() != 0.0f &&
879 AnimateHideWindow(window); 880 AnimateHideWindow(window);
880 } 881 }
881 } 882 }
882 883
883 } // namespace internal 884 } // namespace internal
884 } // namespace ash 885 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/session_state_animator.cc ('k') | ash/wm/window_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698