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

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

Issue 96283002: Web Animations API: Start implementation of Element.animate(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add layout test for animate() Created 7 years 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
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #include "config.h"
32 #include "core/animation/ElementAnimation.h"
33
34 #include "core/animation/DocumentTimeline.h"
35 #include "core/css/CSSParser.h"
36 #include "core/css/resolver/StyleResolver.h"
37 #include "wtf/text/StringBuilder.h"
38
39
40 namespace WebCore {
41
42 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector)
43 {
44 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled());
45
46 KeyframeAnimationEffect::KeyframeVector keyframes;
47 Vector<RefPtr<MutableStylePropertySet> > propertySetVector;
48
49 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
50 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate();
51 propertySetVector.append(propertySet);
52
53 RefPtr<Keyframe> keyframe = Keyframe::create();
54 keyframes.append(keyframe);
55
56 double offset;
57 if (keyframeDictionaryVector[i].get("offset", offset))
58 keyframe->setOffset(offset);
59 else
60 RELEASE_ASSERT_WITH_MESSAGE(false, "Web Animations not yet implement ed: Handling for keyframes without specified offset.");
esprehn 2013/12/09 18:51:25 Can you hit this with JS today if you turn the fla
shans 2013/12/09 23:25:57 This feature is behind the experimental web platfo
Steve Block 2013/12/09 23:32:20 Yes, you can. Is this policy documented somewhere
esprehn 2013/12/09 23:36:16 We should never ship something that we know will c
shans 2013/12/09 23:41:27 It can only crash for people who have the flag ena
rjwright 2013/12/10 03:05:40 Done.
61
62 String compositeString;
63 keyframeDictionaryVector[i].get("composite", compositeString);
64 if (compositeString == String("add"))
65 keyframe->setComposite(AnimationEffect::CompositeAdd);
66
67 Vector<String> keyframeProperties;
68 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
69
70 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
71 String property = keyframeProperties[j];
72 CSSPropertyID id = camelCaseCSSPropertyNameToID(property.impl());
73
74 // FIXME: There is no way to store invalid properties or invalid val ues
75 // in a Keyframe object, so for now I just skip over them. Eventuall y we
76 // will need to support getFrames(), which should return exactly the
77 // keyframes that were input through the API. We will add a layer to wrap
78 // KeyframeAnimationEffect, store input keyframes and implement getF rames.
79 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id))
80 continue;
81
82 String value;
83 keyframeDictionaryVector[i].get(property, value);
84 if (!CSSParser::parseValue(propertySet.get(), id, value, false, elem ent->document()))
85 continue;
esprehn 2013/12/09 18:51:25 This continue doesn't matter, you're at the end of
rjwright 2013/12/10 03:05:40 Done.
86 }
87 }
88
89 StyleResolver::setKeyframePropertyValues(element, propertySetVector, keyfram es);
90 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(key frames);
esprehn 2013/12/09 18:51:25 This should be the return value of the styleResolv
rjwright 2013/12/10 03:05:40 Done.
91
92 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter.
93 Timing timing;
94 timing.hasIterationDuration = true;
95 timing.iterationDuration = 1;
96
97 RefPtr<Animation> animation = Animation::create(element, effect, timing);
98 DocumentTimeline* timeline = element->document().timeline();
99 ASSERT(timeline);
100 timeline->play(animation.get());
101 }
102
103 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698