Chromium Code Reviews| Index: Source/core/animation/ElementAnimation.cpp |
| diff --git a/Source/core/animation/ElementAnimation.cpp b/Source/core/animation/ElementAnimation.cpp |
| index 2588c529051033923ea781342ae7919137df7d06..062717e40d58c563383892432a4bd840793e2582 100644 |
| --- a/Source/core/animation/ElementAnimation.cpp |
| +++ b/Source/core/animation/ElementAnimation.cpp |
| @@ -32,9 +32,9 @@ |
| #include "core/animation/ElementAnimation.h" |
| #include "bindings/v8/Dictionary.h" |
| +#include "bindings/v8/ScriptValue.h" |
| #include "core/animation/DocumentTimeline.h" |
| #include "core/css/parser/BisonCSSParser.h" |
| -#include "core/css/RuntimeCSSEnabled.h" |
| #include "core/css/resolver/StyleResolver.h" |
| #include "wtf/text/StringBuilder.h" |
| #include <algorithm> |
| @@ -59,22 +59,121 @@ CSSPropertyID ElementAnimation::camelCaseCSSPropertyNameToID(const String& prope |
| return id; |
| } |
| -void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDictionaryVector, double duration) |
| +static void populateTiming(Timing& timing, Dictionary timingInputDictionary) |
| +{ |
| + double startDelay = 0; |
| + timingInputDictionary.get("delay", startDelay); |
| + if (!isnan(startDelay) && !isinf(startDelay)) |
| + timing.startDelay = startDelay; |
| + |
| + String fillMode; |
| + timingInputDictionary.get("fill", fillMode); |
| + // FIXME: This will need to be changed to "forwards" when |
| + // Timing.h implements the spec change that makes default |
| + // fill mode "none". |
| + if (fillMode == "none") { |
| + timing.fillMode = Timing::FillModeNone; |
| + } else if (fillMode == "backwards") { |
| + timing.fillMode = Timing::FillModeBackwards; |
| + } else if (fillMode == "both") { |
| + timing.fillMode = Timing::FillModeBoth; |
| + } |
| + |
| + double iterationStart = 0; |
| + timingInputDictionary.get("iterationStart", iterationStart); |
| + if (!isnan(iterationStart) && !isinf(iterationStart)) |
|
dstockwell
2014/01/15 11:13:52
I'm not sure this is the correct procedure for con
rjwright
2014/01/17 05:08:15
Yeah I wasn't sure what to do about this.
|
| + timing.iterationStart = std::max<double>(iterationStart, 0); |
| + |
| + double iterationCount = 1; |
| + timingInputDictionary.get("iterations", iterationCount); |
| + if (!isnan(iterationCount)) |
| + timing.iterationCount = std::max<double>(iterationCount, 0); |
| + |
| + v8::Local<v8::Value> iterationDurationValue; |
| + bool hasIterationDurationValue = timingInputDictionary.get("duration", iterationDurationValue); |
|
dstockwell
2014/01/15 11:13:52
Did we discover whether this will invoke a custom
rjwright
2014/01/17 05:08:15
Yes it does invoke the getter in this case.
|
| + double iterationDuration = 0; |
|
dstockwell
2014/01/15 11:13:52
just declare this as needed on lines 98 / 103
rjwright
2014/01/17 05:08:15
Done.
|
| + if (hasIterationDurationValue) { |
| + if (iterationDurationValue->IsString()) { |
| + // All strings are treated as 'auto' except strings that are numbers, e.g. '1', 'Infinity'. |
| + iterationDuration = iterationDurationValue->NumberValue(); |
| + if (!isnan(iterationDuration)) |
| + timing.iterationDuration = std::max<double>(iterationDuration, 0); |
| + timing.hasIterationDuration = true; |
| + } else if (iterationDurationValue->IsNumber()) { |
| + iterationDuration = iterationDurationValue->NumberValue(); |
| + if (!isnan(iterationDuration)) { |
| + timing.iterationDuration = std::max<double>(iterationDuration, 0); |
| + timing.hasIterationDuration = true; |
| + } |
| + } |
| + } |
| + |
| + double playbackRate = 1; |
| + timingInputDictionary.get("playbackRate", playbackRate); |
| + if (!isnan(playbackRate) && !isinf(playbackRate)) |
| + timing.playbackRate = playbackRate; |
| + |
| + String direction; |
| + timingInputDictionary.get("direction", direction); |
| + if (direction == "reverse") { |
| + timing.direction = Timing::PlaybackDirectionReverse; |
| + } else if (direction == "alternate") { |
| + timing.direction = Timing::PlaybackDirectionAlternate; |
| + } else if (direction == "alternate-reverse") { |
| + timing.direction = Timing::PlaybackDirectionAlternateReverse; |
| + } |
| +} |
|
dstockwell
2014/01/15 11:13:52
timing.assertValid();
rjwright
2014/01/17 05:08:15
Done.
|
| + |
| +static void processTimingInput(Timing& timing, v8::Handle<v8::Value> timingInput) |
| +{ |
| + if (!timingInput.IsEmpty()) { |
| + if (timingInput->IsObject()) { |
| + populateTiming(timing, Dictionary(v8::Handle<v8::Value>::Cast(timingInput), v8::Isolate::GetCurrent())); |
| + } else { |
| + double duration = timingInput->NumberValue(); |
| + if (!isnan(duration)) { |
| + timing.hasIterationDuration = true; |
| + timing.iterationDuration = std::max<double>(duration, 0); |
| + } |
| + } |
| + } |
| +} |
| + |
| +static bool checkDocumentAndRenderer(Element* element) |
| +{ |
| + if (!element->inActiveDocument()) |
| + return false; |
| + element->document().updateStyleIfNeeded(); |
| + if (!element->renderer()) |
| + return false; |
| + return true; |
| +} |
| + |
| +void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDictionaryVector) |
| { |
| ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); |
| // FIXME: This test will not be neccessary once resolution of keyframe values occurs at |
| // animation application time. |
| - if (!element->inActiveDocument()) |
| + if (!checkDocumentAndRenderer(element)) |
| return; |
| - element->document().updateStyleIfNeeded(); |
| - if (!element->renderer()) |
| + |
| + startAnimation(element, keyframeDictionaryVector); |
| +} |
| + |
| +void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDictionaryVector, ScriptValue timingInput) |
| +{ |
| + ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); |
| + |
| + // FIXME: This test will not be neccessary once resolution of keyframe values occurs at |
| + // animation application time. |
| + if (!checkDocumentAndRenderer(element)) |
| return; |
| - startAnimation(element, keyframeDictionaryVector, duration); |
| + startAnimation(element, keyframeDictionaryVector, timingInput.v8Value()); |
| } |
| -void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, double duration) |
| +void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyframeDictionaryVector, v8::Handle<v8::Value> timingInput) |
| { |
| KeyframeEffectModel::KeyframeVector keyframes; |
| Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
| @@ -126,14 +225,8 @@ void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyfr |
| // FIXME: Replace this with code that just parses, when that code is available. |
| RefPtr<KeyframeEffectModel> effect = StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes); |
| - // FIXME: Totally hardcoded Timing for now. Will handle timing parameters later. |
| Timing timing; |
| - // FIXME: Currently there is no way to tell whether or not an iterationDuration |
| - // has been specified (becauser the default argument is 0). So any animation |
| - // created using Element.animate() will have a timing with hasIterationDuration() |
| - // == true. |
| - timing.hasIterationDuration = true; |
| - timing.iterationDuration = std::max<double>(duration, 0); |
| + processTimingInput(timing, timingInput); |
| RefPtr<Animation> animation = Animation::create(element, effect, timing); |
| DocumentTimeline* timeline = element->document().timeline(); |