| 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 "ui/gfx/geometry/point.h" | 12 #include "ui/gfx/geometry/point.h" |
| 12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
| 13 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 class Layer; | 17 class Layer; |
| 17 class CallbackLayerAnimationObserver; | 18 class CallbackLayerAnimationObserver; |
| 18 } // namespace ui | 19 } // namespace ui |
| 19 | 20 |
| 20 namespace views { | 21 namespace views { |
| 21 class RoundedRectangleLayerDelegate; | 22 class RoundedRectangleLayerDelegate; |
| 22 | 23 |
| 23 // Manages fade in/out animations for a painted Layer that is used to provide | 24 // Manages fade in/out animations for a painted Layer that is used to provide |
| 24 // visual feedback on ui::Views for mouse hover states. | 25 // visual feedback on ui::Views for mouse hover states. |
| 25 class VIEWS_EXPORT InkDropHover { | 26 class VIEWS_EXPORT InkDropHover { |
| 26 public: | 27 public: |
| 27 InkDropHover(const gfx::Size& size, int corner_radius); | 28 InkDropHover(const gfx::Size& size, |
| 29 int corner_radius, |
| 30 const gfx::Point& center_point, |
| 31 SkColor color); |
| 28 ~InkDropHover(); | 32 ~InkDropHover(); |
| 29 | 33 |
| 30 // Returns true if the hover animation is either in the process of fading | 34 // Returns true if the hover animation is either in the process of fading |
| 31 // in or is fully visible. | 35 // in or is fully visible. |
| 32 bool IsFadingInOrVisible() const; | 36 bool IsFadingInOrVisible() const; |
| 33 | 37 |
| 34 // Fades in the hover visual over the given |duration|. | 38 // Fades in the hover visual over the given |duration|. |
| 35 void FadeIn(const base::TimeDelta& duration); | 39 void FadeIn(const base::TimeDelta& duration); |
| 36 | 40 |
| 37 // Fades out the hover visual over the given |duration|. | 41 // Fades out the hover visual over the given |duration|. |
| 38 void FadeOut(const base::TimeDelta& duration); | 42 void FadeOut(const base::TimeDelta& duration); |
| 39 | 43 |
| 40 // The root Layer that can be added in to a Layer tree. | 44 // The root Layer that can be added in to a Layer tree. |
| 41 ui::Layer* layer() { return layer_.get(); } | 45 ui::Layer* layer() { return layer_.get(); } |
| 42 | 46 |
| 43 // Sets the |center_point| of the hover layer relative to its parent Layer. | |
| 44 void SetCenterPoint(const gfx::Point& center_point); | |
| 45 | |
| 46 private: | 47 private: |
| 47 enum HoverAnimationType { FADE_IN, FADE_OUT }; | 48 enum HoverAnimationType { FADE_IN, FADE_OUT }; |
| 48 | 49 |
| 49 // Animates a fade in/out as specified by |animation_type| over the given | 50 // Animates a fade in/out as specified by |animation_type| over the given |
| 50 // |duration|. | 51 // |duration|. |
| 51 void AnimateFade(HoverAnimationType animation_type, | 52 void AnimateFade(HoverAnimationType animation_type, |
| 52 const base::TimeDelta& duration); | 53 const base::TimeDelta& duration); |
| 53 | 54 |
| 54 // The callback that will be invoked when a fade in/out animation is complete. | 55 // The callback that will be invoked when a fade in/out animation is complete. |
| 55 bool AnimationEndedCallback( | 56 bool AnimationEndedCallback( |
| 56 HoverAnimationType animation_type, | 57 HoverAnimationType animation_type, |
| 57 const ui::CallbackLayerAnimationObserver& observer); | 58 const ui::CallbackLayerAnimationObserver& observer); |
| 58 | 59 |
| 59 // True if the last animation to be initiated was a FADE_IN, and false | 60 // True if the last animation to be initiated was a FADE_IN, and false |
| 60 // otherwise. | 61 // otherwise. |
| 61 bool last_animation_initiated_was_fade_in_; | 62 bool last_animation_initiated_was_fade_in_; |
| 62 | 63 |
| 63 // The LayerDelegate that paints the hover |layer_|. | 64 // The LayerDelegate that paints the hover |layer_|. |
| 64 scoped_ptr<RoundedRectangleLayerDelegate> layer_delegate_; | 65 scoped_ptr<RoundedRectangleLayerDelegate> layer_delegate_; |
| 65 | 66 |
| 66 // The visual hover layer that is painted by |layer_delegate_|. | 67 // The visual hover layer that is painted by |layer_delegate_|. |
| 67 scoped_ptr<ui::Layer> layer_; | 68 scoped_ptr<ui::Layer> layer_; |
| 68 | 69 |
| 69 DISALLOW_COPY_AND_ASSIGN(InkDropHover); | 70 DISALLOW_COPY_AND_ASSIGN(InkDropHover); |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 } // namespace views | 73 } // namespace views |
| 73 | 74 |
| 74 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 75 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| OLD | NEW |