This source file includes following definitions.
- checkDocumentAndRenderer
- convert
#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().updateRenderTreeIfNeeded();
return element->renderer();
}
PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionState, bool unsafe)
{
if (!unsafe && !checkDocumentAndRenderer(element))
return nullptr;
StyleSheetContents* styleSheetContents = element->document().elementSheet().contents();
AnimatableValueKeyframeVector keyframes;
WillBeHeapVector<RefPtrWillBeMember<MutableStylePropertySet> > propertySetVector;
for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::create();
propertySetVector.append(propertySet);
RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKeyframe::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);
if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty(id))
continue;
String value;
keyframeDictionaryVector[i].get(property, value);
propertySet->setProperty(id, value, false, styleSheetContents);
}
}
RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> keyframeEffectModel = StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes);
if (!keyframeEffectModel->isReplaceOnly()) {
exceptionState.throwDOMException(NotSupportedError, "Partial keyframes are not supported.");
return nullptr;
}
return keyframeEffectModel;
}
}