Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Unified Diff: Source/core/animation/EffectInput.cpp

Issue 182063005: Web Animations API: Refactor IDL input conversion out of Animation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove templates Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..3232583d10a69b8e644c8f7695b7d0326a1752aa
--- /dev/null
+++ b/Source/core/animation/EffectInput.cpp
@@ -0,0 +1,86 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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, Vector<Dictionary> keyframeDictionaryVector, bool unsafe)
esprehn 2014/03/04 00:59:42 You almost certainly want to pass const Vector<Dic
alancutter (OOO until 2018) 2014/03/04 01:21:41 Done.
+{
+ // 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)) {
esprehn 2014/03/04 00:59:42 no braces on a one line if
alancutter (OOO until 2018) 2014/03/04 01:21:41 Done.
dstockwell 2014/03/04 01:29:31 The blink style guide was relaxed about this a lon
+ 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) {
esprehn 2014/03/04 00:59:42 ditto
alancutter (OOO until 2018) 2014/03/04 01:21:41 Done.
+ 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

Powered by Google App Engine
This is Rietveld 408576698