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 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 if (DictionaryHelper::get(keyframeDictionary, property, result)) | |
| 227 return true; | |
| 228 | |
| 229 // The above get() only works for Array objects, we still need to handle obj ects that satisfy the ES6 iterator protocol. | |
|
suzyh_UTC10 (ex-contributor)
2016/09/14 01:07:53
Nit: As discussed in person, remove this comment a
| |
| 230 | |
| 231 Dictionary valuesDictionary; | |
| 232 if (!keyframeDictionary.get(property, valuesDictionary)) { | |
| 233 String value; | |
| 234 DictionaryHelper::get(keyframeDictionary, property, value); | |
| 235 result.append(value); | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 239 DictionaryIterator iterator = valuesDictionary.getIterator(executionContext) ; | |
| 240 if (iterator.isNull()) { | |
| 241 String value; | |
| 242 DictionaryHelper::get(keyframeDictionary, property, value); | |
| 243 result.append(value); | |
| 244 return true; | |
| 245 } | |
| 246 | |
| 247 while (iterator.next(executionContext, exceptionState)) { | |
| 248 String value; | |
| 249 if (!iterator.valueAsString(value)) { | |
| 250 exceptionState.throwTypeError("Unable to read keyframe value as stri ng."); | |
| 251 return false; | |
| 252 } | |
| 253 result.append(value); | |
| 254 } | |
| 255 return !exceptionState.hadException(); | |
| 256 } | |
| 257 | |
| 258 EffectModel* EffectInput::convertObjectForm(Element& element, const Dictionary& keyframeDictionary, ExecutionContext* executionContext, ExceptionState& exceptio nState) | |
| 224 { | 259 { |
| 225 StringKeyframeVector keyframes; | 260 StringKeyframeVector keyframes; |
| 226 | 261 |
| 227 String timingFunctionString; | 262 String timingFunctionString; |
| 228 RefPtr<TimingFunction> timingFunction = nullptr; | 263 RefPtr<TimingFunction> timingFunction = nullptr; |
| 229 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString )) { | 264 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString )) { |
| 230 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti onString, &element.document(), exceptionState); | 265 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti onString, &element.document(), exceptionState); |
| 231 if (!timingFunction) | 266 if (!timingFunction) |
| 232 return nullptr; | 267 return nullptr; |
| 233 } | 268 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 244 Vector<String> keyframeProperties; | 279 Vector<String> keyframeProperties; |
| 245 keyframeDictionary.getPropertyNames(keyframeProperties); | 280 keyframeDictionary.getPropertyNames(keyframeProperties); |
| 246 for (const auto& property : keyframeProperties) { | 281 for (const auto& property : keyframeProperties) { |
| 247 if (property == "offset" | 282 if (property == "offset" |
| 248 || property == "composite" | 283 || property == "composite" |
| 249 || property == "easing") { | 284 || property == "easing") { |
| 250 continue; | 285 continue; |
| 251 } | 286 } |
| 252 | 287 |
| 253 Vector<String> values; | 288 Vector<String> values; |
| 254 bool isList = DictionaryHelper::get(keyframeDictionary, property, values ); | 289 if (!getPropertyIndexedKeyframeValues(keyframeDictionary, property, exec utionContext, exceptionState, values)) |
| 255 if (!isList) { | 290 return nullptr; |
| 256 String value; | |
| 257 DictionaryHelper::get(keyframeDictionary, property, value); | |
| 258 values.append(value); | |
| 259 } | |
| 260 | 291 |
| 261 size_t numKeyframes = values.size(); | 292 size_t numKeyframes = values.size(); |
| 262 for (size_t i = 0; i < numKeyframes; ++i) { | 293 for (size_t i = 0; i < numKeyframes; ++i) { |
| 263 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); | 294 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); |
| 264 | 295 |
| 265 if (frameHasOffset) | 296 if (frameHasOffset) |
| 266 keyframe->setOffset(offset); | 297 keyframe->setOffset(offset); |
| 267 else if (numKeyframes == 1) | 298 else if (numKeyframes == 1) |
| 268 keyframe->setOffset(1.0); | 299 keyframe->setOffset(1.0); |
| 269 else | 300 else |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 282 } | 313 } |
| 283 | 314 |
| 284 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); | 315 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); |
| 285 | 316 |
| 286 DCHECK(!exceptionState.hadException()); | 317 DCHECK(!exceptionState.hadException()); |
| 287 | 318 |
| 288 return createEffectModelFromKeyframes(element, keyframes, exceptionState); | 319 return createEffectModelFromKeyframes(element, keyframes, exceptionState); |
| 289 } | 320 } |
| 290 | 321 |
| 291 } // namespace blink | 322 } // namespace blink |
| OLD | NEW |