15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_COMPOSITOR_LAYER_ANIMATOR_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_COMPOSITOR_LAYER_ANIMATOR_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <deque> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "base/gtest_prod_util.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/linked_ptr.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/observer_list.h" 16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/compositor_export.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/compositor/layer_animation_element.h" 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ui/gfx/animation/tween.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx { 22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class Animation; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Rect; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Transform; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ui { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Layer; 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayerAnimationSequence; 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayerAnimationDelegate; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class LayerAnimationObserver; 3246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class LayerAnimatorCollection; 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScopedLayerAnimationSettings; 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// When a property of layer needs to be changed it is set by way of 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// LayerAnimator. This enables LayerAnimator to animate property changes. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NB: during many tests, set_disable_animations_for_test is used and causes 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// all animations to complete immediately. The layer animation is ref counted 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// so that if its owning layer is deleted (and the owning layer is only other 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// class that should ever hold a ref ptr to a LayerAnimator), the animator can 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ensure that it is not disposed of until it finishes executing. It does this 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// by holding a reference to itself for the duration of methods for which it 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// must guarantee that |this| is valid. 4446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)class COMPOSITOR_EXPORT LayerAnimator : public base::RefCounted<LayerAnimator> { 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum PreemptionStrategy { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IMMEDIATELY_SET_NEW_TARGET, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ENQUEUE_NEW_ANIMATION, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) REPLACE_QUEUED_ANIMATIONS, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) BLEND_WITH_CURRENT_ANIMATION 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit LayerAnimator(base::TimeDelta transition_duration); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // No implicit animations when properties are set. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static LayerAnimator* CreateDefaultAnimator(); 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Implicitly animates when properties are set. 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static LayerAnimator* CreateImplicitAnimator(); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the transform on the delegate. May cause an implicit animation. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetTransform(const gfx::Transform& transform); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Transform GetTargetTransform() const; 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the bounds on the delegate. May cause an implicit animation. 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetBounds(const gfx::Rect& bounds); 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect GetTargetBounds() const; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the opacity on the delegate. May cause an implicit animation. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetOpacity(float opacity); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float GetTargetOpacity() const; 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the visibility of the delegate. May cause an implicit animation. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetVisibility(bool visibility); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool GetTargetVisibility() const; 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the brightness on the delegate. May cause an implicit animation. 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetBrightness(float brightness); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float GetTargetBrightness() const; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the grayscale on the delegate. May cause an implicit animation. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetGrayscale(float grayscale); 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) float GetTargetGrayscale() const; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the color on the delegate. May cause an implicit animation. 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetColor(SkColor color); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SkColor GetTargetColor() const; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Returns the default length of animations, including adjustment for slow 91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // animation mode if set. 92a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::TimeDelta GetTransitionDuration() const; 93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the layer animation delegate the animator is associated with. The 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // animator does not own the delegate. The layer animator expects a non-NULL 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // delegate for most of its operations, so do not call any methods without 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a valid delegate installed. 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SetDelegate(LayerAnimationDelegate* delegate); 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the animation preemption strategy. This determines the behaviour if 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a property is set during an animation. The default is 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // IMMEDIATELY_SET_NEW_TARGET (see ImmediatelySetNewTarget below). 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_preemption_strategy(PreemptionStrategy strategy) { 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) preemption_strategy_ = strategy; 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PreemptionStrategy preemption_strategy() const { 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return preemption_strategy_; 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Start an animation sequence. If an animation for the same property is in 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // progress, it needs to be interrupted with the new animation. The animator 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // takes ownership of this animation sequence. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartAnimation(LayerAnimationSequence* animation); 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedule an animation to be run when possible. The animator takes ownership 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // of this animation sequence. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleAnimation(LayerAnimationSequence* animation); 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Starts the animations to be run together, ensuring that the first elements 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // in these sequences have the same effective start time even when some of 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // them start on the compositor thread (but there is no such guarantee for 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the effective start time of subsequent elements). Obviously will not work 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // if they animate any common properties. The animator takes ownership of the 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animation sequences. Takes PreemptionStrategy into account. 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StartTogether(const std::vector<LayerAnimationSequence*>& animations); 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Schedules the animations to be run together, ensuring that the first 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // elements in these sequences have the same effective start time even when 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // some of them start on the compositor thread (but there is no such guarantee 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // for the effective start time of subsequent elements). Obviously will not 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // work if they animate any common properties. The animator takes ownership 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // of the animation sequences. 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ScheduleTogether(const std::vector<LayerAnimationSequence*>& animations); 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Schedules a pause for length |duration| of all the specified properties. 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // End the list with -1. 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void SchedulePauseForProperties( 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeDelta duration, 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) LayerAnimationElement::AnimatableProperties properties_to_pause); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if there is an animation in the queue (animations remain in 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the queue until they complete, so this includes running animations). 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_animating() const { return !animation_queue_.empty(); } 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if there is an animation in the queue that animates the given 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // property (animations remain in the queue until they complete, so this 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // includes running animations). 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsAnimatingProperty( 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationElement::AnimatableProperty property) const; 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Stops animating the given property. No effect if there is no running 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // animation for the given property. Skips to the final state of the 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // animation. 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StopAnimatingProperty( 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationElement::AnimatableProperty property); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Stops all animation and clears any queued animations. This call progresses 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animations to their end points and notifies all observers. 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StopAnimating() { StopAnimatingInternal(false); } 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This is similar to StopAnimating, but aborts rather than finishes the 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animations and notifies all observers. 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void AbortAllAnimations() { StopAnimatingInternal(true); } 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These functions are used for adding or removing observers from the observer 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // list. The observers are notified when animations end. 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddObserver(LayerAnimationObserver* observer); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveObserver(LayerAnimationObserver* observer); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Called when a threaded animation is actually started. 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnThreadedAnimationStarted(const cc::AnimationEvent& event); 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This determines how implicit animations will be tweened. This has no 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // effect on animations that are explicitly started or scheduled. The default 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is Tween::LINEAR. 177d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void set_tween_type(gfx::Tween::Type tween_type) { tween_type_ = tween_type; } 178d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::Tween::Type tween_type() const { return tween_type_; } 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For testing purposes only. 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_disable_timer_for_test(bool disable_timer) { 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) disable_timer_for_test_ = disable_timer; 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void set_last_step_time(base::TimeTicks time) { 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) last_step_time_ = time; 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks last_step_time() const { return last_step_time_; } 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 19046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void Step(base::TimeTicks time_now); 19146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 19246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void AddToCollection(LayerAnimatorCollection* collection); 19346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void RemoveFromCollection(LayerAnimatorCollection* collection); 19446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~LayerAnimator(); 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationDelegate* delegate() { return delegate_; } 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const LayerAnimationDelegate* delegate() const { return delegate_; } 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Virtual for testing. 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ProgressAnimation(LayerAnimationSequence* sequence, 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::TimeTicks now); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ProgressAnimationToEnd(LayerAnimationSequence* sequence); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if the sequence is owned by this animator. 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool HasAnimation(LayerAnimationSequence* sequence) const; 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class base::RefCounted<LayerAnimator>; 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class ScopedLayerAnimationSettings; 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class LayerAnimatorTestController; 21446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, AnimatorStartedCorrectly); 21546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) FRIEND_TEST_ALL_PREFIXES(LayerAnimatorTest, 21646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) AnimatorRemovedFromCollectionWhenLayerIsDestroyed); 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class RunningAnimation { 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RunningAnimation(const base::WeakPtr<LayerAnimationSequence>& sequence); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~RunningAnimation(); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool is_sequence_alive() const { return !!sequence_.get(); } 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationSequence* sequence() const { return sequence_.get(); } 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::WeakPtr<LayerAnimationSequence> sequence_; 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Copy and assign are allowed. 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::vector<RunningAnimation> RunningAnimations; 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::deque<linked_ptr<LayerAnimationSequence> > AnimationQueue; 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Finishes all animations by either advancing them to their final state or by 2362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // aborting them. 2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void StopAnimatingInternal(bool abort); 2382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Starts or stops stepping depending on whether thare are running animations. 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateAnimationState(); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Removes the sequences from both the running animations and the queue. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns a pointer to the removed animation, if any. NOTE: the caller is 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // responsible for deleting the returned pointer. 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationSequence* RemoveAnimation( 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationSequence* sequence) WARN_UNUSED_RESULT; 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Progresses to the end of the sequence before removing it. 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void FinishAnimation(LayerAnimationSequence* sequence, bool abort); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Finishes any running animation with zero duration. 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void FinishAnyAnimationWithZeroDuration(); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears the running animations and the queue. No sequences are progressed. 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearAnimations(); 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the running animation animating the given property, if any. 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RunningAnimation* GetRunningAnimation( 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationElement::AnimatableProperty property); 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks if the sequence has already been added to the queue and adds it 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to the front if note. 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddToQueueIfNotPresent(LayerAnimationSequence* sequence); 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Any running or queued animation that affects a property in common with 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |sequence| is either finished or aborted depending on |abort|. 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RemoveAllAnimationsWithACommonProperty(LayerAnimationSequence* sequence, 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool abort); 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Preempts a running animation by progressing both the running animation and 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the given sequence to the end. 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ImmediatelySetNewTarget(LayerAnimationSequence* sequence); 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Preempts by aborting the running animation, and starts the given animation. 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ImmediatelyAnimateToNewTarget(LayerAnimationSequence* sequence); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Preempts by adding the new animation to the queue. 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void EnqueueNewAnimation(LayerAnimationSequence* sequence); 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Preempts by wiping out any unstarted animation in the queue and then 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // enqueuing this animation. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReplaceQueuedAnimations(LayerAnimationSequence* sequence); 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If there's an animation in the queue that doesn't animate the same property 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // as a running animation, or an animation schedule to run before it, start it 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // up. Repeat until there are no such animations. 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ProcessQueue(); 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Attempts to add the sequence to the list of running animations. Returns 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false if there is an animation running that already animates one of the 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // properties affected by |sequence|. 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool StartSequenceImmediately(LayerAnimationSequence* sequence); 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets the value of target as if all the running and queued animations were 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // allowed to finish. 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void GetTargetValue(LayerAnimationElement::TargetValue* target) const; 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called whenever an animation is added to the animation queue. Either by 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // starting the animation or adding to the queue. 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnScheduled(LayerAnimationSequence* sequence); 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 302a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Sets |transition_duration_| unless |is_transition_duration_locked_| is set. 303a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void SetTransitionDuration(base::TimeDelta duration); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Clears the animation queues and notifies any running animations that they 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // have been aborted. 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ClearAnimationsInternal(); 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Cleans up any running animations that may have been deleted. 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void PurgeDeletedAnimations(); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) LayerAnimatorCollection* GetLayerAnimatorCollection(); 31346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is the queue of animations to run. 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AnimationQueue animation_queue_; 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The target of all layer animations. 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LayerAnimationDelegate* delegate_; 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The currently running animations. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RunningAnimations running_animations_; 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Determines how animations are replaced. 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PreemptionStrategy preemption_strategy_; 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 326a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Whether the length of animations is locked. While it is locked 327a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // SetTransitionDuration does not set |transition_duration_|. 328a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) bool is_transition_duration_locked_; 329a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default length of animations. 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeDelta transition_duration_; 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default tween type for implicit transitions 334d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) gfx::Tween::Type tween_type_; 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used for coordinating the starting of animations. 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks last_step_time_; 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if we are being stepped by our container. 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool is_started_; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This prevents the animator from automatically stepping through animations 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and allows for manual stepping. 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool disable_timer_for_test_; 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Prevents timer adjustments in case when we start multiple animations 3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // with preemption strategies that discard previous animations. 3482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool adding_animations_; 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Observers are notified when layer animations end, are scheduled or are 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // aborted. 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ObserverList<LayerAnimationObserver> observers_; 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LayerAnimator); 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ui 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // UI_COMPOSITOR_LAYER_ANIMATOR_H_ 360