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

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

Issue 1951593002: Add MD Ink Drop to host only when a ripple/hover is active. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Replaced unique_ptr with scoped_ptr. 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();
67 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); 67 DestroyInkDropHover();
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 AddRootLayerToHostIfNeeded();
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 RemoveRootLayerFromHostIfNeeded();
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);
143 root_layer_->Add(hover_->layer()); 146 root_layer_->Add(hover_->layer());
147 AddRootLayerToHostIfNeeded();
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());
154 hover_->set_observer(nullptr);
150 hover_.reset(); 155 hover_.reset();
156 RemoveRootLayerFromHostIfNeeded();
157 }
158
159 void InkDropAnimationControllerImpl::AddRootLayerToHostIfNeeded() {
160 DCHECK(hover_ || ink_drop_animation_);
161 if (!root_layer_added_to_host_) {
162 root_layer_added_to_host_ = true;
163 ink_drop_host_->AddInkDropLayer(root_layer_.get());
164 }
165 }
166
167 void InkDropAnimationControllerImpl::RemoveRootLayerFromHostIfNeeded() {
168 if (root_layer_added_to_host_ && !hover_ && !ink_drop_animation_) {
169 root_layer_added_to_host_ = false;
170 ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
171 }
151 } 172 }
152 173
153 bool InkDropAnimationControllerImpl::IsHoverFadingInOrVisible() const { 174 bool InkDropAnimationControllerImpl::IsHoverFadingInOrVisible() const {
154 return hover_ && hover_->IsFadingInOrVisible(); 175 return hover_ && hover_->IsFadingInOrVisible();
155 } 176 }
156 177
178 // -----------------------------------------------------------------------------
179 // views::InkDropAnimationObserver:
180
157 void InkDropAnimationControllerImpl::AnimationStarted( 181 void InkDropAnimationControllerImpl::AnimationStarted(
158 InkDropState ink_drop_state) {} 182 InkDropState ink_drop_state) {}
159 183
160 void InkDropAnimationControllerImpl::AnimationEnded( 184 void InkDropAnimationControllerImpl::AnimationEnded(
161 InkDropState ink_drop_state, 185 InkDropState ink_drop_state,
162 InkDropAnimationEndedReason reason) { 186 InkDropAnimationEndedReason reason) {
163 if (reason != InkDropAnimationEndedReason::SUCCESS) 187 if (reason != InkDropAnimationEndedReason::SUCCESS)
164 return; 188 return;
165 if (ShouldAnimateToHidden(ink_drop_state)) { 189 if (ShouldAnimateToHidden(ink_drop_state)) {
166 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN); 190 ink_drop_animation_->AnimateToState(views::InkDropState::HIDDEN);
167 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 191 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
168 if (is_hovered_) 192 if (is_hovered_)
169 StartHoverAfterAnimationTimer(); 193 StartHoverAfterAnimationTimer();
170 // TODO(bruthig): Investigate whether creating and destroying 194 // TODO(bruthig): Investigate whether creating and destroying
171 // InkDropAnimations is expensive and consider creating an 195 // InkDropAnimations is expensive and consider creating an
172 // InkDropAnimationPool. See www.crbug.com/522175. 196 // InkDropAnimationPool. See www.crbug.com/522175.
173 DestroyInkDropAnimation(); 197 DestroyInkDropAnimation();
174 } 198 }
175 } 199 }
176 200
201 // -----------------------------------------------------------------------------
202 // views::InkDropHoverObserver:
203
204 void InkDropAnimationControllerImpl::AnimationStarted(
205 InkDropHover::AnimationType animation_type) {}
206
207 void InkDropAnimationControllerImpl::AnimationEnded(
208 InkDropHover::AnimationType animation_type,
209 InkDropAnimationEndedReason reason) {
210 if (animation_type == InkDropHover::FADE_OUT &&
211 reason == InkDropAnimationEndedReason::SUCCESS) {
212 DestroyInkDropHover();
213 }
214 }
215
177 void InkDropAnimationControllerImpl::SetHoveredInternal( 216 void InkDropAnimationControllerImpl::SetHoveredInternal(
178 bool is_hovered, 217 bool is_hovered,
179 base::TimeDelta animation_duration, 218 base::TimeDelta animation_duration,
180 bool explode) { 219 bool explode) {
181 StopHoverAfterAnimationTimer(); 220 StopHoverAfterAnimationTimer();
182 221
183 if (IsHoverFadingInOrVisible() == is_hovered) 222 if (IsHoverFadingInOrVisible() == is_hovered)
184 return; 223 return;
185 224
186 if (is_hovered) { 225 if (is_hovered) {
(...skipping 24 matching lines...) Expand all
211 } 250 }
212 251
213 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { 252 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() {
214 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds( 253 SetHoveredInternal(true, base::TimeDelta::FromMilliseconds(
215 kHoverFadeInAfterAnimationDurationInMs), 254 kHoverFadeInAfterAnimationDurationInMs),
216 true); 255 true);
217 hover_after_animation_timer_.reset(); 256 hover_after_animation_timer_.reset();
218 } 257 }
219 258
220 } // namespace views 259 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698