| 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/CSSParser.h" |
| 36 #include "core/css/resolver/StyleResolver.h" |
| 37 #include "core/page/RuntimeCSSEnabled.h" |
| 38 #include "wtf/text/StringBuilder.h" |
| 39 |
| 40 |
| 41 namespace WebCore { |
| 42 |
| 43 namespace { |
| 44 |
| 45 static CSSPropertyID camelCaseCSSPropertyNameToID(StringImpl* propertyName) |
| 46 { |
| 47 typedef HashMap<StringImpl*, CSSPropertyID> CSSPropertyIDMap; |
| 48 DEFINE_STATIC_LOCAL(CSSPropertyIDMap, map, ()); |
| 49 |
| 50 CSSPropertyID id = map.get(propertyName); |
| 51 |
| 52 if (propertyName->find('-') != kNotFound) |
| 53 return CSSPropertyInvalid; |
| 54 |
| 55 if (!id) { |
| 56 StringBuilder builder; |
| 57 size_t position = 0; |
| 58 size_t end; |
| 59 while ((end = propertyName->find(isASCIIUpper, position)) != kNotFound)
{ |
| 60 builder.append(propertyName->substring(position, end) + "-" + toASCI
ILower((*propertyName)[end])); |
| 61 position = end + 1; |
| 62 } |
| 63 builder.append(propertyName->substring(position)); |
| 64 // Doesn't handle prefixed properties. |
| 65 id = cssPropertyID(builder.toString()); |
| 66 if (id != CSSPropertyInvalid && RuntimeCSSEnabled::isCSSPropertyEnabled(
id)) |
| 67 map.add(propertyName, id); |
| 68 } |
| 69 |
| 70 return id; |
| 71 } |
| 72 |
| 73 } // namespace |
| 74 |
| 75 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict
ionaryVector) |
| 76 { |
| 77 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); |
| 78 |
| 79 KeyframeAnimationEffect::KeyframeVector keyframes; |
| 80 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
| 81 |
| 82 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| 83 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c
reate(); |
| 84 propertySetVector.append(propertySet); |
| 85 |
| 86 RefPtr<Keyframe> keyframe = Keyframe::create(); |
| 87 keyframes.append(keyframe); |
| 88 |
| 89 double offset; |
| 90 if (keyframeDictionaryVector[i].get("offset", offset)) { |
| 91 keyframe->setOffset(offset); |
| 92 } else { |
| 93 // FIXME: Web Animations CSS engine does not yet implement handling
of |
| 94 // keyframes without specified offsets. This check can be removed wh
en |
| 95 // that funcitonality is implemented. |
| 96 ASSERT_NOT_REACHED(); |
| 97 return; |
| 98 } |
| 99 |
| 100 String compositeString; |
| 101 keyframeDictionaryVector[i].get("composite", compositeString); |
| 102 if (compositeString == String("add")) |
| 103 keyframe->setComposite(AnimationEffect::CompositeAdd); |
| 104 |
| 105 Vector<String> keyframeProperties; |
| 106 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
| 107 |
| 108 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
| 109 String property = keyframeProperties[j]; |
| 110 CSSPropertyID id = camelCaseCSSPropertyNameToID(property.impl()); |
| 111 |
| 112 // FIXME: There is no way to store invalid properties or invalid val
ues |
| 113 // in a Keyframe object, so for now I just skip over them. Eventuall
y we |
| 114 // will need to support getFrames(), which should return exactly the |
| 115 // keyframes that were input through the API. We will add a layer to
wrap |
| 116 // KeyframeAnimationEffect, store input keyframes and implement getF
rames. |
| 117 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty
(id)) |
| 118 continue; |
| 119 |
| 120 String value; |
| 121 keyframeDictionaryVector[i].get(property, value); |
| 122 propertySet->setProperty(id, value); |
| 123 } |
| 124 } |
| 125 |
| 126 RefPtr<KeyframeAnimationEffect> effect = StyleResolver::setKeyframePropertyV
alues(element, propertySetVector, keyframes); |
| 127 |
| 128 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la
ter. |
| 129 Timing timing; |
| 130 timing.hasIterationDuration = true; |
| 131 timing.iterationDuration = 1; |
| 132 |
| 133 RefPtr<Animation> animation = Animation::create(element, effect, timing); |
| 134 DocumentTimeline* timeline = element->document().timeline(); |
| 135 ASSERT(timeline); |
| 136 timeline->play(animation.get()); |
| 137 } |
| 138 |
| 139 } // namespace WebCore |
| OLD | NEW |