Chromium Code Reviews| 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 |
| 145 FloodFillInkDropRipple::~FloodFillInkDropRipple() { | 159 FloodFillInkDropRipple::~FloodFillInkDropRipple() { |
| 146 // Explicitly aborting all the animations ensures all callbacks are invoked | 160 // Explicitly aborting all the animations ensures all callbacks are invoked |
| 147 // while this instance still exists. | 161 // while this instance still exists. |
| 148 AbortAllAnimations(); | 162 AbortAllAnimations(); |
| 149 } | 163 } |
| 150 | 164 |
| 165 void FloodFillInkDropRipple::HostSizeChanged(const gfx::Size& new_size) { | |
| 166 root_layer_.SetBounds(CalculateClipBounds(new_size, clip_insets_)); | |
| 167 switch (target_ink_drop_state()) { | |
| 168 case InkDropState::ACTION_PENDING: | |
| 169 case InkDropState::ALTERNATE_ACTION_PENDING: | |
| 170 case InkDropState::ACTIVATED: | |
| 171 painted_layer_.SetTransform(GetMaxSizeTargetTransform()); | |
|
bruthig
2016/11/28 22:13:46
So will opacity animations continue here or do we
mohsen
2016/11/29 00:07:12
I think the opacity animations continue and it mak
bruthig
2016/11/29 01:37:48
sgtm
| |
| 172 break; | |
| 173 default: | |
| 174 break; | |
| 175 } | |
| 176 } | |
| 177 | |
| 151 void FloodFillInkDropRipple::SnapToActivated() { | 178 void FloodFillInkDropRipple::SnapToActivated() { |
| 152 InkDropRipple::SnapToActivated(); | 179 InkDropRipple::SnapToActivated(); |
| 153 SetOpacity(visible_opacity_); | 180 SetOpacity(visible_opacity_); |
| 154 painted_layer_.SetTransform(GetMaxSizeTargetTransform()); | 181 painted_layer_.SetTransform(GetMaxSizeTargetTransform()); |
| 155 } | 182 } |
| 156 | 183 |
| 157 ui::Layer* FloodFillInkDropRipple::GetRootLayer() { | 184 ui::Layer* FloodFillInkDropRipple::GetRootLayer() { |
| 158 return &root_layer_; | 185 return &root_layer_; |
| 159 } | 186 } |
| 160 | 187 |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 (bounds.bottom_right() - point).Length(); | 361 (bounds.bottom_right() - point).Length(); |
| 335 | 362 |
| 336 float largest_distance = | 363 float largest_distance = |
| 337 std::max(distance_to_top_left, distance_to_top_right); | 364 std::max(distance_to_top_left, distance_to_top_right); |
| 338 largest_distance = std::max(largest_distance, distance_to_bottom_left); | 365 largest_distance = std::max(largest_distance, distance_to_bottom_left); |
| 339 largest_distance = std::max(largest_distance, distance_to_bottom_right); | 366 largest_distance = std::max(largest_distance, distance_to_bottom_right); |
| 340 return largest_distance; | 367 return largest_distance; |
| 341 } | 368 } |
| 342 | 369 |
| 343 } // namespace views | 370 } // namespace views |
| OLD | NEW |