| 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 "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."); |
| 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; |
| 86 } |
| 87 } |
| 88 |
| 89 StyleResolver::setKeyframePropertyValues(keyframes, propertySetVector, eleme
nt); |
| 90 RefPtr<KeyframeAnimationEffect> effect = KeyframeAnimationEffect::create(key
frames); |
| 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 |
| OLD | NEW |