| OLD | NEW |
| 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/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 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // The minimum scale factor to use when scaling rectangle layers. Smaller values | 26 // The minimum scale factor to use when scaling rectangle layers. Smaller values |
| 27 // were causing visual anomalies. | 27 // were causing visual anomalies. |
| 28 const float kMinimumRectScale = 0.0001f; | 28 const float kMinimumRectScale = 0.0001f; |
| 29 | 29 |
| 30 // The minimum scale factor to use when scaling circle layers. Smaller values | 30 // The minimum scale factor to use when scaling circle layers. Smaller values |
| 31 // were causing visual anomalies. | 31 // were causing visual anomalies. |
| 32 const float kMinimumCircleScale = 0.001f; | 32 const float kMinimumCircleScale = 0.001f; |
| 33 | 33 |
| 34 // The ink drop color. | |
| 35 const SkColor kInkDropColor = SK_ColorBLACK; | |
| 36 | |
| 37 // All the sub animations that are used to animate each of the InkDropStates. | 34 // All the sub animations that are used to animate each of the InkDropStates. |
| 38 // These are used to get time durations with | 35 // These are used to get time durations with |
| 39 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub | 36 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub |
| 40 // animation defines the duration for either a transformation animation or an | 37 // animation defines the duration for either a transformation animation or an |
| 41 // opacity animation but there are some exceptions where an entire InkDropState | 38 // opacity animation but there are some exceptions where an entire InkDropState |
| 42 // animation consists of only 1 sub animation and it defines the duration for | 39 // animation consists of only 1 sub animation and it defines the duration for |
| 43 // both the transformation and opacity animations. | 40 // both the transformation and opacity animations. |
| 44 enum InkDropSubAnimations { | 41 enum InkDropSubAnimations { |
| 45 // HIDDEN sub animations. | 42 // HIDDEN sub animations. |
| 46 | 43 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 gfx::Transform transform; | 166 gfx::Transform transform; |
| 170 transform.Scale(x_scale, y_scale); | 167 transform.Scale(x_scale, y_scale); |
| 171 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); | 168 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); |
| 172 return transform; | 169 return transform; |
| 173 } | 170 } |
| 174 | 171 |
| 175 } // namespace | 172 } // namespace |
| 176 | 173 |
| 177 namespace views { | 174 namespace views { |
| 178 | 175 |
| 179 SquareInkDropAnimation::SquareInkDropAnimation(const gfx::Size& large_size, | 176 SquareInkDropAnimation::SquareInkDropAnimation(SkColor color, |
| 177 const gfx::Size& large_size, |
| 180 int large_corner_radius, | 178 int large_corner_radius, |
| 181 const gfx::Size& small_size, | 179 const gfx::Size& small_size, |
| 182 int small_corner_radius) | 180 int small_corner_radius) |
| 183 : large_size_(large_size), | 181 : large_size_(large_size), |
| 184 large_corner_radius_(large_corner_radius), | 182 large_corner_radius_(large_corner_radius), |
| 185 small_size_(small_size), | 183 small_size_(small_size), |
| 186 small_corner_radius_(small_corner_radius), | 184 small_corner_radius_(small_corner_radius), |
| 187 circle_layer_delegate_(new CircleLayerDelegate( | 185 circle_layer_delegate_(new CircleLayerDelegate( |
| 188 kInkDropColor, | 186 color, |
| 189 std::min(large_size_.width(), large_size_.height()) / 2)), | 187 std::min(large_size_.width(), large_size_.height()) / 2)), |
| 190 rect_layer_delegate_( | 188 rect_layer_delegate_(new RectangleLayerDelegate(color, large_size_)) { |
| 191 new RectangleLayerDelegate(kInkDropColor, large_size_)) { | |
| 192 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 189 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
| 193 AddPaintLayer(static_cast<PaintedShape>(i)); | 190 AddPaintLayer(static_cast<PaintedShape>(i)); |
| 194 | 191 |
| 195 root_layer()->SetBounds(gfx::Rect(large_size_)); | 192 root_layer()->SetBounds(gfx::Rect(large_size_)); |
| 196 | 193 |
| 197 SetStateToHiddenInternal(); | 194 SetStateToHiddenInternal(); |
| 198 } | 195 } |
| 199 | 196 |
| 200 SquareInkDropAnimation::~SquareInkDropAnimation() { | 197 SquareInkDropAnimation::~SquareInkDropAnimation() { |
| 201 set_destroying(); | 198 set_destroying(); |
| 202 } | 199 } |
| 203 | 200 |
| 201 SkColor SquareInkDropAnimation::GetColor() const { |
| 202 return circle_layer_delegate_->color(); |
| 203 } |
| 204 |
| 204 void SquareInkDropAnimation::AbortAllAnimations() { | 205 void SquareInkDropAnimation::AbortAllAnimations() { |
| 205 InkDropAnimation::AbortAllAnimations(); | 206 InkDropAnimation::AbortAllAnimations(); |
| 206 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) | 207 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) |
| 207 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); | 208 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 std::string SquareInkDropAnimation::ToLayerName(PaintedShape painted_shape) { | 211 std::string SquareInkDropAnimation::ToLayerName(PaintedShape painted_shape) { |
| 211 switch (painted_shape) { | 212 switch (painted_shape) { |
| 212 case TOP_LEFT_CIRCLE: | 213 case TOP_LEFT_CIRCLE: |
| 213 return "TOP_LEFT_CIRCLE"; | 214 return "TOP_LEFT_CIRCLE"; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 layer->set_delegate(delegate); | 497 layer->set_delegate(delegate); |
| 497 layer->SetVisible(true); | 498 layer->SetVisible(true); |
| 498 layer->SetOpacity(1.0); | 499 layer->SetOpacity(1.0); |
| 499 layer->SetMasksToBounds(false); | 500 layer->SetMasksToBounds(false); |
| 500 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); | 501 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); |
| 501 | 502 |
| 502 painted_layers_[painted_shape].reset(layer); | 503 painted_layers_[painted_shape].reset(layer); |
| 503 } | 504 } |
| 504 | 505 |
| 505 } // namespace views | 506 } // namespace views |
| OLD | NEW |