| 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/ink_drop_highlight.h" | 5 #include "ui/views/animation/ink_drop_highlight.h" |
| 6 | 6 |
| 7 #include "third_party/skia/include/core/SkColor.h" | 7 #include "third_party/skia/include/core/SkColor.h" |
| 8 #include "ui/compositor/callback_layer_animation_observer.h" | 8 #include "ui/compositor/callback_layer_animation_observer.h" |
| 9 #include "ui/compositor/layer.h" | 9 #include "ui/compositor/layer.h" |
| 10 #include "ui/compositor/layer_animation_sequence.h" | 10 #include "ui/compositor/layer_animation_sequence.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 InkDropHighlight::InkDropHighlight( | 37 InkDropHighlight::InkDropHighlight( |
| 38 const gfx::PointF& center_point, | 38 const gfx::PointF& center_point, |
| 39 std::unique_ptr<BasePaintedLayerDelegate> layer_delegate) | 39 std::unique_ptr<BasePaintedLayerDelegate> layer_delegate) |
| 40 : center_point_(center_point), | 40 : center_point_(center_point), |
| 41 visible_opacity_(1.f), | 41 visible_opacity_(1.f), |
| 42 last_animation_initiated_was_fade_in_(false), | 42 last_animation_initiated_was_fade_in_(false), |
| 43 layer_delegate_(std::move(layer_delegate)), | 43 layer_delegate_(std::move(layer_delegate)), |
| 44 layer_(new ui::Layer()), | 44 layer_(new ui::Layer()), |
| 45 observer_(nullptr) { | 45 observer_(nullptr) { |
| 46 const gfx::Rect layer_bounds = layer_delegate_->GetPaintedBounds(); | 46 const gfx::RectF painted_bounds = layer_delegate_->GetPaintedBounds(); |
| 47 size_ = explode_size_ = layer_bounds.size(); | 47 size_ = explode_size_ = painted_bounds.size(); |
| 48 | 48 |
| 49 layer_->SetBounds(layer_bounds); | 49 layer_->SetBounds(gfx::ToEnclosingRect(painted_bounds)); |
| 50 layer_->SetFillsBoundsOpaquely(false); | 50 layer_->SetFillsBoundsOpaquely(false); |
| 51 layer_->set_delegate(layer_delegate_.get()); | 51 layer_->set_delegate(layer_delegate_.get()); |
| 52 layer_->SetVisible(false); | 52 layer_->SetVisible(false); |
| 53 layer_->SetMasksToBounds(false); | 53 layer_->SetMasksToBounds(false); |
| 54 layer_->set_name("InkDropHighlight:layer"); | 54 layer_->set_name("InkDropHighlight:layer"); |
| 55 } | 55 } |
| 56 | 56 |
| 57 InkDropHighlight::InkDropHighlight(const gfx::Size& size, | 57 InkDropHighlight::InkDropHighlight(const gfx::SizeF& size, |
| 58 int corner_radius, | 58 int corner_radius, |
| 59 const gfx::PointF& center_point, | 59 const gfx::PointF& center_point, |
| 60 SkColor color) | 60 SkColor color) |
| 61 : InkDropHighlight( | 61 : InkDropHighlight( |
| 62 center_point, | 62 center_point, |
| 63 std::unique_ptr<BasePaintedLayerDelegate>( | 63 std::unique_ptr<BasePaintedLayerDelegate>( |
| 64 new RoundedRectangleLayerDelegate(color, size, corner_radius))) { | 64 new RoundedRectangleLayerDelegate(color, size, corner_radius))) { |
| 65 visible_opacity_ = 0.128f; | 65 visible_opacity_ = 0.128f; |
| 66 layer_->SetOpacity(visible_opacity_); | 66 layer_->SetOpacity(visible_opacity_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 InkDropHighlight::InkDropHighlight(const gfx::Size& size, |
| 70 int corner_radius, |
| 71 const gfx::PointF& center_point, |
| 72 SkColor color) |
| 73 : InkDropHighlight(gfx::SizeF(size), corner_radius, center_point, color) {} |
| 74 |
| 69 InkDropHighlight::~InkDropHighlight() { | 75 InkDropHighlight::~InkDropHighlight() { |
| 70 // Explicitly aborting all the animations ensures all callbacks are invoked | 76 // Explicitly aborting all the animations ensures all callbacks are invoked |
| 71 // while this instance still exists. | 77 // while this instance still exists. |
| 72 layer_->GetAnimator()->AbortAllAnimations(); | 78 layer_->GetAnimator()->AbortAllAnimations(); |
| 73 } | 79 } |
| 74 | 80 |
| 75 bool InkDropHighlight::IsFadingInOrVisible() const { | 81 bool InkDropHighlight::IsFadingInOrVisible() const { |
| 76 return last_animation_initiated_was_fade_in_; | 82 return last_animation_initiated_was_fade_in_; |
| 77 } | 83 } |
| 78 | 84 |
| 79 void InkDropHighlight::FadeIn(const base::TimeDelta& duration) { | 85 void InkDropHighlight::FadeIn(const base::TimeDelta& duration) { |
| 80 layer_->SetOpacity(kHiddenOpacity); | 86 layer_->SetOpacity(kHiddenOpacity); |
| 81 layer_->SetVisible(true); | 87 layer_->SetVisible(true); |
| 82 AnimateFade(FADE_IN, duration, size_, size_); | 88 AnimateFade(FADE_IN, duration, size_, size_); |
| 83 } | 89 } |
| 84 | 90 |
| 85 void InkDropHighlight::FadeOut(const base::TimeDelta& duration, bool explode) { | 91 void InkDropHighlight::FadeOut(const base::TimeDelta& duration, bool explode) { |
| 86 AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_); | 92 AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_); |
| 87 } | 93 } |
| 88 | 94 |
| 89 test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() { | 95 test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() { |
| 90 return nullptr; | 96 return nullptr; |
| 91 } | 97 } |
| 92 | 98 |
| 93 void InkDropHighlight::AnimateFade(AnimationType animation_type, | 99 void InkDropHighlight::AnimateFade(AnimationType animation_type, |
| 94 const base::TimeDelta& duration, | 100 const base::TimeDelta& duration, |
| 95 const gfx::Size& initial_size, | 101 const gfx::SizeF& initial_size, |
| 96 const gfx::Size& target_size) { | 102 const gfx::SizeF& target_size) { |
| 97 last_animation_initiated_was_fade_in_ = animation_type == FADE_IN; | 103 last_animation_initiated_was_fade_in_ = animation_type == FADE_IN; |
| 98 | 104 |
| 99 layer_->SetTransform(CalculateTransform(initial_size)); | 105 layer_->SetTransform(CalculateTransform(initial_size)); |
| 100 | 106 |
| 101 // The |animation_observer| will be destroyed when the | 107 // The |animation_observer| will be destroyed when the |
| 102 // AnimationStartedCallback() returns true. | 108 // AnimationStartedCallback() returns true. |
| 103 ui::CallbackLayerAnimationObserver* animation_observer = | 109 ui::CallbackLayerAnimationObserver* animation_observer = |
| 104 new ui::CallbackLayerAnimationObserver( | 110 new ui::CallbackLayerAnimationObserver( |
| 105 base::Bind(&InkDropHighlight::AnimationStartedCallback, | 111 base::Bind(&InkDropHighlight::AnimationStartedCallback, |
| 106 base::Unretained(this), animation_type), | 112 base::Unretained(this), animation_type), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 131 new ui::LayerAnimationSequence(std::move(transform_element)); | 137 new ui::LayerAnimationSequence(std::move(transform_element)); |
| 132 | 138 |
| 133 transform_sequence->AddObserver(animation_observer); | 139 transform_sequence->AddObserver(animation_observer); |
| 134 animator->StartAnimation(transform_sequence); | 140 animator->StartAnimation(transform_sequence); |
| 135 } | 141 } |
| 136 | 142 |
| 137 animation_observer->SetActive(); | 143 animation_observer->SetActive(); |
| 138 } | 144 } |
| 139 | 145 |
| 140 gfx::Transform InkDropHighlight::CalculateTransform( | 146 gfx::Transform InkDropHighlight::CalculateTransform( |
| 141 const gfx::Size& size) const { | 147 const gfx::SizeF& size) const { |
| 142 gfx::Transform transform; | 148 gfx::Transform transform; |
| 143 transform.Translate(center_point_.x(), center_point_.y()); | 149 transform.Translate(center_point_.x(), center_point_.y()); |
| 144 // TODO(bruthig): Fix the InkDropHighlight to work well when initialized with | 150 // TODO(bruthig): Fix the InkDropHighlight to work well when initialized with |
| 145 // a (0x0) size. See https://crbug.com/661618. | 151 // a (0x0) size. See https://crbug.com/661618. |
| 146 transform.Scale(size_.width() == 0 ? 0 : size.width() / size_.width(), | 152 transform.Scale(size_.width() == 0 ? 0 : size.width() / size_.width(), |
| 147 size_.height() == 0 ? 0 : size.height() / size_.height()); | 153 size_.height() == 0 ? 0 : size.height() / size_.height()); |
| 148 gfx::Vector2dF layer_offset = layer_delegate_->GetCenteringOffset(); | 154 gfx::Vector2dF layer_offset = layer_delegate_->GetCenteringOffset(); |
| 149 transform.Translate(-layer_offset.x(), -layer_offset.y()); | 155 transform.Translate(-layer_offset.x(), -layer_offset.y()); |
| 150 return transform; | 156 return transform; |
| 151 } | 157 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 168 if (observer_) { | 174 if (observer_) { |
| 169 observer_->AnimationEnded(animation_type, | 175 observer_->AnimationEnded(animation_type, |
| 170 observer.aborted_count() | 176 observer.aborted_count() |
| 171 ? InkDropAnimationEndedReason::PRE_EMPTED | 177 ? InkDropAnimationEndedReason::PRE_EMPTED |
| 172 : InkDropAnimationEndedReason::SUCCESS); | 178 : InkDropAnimationEndedReason::SUCCESS); |
| 173 } | 179 } |
| 174 return true; | 180 return true; |
| 175 } | 181 } |
| 176 | 182 |
| 177 } // namespace views | 183 } // namespace views |
| OLD | NEW |