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 "ash/wm/workspace/workspace_cycler_animator.h" | 5 #include "ash/wm/workspace/workspace_cycler_animator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
12 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
14 #include "ash/wm/property_util.h" | 14 #include "ash/wm/property_util.h" |
15 #include "ash/wm/shelf_layout_manager.h" | 15 #include "ash/wm/shelf_layout_manager.h" |
16 #include "ash/wm/workspace/colored_window_controller.h" | 16 #include "ash/wm/workspace/colored_window_controller.h" |
17 #include "ash/wm/workspace/workspace.h" | 17 #include "ash/wm/workspace/workspace.h" |
| 18 #include "ash/wm/workspace/workspace_cycler_configuration.h" |
| 19 #include "base/values.h" |
18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
19 #include "ui/base/events/event_utils.h" | 21 #include "ui/base/events/event_utils.h" |
20 #include "ui/compositor/layer_animator.h" | 22 #include "ui/compositor/layer_animator.h" |
21 #include "ui/compositor/scoped_layer_animation_settings.h" | 23 #include "ui/compositor/scoped_layer_animation_settings.h" |
22 #include "ui/gfx/transform_util.h" | 24 #include "ui/gfx/transform_util.h" |
23 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
24 | 26 |
25 namespace { | 27 typedef ash::WorkspaceCyclerConfiguration Config; |
26 | |
27 // The maximum number of visible workspaces deeper than the selected workspace. | |
28 const int kMinVisibleOffsetFromSelected = -2; | |
29 | |
30 // The maximum number of visible workspaces shallower than the selected | |
31 // workspace. | |
32 const int kMaxVisibleOffsetFromSelected = 3; | |
33 | |
34 // The scale of the selected workspace when it is completely selected. | |
35 const double kSelectedWorkspaceScale = 0.95; | |
36 | |
37 // The minimum scale for workspaces in the top stack. The scales of the | |
38 // workspaces in the top stack decrease as you go deeper into the stack. | |
39 const double kMinTopStackScale = 0.9; | |
40 | |
41 // The maximum scale for workspaces in the bottom stack. The scales of the | |
42 // workspaces in the bottom stack increase as you go up the stack. | |
43 const double kMaxBottomStackScale = 1.0; | |
44 | |
45 // The minimum workspace brightness. | |
46 const float kMinBrightness = -0.4f; | |
47 | |
48 // The required vertical scroll amount to cycle to the next / previous | |
49 // workspace. | |
50 const double kScrollAmountToCycleToNextWorkspace = 10; | |
51 | |
52 // The ratio of the duration of the animation to the amount that the user has | |
53 // scrolled. | |
54 // The duration of an animation is computed by: | |
55 // distance scrolled * |kCyclerStepAnimationDurationRatio|. | |
56 const double kCyclerStepAnimationDurationRatio = 10; | |
57 | |
58 // The duration of the animations when animating starting the cycler. | |
59 const int kStartCyclerAnimationDuration = 100; | |
60 | |
61 // The duration of the animations when animating stopping the cycler. | |
62 const int kStopCyclerAnimationDuration = 100; | |
63 | |
64 // The background opacity. | |
65 const float kBackgroundOpacity = .8f; | |
66 | |
67 } // namespace | |
68 | 28 |
69 namespace ash { | 29 namespace ash { |
70 namespace internal { | 30 namespace internal { |
71 | 31 |
72 // Class which computes the transform, brightness, and visbility of workspaces | 32 // Class which computes the transform, brightness, and visbility of workspaces |
73 // on behalf of the animator. | 33 // on behalf of the animator. |
74 class StyleCalculator { | 34 class StyleCalculator { |
75 public: | 35 public: |
76 StyleCalculator(const gfx::Rect& screen_bounds, | 36 StyleCalculator(const gfx::Rect& screen_bounds, |
77 const gfx::Rect& maximized_bounds, | 37 const gfx::Rect& maximized_bounds, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // |offset_from_selected| from the selected workspace. | 83 // |offset_from_selected| from the selected workspace. |
124 // This method assumes |scroll_delta| == 0. | 84 // This method assumes |scroll_delta| == 0. |
125 float GetTargetBrightnessForOffset(int offset_from_selected) const; | 85 float GetTargetBrightnessForOffset(int offset_from_selected) const; |
126 | 86 |
127 // Returns the target animation visibility of the workspace with the given | 87 // Returns the target animation visibility of the workspace with the given |
128 // parameters. | 88 // parameters. |
129 // This method assumes |scroll_delta| == 0. | 89 // This method assumes |scroll_delta| == 0. |
130 bool GetTargetVisibilityForOffset(int offset_from_selected, | 90 bool GetTargetVisibilityForOffset(int offset_from_selected, |
131 size_t workspace_index) const; | 91 size_t workspace_index) const; |
132 | 92 |
| 93 // Returns the minimum offset from the selected workspace at which a |
| 94 // workspace can be visible. The offset is used to limit the amount of |
| 95 // workspaces which are simultaneously visible. |
| 96 int GetMinVisibleOffsetFromSelected() const; |
| 97 |
| 98 // Returns the maximum offset from the selected workspace at which a |
| 99 // workspace can be visible. The offset is used to limit the amount of |
| 100 // workspaces which are simultaneously visible. |
| 101 int GetMaxVisibleOffsetFromSelected() const; |
| 102 |
133 // The bounds of the display containing the workspaces in workspace | 103 // The bounds of the display containing the workspaces in workspace |
134 // coordinates, including the shelf if any. | 104 // coordinates, including the shelf if any. |
135 const gfx::Rect screen_bounds_; | 105 const gfx::Rect screen_bounds_; |
136 | 106 |
137 // The bounds of a maximized window. This excludes the shelf if any. | 107 // The bounds of a maximized window. This excludes the shelf if any. |
138 const gfx::Rect maximized_bounds_; | 108 const gfx::Rect maximized_bounds_; |
139 | 109 |
140 // The combined number of visible and hidden workspaces. | 110 // The combined number of visible and hidden workspaces. |
141 size_t num_workspaces_; | 111 size_t num_workspaces_; |
142 | 112 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (scroll_delta < 0) { | 164 if (scroll_delta < 0) { |
195 // The user is part of the way to selecting the workspace at | 165 // The user is part of the way to selecting the workspace at |
196 // |selected_workspace_index| - 1 -> |offset_from_selected| + 1. | 166 // |selected_workspace_index| - 1 -> |offset_from_selected| + 1. |
197 second_offset_from_selected = offset_from_selected + 1; | 167 second_offset_from_selected = offset_from_selected + 1; |
198 } else if (scroll_delta > 0) { | 168 } else if (scroll_delta > 0) { |
199 // The user is part of the way to selecting the workspace at | 169 // The user is part of the way to selecting the workspace at |
200 // |selected_workspace_index| + 1 -> |offset_from_selected| - 1. | 170 // |selected_workspace_index| + 1 -> |offset_from_selected| - 1. |
201 second_offset_from_selected = offset_from_selected - 1; | 171 second_offset_from_selected = offset_from_selected - 1; |
202 } | 172 } |
203 | 173 |
204 double progress = fabs(scroll_delta / kScrollAmountToCycleToNextWorkspace); | 174 int scroll_distance_to_cycle_to_next_workspace = Config::GetDouble( |
| 175 Config::SCROLL_DISTANCE_TO_CYCLE_TO_NEXT_WORKSPACE); |
| 176 double progress = fabs( |
| 177 scroll_delta / scroll_distance_to_cycle_to_next_workspace); |
205 DCHECK_GT(1.0, progress); | 178 DCHECK_GT(1.0, progress); |
206 | 179 |
207 if (transform) { | 180 if (transform) { |
208 gfx::DecomposedTransform first_transform = GetTargetTransformForOffset( | 181 gfx::DecomposedTransform first_transform = GetTargetTransformForOffset( |
209 first_offset_from_selected); | 182 first_offset_from_selected); |
210 | 183 |
211 gfx::DecomposedTransform interpolated_transform; | 184 gfx::DecomposedTransform interpolated_transform; |
212 if (first_offset_from_selected == second_offset_from_selected) { | 185 if (first_offset_from_selected == second_offset_from_selected) { |
213 interpolated_transform = first_transform; | 186 interpolated_transform = first_transform; |
214 } else { | 187 } else { |
(...skipping 29 matching lines...) Expand all Loading... |
244 int offset_from_selected) const { | 217 int offset_from_selected) const { |
245 if (offset_from_selected <= 0) { | 218 if (offset_from_selected <= 0) { |
246 // The selected workspace takes up the entire screen. The workspaces deeper | 219 // The selected workspace takes up the entire screen. The workspaces deeper |
247 // than the selected workspace are stacked exactly under the selected | 220 // than the selected workspace are stacked exactly under the selected |
248 // workspace and are completely occluded by it. | 221 // workspace and are completely occluded by it. |
249 return gfx::Transform(); | 222 return gfx::Transform(); |
250 } | 223 } |
251 | 224 |
252 // The workspaces shallower than the selected workspace are stacked exactly | 225 // The workspaces shallower than the selected workspace are stacked exactly |
253 // on top of each other offscreen. | 226 // on top of each other offscreen. |
| 227 double max_scale = Config::GetDouble(Config::MAX_SCALE); |
| 228 |
254 gfx::Transform transform; | 229 gfx::Transform transform; |
255 transform.Translate(0, screen_bounds_.height()); | 230 transform.Translate(0, screen_bounds_.height()); |
256 transform.Scale(kMaxBottomStackScale, kMaxBottomStackScale); | 231 transform.Scale(max_scale, max_scale); |
257 return transform; | 232 return transform; |
258 } | 233 } |
259 | 234 |
260 gfx::DecomposedTransform StyleCalculator::GetTargetTransformForOffset( | 235 gfx::DecomposedTransform StyleCalculator::GetTargetTransformForOffset( |
261 int offset_from_selected) const { | 236 int offset_from_selected) const { |
262 // When cycling, the workspaces are spread out from the positions computed by | 237 // When cycling, the workspaces are spread out from the positions computed by |
263 // GetStoppedTargetTransformForOffset(). The transforms are computed so that | 238 // GetStoppedTargetTransformForOffset(). The transforms are computed so that |
264 // on screen the workspaces look like this: | 239 // on screen the workspaces look like this: |
265 // ____________________________________________ | 240 // ____________________________________________ |
266 // | ________________________ | | 241 // | ________________________ | |
267 // | | deepest workpace |_________|_ | 242 // | | deepest workpace |_________|_ |
268 // | _|________________________|_ | | | 243 // | _|________________________|_ | | |
269 // | | | | | | 244 // | | | | | |
270 // | _|____________________________|_ | |_ top stack. | 245 // | _|____________________________|_ | |_ top stack. |
271 // | | selected / shallowest workspace| | | | 246 // | | selected / shallowest workspace| | | |
272 // | | | | | | 247 // | | | | | |
273 // | | |_____|_| | 248 // | | |_____|_| |
274 // | | | | | 249 // | | | | |
275 // | | | | | 250 // | | | | |
276 // | _|________________________________|_ | | 251 // | _|________________________________|_ | |
277 // | | deepest workspace |___|_ | 252 // | | deepest workspace |___|_ |
278 // | _|____________________________________|_ | |_ bottom stack. | 253 // | _|____________________________________|_ | |_ bottom stack. |
279 // | | shallowest workspace |_|_| | 254 // | | shallowest workspace |_|_| |
280 // |_|________________________________________|_| | 255 // |_|________________________________________|_| |
281 // The selected workspace is the most visible workspace. It is the workspace | 256 // The selected workspace is the most visible workspace. It is the workspace |
282 // which will be activated if the user does not do any more cycling. | 257 // which will be activated if the user does not do any more cycling. |
283 bool in_top_stack = (offset_from_selected <= 0); | 258 bool in_top_stack = (offset_from_selected <= 0); |
284 | 259 |
285 // Give workspaces with offsets below |kMinVisibleOffsetFromSelected| the | 260 int min_visible_offset_from_selected = GetMinVisibleOffsetFromSelected(); |
286 // same transform as the workspace at |kMinVisibleOffsetFromSelected|. As | 261 int max_visible_offset_from_selected = GetMaxVisibleOffsetFromSelected(); |
287 // the workspace at |kMinVisibleOffsetFromSelected| completely occludes | |
288 // these extra workspaces, they can be hidden. | |
289 // |kMaxVisibleOffsetFromSelected| is dealt with similarly. | |
290 if (offset_from_selected < kMinVisibleOffsetFromSelected) | |
291 offset_from_selected = kMinVisibleOffsetFromSelected; | |
292 else if (offset_from_selected > kMaxVisibleOffsetFromSelected) | |
293 offset_from_selected = kMaxVisibleOffsetFromSelected; | |
294 | 262 |
295 double scale = kSelectedWorkspaceScale; | 263 // Give workspaces at hidden offsets the transform of the workspace at the |
| 264 // nearest visible offset. This is needed to produce a valid result when |
| 265 // interpolating between the values of GetTargetTransformForOffset() for a |
| 266 // visible and hidden offset. |
| 267 if (offset_from_selected < min_visible_offset_from_selected) |
| 268 offset_from_selected = min_visible_offset_from_selected; |
| 269 else if (offset_from_selected > max_visible_offset_from_selected) |
| 270 offset_from_selected = max_visible_offset_from_selected; |
| 271 |
| 272 double selected_scale = Config::GetDouble(Config::SELECTED_SCALE); |
| 273 |
| 274 double scale = selected_scale; |
296 if (in_top_stack) { | 275 if (in_top_stack) { |
| 276 double min_scale = Config::GetDouble(Config::MIN_SCALE); |
297 scale -= static_cast<double>(offset_from_selected) / | 277 scale -= static_cast<double>(offset_from_selected) / |
298 kMinVisibleOffsetFromSelected * | 278 min_visible_offset_from_selected * (selected_scale - min_scale); |
299 (kSelectedWorkspaceScale - kMinTopStackScale); | |
300 } else { | 279 } else { |
| 280 double max_scale = Config::GetDouble(Config::MAX_SCALE); |
301 scale += static_cast<double>(offset_from_selected) / | 281 scale += static_cast<double>(offset_from_selected) / |
302 kMaxVisibleOffsetFromSelected * | 282 max_visible_offset_from_selected * (max_scale - selected_scale); |
303 (kMaxBottomStackScale - kSelectedWorkspaceScale); | |
304 } | 283 } |
305 | 284 |
306 // Compute the workspace's y offset. As abs(|offset_from_selected|) increases, | 285 // Compute the workspace's y offset. |
307 // the amount of the top of the workspace which is visible from beneath the | |
308 // shallower workspaces decreases exponentially. | |
309 double y_offset = 0; | 286 double y_offset = 0; |
310 if (in_top_stack) { | 287 if (offset_from_selected == 0) { |
311 const double kTopStackYOffsets[-kMinVisibleOffsetFromSelected + 1] = | 288 y_offset = Config::GetDouble(Config::SELECTED_Y_OFFSET); |
312 { 40, 28, 20 }; | |
313 y_offset = kTopStackYOffsets[ | |
314 static_cast<size_t>(std::abs(offset_from_selected))]; | |
315 } else { | 289 } else { |
316 const double kBottomStackYOffsets[kMaxVisibleOffsetFromSelected] = | 290 const base::ListValue* y_offsets = NULL; |
317 { -40, -32, -20 }; | 291 if (in_top_stack) { |
318 y_offset = maximized_bounds_.height() + | 292 y_offsets = Config::GetListValue(Config::DEEPER_THAN_SELECTED_Y_OFFSETS); |
319 kBottomStackYOffsets[static_cast<size_t>(offset_from_selected - 1)]; | 293 } else { |
| 294 y_offsets = Config::GetListValue( |
| 295 Config::SHALLOWER_THAN_SELECTED_Y_OFFSETS); |
| 296 y_offset = maximized_bounds_.height(); |
| 297 } |
| 298 size_t y_offset_index = static_cast<size_t>( |
| 299 std::abs(offset_from_selected) - 1); |
| 300 DCHECK(y_offsets); |
| 301 DCHECK_GT(y_offsets->GetSize(), y_offset_index); |
| 302 double y_offset_config_value = 0; |
| 303 y_offsets->GetDouble(y_offset_index, &y_offset_config_value); |
| 304 y_offset += y_offset_config_value; |
320 } | 305 } |
321 | 306 |
322 // Center the workspace horizontally. | 307 // Center the workspace horizontally. |
323 double x_offset = maximized_bounds_.width() * (1 - scale) / 2; | 308 double x_offset = maximized_bounds_.width() * (1 - scale) / 2; |
324 | 309 |
325 gfx::DecomposedTransform transform; | 310 gfx::DecomposedTransform transform; |
326 transform.translate[0] = x_offset; | 311 transform.translate[0] = x_offset; |
327 transform.translate[1] = y_offset; | 312 transform.translate[1] = y_offset; |
328 transform.scale[0] = scale; | 313 transform.scale[0] = scale; |
329 transform.scale[1] = scale; | 314 transform.scale[1] = scale; |
330 return transform; | 315 return transform; |
331 } | 316 } |
332 | 317 |
333 float StyleCalculator::GetTargetBrightnessForOffset( | 318 float StyleCalculator::GetTargetBrightnessForOffset( |
334 int offset_from_selected) const { | 319 int offset_from_selected) const { |
335 int max_visible_distance_from_selected = std::max( | 320 int max_visible_distance_from_selected = std::max( |
336 std::abs(kMinVisibleOffsetFromSelected), kMaxVisibleOffsetFromSelected); | 321 std::abs(GetMinVisibleOffsetFromSelected()), |
337 return kMinBrightness * std::min( | 322 GetMaxVisibleOffsetFromSelected()); |
| 323 return Config::GetDouble(Config::MIN_BRIGHTNESS) * std::min( |
338 1.0, | 324 1.0, |
339 static_cast<double>(std::abs(offset_from_selected)) / | 325 static_cast<double>(std::abs(offset_from_selected)) / |
340 max_visible_distance_from_selected); | 326 max_visible_distance_from_selected); |
341 } | 327 } |
342 | 328 |
343 bool StyleCalculator::GetTargetVisibilityForOffset( | 329 bool StyleCalculator::GetTargetVisibilityForOffset( |
344 int offset_from_selected, | 330 int offset_from_selected, |
345 size_t workspace_index) const { | 331 size_t workspace_index) const { |
346 // The workspace at the highest possible index is the shallowest workspace | 332 // The workspace at the highest possible index is the shallowest workspace |
347 // out of both stacks and is always visible. | 333 // out of both stacks and is always visible. |
348 // The workspace at |kMaxVisibleWorkspaceFromSelected| is hidden because | 334 // The workspace at |GetMaxVisibleOffsetFromSelected()| is hidden because it |
349 // it has the same transform as the shallowest workspace and is completely | 335 // has the same transform as the shallowest workspace and is completely |
350 // occluded by it. | 336 // occluded by it. |
351 if (workspace_index == num_workspaces_ - 1) | 337 if (workspace_index == num_workspaces_ - 1) |
352 return true; | 338 return true; |
353 | 339 |
354 return offset_from_selected >= kMinVisibleOffsetFromSelected && | 340 return offset_from_selected >= GetMinVisibleOffsetFromSelected() && |
355 offset_from_selected < kMaxVisibleOffsetFromSelected; | 341 offset_from_selected < GetMaxVisibleOffsetFromSelected(); |
| 342 } |
| 343 |
| 344 int StyleCalculator::GetMinVisibleOffsetFromSelected() const { |
| 345 const base::ListValue* y_offsets = Config::GetListValue( |
| 346 Config::DEEPER_THAN_SELECTED_Y_OFFSETS); |
| 347 DCHECK(y_offsets); |
| 348 // Hide workspaces for which there is no y offset specified. |
| 349 return -y_offsets->GetSize(); |
| 350 } |
| 351 |
| 352 int StyleCalculator::GetMaxVisibleOffsetFromSelected() const { |
| 353 const base::ListValue* y_offsets = Config::GetListValue( |
| 354 Config::SHALLOWER_THAN_SELECTED_Y_OFFSETS); |
| 355 DCHECK(y_offsets); |
| 356 // Hide workspaces for which there is no y offset specified. |
| 357 return y_offsets->GetSize(); |
356 } | 358 } |
357 | 359 |
358 WorkspaceCyclerAnimator::WorkspaceCyclerAnimator(Delegate* delegate) | 360 WorkspaceCyclerAnimator::WorkspaceCyclerAnimator(Delegate* delegate) |
359 : delegate_(delegate), | 361 : delegate_(delegate), |
360 initial_active_workspace_index_(0), | 362 initial_active_workspace_index_(0), |
361 selected_workspace_index_(0), | 363 selected_workspace_index_(0), |
362 scroll_delta_(0), | 364 scroll_delta_(0), |
363 animation_type_(NONE), | 365 animation_type_(NONE), |
364 launcher_background_controller_(NULL), | 366 launcher_background_controller_(NULL), |
365 style_calculator_(NULL) { | 367 style_calculator_(NULL) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 ui::Layer* layer = window->layer(); | 408 ui::Layer* layer = window->layer(); |
407 | 409 |
408 gfx::Transform transform; | 410 gfx::Transform transform; |
409 float brightness = 0.0f; | 411 float brightness = 0.0f; |
410 style_calculator_->GetStoppedTargetProperties(selected_workspace_index_, i, | 412 style_calculator_->GetStoppedTargetProperties(selected_workspace_index_, i, |
411 &transform, &brightness, NULL); | 413 &transform, &brightness, NULL); |
412 layer->SetTransform(transform); | 414 layer->SetTransform(transform); |
413 layer->SetLayerBrightness(brightness); | 415 layer->SetLayerBrightness(brightness); |
414 } | 416 } |
415 | 417 |
| 418 int start_cycler_animation_duration = static_cast<int>(Config::GetDouble( |
| 419 Config::START_CYCLER_ANIMATION_DURATION)); |
| 420 |
416 scroll_delta_ = 0; | 421 scroll_delta_ = 0; |
417 animation_type_ = CYCLER_START; | 422 animation_type_ = CYCLER_START; |
418 AnimateToUpdatedState(kStartCyclerAnimationDuration); | 423 AnimateToUpdatedState(start_cycler_animation_duration); |
419 | 424 |
420 aura::Window* background = GetDesktopBackground(); | 425 aura::Window* background = GetDesktopBackground(); |
421 if (background) { | 426 if (background) { |
422 ui::Layer* layer = background->layer(); | 427 ui::Layer* layer = background->layer(); |
423 | 428 |
424 if (!background->IsVisible()) { | 429 if (!background->IsVisible()) { |
425 background->Show(); | 430 background->Show(); |
426 layer->SetOpacity(0.0f); | 431 layer->SetOpacity(0.0f); |
427 } | 432 } |
428 | 433 |
429 { | 434 { |
430 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 435 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
431 settings.SetPreemptionStrategy( | 436 settings.SetPreemptionStrategy( |
432 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 437 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
433 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 438 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
434 kStartCyclerAnimationDuration)); | 439 start_cycler_animation_duration)); |
435 | 440 |
436 layer->SetOpacity(kBackgroundOpacity); | 441 layer->SetOpacity(Config::GetDouble(Config::BACKGROUND_OPACITY)); |
437 } | 442 } |
438 } | 443 } |
439 | 444 |
440 // Create a window to simulate a fully opaque launcher. This prevents | 445 // Create a window to simulate a fully opaque launcher. This prevents |
441 // workspaces from showing from behind the launcher. | 446 // workspaces from showing from behind the launcher. |
442 CreateLauncherBackground(); | 447 CreateLauncherBackground(); |
443 } | 448 } |
444 | 449 |
445 void WorkspaceCyclerAnimator::AnimateStoppingCycler() { | 450 void WorkspaceCyclerAnimator::AnimateStoppingCycler() { |
446 if (scroll_delta_ != 0) { | 451 if (scroll_delta_ != 0) { |
447 // Completely select the workspace at |selected_workspace_index_|. | 452 // Completely select the workspace at |selected_workspace_index_|. |
448 int animation_duration = GetAnimationDurationForChangeInScrollDelta( | 453 int animation_duration = GetAnimationDurationForChangeInScrollDelta( |
449 -scroll_delta_); | 454 -scroll_delta_); |
450 scroll_delta_ = 0; | 455 scroll_delta_ = 0; |
451 animation_type_ = CYCLER_COMPLETELY_SELECT; | 456 animation_type_ = CYCLER_COMPLETELY_SELECT; |
452 AnimateToUpdatedState(animation_duration); | 457 AnimateToUpdatedState(animation_duration); |
453 return; | 458 return; |
454 } | 459 } |
455 | 460 |
| 461 int stop_cycler_animation_duration = static_cast<int>(Config::GetDouble( |
| 462 Config::STOP_CYCLER_ANIMATION_DURATION)); |
| 463 |
456 animation_type_ = CYCLER_END; | 464 animation_type_ = CYCLER_END; |
457 AnimateToUpdatedState(kStopCyclerAnimationDuration); | 465 AnimateToUpdatedState(stop_cycler_animation_duration); |
458 | 466 |
459 aura::Window* background = GetDesktopBackground(); | 467 aura::Window* background = GetDesktopBackground(); |
460 if (background) { | 468 if (background) { |
461 ui::Layer* layer = background->layer(); | 469 ui::Layer* layer = background->layer(); |
462 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 470 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
463 settings.SetPreemptionStrategy( | 471 settings.SetPreemptionStrategy( |
464 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 472 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
465 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 473 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
466 kStopCyclerAnimationDuration)); | 474 stop_cycler_animation_duration)); |
467 | 475 |
468 layer->SetOpacity((selected_workspace_index_ == 0) ? 1.0f : 0.0f); | 476 layer->SetOpacity((selected_workspace_index_ == 0) ? 1.0f : 0.0f); |
469 } | 477 } |
470 } | 478 } |
471 | 479 |
472 void WorkspaceCyclerAnimator::AbortAnimations() { | 480 void WorkspaceCyclerAnimator::AbortAnimations() { |
473 StopObservingImplicitAnimations(); | 481 StopObservingImplicitAnimations(); |
474 animation_type_ = NONE; | 482 animation_type_ = NONE; |
475 CyclerStopped(initial_active_workspace_index_); | 483 CyclerStopped(initial_active_workspace_index_); |
476 } | 484 } |
477 | 485 |
478 void WorkspaceCyclerAnimator::AnimateCyclingByScrollDelta(float scroll_delta) { | 486 void WorkspaceCyclerAnimator::AnimateCyclingByScrollDelta(double scroll_delta) { |
479 if (scroll_delta == 0.0f) | 487 if (scroll_delta == 0) |
480 return; | 488 return; |
481 | 489 |
482 // Drop any updates received while an animation is running. | 490 // Drop any updates received while an animation is running. |
483 // TODO(pkotwicz): Do something better. | 491 // TODO(pkotwicz): Do something better. |
484 if (animation_type_ != NONE) | 492 if (animation_type_ != NONE) |
485 return; | 493 return; |
486 | 494 |
487 if (ui::IsNaturalScrollEnabled()) | 495 if (ui::IsNaturalScrollEnabled()) |
488 scroll_delta *= -1; | 496 scroll_delta *= -1; |
489 | 497 |
490 double old_scroll_delta = scroll_delta_; | 498 double old_scroll_delta = scroll_delta_; |
491 scroll_delta_ += scroll_delta; | 499 scroll_delta_ += scroll_delta; |
492 | 500 |
| 501 int scroll_distance_to_cycle_to_next_workspace = Config::GetDouble( |
| 502 Config::SCROLL_DISTANCE_TO_CYCLE_TO_NEXT_WORKSPACE); |
| 503 |
493 double min_scroll_delta = -1 * | 504 double min_scroll_delta = -1 * |
494 static_cast<double>(selected_workspace_index_) * | 505 static_cast<double>(selected_workspace_index_) * |
495 kScrollAmountToCycleToNextWorkspace; | 506 scroll_distance_to_cycle_to_next_workspace; |
496 double max_scroll_delta = static_cast<double>( | 507 double max_scroll_delta = static_cast<double>( |
497 workspaces_.size() - 1 - selected_workspace_index_) * | 508 workspaces_.size() - 1 - selected_workspace_index_) * |
498 kScrollAmountToCycleToNextWorkspace; | 509 scroll_distance_to_cycle_to_next_workspace; |
499 | 510 |
500 if (scroll_delta_ < min_scroll_delta) | 511 if (scroll_delta_ < min_scroll_delta) |
501 scroll_delta_ = min_scroll_delta; | 512 scroll_delta_ = min_scroll_delta; |
502 else if (scroll_delta_ > max_scroll_delta) | 513 else if (scroll_delta_ > max_scroll_delta) |
503 scroll_delta_ = max_scroll_delta; | 514 scroll_delta_ = max_scroll_delta; |
504 | 515 |
505 if (scroll_delta_ == old_scroll_delta) | 516 if (scroll_delta_ == old_scroll_delta) |
506 return; | 517 return; |
507 | 518 |
508 // Set the selected workspace to the workspace that the user is closest to | 519 // Set the selected workspace to the workspace that the user is closest to |
509 // selecting completely. A workspace is completely selected when the user | 520 // selecting completely. A workspace is completely selected when the user |
510 // has scrolled the exact amount to select the workspace with no undershoot / | 521 // has scrolled the exact amount to select the workspace with no undershoot / |
511 // overshoot. | 522 // overshoot. |
512 int workspace_change = floor(scroll_delta_ / | 523 int workspace_change = floor(scroll_delta_ / |
513 kScrollAmountToCycleToNextWorkspace + .5); | 524 scroll_distance_to_cycle_to_next_workspace + .5); |
514 selected_workspace_index_ += workspace_change; | 525 selected_workspace_index_ += workspace_change; |
515 | 526 |
516 // Set |scroll_delta_| to the amount of undershoot / overshoot. | 527 // Set |scroll_delta_| to the amount of undershoot / overshoot. |
517 scroll_delta_ -= workspace_change * kScrollAmountToCycleToNextWorkspace; | 528 scroll_delta_ -= workspace_change * |
| 529 scroll_distance_to_cycle_to_next_workspace; |
518 | 530 |
519 int animation_duration = GetAnimationDurationForChangeInScrollDelta( | 531 int animation_duration = GetAnimationDurationForChangeInScrollDelta( |
520 scroll_delta_ - old_scroll_delta); | 532 scroll_delta_ - old_scroll_delta); |
521 | 533 |
522 animation_type_ = CYCLER_UPDATE; | 534 animation_type_ = CYCLER_UPDATE; |
523 AnimateToUpdatedState(animation_duration); | 535 AnimateToUpdatedState(animation_duration); |
524 } | 536 } |
525 | 537 |
526 void WorkspaceCyclerAnimator::AnimateToUpdatedState(int animation_duration) { | 538 void WorkspaceCyclerAnimator::AnimateToUpdatedState(int animation_duration) { |
527 DCHECK_NE(NONE, animation_type_); | 539 DCHECK_NE(NONE, animation_type_); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } else { | 641 } else { |
630 window->Hide(); | 642 window->Hide(); |
631 } | 643 } |
632 | 644 |
633 layer->SetTransform(target_transform); | 645 layer->SetTransform(target_transform); |
634 layer->SetLayerBrightness(target_brightness); | 646 layer->SetLayerBrightness(target_brightness); |
635 } | 647 } |
636 | 648 |
637 int WorkspaceCyclerAnimator::GetAnimationDurationForChangeInScrollDelta( | 649 int WorkspaceCyclerAnimator::GetAnimationDurationForChangeInScrollDelta( |
638 double change) const { | 650 double change) const { |
639 return static_cast<int>( | 651 double ratio = Config::GetDouble( |
640 fabs(change) * kCyclerStepAnimationDurationRatio); | 652 Config::CYCLER_STEP_ANIMATION_DURATION_RATIO); |
| 653 return static_cast<int>(fabs(change) * ratio); |
641 } | 654 } |
642 | 655 |
643 void WorkspaceCyclerAnimator::CreateLauncherBackground() { | 656 void WorkspaceCyclerAnimator::CreateLauncherBackground() { |
644 if (screen_bounds_ == maximized_bounds_) | 657 if (screen_bounds_ == maximized_bounds_) |
645 return; | 658 return; |
646 | 659 |
647 aura::Window* random_workspace_window = workspaces_[0]->window(); | 660 aura::Window* random_workspace_window = workspaces_[0]->window(); |
648 ash::Launcher* launcher = ash::Launcher::ForWindow(random_workspace_window); | 661 ash::Launcher* launcher = ash::Launcher::ForWindow(random_workspace_window); |
649 aura::Window* launcher_window = launcher->widget()->GetNativeWindow(); | 662 aura::Window* launcher_window = launcher->widget()->GetNativeWindow(); |
650 | 663 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 MessageLoopForUI::current()->PostTask( | 714 MessageLoopForUI::current()->PostTask( |
702 FROM_HERE, | 715 FROM_HERE, |
703 base::Bind(&WorkspaceCyclerAnimator::NotifyDelegate, | 716 base::Bind(&WorkspaceCyclerAnimator::NotifyDelegate, |
704 AsWeakPtr(), | 717 AsWeakPtr(), |
705 completed_animation)); | 718 completed_animation)); |
706 } | 719 } |
707 } | 720 } |
708 | 721 |
709 } // namespace internal | 722 } // namespace internal |
710 } // namespace ash | 723 } // namespace ash |
OLD | NEW |