Home | History | Annotate | Download | only in test
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "cc/animation/animation.h"
      6 #include "ui/compositor/layer_animation_sequence.h"
      7 #include "ui/compositor/test/layer_animator_test_controller.h"
      8 
      9 namespace ui {
     10 
     11 LayerAnimatorTestController::LayerAnimatorTestController(
     12     scoped_refptr<LayerAnimator> animator)
     13     : animator_(animator) {
     14 }
     15 
     16 LayerAnimatorTestController::~LayerAnimatorTestController() {
     17 }
     18 
     19 LayerAnimationSequence* LayerAnimatorTestController::GetRunningSequence(
     20     LayerAnimationElement::AnimatableProperty property) {
     21   LayerAnimator::RunningAnimation* running_animation =
     22       animator_->GetRunningAnimation(property);
     23   if (running_animation)
     24     return running_animation->sequence();
     25   else
     26     return NULL;
     27 }
     28 
     29 void LayerAnimatorTestController::StartThreadedAnimationsIfNeeded() {
     30   std::vector<cc::Animation::TargetProperty> threaded_properties;
     31   threaded_properties.push_back(cc::Animation::Opacity);
     32   threaded_properties.push_back(cc::Animation::Transform);
     33 
     34   for (size_t i = 0; i < threaded_properties.size(); i++) {
     35     LayerAnimationElement::AnimatableProperty animatable_property =
     36         LayerAnimationElement::ToAnimatableProperty(threaded_properties[i]);
     37     LayerAnimationSequence* sequence = GetRunningSequence(animatable_property);
     38     if (!sequence)
     39       continue;
     40 
     41     LayerAnimationElement* element = sequence->CurrentElement();
     42     if (element->properties().find(animatable_property) ==
     43         element->properties().end())
     44       continue;
     45 
     46     if (!element->Started() ||
     47         element->effective_start_time() != base::TimeTicks())
     48       continue;
     49 
     50     animator_->OnThreadedAnimationStarted(cc::AnimationEvent(
     51         cc::AnimationEvent::Started,
     52         0,
     53         element->animation_group_id(),
     54         threaded_properties[i],
     55         (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF()));
     56   }
     57 }
     58 
     59 }  // namespace ui
     60