OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 template <> | 46 template <> |
47 void appendKeyframe<TransformAnimationValue, CCTransformKeyframe, CCKeyframedTra
nsformAnimationCurve>(CCKeyframedTransformAnimationCurve& curve, double keyTime,
const TransformAnimationValue* value, PassOwnPtr<CCTimingFunction> timingFuncti
on) | 47 void appendKeyframe<TransformAnimationValue, CCTransformKeyframe, CCKeyframedTra
nsformAnimationCurve>(CCKeyframedTransformAnimationCurve& curve, double keyTime,
const TransformAnimationValue* value, PassOwnPtr<CCTimingFunction> timingFuncti
on) |
48 { | 48 { |
49 curve.addKeyframe(CCTransformKeyframe::create(keyTime, *value->value(), timi
ngFunction)); | 49 curve.addKeyframe(CCTransformKeyframe::create(keyTime, *value->value(), timi
ngFunction)); |
50 } | 50 } |
51 | 51 |
52 template <class Value, class Keyframe, class Curve> | 52 template <class Value, class Keyframe, class Curve> |
53 PassOwnPtr<CCActiveAnimation> createActiveAnimation(const KeyframeValueList& val
ueList, const Animation* animation, size_t animationId, size_t groupId, double t
imeOffset, CCActiveAnimation::TargetProperty targetProperty) | 53 PassOwnPtr<CCActiveAnimation> createActiveAnimation(const KeyframeValueList& val
ueList, const Animation* animation, size_t animationId, size_t groupId, double t
imeOffset, CCActiveAnimation::TargetProperty targetProperty) |
54 { | 54 { |
55 // FIXME: add support for different directions. | 55 bool alternate = false; |
56 if (animation && animation->isDirectionSet() && animation->direction() != An
imation::AnimationDirectionNormal) | 56 bool reverse = false; |
57 return nullptr; | 57 if (animation && animation->isDirectionSet()) { |
58 | 58 Animation::AnimationDirection direction = animation->direction(); |
59 // FIXME: add support for fills forwards and fills backwards | 59 if (direction == Animation::AnimationDirectionAlternate || direction ==
Animation::AnimationDirectionAlternateReverse) |
60 if (animation && animation->isFillModeSet() && (animation->fillsForwards() |
| animation->fillsBackwards())) | 60 alternate = true; |
61 return nullptr; | 61 if (direction == Animation::AnimationDirectionReverse || direction == An
imation::AnimationDirectionAlternateReverse) |
| 62 reverse = true; |
| 63 } |
62 | 64 |
63 OwnPtr<Curve> curve = Curve::create(); | 65 OwnPtr<Curve> curve = Curve::create(); |
64 Vector<Keyframe> keyframes; | 66 Vector<Keyframe> keyframes; |
65 | 67 |
66 for (size_t i = 0; i < valueList.size(); i++) { | 68 for (size_t i = 0; i < valueList.size(); i++) { |
67 const Value* originalValue = static_cast<const Value*>(valueList.at(i)); | 69 size_t index = reverse ? valueList.size() - i - 1 : i; |
| 70 |
| 71 const Value* originalValue = static_cast<const Value*>(valueList.at(inde
x)); |
68 | 72 |
69 OwnPtr<CCTimingFunction> timingFunction; | 73 OwnPtr<CCTimingFunction> timingFunction; |
70 const TimingFunction* originalTimingFunction = originalValue->timingFunc
tion(); | 74 const TimingFunction* originalTimingFunction = originalValue->timingFunc
tion(); |
71 | 75 |
72 // If there hasn't been a timing function associated with this keyframe,
use the | 76 // If there hasn't been a timing function associated with this keyframe,
use the |
73 // animation's timing function, if we have one. | 77 // animation's timing function, if we have one. |
74 if (!originalTimingFunction && animation->isTimingFunctionSet()) | 78 if (!originalTimingFunction && animation->isTimingFunctionSet()) |
75 originalTimingFunction = animation->timingFunction().get(); | 79 originalTimingFunction = animation->timingFunction().get(); |
76 | 80 |
77 if (originalTimingFunction) { | 81 if (originalTimingFunction) { |
78 switch (originalTimingFunction->type()) { | 82 switch (originalTimingFunction->type()) { |
79 case TimingFunction::StepsFunction: | 83 case TimingFunction::StepsFunction: |
80 // FIXME: add support for steps timing function. | 84 // FIXME: add support for steps timing function. |
81 return nullptr; | 85 return nullptr; |
82 case TimingFunction::LinearFunction: | 86 case TimingFunction::LinearFunction: |
83 // Don't set the timing function. Keyframes are interpolated lin
early if there is no timing function. | 87 // Don't set the timing function. Keyframes are interpolated lin
early if there is no timing function. |
84 break; | 88 break; |
85 case TimingFunction::CubicBezierFunction: | 89 case TimingFunction::CubicBezierFunction: |
86 const CubicBezierTimingFunction* originalBezierTimingFunction =
static_cast<const CubicBezierTimingFunction*>(originalTimingFunction); | 90 const CubicBezierTimingFunction* originalBezierTimingFunction =
static_cast<const CubicBezierTimingFunction*>(originalTimingFunction); |
87 timingFunction = CCCubicBezierTimingFunction::create(originalBez
ierTimingFunction->x1(), originalBezierTimingFunction->y1(), originalBezierTimin
gFunction->x2(), originalBezierTimingFunction->y2()); | 91 timingFunction = CCCubicBezierTimingFunction::create(originalBez
ierTimingFunction->x1(), originalBezierTimingFunction->y1(), originalBezierTimin
gFunction->x2(), originalBezierTimingFunction->y2()); |
88 break; | 92 break; |
89 } // switch | 93 } // switch |
90 } else | 94 } else |
91 timingFunction = CCEaseTimingFunction::create(); | 95 timingFunction = CCEaseTimingFunction::create(); |
92 | 96 |
93 double duration = (animation && animation->isDurationSet()) ? animation-
>duration() : 1; | 97 double duration = (animation && animation->isDurationSet()) ? animation-
>duration() : 1; |
94 appendKeyframe<Value, Keyframe, Curve>(*curve, originalValue->keyTime()
* duration, originalValue, timingFunction.release()); | 98 double keyTime = originalValue->keyTime() * duration; |
| 99 if (reverse) |
| 100 keyTime = duration - keyTime; |
| 101 appendKeyframe<Value, Keyframe, Curve>(*curve, keyTime, originalValue, t
imingFunction.release()); |
95 } | 102 } |
96 | 103 |
97 OwnPtr<CCActiveAnimation> anim = CCActiveAnimation::create(curve.release(),
animationId, groupId, targetProperty); | 104 OwnPtr<CCActiveAnimation> anim = CCActiveAnimation::create(curve.release(),
animationId, groupId, targetProperty); |
98 | 105 |
99 ASSERT(anim.get()); | 106 ASSERT(anim.get()); |
100 | 107 |
101 if (anim.get()) { | 108 if (anim.get()) { |
102 int iterations = (animation && animation->isIterationCountSet()) ? anima
tion->iterationCount() : 1; | 109 int iterations = (animation && animation->isIterationCountSet()) ? anima
tion->iterationCount() : 1; |
103 anim->setIterations(iterations); | 110 anim->setIterations(iterations); |
| 111 anim->setAlternatesDirection(alternate); |
104 } | 112 } |
105 | 113 |
106 // In order to avoid skew, the main thread animation cannot tick until it ha
s received the start time of | 114 // In order to avoid skew, the main thread animation cannot tick until it ha
s received the start time of |
107 // the corresponding impl thread animation. | 115 // the corresponding impl thread animation. |
108 anim->setNeedsSynchronizedStartTime(true); | 116 anim->setNeedsSynchronizedStartTime(true); |
109 | 117 |
110 // If timeOffset > 0, then the animation has started in the past. | 118 // If timeOffset > 0, then the animation has started in the past. |
111 anim->setTimeOffset(timeOffset); | 119 anim->setTimeOffset(timeOffset); |
112 | 120 |
113 return anim.release(); | 121 return anim.release(); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 m_client->setOpacityFromAnimation(opacity); | 487 m_client->setOpacityFromAnimation(opacity); |
480 break; | 488 break; |
481 } | 489 } |
482 | 490 |
483 } | 491 } |
484 } | 492 } |
485 } | 493 } |
486 } | 494 } |
487 | 495 |
488 } // namespace WebCore | 496 } // namespace WebCore |
OLD | NEW |