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