| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const Dictionary& dictionary = effectInput.getAsDictionary(); | 149 const Dictionary& dictionary = effectInput.getAsDictionary(); |
| 150 DictionaryIterator iterator = dictionary.getIterator(executionContext); | 150 DictionaryIterator iterator = dictionary.getIterator(executionContext); |
| 151 if (!iterator.isNull()) { | 151 if (!iterator.isNull()) { |
| 152 // TODO(alancutter): Convert keyframes during iteration rather than afte
r to match spec. | 152 // TODO(alancutter): Convert keyframes during iteration rather than afte
r to match spec. |
| 153 Vector<Dictionary> keyframeDictionaries; | 153 Vector<Dictionary> keyframeDictionaries; |
| 154 if (exhaustDictionaryIterator(iterator, executionContext, exceptionState
, keyframeDictionaries)) | 154 if (exhaustDictionaryIterator(iterator, executionContext, exceptionState
, keyframeDictionaries)) |
| 155 return convertArrayForm(*element, keyframeDictionaries, exceptionSta
te); | 155 return convertArrayForm(*element, keyframeDictionaries, exceptionSta
te); |
| 156 return nullptr; | 156 return nullptr; |
| 157 } | 157 } |
| 158 | 158 |
| 159 return convertObjectForm(*element, dictionary, exceptionState); | 159 return convertObjectForm(*element, dictionary, executionContext, exceptionSt
ate); |
| 160 } | 160 } |
| 161 | 161 |
| 162 EffectModel* EffectInput::convertArrayForm(Element& element, const Vector<Dictio
nary>& keyframeDictionaries, ExceptionState& exceptionState) | 162 EffectModel* EffectInput::convertArrayForm(Element& element, const Vector<Dictio
nary>& keyframeDictionaries, ExceptionState& exceptionState) |
| 163 { | 163 { |
| 164 StringKeyframeVector keyframes; | 164 StringKeyframeVector keyframes; |
| 165 double lastOffset = 0; | 165 double lastOffset = 0; |
| 166 | 166 |
| 167 for (const Dictionary& keyframeDictionary : keyframeDictionaries) { | 167 for (const Dictionary& keyframeDictionary : keyframeDictionaries) { |
| 168 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); | 168 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 169 | 169 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 setKeyframeValue(element, *keyframe.get(), property, value); | 213 setKeyframeValue(element, *keyframe.get(), property, value); |
| 214 } | 214 } |
| 215 keyframes.append(keyframe); | 215 keyframes.append(keyframe); |
| 216 } | 216 } |
| 217 | 217 |
| 218 DCHECK(!exceptionState.hadException()); | 218 DCHECK(!exceptionState.hadException()); |
| 219 | 219 |
| 220 return createEffectModelFromKeyframes(element, keyframes, exceptionState); | 220 return createEffectModelFromKeyframes(element, keyframes, exceptionState); |
| 221 } | 221 } |
| 222 | 222 |
| 223 EffectModel* EffectInput::convertObjectForm(Element& element, const Dictionary&
keyframeDictionary, ExceptionState& exceptionState) | 223 static bool getPropertyIndexedKeyframeValues(const Dictionary& keyframeDictionar
y, const String& property, ExecutionContext* executionContext, ExceptionState& e
xceptionState, Vector<String>& result) |
| 224 { |
| 225 DCHECK(result.isEmpty()); |
| 226 |
| 227 // Array of strings. |
| 228 if (DictionaryHelper::get(keyframeDictionary, property, result)) |
| 229 return true; |
| 230 |
| 231 Dictionary valuesDictionary; |
| 232 if (!keyframeDictionary.get(property, valuesDictionary) || valuesDictionary.
isUndefinedOrNull()) { |
| 233 // Non-object. |
| 234 String value; |
| 235 DictionaryHelper::get(keyframeDictionary, property, value); |
| 236 result.append(value); |
| 237 return true; |
| 238 } |
| 239 |
| 240 DictionaryIterator iterator = valuesDictionary.getIterator(executionContext)
; |
| 241 if (iterator.isNull()) { |
| 242 // Non-iterable object. |
| 243 String value; |
| 244 DictionaryHelper::get(keyframeDictionary, property, value); |
| 245 result.append(value); |
| 246 return true; |
| 247 } |
| 248 |
| 249 // Iterable object. |
| 250 while (iterator.next(executionContext, exceptionState)) { |
| 251 String value; |
| 252 if (!iterator.valueAsString(value)) { |
| 253 exceptionState.throwTypeError("Unable to read keyframe value as stri
ng."); |
| 254 return false; |
| 255 } |
| 256 result.append(value); |
| 257 } |
| 258 return !exceptionState.hadException(); |
| 259 } |
| 260 |
| 261 EffectModel* EffectInput::convertObjectForm(Element& element, const Dictionary&
keyframeDictionary, ExecutionContext* executionContext, ExceptionState& exceptio
nState) |
| 224 { | 262 { |
| 225 StringKeyframeVector keyframes; | 263 StringKeyframeVector keyframes; |
| 226 | 264 |
| 227 String timingFunctionString; | 265 String timingFunctionString; |
| 228 RefPtr<TimingFunction> timingFunction = nullptr; | 266 RefPtr<TimingFunction> timingFunction = nullptr; |
| 229 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString
)) { | 267 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString
)) { |
| 230 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti
onString, &element.document(), exceptionState); | 268 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti
onString, &element.document(), exceptionState); |
| 231 if (!timingFunction) | 269 if (!timingFunction) |
| 232 return nullptr; | 270 return nullptr; |
| 233 } | 271 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 244 Vector<String> keyframeProperties; | 282 Vector<String> keyframeProperties; |
| 245 keyframeDictionary.getPropertyNames(keyframeProperties); | 283 keyframeDictionary.getPropertyNames(keyframeProperties); |
| 246 for (const auto& property : keyframeProperties) { | 284 for (const auto& property : keyframeProperties) { |
| 247 if (property == "offset" | 285 if (property == "offset" |
| 248 || property == "composite" | 286 || property == "composite" |
| 249 || property == "easing") { | 287 || property == "easing") { |
| 250 continue; | 288 continue; |
| 251 } | 289 } |
| 252 | 290 |
| 253 Vector<String> values; | 291 Vector<String> values; |
| 254 bool isList = DictionaryHelper::get(keyframeDictionary, property, values
); | 292 if (!getPropertyIndexedKeyframeValues(keyframeDictionary, property, exec
utionContext, exceptionState, values)) |
| 255 if (!isList) { | 293 return nullptr; |
| 256 String value; | |
| 257 DictionaryHelper::get(keyframeDictionary, property, value); | |
| 258 values.append(value); | |
| 259 } | |
| 260 | 294 |
| 261 size_t numKeyframes = values.size(); | 295 size_t numKeyframes = values.size(); |
| 262 for (size_t i = 0; i < numKeyframes; ++i) { | 296 for (size_t i = 0; i < numKeyframes; ++i) { |
| 263 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); | 297 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 264 | 298 |
| 265 if (frameHasOffset) | 299 if (frameHasOffset) |
| 266 keyframe->setOffset(offset); | 300 keyframe->setOffset(offset); |
| 267 else if (numKeyframes == 1) | 301 else if (numKeyframes == 1) |
| 268 keyframe->setOffset(1.0); | 302 keyframe->setOffset(1.0); |
| 269 else | 303 else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 282 } | 316 } |
| 283 | 317 |
| 284 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); | 318 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); |
| 285 | 319 |
| 286 DCHECK(!exceptionState.hadException()); | 320 DCHECK(!exceptionState.hadException()); |
| 287 | 321 |
| 288 return createEffectModelFromKeyframes(element, keyframes, exceptionState); | 322 return createEffectModelFromKeyframes(element, keyframes, exceptionState); |
| 289 } | 323 } |
| 290 | 324 |
| 291 } // namespace blink | 325 } // namespace blink |
| OLD | NEW |