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

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: Fix broken unit test 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
« no previous file with comments | « Source/core/animation/ElementAnimation.h ('k') | Source/core/animation/ElementAnimation.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/resolver/StyleResolver.h"
36 #include "core/page/RuntimeCSSEnabled.h"
37 #include "wtf/text/StringBuilder.h"
38
39
40 namespace WebCore {
41
42 CSSPropertyID ElementAnimation::camelCaseCSSPropertyNameToID(StringImpl* propert yName)
43 {
44 typedef HashMap<StringImpl*, CSSPropertyID> CSSPropertyIDMap;
45 DEFINE_STATIC_LOCAL(CSSPropertyIDMap, map, ());
46
47 if (propertyName->find('-') != kNotFound)
48 return CSSPropertyInvalid;
49
50 CSSPropertyID id = map.get(propertyName);
51
52 if (!id) {
53 StringBuilder builder;
54 size_t position = 0;
55 size_t end;
56 while ((end = propertyName->find(isASCIIUpper, position)) != kNotFound) {
57 builder.append(propertyName->substring(position, end - position) + " -" + toASCIILower((*propertyName)[end]));
58 position = end + 1;
59 }
60 builder.append(propertyName->substring(position));
61 // Doesn't handle prefixed properties.
62 id = cssPropertyID(builder.toString());
63 if (id != CSSPropertyInvalid && RuntimeCSSEnabled::isCSSPropertyEnabled( id))
64 map.add(propertyName, id);
65 }
66 return id;
67 }
68
69 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector)
70 {
71 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled());
72
73 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at
74 // animation application time.
75 if (!element->inActiveDocument()) {
76 return;
77 }
esprehn 2013/12/12 06:40:11 nit: braces are not needed for one line if stateme
78 element->document().updateStyleIfNeeded();
79 if (!element->renderer()) {
80 return;
81 }
82
83 startAnimation(element, keyframeDictionaryVector);
84 }
85
86 void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyfr ameDictionaryVector)
87 {
88 KeyframeAnimationEffect::KeyframeVector keyframes;
89 Vector<RefPtr<MutableStylePropertySet> > propertySetVector;
90
91 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
92 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate();
93 propertySetVector.append(propertySet);
94
95 RefPtr<Keyframe> keyframe = Keyframe::create();
96 keyframes.append(keyframe);
97
98 double offset;
99 if (keyframeDictionaryVector[i].get("offset", offset)) {
100 keyframe->setOffset(offset);
101 } else {
102 // FIXME: Web Animations CSS engine does not yet implement handling of
103 // keyframes without specified offsets. This check can be removed wh en
104 // that funcitonality is implemented.
105 ASSERT_NOT_REACHED();
106 return;
107 }
108
109 String compositeString;
110 keyframeDictionaryVector[i].get("composite", compositeString);
111 if (compositeString == "add")
112 keyframe->setComposite(AnimationEffect::CompositeAdd);
113
114 Vector<String> keyframeProperties;
115 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
116
117 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
118 String property = keyframeProperties[j];
119 CSSPropertyID id = camelCaseCSSPropertyNameToID(property.impl());
120
121 // FIXME: There is no way to store invalid properties or invalid val ues
122 // in a Keyframe object, so for now I just skip over them. Eventuall y we
123 // will need to support getFrames(), which should return exactly the
124 // keyframes that were input through the API. We will add a layer to wrap
125 // KeyframeAnimationEffect, store input keyframes and implement getF rames.
126 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id))
127 continue;
128
129 String value;
130 keyframeDictionaryVector[i].get(property, value);
131 propertySet->setProperty(id, value);
132 }
133 }
134
135 // FIXME: Replace this with code that just parses, when that code is availab le.
136 RefPtr<KeyframeAnimationEffect> effect = StyleResolver::createKeyframeAnimat ionEffect(*element, propertySetVector, keyframes);
137
138 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter.
139 Timing timing;
140 timing.hasIterationDuration = true;
141 timing.iterationDuration = 1;
142
143 RefPtr<Animation> animation = Animation::create(element, effect, timing);
144 DocumentTimeline* timeline = element->document().timeline();
145 ASSERT(timeline);
146 timeline->play(animation.get());
147 }
148
149 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/ElementAnimation.h ('k') | Source/core/animation/ElementAnimation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698