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

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

Issue 1422593003: Made material design ink drop QUICK_ACTION animation more visible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged in changes to ink drop hover. Created 5 years, 1 month 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
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_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 "base/timer/timer.h" 8 #include "base/timer/timer.h"
8 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
9 #include "ui/views/animation/ink_drop_animation.h" 10 #include "ui/views/animation/ink_drop_animation.h"
10 #include "ui/views/animation/ink_drop_consumer.h" 11 #include "ui/views/animation/ink_drop_consumer.h"
11 #include "ui/views/animation/ink_drop_host.h" 12 #include "ui/views/animation/ink_drop_host.h"
12 #include "ui/views/animation/ink_drop_hover.h" 13 #include "ui/views/animation/ink_drop_hover.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 namespace { 17 namespace {
(...skipping 21 matching lines...) Expand all
38 } // namespace 39 } // namespace
39 40
40 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( 41 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
41 InkDropHost* ink_drop_host, 42 InkDropHost* ink_drop_host,
42 InkDropConsumer* ink_drop_consumer) 43 InkDropConsumer* ink_drop_consumer)
43 : ink_drop_host_(ink_drop_host), 44 : ink_drop_host_(ink_drop_host),
44 ink_drop_consumer_(ink_drop_consumer), 45 ink_drop_consumer_(ink_drop_consumer),
45 ink_drop_large_corner_radius_(0), 46 ink_drop_large_corner_radius_(0),
46 ink_drop_small_corner_radius_(0), 47 ink_drop_small_corner_radius_(0),
47 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), 48 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
49 can_destroy_after_hidden_animation_(true),
48 hover_after_animation_timer_(new base::OneShotTimer()) { 50 hover_after_animation_timer_(new base::OneShotTimer()) {
49 ink_drop_host_->AddInkDropLayer(root_layer_.get()); 51 ink_drop_host_->AddInkDropLayer(root_layer_.get());
50 } 52 }
51 53
52 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { 54 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() {
53 // Explicitly destroy the InkDropAnimation so that this still exists if 55 // Explicitly destroy the InkDropAnimation so that this still exists if
54 // views::InkDropAnimationObserver methods are called on this. 56 // views::InkDropAnimationObserver methods are called on this.
55 DestroyInkDropAnimation(); 57 DestroyInkDropAnimation();
56 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 58 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
57 } 59 }
58 60
59 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const { 61 InkDropState InkDropAnimationControllerImpl::GetInkDropState() const {
60 if (!ink_drop_animation_) 62 if (!ink_drop_animation_)
61 return InkDropState::HIDDEN; 63 return InkDropState::HIDDEN;
62 return ink_drop_animation_->ink_drop_state(); 64 return ink_drop_animation_->ink_drop_state();
63 } 65 }
64 66
65 void InkDropAnimationControllerImpl::AnimateToState( 67 void InkDropAnimationControllerImpl::AnimateToState(
66 InkDropState ink_drop_state) { 68 InkDropState ink_drop_state) {
67 if (!ink_drop_animation_) 69 if (!ink_drop_animation_)
68 CreateInkDropAnimation(); 70 CreateInkDropAnimation();
71
72 // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to
73 // know if it is safe to destroy the |ink_drop_animation_| and it is not safe
74 // when the notification is raised within a call to
75 // InkDropAnimation::AnimateToState().
76 base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation(
77 &can_destroy_after_hidden_animation_, false);
78
79 // Make sure the ink drop completes its full state transitions if it was going
80 // to auto transition to the HIDDEN state.
81 if (WillAutoAnimateToHidden())
82 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
69 ink_drop_animation_->AnimateToState(ink_drop_state); 83 ink_drop_animation_->AnimateToState(ink_drop_state);
70 } 84 }
71 85
86 bool InkDropAnimationControllerImpl::WillAutoAnimateToHidden() const {
87 if (!ink_drop_animation_)
88 return false;
89 switch (ink_drop_animation_->ink_drop_state()) {
90 case views::InkDropState::QUICK_ACTION:
91 case views::InkDropState::SLOW_ACTION:
92 case views::InkDropState::DEACTIVATED:
93 return true;
94 default:
95 return false;
96 }
97 }
98
72 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) { 99 void InkDropAnimationControllerImpl::SetHovered(bool is_hovered) {
73 SetHoveredInternal(is_hovered, 100 SetHoveredInternal(is_hovered,
74 is_hovered ? base::TimeDelta::FromMilliseconds( 101 is_hovered ? base::TimeDelta::FromMilliseconds(
75 kHoverFadeInFromUserInputDurationInMs) 102 kHoverFadeInFromUserInputDurationInMs)
76 : base::TimeDelta::FromMilliseconds( 103 : base::TimeDelta::FromMilliseconds(
77 kHoverFadeOutFromUserInputDurationInMs)); 104 kHoverFadeOutFromUserInputDurationInMs));
78 } 105 }
79 106
80 bool InkDropAnimationControllerImpl::IsHovered() const { 107 bool InkDropAnimationControllerImpl::IsHovered() const {
81 return hover_ && hover_->IsVisible(); 108 return hover_ && hover_->IsVisible();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( 185 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds(
159 kHoverFadeOutBeforeAnimationDurationInMs)); 186 kHoverFadeOutBeforeAnimationDurationInMs));
160 } 187 }
161 } 188 }
162 189
163 void InkDropAnimationControllerImpl::InkDropAnimationEnded( 190 void InkDropAnimationControllerImpl::InkDropAnimationEnded(
164 InkDropState ink_drop_state, 191 InkDropState ink_drop_state,
165 InkDropAnimationEndedReason reason) { 192 InkDropAnimationEndedReason reason) {
166 if (reason != SUCCESS) 193 if (reason != SUCCESS)
167 return; 194 return;
168 switch (ink_drop_state) { 195 if (WillAutoAnimateToHidden())
169 case views::InkDropState::QUICK_ACTION: 196 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
170 case views::InkDropState::SLOW_ACTION: 197 else if (ink_drop_state == views::InkDropState::HIDDEN) {
171 case views::InkDropState::DEACTIVATED: 198 StartHoverAfterAnimationTimer();
172 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); 199 if (can_destroy_after_hidden_animation_) {
173 break;
174 case views::InkDropState::HIDDEN:
175 StartHoverAfterAnimationTimer();
176 // TODO(bruthig): Investigate whether creating and destroying 200 // TODO(bruthig): Investigate whether creating and destroying
177 // InkDropAnimations is expensive and consider creating an 201 // InkDropAnimations is expensive and consider creating an
178 // InkDropAnimationPool. See www.crbug.com/522175. 202 // InkDropAnimationPool. See www.crbug.com/522175.
179 DestroyInkDropAnimation(); 203 DestroyInkDropAnimation();
180 break; 204 }
181 default:
182 break;
183 } 205 }
184 } 206 }
185 207
186 void InkDropAnimationControllerImpl::SetHoveredInternal( 208 void InkDropAnimationControllerImpl::SetHoveredInternal(
187 bool is_hovered, 209 bool is_hovered,
188 base::TimeDelta animation_duration) { 210 base::TimeDelta animation_duration) {
189 StopHoverAfterAnimationTimer(); 211 StopHoverAfterAnimationTimer();
190 212
191 if (IsHovered() == is_hovered) 213 if (IsHovered() == is_hovered)
192 return; 214 return;
(...skipping 24 matching lines...) Expand all
217 hover_after_animation_timer_->Reset(); 239 hover_after_animation_timer_->Reset();
218 } 240 }
219 241
220 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { 242 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() {
221 SetHoveredInternal(ink_drop_consumer_->ShouldShowInkDropHover(), 243 SetHoveredInternal(ink_drop_consumer_->ShouldShowInkDropHover(),
222 base::TimeDelta::FromMilliseconds( 244 base::TimeDelta::FromMilliseconds(
223 kHoverFadeInAfterAnimationDurationInMs)); 245 kHoverFadeInAfterAnimationDurationInMs));
224 } 246 }
225 247
226 } // namespace views 248 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698