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

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

Issue 251463003: Web Animations API: Sort keyframes by offset (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Detect null offset Created 6 years, 8 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
index 8e29bd8af94b7cc39935f1424c521f9e612da42e..87db3435d16d11016bdf934e7c0d075a71fad811 100644
--- a/Source/core/animation/EffectInput.cpp
+++ b/Source/core/animation/EffectInput.cpp
@@ -38,6 +38,7 @@
#include "core/css/parser/BisonCSSParser.h"
#include "core/css/resolver/StyleResolver.h"
#include "core/dom/Element.h"
+#include "wtf/NonCopyingSort.h"
namespace WebCore {
@@ -59,14 +60,33 @@ PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
StyleSheetContents* styleSheetContents = element->document().elementSheet().contents();
StringKeyframeVector keyframes;
+ bool everyFrameHasOffset = true;
+ bool looselySortedByOffset = true;
+ double lastOffset = -std::numeric_limits<double>::infinity();
for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
- keyframes.append(keyframe);
- double offset;
- if (keyframeDictionaryVector[i].get("offset", offset))
- keyframe->setOffset(offset);
+ bool frameHasOffset = false;
+ v8::Local<v8::Value> v8Value;
dstockwell 2014/04/29 08:11:47 v8::Local is not usually used in core/ code, +hara
haraken 2014/04/29 08:16:20 Can we use ScriptValue?
+ if (keyframeDictionaryVector[i].get("offset", v8Value) && !v8Value->IsNull()) {
+ v8::Local<v8::Number> v8Number = v8Value->ToNumber();
+ if (!v8Number.IsEmpty()) {
+ double offset = v8Number->Value();
+ // Keyframes with offsets outside the range [0.0, 1.0] are ignored.
+ if (isNull(offset) || offset < 0 || offset > 1)
+ continue;
+
+ keyframe->setOffset(offset);
+ if (offset < lastOffset)
+ looselySortedByOffset = false;
+ lastOffset = offset;
+ frameHasOffset = true;
+ }
+ }
+ everyFrameHasOffset = everyFrameHasOffset && frameHasOffset;
+
+ keyframes.append(keyframe);
String compositeString;
keyframeDictionaryVector[i].get("composite", compositeString);
@@ -93,6 +113,14 @@ PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
}
}
+ if (!looselySortedByOffset) {
+ if (!everyFrameHasOffset) {
+ exceptionState.throwDOMException(InvalidModificationError, "Keyframes are not loosely sorted by offset.");
+ return nullptr;
+ }
+ nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffsets);
+ }
+
RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKeyframeEffectModel::create(keyframes);
if (!keyframeEffectModel->isReplaceOnly()) {
exceptionState.throwDOMException(NotSupportedError, "Partial keyframes are not supported.");

Powered by Google App Engine
This is Rietveld 408576698