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

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

Issue 1937103003: Rename of InkDropAnimation classes to InkDropRipple. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed test_ink_drop_animation_observer.h from views.gyp and doc update. 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/flood_fill_ink_drop_animation.h" 5 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/compositor/layer.h" 11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_sequence.h" 12 #include "ui/compositor/layer_animation_sequence.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/geometry/point_conversions.h" 14 #include "ui/gfx/geometry/point_conversions.h"
15 #include "ui/gfx/geometry/vector2d_f.h" 15 #include "ui/gfx/geometry/vector2d_f.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 200, // ALTERNATE_ACTION_PENDING 89 200, // ALTERNATE_ACTION_PENDING
90 300, // ALTERNATE_ACTION_TRIGGERED_FADE_OUT 90 300, // ALTERNATE_ACTION_TRIGGERED_FADE_OUT
91 150, // ACTIVATED_FADE_IN 91 150, // ACTIVATED_FADE_IN
92 200, // ACTIVATED_TRANSFORM 92 200, // ACTIVATED_TRANSFORM
93 300, // DEACTIVATED_FADE_OUT 93 300, // DEACTIVATED_FADE_OUT
94 }; 94 };
95 95
96 // Returns the InkDropState sub animation duration for the given |state|. 96 // Returns the InkDropState sub animation duration for the given |state|.
97 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { 97 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
98 return base::TimeDelta::FromMilliseconds( 98 return base::TimeDelta::FromMilliseconds(
99 (views::InkDropAnimation::UseFastAnimations() 99 (views::InkDropRipple::UseFastAnimations()
100 ? 1 100 ? 1
101 : views::InkDropAnimation::kSlowAnimationDurationFactor) * 101 : views::InkDropRipple::kSlowAnimationDurationFactor) *
102 kAnimationDurationInMs[state]); 102 kAnimationDurationInMs[state]);
103 } 103 }
104 104
105 } // namespace 105 } // namespace
106 106
107 namespace views { 107 namespace views {
108 108
109 FloodFillInkDropAnimation::FloodFillInkDropAnimation( 109 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Rect& clip_bounds,
110 const gfx::Rect& clip_bounds, 110 const gfx::Point& center_point,
111 const gfx::Point& center_point, 111 SkColor color)
112 SkColor color)
113 : clip_bounds_(clip_bounds), 112 : clip_bounds_(clip_bounds),
114 center_point_(center_point), 113 center_point_(center_point),
115 root_layer_(ui::LAYER_NOT_DRAWN), 114 root_layer_(ui::LAYER_NOT_DRAWN),
116 circle_layer_delegate_( 115 circle_layer_delegate_(
117 color, 116 color,
118 std::max(clip_bounds_.width(), clip_bounds_.height()) / 2.f), 117 std::max(clip_bounds_.width(), clip_bounds_.height()) / 2.f),
119 ink_drop_state_(InkDropState::HIDDEN) { 118 ink_drop_state_(InkDropState::HIDDEN) {
120 root_layer_.set_name("FloodFillInkDropAnimation:ROOT_LAYER"); 119 root_layer_.set_name("FloodFillInkDropRipple:ROOT_LAYER");
121 root_layer_.SetMasksToBounds(true); 120 root_layer_.SetMasksToBounds(true);
122 root_layer_.SetBounds(clip_bounds); 121 root_layer_.SetBounds(clip_bounds);
123 122
124 const int painted_size_length = 123 const int painted_size_length =
125 2 * std::max(clip_bounds_.width(), clip_bounds_.height()); 124 2 * std::max(clip_bounds_.width(), clip_bounds_.height());
126 125
127 painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length)); 126 painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length));
128 painted_layer_.SetFillsBoundsOpaquely(false); 127 painted_layer_.SetFillsBoundsOpaquely(false);
129 painted_layer_.set_delegate(&circle_layer_delegate_); 128 painted_layer_.set_delegate(&circle_layer_delegate_);
130 painted_layer_.SetVisible(true); 129 painted_layer_.SetVisible(true);
131 painted_layer_.SetOpacity(1.0); 130 painted_layer_.SetOpacity(1.0);
132 painted_layer_.SetMasksToBounds(false); 131 painted_layer_.SetMasksToBounds(false);
133 painted_layer_.set_name("FloodFillInkDropAnimation:PAINTED_LAYER"); 132 painted_layer_.set_name("FloodFillInkDropRipple:PAINTED_LAYER");
134 133
135 root_layer_.Add(&painted_layer_); 134 root_layer_.Add(&painted_layer_);
136 135
137 SetStateToHidden(); 136 SetStateToHidden();
138 } 137 }
139 138
140 FloodFillInkDropAnimation::~FloodFillInkDropAnimation() { 139 FloodFillInkDropRipple::~FloodFillInkDropRipple() {
141 // Explicitly aborting all the animations ensures all callbacks are invoked 140 // Explicitly aborting all the animations ensures all callbacks are invoked
142 // while this instance still exists. 141 // while this instance still exists.
143 AbortAllAnimations(); 142 AbortAllAnimations();
144 } 143 }
145 144
146 void FloodFillInkDropAnimation::SnapToActivated() { 145 void FloodFillInkDropRipple::SnapToActivated() {
147 InkDropAnimation::SnapToActivated(); 146 InkDropRipple::SnapToActivated();
148 SetOpacity(kVisibleOpacity); 147 SetOpacity(kVisibleOpacity);
149 painted_layer_.SetTransform(GetMaxSizeTargetTransform()); 148 painted_layer_.SetTransform(GetMaxSizeTargetTransform());
150 } 149 }
151 150
152 ui::Layer* FloodFillInkDropAnimation::GetRootLayer() { 151 ui::Layer* FloodFillInkDropRipple::GetRootLayer() {
153 return &root_layer_; 152 return &root_layer_;
154 } 153 }
155 154
156 bool FloodFillInkDropAnimation::IsVisible() const { 155 bool FloodFillInkDropRipple::IsVisible() const {
157 return root_layer_.visible(); 156 return root_layer_.visible();
158 } 157 }
159 158
160 void FloodFillInkDropAnimation::AnimateStateChange( 159 void FloodFillInkDropRipple::AnimateStateChange(
161 InkDropState old_ink_drop_state, 160 InkDropState old_ink_drop_state,
162 InkDropState new_ink_drop_state, 161 InkDropState new_ink_drop_state,
163 ui::LayerAnimationObserver* animation_observer) { 162 ui::LayerAnimationObserver* animation_observer) {
164 switch (new_ink_drop_state) { 163 switch (new_ink_drop_state) {
165 case InkDropState::HIDDEN: 164 case InkDropState::HIDDEN:
166 if (!IsVisible()) { 165 if (!IsVisible()) {
167 SetStateToHidden(); 166 SetStateToHidden();
168 } else { 167 } else {
169 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT), 168 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT),
170 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 169 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 237 }
239 case InkDropState::DEACTIVATED: 238 case InkDropState::DEACTIVATED:
240 AnimateToOpacity(kHiddenOpacity, 239 AnimateToOpacity(kHiddenOpacity,
241 GetAnimationDuration(DEACTIVATED_FADE_OUT), 240 GetAnimationDuration(DEACTIVATED_FADE_OUT),
242 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 241 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
243 gfx::Tween::EASE_IN_OUT, animation_observer); 242 gfx::Tween::EASE_IN_OUT, animation_observer);
244 break; 243 break;
245 } 244 }
246 } 245 }
247 246
248 void FloodFillInkDropAnimation::SetStateToHidden() { 247 void FloodFillInkDropRipple::SetStateToHidden() {
249 painted_layer_.SetTransform(CalculateTransform(kMinRadius)); 248 painted_layer_.SetTransform(CalculateTransform(kMinRadius));
250 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity); 249 root_layer_.SetOpacity(InkDropRipple::kHiddenOpacity);
251 root_layer_.SetVisible(false); 250 root_layer_.SetVisible(false);
252 } 251 }
253 252
254 void FloodFillInkDropAnimation::AbortAllAnimations() { 253 void FloodFillInkDropRipple::AbortAllAnimations() {
255 root_layer_.GetAnimator()->AbortAllAnimations(); 254 root_layer_.GetAnimator()->AbortAllAnimations();
256 painted_layer_.GetAnimator()->AbortAllAnimations(); 255 painted_layer_.GetAnimator()->AbortAllAnimations();
257 } 256 }
258 257
259 void FloodFillInkDropAnimation::AnimateToTransform( 258 void FloodFillInkDropRipple::AnimateToTransform(
260 const gfx::Transform& transform, 259 const gfx::Transform& transform,
261 base::TimeDelta duration, 260 base::TimeDelta duration,
262 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 261 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
263 gfx::Tween::Type tween, 262 gfx::Tween::Type tween,
264 ui::LayerAnimationObserver* animation_observer) { 263 ui::LayerAnimationObserver* animation_observer) {
265 ui::LayerAnimator* animator = painted_layer_.GetAnimator(); 264 ui::LayerAnimator* animator = painted_layer_.GetAnimator();
266 ui::ScopedLayerAnimationSettings animation(animator); 265 ui::ScopedLayerAnimationSettings animation(animator);
267 animation.SetPreemptionStrategy(preemption_strategy); 266 animation.SetPreemptionStrategy(preemption_strategy);
268 animation.SetTweenType(tween); 267 animation.SetTweenType(tween);
269 ui::LayerAnimationElement* element = 268 ui::LayerAnimationElement* element =
270 ui::LayerAnimationElement::CreateTransformElement(transform, duration); 269 ui::LayerAnimationElement::CreateTransformElement(transform, duration);
271 ui::LayerAnimationSequence* sequence = 270 ui::LayerAnimationSequence* sequence =
272 new ui::LayerAnimationSequence(element); 271 new ui::LayerAnimationSequence(element);
273 272
274 if (animation_observer) 273 if (animation_observer)
275 sequence->AddObserver(animation_observer); 274 sequence->AddObserver(animation_observer);
276 275
277 animator->StartAnimation(sequence); 276 animator->StartAnimation(sequence);
278 } 277 }
279 278
280 void FloodFillInkDropAnimation::SetOpacity(float opacity) { 279 void FloodFillInkDropRipple::SetOpacity(float opacity) {
281 root_layer_.SetOpacity(opacity); 280 root_layer_.SetOpacity(opacity);
282 } 281 }
283 282
284 void FloodFillInkDropAnimation::AnimateToOpacity( 283 void FloodFillInkDropRipple::AnimateToOpacity(
285 float opacity, 284 float opacity,
286 base::TimeDelta duration, 285 base::TimeDelta duration,
287 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 286 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
288 gfx::Tween::Type tween, 287 gfx::Tween::Type tween,
289 ui::LayerAnimationObserver* animation_observer) { 288 ui::LayerAnimationObserver* animation_observer) {
290 ui::LayerAnimator* animator = root_layer_.GetAnimator(); 289 ui::LayerAnimator* animator = root_layer_.GetAnimator();
291 ui::ScopedLayerAnimationSettings animation_settings(animator); 290 ui::ScopedLayerAnimationSettings animation_settings(animator);
292 animation_settings.SetPreemptionStrategy(preemption_strategy); 291 animation_settings.SetPreemptionStrategy(preemption_strategy);
293 animation_settings.SetTweenType(tween); 292 animation_settings.SetTweenType(tween);
294 ui::LayerAnimationElement* animation_element = 293 ui::LayerAnimationElement* animation_element =
295 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); 294 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
296 ui::LayerAnimationSequence* animation_sequence = 295 ui::LayerAnimationSequence* animation_sequence =
297 new ui::LayerAnimationSequence(animation_element); 296 new ui::LayerAnimationSequence(animation_element);
298 297
299 if (animation_observer) 298 if (animation_observer)
300 animation_sequence->AddObserver(animation_observer); 299 animation_sequence->AddObserver(animation_observer);
301 300
302 animator->StartAnimation(animation_sequence); 301 animator->StartAnimation(animation_sequence);
303 } 302 }
304 303
305 gfx::Transform FloodFillInkDropAnimation::CalculateTransform( 304 gfx::Transform FloodFillInkDropRipple::CalculateTransform(
306 float target_radius) const { 305 float target_radius) const {
307 const float target_scale = target_radius / circle_layer_delegate_.radius(); 306 const float target_scale = target_radius / circle_layer_delegate_.radius();
308 const gfx::Point drawn_center_point = 307 const gfx::Point drawn_center_point =
309 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint()); 308 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint());
310 309
311 gfx::Transform transform = gfx::Transform(); 310 gfx::Transform transform = gfx::Transform();
312 transform.Translate(center_point_.x(), center_point_.y()); 311 transform.Translate(center_point_.x(), center_point_.y());
313 transform.Scale(target_scale, target_scale); 312 transform.Scale(target_scale, target_scale);
314 transform.Translate(-drawn_center_point.x() - root_layer_.bounds().x(), 313 transform.Translate(-drawn_center_point.x() - root_layer_.bounds().x(),
315 -drawn_center_point.y() - root_layer_.bounds().y()); 314 -drawn_center_point.y() - root_layer_.bounds().y());
316 315
317 return transform; 316 return transform;
318 } 317 }
319 318
320 gfx::Transform FloodFillInkDropAnimation::GetMaxSizeTargetTransform() const { 319 gfx::Transform FloodFillInkDropRipple::GetMaxSizeTargetTransform() const {
321 // TODO(estade): get rid of this 2, but make the fade out start before the 320 // TODO(estade): get rid of this 2, but make the fade out start before the
322 // active/action transform is done. 321 // active/action transform is done.
323 return CalculateTransform( 322 return CalculateTransform(
324 gfx::Vector2dF(clip_bounds_.width(), clip_bounds_.height()).Length() / 2); 323 gfx::Vector2dF(clip_bounds_.width(), clip_bounds_.height()).Length() / 2);
325 } 324 }
326 325
327 } // namespace views 326 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/flood_fill_ink_drop_ripple.h ('k') | ui/views/animation/ink_drop_animation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698