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

Side by Side Diff: Source/core/animation/EffectInput.cpp

Issue 194733002: Web Animations: Use StringKeyframes for element.animate() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: More comments 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/AnimationTest.cpp ('k') | Source/core/animation/Keyframe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 15 matching lines...) Expand all
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
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/css/CSSAnimations.h" 36 #include "core/animation/KeyframeEffectModel.h"
37 #include "core/animation/StringKeyframe.h"
37 #include "core/css/parser/BisonCSSParser.h" 38 #include "core/css/parser/BisonCSSParser.h"
38 #include "core/css/resolver/StyleResolver.h" 39 #include "core/css/resolver/StyleResolver.h"
39 #include "core/dom/Element.h" 40 #include "core/dom/Element.h"
40 41
41 namespace WebCore { 42 namespace WebCore {
42 43
43 static bool checkDocumentAndRenderer(Element* element) 44 // FIXME: Remove this once we've removed the dependency on Element.
45 static bool checkDocumentAndRenderer(Element& element)
44 { 46 {
45 if (!element->inActiveDocument()) 47 if (!element.inActiveDocument())
46 return false; 48 return false;
47 element->document().updateRenderTreeIfNeeded(); 49 element.document().updateRenderTreeIfNeeded();
48 return element->renderer(); 50 return element.renderer();
49 } 51 }
50 52
51 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionSta te, bool unsafe) 53 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat e, bool unsafe)
52 { 54 {
53 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at 55 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at
54 // animation application time. 56 // animation application time.
55 if (!unsafe && !checkDocumentAndRenderer(element)) 57 if (!unsafe && !checkDocumentAndRenderer(*element))
56 return nullptr; 58 return nullptr;
57 59
58 StyleSheetContents* styleSheetContents = element->document().elementSheet(). contents(); 60 StyleSheetContents* styleSheetContents = element->document().elementSheet(). contents();
59 61 StringKeyframeVector keyframes;
60 // FIXME: Move this code into KeyframeEffectModel, it will be used by the ID L constructor for that class.
61 AnimatableValueKeyframeVector keyframes;
62 WillBeHeapVector<RefPtrWillBeMember<MutableStylePropertySet> > propertySetVe ctor;
63 62
64 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { 63 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
65 RefPtrWillBeRawPtr<MutableStylePropertySet> propertySet = MutableStylePr opertySet::create(); 64 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
66 propertySetVector.append(propertySet);
67
68 RefPtrWillBeRawPtr<AnimatableValueKeyframe> keyframe = AnimatableValueKe yframe::create();
69 keyframes.append(keyframe); 65 keyframes.append(keyframe);
70 66
71 double offset; 67 double offset;
72 if (keyframeDictionaryVector[i].get("offset", offset)) 68 if (keyframeDictionaryVector[i].get("offset", offset))
73 keyframe->setOffset(offset); 69 keyframe->setOffset(offset);
74 70
75 String compositeString; 71 String compositeString;
76 keyframeDictionaryVector[i].get("composite", compositeString); 72 keyframeDictionaryVector[i].get("composite", compositeString);
77 if (compositeString == "add") 73 if (compositeString == "add")
78 keyframe->setComposite(AnimationEffect::CompositeAdd); 74 keyframe->setComposite(AnimationEffect::CompositeAdd);
79 75
80 String timingFunctionString; 76 String timingFunctionString;
81 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { 77 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) {
82 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); 78 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString);
83 if (timingFunctionValue) 79 if (timingFunctionValue)
84 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); 80 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false));
85 } 81 }
86 82
87 Vector<String> keyframeProperties; 83 Vector<String> keyframeProperties;
88 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); 84 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
89
90 for (size_t j = 0; j < keyframeProperties.size(); ++j) { 85 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
91 String property = keyframeProperties[j]; 86 String property = keyframeProperties[j];
92 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); 87 CSSPropertyID id = camelCaseCSSPropertyNameToID(property);
93 88 if (id == CSSPropertyInvalid)
94 // FIXME: There is no way to store invalid properties or invalid val ues
95 // in a Keyframe object, so for now I just skip over them. Eventuall y we
96 // will need to support getFrames(), which should return exactly the
97 // keyframes that were input through the API. We will add a layer to wrap
98 // KeyframeEffectModel, store input keyframes and implement getFrame s.
99 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id))
100 continue; 89 continue;
101
102 String value; 90 String value;
103 keyframeDictionaryVector[i].get(property, value); 91 keyframeDictionaryVector[i].get(property, value);
104 propertySet->setProperty(id, value, false, styleSheetContents); 92 keyframe->setPropertyValue(id, value, styleSheetContents);
105 } 93 }
106 } 94 }
107 95
108 // FIXME: Replace this with code that just parses, when that code is availab le. 96 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes);
109 RefPtrWillBeRawPtr<AnimatableValueKeyframeEffectModel> keyframeEffectModel = StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes );
110 if (!keyframeEffectModel->isReplaceOnly()) { 97 if (!keyframeEffectModel->isReplaceOnly()) {
111 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); 98 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported.");
112 return nullptr; 99 return nullptr;
113 } 100 }
101 keyframeEffectModel->forceConversionsToAnimatableValues(element);
114 102
115 return keyframeEffectModel; 103 return keyframeEffectModel;
116 } 104 }
117 105
118 } // namespace WebCore 106 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationTest.cpp ('k') | Source/core/animation/Keyframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698