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_animation_controller_impl.h" | 5 #include "ui/views/animation/ink_drop_animation_controller_impl.h" |
6 | 6 |
7 #include "base/auto_reset.h" | |
7 #include "ui/compositor/layer.h" | 8 #include "ui/compositor/layer.h" |
8 #include "ui/views/animation/ink_drop_animation.h" | 9 #include "ui/views/animation/ink_drop_animation.h" |
9 #include "ui/views/animation/ink_drop_host.h" | 10 #include "ui/views/animation/ink_drop_host.h" |
10 #include "ui/views/animation/ink_drop_hover.h" | 11 #include "ui/views/animation/ink_drop_hover.h" |
11 | 12 |
12 namespace views { | 13 namespace views { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // The duration of the hover state fade in animation. | 17 // The duration of the hover state fade in animation. |
17 const int kFadeInDurationInMs = 250; | 18 const int kFadeInDurationInMs = 250; |
18 | 19 |
19 // The duration of the hover state fade out animation. | 20 // The duration of the hover state fade out animation. |
20 const int kFadeOutDurationInMs = 250; | 21 const int kFadeOutDurationInMs = 250; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( | 25 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( |
25 InkDropHost* ink_drop_host) | 26 InkDropHost* ink_drop_host) |
26 : ink_drop_host_(ink_drop_host), | 27 : ink_drop_host_(ink_drop_host), |
27 ink_drop_large_corner_radius_(0), | 28 ink_drop_large_corner_radius_(0), |
28 ink_drop_small_corner_radius_(0), | 29 ink_drop_small_corner_radius_(0), |
29 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)) { | 30 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
31 can_destroy_after_hidden_animation_(true) { | |
30 ink_drop_host_->AddInkDropLayer(root_layer_.get()); | 32 ink_drop_host_->AddInkDropLayer(root_layer_.get()); |
31 } | 33 } |
32 | 34 |
33 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { | 35 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { |
34 // Explicitly destroy the InkDropAnimation so that this still exists if | 36 // Explicitly destroy the InkDropAnimation so that this still exists if |
35 // views::InkDropAnimationObserver methods are called on this. | 37 // views::InkDropAnimationObserver methods are called on this. |
36 DestroyInkDropAnimation(); | 38 DestroyInkDropAnimation(); |
37 } | 39 } |
38 | 40 |
39 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { | 41 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { |
40 if (!ink_drop_animation_) | 42 if (!ink_drop_animation_) |
41 return InkDropState::HIDDEN; | 43 return InkDropState::HIDDEN; |
42 return ink_drop_animation_->ink_drop_state(); | 44 return ink_drop_animation_->ink_drop_state(); |
43 } | 45 } |
44 | 46 |
45 void InkDropAnimationControllerImpl::AnimateToState( | 47 void InkDropAnimationControllerImpl::AnimateToState( |
46 InkDropState ink_drop_state) { | 48 InkDropState ink_drop_state) { |
47 if (!ink_drop_animation_) | 49 if (!ink_drop_animation_) |
48 CreateInkDropAnimation(); | 50 CreateInkDropAnimation(); |
51 | |
52 // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to | |
53 // know if it is safe to destroy the |ink_drop_animation_| and it is not safe | |
54 // when the notification is raised within a call to | |
55 // InkDropAnimation::AnimateToState(). | |
56 base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation( | |
57 &can_destroy_after_hidden_animation_, false); | |
58 | |
59 // Make sure the ink drop completes its full state transitions if it was going | |
60 // to auto transition to the HIDDEN state. | |
61 if (WillAutoAnimateToHidden()) | |
62 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); | |
49 ink_drop_animation_->AnimateToState(ink_drop_state); | 63 ink_drop_animation_->AnimateToState(ink_drop_state); |
50 } | 64 } |
51 | 65 |
66 bool InkDropAnimationControllerImpl::WillAutoAnimateToHidden() const { | |
varkha
2015/11/06 00:00:27
nit: Maybe ShouldAutoAnimateToHidden? It is not re
bruthig
2015/11/11 18:11:20
From the perspective of the InkDropAnimationContro
| |
67 if (!ink_drop_animation_) | |
68 return false; | |
69 switch (ink_drop_animation_->ink_drop_state()) { | |
70 case views::InkDropState::QUICK_ACTION: | |
71 case views::InkDropState::SLOW_ACTION: | |
72 case views::InkDropState::DEACTIVATED: | |
73 return true; | |
74 default: | |
75 return false; | |
76 } | |
77 } | |
78 | |
52 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { | 79 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { |
53 if (IsHovered() == is_hovered) | 80 if (IsHovered() == is_hovered) |
54 return; | 81 return; |
55 | 82 |
56 if (is_hovered) { | 83 if (is_hovered) { |
57 if (!hover_) | 84 if (!hover_) |
58 CreateInkDropHover(); | 85 CreateInkDropHover(); |
59 if (GetInkDropState() == views::InkDropState::HIDDEN) { | 86 if (GetInkDropState() == views::InkDropState::HIDDEN) { |
60 base::TimeDelta duration = | 87 base::TimeDelta duration = |
61 base::TimeDelta::FromMilliseconds(kFadeInDurationInMs); | 88 base::TimeDelta::FromMilliseconds(kFadeInDurationInMs); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 SetHovered(false); | 181 SetHovered(false); |
155 break; | 182 break; |
156 } | 183 } |
157 } | 184 } |
158 | 185 |
159 void InkDropAnimationControllerImpl::InkDropAnimationEnded( | 186 void InkDropAnimationControllerImpl::InkDropAnimationEnded( |
160 InkDropState ink_drop_state, | 187 InkDropState ink_drop_state, |
161 InkDropAnimationEndedReason reason) { | 188 InkDropAnimationEndedReason reason) { |
162 if (reason != SUCCESS) | 189 if (reason != SUCCESS) |
163 return; | 190 return; |
164 switch (ink_drop_state) { | 191 if (WillAutoAnimateToHidden()) |
165 case views::InkDropState::QUICK_ACTION: | 192 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); |
166 case views::InkDropState::SLOW_ACTION: | 193 else if (ink_drop_state == views::InkDropState::HIDDEN && |
167 case views::InkDropState::DEACTIVATED: | 194 can_destroy_after_hidden_animation_) { |
168 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); | |
169 break; | |
170 case views::InkDropState::HIDDEN: | |
171 // TODO(bruthig): Investigate whether creating and destroying | 195 // TODO(bruthig): Investigate whether creating and destroying |
172 // InkDropAnimations is expensive and consider creating an | 196 // InkDropAnimations is expensive and consider creating an |
173 // InkDropAnimationPool. See www.crbug.com/522175. | 197 // InkDropAnimationPool. See www.crbug.com/522175. |
174 DestroyInkDropAnimation(); | 198 DestroyInkDropAnimation(); |
175 break; | |
176 default: | |
177 break; | |
178 } | 199 } |
179 } | 200 } |
180 | 201 |
181 } // namespace views | 202 } // namespace views |
OLD | NEW |