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 v8::Local<v8::Value> v8Value; | |
dstockwell
2014/04/29 08:11:47
v8::Local is not usually used in core/ code, +hara
haraken
2014/04/29 08:16:20
Can we use ScriptValue?
| |
72 if (keyframeDictionaryVector[i].get("offset", v8Value) && !v8Value->IsNu ll()) { | |
73 v8::Local<v8::Number> v8Number = v8Value->ToNumber(); | |
74 if (!v8Number.IsEmpty()) { | |
75 double offset = v8Number->Value(); | |
76 // Keyframes with offsets outside the range [0.0, 1.0] are ignor ed. | |
77 if (isNull(offset) || offset < 0 || offset > 1) | |
78 continue; | |
79 | |
80 keyframe->setOffset(offset); | |
81 if (offset < lastOffset) | |
82 looselySortedByOffset = false; | |
83 lastOffset = offset; | |
84 frameHasOffset = true; | |
85 } | |
86 } | |
87 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset; | |
88 | |
65 keyframes.append(keyframe); | 89 keyframes.append(keyframe); |
66 | 90 |
67 double offset; | |
68 if (keyframeDictionaryVector[i].get("offset", offset)) | |
69 keyframe->setOffset(offset); | |
70 | |
71 String compositeString; | 91 String compositeString; |
72 keyframeDictionaryVector[i].get("composite", compositeString); | 92 keyframeDictionaryVector[i].get("composite", compositeString); |
73 if (compositeString == "add") | 93 if (compositeString == "add") |
74 keyframe->setComposite(AnimationEffect::CompositeAdd); | 94 keyframe->setComposite(AnimationEffect::CompositeAdd); |
75 | 95 |
76 String timingFunctionString; | 96 String timingFunctionString; |
77 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { | 97 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { |
78 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); | 98 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); |
79 if (timingFunctionValue) | 99 if (timingFunctionValue) |
80 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); | 100 keyframe->setEasing(CSSToStyleMap::animationTimingFunction(timin gFunctionValue.get(), false)); |
81 } | 101 } |
82 | 102 |
83 Vector<String> keyframeProperties; | 103 Vector<String> keyframeProperties; |
84 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); | 104 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); |
85 for (size_t j = 0; j < keyframeProperties.size(); ++j) { | 105 for (size_t j = 0; j < keyframeProperties.size(); ++j) { |
86 String property = keyframeProperties[j]; | 106 String property = keyframeProperties[j]; |
87 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); | 107 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); |
88 if (id == CSSPropertyInvalid) | 108 if (id == CSSPropertyInvalid) |
89 continue; | 109 continue; |
90 String value; | 110 String value; |
91 keyframeDictionaryVector[i].get(property, value); | 111 keyframeDictionaryVector[i].get(property, value); |
92 keyframe->setPropertyValue(id, value, styleSheetContents); | 112 keyframe->setPropertyValue(id, value, styleSheetContents); |
93 } | 113 } |
94 } | 114 } |
95 | 115 |
116 if (!looselySortedByOffset) { | |
117 if (!everyFrameHasOffset) { | |
118 exceptionState.throwDOMException(InvalidModificationError, "Keyframe s are not loosely sorted by offset."); | |
119 return nullptr; | |
120 } | |
121 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs ets); | |
122 } | |
123 | |
96 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); | 124 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); |
97 if (!keyframeEffectModel->isReplaceOnly()) { | 125 if (!keyframeEffectModel->isReplaceOnly()) { |
98 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); | 126 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); |
99 return nullptr; | 127 return nullptr; |
100 } | 128 } |
101 keyframeEffectModel->forceConversionsToAnimatableValues(element); | 129 keyframeEffectModel->forceConversionsToAnimatableValues(element); |
102 | 130 |
103 return keyframeEffectModel; | 131 return keyframeEffectModel; |
104 } | 132 } |
105 | 133 |
106 } // namespace WebCore | 134 } // namespace WebCore |
OLD | NEW |