| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/animation/EffectInput.h" | 32 #include "core/animation/EffectInput.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/Dictionary.h" | 34 #include "bindings/core/v8/Dictionary.h" |
| 35 #include "bindings/core/v8/DictionaryHelper.h" |
| 35 #include "core/animation/AnimationHelpers.h" | 36 #include "core/animation/AnimationHelpers.h" |
| 36 #include "core/animation/KeyframeEffectModel.h" | 37 #include "core/animation/KeyframeEffectModel.h" |
| 37 #include "core/animation/StringKeyframe.h" | 38 #include "core/animation/StringKeyframe.h" |
| 38 #include "core/css/parser/BisonCSSParser.h" | 39 #include "core/css/parser/BisonCSSParser.h" |
| 39 #include "core/css/resolver/CSSToStyleMap.h" | 40 #include "core/css/resolver/CSSToStyleMap.h" |
| 40 #include "core/css/resolver/StyleResolver.h" | 41 #include "core/css/resolver/StyleResolver.h" |
| 41 #include "core/dom/Document.h" | 42 #include "core/dom/Document.h" |
| 42 #include "core/dom/Element.h" | 43 #include "core/dom/Element.h" |
| 43 #include "wtf/NonCopyingSort.h" | 44 #include "wtf/NonCopyingSort.h" |
| 44 | 45 |
| 45 namespace WebCore { | 46 namespace WebCore { |
| 46 | 47 |
| 47 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat
e) | 48 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat
e) |
| 48 { | 49 { |
| 49 // FIXME: Remove the dependency on element. | 50 // FIXME: Remove the dependency on element. |
| 50 if (!element) | 51 if (!element) |
| 51 return nullptr; | 52 return nullptr; |
| 52 | 53 |
| 53 StyleSheetContents* styleSheetContents = element->document().elementSheet().
contents(); | 54 StyleSheetContents* styleSheetContents = element->document().elementSheet().
contents(); |
| 54 StringKeyframeVector keyframes; | 55 StringKeyframeVector keyframes; |
| 55 bool everyFrameHasOffset = true; | 56 bool everyFrameHasOffset = true; |
| 56 bool looselySortedByOffset = true; | 57 bool looselySortedByOffset = true; |
| 57 double lastOffset = -std::numeric_limits<double>::infinity(); | 58 double lastOffset = -std::numeric_limits<double>::infinity(); |
| 58 | 59 |
| 59 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | 60 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| 60 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); | 61 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 61 | 62 |
| 62 bool frameHasOffset = false; | 63 bool frameHasOffset = false; |
| 63 double offset; | 64 double offset; |
| 64 if (keyframeDictionaryVector[i].get("offset", offset)) { | 65 if (DictionaryHelper::get(keyframeDictionaryVector[i], "offset", offset)
) { |
| 65 // Keyframes with offsets outside the range [0.0, 1.0] are ignored. | 66 // Keyframes with offsets outside the range [0.0, 1.0] are ignored. |
| 66 if (std::isnan(offset) || offset < 0 || offset > 1) | 67 if (std::isnan(offset) || offset < 0 || offset > 1) |
| 67 continue; | 68 continue; |
| 68 | 69 |
| 69 frameHasOffset = true; | 70 frameHasOffset = true; |
| 70 // The JS value null gets converted to 0 so we need to check whether
the original value is null. | 71 // The JS value null gets converted to 0 so we need to check whether
the original value is null. |
| 71 if (offset == 0) { | 72 if (offset == 0) { |
| 72 ScriptValue scriptValue; | 73 ScriptValue scriptValue; |
| 73 if (keyframeDictionaryVector[i].get("offset", scriptValue) && sc
riptValue.isNull()) | 74 if (DictionaryHelper::get(keyframeDictionaryVector[i], "offset",
scriptValue) && scriptValue.isNull()) |
| 74 frameHasOffset = false; | 75 frameHasOffset = false; |
| 75 } | 76 } |
| 76 if (frameHasOffset) { | 77 if (frameHasOffset) { |
| 77 keyframe->setOffset(offset); | 78 keyframe->setOffset(offset); |
| 78 if (offset < lastOffset) | 79 if (offset < lastOffset) |
| 79 looselySortedByOffset = false; | 80 looselySortedByOffset = false; |
| 80 lastOffset = offset; | 81 lastOffset = offset; |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset; | 84 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset; |
| 84 | 85 |
| 85 keyframes.append(keyframe); | 86 keyframes.append(keyframe); |
| 86 | 87 |
| 87 String compositeString; | 88 String compositeString; |
| 88 keyframeDictionaryVector[i].get("composite", compositeString); | 89 DictionaryHelper::get(keyframeDictionaryVector[i], "composite", composit
eString); |
| 89 if (compositeString == "add") | 90 if (compositeString == "add") |
| 90 keyframe->setComposite(AnimationEffect::CompositeAdd); | 91 keyframe->setComposite(AnimationEffect::CompositeAdd); |
| 91 | 92 |
| 92 String timingFunctionString; | 93 String timingFunctionString; |
| 93 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { | 94 if (DictionaryHelper::get(keyframeDictionaryVector[i], "easing", timingF
unctionString)) { |
| 94 if (RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParse
r::parseAnimationTimingFunctionValue(timingFunctionString)) | 95 if (RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParse
r::parseAnimationTimingFunctionValue(timingFunctionString)) |
| 95 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(ti
mingFunctionValue.get(), true)); | 96 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(ti
mingFunctionValue.get(), true)); |
| 96 } | 97 } |
| 97 | 98 |
| 98 Vector<String> keyframeProperties; | 99 Vector<String> keyframeProperties; |
| 99 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | 100 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
| 100 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | 101 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
| 101 String property = keyframeProperties[j]; | 102 String property = keyframeProperties[j]; |
| 102 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); | 103 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
| 103 if (id == CSSPropertyInvalid) | 104 if (id == CSSPropertyInvalid) |
| 104 continue; | 105 continue; |
| 105 String value; | 106 String value; |
| 106 keyframeDictionaryVector[i].get(property, value); | 107 DictionaryHelper::get(keyframeDictionaryVector[i], property, value); |
| 107 keyframe->setPropertyValue(id, value, styleSheetContents); | 108 keyframe->setPropertyValue(id, value, styleSheetContents); |
| 108 } | 109 } |
| 109 } | 110 } |
| 110 | 111 |
| 111 if (!looselySortedByOffset) { | 112 if (!looselySortedByOffset) { |
| 112 if (!everyFrameHasOffset) { | 113 if (!everyFrameHasOffset) { |
| 113 exceptionState.throwDOMException(InvalidModificationError, "Keyframe
s are not loosely sorted by offset."); | 114 exceptionState.throwDOMException(InvalidModificationError, "Keyframe
s are not loosely sorted by offset."); |
| 114 return nullptr; | 115 return nullptr; |
| 115 } | 116 } |
| 116 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs
ets); | 117 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs
ets); |
| 117 } | 118 } |
| 118 | 119 |
| 119 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe
yframeEffectModel::create(keyframes); | 120 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe
yframeEffectModel::create(keyframes); |
| 120 if (!keyframeEffectModel->isReplaceOnly()) { | 121 if (!keyframeEffectModel->isReplaceOnly()) { |
| 121 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a
re not supported."); | 122 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a
re not supported."); |
| 122 return nullptr; | 123 return nullptr; |
| 123 } | 124 } |
| 124 keyframeEffectModel->forceConversionsToAnimatableValues(element); | 125 keyframeEffectModel->forceConversionsToAnimatableValues(element); |
| 125 | 126 |
| 126 return keyframeEffectModel; | 127 return keyframeEffectModel; |
| 127 } | 128 } |
| 128 | 129 |
| 129 } // namespace WebCore | 130 } // namespace WebCore |
| OLD | NEW |