| 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/flood_fill_ink_drop_animation.h" | 5 #include "ui/views/animation/flood_fill_ink_drop_animation.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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 namespace views { | 107 namespace views { |
| 108 | 108 |
| 109 FloodFillInkDropAnimation::FloodFillInkDropAnimation( | 109 FloodFillInkDropAnimation::FloodFillInkDropAnimation( |
| 110 const gfx::Size& size, | 110 const gfx::Size& size, |
| 111 const gfx::Point& center_point, | 111 const gfx::Point& center_point, |
| 112 SkColor color) | 112 SkColor color) |
| 113 : size_(size), | 113 : FloodFillInkDropAnimation(gfx::Rect(size), center_point, color) {} |
| 114 |
| 115 FloodFillInkDropAnimation::FloodFillInkDropAnimation( |
| 116 const gfx::Rect& clip_bounds, |
| 117 const gfx::Point& center_point, |
| 118 SkColor color) |
| 119 : clip_bounds_(clip_bounds), |
| 114 center_point_(center_point), | 120 center_point_(center_point), |
| 115 root_layer_(ui::LAYER_NOT_DRAWN), | 121 root_layer_(ui::LAYER_NOT_DRAWN), |
| 116 circle_layer_delegate_(color, | 122 circle_layer_delegate_( |
| 117 std::max(size_.width(), size_.height()) / 2.f), | 123 color, |
| 124 std::max(clip_bounds_.width(), clip_bounds_.height()) / 2.f), |
| 118 ink_drop_state_(InkDropState::HIDDEN) { | 125 ink_drop_state_(InkDropState::HIDDEN) { |
| 119 root_layer_.set_name("FloodFillInkDropAnimation:ROOT_LAYER"); | 126 root_layer_.set_name("FloodFillInkDropAnimation:ROOT_LAYER"); |
| 120 root_layer_.SetMasksToBounds(true); | 127 root_layer_.SetMasksToBounds(true); |
| 121 root_layer_.SetBounds(gfx::Rect(size_)); | 128 root_layer_.SetBounds(clip_bounds); |
| 122 | 129 |
| 123 const gfx::Vector2dF translate_vector = | 130 const int painted_size_length = |
| 124 center_point_ - root_layer_.bounds().CenterPoint(); | 131 2 * std::max(clip_bounds_.width(), clip_bounds_.height()); |
| 125 gfx::Transform transfrom; | |
| 126 transfrom.Translate(translate_vector.x(), translate_vector.y()); | |
| 127 root_layer_.SetTransform(transfrom); | |
| 128 | |
| 129 const int painted_size_length = 2 * std::max(size_.width(), size_.height()); | |
| 130 | 132 |
| 131 painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length)); | 133 painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length)); |
| 132 painted_layer_.SetFillsBoundsOpaquely(false); | 134 painted_layer_.SetFillsBoundsOpaquely(false); |
| 133 painted_layer_.set_delegate(&circle_layer_delegate_); | 135 painted_layer_.set_delegate(&circle_layer_delegate_); |
| 134 painted_layer_.SetVisible(true); | 136 painted_layer_.SetVisible(true); |
| 135 painted_layer_.SetOpacity(1.0); | 137 painted_layer_.SetOpacity(1.0); |
| 136 painted_layer_.SetMasksToBounds(false); | 138 painted_layer_.SetMasksToBounds(false); |
| 137 painted_layer_.set_name("FloodFillInkDropAnimation:PAINTED_LAYER"); | 139 painted_layer_.set_name("FloodFillInkDropAnimation:PAINTED_LAYER"); |
| 138 | 140 |
| 139 root_layer_.Add(&painted_layer_); | 141 root_layer_.Add(&painted_layer_); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 animator->StartAnimation(animation_sequence); | 308 animator->StartAnimation(animation_sequence); |
| 307 } | 309 } |
| 308 | 310 |
| 309 gfx::Transform FloodFillInkDropAnimation::CalculateTransform( | 311 gfx::Transform FloodFillInkDropAnimation::CalculateTransform( |
| 310 float target_radius) const { | 312 float target_radius) const { |
| 311 const float target_scale = target_radius / circle_layer_delegate_.radius(); | 313 const float target_scale = target_radius / circle_layer_delegate_.radius(); |
| 312 const gfx::Point drawn_center_point = | 314 const gfx::Point drawn_center_point = |
| 313 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint()); | 315 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint()); |
| 314 | 316 |
| 315 gfx::Transform transform = gfx::Transform(); | 317 gfx::Transform transform = gfx::Transform(); |
| 316 transform.Translate(root_layer_.bounds().CenterPoint().x(), | 318 transform.Translate(center_point_.x(), center_point_.y()); |
| 317 root_layer_.bounds().CenterPoint().y()); | |
| 318 transform.Scale(target_scale, target_scale); | 319 transform.Scale(target_scale, target_scale); |
| 319 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); | 320 transform.Translate(-drawn_center_point.x() - root_layer_.bounds().x(), |
| 321 -drawn_center_point.y() - root_layer_.bounds().y()); |
| 320 | 322 |
| 321 return transform; | 323 return transform; |
| 322 } | 324 } |
| 323 | 325 |
| 324 gfx::Transform FloodFillInkDropAnimation::GetMaxSizeTargetTransform() const { | 326 gfx::Transform FloodFillInkDropAnimation::GetMaxSizeTargetTransform() const { |
| 325 // TODO(estade): get rid of this 2, but make the fade out start before the | 327 // TODO(estade): get rid of this 2, but make the fade out start before the |
| 326 // active/action transform is done. | 328 // active/action transform is done. |
| 327 return CalculateTransform( | 329 return CalculateTransform( |
| 328 gfx::Vector2dF(size_.width(), size_.height()).Length() / 2); | 330 gfx::Vector2dF(clip_bounds_.width(), clip_bounds_.height()).Length() / 2); |
| 329 } | 331 } |
| 330 | 332 |
| 331 } // namespace views | 333 } // namespace views |
| OLD | NEW |