Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: ui/views/animation/ink_drop_hover.h

Issue 1890243002: Expand the Material Design hover as it fades out when a ripple is triggered. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Optimized InkDropHover::AnimateFade() to not trigger a transformation animation if not required. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/animation/ink_drop_host_view.cc ('k') | ui/views/animation/ink_drop_hover.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
14 #include "ui/gfx/geometry/point_f.h"
14 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
16 #include "ui/gfx/transform.h"
15 #include "ui/views/views_export.h" 17 #include "ui/views/views_export.h"
16 18
17 namespace ui { 19 namespace ui {
18 class Layer; 20 class Layer;
19 class CallbackLayerAnimationObserver; 21 class CallbackLayerAnimationObserver;
20 } // namespace ui 22 } // namespace ui
21 23
22 namespace views { 24 namespace views {
23 class RoundedRectangleLayerDelegate; 25 class RoundedRectangleLayerDelegate;
24 26
25 // Manages fade in/out animations for a painted Layer that is used to provide 27 // Manages fade in/out animations for a painted Layer that is used to provide
26 // visual feedback on ui::Views for mouse hover states. 28 // visual feedback on ui::Views for mouse hover states.
27 class VIEWS_EXPORT InkDropHover { 29 class VIEWS_EXPORT InkDropHover {
28 public: 30 public:
29 InkDropHover(const gfx::Size& size, 31 InkDropHover(const gfx::Size& size,
30 int corner_radius, 32 int corner_radius,
31 const gfx::Point& center_point, 33 const gfx::Point& center_point,
32 SkColor color); 34 SkColor color);
33 ~InkDropHover(); 35 ~InkDropHover();
34 36
37 void set_explode_size(const gfx::Size& size) { explode_size_ = size; }
38
35 // Returns true if the hover animation is either in the process of fading 39 // Returns true if the hover animation is either in the process of fading
36 // in or is fully visible. 40 // in or is fully visible.
37 bool IsFadingInOrVisible() const; 41 bool IsFadingInOrVisible() const;
38 42
39 // Fades in the hover visual over the given |duration|. 43 // Fades in the hover visual over the given |duration|.
40 void FadeIn(const base::TimeDelta& duration); 44 void FadeIn(const base::TimeDelta& duration);
41 45
42 // Fades out the hover visual over the given |duration|. 46 // Fades out the hover visual over the given |duration|. If |explode| is true
43 void FadeOut(const base::TimeDelta& duration); 47 // then the hover will animate a size increase in addition to the fade out.
48 void FadeOut(const base::TimeDelta& duration, bool explode);
44 49
45 // The root Layer that can be added in to a Layer tree. 50 // The root Layer that can be added in to a Layer tree.
46 ui::Layer* layer() { return layer_.get(); } 51 ui::Layer* layer() { return layer_.get(); }
47 52
48 private: 53 private:
49 enum HoverAnimationType { FADE_IN, FADE_OUT }; 54 enum HoverAnimationType { FADE_IN, FADE_OUT };
50 55
51 // Animates a fade in/out as specified by |animation_type| over the given 56 // Animates a fade in/out as specified by |animation_type| combined with a
57 // transformation from the |initial_size| to the |target_size| over the given
52 // |duration|. 58 // |duration|.
53 void AnimateFade(HoverAnimationType animation_type, 59 void AnimateFade(HoverAnimationType animation_type,
54 const base::TimeDelta& duration); 60 const base::TimeDelta& duration,
61 const gfx::Size& initial_size,
62 const gfx::Size& target_size);
63
64 // Calculates the Transform to apply to |layer_| for the given |size|.
65 gfx::Transform CalculateTransform(const gfx::Size& size) const;
55 66
56 // The callback that will be invoked when a fade in/out animation is complete. 67 // The callback that will be invoked when a fade in/out animation is complete.
57 bool AnimationEndedCallback( 68 bool AnimationEndedCallback(
58 HoverAnimationType animation_type, 69 HoverAnimationType animation_type,
59 const ui::CallbackLayerAnimationObserver& observer); 70 const ui::CallbackLayerAnimationObserver& observer);
60 71
72 // The size of the hover shape when fully faded in.
73 gfx::Size size_;
74
75 // The target size of the hover shape when it expands during a fade out
76 // animation.
77 gfx::Size explode_size_;
78
79 // The center point of the hover shape in the parent Layer's coordinate space.
80 gfx::PointF center_point_;
81
61 // True if the last animation to be initiated was a FADE_IN, and false 82 // True if the last animation to be initiated was a FADE_IN, and false
62 // otherwise. 83 // otherwise.
63 bool last_animation_initiated_was_fade_in_; 84 bool last_animation_initiated_was_fade_in_;
64 85
65 // The LayerDelegate that paints the hover |layer_|. 86 // The LayerDelegate that paints the hover |layer_|.
66 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_; 87 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_;
67 88
68 // The visual hover layer that is painted by |layer_delegate_|. 89 // The visual hover layer that is painted by |layer_delegate_|.
69 std::unique_ptr<ui::Layer> layer_; 90 std::unique_ptr<ui::Layer> layer_;
70 91
71 DISALLOW_COPY_AND_ASSIGN(InkDropHover); 92 DISALLOW_COPY_AND_ASSIGN(InkDropHover);
72 }; 93 };
73 94
74 } // namespace views 95 } // namespace views
75 96
76 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ 97 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_host_view.cc ('k') | ui/views/animation/ink_drop_hover.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698