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

Side by Side Diff: ash/wm/workspace/workspace_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
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/workspace/workspace_animations.h" 5 #include "ash/wm/workspace/workspace_animations.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
(...skipping 15 matching lines...) Expand all
26 26
27 enum WorkspaceScaleType { 27 enum WorkspaceScaleType {
28 WORKSPACE_SCALE_ABOVE, 28 WORKSPACE_SCALE_ABOVE,
29 WORKSPACE_SCALE_BELOW, 29 WORKSPACE_SCALE_BELOW,
30 }; 30 };
31 31
32 // Applies the specified WorkspaceScaleType. 32 // Applies the specified WorkspaceScaleType.
33 void ApplyWorkspaceScale(ui::Layer* layer, WorkspaceScaleType type) { 33 void ApplyWorkspaceScale(ui::Layer* layer, WorkspaceScaleType type) {
34 const float scale = type == WORKSPACE_SCALE_ABOVE ? kWorkspaceScaleAbove : 34 const float scale = type == WORKSPACE_SCALE_ABOVE ? kWorkspaceScaleAbove :
35 kWorkspaceScaleBelow; 35 kWorkspaceScaleBelow;
36 ui::Transform transform; 36 gfx::Transform transform;
37 transform.ConcatScale(scale, scale); 37 transform.ConcatScale(scale, scale);
38 transform.ConcatTranslate( 38 transform.ConcatTranslate(
39 -layer->bounds().width() * (scale - 1.0f) / 2, 39 -layer->bounds().width() * (scale - 1.0f) / 2,
40 -layer->bounds().height() * (scale - 1.0f) / 2); 40 -layer->bounds().height() * (scale - 1.0f) / 2);
41 layer->SetTransform(transform); 41 layer->SetTransform(transform);
42 } 42 }
43 43
44 // If |details.duration| is not-empty it is returned, otherwise 44 // If |details.duration| is not-empty it is returned, otherwise
45 // |kWorkspaceSwitchTimeMS| is returned. 45 // |kWorkspaceSwitchTimeMS| is returned.
46 base::TimeDelta DurationForWorkspaceShowOrHide( 46 base::TimeDelta DurationForWorkspaceShowOrHide(
(...skipping 16 matching lines...) Expand all
63 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() { 63 WorkspaceAnimationDetails::~WorkspaceAnimationDetails() {
64 } 64 }
65 65
66 void ShowWorkspace(aura::Window* window, 66 void ShowWorkspace(aura::Window* window,
67 const WorkspaceAnimationDetails& details) { 67 const WorkspaceAnimationDetails& details) {
68 window->Show(); 68 window->Show();
69 69
70 if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch( 70 if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch(
71 ash::switches::kAshWindowAnimationsDisabled)) { 71 ash::switches::kAshWindowAnimationsDisabled)) {
72 window->layer()->SetOpacity(1.0f); 72 window->layer()->SetOpacity(1.0f);
73 window->layer()->SetTransform(ui::Transform()); 73 window->layer()->SetTransform(gfx::Transform());
74 return; 74 return;
75 } 75 }
76 76
77 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f); 77 window->layer()->SetOpacity(details.animate_opacity ? 0.0f : 1.0f);
78 if (details.animate_scale) { 78 if (details.animate_scale) {
79 ApplyWorkspaceScale(window->layer(), 79 ApplyWorkspaceScale(window->layer(),
80 details.direction == WORKSPACE_ANIMATE_UP ? 80 details.direction == WORKSPACE_ANIMATE_UP ?
81 WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE); 81 WORKSPACE_SCALE_BELOW : WORKSPACE_SCALE_ABOVE);
82 } else { 82 } else {
83 window->layer()->SetTransform(ui::Transform()); 83 window->layer()->SetTransform(gfx::Transform());
84 } 84 }
85 85
86 // In order for pause to work we need to stop animations. 86 // In order for pause to work we need to stop animations.
87 window->layer()->GetAnimator()->StopAnimating(); 87 window->layer()->GetAnimator()->StopAnimating();
88 88
89 { 89 {
90 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 90 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
91 91
92 if (details.pause_time_ms > 0) { 92 if (details.pause_time_ms > 0) {
93 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 93 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
94 window->layer()->GetAnimator()->SchedulePauseForProperties( 94 window->layer()->GetAnimator()->SchedulePauseForProperties(
95 base::TimeDelta::FromMilliseconds(details.pause_time_ms), 95 base::TimeDelta::FromMilliseconds(details.pause_time_ms),
96 ui::LayerAnimationElement::TRANSFORM, 96 ui::LayerAnimationElement::TRANSFORM,
97 ui::LayerAnimationElement::OPACITY, 97 ui::LayerAnimationElement::OPACITY,
98 ui::LayerAnimationElement::BRIGHTNESS, 98 ui::LayerAnimationElement::BRIGHTNESS,
99 ui::LayerAnimationElement::VISIBILITY, 99 ui::LayerAnimationElement::VISIBILITY,
100 -1); 100 -1);
101 } 101 }
102 102
103 settings.SetTweenType(kWorkspaceTweenType); 103 settings.SetTweenType(kWorkspaceTweenType);
104 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); 104 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details));
105 window->layer()->SetTransform(ui::Transform()); 105 window->layer()->SetTransform(gfx::Transform());
106 window->layer()->SetOpacity(1.0f); 106 window->layer()->SetOpacity(1.0f);
107 } 107 }
108 } 108 }
109 109
110 void HideWorkspace(aura::Window* window, 110 void HideWorkspace(aura::Window* window,
111 const WorkspaceAnimationDetails& details) { 111 const WorkspaceAnimationDetails& details) {
112 window->layer()->SetTransform(ui::Transform()); 112 window->layer()->SetTransform(gfx::Transform());
113 window->layer()->SetOpacity(1.0f); 113 window->layer()->SetOpacity(1.0f);
114 window->layer()->GetAnimator()->StopAnimating(); 114 window->layer()->GetAnimator()->StopAnimating();
115 115
116 if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch( 116 if (!details.animate || CommandLine::ForCurrentProcess()->HasSwitch(
117 ash::switches::kAshWindowAnimationsDisabled)) { 117 ash::switches::kAshWindowAnimationsDisabled)) {
118 window->Hide(); 118 window->Hide();
119 return; 119 return;
120 } 120 }
121 121
122 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); 122 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator());
123 if (details.pause_time_ms > 0) { 123 if (details.pause_time_ms > 0) {
124 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 124 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
125 window->layer()->GetAnimator()->SchedulePauseForProperties( 125 window->layer()->GetAnimator()->SchedulePauseForProperties(
126 base::TimeDelta::FromMilliseconds(details.pause_time_ms), 126 base::TimeDelta::FromMilliseconds(details.pause_time_ms),
127 ui::LayerAnimationElement::TRANSFORM, 127 ui::LayerAnimationElement::TRANSFORM,
128 ui::LayerAnimationElement::OPACITY, 128 ui::LayerAnimationElement::OPACITY,
129 ui::LayerAnimationElement::BRIGHTNESS, 129 ui::LayerAnimationElement::BRIGHTNESS,
130 ui::LayerAnimationElement::VISIBILITY, 130 ui::LayerAnimationElement::VISIBILITY,
131 -1); 131 -1);
132 } 132 }
133 133
134 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details)); 134 settings.SetTransitionDuration(DurationForWorkspaceShowOrHide(details));
135 settings.SetTweenType(kWorkspaceTweenType); 135 settings.SetTweenType(kWorkspaceTweenType);
136 if (details.animate_scale) { 136 if (details.animate_scale) {
137 ApplyWorkspaceScale(window->layer(), 137 ApplyWorkspaceScale(window->layer(),
138 details.direction == WORKSPACE_ANIMATE_UP ? 138 details.direction == WORKSPACE_ANIMATE_UP ?
139 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW); 139 WORKSPACE_SCALE_ABOVE : WORKSPACE_SCALE_BELOW);
140 } else { 140 } else {
141 window->layer()->SetTransform(ui::Transform()); 141 window->layer()->SetTransform(gfx::Transform());
142 } 142 }
143 143
144 // NOTE: Hide() must be before SetOpacity(), else 144 // NOTE: Hide() must be before SetOpacity(), else
145 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the 145 // VisibilityController::UpdateLayerVisibility doesn't pass the false to the
146 // layer so that the layer and window end up out of sync and confused. 146 // layer so that the layer and window end up out of sync and confused.
147 window->Hide(); 147 window->Hide();
148 148
149 if (details.animate_opacity) 149 if (details.animate_opacity)
150 window->layer()->SetOpacity(0.0f); 150 window->layer()->SetOpacity(0.0f);
151 151
152 // After the animation completes snap the transform back to the identity, 152 // After the animation completes snap the transform back to the identity,
153 // otherwise any one that asks for screen bounds gets a slightly scaled 153 // otherwise any one that asks for screen bounds gets a slightly scaled
154 // version. 154 // version.
155 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION); 155 settings.SetPreemptionStrategy(ui::LayerAnimator::ENQUEUE_NEW_ANIMATION);
156 settings.SetTransitionDuration(base::TimeDelta()); 156 settings.SetTransitionDuration(base::TimeDelta());
157 window->layer()->SetTransform(ui::Transform()); 157 window->layer()->SetTransform(gfx::Transform());
158 } 158 }
159 159
160 } // namespace internal 160 } // namespace internal
161 } // namespace ash 161 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_manager_unittest.cc ('k') | chrome/browser/chromeos/login/base_login_display_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698