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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/EffectInput.h" 32 #include "core/animation/EffectInput.h"
33 33
34 #include "bindings/v8/Dictionary.h" 34 #include "bindings/v8/Dictionary.h"
35 #include "core/animation/AnimationHelpers.h" 35 #include "core/animation/AnimationHelpers.h"
36 #include "core/animation/KeyframeEffectModel.h" 36 #include "core/animation/KeyframeEffectModel.h"
37 #include "core/animation/StringKeyframe.h" 37 #include "core/animation/StringKeyframe.h"
38 #include "core/css/parser/BisonCSSParser.h" 38 #include "core/css/parser/BisonCSSParser.h"
39 #include "core/css/resolver/StyleResolver.h" 39 #include "core/css/resolver/StyleResolver.h"
40 #include "core/dom/Element.h" 40 #include "core/dom/Element.h"
41 #include "wtf/NonCopyingSort.h"
41 42
42 namespace WebCore { 43 namespace WebCore {
43 44
45 namespace {
46
47 bool compareOffsets(const RefPtrWillBeMember<StringKeyframe>& keyframe1, const R efPtrWillBeMember<StringKeyframe>& keyframe2)
48 {
49 ASSERT(keyframe1 && keyframe2);
50 return keyframe1->offset() < keyframe2->offset();
51 }
52
53 }
54
44 // FIXME: Remove this once we've removed the dependency on Element. 55 // FIXME: Remove this once we've removed the dependency on Element.
45 static bool checkDocumentAndRenderer(Element* element) 56 static bool checkDocumentAndRenderer(Element* element)
46 { 57 {
47 if (!element || !element->inActiveDocument()) 58 if (!element || !element->inActiveDocument())
48 return false; 59 return false;
49 element->document().updateRenderTreeIfNeeded(); 60 element->document().updateRenderTreeIfNeeded();
50 return element->renderer(); 61 return element->renderer();
51 } 62 }
52 63
53 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat e, bool unsafe) 64 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat e, bool unsafe)
54 { 65 {
55 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at 66 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at
56 // animation application time. 67 // animation application time.
57 if (!unsafe && !checkDocumentAndRenderer(element)) 68 if (!unsafe && !checkDocumentAndRenderer(element))
58 return nullptr; 69 return nullptr;
59 70
60 StyleSheetContents* styleSheetContents = element->document().elementSheet(). contents(); 71 StyleSheetContents* styleSheetContents = element->document().elementSheet(). contents();
61 StringKeyframeVector keyframes; 72 StringKeyframeVector keyframes;
73 bool everyFrameHasOffset = true;
74 bool looselySortedByOffset = true;
75 double lastOffset = -std::numeric_limits<double>::infinity();
62 76
63 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { 77 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
64 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); 78 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
65 keyframes.append(keyframe); 79 keyframes.append(keyframe);
66 80
67 double offset; 81 double offset;
68 if (keyframeDictionaryVector[i].get("offset", offset)) 82 if (keyframeDictionaryVector[i].get("offset", offset)) {
69 keyframe->setOffset(offset); 83 keyframe->setOffset(offset);
84 if (offset < lastOffset)
85 looselySortedByOffset = false;
86 lastOffset = offset;
87 } else {
88 everyFrameHasOffset = false;
89 }
70 90
71 String compositeString; 91 String compositeString;
72 keyframeDictionaryVector[i].get("composite", compositeString); 92 keyframeDictionaryVector[i].get("composite", compositeString);
73 if (compositeString == "add") 93 if (compositeString == "add")
74 keyframe->setComposite(AnimationEffect::CompositeAdd); 94 keyframe->setComposite(AnimationEffect::CompositeAdd);
75 95
76 String timingFunctionString; 96 String timingFunctionString;
77 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { 97 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) {
78 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); 98 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString);
79 if (timingFunctionValue) 99 if (timingFunctionValue)
80 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); 100 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false));
81 } 101 }
82 102
83 Vector<String> keyframeProperties; 103 Vector<String> keyframeProperties;
84 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); 104 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
85 for (size_t j = 0; j < keyframeProperties.size(); ++j) { 105 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
86 String property = keyframeProperties[j]; 106 String property = keyframeProperties[j];
87 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); 107 CSSPropertyID id = camelCaseCSSPropertyNameToID(property);
88 if (id == CSSPropertyInvalid) 108 if (id == CSSPropertyInvalid)
89 continue; 109 continue;
90 String value; 110 String value;
91 keyframeDictionaryVector[i].get(property, value); 111 keyframeDictionaryVector[i].get(property, value);
92 keyframe->setPropertyValue(id, value, styleSheetContents); 112 keyframe->setPropertyValue(id, value, styleSheetContents);
93 } 113 }
94 } 114 }
95 115
116 if (!looselySortedByOffset) {
117 if (!everyFrameHasOffset) {
118 exceptionState.throwDOMException(InvalidModificationError, "Keyframe s are not loosely sorted by offset.");
119 return nullptr;
120 }
121 nonCopyingSort(keyframes.begin(), keyframes.end(), compareOffsets);
122 }
123
96 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); 124 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes);
97 if (!keyframeEffectModel->isReplaceOnly()) { 125 if (!keyframeEffectModel->isReplaceOnly()) {
98 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); 126 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported.");
99 return nullptr; 127 return nullptr;
100 } 128 }
101 keyframeEffectModel->forceConversionsToAnimatableValues(element); 129 keyframeEffectModel->forceConversionsToAnimatableValues(element);
102 130
103 return keyframeEffectModel; 131 return keyframeEffectModel;
104 } 132 }
105 133
106 } // namespace WebCore 134 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698