Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: ui/views/animation/ink_drop_hover.cc

Issue 1924663007: Expand the Material Design hover as it fades out when a ripple is triggered. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/animation/ink_drop_hover.h ('k') | ui/views/animation/ink_drop_hover_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.128f; 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 } // namespace 24 } // namespace
25 25
26 InkDropHover::InkDropHover(const gfx::Size& size, 26 InkDropHover::InkDropHover(const gfx::Size& size,
27 int corner_radius, 27 int corner_radius,
28 const gfx::Point& center_point, 28 const gfx::Point& center_point,
29 SkColor color) 29 SkColor color)
30 : last_animation_initiated_was_fade_in_(false), 30 : size_(size),
31 explode_size_(size),
32 center_point_(center_point),
33 last_animation_initiated_was_fade_in_(false),
31 layer_delegate_( 34 layer_delegate_(
32 new RoundedRectangleLayerDelegate(color, size, corner_radius)), 35 new RoundedRectangleLayerDelegate(color, size, corner_radius)),
33 layer_(new ui::Layer()) { 36 layer_(new ui::Layer()) {
34 layer_->SetBounds(gfx::Rect(size)); 37 layer_->SetBounds(gfx::Rect(size));
35 layer_->SetFillsBoundsOpaquely(false); 38 layer_->SetFillsBoundsOpaquely(false);
36 layer_->set_delegate(layer_delegate_.get()); 39 layer_->set_delegate(layer_delegate_.get());
37 layer_->SetVisible(false); 40 layer_->SetVisible(false);
38 layer_->SetOpacity(kHoverVisibleOpacity); 41 layer_->SetOpacity(kHoverVisibleOpacity);
39 layer_->SetMasksToBounds(false); 42 layer_->SetMasksToBounds(false);
40 layer_->set_name("InkDropHover:layer"); 43 layer_->set_name("InkDropHover:layer");
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);
46 } 44 }
47 45
48 InkDropHover::~InkDropHover() {} 46 InkDropHover::~InkDropHover() {}
49 47
50 bool InkDropHover::IsFadingInOrVisible() const { 48 bool InkDropHover::IsFadingInOrVisible() const {
51 return last_animation_initiated_was_fade_in_; 49 return last_animation_initiated_was_fade_in_;
52 } 50 }
53 51
54 void InkDropHover::FadeIn(const base::TimeDelta& duration) { 52 void InkDropHover::FadeIn(const base::TimeDelta& duration) {
55 layer_->SetOpacity(kHiddenOpacity); 53 layer_->SetOpacity(kHiddenOpacity);
56 layer_->SetVisible(true); 54 layer_->SetVisible(true);
57 AnimateFade(FADE_IN, duration); 55 AnimateFade(FADE_IN, duration, size_, size_);
58 } 56 }
59 57
60 void InkDropHover::FadeOut(const base::TimeDelta& duration) { 58 void InkDropHover::FadeOut(const base::TimeDelta& duration, bool explode) {
61 AnimateFade(FADE_OUT, duration); 59 AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_);
62 } 60 }
63 61
64 void InkDropHover::AnimateFade(HoverAnimationType animation_type, 62 void InkDropHover::AnimateFade(HoverAnimationType animation_type,
65 const base::TimeDelta& duration) { 63 const base::TimeDelta& duration,
64 const gfx::Size& initial_size,
65 const gfx::Size& target_size) {
66 last_animation_initiated_was_fade_in_ = animation_type == FADE_IN; 66 last_animation_initiated_was_fade_in_ = animation_type == FADE_IN;
67 67
68 layer_->SetTransform(CalculateTransform(initial_size));
69
68 // The |animation_observer| will be destroyed when the 70 // The |animation_observer| will be destroyed when the
69 // AnimationStartedCallback() returns true. 71 // AnimationStartedCallback() returns true.
70 ui::CallbackLayerAnimationObserver* animation_observer = 72 ui::CallbackLayerAnimationObserver* animation_observer =
71 new ui::CallbackLayerAnimationObserver( 73 new ui::CallbackLayerAnimationObserver(
72 base::Bind(&InkDropHover::AnimationEndedCallback, 74 base::Bind(&InkDropHover::AnimationEndedCallback,
73 base::Unretained(this), animation_type)); 75 base::Unretained(this), animation_type));
74 76
75 ui::LayerAnimator* animator = layer_->GetAnimator(); 77 ui::LayerAnimator* animator = layer_->GetAnimator();
76 ui::ScopedLayerAnimationSettings animation(animator); 78 ui::ScopedLayerAnimationSettings animation(animator);
77 animation.SetTweenType(gfx::Tween::EASE_IN_OUT); 79 animation.SetTweenType(gfx::Tween::EASE_IN_OUT);
78 animation.SetPreemptionStrategy( 80 animation.SetPreemptionStrategy(
79 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 81 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
80 ui::LayerAnimationElement* animation_element = 82
83 ui::LayerAnimationElement* opacity_element =
81 ui::LayerAnimationElement::CreateOpacityElement( 84 ui::LayerAnimationElement::CreateOpacityElement(
82 animation_type == FADE_IN ? kHoverVisibleOpacity : kHiddenOpacity, 85 animation_type == FADE_IN ? kHoverVisibleOpacity : kHiddenOpacity,
83 duration); 86 duration);
84 ui::LayerAnimationSequence* animation_sequence = 87 ui::LayerAnimationSequence* opacity_sequence =
85 new ui::LayerAnimationSequence(animation_element); 88 new ui::LayerAnimationSequence(opacity_element);
86 animation_sequence->AddObserver(animation_observer); 89 opacity_sequence->AddObserver(animation_observer);
90 animator->StartAnimation(opacity_sequence);
87 91
88 animator->StartAnimation(animation_sequence); 92 if (initial_size != target_size) {
93 ui::LayerAnimationElement* transform_element =
94 ui::LayerAnimationElement::CreateTransformElement(
95 CalculateTransform(target_size), duration);
96 ui::LayerAnimationSequence* transform_sequence =
97 new ui::LayerAnimationSequence(transform_element);
98 transform_sequence->AddObserver(animation_observer);
99 animator->StartAnimation(transform_sequence);
100 }
89 101
90 animation_observer->SetActive(); 102 animation_observer->SetActive();
91 } 103 }
92 104
105 gfx::Transform InkDropHover::CalculateTransform(const gfx::Size& size) const {
106 gfx::Transform transform;
107 transform.Translate(center_point_.x(), center_point_.y());
108 transform.Scale(size.width() / size_.width(), size.height() / size_.height());
109 transform.Translate(-layer_delegate_->GetCenterPoint().x(),
110 -layer_delegate_->GetCenterPoint().y());
111 return transform;
112 }
113
93 bool InkDropHover::AnimationEndedCallback( 114 bool InkDropHover::AnimationEndedCallback(
94 HoverAnimationType animation_type, 115 HoverAnimationType animation_type,
95 const ui::CallbackLayerAnimationObserver& observer) { 116 const ui::CallbackLayerAnimationObserver& observer) {
96 // AnimationEndedCallback() may be invoked when this is being destroyed and 117 // AnimationEndedCallback() may be invoked when this is being destroyed and
97 // |layer_| may be null. 118 // |layer_| may be null.
98 if (animation_type == FADE_OUT && layer_) 119 if (animation_type == FADE_OUT && layer_)
99 layer_->SetVisible(false); 120 layer_->SetVisible(false);
100 return true; 121 return true;
101 } 122 }
102 123
103 } // namespace views 124 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_hover.h ('k') | ui/views/animation/ink_drop_hover_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698