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(); |
69 | |
70 bool frameHasOffset = false; | |
71 double offset; | |
72 if (keyframeDictionaryVector[i].get("offset", offset)) { | |
73 // Keyframes with offsets outside the range [0.0, 1.0] are ignored. | |
74 if (isNull(offset) || offset < 0 || offset > 1) | |
dstockwell
2014/04/29 09:10:09
this should probably use std isnan rather than isn
alancutter (OOO until 2018)
2014/04/29 09:12:23
Done.
| |
75 continue; | |
76 | |
77 frameHasOffset = true; | |
78 // The JS value null get converted to 0 so we need to check whether the original value is null. | |
dstockwell
2014/04/29 09:10:09
gets
alancutter (OOO until 2018)
2014/04/29 09:12:23
Done.
| |
79 if (offset == 0) { | |
80 ScriptValue scriptValue; | |
81 if (keyframeDictionaryVector[i].get("offset", scriptValue) && sc riptValue->isNull()) | |
82 frameHasOffset = false; | |
83 } | |
84 if (frameHasOffset) { | |
85 keyframe->setOffset(offset); | |
86 if (offset < lastOffset) | |
87 looselySortedByOffset = false; | |
88 lastOffset = offset; | |
89 } | |
90 } | |
91 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset; | |
92 | |
65 keyframes.append(keyframe); | 93 keyframes.append(keyframe); |
66 | 94 |
67 double offset; | |
68 if (keyframeDictionaryVector[i].get("offset", offset)) | |
69 keyframe->setOffset(offset); | |
70 | |
71 String compositeString; | 95 String compositeString; |
72 keyframeDictionaryVector[i].get("composite", compositeString); | 96 keyframeDictionaryVector[i].get("composite", compositeString); |
73 if (compositeString == "add") | 97 if (compositeString == "add") |
74 keyframe->setComposite(AnimationEffect::CompositeAdd); | 98 keyframe->setComposite(AnimationEffect::CompositeAdd); |
75 | 99 |
76 String timingFunctionString; | 100 String timingFunctionString; |
77 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { | 101 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { |
78 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); | 102 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); |
79 if (timingFunctionValue) | 103 if (timingFunctionValue) |
80 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); | 104 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); |
81 } | 105 } |
82 | 106 |
83 Vector<String> keyframeProperties; | 107 Vector<String> keyframeProperties; |
84 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | 108 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
85 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | 109 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
86 String property = keyframeProperties[j]; | 110 String property = keyframeProperties[j]; |
87 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); | 111 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
88 if (id == CSSPropertyInvalid) | 112 if (id == CSSPropertyInvalid) |
89 continue; | 113 continue; |
90 String value; | 114 String value; |
91 keyframeDictionaryVector[i].get(property, value); | 115 keyframeDictionaryVector[i].get(property, value); |
92 keyframe->setPropertyValue(id, value, styleSheetContents); | 116 keyframe->setPropertyValue(id, value, styleSheetContents); |
93 } | 117 } |
94 } | 118 } |
95 | 119 |
120 if (!looselySortedByOffset) { | |
121 if (!everyFrameHasOffset) { | |
122 exceptionState.throwDOMException(InvalidModificationError, "Keyframe s are not loosely sorted by offset."); | |
123 return nullptr; | |
124 } | |
125 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs ets); | |
126 } | |
127 | |
96 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); | 128 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); |
97 if (!keyframeEffectModel->isReplaceOnly()) { | 129 if (!keyframeEffectModel->isReplaceOnly()) { |
98 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); | 130 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); |
99 return nullptr; | 131 return nullptr; |
100 } | 132 } |
101 keyframeEffectModel->forceConversionsToAnimatableValues(element); | 133 keyframeEffectModel->forceConversionsToAnimatableValues(element); |
102 | 134 |
103 return keyframeEffectModel; | 135 return keyframeEffectModel; |
104 } | 136 } |
105 | 137 |
106 } // namespace WebCore | 138 } // namespace WebCore |
OLD | NEW |