| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_HOVER_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 13 #include "ui/gfx/geometry/point_f.h" |
| 13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 15 #include "ui/gfx/transform.h" |
| 14 #include "ui/views/views_export.h" | 16 #include "ui/views/views_export.h" |
| 15 | 17 |
| 16 namespace ui { | 18 namespace ui { |
| 17 class Layer; | 19 class Layer; |
| 18 class CallbackLayerAnimationObserver; | 20 class CallbackLayerAnimationObserver; |
| 19 } // namespace ui | 21 } // namespace ui |
| 20 | 22 |
| 21 namespace views { | 23 namespace views { |
| 22 class RoundedRectangleLayerDelegate; | 24 class RoundedRectangleLayerDelegate; |
| 23 | 25 |
| 24 // Manages fade in/out animations for a painted Layer that is used to provide | 26 // Manages fade in/out animations for a painted Layer that is used to provide |
| 25 // visual feedback on ui::Views for mouse hover states. | 27 // visual feedback on ui::Views for mouse hover states. |
| 26 class VIEWS_EXPORT InkDropHover { | 28 class VIEWS_EXPORT InkDropHover { |
| 27 public: | 29 public: |
| 28 InkDropHover(const gfx::Size& size, | 30 InkDropHover(const gfx::Size& size, |
| 29 int corner_radius, | 31 int corner_radius, |
| 30 const gfx::Point& center_point, | 32 const gfx::Point& center_point, |
| 31 SkColor color); | 33 SkColor color); |
| 32 ~InkDropHover(); | 34 ~InkDropHover(); |
| 33 | 35 |
| 36 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } |
| 37 |
| 34 // Returns true if the hover animation is either in the process of fading | 38 // Returns true if the hover animation is either in the process of fading |
| 35 // in or is fully visible. | 39 // in or is fully visible. |
| 36 bool IsFadingInOrVisible() const; | 40 bool IsFadingInOrVisible() const; |
| 37 | 41 |
| 38 // Fades in the hover visual over the given |duration|. | 42 // Fades in the hover visual over the given |duration|. |
| 39 void FadeIn(const base::TimeDelta& duration); | 43 void FadeIn(const base::TimeDelta& duration); |
| 40 | 44 |
| 41 // Fades out the hover visual over the given |duration|. | 45 // Fades out the hover visual over the given |duration|. If |explode| is true |
| 42 void FadeOut(const base::TimeDelta& duration); | 46 // then the hover will animate a size increase in addition to the fade out. |
| 47 void FadeOut(const base::TimeDelta& duration, bool explode); |
| 43 | 48 |
| 44 // The root Layer that can be added in to a Layer tree. | 49 // The root Layer that can be added in to a Layer tree. |
| 45 ui::Layer* layer() { return layer_.get(); } | 50 ui::Layer* layer() { return layer_.get(); } |
| 46 | 51 |
| 47 private: | 52 private: |
| 48 enum HoverAnimationType { FADE_IN, FADE_OUT }; | 53 enum HoverAnimationType { FADE_IN, FADE_OUT }; |
| 49 | 54 |
| 50 // Animates a fade in/out as specified by |animation_type| over the given | 55 // Animates a fade in/out as specified by |animation_type| combined with a |
| 56 // transformation from the |initial_size| to the |target_size| over the given |
| 51 // |duration|. | 57 // |duration|. |
| 52 void AnimateFade(HoverAnimationType animation_type, | 58 void AnimateFade(HoverAnimationType animation_type, |
| 53 const base::TimeDelta& duration); | 59 const base::TimeDelta& duration, |
| 60 const gfx::Size& initial_size, |
| 61 const gfx::Size& target_size); |
| 62 |
| 63 // Calculates the Transform to apply to |layer_| for the given |size|. |
| 64 gfx::Transform CalculateTransform(const gfx::Size& size) const; |
| 54 | 65 |
| 55 // The callback that will be invoked when a fade in/out animation is complete. | 66 // The callback that will be invoked when a fade in/out animation is complete. |
| 56 bool AnimationEndedCallback( | 67 bool AnimationEndedCallback( |
| 57 HoverAnimationType animation_type, | 68 HoverAnimationType animation_type, |
| 58 const ui::CallbackLayerAnimationObserver& observer); | 69 const ui::CallbackLayerAnimationObserver& observer); |
| 59 | 70 |
| 71 // The size of the hover shape when fully faded in. |
| 72 gfx::Size size_; |
| 73 |
| 74 // The target size of the hover shape when it expands during a fade out |
| 75 // animation. |
| 76 gfx::Size explode_size_; |
| 77 |
| 78 // The center point of the hover shape in the parent Layer's coordinate space. |
| 79 gfx::PointF center_point_; |
| 80 |
| 60 // True if the last animation to be initiated was a FADE_IN, and false | 81 // True if the last animation to be initiated was a FADE_IN, and false |
| 61 // otherwise. | 82 // otherwise. |
| 62 bool last_animation_initiated_was_fade_in_; | 83 bool last_animation_initiated_was_fade_in_; |
| 63 | 84 |
| 64 // The LayerDelegate that paints the hover |layer_|. | 85 // The LayerDelegate that paints the hover |layer_|. |
| 65 scoped_ptr<RoundedRectangleLayerDelegate> layer_delegate_; | 86 scoped_ptr<RoundedRectangleLayerDelegate> layer_delegate_; |
| 66 | 87 |
| 67 // The visual hover layer that is painted by |layer_delegate_|. | 88 // The visual hover layer that is painted by |layer_delegate_|. |
| 68 scoped_ptr<ui::Layer> layer_; | 89 scoped_ptr<ui::Layer> layer_; |
| 69 | 90 |
| 70 DISALLOW_COPY_AND_ASSIGN(InkDropHover); | 91 DISALLOW_COPY_AND_ASSIGN(InkDropHover); |
| 71 }; | 92 }; |
| 72 | 93 |
| 73 } // namespace views | 94 } // namespace views |
| 74 | 95 |
| 75 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 96 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| OLD | NEW |