| 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 20 matching lines...) Expand all Loading... |
| 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/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "core/animation/AnimationHelpers.h" | 35 #include "core/animation/AnimationHelpers.h" |
| 36 #include "core/animation/KeyframeEffectModel.h" | 36 #include "core/animation/KeyframeEffectModel.h" |
| 37 #include "core/animation/StringKeyframe.h" | 37 #include "core/animation/StringKeyframe.h" |
| 38 #include "core/css/parser/BisonCSSParser.h" | 38 #include "core/css/parser/BisonCSSParser.h" |
| 39 #include "core/css/resolver/StyleResolver.h" | 39 #include "core/css/resolver/StyleResolver.h" |
| 40 #include "core/dom/Element.h" | 40 #include "core/dom/Element.h" |
| 41 #include "wtf/NonCopyingSort.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 // FIXME: Remove this once we've removed the dependency on Element. | 45 // FIXME: Remove this once we've removed the dependency on Element. |
| 45 static bool checkDocumentAndRenderer(Element* element) | 46 static bool checkDocumentAndRenderer(Element* element) |
| 46 { | 47 { |
| 47 if (!element || !element->inActiveDocument()) | 48 if (!element || !element->inActiveDocument()) |
| 48 return false; | 49 return false; |
| 49 element->document().updateRenderTreeIfNeeded(); | 50 element->document().updateRenderTreeIfNeeded(); |
| 50 return element->renderer(); | 51 return element->renderer(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat
e, bool unsafe) | 54 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c
onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionStat
e, bool unsafe) |
| 54 { | 55 { |
| 55 // FIXME: This test will not be neccessary once resolution of keyframe value
s occurs at | 56 // FIXME: This test will not be neccessary once resolution of keyframe value
s occurs at |
| 56 // animation application time. | 57 // animation application time. |
| 57 if (!unsafe && !checkDocumentAndRenderer(element)) | 58 if (!unsafe && !checkDocumentAndRenderer(element)) |
| 58 return nullptr; | 59 return nullptr; |
| 59 | 60 |
| 60 StyleSheetContents* styleSheetContents = element->document().elementSheet().
contents(); | 61 StyleSheetContents* styleSheetContents = element->document().elementSheet().
contents(); |
| 61 StringKeyframeVector keyframes; | 62 StringKeyframeVector keyframes; |
| 63 bool everyFrameHasOffset = true; |
| 64 bool looselySortedByOffset = true; |
| 65 double lastOffset = -std::numeric_limits<double>::infinity(); |
| 62 | 66 |
| 63 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | 67 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| 64 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); | 68 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 65 keyframes.append(keyframe); | 69 keyframes.append(keyframe); |
| 66 | 70 |
| 67 double offset; | 71 double offset; |
| 68 if (keyframeDictionaryVector[i].get("offset", offset)) | 72 if (keyframeDictionaryVector[i].get("offset", offset)) { |
| 69 keyframe->setOffset(offset); | 73 keyframe->setOffset(offset); |
| 74 if (offset < lastOffset) |
| 75 looselySortedByOffset = false; |
| 76 lastOffset = offset; |
| 77 } else { |
| 78 everyFrameHasOffset = false; |
| 79 } |
| 70 | 80 |
| 71 String compositeString; | 81 String compositeString; |
| 72 keyframeDictionaryVector[i].get("composite", compositeString); | 82 keyframeDictionaryVector[i].get("composite", compositeString); |
| 73 if (compositeString == "add") | 83 if (compositeString == "add") |
| 74 keyframe->setComposite(AnimationEffect::CompositeAdd); | 84 keyframe->setComposite(AnimationEffect::CompositeAdd); |
| 75 | 85 |
| 76 String timingFunctionString; | 86 String timingFunctionString; |
| 77 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { | 87 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { |
| 78 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p
arseAnimationTimingFunctionValue(timingFunctionString); | 88 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p
arseAnimationTimingFunctionValue(timingFunctionString); |
| 79 if (timingFunctionValue) | 89 if (timingFunctionValue) |
| 80 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin
gFunctionValue.get(), false)); | 90 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin
gFunctionValue.get(), false)); |
| 81 } | 91 } |
| 82 | 92 |
| 83 Vector<String> keyframeProperties; | 93 Vector<String> keyframeProperties; |
| 84 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | 94 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
| 85 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | 95 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
| 86 String property = keyframeProperties[j]; | 96 String property = keyframeProperties[j]; |
| 87 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); | 97 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
| 88 if (id == CSSPropertyInvalid) | 98 if (id == CSSPropertyInvalid) |
| 89 continue; | 99 continue; |
| 90 String value; | 100 String value; |
| 91 keyframeDictionaryVector[i].get(property, value); | 101 keyframeDictionaryVector[i].get(property, value); |
| 92 keyframe->setPropertyValue(id, value, styleSheetContents); | 102 keyframe->setPropertyValue(id, value, styleSheetContents); |
| 93 } | 103 } |
| 94 } | 104 } |
| 95 | 105 |
| 106 if (!looselySortedByOffset) { |
| 107 if (!everyFrameHasOffset) { |
| 108 exceptionState.throwDOMException(InvalidModificationError, "Keyframe
s are not loosely sorted by offset."); |
| 109 return nullptr; |
| 110 } |
| 111 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs
ets); |
| 112 } |
| 113 |
| 96 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe
yframeEffectModel::create(keyframes); | 114 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe
yframeEffectModel::create(keyframes); |
| 97 if (!keyframeEffectModel->isReplaceOnly()) { | 115 if (!keyframeEffectModel->isReplaceOnly()) { |
| 98 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a
re not supported."); | 116 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a
re not supported."); |
| 99 return nullptr; | 117 return nullptr; |
| 100 } | 118 } |
| 101 keyframeEffectModel->forceConversionsToAnimatableValues(element); | 119 keyframeEffectModel->forceConversionsToAnimatableValues(element); |
| 102 | 120 |
| 103 return keyframeEffectModel; | 121 return keyframeEffectModel; |
| 104 } | 122 } |
| 105 | 123 |
| 106 } // namespace WebCore | 124 } // namespace WebCore |
| OLD | NEW |