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_IMPL_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
6 #define UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/gfx/geometry/size.h" | 12 #include "ui/gfx/geometry/size.h" |
13 #include "ui/views/animation/ink_drop.h" | 13 #include "ui/views/animation/ink_drop.h" |
14 #include "ui/views/animation/ink_drop_hover_observer.h" | 14 #include "ui/views/animation/ink_drop_highlight_observer.h" |
15 #include "ui/views/animation/ink_drop_ripple_observer.h" | 15 #include "ui/views/animation/ink_drop_ripple_observer.h" |
16 #include "ui/views/views_export.h" | 16 #include "ui/views/views_export.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 class Timer; | 19 class Timer; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 namespace views { | 22 namespace views { |
23 namespace test { | 23 namespace test { |
24 class InkDropImplTestApi; | 24 class InkDropImplTestApi; |
25 } // namespace test | 25 } // namespace test |
26 | 26 |
27 class InkDropRipple; | 27 class InkDropRipple; |
28 class InkDropHost; | 28 class InkDropHost; |
29 class InkDropHover; | 29 class InkDropHighlight; |
30 class InkDropFactoryTest; | 30 class InkDropFactoryTest; |
31 | 31 |
32 // A functional implementation of an InkDrop. | 32 // A functional implementation of an InkDrop. |
33 class VIEWS_EXPORT InkDropImpl : public InkDrop, | 33 class VIEWS_EXPORT InkDropImpl : public InkDrop, |
34 public InkDropRippleObserver, | 34 public InkDropRippleObserver, |
35 public InkDropHoverObserver { | 35 public InkDropHighlightObserver { |
36 public: | 36 public: |
37 // Constructs an ink drop that will attach the ink drop to the given | 37 // Constructs an ink drop that will attach the ink drop to the given |
38 // |ink_drop_host|. | 38 // |ink_drop_host|. |
39 explicit InkDropImpl(InkDropHost* ink_drop_host); | 39 explicit InkDropImpl(InkDropHost* ink_drop_host); |
40 ~InkDropImpl() override; | 40 ~InkDropImpl() override; |
41 | 41 |
42 // InkDrop: | 42 // InkDrop: |
43 InkDropState GetTargetInkDropState() const override; | 43 InkDropState GetTargetInkDropState() const override; |
44 bool IsVisible() const override; | 44 bool IsVisible() const override; |
45 void AnimateToState(InkDropState ink_drop_state) override; | 45 void AnimateToState(InkDropState ink_drop_state) override; |
46 void SnapToActivated() override; | 46 void SnapToActivated() override; |
47 void SetHovered(bool is_hovered) override; | 47 void SetHovered(bool is_hovered) override; |
48 void SetFocused(bool is_focused) override; | 48 void SetFocused(bool is_focused) override; |
49 | 49 |
50 private: | 50 private: |
51 friend class test::InkDropImplTestApi; | 51 friend class test::InkDropImplTestApi; |
52 | 52 |
53 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state. | 53 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state. |
54 void DestroyHiddenTargetedAnimations(); | 54 void DestroyHiddenTargetedAnimations(); |
55 | 55 |
56 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If | 56 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If |
57 // |ink_drop_ripple_| wasn't null then it will be destroyed using | 57 // |ink_drop_ripple_| wasn't null then it will be destroyed using |
58 // DestroyInkDropRipple(). | 58 // DestroyInkDropRipple(). |
59 void CreateInkDropRipple(); | 59 void CreateInkDropRipple(); |
60 | 60 |
61 // Destroys the current |ink_drop_ripple_|. | 61 // Destroys the current |ink_drop_ripple_|. |
62 void DestroyInkDropRipple(); | 62 void DestroyInkDropRipple(); |
63 | 63 |
64 // Creates a new InkDropHover and sets it to |hover_|. If |hover_| wasn't null | 64 // Creates a new InkDropHighlight and assigns it to |highlight_|. If |
65 // then it will be destroyed using DestroyInkDropHover(). | 65 // |highlight_| wasn't null then it will be destroyed using |
66 void CreateInkDropHover(); | 66 // DestroyInkDropHighlight(). |
| 67 void CreateInkDropHighlight(); |
67 | 68 |
68 // Destroys the current |hover_|. | 69 // Destroys the current |highlight_|. |
69 void DestroyInkDropHover(); | 70 void DestroyInkDropHighlight(); |
70 | 71 |
71 // Adds the |root_layer_| to the |ink_drop_host_| if it hasn't already been | 72 // Adds the |root_layer_| to the |ink_drop_host_| if it hasn't already been |
72 // added. | 73 // added. |
73 void AddRootLayerToHostIfNeeded(); | 74 void AddRootLayerToHostIfNeeded(); |
74 | 75 |
75 // Removes the |root_layer_| from the |ink_drop_host_| if no ink drop ripple | 76 // Removes the |root_layer_| from the |ink_drop_host_| if no ink drop ripple |
76 // or hover is active. | 77 // or highlight is active. |
77 void RemoveRootLayerFromHostIfNeeded(); | 78 void RemoveRootLayerFromHostIfNeeded(); |
78 | 79 |
79 // Returns true if the hover animation is in the process of fading in or | 80 // Returns true if the highlight animation is in the process of fading in or |
80 // is visible. | 81 // is visible. |
81 bool IsHoverFadingInOrVisible() const; | 82 bool IsHighlightFadingInOrVisible() const; |
82 | 83 |
83 // views::InkDropRippleObserver: | 84 // views::InkDropRippleObserver: |
84 void AnimationStarted(InkDropState ink_drop_state) override; | 85 void AnimationStarted(InkDropState ink_drop_state) override; |
85 void AnimationEnded(InkDropState ink_drop_state, | 86 void AnimationEnded(InkDropState ink_drop_state, |
86 InkDropAnimationEndedReason reason) override; | 87 InkDropAnimationEndedReason reason) override; |
87 | 88 |
88 // views::InkDropHoverObserver: | 89 // views::InkDropHighlightObserver: |
89 void AnimationStarted(InkDropHover::AnimationType animation_type) override; | 90 void AnimationStarted( |
90 void AnimationEnded(InkDropHover::AnimationType animation_type, | 91 InkDropHighlight::AnimationType animation_type) override; |
| 92 void AnimationEnded(InkDropHighlight::AnimationType animation_type, |
91 InkDropAnimationEndedReason reason) override; | 93 InkDropAnimationEndedReason reason) override; |
92 | 94 |
93 // Enables or disables the hover state based on |should_highlight| and if an | 95 // Enables or disables the highlight state based on |should_highlight| and if |
94 // animation is triggered it will be scheduled to have the given | 96 // an animation is triggered it will be scheduled to have the given |
95 // |animation_duration|. If |explode| is true the hover will expand as it | 97 // |animation_duration|. If |explode| is true the highlight will expand as it |
96 // fades out. |explode| is ignored when |should_higlight| is true. | 98 // fades out. |explode| is ignored when |should_higlight| is true. |
97 void SetHighlight(bool should_highlight, | 99 void SetHighlight(bool should_highlight, |
98 base::TimeDelta animation_duration, | 100 base::TimeDelta animation_duration, |
99 bool explode); | 101 bool explode); |
100 | 102 |
101 // Returns true if this ink drop is hovered or focused. | 103 // Returns true if this ink drop is hovered or focused. |
102 bool ShouldHighlight() const; | 104 bool ShouldHighlight() const; |
103 | 105 |
104 // Starts the |hover_after_ripple_timer_| timer. This will stop the current | 106 // Starts the |highlight_after_ripple_timer_| timer. This will stop the |
105 // |hover_after_ripple_timer_| instance if it exists. | 107 // current |
106 void StartHoverAfterRippleTimer(); | 108 // |highlight_after_ripple_timer_| instance if it exists. |
| 109 void StartHighlightAfterRippleTimer(); |
107 | 110 |
108 // Stops and destroys the current |hover_after_ripple_timer_| instance. | 111 // Stops and destroys the current |highlight_after_ripple_timer_| instance. |
109 void StopHoverAfterRippleTimer(); | 112 void StopHighlightAfterRippleTimer(); |
110 | 113 |
111 // Callback for when the |hover_after_ripple_timer_| fires. | 114 // Callback for when the |highlight_after_ripple_timer_| fires. |
112 void HoverAfterRippleTimerFired(); | 115 void HighlightAfterRippleTimerFired(); |
113 | 116 |
114 // The host of the ink drop. Used to poll for information such as whether the | 117 // The host of the ink drop. Used to poll for information such as whether the |
115 // hover should be shown or not. | 118 // highlight should be shown or not. |
116 InkDropHost* ink_drop_host_; | 119 InkDropHost* ink_drop_host_; |
117 | 120 |
118 // The root Layer that parents the InkDropRipple layers and the InkDropHover | 121 // The root Layer that parents the InkDropRipple layers and the |
119 // layers. The |root_layer_| is the one that is added and removed from the | 122 // InkDropHighlight layers. The |root_layer_| is the one that is added and |
120 // InkDropHost. | 123 // removed from the InkDropHost. |
121 std::unique_ptr<ui::Layer> root_layer_; | 124 std::unique_ptr<ui::Layer> root_layer_; |
122 | 125 |
123 // True when the |root_layer_| has been added to the |ink_drop_host_|. | 126 // True when the |root_layer_| has been added to the |ink_drop_host_|. |
124 bool root_layer_added_to_host_; | 127 bool root_layer_added_to_host_; |
125 | 128 |
126 // The current InkDropHover. Lazily created using CreateInkDropHover(); | 129 // The current InkDropHighlight. Lazily created using |
127 std::unique_ptr<InkDropHover> hover_; | 130 // CreateInkDropHighlight(); |
| 131 std::unique_ptr<InkDropHighlight> highlight_; |
128 | 132 |
129 // Tracks the logical hovered state of |this| as manipulated by the public | 133 // Tracks the logical hovered state of |this| as manipulated by the public |
130 // SetHovered() function. | 134 // SetHovered() function. |
131 bool is_hovered_; | 135 bool is_hovered_; |
132 | 136 |
133 // Tracks the logical focused state of |this| as manipulated by the public | 137 // Tracks the logical focused state of |this| as manipulated by the public |
134 // SetFocused() function. | 138 // SetFocused() function. |
135 bool is_focused_; | 139 bool is_focused_; |
136 | 140 |
137 // The current InkDropRipple. Created on demand using CreateInkDropRipple(). | 141 // The current InkDropRipple. Created on demand using CreateInkDropRipple(). |
138 std::unique_ptr<InkDropRipple> ink_drop_ripple_; | 142 std::unique_ptr<InkDropRipple> ink_drop_ripple_; |
139 | 143 |
140 // The timer used to delay the hover fade in after an ink drop ripple | 144 // The timer used to delay the highlight fade in after an ink drop ripple |
141 // animation. | 145 // animation. |
142 std::unique_ptr<base::Timer> hover_after_ripple_timer_; | 146 std::unique_ptr<base::Timer> highlight_after_ripple_timer_; |
143 | 147 |
144 DISALLOW_COPY_AND_ASSIGN(InkDropImpl); | 148 DISALLOW_COPY_AND_ASSIGN(InkDropImpl); |
145 }; | 149 }; |
146 | 150 |
147 } // namespace views | 151 } // namespace views |
148 | 152 |
149 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ | 153 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ |
OLD | NEW |