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

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

Issue 253093002: Web Animations API: Sort keyframes by offset (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: isnan 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..52e3289eb5b756d430a9b3df0531a7134302a33b 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,37 @@ 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);
+ bool frameHasOffset = false;
double offset;
- if (keyframeDictionaryVector[i].get("offset", offset))
- keyframe->setOffset(offset);
+ if (keyframeDictionaryVector[i].get("offset", offset)) {
+ // Keyframes with offsets outside the range [0.0, 1.0] are ignored.
+ if (std::isnan(offset) || offset < 0 || offset > 1)
+ continue;
+
+ frameHasOffset = true;
+ // The JS value null gets converted to 0 so we need to check whether the original value is null.
+ if (offset == 0) {
+ ScriptValue scriptValue;
+ if (keyframeDictionaryVector[i].get("offset", scriptValue) && scriptValue.isNull())
+ frameHasOffset = false;
+ }
+ if (frameHasOffset) {
+ keyframe->setOffset(offset);
+ if (offset < lastOffset)
+ looselySortedByOffset = false;
+ lastOffset = offset;
+ }
+ }
+ everyFrameHasOffset = everyFrameHasOffset && frameHasOffset;
+
+ keyframes.append(keyframe);
String compositeString;
keyframeDictionaryVector[i].get("composite", compositeString);
@@ -93,6 +117,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.");
« no previous file with comments | « LayoutTests/web-animations-api/element-animate-list-of-keyframes.html ('k') | Source/core/animation/EffectInputTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698