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

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

Issue 2250783002: Allow InkDropRipple to co-exist with highlight (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove EmptyInkDropRipple Created 4 years, 3 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
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 #include "ui/views/animation/ink_drop_impl.h" 5 #include "ui/views/animation/ink_drop_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/views/animation/ink_drop_highlight.h" 10 #include "ui/views/animation/ink_drop_highlight.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (!ink_drop_ripple_) 71 if (!ink_drop_ripple_)
72 return InkDropState::HIDDEN; 72 return InkDropState::HIDDEN;
73 return ink_drop_ripple_->target_ink_drop_state(); 73 return ink_drop_ripple_->target_ink_drop_state();
74 } 74 }
75 75
76 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) { 76 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) {
77 DestroyHiddenTargetedAnimations(); 77 DestroyHiddenTargetedAnimations();
78 if (!ink_drop_ripple_) 78 if (!ink_drop_ripple_)
79 CreateInkDropRipple(); 79 CreateInkDropRipple();
80 80
81 // When deactivating and the host is focused, snap back to the highlight 81 if (ink_drop_ripple_->OverridesHighlight()) {
82 // state. (In the case of highlighting due to hover, we'll animate the 82 // When deactivating and the host is focused, snap back to the highlight
83 // highlight back in after a delay.) 83 // state. (In the case of highlighting due to hover, we'll animate the
84 if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) { 84 // highlight back in after a delay.)
85 ink_drop_ripple_->HideImmediately(); 85 if (ink_drop_state == views::InkDropState::DEACTIVATED && is_focused_) {
86 SetHighlight(true, base::TimeDelta(), false); 86 ink_drop_ripple_->HideImmediately();
87 return; 87 SetHighlight(true, base::TimeDelta(), false);
88 } 88 return;
89 }
89 90
90 if (ink_drop_state != views::InkDropState::HIDDEN) { 91 if (ink_drop_state != views::InkDropState::HIDDEN) {
91 SetHighlight(false, base::TimeDelta::FromMilliseconds( 92 SetHighlight(false, base::TimeDelta::FromMilliseconds(
92 kHighlightFadeOutBeforeRippleDurationMs), 93 kHighlightFadeOutBeforeRippleDurationMs),
93 true); 94 true);
95 }
94 } 96 }
95 97
96 ink_drop_ripple_->AnimateToState(ink_drop_state); 98 ink_drop_ripple_->AnimateToState(ink_drop_state);
97 } 99 }
98 100
99 void InkDropImpl::SnapToActivated() { 101 void InkDropImpl::SnapToActivated() {
100 DestroyHiddenTargetedAnimations(); 102 DestroyHiddenTargetedAnimations();
101 if (!ink_drop_ripple_) 103 if (!ink_drop_ripple_)
102 CreateInkDropRipple(); 104 CreateInkDropRipple();
103 105
104 SetHighlight(false, base::TimeDelta(), false); 106 if (ink_drop_ripple_->OverridesHighlight())
107 SetHighlight(false, base::TimeDelta(), false);
105 108
106 ink_drop_ripple_->SnapToActivated(); 109 ink_drop_ripple_->SnapToActivated();
107 } 110 }
108 111
109 void InkDropImpl::SetHovered(bool is_hovered) { 112 void InkDropImpl::SetHovered(bool is_hovered) {
110 is_hovered_ = is_hovered; 113 is_hovered_ = is_hovered;
111 SetHighlight(ShouldHighlight(), 114 SetHighlight(ShouldHighlight(),
112 ShouldHighlight() 115 ShouldHighlight()
113 ? base::TimeDelta::FromMilliseconds( 116 ? base::TimeDelta::FromMilliseconds(
114 kHighlightFadeInFromUserInputDurationMs) 117 kHighlightFadeInFromUserInputDurationMs)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (!highlight_) 164 if (!highlight_)
162 return; 165 return;
163 root_layer_->Remove(highlight_->layer()); 166 root_layer_->Remove(highlight_->layer());
164 highlight_->set_observer(nullptr); 167 highlight_->set_observer(nullptr);
165 highlight_.reset(); 168 highlight_.reset();
166 RemoveRootLayerFromHostIfNeeded(); 169 RemoveRootLayerFromHostIfNeeded();
167 } 170 }
168 171
169 void InkDropImpl::AddRootLayerToHostIfNeeded() { 172 void InkDropImpl::AddRootLayerToHostIfNeeded() {
170 DCHECK(highlight_ || ink_drop_ripple_); 173 DCHECK(highlight_ || ink_drop_ripple_);
174 DCHECK(!root_layer_->children().empty());
171 if (!root_layer_added_to_host_) { 175 if (!root_layer_added_to_host_) {
172 root_layer_added_to_host_ = true; 176 root_layer_added_to_host_ = true;
173 ink_drop_host_->AddInkDropLayer(root_layer_.get()); 177 ink_drop_host_->AddInkDropLayer(root_layer_.get());
174 } 178 }
175 } 179 }
176 180
177 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { 181 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() {
178 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { 182 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) {
179 root_layer_added_to_host_ = false; 183 root_layer_added_to_host_ = false;
180 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 184 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
(...skipping 11 matching lines...) Expand all
192 196
193 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, 197 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state,
194 InkDropAnimationEndedReason reason) { 198 InkDropAnimationEndedReason reason) {
195 if (reason != InkDropAnimationEndedReason::SUCCESS) 199 if (reason != InkDropAnimationEndedReason::SUCCESS)
196 return; 200 return;
197 if (ShouldAnimateToHidden(ink_drop_state)) { 201 if (ShouldAnimateToHidden(ink_drop_state)) {
198 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); 202 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN);
199 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 203 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
200 // Re-highlight, as necessary. For hover, there's a delay; for focus, jump 204 // Re-highlight, as necessary. For hover, there's a delay; for focus, jump
201 // straight into the animation. 205 // straight into the animation.
202 if (is_focused_) 206 if (!IsHighlightFadingInOrVisible()) {
203 HighlightAfterRippleTimerFired(); 207 if (is_focused_)
204 else if (is_hovered_) 208 HighlightAfterRippleTimerFired();
205 StartHighlightAfterRippleTimer(); 209 else if (is_hovered_)
210 StartHighlightAfterRippleTimer();
211 }
206 212
207 // TODO(bruthig): Investigate whether creating and destroying 213 // TODO(bruthig): Investigate whether creating and destroying
208 // InkDropRipples is expensive and consider creating an 214 // InkDropRipples is expensive and consider creating an
209 // InkDropRipplePool. See www.crbug.com/522175. 215 // InkDropRipplePool. See www.crbug.com/522175.
210 DestroyInkDropRipple(); 216 DestroyInkDropRipple();
211 } 217 }
212 } 218 }
213 219
214 // ----------------------------------------------------------------------------- 220 // -----------------------------------------------------------------------------
215 // views::InkDropHighlightObserver: 221 // views::InkDropHighlightObserver:
(...skipping 12 matching lines...) Expand all
228 void InkDropImpl::SetHighlight(bool should_highlight, 234 void InkDropImpl::SetHighlight(bool should_highlight,
229 base::TimeDelta animation_duration, 235 base::TimeDelta animation_duration,
230 bool explode) { 236 bool explode) {
231 highlight_after_ripple_timer_.reset(); 237 highlight_after_ripple_timer_.reset();
232 238
233 if (IsHighlightFadingInOrVisible() == should_highlight) 239 if (IsHighlightFadingInOrVisible() == should_highlight)
234 return; 240 return;
235 241
236 if (should_highlight) { 242 if (should_highlight) {
237 CreateInkDropHighlight(); 243 CreateInkDropHighlight();
238 if (highlight_ && !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible())) 244 if (highlight_ &&
245 !(ink_drop_ripple_ && ink_drop_ripple_->IsVisible() &&
246 ink_drop_ripple_->OverridesHighlight())) {
239 highlight_->FadeIn(animation_duration); 247 highlight_->FadeIn(animation_duration);
248 }
240 } else { 249 } else {
241 highlight_->FadeOut(animation_duration, explode); 250 highlight_->FadeOut(animation_duration, explode);
242 } 251 }
243 } 252 }
244 253
245 bool InkDropImpl::ShouldHighlight() const { 254 bool InkDropImpl::ShouldHighlight() const {
246 return is_focused_ || is_hovered_; 255 return is_focused_ || is_hovered_;
247 } 256 }
248 257
249 void InkDropImpl::StartHighlightAfterRippleTimer() { 258 void InkDropImpl::StartHighlightAfterRippleTimer() {
250 highlight_after_ripple_timer_.reset(new base::OneShotTimer); 259 highlight_after_ripple_timer_.reset(new base::OneShotTimer);
251 highlight_after_ripple_timer_->Start( 260 highlight_after_ripple_timer_->Start(
252 FROM_HERE, 261 FROM_HERE,
253 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayMs), 262 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayMs),
254 base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired, 263 base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired,
255 base::Unretained(this))); 264 base::Unretained(this)));
256 } 265 }
257 266
258 void InkDropImpl::HighlightAfterRippleTimerFired() { 267 void InkDropImpl::HighlightAfterRippleTimerFired() {
259 SetHighlight(true, base::TimeDelta::FromMilliseconds( 268 SetHighlight(true, base::TimeDelta::FromMilliseconds(
260 kHighlightFadeInAfterRippleDurationMs), 269 kHighlightFadeInAfterRippleDurationMs),
261 true); 270 true);
262 highlight_after_ripple_timer_.reset(); 271 highlight_after_ripple_timer_.reset();
263 } 272 }
264 273
265 } // namespace views 274 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/flood_fill_ink_drop_ripple.cc ('k') | ui/views/animation/ink_drop_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698