| 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 "sky/engine/config.h" | |
| 32 #include "sky/engine/core/animation/EffectInput.h" | |
| 33 | |
| 34 #include "sky/engine/bindings/core/v8/Dictionary.h" | |
| 35 #include "sky/engine/core/animation/AnimationHelpers.h" | |
| 36 #include "sky/engine/core/animation/KeyframeEffectModel.h" | |
| 37 #include "sky/engine/core/animation/StringKeyframe.h" | |
| 38 #include "sky/engine/core/css/parser/BisonCSSParser.h" | |
| 39 #include "sky/engine/core/css/resolver/CSSToStyleMap.h" | |
| 40 #include "sky/engine/core/css/resolver/StyleResolver.h" | |
| 41 #include "sky/engine/core/dom/Document.h" | |
| 42 #include "sky/engine/core/dom/Element.h" | |
| 43 #include "sky/engine/wtf/NonCopyingSort.h" | |
| 44 | |
| 45 namespace blink { | |
| 46 | |
| 47 PassRefPtr<AnimationEffect> EffectInput::convert(Element* element, const Vector<
Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionState) | |
| 48 { | |
| 49 // FIXME: Remove the dependency on element. | |
| 50 if (!element) | |
| 51 return nullptr; | |
| 52 | |
| 53 StyleSheetContents* styleSheetContents = element->document().elementSheet().
contents(); | |
| 54 StringKeyframeVector keyframes; | |
| 55 double lastOffset = 0; | |
| 56 | |
| 57 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | |
| 58 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); | |
| 59 | |
| 60 ScriptValue scriptValue; | |
| 61 bool frameHasOffset = DictionaryHelper::get(keyframeDictionaryVector[i],
"offset", scriptValue) && !scriptValue.isNull(); | |
| 62 | |
| 63 if (frameHasOffset) { | |
| 64 double offset; | |
| 65 DictionaryHelper::get(keyframeDictionaryVector[i], "offset", offset)
; | |
| 66 | |
| 67 // Keyframes with offsets outside the range [0.0, 1.0] are an error. | |
| 68 if (std::isnan(offset)) { | |
| 69 exceptionState.throwDOMException(InvalidModificationError, "Non
numeric offset provided"); | |
| 70 } | |
| 71 | |
| 72 if (offset < 0 || offset > 1) { | |
| 73 exceptionState.throwDOMException(InvalidModificationError, "Offs
ets provided outside the range [0, 1]"); | |
| 74 return nullptr; | |
| 75 } | |
| 76 | |
| 77 if (offset < lastOffset) { | |
| 78 exceptionState.throwDOMException(InvalidModificationError, "Keyf
rames with specified offsets are not sorted"); | |
| 79 return nullptr; | |
| 80 } | |
| 81 | |
| 82 lastOffset = offset; | |
| 83 | |
| 84 keyframe->setOffset(offset); | |
| 85 } | |
| 86 keyframes.append(keyframe); | |
| 87 | |
| 88 String compositeString; | |
| 89 DictionaryHelper::get(keyframeDictionaryVector[i], "composite", composit
eString); | |
| 90 if (compositeString == "add") | |
| 91 keyframe->setComposite(AnimationEffect::CompositeAdd); | |
| 92 | |
| 93 String timingFunctionString; | |
| 94 if (DictionaryHelper::get(keyframeDictionaryVector[i], "easing", timingF
unctionString)) { | |
| 95 if (RefPtr<CSSValue> timingFunctionValue = BisonCSSParser::parseAnim
ationTimingFunctionValue(timingFunctionString)) | |
| 96 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(ti
mingFunctionValue.get(), true)); | |
| 97 } | |
| 98 | |
| 99 Vector<String> keyframeProperties; | |
| 100 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | |
| 101 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | |
| 102 String property = keyframeProperties[j]; | |
| 103 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); | |
| 104 if (id == CSSPropertyInvalid) | |
| 105 continue; | |
| 106 String value; | |
| 107 DictionaryHelper::get(keyframeDictionaryVector[i], property, value); | |
| 108 keyframe->setPropertyValue(id, value, styleSheetContents); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 RefPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKeyframeEffect
Model::create(keyframes); | |
| 113 if (!keyframeEffectModel->isReplaceOnly()) { | |
| 114 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a
re not supported."); | |
| 115 return nullptr; | |
| 116 } | |
| 117 keyframeEffectModel->forceConversionsToAnimatableValues(element); | |
| 118 | |
| 119 return keyframeEffectModel; | |
| 120 } | |
| 121 | |
| 122 } // namespace blink | |
| OLD | NEW |