| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "ui/gfx/geometry/point.h" | |
| 10 #include "ui/views/animation/ink_drop_animation_observer.h" | |
| 11 #include "ui/views/animation/ink_drop_state.h" | |
| 12 #include "ui/views/views_export.h" | |
| 13 | |
| 14 namespace ui { | |
| 15 class CallbackLayerAnimationObserver; | |
| 16 class Layer; | |
| 17 class LayerAnimationObserver; | |
| 18 } // namespace ui | |
| 19 | |
| 20 namespace views { | |
| 21 | |
| 22 namespace test { | |
| 23 class InkDropAnimationTestApi; | |
| 24 } // namespace test | |
| 25 | |
| 26 // Simple base class for animations that provide visual feedback for View state. | |
| 27 // Manages the attached InkDropAnimationObservers. | |
| 28 // | |
| 29 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to | |
| 30 // the doc here. | |
| 31 class VIEWS_EXPORT InkDropAnimation { | |
| 32 public: | |
| 33 // TODO(bruthig): Remove UseFastAnimations() and kSlowAnimationDurationFactor. | |
| 34 // See http://crbug.com/584681 | |
| 35 | |
| 36 // Checks CommandLine switches to determine if the visual feedback should have | |
| 37 // a fast animations speed. | |
| 38 static bool UseFastAnimations(); | |
| 39 | |
| 40 // The factor at which to increase the animation durations if | |
| 41 // UseFastAnimations() returns true. | |
| 42 static const double kSlowAnimationDurationFactor; | |
| 43 | |
| 44 // The opacity of the ink drop when it is not visible. | |
| 45 static const float kHiddenOpacity; | |
| 46 | |
| 47 // The opacity of the ink drop when it is visible. | |
| 48 static const float kVisibleOpacity; | |
| 49 | |
| 50 InkDropAnimation(); | |
| 51 virtual ~InkDropAnimation(); | |
| 52 | |
| 53 // In the event that an animation is in progress for ink drop state 's1' and | |
| 54 // an animation to a new state 's2' is triggered, then | |
| 55 // AnimationEnded(s1, PRE_EMPTED) will be called before | |
| 56 // AnimationStarted(s2). | |
| 57 void set_observer(InkDropAnimationObserver* observer) { | |
| 58 observer_ = observer; | |
| 59 } | |
| 60 | |
| 61 // Animates from the current InkDropState to the new |ink_drop_state|. | |
| 62 // | |
| 63 // NOTE: GetTargetInkDropState() should return the new |ink_drop_state| value | |
| 64 // to any observers being notified as a result of the call. | |
| 65 void AnimateToState(InkDropState ink_drop_state); | |
| 66 | |
| 67 InkDropState target_ink_drop_state() const { return target_ink_drop_state_; } | |
| 68 | |
| 69 // Immediately aborts all in-progress animations and hides the ink drop. | |
| 70 // | |
| 71 // NOTE: This will NOT raise InkDropAnimation(Started|Ended) events for the | |
| 72 // state transition to HIDDEN! | |
| 73 void HideImmediately(); | |
| 74 | |
| 75 // Immediately snaps the ink drop to the ACTIVATED target state. All pending | |
| 76 // animations are aborted. Events will be raised for the pending animations | |
| 77 // as well as the transition to the ACTIVATED state. | |
| 78 virtual void SnapToActivated(); | |
| 79 | |
| 80 // The root Layer that can be added in to a Layer tree. | |
| 81 virtual ui::Layer* GetRootLayer() = 0; | |
| 82 | |
| 83 // Returns true when the ripple is visible. This is different from checking if | |
| 84 // the ink_drop_state() == HIDDEN because the ripple may be visible while it | |
| 85 // animates to the target HIDDEN state. | |
| 86 virtual bool IsVisible() const = 0; | |
| 87 | |
| 88 // Returns a test api to access internals of this. Default implmentations | |
| 89 // should return nullptr and test specific subclasses can override to return | |
| 90 // an instance. | |
| 91 virtual test::InkDropAnimationTestApi* GetTestApi(); | |
| 92 | |
| 93 protected: | |
| 94 // Animates the ripple from the |old_ink_drop_state| to the | |
| 95 // |new_ink_drop_state|. |observer| is added to all LayerAnimationSequence's | |
| 96 // used if not null. | |
| 97 virtual void AnimateStateChange(InkDropState old_ink_drop_state, | |
| 98 InkDropState new_ink_drop_state, | |
| 99 ui::LayerAnimationObserver* observer) = 0; | |
| 100 | |
| 101 // Updates the transforms, opacity, and visibility to a HIDDEN state. | |
| 102 virtual void SetStateToHidden() = 0; | |
| 103 | |
| 104 virtual void AbortAllAnimations() = 0; | |
| 105 | |
| 106 private: | |
| 107 // The Callback invoked when all of the animation sequences for the specific | |
| 108 // |ink_drop_state| animation have started. |observer| is the | |
| 109 // ui::CallbackLayerAnimationObserver which is notifying the callback. | |
| 110 void AnimationStartedCallback( | |
| 111 InkDropState ink_drop_state, | |
| 112 const ui::CallbackLayerAnimationObserver& observer); | |
| 113 | |
| 114 // The Callback invoked when all of the animation sequences for the specific | |
| 115 // |ink_drop_state| animation have finished. |observer| is the | |
| 116 // ui::CallbackLayerAnimationObserver which is notifying the callback. | |
| 117 bool AnimationEndedCallback( | |
| 118 InkDropState ink_drop_state, | |
| 119 const ui::CallbackLayerAnimationObserver& observer); | |
| 120 | |
| 121 // The target InkDropState. | |
| 122 InkDropState target_ink_drop_state_; | |
| 123 | |
| 124 InkDropAnimationObserver* observer_; | |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | |
| 127 }; | |
| 128 | |
| 129 } // namespace views | |
| 130 | |
| 131 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | |
| OLD | NEW |