1 // Copyright 2019 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 #ifndef ASH_ASSISTANT_UI_MAIN_STAGE_ELEMENT_ANIMATOR_H_ 6 #define ASH_ASSISTANT_UI_MAIN_STAGE_ELEMENT_ANIMATOR_H_ 7 8 #include "base/macros.h" 9 #include "base/time/time.h" 10 11 namespace ui { 12 class CallbackLayerAnimationObserver; 13 class Layer; 14 } // namespace ui 15 16 namespace views { 17 class View; 18 } // namespace views 19 20 namespace ash { 21 22 // Defines all the animations for the associated UI element. 23 class ElementAnimator { 24 public: 25 // Fade out duration used in the default implementation of |FadeOut|. 26 constexpr static base::TimeDelta kFadeOutDuration = 27 base::TimeDelta::FromMilliseconds(150); 28 // Fade out opacity used in the default implementation of |FadeOut|. 29 constexpr static float kFadeOutOpacity = 0.26f; 30 // Minimum allowed opacity as a target when fading out. 31 // Note that we approximate 0% by actually using 0.01%. We do this to 32 // workaround a DCHECK that requires aura::Windows to have a target opacity > 33 // 0% when shown. Because our window will be removed after it reaches this 34 // value, it should be safe to circumnavigate this DCHECK. 35 constexpr static float kMinimumAnimateOutOpacity = 0.0001f; 36 37 explicit ElementAnimator(views::View* animated_view); 38 virtual ~ElementAnimator() = default; 39 40 // Fade out the current element, meaning it will still be visible but 41 // partially opaque. 42 virtual void FadeOut(ui::CallbackLayerAnimationObserver* observer); 43 44 // Start the animation to remove the element. 45 virtual void AnimateOut(ui::CallbackLayerAnimationObserver* observer) = 0; 46 47 // Start the animation to add the element. 48 virtual void AnimateIn(ui::CallbackLayerAnimationObserver* observer) = 0; 49 50 // Abort whatever animation is currently in progress. 51 virtual void AbortAnimation(); 52 53 // The view that is being animated. 54 virtual views::View* view() const; 55 56 // The layer that needs to be animated. 57 // Used by the default implementations for |FadeOut| and |AbortAnimation|. 58 // Defaults to |view()->layer()|. 59 virtual ui::Layer* layer() const; 60 61 private: 62 // The parent |AnimatedContainerView| owns both |view_| and |this| and will 63 // delete |this| when |view_| is removed. 64 views::View* const view_; 65 66 DISALLOW_COPY_AND_ASSIGN(ElementAnimator); 67 }; 68 69 } // namespace ash 70 71 #endif // ASH_ASSISTANT_UI_MAIN_STAGE_ELEMENT_ANIMATOR_H_ 72