| 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_hover.h" | 5 #include "ui/views/animation/ink_drop_hover.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" |
| 11 #include "ui/compositor/scoped_layer_animation_settings.h" | 11 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 12 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" | 12 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" |
| 13 | 13 |
| 14 namespace views { | 14 namespace views { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // The opacity of the hover when it is visible. | 18 // The opacity of the hover when it is visible. |
| 19 const float kHoverVisibleOpacity = 0.08f; | 19 const float kHoverVisibleOpacity = 0.128f; |
| 20 | 20 |
| 21 // The opacity of the hover when it is not visible. | 21 // The opacity of the hover when it is not visible. |
| 22 const float kHiddenOpacity = 0.0f; | 22 const float kHiddenOpacity = 0.0f; |
| 23 | 23 |
| 24 // The hover color. | |
| 25 const SkColor kHoverColor = SK_ColorBLACK; | |
| 26 | |
| 27 } // namespace | 24 } // namespace |
| 28 | 25 |
| 29 InkDropHover::InkDropHover(const gfx::Size& size, int corner_radius) | 26 InkDropHover::InkDropHover(const gfx::Size& size, |
| 27 int corner_radius, |
| 28 const gfx::Point& center_point, |
| 29 SkColor color) |
| 30 : last_animation_initiated_was_fade_in_(false), | 30 : last_animation_initiated_was_fade_in_(false), |
| 31 layer_delegate_( | 31 layer_delegate_( |
| 32 new RoundedRectangleLayerDelegate(kHoverColor, size, corner_radius)), | 32 new RoundedRectangleLayerDelegate(color, size, corner_radius)), |
| 33 layer_(new ui::Layer()) { | 33 layer_(new ui::Layer()) { |
| 34 layer_->SetBounds(gfx::Rect(size)); | 34 layer_->SetBounds(gfx::Rect(size)); |
| 35 layer_->SetFillsBoundsOpaquely(false); | 35 layer_->SetFillsBoundsOpaquely(false); |
| 36 layer_->set_delegate(layer_delegate_.get()); | 36 layer_->set_delegate(layer_delegate_.get()); |
| 37 layer_->SetVisible(false); | 37 layer_->SetVisible(false); |
| 38 layer_->SetOpacity(kHoverVisibleOpacity); | 38 layer_->SetOpacity(kHoverVisibleOpacity); |
| 39 layer_->SetMasksToBounds(false); | 39 layer_->SetMasksToBounds(false); |
| 40 layer_->set_name("InkDropHover:layer"); | 40 layer_->set_name("InkDropHover:layer"); |
| 41 SetCenterPoint(gfx::Rect(size).CenterPoint()); | 41 |
| 42 gfx::Transform transform; |
| 43 transform.Translate(center_point.x() - layer_->bounds().CenterPoint().x(), |
| 44 center_point.y() - layer_->bounds().CenterPoint().y()); |
| 45 layer_->SetTransform(transform); |
| 42 } | 46 } |
| 43 | 47 |
| 44 InkDropHover::~InkDropHover() {} | 48 InkDropHover::~InkDropHover() {} |
| 45 | 49 |
| 46 bool InkDropHover::IsFadingInOrVisible() const { | 50 bool InkDropHover::IsFadingInOrVisible() const { |
| 47 return last_animation_initiated_was_fade_in_; | 51 return last_animation_initiated_was_fade_in_; |
| 48 } | 52 } |
| 49 | 53 |
| 50 void InkDropHover::FadeIn(const base::TimeDelta& duration) { | 54 void InkDropHover::FadeIn(const base::TimeDelta& duration) { |
| 51 layer_->SetOpacity(kHiddenOpacity); | 55 layer_->SetOpacity(kHiddenOpacity); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 79 duration); | 83 duration); |
| 80 ui::LayerAnimationSequence* animation_sequence = | 84 ui::LayerAnimationSequence* animation_sequence = |
| 81 new ui::LayerAnimationSequence(animation_element); | 85 new ui::LayerAnimationSequence(animation_element); |
| 82 animation_sequence->AddObserver(animation_observer); | 86 animation_sequence->AddObserver(animation_observer); |
| 83 | 87 |
| 84 animator->StartAnimation(animation_sequence); | 88 animator->StartAnimation(animation_sequence); |
| 85 | 89 |
| 86 animation_observer->SetActive(); | 90 animation_observer->SetActive(); |
| 87 } | 91 } |
| 88 | 92 |
| 89 void InkDropHover::SetCenterPoint(const gfx::Point& center_point) { | |
| 90 gfx::Transform transform; | |
| 91 transform.Translate(center_point.x() - layer_->bounds().CenterPoint().x(), | |
| 92 center_point.y() - layer_->bounds().CenterPoint().y()); | |
| 93 layer_->SetTransform(transform); | |
| 94 } | |
| 95 | |
| 96 bool InkDropHover::AnimationEndedCallback( | 93 bool InkDropHover::AnimationEndedCallback( |
| 97 HoverAnimationType animation_type, | 94 HoverAnimationType animation_type, |
| 98 const ui::CallbackLayerAnimationObserver& observer) { | 95 const ui::CallbackLayerAnimationObserver& observer) { |
| 99 // AnimationEndedCallback() may be invoked when this is being destroyed and | 96 // AnimationEndedCallback() may be invoked when this is being destroyed and |
| 100 // |layer_| may be null. | 97 // |layer_| may be null. |
| 101 if (animation_type == FADE_OUT && layer_) | 98 if (animation_type == FADE_OUT && layer_) |
| 102 layer_->SetVisible(false); | 99 layer_->SetVisible(false); |
| 103 return true; | 100 return true; |
| 104 } | 101 } |
| 105 | 102 |
| 106 } // namespace views | 103 } // namespace views |
| OLD | NEW |