Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 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/ElementAnimation.h" | 32 #include "core/animation/ElementAnimation.h" |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptValue.h" | |
| 34 #include "core/animation/DocumentTimeline.h" | 35 #include "core/animation/DocumentTimeline.h" |
| 35 #include "core/css/RuntimeCSSEnabled.h" | 36 #include "core/css/RuntimeCSSEnabled.h" |
| 36 #include "core/css/resolver/StyleResolver.h" | 37 #include "core/css/resolver/StyleResolver.h" |
| 37 #include "wtf/text/StringBuilder.h" | 38 #include "wtf/text/StringBuilder.h" |
| 38 #include <algorithm> | 39 #include <algorithm> |
| 39 | 40 |
| 40 namespace WebCore { | 41 namespace WebCore { |
| 41 | 42 |
| 42 CSSPropertyID ElementAnimation::camelCaseCSSPropertyNameToID(StringImpl* propert yName) | 43 CSSPropertyID ElementAnimation::camelCaseCSSPropertyNameToID(StringImpl* propert yName) |
| 43 { | 44 { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 59 } | 60 } |
| 60 builder.append(propertyName->substring(position)); | 61 builder.append(propertyName->substring(position)); |
| 61 // Doesn't handle prefixed properties. | 62 // Doesn't handle prefixed properties. |
| 62 id = cssPropertyID(builder.toString()); | 63 id = cssPropertyID(builder.toString()); |
| 63 if (id != CSSPropertyInvalid && RuntimeCSSEnabled::isCSSPropertyEnabled( id)) | 64 if (id != CSSPropertyInvalid && RuntimeCSSEnabled::isCSSPropertyEnabled( id)) |
| 64 map.add(propertyName, id); | 65 map.add(propertyName, id); |
| 65 } | 66 } |
| 66 return id; | 67 return id; |
| 67 } | 68 } |
| 68 | 69 |
| 69 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector, double duration) | 70 static bool populateTiming(Timing& timing, Dictionary timingInputDictionary) |
| 71 { | |
| 72 if (timingInputDictionary.hasProperty("startDelay")) { | |
|
Steve Block
2013/12/17 00:05:35
This has been renamed to 'delay'. We should rename
rjwright
2013/12/18 04:17:14
Ok. Is it just this one? And is the spec up to dat
| |
| 73 double startDelay = std::numeric_limits<double>::quiet_NaN(); | |
| 74 timingInputDictionary.get("startDelay", startDelay); | |
| 75 ASSERT(!isnan(startDelay)); | |
| 76 ASSERT(!isinf(startDelay)); | |
|
Steve Block
2013/12/17 00:05:35
We shouldn't be asserting here - a developer could
rjwright
2013/12/18 04:17:14
Done.
| |
| 77 if (isnan(startDelay) || isinf(startDelay)) | |
| 78 return false; | |
| 79 timing.startDelay = startDelay; | |
| 80 } | |
|
shans
2013/12/16 23:47:22
I think it's simpler to check the bool result of D
rjwright1
2013/12/16 23:58:31
Ok,but these two suggestions only work in unison.
rjwright
2013/12/18 04:17:14
Done.
| |
| 81 | |
| 82 if (timingInputDictionary.hasProperty("fillMode")) { | |
| 83 String fillMode; | |
| 84 timingInputDictionary.get("fillMode", fillMode); | |
| 85 | |
| 86 if (fillMode == "none") { | |
| 87 timing.fillMode = Timing::FillModeNone; | |
| 88 } else if (fillMode == "forwards") { | |
| 89 timing.fillMode = Timing::FillModeForwards; | |
| 90 } else if (fillMode == "backwards") { | |
| 91 timing.fillMode = Timing::FillModeBackwards; | |
| 92 } else if (fillMode == "both") { | |
| 93 timing.fillMode = Timing::FillModeBoth; | |
| 94 } else { | |
| 95 ASSERT_NOT_REACHED(); | |
|
Steve Block
2013/12/17 00:05:35
Same thing about asserting and ignoring invalid in
rjwright
2013/12/18 04:17:14
Done.
| |
| 96 return false; | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 if (timingInputDictionary.hasProperty("iterationStart")) { | |
| 101 double iterationStart = std::numeric_limits<double>::quiet_NaN(); | |
| 102 timingInputDictionary.get("iterationStart", iterationStart); | |
| 103 ASSERT(!isnan(iterationStart)); | |
| 104 ASSERT(!isinf(iterationStart)); | |
| 105 if (isnan(iterationStart) || isinf(iterationStart)) | |
| 106 return false; | |
| 107 timing.iterationStart = std::max<double>(iterationStart, 0); | |
| 108 } | |
| 109 | |
| 110 if (timingInputDictionary.hasProperty("iterationCount")) { | |
| 111 double iterationCount = std::numeric_limits<double>::quiet_NaN(); | |
| 112 timingInputDictionary.get("iterationCount", iterationCount); | |
| 113 ASSERT(!isnan(iterationCount)); | |
| 114 if (isnan(iterationCount)) | |
| 115 return false; | |
| 116 timing.iterationCount = std::max<double>(iterationCount, 0); | |
| 117 } | |
| 118 | |
| 119 if (timingInputDictionary.hasProperty("iterationDuration")) { | |
| 120 v8::Local<v8::Value> iterationDurationValue; | |
| 121 timingInputDictionary.get("iterationDuration", iterationDurationValue); | |
| 122 | |
| 123 double iterationDuration; | |
| 124 if (iterationDurationValue->IsString()) { | |
| 125 // All strings are treated as 'auto' except strings that are numbers , e.g. '1' | |
| 126 bool isDouble = true; | |
| 127 iterationDuration = toCoreString(iterationDurationValue->ToString()) .toDouble(&isDouble); | |
| 128 if (isDouble) | |
| 129 timing.iterationDuration = std::max<double>(iterationDuration, 0 ); | |
| 130 else | |
| 131 timing.iterationDuration = 0; | |
| 132 timing.hasIterationDuration = true; | |
| 133 } else if (iterationDurationValue->IsNumber()) { | |
| 134 iterationDuration = iterationDurationValue->NumberValue(); | |
| 135 ASSERT(!isnan(iterationDuration)); | |
| 136 if (isnan(iterationDuration)) | |
| 137 return false; | |
| 138 timing.iterationDuration = std::max<double>(iterationDuration, 0); | |
| 139 timing.hasIterationDuration = true; | |
| 140 } else { | |
| 141 ASSERT_NOT_REACHED(); | |
| 142 return false; | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 return true; | |
| 147 } | |
| 148 | |
| 149 static bool checkDocumentAndRenderer(Element* element) | |
| 150 { | |
| 151 if (!element->inActiveDocument()) | |
| 152 return false; | |
| 153 element->document().updateStyleIfNeeded(); | |
| 154 if (!element->renderer()) | |
| 155 return false; | |
| 156 return true; | |
| 157 } | |
| 158 | |
| 159 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector) | |
| 70 { | 160 { |
| 71 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | 161 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); |
| 72 | 162 |
| 73 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at | 163 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at |
| 74 // animation application time. | 164 // animation application time. |
| 75 if (!element->inActiveDocument()) | 165 if (!checkDocumentAndRenderer(element)) |
| 76 return; | |
| 77 element->document().updateStyleIfNeeded(); | |
| 78 if (!element->renderer()) | |
| 79 return; | 166 return; |
| 80 | 167 |
| 81 startAnimation(element, keyframeDictionaryVector, duration); | 168 startAnimation(element, keyframeDictionaryVector); |
| 82 } | 169 } |
| 83 | 170 |
| 84 void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyfr ameDictionaryVector, double duration) | 171 void ElementAnimation::animate(Element* element, Vector<Dictionary> keyframeDict ionaryVector, ScriptValue timingInput) |
| 172 { | |
| 173 ASSERT(RuntimeEnabledFeatures::webAnimationsAPIEnabled()); | |
| 174 | |
| 175 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at | |
| 176 // animation application time. | |
| 177 if (!checkDocumentAndRenderer(element)) | |
| 178 return; | |
| 179 | |
| 180 startAnimation(element, keyframeDictionaryVector, timingInput.v8Value()); | |
| 181 } | |
| 182 | |
| 183 void ElementAnimation::startAnimation(Element* element, Vector<Dictionary> keyfr ameDictionaryVector, v8::Handle<v8::Value> timingInput) | |
| 85 { | 184 { |
| 86 KeyframeAnimationEffect::KeyframeVector keyframes; | 185 KeyframeAnimationEffect::KeyframeVector keyframes; |
| 87 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; | 186 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; |
| 88 | 187 |
| 89 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { | 188 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { |
| 90 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(); | 189 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(); |
| 91 propertySetVector.append(propertySet); | 190 propertySetVector.append(propertySet); |
| 92 | 191 |
| 93 RefPtr<Keyframe> keyframe = Keyframe::create(); | 192 RefPtr<Keyframe> keyframe = Keyframe::create(); |
| 94 keyframes.append(keyframe); | 193 keyframes.append(keyframe); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 225 |
| 127 String value; | 226 String value; |
| 128 keyframeDictionaryVector[i].get(property, value); | 227 keyframeDictionaryVector[i].get(property, value); |
| 129 propertySet->setProperty(id, value); | 228 propertySet->setProperty(id, value); |
| 130 } | 229 } |
| 131 } | 230 } |
| 132 | 231 |
| 133 // FIXME: Replace this with code that just parses, when that code is availab le. | 232 // FIXME: Replace this with code that just parses, when that code is availab le. |
| 134 RefPtr<KeyframeAnimationEffect> effect = StyleResolver::createKeyframeAnimat ionEffect(*element, propertySetVector, keyframes); | 233 RefPtr<KeyframeAnimationEffect> effect = StyleResolver::createKeyframeAnimat ionEffect(*element, propertySetVector, keyframes); |
| 135 | 234 |
| 136 // FIXME: Totally hardcoded Timing for now. Will handle timing parameters la ter. | |
| 137 Timing timing; | 235 Timing timing; |
| 138 // FIXME: Currently there is no way to tell whether or not an iterationDurat ion | 236 if (!timingInput.IsEmpty()) { |
| 139 // has been specified (becauser the default argument is 0). So any animation | 237 if (timingInput->IsNumber()) { |
| 140 // created using Element.animate() will have a timing with hasIterationDurat ion() | 238 timing.hasIterationDuration = true; |
| 141 // == true. | 239 timing.iterationDuration = std::max<double>(timingInput->NumberValue (), 0); |
| 142 timing.hasIterationDuration = true; | 240 } else if (timingInput->IsObject()) { |
| 143 timing.iterationDuration = std::max<double>(duration, 0); | 241 // FIXME: This just returns if any of the timing input members are i nvalid |
| 242 // (e.g. a non-numeric iterationCount). Maybe it should do something more useful. | |
| 243 if (!populateTiming(timing, Dictionary::Dictionary(v8::Handle<v8::Va lue>::Cast(timingInput), v8::Isolate::GetCurrent()))) | |
| 244 return; | |
|
Steve Block
2013/12/17 00:05:35
Again, I don't think we should fail.
rjwright
2013/12/18 04:17:14
Done.
| |
| 245 } else { | |
| 246 return; | |
|
Steve Block
2013/12/17 00:05:35
This seems wrong. I think that if timingInput is n
rjwright
2013/12/18 04:17:14
Sounds good, but I have no idea how to do it.
| |
| 247 } | |
| 248 } | |
| 144 | 249 |
| 145 RefPtr<Animation> animation = Animation::create(element, effect, timing); | 250 RefPtr<Animation> animation = Animation::create(element, effect, timing); |
| 146 DocumentTimeline* timeline = element->document().timeline(); | 251 DocumentTimeline* timeline = element->document().timeline(); |
| 147 ASSERT(timeline); | 252 ASSERT(timeline); |
| 148 timeline->play(animation.get()); | 253 timeline->play(animation.get()); |
| 149 } | 254 } |
| 150 | 255 |
| 151 } // namespace WebCore | 256 } // namespace WebCore |
| OLD | NEW |