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/EffectInput.h" |
| 33 |
| 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "core/animation/AnimationHelpers.h" |
| 36 #include "core/animation/css/CSSAnimations.h" |
| 37 #include "core/css/parser/BisonCSSParser.h" |
| 38 #include "core/css/resolver/StyleResolver.h" |
| 39 #include "core/dom/Element.h" |
| 40 |
| 41 namespace WebCore { |
| 42 |
| 43 static bool checkDocumentAndRenderer(Element* element) |
| 44 { |
| 45 if (!element->inActiveDocument()) |
| 46 return false; |
| 47 element->document().updateStyleIfNeeded(); |
| 48 return element->renderer(); |
| 49 } |
| 50 |
| 51 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
onst Vector<Dictionary>& keyframeDictionaryVector, bool unsafe) |
| 52 { |
| 53 // FIXME: This test will not be neccessary once resolution of keyframe value
s occurs at |
| 54 // animation application time. |
| 55 if (!unsafe && !checkDocumentAndRenderer(element)) |
| 56 return nullptr; |
| 57 |
| 58 // FIXME: Move this code into KeyframeEffectModel, it will be used by the ID
L constructor for that class. |
| 59 KeyframeEffectModel::KeyframeVector keyframes; |
| 60 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
| 61 |
| 62 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| 63 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c
reate(); |
| 64 propertySetVector.append(propertySet); |
| 65 |
| 66 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); |
| 67 keyframes.append(keyframe); |
| 68 |
| 69 double offset; |
| 70 if (keyframeDictionaryVector[i].get("offset", offset)) |
| 71 keyframe->setOffset(offset); |
| 72 |
| 73 String compositeString; |
| 74 keyframeDictionaryVector[i].get("composite", compositeString); |
| 75 if (compositeString == "add") |
| 76 keyframe->setComposite(AnimationEffect::CompositeAdd); |
| 77 |
| 78 String timingFunctionString; |
| 79 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { |
| 80 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p
arseAnimationTimingFunctionValue(timingFunctionString); |
| 81 if (timingFunctionValue) |
| 82 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin
gFunctionValue.get(), false)); |
| 83 } |
| 84 |
| 85 Vector<String> keyframeProperties; |
| 86 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
| 87 |
| 88 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
| 89 String property = keyframeProperties[j]; |
| 90 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
| 91 |
| 92 // FIXME: There is no way to store invalid properties or invalid val
ues |
| 93 // in a Keyframe object, so for now I just skip over them. Eventuall
y we |
| 94 // will need to support getFrames(), which should return exactly the |
| 95 // keyframes that were input through the API. We will add a layer to
wrap |
| 96 // KeyframeEffectModel, store input keyframes and implement getFrame
s. |
| 97 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty
(id)) |
| 98 continue; |
| 99 |
| 100 String value; |
| 101 keyframeDictionaryVector[i].get(property, value); |
| 102 propertySet->setProperty(id, value); |
| 103 } |
| 104 } |
| 105 |
| 106 // FIXME: Replace this with code that just parses, when that code is availab
le. |
| 107 return StyleResolver::createKeyframeEffectModel(*element, propertySetVector,
keyframes); |
| 108 } |
| 109 |
| 110 } // namespace WebCore |
OLD | NEW |