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

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

Issue 1682893002: Color the ink drop ripple and hover effects based on theming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit tests Created 4 years, 10 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return InkDropState::HIDDEN; 74 return InkDropState::HIDDEN;
75 return ink_drop_animation_->ink_drop_state(); 75 return ink_drop_animation_->ink_drop_state();
76 } 76 }
77 77
78 bool InkDropAnimationControllerImpl::IsVisible() const { 78 bool InkDropAnimationControllerImpl::IsVisible() const {
79 return ink_drop_animation_ && ink_drop_animation_->IsVisible(); 79 return ink_drop_animation_ && ink_drop_animation_->IsVisible();
80 } 80 }
81 81
82 void InkDropAnimationControllerImpl::AnimateToState( 82 void InkDropAnimationControllerImpl::AnimateToState(
83 InkDropState ink_drop_state) { 83 InkDropState ink_drop_state) {
84 if (!ink_drop_animation_) 84 EnsureInkDropAnimation();
85 CreateInkDropAnimation();
86 85
87 // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to 86 // The InkDropAnimationObserver::InkDropAnimationEnded() callback needs to
88 // know if it is safe to destroy the |ink_drop_animation_| and it is not safe 87 // know if it is safe to destroy the |ink_drop_animation_| and it is not safe
89 // when the notification is raised within a call to 88 // when the notification is raised within a call to
90 // InkDropAnimation::AnimateToState(). 89 // InkDropAnimation::AnimateToState().
91 base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation( 90 base::AutoReset<bool> auto_reset_can_destroy_after_hidden_animation(
92 &can_destroy_after_hidden_animation_, false); 91 &can_destroy_after_hidden_animation_, false);
93 92
94 if (ink_drop_state != views::InkDropState::HIDDEN) { 93 if (ink_drop_state != views::InkDropState::HIDDEN) {
95 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds( 94 SetHoveredInternal(false, base::TimeDelta::FromMilliseconds(
(...skipping 14 matching lines...) Expand all
110 is_hovered ? base::TimeDelta::FromMilliseconds( 109 is_hovered ? base::TimeDelta::FromMilliseconds(
111 kHoverFadeInFromUserInputDurationInMs) 110 kHoverFadeInFromUserInputDurationInMs)
112 : base::TimeDelta::FromMilliseconds( 111 : base::TimeDelta::FromMilliseconds(
113 kHoverFadeOutFromUserInputDurationInMs)); 112 kHoverFadeOutFromUserInputDurationInMs));
114 } 113 }
115 114
116 bool InkDropAnimationControllerImpl::IsHovered() const { 115 bool InkDropAnimationControllerImpl::IsHovered() const {
117 return hover_ && hover_->IsVisible(); 116 return hover_ && hover_->IsVisible();
118 } 117 }
119 118
120 gfx::Size InkDropAnimationControllerImpl::GetInkDropLargeSize() const {
121 return ink_drop_large_size_;
122 }
123
124 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size, 119 void InkDropAnimationControllerImpl::SetInkDropSize(const gfx::Size& large_size,
125 int large_corner_radius, 120 int large_corner_radius,
126 const gfx::Size& small_size, 121 const gfx::Size& small_size,
127 int small_corner_radius) { 122 int small_corner_radius) {
123 CHECK(!ink_drop_animation_);
124 CHECK(!hover_);
sadrul 2016/02/10 23:26:49 D versions?
Evan Stade 2016/02/11 00:13:25 ah yes, thanks, meant to DCHECK. CHECK was just fo
125
128 // TODO(bruthig): Fix the ink drop animations to work for non-square sizes. 126 // TODO(bruthig): Fix the ink drop animations to work for non-square sizes.
129 DCHECK_EQ(large_size.width(), large_size.height()) 127 DCHECK_EQ(large_size.width(), large_size.height())
130 << "The ink drop animation does not currently support non-square sizes."; 128 << "The ink drop animation does not currently support non-square sizes.";
131 DCHECK_EQ(small_size.width(), small_size.height()) 129 DCHECK_EQ(small_size.width(), small_size.height())
132 << "The ink drop animation does not currently support non-square sizes."; 130 << "The ink drop animation does not currently support non-square sizes.";
133 ink_drop_large_size_ = large_size; 131 ink_drop_large_size_ = large_size;
134 ink_drop_large_corner_radius_ = large_corner_radius; 132 ink_drop_large_corner_radius_ = large_corner_radius;
135 ink_drop_small_size_ = small_size; 133 ink_drop_small_size_ = small_size;
136 ink_drop_small_corner_radius_ = small_corner_radius; 134 ink_drop_small_corner_radius_ = small_corner_radius;
137
138 DestroyInkDropAnimation();
139 DestroyInkDropHover();
140 } 135 }
141 136
142 void InkDropAnimationControllerImpl::SetInkDropCenter( 137 void InkDropAnimationControllerImpl::SetInkDropCenter(
143 const gfx::Point& center_point) { 138 const gfx::Point& center_point) {
144 ink_drop_center_ = center_point; 139 ink_drop_center_ = center_point;
145 if (ink_drop_animation_) 140 if (ink_drop_animation_)
146 ink_drop_animation_->SetCenterPoint(ink_drop_center_); 141 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
147 if (hover_) 142 if (hover_)
148 hover_->SetCenterPoint(ink_drop_center_); 143 hover_->SetCenterPoint(ink_drop_center_);
149 } 144 }
150 145
151 void InkDropAnimationControllerImpl::CreateInkDropAnimation() { 146 void InkDropAnimationControllerImpl::EnsureInkDropAnimation() {
147 SkColor color = ink_drop_host_->GetInkDropBaseColor();
148 if (ink_drop_animation_ && ink_drop_animation_->GetColor() == color)
149 return;
150
152 DestroyInkDropAnimation(); 151 DestroyInkDropAnimation();
153 152
154 ink_drop_animation_.reset(new SquareInkDropAnimation( 153 ink_drop_animation_.reset(new SquareInkDropAnimation(
155 ink_drop_large_size_, ink_drop_large_corner_radius_, ink_drop_small_size_, 154 color, ink_drop_large_size_, ink_drop_large_corner_radius_,
156 ink_drop_small_corner_radius_)); 155 ink_drop_small_size_, ink_drop_small_corner_radius_));
157 156
158 ink_drop_animation_->AddObserver(this); 157 ink_drop_animation_->AddObserver(this);
159 ink_drop_animation_->SetCenterPoint(ink_drop_center_); 158 ink_drop_animation_->SetCenterPoint(ink_drop_center_);
160 root_layer_->Add(ink_drop_animation_->root_layer()); 159 root_layer_->Add(ink_drop_animation_->root_layer());
161 } 160 }
162 161
163 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() { 162 void InkDropAnimationControllerImpl::DestroyInkDropAnimation() {
164 if (!ink_drop_animation_) 163 if (!ink_drop_animation_)
165 return; 164 return;
166 root_layer_->Remove(ink_drop_animation_->root_layer()); 165 root_layer_->Remove(ink_drop_animation_->root_layer());
167 ink_drop_animation_->RemoveObserver(this); 166 ink_drop_animation_->RemoveObserver(this);
168 ink_drop_animation_.reset(); 167 ink_drop_animation_.reset();
169 } 168 }
170 169
171 void InkDropAnimationControllerImpl::CreateInkDropHover() { 170 void InkDropAnimationControllerImpl::EnsureInkDropHover() {
171 SkColor color = ink_drop_host_->GetInkDropBaseColor();
172 if (hover_ && hover_->GetColor() == color)
173 return;
174
172 DestroyInkDropHover(); 175 DestroyInkDropHover();
173 176
174 hover_.reset( 177 hover_.reset(new InkDropHover(ink_drop_host_->GetInkDropBaseColor(),
175 new InkDropHover(ink_drop_small_size_, ink_drop_small_corner_radius_)); 178 ink_drop_small_size_,
179 ink_drop_small_corner_radius_));
176 hover_->SetCenterPoint(ink_drop_center_); 180 hover_->SetCenterPoint(ink_drop_center_);
177 root_layer_->Add(hover_->layer()); 181 root_layer_->Add(hover_->layer());
178 } 182 }
179 183
180 void InkDropAnimationControllerImpl::DestroyInkDropHover() { 184 void InkDropAnimationControllerImpl::DestroyInkDropHover() {
181 if (!hover_) 185 if (!hover_)
182 return; 186 return;
183 root_layer_->Remove(hover_->layer()); 187 root_layer_->Remove(hover_->layer());
184 hover_.reset(); 188 hover_.reset();
185 } 189 }
(...skipping 26 matching lines...) Expand all
212 216
213 void InkDropAnimationControllerImpl::SetHoveredInternal( 217 void InkDropAnimationControllerImpl::SetHoveredInternal(
214 bool is_hovered, 218 bool is_hovered,
215 base::TimeDelta animation_duration) { 219 base::TimeDelta animation_duration) {
216 StopHoverAfterAnimationTimer(); 220 StopHoverAfterAnimationTimer();
217 221
218 if (IsHovered() == is_hovered) 222 if (IsHovered() == is_hovered)
219 return; 223 return;
220 224
221 if (is_hovered) { 225 if (is_hovered) {
222 if (!hover_) 226 EnsureInkDropHover();
223 CreateInkDropHover(); 227 if (!IsVisible())
224 if (!IsVisible()) {
225 hover_->FadeIn(animation_duration); 228 hover_->FadeIn(animation_duration);
226 }
227 } else { 229 } else {
228 hover_->FadeOut(animation_duration); 230 hover_->FadeOut(animation_duration);
229 } 231 }
230 } 232 }
231 233
232 void InkDropAnimationControllerImpl::StartHoverAfterAnimationTimer() { 234 void InkDropAnimationControllerImpl::StartHoverAfterAnimationTimer() {
233 StopHoverAfterAnimationTimer(); 235 StopHoverAfterAnimationTimer();
234 236
235 if (!hover_after_animation_timer_) 237 if (!hover_after_animation_timer_)
236 hover_after_animation_timer_.reset(new base::OneShotTimer); 238 hover_after_animation_timer_.reset(new base::OneShotTimer);
(...skipping 11 matching lines...) Expand all
248 } 250 }
249 251
250 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() { 252 void InkDropAnimationControllerImpl::HoverAfterAnimationTimerFired() {
251 SetHoveredInternal(ink_drop_host_->ShouldShowInkDropHover(), 253 SetHoveredInternal(ink_drop_host_->ShouldShowInkDropHover(),
252 base::TimeDelta::FromMilliseconds( 254 base::TimeDelta::FromMilliseconds(
253 kHoverFadeInAfterAnimationDurationInMs)); 255 kHoverFadeInAfterAnimationDurationInMs));
254 hover_after_animation_timer_.reset(); 256 hover_after_animation_timer_.reset();
255 } 257 }
256 258
257 } // namespace views 259 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698