Home | History | Annotate | Download | only in wm
      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
      3 // found in the LICENSE file.
      4 
      5 #include "ash/wm/session_state_animator.h"
      6 
      7 #include "ash/shell.h"
      8 #include "ash/shell_window_ids.h"
      9 #include "ash/wm/window_animations.h"
     10 #include "ui/aura/client/aura_constants.h"
     11 #include "ui/aura/window_event_dispatcher.h"
     12 #include "ui/compositor/layer_animation_observer.h"
     13 #include "ui/compositor/layer_animation_sequence.h"
     14 #include "ui/compositor/scoped_layer_animation_settings.h"
     15 #include "ui/views/widget/widget.h"
     16 
     17 namespace ash {
     18 
     19 const int SessionStateAnimator::kAllLockScreenContainersMask =
     20     SessionStateAnimator::LOCK_SCREEN_BACKGROUND |
     21     SessionStateAnimator::LOCK_SCREEN_CONTAINERS |
     22     SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS;
     23 
     24 const int SessionStateAnimator::kAllNonRootContainersMask =
     25     SessionStateAnimator::kAllLockScreenContainersMask |
     26     SessionStateAnimator::DESKTOP_BACKGROUND |
     27     SessionStateAnimator::LAUNCHER |
     28     SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS;
     29 
     30 SessionStateAnimator::AnimationSequence::AnimationSequence(
     31     base::Closure callback)
     32   : sequence_ended_(false),
     33     animation_completed_(false),
     34     invoke_callback_(false),
     35     callback_(callback) {
     36 }
     37 
     38 SessionStateAnimator::AnimationSequence::~AnimationSequence() {
     39 }
     40 
     41 void SessionStateAnimator::AnimationSequence::EndSequence() {
     42   sequence_ended_ = true;
     43   CleanupIfSequenceCompleted();
     44 }
     45 
     46 void SessionStateAnimator::AnimationSequence::OnAnimationCompleted() {
     47   animation_completed_ = true;
     48   invoke_callback_ = true;
     49   CleanupIfSequenceCompleted();
     50 }
     51 
     52 void SessionStateAnimator::AnimationSequence::OnAnimationAborted() {
     53   animation_completed_ = true;
     54   invoke_callback_ = false;
     55   CleanupIfSequenceCompleted();
     56 }
     57 
     58 void SessionStateAnimator::AnimationSequence::CleanupIfSequenceCompleted() {
     59   if (sequence_ended_ && animation_completed_) {
     60     if (invoke_callback_)
     61       callback_.Run();
     62     delete this;
     63   }
     64 }
     65 
     66 SessionStateAnimator::SessionStateAnimator() {
     67 }
     68 
     69 SessionStateAnimator::~SessionStateAnimator() {
     70 }
     71 
     72 base::TimeDelta SessionStateAnimator::GetDuration(
     73     SessionStateAnimator::AnimationSpeed speed) {
     74   switch (speed) {
     75     case ANIMATION_SPEED_IMMEDIATE:
     76       return base::TimeDelta();
     77     case ANIMATION_SPEED_UNDOABLE:
     78       return base::TimeDelta::FromMilliseconds(400);
     79     case ANIMATION_SPEED_REVERT:
     80       return base::TimeDelta::FromMilliseconds(150);
     81     case ANIMATION_SPEED_FAST:
     82       return base::TimeDelta::FromMilliseconds(150);
     83     case ANIMATION_SPEED_SHOW_LOCK_SCREEN:
     84       return base::TimeDelta::FromMilliseconds(200);
     85     case ANIMATION_SPEED_MOVE_WINDOWS:
     86       return base::TimeDelta::FromMilliseconds(350);
     87     case ANIMATION_SPEED_UNDO_MOVE_WINDOWS:
     88       return base::TimeDelta::FromMilliseconds(350);
     89     case ANIMATION_SPEED_SHUTDOWN:
     90       return base::TimeDelta::FromMilliseconds(1000);
     91     case ANIMATION_SPEED_REVERT_SHUTDOWN:
     92       return base::TimeDelta::FromMilliseconds(500);
     93   }
     94   // Satisfy compilers that do not understand that we will return from switch
     95   // above anyway.
     96   DCHECK(false) << "Unhandled animation speed " << speed;
     97   return base::TimeDelta();
     98 }
     99 
    100 }  // namespace ash
    101