blob: 4eeb6f2b080788f6ca8165fb574320d302218b5b [file] [log] [blame]
// Copyright 2015 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
#include <algorithm>
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "cobalt/cssom/property_definitions.h"
#include "cobalt/cssom/timing_function.h"
namespace cobalt {
namespace cssom {
class PropertyValue;
// A Transition object represents a persistant transition from one CSS style
// value to another. Most of the data members of this class are defined with
// names based off of the concepts named here:
class Transition {
Transition(PropertyKey target_property,
const scoped_refptr<PropertyValue>& start_value,
const scoped_refptr<PropertyValue>& end_value,
const base::TimeDelta& start_time, const base::TimeDelta& duration,
const base::TimeDelta& delay,
const scoped_refptr<TimingFunction>& timing_function,
scoped_refptr<PropertyValue> reversing_adjusted_start_value,
float reversing_shortening_factor);
PropertyKey target_property() const { return target_property_; }
const base::TimeDelta& start_time() const { return start_time_; }
const base::TimeDelta& duration() const { return duration_; }
const base::TimeDelta& delay() const { return delay_; }
const scoped_refptr<TimingFunction>& timing_function() const {
return timing_function_;
const scoped_refptr<PropertyValue>& start_value() const {
return start_value_;
const scoped_refptr<PropertyValue>& end_value() const { return end_value_; }
// The reversing shortening factor and reversing adjusted start value are
// both used for dealing with the special case where a property that is
// already transitioning is modified again to now transition back to where
// it was transitioning from. In this case, it would look weird if the
// reversing transition took the full duration despite the original transition
// being cancelled part-way through and so not taking the full duration.
// These members help us know how to modify the reversing transition to have
// the same duration as the cancelled initial transition. They are described
// here:
const scoped_refptr<PropertyValue>& reversing_adjusted_start_value() const {
return reversing_adjusted_start_value_;
float reversing_shortening_factor() const {
return reversing_shortening_factor_;
// Returns the animation progress at a specified time. This will take into
// account animation delay, duration, and timing function.
float Progress(const base::TimeDelta& time) const;
const base::TimeDelta EndTime() const;
// Produces an animated property value for the specified time.
scoped_refptr<PropertyValue> Evaluate(const base::TimeDelta& time) const;
PropertyKey target_property_;
scoped_refptr<PropertyValue> start_value_;
scoped_refptr<PropertyValue> end_value_;
base::TimeDelta start_time_;
base::TimeDelta duration_;
base::TimeDelta delay_;
scoped_refptr<TimingFunction> timing_function_;
// See the getter methods for these members for documentation.
scoped_refptr<PropertyValue> reversing_adjusted_start_value_;
float reversing_shortening_factor_;
} // namespace cssom
} // namespace cobalt