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 double 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 Config::Property y_offsets_property; |
317 { -40, -32, -20 }; | 291 if (in_top_stack) { |
318 y_offset = maximized_bounds_.height() + | 292 y_offsets_property = Config::DEEPER_THAN_SELECTED_Y_OFFSETS; |
319 kBottomStackYOffsets[static_cast<size_t>(offset_from_selected - 1)]; | 293 } else { |
| 294 y_offsets_property = Config::SHALLOWER_THAN_SELECTED_Y_OFFSETS; |
| 295 y_offset = maximized_bounds_.height(); |
| 296 } |
| 297 const base::ListValue& y_offsets = Config::GetListValue(y_offsets_property); |
| 298 size_t y_offset_index = static_cast<size_t>( |
| 299 std::abs(offset_from_selected) - 1); |
| 300 DCHECK_GT(y_offsets.GetSize(), y_offset_index); |
| 301 double y_offset_config_value = 0; |
| 302 y_offsets.GetDouble(y_offset_index, &y_offset_config_value); |
| 303 y_offset += y_offset_config_value; |
320 } | 304 } |
321 | 305 |
322 // Center the workspace horizontally. | 306 // Center the workspace horizontally. |
323 double x_offset = maximized_bounds_.width() * (1 - scale) / 2; | 307 double x_offset = maximized_bounds_.width() * (1 - scale) / 2; |
324 | 308 |
325 gfx::DecomposedTransform transform; | 309 gfx::DecomposedTransform transform; |
326 transform.translate[0] = x_offset; | 310 transform.translate[0] = x_offset; |
327 transform.translate[1] = y_offset; | 311 transform.translate[1] = y_offset; |
328 transform.scale[0] = scale; | 312 transform.scale[0] = scale; |
329 transform.scale[1] = scale; | 313 transform.scale[1] = scale; |
330 return transform; | 314 return transform; |
331 } | 315 } |
332 | 316 |
333 float StyleCalculator::GetTargetBrightnessForOffset( | 317 float StyleCalculator::GetTargetBrightnessForOffset( |
334 int offset_from_selected) const { | 318 int offset_from_selected) const { |
335 int max_visible_distance_from_selected = std::max( | 319 int max_visible_distance_from_selected = std::max( |
336 std::abs(kMinVisibleOffsetFromSelected), kMaxVisibleOffsetFromSelected); | 320 std::abs(GetMinVisibleOffsetFromSelected()), |
337 return kMinBrightness * std::min( | 321 GetMaxVisibleOffsetFromSelected()); |
| 322 return Config::GetDouble(Config::MIN_BRIGHTNESS) * std::min( |
338 1.0, | 323 1.0, |
339 static_cast<double>(std::abs(offset_from_selected)) / | 324 static_cast<double>(std::abs(offset_from_selected)) / |
340 max_visible_distance_from_selected); | 325 max_visible_distance_from_selected); |
341 } | 326 } |
342 | 327 |
343 bool StyleCalculator::GetTargetVisibilityForOffset( | 328 bool StyleCalculator::GetTargetVisibilityForOffset( |
344 int offset_from_selected, | 329 int offset_from_selected, |
345 size_t workspace_index) const { | 330 size_t workspace_index) const { |
346 // The workspace at the highest possible index is the shallowest workspace | 331 // The workspace at the highest possible index is the shallowest workspace |
347 // out of both stacks and is always visible. | 332 // out of both stacks and is always visible. |
348 // The workspace at |kMaxVisibleWorkspaceFromSelected| is hidden because | 333 // The workspace at |GetMaxVisibleOffsetFromSelected()| is hidden because it |
349 // it has the same transform as the shallowest workspace and is completely | 334 // has the same transform as the shallowest workspace and is completely |
350 // occluded by it. | 335 // occluded by it. |
351 if (workspace_index == num_workspaces_ - 1) | 336 if (workspace_index == num_workspaces_ - 1) |
352 return true; | 337 return true; |
353 | 338 |
354 return offset_from_selected >= kMinVisibleOffsetFromSelected && | 339 return offset_from_selected >= GetMinVisibleOffsetFromSelected() && |
355 offset_from_selected < kMaxVisibleOffsetFromSelected; | 340 offset_from_selected < GetMaxVisibleOffsetFromSelected(); |
| 341 } |
| 342 |
| 343 int StyleCalculator::GetMinVisibleOffsetFromSelected() const { |
| 344 const base::ListValue& y_offsets = Config::GetListValue( |
| 345 Config::DEEPER_THAN_SELECTED_Y_OFFSETS); |
| 346 // Hide workspaces for which there is no y offset specified. |
| 347 return -y_offsets.GetSize(); |
| 348 } |
| 349 |
| 350 int StyleCalculator::GetMaxVisibleOffsetFromSelected() const { |
| 351 const base::ListValue& y_offsets = Config::GetListValue( |
| 352 Config::SHALLOWER_THAN_SELECTED_Y_OFFSETS); |
| 353 // Hide workspaces for which there is no y offset specified. |
| 354 return y_offsets.GetSize(); |
356 } | 355 } |
357 | 356 |
358 WorkspaceCyclerAnimator::WorkspaceCyclerAnimator(Delegate* delegate) | 357 WorkspaceCyclerAnimator::WorkspaceCyclerAnimator(Delegate* delegate) |
359 : delegate_(delegate), | 358 : delegate_(delegate), |
360 initial_active_workspace_index_(0), | 359 initial_active_workspace_index_(0), |
361 selected_workspace_index_(0), | 360 selected_workspace_index_(0), |
362 scroll_delta_(0), | 361 scroll_delta_(0), |
363 animation_type_(NONE), | 362 animation_type_(NONE), |
364 launcher_background_controller_(NULL), | 363 launcher_background_controller_(NULL), |
365 style_calculator_(NULL) { | 364 style_calculator_(NULL) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 ui::Layer* layer = window->layer(); | 405 ui::Layer* layer = window->layer(); |
407 | 406 |
408 gfx::Transform transform; | 407 gfx::Transform transform; |
409 float brightness = 0.0f; | 408 float brightness = 0.0f; |
410 style_calculator_->GetStoppedTargetProperties(selected_workspace_index_, i, | 409 style_calculator_->GetStoppedTargetProperties(selected_workspace_index_, i, |
411 &transform, &brightness, NULL); | 410 &transform, &brightness, NULL); |
412 layer->SetTransform(transform); | 411 layer->SetTransform(transform); |
413 layer->SetLayerBrightness(brightness); | 412 layer->SetLayerBrightness(brightness); |
414 } | 413 } |
415 | 414 |
| 415 int start_cycler_animation_duration = static_cast<int>(Config::GetDouble( |
| 416 Config::START_CYCLER_ANIMATION_DURATION)); |
| 417 |
416 scroll_delta_ = 0; | 418 scroll_delta_ = 0; |
417 animation_type_ = CYCLER_START; | 419 animation_type_ = CYCLER_START; |
418 AnimateToUpdatedState(kStartCyclerAnimationDuration); | 420 AnimateToUpdatedState(start_cycler_animation_duration); |
419 | 421 |
420 aura::Window* background = GetDesktopBackground(); | 422 aura::Window* background = GetDesktopBackground(); |
421 if (background) { | 423 if (background) { |
422 ui::Layer* layer = background->layer(); | 424 ui::Layer* layer = background->layer(); |
423 | 425 |
424 if (!background->IsVisible()) { | 426 if (!background->IsVisible()) { |
425 background->Show(); | 427 background->Show(); |
426 layer->SetOpacity(0.0f); | 428 layer->SetOpacity(0.0f); |
427 } | 429 } |
428 | 430 |
429 { | 431 { |
430 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 432 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
431 settings.SetPreemptionStrategy( | 433 settings.SetPreemptionStrategy( |
432 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 434 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
433 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 435 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
434 kStartCyclerAnimationDuration)); | 436 start_cycler_animation_duration)); |
435 | 437 |
436 layer->SetOpacity(kBackgroundOpacity); | 438 layer->SetOpacity(Config::GetDouble(Config::BACKGROUND_OPACITY)); |
437 } | 439 } |
438 } | 440 } |
439 | 441 |
440 // Create a window to simulate a fully opaque launcher. This prevents | 442 // Create a window to simulate a fully opaque launcher. This prevents |
441 // workspaces from showing from behind the launcher. | 443 // workspaces from showing from behind the launcher. |
442 CreateLauncherBackground(); | 444 CreateLauncherBackground(); |
443 } | 445 } |
444 | 446 |
445 void WorkspaceCyclerAnimator::AnimateStoppingCycler() { | 447 void WorkspaceCyclerAnimator::AnimateStoppingCycler() { |
446 if (scroll_delta_ != 0) { | 448 if (scroll_delta_ != 0) { |
447 // Completely select the workspace at |selected_workspace_index_|. | 449 // Completely select the workspace at |selected_workspace_index_|. |
448 int animation_duration = GetAnimationDurationForChangeInScrollDelta( | 450 int animation_duration = GetAnimationDurationForChangeInScrollDelta( |
449 -scroll_delta_); | 451 -scroll_delta_); |
450 scroll_delta_ = 0; | 452 scroll_delta_ = 0; |
451 animation_type_ = CYCLER_COMPLETELY_SELECT; | 453 animation_type_ = CYCLER_COMPLETELY_SELECT; |
452 AnimateToUpdatedState(animation_duration); | 454 AnimateToUpdatedState(animation_duration); |
453 return; | 455 return; |
454 } | 456 } |
455 | 457 |
| 458 int stop_cycler_animation_duration = static_cast<int>(Config::GetDouble( |
| 459 Config::STOP_CYCLER_ANIMATION_DURATION)); |
| 460 |
456 animation_type_ = CYCLER_END; | 461 animation_type_ = CYCLER_END; |
457 AnimateToUpdatedState(kStopCyclerAnimationDuration); | 462 AnimateToUpdatedState(stop_cycler_animation_duration); |
458 | 463 |
459 aura::Window* background = GetDesktopBackground(); | 464 aura::Window* background = GetDesktopBackground(); |
460 if (background) { | 465 if (background) { |
461 ui::Layer* layer = background->layer(); | 466 ui::Layer* layer = background->layer(); |
462 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 467 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
463 settings.SetPreemptionStrategy( | 468 settings.SetPreemptionStrategy( |
464 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | 469 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
465 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | 470 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
466 kStopCyclerAnimationDuration)); | 471 stop_cycler_animation_duration)); |
467 | 472 |
468 layer->SetOpacity((selected_workspace_index_ == 0) ? 1.0f : 0.0f); | 473 layer->SetOpacity((selected_workspace_index_ == 0) ? 1.0f : 0.0f); |
469 } | 474 } |
470 } | 475 } |
471 | 476 |
472 void WorkspaceCyclerAnimator::AbortAnimations() { | 477 void WorkspaceCyclerAnimator::AbortAnimations() { |
473 StopObservingImplicitAnimations(); | 478 StopObservingImplicitAnimations(); |
474 animation_type_ = NONE; | 479 animation_type_ = NONE; |
475 CyclerStopped(initial_active_workspace_index_); | 480 CyclerStopped(initial_active_workspace_index_); |
476 } | 481 } |
477 | 482 |
478 void WorkspaceCyclerAnimator::AnimateCyclingByScrollDelta(float scroll_delta) { | 483 void WorkspaceCyclerAnimator::AnimateCyclingByScrollDelta(double scroll_delta) { |
479 if (scroll_delta == 0.0f) | 484 if (scroll_delta == 0) |
480 return; | 485 return; |
481 | 486 |
482 // Drop any updates received while an animation is running. | 487 // Drop any updates received while an animation is running. |
483 // TODO(pkotwicz): Do something better. | 488 // TODO(pkotwicz): Do something better. |
484 if (animation_type_ != NONE) | 489 if (animation_type_ != NONE) |
485 return; | 490 return; |
486 | 491 |
487 if (ui::IsNaturalScrollEnabled()) | 492 if (ui::IsNaturalScrollEnabled()) |
488 scroll_delta *= -1; | 493 scroll_delta *= -1; |
489 | 494 |
490 double old_scroll_delta = scroll_delta_; | 495 double old_scroll_delta = scroll_delta_; |
491 scroll_delta_ += scroll_delta; | 496 scroll_delta_ += scroll_delta; |
492 | 497 |
| 498 double scroll_distance_to_cycle_to_next_workspace = Config::GetDouble( |
| 499 Config::SCROLL_DISTANCE_TO_CYCLE_TO_NEXT_WORKSPACE); |
| 500 |
493 double min_scroll_delta = -1 * | 501 double min_scroll_delta = -1 * |
494 static_cast<double>(selected_workspace_index_) * | 502 static_cast<double>(selected_workspace_index_) * |
495 kScrollAmountToCycleToNextWorkspace; | 503 scroll_distance_to_cycle_to_next_workspace; |
496 double max_scroll_delta = static_cast<double>( | 504 double max_scroll_delta = static_cast<double>( |
497 workspaces_.size() - 1 - selected_workspace_index_) * | 505 workspaces_.size() - 1 - selected_workspace_index_) * |
498 kScrollAmountToCycleToNextWorkspace; | 506 scroll_distance_to_cycle_to_next_workspace; |
499 | 507 |
500 if (scroll_delta_ < min_scroll_delta) | 508 if (scroll_delta_ < min_scroll_delta) |
501 scroll_delta_ = min_scroll_delta; | 509 scroll_delta_ = min_scroll_delta; |
502 else if (scroll_delta_ > max_scroll_delta) | 510 else if (scroll_delta_ > max_scroll_delta) |
503 scroll_delta_ = max_scroll_delta; | 511 scroll_delta_ = max_scroll_delta; |
504 | 512 |
505 if (scroll_delta_ == old_scroll_delta) | 513 if (scroll_delta_ == old_scroll_delta) |
506 return; | 514 return; |
507 | 515 |
508 // Set the selected workspace to the workspace that the user is closest to | 516 // Set the selected workspace to the workspace that the user is closest to |
509 // selecting completely. A workspace is completely selected when the user | 517 // selecting completely. A workspace is completely selected when the user |
510 // has scrolled the exact amount to select the workspace with no undershoot / | 518 // has scrolled the exact amount to select the workspace with no undershoot / |
511 // overshoot. | 519 // overshoot. |
512 int workspace_change = floor(scroll_delta_ / | 520 int workspace_change = floor(scroll_delta_ / |
513 kScrollAmountToCycleToNextWorkspace + .5); | 521 scroll_distance_to_cycle_to_next_workspace + .5); |
514 selected_workspace_index_ += workspace_change; | 522 selected_workspace_index_ += workspace_change; |
515 | 523 |
516 // Set |scroll_delta_| to the amount of undershoot / overshoot. | 524 // Set |scroll_delta_| to the amount of undershoot / overshoot. |
517 scroll_delta_ -= workspace_change * kScrollAmountToCycleToNextWorkspace; | 525 scroll_delta_ -= workspace_change * |
| 526 scroll_distance_to_cycle_to_next_workspace; |
518 | 527 |
519 int animation_duration = GetAnimationDurationForChangeInScrollDelta( | 528 int animation_duration = GetAnimationDurationForChangeInScrollDelta( |
520 scroll_delta_ - old_scroll_delta); | 529 scroll_delta_ - old_scroll_delta); |
521 | 530 |
522 animation_type_ = CYCLER_UPDATE; | 531 animation_type_ = CYCLER_UPDATE; |
523 AnimateToUpdatedState(animation_duration); | 532 AnimateToUpdatedState(animation_duration); |
524 } | 533 } |
525 | 534 |
526 void WorkspaceCyclerAnimator::AnimateToUpdatedState(int animation_duration) { | 535 void WorkspaceCyclerAnimator::AnimateToUpdatedState(int animation_duration) { |
527 DCHECK_NE(NONE, animation_type_); | 536 DCHECK_NE(NONE, animation_type_); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } else { | 638 } else { |
630 window->Hide(); | 639 window->Hide(); |
631 } | 640 } |
632 | 641 |
633 layer->SetTransform(target_transform); | 642 layer->SetTransform(target_transform); |
634 layer->SetLayerBrightness(target_brightness); | 643 layer->SetLayerBrightness(target_brightness); |
635 } | 644 } |
636 | 645 |
637 int WorkspaceCyclerAnimator::GetAnimationDurationForChangeInScrollDelta( | 646 int WorkspaceCyclerAnimator::GetAnimationDurationForChangeInScrollDelta( |
638 double change) const { | 647 double change) const { |
639 return static_cast<int>( | 648 double ratio = Config::GetDouble( |
640 fabs(change) * kCyclerStepAnimationDurationRatio); | 649 Config::CYCLER_STEP_ANIMATION_DURATION_RATIO); |
| 650 return static_cast<int>(fabs(change) * ratio); |
641 } | 651 } |
642 | 652 |
643 void WorkspaceCyclerAnimator::CreateLauncherBackground() { | 653 void WorkspaceCyclerAnimator::CreateLauncherBackground() { |
644 if (screen_bounds_ == maximized_bounds_) | 654 if (screen_bounds_ == maximized_bounds_) |
645 return; | 655 return; |
646 | 656 |
647 aura::Window* random_workspace_window = workspaces_[0]->window(); | 657 aura::Window* random_workspace_window = workspaces_[0]->window(); |
648 ash::Launcher* launcher = ash::Launcher::ForWindow(random_workspace_window); | 658 ash::Launcher* launcher = ash::Launcher::ForWindow(random_workspace_window); |
649 aura::Window* launcher_window = launcher->widget()->GetNativeWindow(); | 659 aura::Window* launcher_window = launcher->widget()->GetNativeWindow(); |
650 | 660 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 MessageLoopForUI::current()->PostTask( | 711 MessageLoopForUI::current()->PostTask( |
702 FROM_HERE, | 712 FROM_HERE, |
703 base::Bind(&WorkspaceCyclerAnimator::NotifyDelegate, | 713 base::Bind(&WorkspaceCyclerAnimator::NotifyDelegate, |
704 AsWeakPtr(), | 714 AsWeakPtr(), |
705 completed_animation)); | 715 completed_animation)); |
706 } | 716 } |
707 } | 717 } |
708 | 718 |
709 } // namespace internal | 719 } // namespace internal |
710 } // namespace ash | 720 } // namespace ash |
OLD | NEW |