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

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

Issue 1897073002: Add MD Ink Drop Layers to InkDropHost only when a ripple/hover is active. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some more tests. 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
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/auto_reset.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/views/animation/ink_drop_host.h" 10 #include "ui/views/animation/ink_drop_host.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return false; 47 return false;
48 } 48 }
49 } 49 }
50 50
51 } // namespace 51 } // namespace
52 52
53 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl( 53 InkDropAnimationControllerImpl::InkDropAnimationControllerImpl(
54 InkDropHost* ink_drop_host) 54 InkDropHost* ink_drop_host)
55 : ink_drop_host_(ink_drop_host), 55 : ink_drop_host_(ink_drop_host),
56 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), 56 root_layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)),
57 root_layer_added_to_host_(false),
57 is_hovered_(false), 58 is_hovered_(false),
58 hover_after_animation_timer_(nullptr) { 59 hover_after_animation_timer_(nullptr) {
59 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer"); 60 root_layer_->set_name("InkDropAnimationControllerImpl:RootLayer");
60 ink_drop_host_->AddInkDropLayer(root_layer_.get());
61 } 61 }
62 62
63 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() { 63 InkDropAnimationControllerImpl::~InkDropAnimationControllerImpl() {
64 // Explicitly destroy the InkDropAnimation so that this still exists if 64 // Explicitly destroy the InkDropAnimation so that this still exists if
65 // views::InkDropAnimationObserver methods are called on this. 65 // views::InkDropAnimationObserver methods are called on this.
66 DestroyInkDropAnimation(); 66 DestroyInkDropAnimation();
varkha 2016/04/28 20:35:00 Don't you need to call DestroyInkDropHover() here
bruthig 2016/04/29 11:02:34 Good catch! Fixed and test added.
67 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 67 RemoveRootLayerFromHost();
68 } 68 }
69 69
70 InkDropState InkDropAnimationControllerImpl::GetTargetInkDropState() const { 70 InkDropState InkDropAnimationControllerImpl::GetTargetInkDropState() const {
71 if (!ink_drop_animation_) 71 if (!ink_drop_animation_)
72 return InkDropState::HIDDEN; 72 return InkDropState::HIDDEN;
73 return ink_drop_animation_->target_ink_drop_state(); 73 return ink_drop_animation_->target_ink_drop_state();
74 } 74 }
75 75
76 bool InkDropAnimationControllerImpl::IsVisible() const { 76 bool InkDropAnimationControllerImpl::IsVisible() const {
77 return ink_drop_animation_ && ink_drop_animation_->IsVisible(); 77 return ink_drop_animation_ && ink_drop_animation_->IsVisible();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state()))) { 118 ShouldAnimateToHidden(ink_drop_animation_->target_ink_drop_state()))) {
119 DestroyInkDropAnimation(); 119 DestroyInkDropAnimation();
120 } 120 }
121 } 121 }
122 122
123 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { 123 void InkDropAnimationControllerImpl::CreateInkDropAnimation() {
124 DestroyInkDropAnimation(); 124 DestroyInkDropAnimation();
125 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation(); 125 ink_drop_animation_ = ink_drop_host_->CreateInkDropAnimation();
126 ink_drop_animation_->set_observer(this); 126 ink_drop_animation_->set_observer(this);
127 root_layer_->Add(ink_drop_animation_->GetRootLayer()); 127 root_layer_->Add(ink_drop_animation_->GetRootLayer());
128 AddRootLayerToHost();
128 } 129 }
129 130
130 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { 131 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() {
131 if (!ink_drop_animation_) 132 if (!ink_drop_animation_)
132 return; 133 return;
133 root_layer_->Remove(ink_drop_animation_->GetRootLayer()); 134 root_layer_->Remove(ink_drop_animation_->GetRootLayer());
134 ink_drop_animation_.reset(); 135 ink_drop_animation_.reset();
136 RemoveRootLayerFromHost();
135 } 137 }
136 138
137 void InkDropAnimationControllerImpl::CreateInkDropHover() { 139 void InkDropAnimationControllerImpl::CreateInkDropHover() {
138 DestroyInkDropHover(); 140 DestroyInkDropHover();
139 141
140 hover_ = ink_drop_host_->CreateInkDropHover(); 142 hover_ = ink_drop_host_->CreateInkDropHover();
141 if (!hover_) 143 if (!hover_)
142 return; 144 return;
145 hover_->set_observer(this);
varkha 2016/04/28 20:35:00 Do you ever need to set it back to nullptr? I thin
bruthig 2016/04/29 11:02:34 Updated to explicitly set_observer(nullptr) in Des
143 root_layer_->Add(hover_->layer()); 146 root_layer_->Add(hover_->layer());
147 AddRootLayerToHost();
144 } 148 }
145 149
146 void InkDropAnimationControllerImpl::DestroyInkDropHover() { 150 void InkDropAnimationControllerImpl::DestroyInkDropHover() {
147 if (!hover_) 151 if (!hover_)
148 return; 152 return;
149 root_layer_->Remove(hover_->layer()); 153 root_layer_->Remove(hover_->layer());
150 hover_.reset(); 154 hover_.reset();
155 RemoveRootLayerFromHost();
156 }
157
158 void InkDropAnimationControllerImpl::AddRootLayerToHost() {
159 if (!root_layer_added_to_host_ && (hover_ || ink_drop_animation_)) {
varkha 2016/04/28 20:35:00 Shouldn't it be possible to DCHECK(hover_ || ink_d
bruthig 2016/04/29 11:02:34 Done.
160 root_layer_added_to_host_ = true;
161 ink_drop_host_->AddInkDropLayer(root_layer_.get());
162 }
163 }
164
165 void InkDropAnimationControllerImpl::RemoveRootLayerFromHost() {
166 if (root_layer_added_to_host_ && !hover_ && !ink_drop_animation_) {
167 root_layer_added_to_host_ = false;
168 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
169 }
151 } 170 }
152 171
153 bool InkDropAnimationControllerImpl::IsHoverFadingInOrVisible() const { 172 bool InkDropAnimationControllerImpl::IsHoverFadingInOrVisible() const {
154 return hover_ && hover_->IsFadingInOrVisible(); 173 return hover_ && hover_->IsFadingInOrVisible();
155 } 174 }
156 175
157 void InkDropAnimationControllerImpl::AnimationStarted( 176 void InkDropAnimationControllerImpl::AnimationStarted(
158 InkDropState ink_drop_state) {} 177 InkDropState ink_drop_state) {}
159 178
160 void InkDropAnimationControllerImpl::AnimationEnded( 179 void InkDropAnimationControllerImpl::AnimationEnded(
161 InkDropState ink_drop_state, 180 InkDropState ink_drop_state,
162 InkDropAnimationEndedReason reason) { 181 InkDropAnimationEndedReason reason) {
163 if (reason != InkDropAnimationEndedReason::SUCCESS) 182 if (reason != InkDropAnimationEndedReason::SUCCESS)
164 return; 183 return;
165 if (ShouldAnimateToHidden(ink_drop_state)) { 184 if (ShouldAnimateToHidden(ink_drop_state)) {
166 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); 185 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
167 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 186 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
168 if (is_hovered_) 187 if (is_hovered_)
169 StartHoverAfterAnimationTimer(); 188 StartHoverAfterAnimationTimer();
170 // TODO(bruthig): Investigate whether creating and destroying 189 // TODO(bruthig): Investigate whether creating and destroying
171 // InkDropAnimations is expensive and consider creating an 190 // InkDropAnimations is expensive and consider creating an
172 // InkDropAnimationPool. See www.crbug.com/522175. 191 // InkDropAnimationPool. See www.crbug.com/522175.
173 DestroyInkDropAnimation(); 192 DestroyInkDropAnimation();
174 } 193 }
175 } 194 }
176 195
varkha 2016/04/28 20:35:00 Maybe a // views::InkDropHoverObserver: banner com
bruthig 2016/04/29 11:02:34 Done.
196 void InkDropAnimationControllerImpl::AnimationStarted(
197 InkDropHover::AnimationType animation_type) {}
198
199 void InkDropAnimationControllerImpl::AnimationEnded(
200 InkDropHover::AnimationType animation_type,
201 InkDropAnimationEndedReason reason) {
202 if (animation_type == InkDropHover::FADE_OUT &&
203 reason == InkDropAnimationEndedReason::SUCCESS) {
204 DestroyInkDropHover();
205 }
206 }
207
177 void InkDropAnimationControllerImpl::SetHoveredInternal( 208 void InkDropAnimationControllerImpl::SetHoveredInternal(
178 bool is_hovered, 209 bool is_hovered,
179 base::TimeDelta animation_duration, 210 base::TimeDelta animation_duration,
180 bool explode) { 211 bool explode) {
181 StopHoverAfterAnimationTimer(); 212 StopHoverAfterAnimationTimer();
182 213
183 if (IsHoverFadingInOrVisible() == is_hovered) 214 if (IsHoverFadingInOrVisible() == is_hovered)
184 return; 215 return;
185 216
186 if (is_hovered) { 217 if (is_hovered) {
(...skipping 24 matching lines...) Expand all
211 } 242 }
212 243
213 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { 244 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() {
214 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( 245 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds(
215 kHoverFadeInAfterAnimationDurationInMs), 246 kHoverFadeInAfterAnimationDurationInMs),
216 true); 247 true);
217 hover_after_animation_timer_.reset(); 248 hover_after_animation_timer_.reset();
218 } 249 }
219 250
220 } // namespace views 251 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698