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

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

Issue 2447523002: [ash-md] Added different highlighting modes to the InkDropImpl. (Closed)
Patch Set: Fixed compile errors. Created 4 years, 1 month 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
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_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_highlight_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 {
19 class Timer;
20 } // namespace base
21
22 namespace views { 18 namespace views {
23 namespace test { 19 namespace test {
24 class InkDropImplTestApi; 20 class InkDropImplTestApi;
25 } // namespace test 21 } // namespace test
26 22
27 class InkDropRipple; 23 class InkDropRipple;
28 class InkDropHost; 24 class InkDropHost;
29 class InkDropHighlight; 25 class InkDropHighlight;
30 class InkDropFactoryTest; 26 class InkDropFactoryTest;
31 27
32 // A functional implementation of an InkDrop. 28 // A functional implementation of an InkDrop.
33 class VIEWS_EXPORT InkDropImpl : public InkDrop, 29 class VIEWS_EXPORT InkDropImpl : public InkDrop,
34 public InkDropRippleObserver, 30 public InkDropRippleObserver,
35 public InkDropHighlightObserver { 31 public InkDropHighlightObserver {
36 public: 32 public:
33 // The different auto highlight behaviors.
34 enum class AutoHighlightMode {
35 // No auto-highlighting is done. The highlight will only be shown/hidden as
36 // per the hover/focus settings.
37 NONE,
38 // The highlight will be hidden when a ripple becomes visible. After the
39 // ripple is hidden the highlight will be made visible again if the
40 // hover/focus settings deem it should be.
41 HIDE_ON_RIPPLE,
42 // The highlight is made visible when the ripple becomes visible. After the
43 // ripple is hidden the highlight will be hidden again if the hover/focus
44 // settings deem it should be.
45 SHOW_ON_RIPPLE,
46 };
47
37 // Constructs an ink drop that will attach the ink drop to the given 48 // Constructs an ink drop that will attach the ink drop to the given
38 // |ink_drop_host|. 49 // |ink_drop_host|.
39 explicit InkDropImpl(InkDropHost* ink_drop_host); 50 explicit InkDropImpl(InkDropHost* ink_drop_host);
40 ~InkDropImpl() override; 51 ~InkDropImpl() override;
41 52
53 void SetShowHighlightOnHover(bool show_highlight_on_hover);
sky 2016/11/02 02:52:11 Do these need to change once a button is created?
bruthig 2016/11/04 18:50:37 Not currently, but having them as configuration me
54
55 void SetShowHighlightOnFocus(bool show_highlight_on_focus);
56
57 // Auto highlighting is a mechanism to show/hide the highlight based on the
58 // visibility of the ripple. See the documentation of the AutoHighlightMode
59 // for more info on the different modes.
60 //
61 // This method is intended as a configuration option to be used after
62 // construction. Behavior is undefined if |this| has already handled any
63 // InkDrop defined functions.
64 void SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode);
65
42 // InkDrop: 66 // InkDrop:
43 InkDropState GetTargetInkDropState() const override; 67 InkDropState GetTargetInkDropState() const override;
44 void AnimateToState(InkDropState ink_drop_state) override; 68 void AnimateToState(InkDropState ink_drop_state) override;
45 void SnapToActivated() override; 69 void SnapToActivated() override;
46 void SetHovered(bool is_hovered) override; 70 void SetHovered(bool is_hovered) override;
47 void SetFocused(bool is_focused) override; 71 void SetFocused(bool is_focused) override;
48 72
49 private: 73 private:
50 friend class test::InkDropImplTestApi; 74 friend class test::InkDropImplTestApi;
51 75
76 // Base state classes.
77 class HighlightState;
78
79 // AutoHighlightMode::NONE
80 class NoAutoHighlightHiddenState;
81 class NoAutoHighlightVisibleState;
82
83 // AutoHighlightMode::HIDE_ON_RIPPLE
84 class HideHighlightOnRippleHiddenState;
85 class HideHighlightOnRippleVisibleState;
86
87 // AutoHighlightMode::SHOW_ON_RIPPLE states
88 class ShowHighlightOnRippleHiddenState;
89 class ShowHighlightOnRippleVisibleState;
90
91 class HighlightStateFactory;
92
52 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state. 93 // Destroys |ink_drop_ripple_| if it's targeted to the HIDDEN state.
53 void DestroyHiddenTargetedAnimations(); 94 void DestroyHiddenTargetedAnimations();
54 95
55 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If 96 // Creates a new InkDropRipple and sets it to |ink_drop_ripple_|. If
56 // |ink_drop_ripple_| wasn't null then it will be destroyed using 97 // |ink_drop_ripple_| wasn't null then it will be destroyed using
57 // DestroyInkDropRipple(). 98 // DestroyInkDropRipple().
58 void CreateInkDropRipple(); 99 void CreateInkDropRipple();
59 100
60 // Destroys the current |ink_drop_ripple_|. 101 // Destroys the current |ink_drop_ripple_|.
61 void DestroyInkDropRipple(); 102 void DestroyInkDropRipple();
(...skipping 30 matching lines...) Expand all
92 InkDropAnimationEndedReason reason) override; 133 InkDropAnimationEndedReason reason) override;
93 134
94 // Enables or disables the highlight state based on |should_highlight| and if 135 // Enables or disables the highlight state based on |should_highlight| and if
95 // an animation is triggered it will be scheduled to have the given 136 // an animation is triggered it will be scheduled to have the given
96 // |animation_duration|. If |explode| is true the highlight will expand as it 137 // |animation_duration|. If |explode| is true the highlight will expand as it
97 // fades out. |explode| is ignored when |should_higlight| is true. 138 // fades out. |explode| is ignored when |should_higlight| is true.
98 void SetHighlight(bool should_highlight, 139 void SetHighlight(bool should_highlight,
99 base::TimeDelta animation_duration, 140 base::TimeDelta animation_duration,
100 bool explode); 141 bool explode);
101 142
102 // Returns true if this ink drop is hovered or focused. 143 // Returns true if |this| should be hovered based on hover/focus status.
103 bool ShouldHighlight() const; 144 bool ShouldHighlight() const;
104 145
105 // Starts the |highlight_after_ripple_timer_| timer. This will stop the 146 // Returns true if |this| should be hovered based on focus status.
106 // current 147 bool ShouldHighlightBasedOnFocus() const;
107 // |highlight_after_ripple_timer_| instance if it exists.
108 void StartHighlightAfterRippleTimer();
109 148
110 // Callback for when the |highlight_after_ripple_timer_| fires. 149 // Updates the current |highlight_state_|. Calls Exit()/Enter() on the
111 void HighlightAfterRippleTimerFired(); 150 // previous/new state to notify them of the transition.
151 void SetHighlightState(std::unique_ptr<HighlightState> highlight_state);
112 152
113 // The host of the ink drop. Used to poll for information such as whether the 153 // The host of the ink drop. Used to poll for information such as whether the
114 // highlight should be shown or not. 154 // highlight should be shown or not.
115 InkDropHost* ink_drop_host_; 155 InkDropHost* ink_drop_host_;
116 156
117 // The root Layer that parents the InkDropRipple layers and the 157 // The root Layer that parents the InkDropRipple layers and the
118 // InkDropHighlight layers. The |root_layer_| is the one that is added and 158 // InkDropHighlight layers. The |root_layer_| is the one that is added and
119 // removed from the InkDropHost. 159 // removed from the InkDropHost.
120 std::unique_ptr<ui::Layer> root_layer_; 160 std::unique_ptr<ui::Layer> root_layer_;
121 161
122 // True when the |root_layer_| has been added to the |ink_drop_host_|. 162 // True when the |root_layer_| has been added to the |ink_drop_host_|.
123 bool root_layer_added_to_host_; 163 bool root_layer_added_to_host_;
124 164
125 // The current InkDropHighlight. Lazily created using 165 // The current InkDropHighlight. Lazily created using
126 // CreateInkDropHighlight(); 166 // CreateInkDropHighlight();
127 std::unique_ptr<InkDropHighlight> highlight_; 167 std::unique_ptr<InkDropHighlight> highlight_;
128 168
169 // True denotes the highlight should be shown when this is hovered.
170 bool show_highlight_on_hover_;
171
172 // True denotes the highlight should be shown when this is focused.
173 bool show_highlight_on_focus_;
174
129 // Tracks the logical hovered state of |this| as manipulated by the public 175 // Tracks the logical hovered state of |this| as manipulated by the public
130 // SetHovered() function. 176 // SetHovered() function.
131 bool is_hovered_; 177 bool is_hovered_;
132 178
133 // Tracks the logical focused state of |this| as manipulated by the public 179 // Tracks the logical focused state of |this| as manipulated by the public
134 // SetFocused() function. 180 // SetFocused() function.
135 bool is_focused_; 181 bool is_focused_;
136 182
137 // The current InkDropRipple. Created on demand using CreateInkDropRipple(). 183 // The current InkDropRipple. Created on demand using CreateInkDropRipple().
138 std::unique_ptr<InkDropRipple> ink_drop_ripple_; 184 std::unique_ptr<InkDropRipple> ink_drop_ripple_;
139 185
140 // The timer used to delay the highlight fade in after an ink drop ripple 186 // Used by |this| to initialize the starting |highlight_state_| and by the
141 // animation. 187 // current |highlight_state_ to create the next state.
142 std::unique_ptr<base::Timer> highlight_after_ripple_timer_; 188 std::unique_ptr<HighlightStateFactory> highlight_state_factory_;
189
190 // The current state object that handles all inputs that affect the visibility
191 // of the InkDropHighlight.
192 std::unique_ptr<HighlightState> highlight_state_;
143 193
144 DISALLOW_COPY_AND_ASSIGN(InkDropImpl); 194 DISALLOW_COPY_AND_ASSIGN(InkDropImpl);
145 }; 195 };
146 196
147 } // namespace views 197 } // namespace views
148 198
149 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_ 199 #endif // UI_VIEWS_ANIMATION_INK_DROP_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698