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