| 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_HIGHLIGHT_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ |
| 7 | 7 |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
| 15 #include "ui/gfx/geometry/point_f.h" | 15 #include "ui/gfx/geometry/point_f.h" |
| 16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
| 17 #include "ui/gfx/geometry/size_f.h" |
| 17 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
| 18 #include "ui/views/views_export.h" | 19 #include "ui/views/views_export.h" |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 class Layer; | 22 class Layer; |
| 22 class CallbackLayerAnimationObserver; | 23 class CallbackLayerAnimationObserver; |
| 23 } // namespace ui | 24 } // namespace ui |
| 24 | 25 |
| 25 namespace views { | 26 namespace views { |
| 26 namespace test { | 27 namespace test { |
| 27 class InkDropHighlightTestApi; | 28 class InkDropHighlightTestApi; |
| 28 } // namespace test | 29 } // namespace test |
| 29 | 30 |
| 30 class BasePaintedLayerDelegate; | 31 class BasePaintedLayerDelegate; |
| 31 class InkDropHighlightObserver; | 32 class InkDropHighlightObserver; |
| 32 | 33 |
| 33 // Manages fade in/out animations for a painted Layer that is used to provide | 34 // Manages fade in/out animations for a painted Layer that is used to provide |
| 34 // visual feedback on ui::Views for highlight states (e.g. mouse hover, keyboard | 35 // visual feedback on ui::Views for highlight states (e.g. mouse hover, keyboard |
| 35 // focus). | 36 // focus). |
| 36 class VIEWS_EXPORT InkDropHighlight { | 37 class VIEWS_EXPORT InkDropHighlight { |
| 37 public: | 38 public: |
| 38 enum AnimationType { FADE_IN, FADE_OUT }; | 39 enum AnimationType { FADE_IN, FADE_OUT }; |
| 39 | 40 |
| 40 // Creates a highlight with a specified painter. | 41 // Creates a highlight with a specified painter. |
| 41 InkDropHighlight(const gfx::PointF& center_point, | 42 InkDropHighlight(const gfx::PointF& center_point, |
| 42 std::unique_ptr<BasePaintedLayerDelegate> layer_delegate); | 43 std::unique_ptr<BasePaintedLayerDelegate> layer_delegate); |
| 43 | 44 |
| 44 // Creates a highlight that paints a partially transparent roundrect with | 45 // Creates a highlight that paints a partially transparent roundrect with |
| 45 // color |color|. | 46 // color |color|. |
| 47 InkDropHighlight(const gfx::SizeF& size, |
| 48 int corner_radius, |
| 49 const gfx::PointF& center_point, |
| 50 SkColor color); |
| 51 |
| 52 // Deprecated version of the above that takes a Size instead of SizeF. |
| 53 // TODO(estade): remove. See crbug.com/706228 |
| 46 InkDropHighlight(const gfx::Size& size, | 54 InkDropHighlight(const gfx::Size& size, |
| 47 int corner_radius, | 55 int corner_radius, |
| 48 const gfx::PointF& center_point, | 56 const gfx::PointF& center_point, |
| 49 SkColor color); | 57 SkColor color); |
| 58 |
| 50 virtual ~InkDropHighlight(); | 59 virtual ~InkDropHighlight(); |
| 51 | 60 |
| 52 void set_observer(InkDropHighlightObserver* observer) { | 61 void set_observer(InkDropHighlightObserver* observer) { |
| 53 observer_ = observer; | 62 observer_ = observer; |
| 54 } | 63 } |
| 55 | 64 |
| 56 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } | 65 void set_explode_size(const gfx::SizeF& size) { explode_size_ = size; } |
| 57 | 66 |
| 58 void set_visible_opacity(float visible_opacity) { | 67 void set_visible_opacity(float visible_opacity) { |
| 59 visible_opacity_ = visible_opacity; | 68 visible_opacity_ = visible_opacity; |
| 60 } | 69 } |
| 61 | 70 |
| 62 // Returns true if the highlight animation is either in the process of fading | 71 // Returns true if the highlight animation is either in the process of fading |
| 63 // in or is fully visible. | 72 // in or is fully visible. |
| 64 bool IsFadingInOrVisible() const; | 73 bool IsFadingInOrVisible() const; |
| 65 | 74 |
| 66 // Fades in the highlight visual over the given |duration|. | 75 // Fades in the highlight visual over the given |duration|. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 virtual test::InkDropHighlightTestApi* GetTestApi(); | 89 virtual test::InkDropHighlightTestApi* GetTestApi(); |
| 81 | 90 |
| 82 private: | 91 private: |
| 83 friend class test::InkDropHighlightTestApi; | 92 friend class test::InkDropHighlightTestApi; |
| 84 | 93 |
| 85 // Animates a fade in/out as specified by |animation_type| combined with a | 94 // Animates a fade in/out as specified by |animation_type| combined with a |
| 86 // transformation from the |initial_size| to the |target_size| over the given | 95 // transformation from the |initial_size| to the |target_size| over the given |
| 87 // |duration|. | 96 // |duration|. |
| 88 void AnimateFade(AnimationType animation_type, | 97 void AnimateFade(AnimationType animation_type, |
| 89 const base::TimeDelta& duration, | 98 const base::TimeDelta& duration, |
| 90 const gfx::Size& initial_size, | 99 const gfx::SizeF& initial_size, |
| 91 const gfx::Size& target_size); | 100 const gfx::SizeF& target_size); |
| 92 | 101 |
| 93 // Calculates the Transform to apply to |layer_| for the given |size|. | 102 // Calculates the Transform to apply to |layer_| for the given |size|. |
| 94 gfx::Transform CalculateTransform(const gfx::Size& size) const; | 103 gfx::Transform CalculateTransform(const gfx::SizeF& size) const; |
| 95 | 104 |
| 96 // The callback that will be invoked when a fade in/out animation is started. | 105 // The callback that will be invoked when a fade in/out animation is started. |
| 97 void AnimationStartedCallback( | 106 void AnimationStartedCallback( |
| 98 AnimationType animation_type, | 107 AnimationType animation_type, |
| 99 const ui::CallbackLayerAnimationObserver& observer); | 108 const ui::CallbackLayerAnimationObserver& observer); |
| 100 | 109 |
| 101 // The callback that will be invoked when a fade in/out animation is complete. | 110 // The callback that will be invoked when a fade in/out animation is complete. |
| 102 bool AnimationEndedCallback( | 111 bool AnimationEndedCallback( |
| 103 AnimationType animation_type, | 112 AnimationType animation_type, |
| 104 const ui::CallbackLayerAnimationObserver& observer); | 113 const ui::CallbackLayerAnimationObserver& observer); |
| 105 | 114 |
| 106 // The size of the highlight shape when fully faded in. | 115 // The size of the highlight shape when fully faded in. |
| 107 gfx::Size size_; | 116 gfx::SizeF size_; |
| 108 | 117 |
| 109 // The target size of the highlight shape when it expands during a fade out | 118 // The target size of the highlight shape when it expands during a fade out |
| 110 // animation. | 119 // animation. |
| 111 gfx::Size explode_size_; | 120 gfx::SizeF explode_size_; |
| 112 | 121 |
| 113 // The center point of the highlight shape in the parent Layer's coordinate | 122 // The center point of the highlight shape in the parent Layer's coordinate |
| 114 // space. | 123 // space. |
| 115 gfx::PointF center_point_; | 124 gfx::PointF center_point_; |
| 116 | 125 |
| 117 // The opacity for the fully visible state of the highlight. | 126 // The opacity for the fully visible state of the highlight. |
| 118 float visible_opacity_; | 127 float visible_opacity_; |
| 119 | 128 |
| 120 // True if the last animation to be initiated was a FADE_IN, and false | 129 // True if the last animation to be initiated was a FADE_IN, and false |
| 121 // otherwise. | 130 // otherwise. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 138 | 147 |
| 139 // This is declared here for use in gtest-based unit tests but is defined in | 148 // This is declared here for use in gtest-based unit tests but is defined in |
| 140 // the views_test_support target. Depend on that to use this in your unit test. | 149 // the views_test_support target. Depend on that to use this in your unit test. |
| 141 // This should not be used in production code - call ToString() instead. | 150 // This should not be used in production code - call ToString() instead. |
| 142 void PrintTo(InkDropHighlight::AnimationType animation_type, | 151 void PrintTo(InkDropHighlight::AnimationType animation_type, |
| 143 ::std::ostream* os); | 152 ::std::ostream* os); |
| 144 | 153 |
| 145 } // namespace views | 154 } // namespace views |
| 146 | 155 |
| 147 #endif // UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ | 156 #endif // UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ |
| OLD | NEW |