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

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: Added test to check that animate() does not leak into stable. 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/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 KeyframeAnimationEffect::KeyframeVector keyframes;
74 Vector<RefPtr<MutableStylePropertySet> > propertySetVector;
75
76 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
77 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate();
78 propertySetVector.append(propertySet);
79
80 RefPtr<Keyframe> keyframe = Keyframe::create();
81 keyframes.append(keyframe);
82
83 double offset;
84 if (keyframeDictionaryVector[i].get("offset", offset)) {
85 keyframe->setOffset(offset);
86 } else {
87 // FIXME: Web Animations CSS engine does not yet implement handling of
88 // keyframes without specified offsets. This check can be removed wh en
89 // that funcitonality is implemented.
90 ASSERT_NOT_REACHED();
91 return;
92 }
93
94 String compositeString;
95 keyframeDictionaryVector[i].get("composite", compositeString);
96 if (compositeString == "add")
97 keyframe->setComposite(AnimationEffect::CompositeAdd);
98
99 Vector<String> keyframeProperties;
100 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
101
102 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
103 String property = keyframeProperties[j];
104 CSSPropertyID id = camelCaseCSSPropertyNameToID(property.impl());
105
106 // FIXME: There is no way to store invalid properties or invalid val ues
107 // in a Keyframe object, so for now I just skip over them. Eventuall y we
108 // will need to support getFrames(), which should return exactly the
109 // keyframes that were input through the API. We will add a layer to wrap
110 // KeyframeAnimationEffect, store input keyframes and implement getF rames.
111 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id))
112 continue;
113
114 String value;
115 keyframeDictionaryVector[i].get(property, value);
116 propertySet->setProperty(id, value);
117 }
118 }
119
120 // FIXME: Replace this with code that just parses, when that code is availab le.
121 RefPtr<KeyframeAnimationEffect> effect = StyleResolver::createKeyframeAnimat ionEffect(*element, propertySetVector, keyframes);
122
123 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter.
124 Timing timing;
125 timing.hasIterationDuration = true;
126 timing.iterationDuration = 1;
127
128 RefPtr<Animation> animation = Animation::create(element, effect, timing);
129 DocumentTimeline* timeline = element->document().timeline();
130 ASSERT(timeline);
131 timeline->play(animation.get());
132 }
133
134 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698