OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compositor/layer_animation_element.h" | 5 #include "ui/compositor/layer_animation_element.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "ui/base/animation/tween.h" | 8 #include "ui/base/animation/tween.h" |
9 #include "ui/compositor/layer_animation_delegate.h" | 9 #include "ui/compositor/layer_animation_delegate.h" |
10 #include "ui/compositor/layer_animator.h" | 10 #include "ui/compositor/layer_animator.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 properties.insert(LayerAnimationElement::VISIBILITY); | 225 properties.insert(LayerAnimationElement::VISIBILITY); |
226 return properties; | 226 return properties; |
227 } | 227 } |
228 | 228 |
229 bool start_; | 229 bool start_; |
230 const bool target_; | 230 const bool target_; |
231 | 231 |
232 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); | 232 DISALLOW_COPY_AND_ASSIGN(VisibilityTransition); |
233 }; | 233 }; |
234 | 234 |
| 235 // BrightnessTransition -------------------------------------------------------- |
| 236 |
| 237 class BrightnessTransition : public LayerAnimationElement { |
| 238 public: |
| 239 BrightnessTransition(float target, base::TimeDelta duration) |
| 240 : LayerAnimationElement(GetProperties(), duration), |
| 241 start_(0.0f), |
| 242 target_(target) { |
| 243 } |
| 244 virtual ~BrightnessTransition() {} |
| 245 |
| 246 protected: |
| 247 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 248 start_ = delegate->GetBrightnessForAnimation(); |
| 249 } |
| 250 |
| 251 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
| 252 delegate->SetBrightnessFromAnimation( |
| 253 Tween::ValueBetween(t, start_, target_)); |
| 254 return true; |
| 255 } |
| 256 |
| 257 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
| 258 target->brightness = target_; |
| 259 } |
| 260 |
| 261 virtual void OnAbort() OVERRIDE {} |
| 262 |
| 263 private: |
| 264 static AnimatableProperties GetProperties() { |
| 265 AnimatableProperties properties; |
| 266 properties.insert(LayerAnimationElement::BRIGHTNESS); |
| 267 return properties; |
| 268 } |
| 269 |
| 270 float start_; |
| 271 const float target_; |
| 272 |
| 273 DISALLOW_COPY_AND_ASSIGN(BrightnessTransition); |
| 274 }; |
| 275 |
| 276 // GrayscaleTransition --------------------------------------------------------- |
| 277 |
| 278 class GrayscaleTransition : public LayerAnimationElement { |
| 279 public: |
| 280 GrayscaleTransition(float target, base::TimeDelta duration) |
| 281 : LayerAnimationElement(GetProperties(), duration), |
| 282 start_(0.0f), |
| 283 target_(target) { |
| 284 } |
| 285 virtual ~GrayscaleTransition() {} |
| 286 |
| 287 protected: |
| 288 virtual void OnStart(LayerAnimationDelegate* delegate) OVERRIDE { |
| 289 start_ = delegate->GetGrayscaleForAnimation(); |
| 290 } |
| 291 |
| 292 virtual bool OnProgress(double t, LayerAnimationDelegate* delegate) OVERRIDE { |
| 293 delegate->SetGrayscaleFromAnimation( |
| 294 Tween::ValueBetween(t, start_, target_)); |
| 295 return true; |
| 296 } |
| 297 |
| 298 virtual void OnGetTarget(TargetValue* target) const OVERRIDE { |
| 299 target->grayscale = target_; |
| 300 } |
| 301 |
| 302 virtual void OnAbort() OVERRIDE {} |
| 303 |
| 304 private: |
| 305 static AnimatableProperties GetProperties() { |
| 306 AnimatableProperties properties; |
| 307 properties.insert(LayerAnimationElement::GRAYSCALE); |
| 308 return properties; |
| 309 } |
| 310 |
| 311 float start_; |
| 312 const float target_; |
| 313 |
| 314 DISALLOW_COPY_AND_ASSIGN(GrayscaleTransition); |
| 315 }; |
| 316 |
235 } // namespace | 317 } // namespace |
236 | 318 |
237 // LayerAnimationElement::TargetValue ------------------------------------------ | 319 // LayerAnimationElement::TargetValue ------------------------------------------ |
238 | 320 |
239 LayerAnimationElement::TargetValue::TargetValue() | 321 LayerAnimationElement::TargetValue::TargetValue() |
240 : opacity(0.0f), | 322 : opacity(0.0f), |
241 visibility(false) { | 323 visibility(false), |
| 324 brightness(0.0f), |
| 325 grayscale(0.0f) { |
242 } | 326 } |
243 | 327 |
244 LayerAnimationElement::TargetValue::TargetValue( | 328 LayerAnimationElement::TargetValue::TargetValue( |
245 const LayerAnimationDelegate* delegate) | 329 const LayerAnimationDelegate* delegate) |
246 : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()), | 330 : bounds(delegate ? delegate->GetBoundsForAnimation() : gfx::Rect()), |
247 transform(delegate ? delegate->GetTransformForAnimation() : Transform()), | 331 transform(delegate ? delegate->GetTransformForAnimation() : Transform()), |
248 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), | 332 opacity(delegate ? delegate->GetOpacityForAnimation() : 0.0f), |
249 visibility(delegate ? delegate->GetVisibilityForAnimation() : false) { | 333 visibility(delegate ? delegate->GetVisibilityForAnimation() : false), |
| 334 brightness(delegate ? delegate->GetBrightnessForAnimation() : 0.0f), |
| 335 grayscale(delegate ? delegate->GetGrayscaleForAnimation() : 0.0f) { |
250 } | 336 } |
251 | 337 |
252 // LayerAnimationElement ------------------------------------------------------- | 338 // LayerAnimationElement ------------------------------------------------------- |
253 | 339 |
254 LayerAnimationElement::LayerAnimationElement( | 340 LayerAnimationElement::LayerAnimationElement( |
255 const AnimatableProperties& properties, | 341 const AnimatableProperties& properties, |
256 base::TimeDelta duration) | 342 base::TimeDelta duration) |
257 : first_frame_(true), | 343 : first_frame_(true), |
258 properties_(properties), | 344 properties_(properties), |
259 duration_(GetEffectiveDuration(duration)), | 345 duration_(GetEffectiveDuration(duration)), |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 return new OpacityTransition(opacity, duration); | 404 return new OpacityTransition(opacity, duration); |
319 } | 405 } |
320 | 406 |
321 // static | 407 // static |
322 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( | 408 LayerAnimationElement* LayerAnimationElement::CreateVisibilityElement( |
323 bool visibility, base::TimeDelta duration) { | 409 bool visibility, base::TimeDelta duration) { |
324 return new VisibilityTransition(visibility, duration); | 410 return new VisibilityTransition(visibility, duration); |
325 } | 411 } |
326 | 412 |
327 // static | 413 // static |
| 414 LayerAnimationElement* LayerAnimationElement::CreateBrightnessElement( |
| 415 float brightness, base::TimeDelta duration) { |
| 416 return new BrightnessTransition(brightness, duration); |
| 417 } |
| 418 |
| 419 // static |
| 420 LayerAnimationElement* LayerAnimationElement::CreateGrayscaleElement( |
| 421 float grayscale, base::TimeDelta duration) { |
| 422 return new GrayscaleTransition(grayscale, duration); |
| 423 } |
| 424 |
| 425 // static |
328 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( | 426 LayerAnimationElement* LayerAnimationElement::CreatePauseElement( |
329 const AnimatableProperties& properties, base::TimeDelta duration) { | 427 const AnimatableProperties& properties, base::TimeDelta duration) { |
330 return new Pause(properties, duration); | 428 return new Pause(properties, duration); |
331 } | 429 } |
332 | 430 |
333 } // namespace ui | 431 } // namespace ui |
OLD | NEW |