Chromium Code Reviews| Index: Source/core/animation/EffectInput.cpp |
| diff --git a/Source/core/animation/EffectInput.cpp b/Source/core/animation/EffectInput.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0dbccebc55db887894e2de6a72b05f48652b72fc |
| --- /dev/null |
| +++ b/Source/core/animation/EffectInput.cpp |
| @@ -0,0 +1,84 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
dstockwell
2014/03/04 01:29:31
This doesn't look like a brand new file. There was
alancutter (OOO until 2018)
2014/03/04 01:35:14
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "config.h" |
| +#include "core/animation/EffectInput.h" |
| + |
| +#include "bindings/v8/Dictionary.h" |
| +#include "core/animation/AnimationHelpers.h" |
| +#include "core/animation/css/CSSAnimations.h" |
| +#include "core/css/parser/BisonCSSParser.h" |
| +#include "core/css/resolver/StyleResolver.h" |
| +#include "core/dom/Element.h" |
| + |
| +namespace WebCore { |
| + |
| +static bool checkDocumentAndRenderer(Element* element) |
| +{ |
| + if (!element->inActiveDocument()) |
| + return false; |
| + element->document().updateStyleIfNeeded(); |
| + return element->renderer(); |
| +} |
| + |
| +PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<Dictionary>& keyframeDictionaryVector, bool unsafe) |
| +{ |
| + // FIXME: This test will not be neccessary once resolution of keyframe values occurs at |
| + // animation application time. |
| + if (!unsafe && !checkDocumentAndRenderer(element)) |
| + return nullptr; |
| + |
| + // FIXME: Move this code into KeyframeEffectModel, it will be used by the IDL constructor for that class. |
| + KeyframeEffectModel::KeyframeVector keyframes; |
| + Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
| + |
| + for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| + RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::create(); |
| + propertySetVector.append(propertySet); |
| + |
| + RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); |
| + keyframes.append(keyframe); |
| + |
| + double offset; |
| + if (keyframeDictionaryVector[i].get("offset", offset)) |
| + keyframe->setOffset(offset); |
| + |
| + String compositeString; |
| + keyframeDictionaryVector[i].get("composite", compositeString); |
| + if (compositeString == "add") |
| + keyframe->setComposite(AnimationEffect::CompositeAdd); |
| + |
| + String timingFunctionString; |
| + if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { |
| + RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::parseAnimationTimingFunctionValue(timingFunctionString); |
| + if (timingFunctionValue) |
| + keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timingFunctionValue.get(), false)); |
| + } |
| + |
| + Vector<String> keyframeProperties; |
| + keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
| + |
| + for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
| + String property = keyframeProperties[j]; |
| + CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
| + |
| + // FIXME: There is no way to store invalid properties or invalid values |
| + // in a Keyframe object, so for now I just skip over them. Eventually we |
| + // will need to support getFrames(), which should return exactly the |
| + // keyframes that were input through the API. We will add a layer to wrap |
| + // KeyframeEffectModel, store input keyframes and implement getFrames. |
| + if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty(id)) |
| + continue; |
| + |
| + String value; |
| + keyframeDictionaryVector[i].get(property, value); |
| + propertySet->setProperty(id, value); |
| + } |
| + } |
| + |
| + // FIXME: Replace this with code that just parses, when that code is available. |
| + return StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes); |
| +} |
| + |
| +} // namespace WebCore |