| OLD | NEW |
| 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/square_ink_drop_animation.h" | 5 #include "ui/views/animation/square_ink_drop_animation.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // The minimum scale factor to use when scaling rectangle layers. Smaller values | 27 // The minimum scale factor to use when scaling rectangle layers. Smaller values |
| 28 // were causing visual anomalies. | 28 // were causing visual anomalies. |
| 29 const float kMinimumRectScale = 0.0001f; | 29 const float kMinimumRectScale = 0.0001f; |
| 30 | 30 |
| 31 // The minimum scale factor to use when scaling circle layers. Smaller values | 31 // The minimum scale factor to use when scaling circle layers. Smaller values |
| 32 // were causing visual anomalies. | 32 // were causing visual anomalies. |
| 33 const float kMinimumCircleScale = 0.001f; | 33 const float kMinimumCircleScale = 0.001f; |
| 34 | 34 |
| 35 // The ink drop color. | |
| 36 const SkColor kInkDropColor = SK_ColorBLACK; | |
| 37 | |
| 38 // All the sub animations that are used to animate each of the InkDropStates. | 35 // All the sub animations that are used to animate each of the InkDropStates. |
| 39 // These are used to get time durations with | 36 // These are used to get time durations with |
| 40 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub | 37 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub |
| 41 // animation defines the duration for either a transformation animation or an | 38 // animation defines the duration for either a transformation animation or an |
| 42 // opacity animation but there are some exceptions where an entire InkDropState | 39 // opacity animation but there are some exceptions where an entire InkDropState |
| 43 // animation consists of only 1 sub animation and it defines the duration for | 40 // animation consists of only 1 sub animation and it defines the duration for |
| 44 // both the transformation and opacity animations. | 41 // both the transformation and opacity animations. |
| 45 enum InkDropSubAnimations { | 42 enum InkDropSubAnimations { |
| 46 // HIDDEN sub animations. | 43 // HIDDEN sub animations. |
| 47 | 44 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 return transform; | 170 return transform; |
| 174 } | 171 } |
| 175 | 172 |
| 176 } // namespace | 173 } // namespace |
| 177 | 174 |
| 178 namespace views { | 175 namespace views { |
| 179 | 176 |
| 180 SquareInkDropAnimation::SquareInkDropAnimation(const gfx::Size& large_size, | 177 SquareInkDropAnimation::SquareInkDropAnimation(const gfx::Size& large_size, |
| 181 int large_corner_radius, | 178 int large_corner_radius, |
| 182 const gfx::Size& small_size, | 179 const gfx::Size& small_size, |
| 183 int small_corner_radius) | 180 int small_corner_radius, |
| 181 const gfx::Point& center_point, |
| 182 SkColor color) |
| 184 : large_size_(large_size), | 183 : large_size_(large_size), |
| 185 large_corner_radius_(large_corner_radius), | 184 large_corner_radius_(large_corner_radius), |
| 186 small_size_(small_size), | 185 small_size_(small_size), |
| 187 small_corner_radius_(small_corner_radius), | 186 small_corner_radius_(small_corner_radius), |
| 188 circle_layer_delegate_(new CircleLayerDelegate( | 187 circle_layer_delegate_(new CircleLayerDelegate( |
| 189 kInkDropColor, | 188 color, |
| 190 std::min(large_size_.width(), large_size_.height()) / 2)), | 189 std::min(large_size_.width(), large_size_.height()) / 2)), |
| 191 rect_layer_delegate_( | 190 rect_layer_delegate_(new RectangleLayerDelegate(color, large_size_)), |
| 192 new RectangleLayerDelegate(kInkDropColor, large_size_)), | |
| 193 root_layer_(ui::LAYER_NOT_DRAWN), | 191 root_layer_(ui::LAYER_NOT_DRAWN), |
| 194 ink_drop_state_(InkDropState::HIDDEN) { | 192 ink_drop_state_(InkDropState::HIDDEN) { |
| 195 root_layer_.set_name("SquareInkDropAnimation:ROOT_LAYER"); | 193 root_layer_.set_name("SquareInkDropAnimation:ROOT_LAYER"); |
| 196 | 194 |
| 197 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 195 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
| 198 AddPaintLayer(static_cast<PaintedShape>(i)); | 196 AddPaintLayer(static_cast<PaintedShape>(i)); |
| 199 | 197 |
| 200 root_layer_.SetMasksToBounds(false); | 198 root_layer_.SetMasksToBounds(false); |
| 201 root_layer_.SetBounds(gfx::Rect(large_size_)); | 199 root_layer_.SetBounds(gfx::Rect(large_size_)); |
| 202 | 200 |
| 201 gfx::Transform transform; |
| 202 transform.Translate(center_point.x(), center_point.y()); |
| 203 root_layer_.SetTransform(transform); |
| 204 |
| 203 SetStateToHidden(); | 205 SetStateToHidden(); |
| 204 } | 206 } |
| 205 | 207 |
| 206 SquareInkDropAnimation::~SquareInkDropAnimation() { | 208 SquareInkDropAnimation::~SquareInkDropAnimation() { |
| 207 // Explicitly aborting all the animations ensures all callbacks are invoked | 209 // Explicitly aborting all the animations ensures all callbacks are invoked |
| 208 // while this instance still exists. | 210 // while this instance still exists. |
| 209 AbortAllAnimations(); | 211 AbortAllAnimations(); |
| 210 } | 212 } |
| 211 | 213 |
| 212 ui::Layer* SquareInkDropAnimation::GetRootLayer() { | 214 ui::Layer* SquareInkDropAnimation::GetRootLayer() { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // the target InkDropState when calling GetInkDropState(). | 252 // the target InkDropState when calling GetInkDropState(). |
| 251 ink_drop_state_ = ink_drop_state; | 253 ink_drop_state_ = ink_drop_state; |
| 252 | 254 |
| 253 if (old_ink_drop_state == InkDropState::HIDDEN && | 255 if (old_ink_drop_state == InkDropState::HIDDEN && |
| 254 ink_drop_state_ != InkDropState::HIDDEN) { | 256 ink_drop_state_ != InkDropState::HIDDEN) { |
| 255 root_layer_.SetVisible(true); | 257 root_layer_.SetVisible(true); |
| 256 } | 258 } |
| 257 | 259 |
| 258 AnimateStateChange(old_ink_drop_state, ink_drop_state_, animation_observer); | 260 AnimateStateChange(old_ink_drop_state, ink_drop_state_, animation_observer); |
| 259 animation_observer->SetActive(); | 261 animation_observer->SetActive(); |
| 260 } | 262 // |this| may be deleted! |animation_observer| might synchronously call |
| 261 | 263 // AnimationEndedCallback which can delete |this|. |
| 262 void SquareInkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { | |
| 263 gfx::Transform transform; | |
| 264 transform.Translate(center_point.x(), center_point.y()); | |
| 265 root_layer_.SetTransform(transform); | |
| 266 } | 264 } |
| 267 | 265 |
| 268 void SquareInkDropAnimation::HideImmediately() { | 266 void SquareInkDropAnimation::HideImmediately() { |
| 269 AbortAllAnimations(); | 267 AbortAllAnimations(); |
| 270 SetStateToHidden(); | 268 SetStateToHidden(); |
| 271 ink_drop_state_ = InkDropState::HIDDEN; | 269 ink_drop_state_ = InkDropState::HIDDEN; |
| 272 } | 270 } |
| 273 | 271 |
| 274 std::string SquareInkDropAnimation::ToLayerName(PaintedShape painted_shape) { | 272 std::string SquareInkDropAnimation::ToLayerName(PaintedShape painted_shape) { |
| 275 switch (painted_shape) { | 273 switch (painted_shape) { |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 if (ink_drop_state == InkDropState::HIDDEN) | 604 if (ink_drop_state == InkDropState::HIDDEN) |
| 607 SetStateToHidden(); | 605 SetStateToHidden(); |
| 608 NotifyAnimationEnded(ink_drop_state, | 606 NotifyAnimationEnded(ink_drop_state, |
| 609 observer.aborted_count() | 607 observer.aborted_count() |
| 610 ? InkDropAnimationObserver::PRE_EMPTED | 608 ? InkDropAnimationObserver::PRE_EMPTED |
| 611 : InkDropAnimationObserver::SUCCESS); | 609 : InkDropAnimationObserver::SUCCESS); |
| 612 return true; | 610 return true; |
| 613 } | 611 } |
| 614 | 612 |
| 615 } // namespace views | 613 } // namespace views |
| OLD | NEW |