| 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_ripple.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" | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  100   // accessibility reasons."See https://crbug.com/658384. |  100   // accessibility reasons."See https://crbug.com/658384. | 
|  101   if (!gfx::Animation::ShouldRenderRichAnimation()) |  101   if (!gfx::Animation::ShouldRenderRichAnimation()) | 
|  102     return base::TimeDelta(); |  102     return base::TimeDelta(); | 
|  103   return base::TimeDelta::FromMilliseconds( |  103   return base::TimeDelta::FromMilliseconds( | 
|  104       (views::InkDropRipple::UseFastAnimations() |  104       (views::InkDropRipple::UseFastAnimations() | 
|  105            ? 1 |  105            ? 1 | 
|  106            : views::InkDropRipple::kSlowAnimationDurationFactor) * |  106            : views::InkDropRipple::kSlowAnimationDurationFactor) * | 
|  107       kAnimationDurationInMs[state]); |  107       kAnimationDurationInMs[state]); | 
|  108 } |  108 } | 
|  109  |  109  | 
 |  110 gfx::Rect CalculateClipBounds(const gfx::Size& host_size, | 
 |  111                               const gfx::Insets& clip_insets) { | 
 |  112   gfx::Rect clip_bounds(host_size); | 
 |  113   clip_bounds.Inset(clip_insets); | 
 |  114   return clip_bounds; | 
 |  115 } | 
 |  116  | 
 |  117 float CalculateCircleLayerRadius(const gfx::Rect& clip_bounds) { | 
 |  118   return std::max(clip_bounds.width(), clip_bounds.height()) / 2.f; | 
 |  119 } | 
 |  120  | 
|  110 }  // namespace |  121 }  // namespace | 
|  111  |  122  | 
|  112 namespace views { |  123 namespace views { | 
|  113  |  124  | 
|  114 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Rect& clip_bounds, |  125 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size, | 
 |  126                                                const gfx::Insets& clip_insets, | 
|  115                                                const gfx::Point& center_point, |  127                                                const gfx::Point& center_point, | 
|  116                                                SkColor color, |  128                                                SkColor color, | 
|  117                                                float visible_opacity) |  129                                                float visible_opacity) | 
|  118     : center_point_(center_point), |  130     : clip_insets_(clip_insets), | 
 |  131       center_point_(center_point), | 
|  119       visible_opacity_(visible_opacity), |  132       visible_opacity_(visible_opacity), | 
|  120       root_layer_(ui::LAYER_NOT_DRAWN), |  133       root_layer_(ui::LAYER_NOT_DRAWN), | 
|  121       circle_layer_delegate_( |  134       circle_layer_delegate_(color, | 
|  122           color, |  135                              CalculateCircleLayerRadius( | 
|  123           std::max(clip_bounds.width(), clip_bounds.height()) / 2.f), |  136                                  CalculateClipBounds(host_size, clip_insets))), | 
|  124       ink_drop_state_(InkDropState::HIDDEN) { |  137       ink_drop_state_(InkDropState::HIDDEN) { | 
 |  138   gfx::Rect clip_bounds = CalculateClipBounds(host_size, clip_insets); | 
|  125   root_layer_.set_name("FloodFillInkDropRipple:ROOT_LAYER"); |  139   root_layer_.set_name("FloodFillInkDropRipple:ROOT_LAYER"); | 
|  126   root_layer_.SetMasksToBounds(true); |  140   root_layer_.SetMasksToBounds(true); | 
|  127   root_layer_.SetBounds(clip_bounds); |  141   root_layer_.SetBounds(clip_bounds); | 
|  128  |  142  | 
|  129   const int painted_size_length = |  143   const int painted_size_length = | 
|  130       std::max(clip_bounds.width(), clip_bounds.height()); |  144       std::max(clip_bounds.width(), clip_bounds.height()); | 
|  131  |  145  | 
|  132   painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length)); |  146   painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length)); | 
|  133   painted_layer_.SetFillsBoundsOpaquely(false); |  147   painted_layer_.SetFillsBoundsOpaquely(false); | 
|  134   painted_layer_.set_delegate(&circle_layer_delegate_); |  148   painted_layer_.set_delegate(&circle_layer_delegate_); | 
|  135   painted_layer_.SetVisible(true); |  149   painted_layer_.SetVisible(true); | 
|  136   painted_layer_.SetOpacity(1.0); |  150   painted_layer_.SetOpacity(1.0); | 
|  137   painted_layer_.SetMasksToBounds(false); |  151   painted_layer_.SetMasksToBounds(false); | 
|  138   painted_layer_.set_name("FloodFillInkDropRipple:PAINTED_LAYER"); |  152   painted_layer_.set_name("FloodFillInkDropRipple:PAINTED_LAYER"); | 
|  139  |  153  | 
|  140   root_layer_.Add(&painted_layer_); |  154   root_layer_.Add(&painted_layer_); | 
|  141  |  155  | 
|  142   SetStateToHidden(); |  156   SetStateToHidden(); | 
|  143 } |  157 } | 
|  144  |  158  | 
 |  159 FloodFillInkDropRipple::FloodFillInkDropRipple(const gfx::Size& host_size, | 
 |  160                                                const gfx::Point& center_point, | 
 |  161                                                SkColor color, | 
 |  162                                                float visible_opacity) | 
 |  163     : FloodFillInkDropRipple(host_size, | 
 |  164                              gfx::Insets(), | 
 |  165                              center_point, | 
 |  166                              color, | 
 |  167                              visible_opacity) {} | 
 |  168  | 
|  145 FloodFillInkDropRipple::~FloodFillInkDropRipple() { |  169 FloodFillInkDropRipple::~FloodFillInkDropRipple() { | 
|  146   // Explicitly aborting all the animations ensures all callbacks are invoked |  170   // Explicitly aborting all the animations ensures all callbacks are invoked | 
|  147   // while this instance still exists. |  171   // while this instance still exists. | 
|  148   AbortAllAnimations(); |  172   AbortAllAnimations(); | 
|  149 } |  173 } | 
|  150  |  174  | 
 |  175 void FloodFillInkDropRipple::HostSizeChanged(const gfx::Size& new_size) { | 
 |  176   root_layer_.SetBounds(CalculateClipBounds(new_size, clip_insets_)); | 
 |  177   switch (target_ink_drop_state()) { | 
 |  178     case InkDropState::ACTION_PENDING: | 
 |  179     case InkDropState::ALTERNATE_ACTION_PENDING: | 
 |  180     case InkDropState::ACTIVATED: | 
 |  181       painted_layer_.SetTransform(GetMaxSizeTargetTransform()); | 
 |  182       break; | 
 |  183     default: | 
 |  184       break; | 
 |  185   } | 
 |  186 } | 
 |  187  | 
|  151 void FloodFillInkDropRipple::SnapToActivated() { |  188 void FloodFillInkDropRipple::SnapToActivated() { | 
|  152   InkDropRipple::SnapToActivated(); |  189   InkDropRipple::SnapToActivated(); | 
|  153   SetOpacity(visible_opacity_); |  190   SetOpacity(visible_opacity_); | 
|  154   painted_layer_.SetTransform(GetMaxSizeTargetTransform()); |  191   painted_layer_.SetTransform(GetMaxSizeTargetTransform()); | 
|  155 } |  192 } | 
|  156  |  193  | 
|  157 ui::Layer* FloodFillInkDropRipple::GetRootLayer() { |  194 ui::Layer* FloodFillInkDropRipple::GetRootLayer() { | 
|  158   return &root_layer_; |  195   return &root_layer_; | 
|  159 } |  196 } | 
|  160  |  197  | 
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  334       (bounds.bottom_right() - point).Length(); |  371       (bounds.bottom_right() - point).Length(); | 
|  335  |  372  | 
|  336   float largest_distance = |  373   float largest_distance = | 
|  337       std::max(distance_to_top_left, distance_to_top_right); |  374       std::max(distance_to_top_left, distance_to_top_right); | 
|  338   largest_distance = std::max(largest_distance, distance_to_bottom_left); |  375   largest_distance = std::max(largest_distance, distance_to_bottom_left); | 
|  339   largest_distance = std::max(largest_distance, distance_to_bottom_right); |  376   largest_distance = std::max(largest_distance, distance_to_bottom_right); | 
|  340   return largest_distance; |  377   return largest_distance; | 
|  341 } |  378 } | 
|  342  |  379  | 
|  343 }  // namespace views |  380 }  // namespace views | 
| OLD | NEW |