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

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

Issue 1937353002: Rename of InkDropAnimationController classes to InkDrop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed tdanderson@ comments from patch set 2. Created 4 years, 7 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_impl.h ('k') | ui/views/animation/ink_drop_impl_unittest.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 #include "ui/views/animation/ink_drop_animation_controller_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_host.h" 10 #include "ui/views/animation/ink_drop_host.h"
11 #include "ui/views/animation/ink_drop_hover.h" 11 #include "ui/views/animation/ink_drop_hover.h"
12 #include "ui/views/animation/square_ink_drop_ripple.h" 12 #include "ui/views/animation/square_ink_drop_ripple.h"
13 13
14 namespace views { 14 namespace views {
15 15
(...skipping 27 matching lines...) Expand all
43 case views::InkDropState::ALTERNATE_ACTION_TRIGGERED: 43 case views::InkDropState::ALTERNATE_ACTION_TRIGGERED:
44 case views::InkDropState::DEACTIVATED: 44 case views::InkDropState::DEACTIVATED:
45 return true; 45 return true;
46 default: 46 default:
47 return false; 47 return false;
48 } 48 }
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( 53 InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host)
54 InkDropHost* ink_drop_host)
55 : ink_drop_host_(ink_drop_host), 54 : ink_drop_host_(ink_drop_host),
56 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), 55 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
57 root_layer_added_to_host_(false), 56 root_layer_added_to_host_(false),
58 is_hovered_(false), 57 is_hovered_(false),
59 hover_after_ripple_timer_(nullptr) { 58 hover_after_ripple_timer_(nullptr) {
60 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer"); 59 root_layer_->set_name("InkDropImpl:RootLayer");
61 } 60 }
62 61
63 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { 62 InkDropImpl::~InkDropImpl() {
64 // Explicitly destroy the InkDropRipple so that this still exists if 63 // Explicitly destroy the InkDropRipple so that this still exists if
65 // views::InkDropRippleObserver methods are called on this. 64 // views::InkDropRippleObserver methods are called on this.
66 DestroyInkDropRipple(); 65 DestroyInkDropRipple();
67 DestroyInkDropHover(); 66 DestroyInkDropHover();
68 } 67 }
69 68
70 InkDropState InkDropAnimationControllerImpl::GetTargetInkDropState() const { 69 InkDropState InkDropImpl::GetTargetInkDropState() const {
71 if (!ink_drop_ripple_) 70 if (!ink_drop_ripple_)
72 return InkDropState::HIDDEN; 71 return InkDropState::HIDDEN;
73 return ink_drop_ripple_->target_ink_drop_state(); 72 return ink_drop_ripple_->target_ink_drop_state();
74 } 73 }
75 74
76 bool InkDropAnimationControllerImpl::IsVisible() const { 75 bool InkDropImpl::IsVisible() const {
77 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible(); 76 return ink_drop_ripple_ && ink_drop_ripple_->IsVisible();
78 } 77 }
79 78
80 void InkDropAnimationControllerImpl::AnimateToState( 79 void InkDropImpl::AnimateToState(InkDropState ink_drop_state) {
81 InkDropState ink_drop_state) {
82 DestroyHiddenTargetedAnimations(); 80 DestroyHiddenTargetedAnimations();
83 if (!ink_drop_ripple_) 81 if (!ink_drop_ripple_)
84 CreateInkDropRipple(); 82 CreateInkDropRipple();
85 83
86 if (ink_drop_state != views::InkDropState::HIDDEN) { 84 if (ink_drop_state != views::InkDropState::HIDDEN) {
87 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( 85 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds(
88 kHoverFadeOutBeforeRippleDurationInMs), 86 kHoverFadeOutBeforeRippleDurationInMs),
89 true); 87 true);
90 } 88 }
91 89
92 ink_drop_ripple_->AnimateToState(ink_drop_state); 90 ink_drop_ripple_->AnimateToState(ink_drop_state);
93 } 91 }
94 92
95 void InkDropAnimationControllerImpl::SnapToActivated() { 93 void InkDropImpl::SnapToActivated() {
96 DestroyHiddenTargetedAnimations(); 94 DestroyHiddenTargetedAnimations();
97 if (!ink_drop_ripple_) 95 if (!ink_drop_ripple_)
98 CreateInkDropRipple(); 96 CreateInkDropRipple();
99 97
100 SetHoveredInternal(false, base::TimeDelta(), false); 98 SetHoveredInternal(false, base::TimeDelta(), false);
101 99
102 ink_drop_ripple_->SnapToActivated(); 100 ink_drop_ripple_->SnapToActivated();
103 } 101 }
104 102
105 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { 103 void InkDropImpl::SetHovered(bool is_hovered) {
106 is_hovered_ = is_hovered; 104 is_hovered_ = is_hovered;
107 SetHoveredInternal(is_hovered, 105 SetHoveredInternal(is_hovered,
108 is_hovered ? base::TimeDelta::FromMilliseconds( 106 is_hovered ? base::TimeDelta::FromMilliseconds(
109 kHoverFadeInFromUserInputDurationInMs) 107 kHoverFadeInFromUserInputDurationInMs)
110 : base::TimeDelta::FromMilliseconds( 108 : base::TimeDelta::FromMilliseconds(
111 kHoverFadeOutFromUserInputDurationInMs), 109 kHoverFadeOutFromUserInputDurationInMs),
112 false); 110 false);
113 } 111 }
114 112
115 void InkDropAnimationControllerImpl::DestroyHiddenTargetedAnimations() { 113 void InkDropImpl::DestroyHiddenTargetedAnimations() {
116 if (ink_drop_ripple_ && 114 if (ink_drop_ripple_ &&
117 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || 115 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN ||
118 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { 116 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) {
119 DestroyInkDropRipple(); 117 DestroyInkDropRipple();
120 } 118 }
121 } 119 }
122 120
123 void InkDropAnimationControllerImpl::CreateInkDropRipple() { 121 void InkDropImpl::CreateInkDropRipple() {
124 DestroyInkDropRipple(); 122 DestroyInkDropRipple();
125 ink_drop_ripple_ = ink_drop_host_->CreateInkDropRipple(); 123 ink_drop_ripple_ = ink_drop_host_->CreateInkDropRipple();
126 ink_drop_ripple_->set_observer(this); 124 ink_drop_ripple_->set_observer(this);
127 root_layer_->Add(ink_drop_ripple_->GetRootLayer()); 125 root_layer_->Add(ink_drop_ripple_->GetRootLayer());
128 AddRootLayerToHostIfNeeded(); 126 AddRootLayerToHostIfNeeded();
129 } 127 }
130 128
131 void InkDropAnimationControllerImpl::DestroyInkDropRipple() { 129 void InkDropImpl::DestroyInkDropRipple() {
132 if (!ink_drop_ripple_) 130 if (!ink_drop_ripple_)
133 return; 131 return;
134 root_layer_->Remove(ink_drop_ripple_->GetRootLayer()); 132 root_layer_->Remove(ink_drop_ripple_->GetRootLayer());
135 ink_drop_ripple_.reset(); 133 ink_drop_ripple_.reset();
136 RemoveRootLayerFromHostIfNeeded(); 134 RemoveRootLayerFromHostIfNeeded();
137 } 135 }
138 136
139 void InkDropAnimationControllerImpl::CreateInkDropHover() { 137 void InkDropImpl::CreateInkDropHover() {
140 DestroyInkDropHover(); 138 DestroyInkDropHover();
141 139
142 hover_ = ink_drop_host_->CreateInkDropHover(); 140 hover_ = ink_drop_host_->CreateInkDropHover();
143 if (!hover_) 141 if (!hover_)
144 return; 142 return;
145 hover_->set_observer(this); 143 hover_->set_observer(this);
146 root_layer_->Add(hover_->layer()); 144 root_layer_->Add(hover_->layer());
147 AddRootLayerToHostIfNeeded(); 145 AddRootLayerToHostIfNeeded();
148 } 146 }
149 147
150 void InkDropAnimationControllerImpl::DestroyInkDropHover() { 148 void InkDropImpl::DestroyInkDropHover() {
151 if (!hover_) 149 if (!hover_)
152 return; 150 return;
153 root_layer_->Remove(hover_->layer()); 151 root_layer_->Remove(hover_->layer());
154 hover_->set_observer(nullptr); 152 hover_->set_observer(nullptr);
155 hover_.reset(); 153 hover_.reset();
156 RemoveRootLayerFromHostIfNeeded(); 154 RemoveRootLayerFromHostIfNeeded();
157 } 155 }
158 156
159 void InkDropAnimationControllerImpl::AddRootLayerToHostIfNeeded() { 157 void InkDropImpl::AddRootLayerToHostIfNeeded() {
160 DCHECK(hover_ || ink_drop_ripple_); 158 DCHECK(hover_ || ink_drop_ripple_);
161 if (!root_layer_added_to_host_) { 159 if (!root_layer_added_to_host_) {
162 root_layer_added_to_host_ = true; 160 root_layer_added_to_host_ = true;
163 ink_drop_host_->AddInkDropLayer(root_layer_.get()); 161 ink_drop_host_->AddInkDropLayer(root_layer_.get());
164 } 162 }
165 } 163 }
166 164
167 void InkDropAnimationControllerImpl::RemoveRootLayerFromHostIfNeeded() { 165 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() {
168 if (root_layer_added_to_host_ && !hover_ && !ink_drop_ripple_) { 166 if (root_layer_added_to_host_ && !hover_ && !ink_drop_ripple_) {
169 root_layer_added_to_host_ = false; 167 root_layer_added_to_host_ = false;
170 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 168 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
171 } 169 }
172 } 170 }
173 171
174 bool InkDropAnimationControllerImpl::IsHoverFadingInOrVisible() const { 172 bool InkDropImpl::IsHoverFadingInOrVisible() const {
175 return hover_ && hover_->IsFadingInOrVisible(); 173 return hover_ && hover_->IsFadingInOrVisible();
176 } 174 }
177 175
178 // ----------------------------------------------------------------------------- 176 // -----------------------------------------------------------------------------
179 // views::InkDropRippleObserver: 177 // views::InkDropRippleObserver:
180 178
181 void InkDropAnimationControllerImpl::AnimationStarted( 179 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) {}
182 InkDropState ink_drop_state) {}
183 180
184 void InkDropAnimationControllerImpl::AnimationEnded( 181 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state,
185 InkDropState ink_drop_state, 182 InkDropAnimationEndedReason reason) {
186 InkDropAnimationEndedReason reason) {
187 if (reason != InkDropAnimationEndedReason::SUCCESS) 183 if (reason != InkDropAnimationEndedReason::SUCCESS)
188 return; 184 return;
189 if (ShouldAnimateToHidden(ink_drop_state)) { 185 if (ShouldAnimateToHidden(ink_drop_state)) {
190 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); 186 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN);
191 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 187 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
192 if (is_hovered_) 188 if (is_hovered_)
193 StartHoverAfterRippleTimer(); 189 StartHoverAfterRippleTimer();
194 // TODO(bruthig): Investigate whether creating and destroying 190 // TODO(bruthig): Investigate whether creating and destroying
195 // InkDropRipples is expensive and consider creating an 191 // InkDropRipples is expensive and consider creating an
196 // InkDropRipplePool. See www.crbug.com/522175. 192 // InkDropRipplePool. See www.crbug.com/522175.
197 DestroyInkDropRipple(); 193 DestroyInkDropRipple();
198 } 194 }
199 } 195 }
200 196
201 // ----------------------------------------------------------------------------- 197 // -----------------------------------------------------------------------------
202 // views::InkDropHoverObserver: 198 // views::InkDropHoverObserver:
203 199
204 void InkDropAnimationControllerImpl::AnimationStarted( 200 void InkDropImpl::AnimationStarted(InkDropHover::AnimationType animation_type) {
205 InkDropHover::AnimationType animation_type) {} 201 }
206 202
207 void InkDropAnimationControllerImpl::AnimationEnded( 203 void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type,
208 InkDropHover::AnimationType animation_type, 204 InkDropAnimationEndedReason reason) {
209 InkDropAnimationEndedReason reason) {
210 if (animation_type == InkDropHover::FADE_OUT && 205 if (animation_type == InkDropHover::FADE_OUT &&
211 reason == InkDropAnimationEndedReason::SUCCESS) { 206 reason == InkDropAnimationEndedReason::SUCCESS) {
212 DestroyInkDropHover(); 207 DestroyInkDropHover();
213 } 208 }
214 } 209 }
215 210
216 void InkDropAnimationControllerImpl::SetHoveredInternal( 211 void InkDropImpl::SetHoveredInternal(bool is_hovered,
217 bool is_hovered, 212 base::TimeDelta animation_duration,
218 base::TimeDelta animation_duration, 213 bool explode) {
219 bool explode) {
220 StopHoverAfterRippleTimer(); 214 StopHoverAfterRippleTimer();
221 215
222 if (IsHoverFadingInOrVisible() == is_hovered) 216 if (IsHoverFadingInOrVisible() == is_hovered)
223 return; 217 return;
224 218
225 if (is_hovered) { 219 if (is_hovered) {
226 CreateInkDropHover(); 220 CreateInkDropHover();
227 if (hover_ && !IsVisible()) 221 if (hover_ && !IsVisible())
228 hover_->FadeIn(animation_duration); 222 hover_->FadeIn(animation_duration);
229 } else { 223 } else {
230 hover_->FadeOut(animation_duration, explode); 224 hover_->FadeOut(animation_duration, explode);
231 } 225 }
232 } 226 }
233 227
234 void InkDropAnimationControllerImpl::StartHoverAfterRippleTimer() { 228 void InkDropImpl::StartHoverAfterRippleTimer() {
235 StopHoverAfterRippleTimer(); 229 StopHoverAfterRippleTimer();
236 230
237 if (!hover_after_ripple_timer_) 231 if (!hover_after_ripple_timer_)
238 hover_after_ripple_timer_.reset(new base::OneShotTimer); 232 hover_after_ripple_timer_.reset(new base::OneShotTimer);
239 233
240 hover_after_ripple_timer_->Start( 234 hover_after_ripple_timer_->Start(
241 FROM_HERE, 235 FROM_HERE,
242 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs), 236 base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs),
243 base::Bind(&InkDropAnimationControllerImpl::HoverAfterRippleTimerFired, 237 base::Bind(&InkDropImpl::HoverAfterRippleTimerFired,
244 base::Unretained(this))); 238 base::Unretained(this)));
245 } 239 }
246 240
247 void InkDropAnimationControllerImpl::StopHoverAfterRippleTimer() { 241 void InkDropImpl::StopHoverAfterRippleTimer() {
248 if (hover_after_ripple_timer_) 242 if (hover_after_ripple_timer_)
249 hover_after_ripple_timer_.reset(); 243 hover_after_ripple_timer_.reset();
250 } 244 }
251 245
252 void InkDropAnimationControllerImpl::HoverAfterRippleTimerFired() { 246 void InkDropImpl::HoverAfterRippleTimerFired() {
253 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( 247 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds(
254 kHoverFadeInAfterRippleDurationInMs), 248 kHoverFadeInAfterRippleDurationInMs),
255 true); 249 true);
256 hover_after_ripple_timer_.reset(); 250 hover_after_ripple_timer_.reset();
257 } 251 }
258 252
259 } // namespace views 253 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_impl.h ('k') | ui/views/animation/ink_drop_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698