Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: third_party/WebKit/Source/core/animation/EffectInput.cpp

Issue 2334123002: Web Animations: Support iterator protocol in property indexed keyframe values (Closed)
Patch Set: Exception handling Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/animation/EffectInput.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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.
230 Dictionary valuesDictionary;
231 bool success = keyframeDictionary.get(property, valuesDictionary);
232 DictionaryIterator iterator(success ? valuesDictionary.getIterator(execution Context) : nullptr);
233 if (iterator.isNull()) {
suzyh_UTC10 (ex-contributor) 2016/09/13 08:21:21 This code is difficult to read/understand. IIUC, i
alancutter (OOO until 2018) 2016/09/13 09:31:28 I was avoiding code duplication. Probably not wort
234 String value;
235 DictionaryHelper::get(keyframeDictionary, property, value);
236 result.append(value);
237 return true;
238 }
239
240 while (iterator.next(executionContext, exceptionState)) {
241 String value;
242 if (!iterator.valueAsString(value))
243 return false;
244 result.append(value);
245 }
246 return !exceptionState.hadException();
247 }
248
249 EffectModel* EffectInput::convertObjectForm(Element& element, const Dictionary& keyframeDictionary, ExecutionContext* executionContext, ExceptionState& exceptio nState)
224 { 250 {
225 StringKeyframeVector keyframes; 251 StringKeyframeVector keyframes;
226 252
227 String timingFunctionString; 253 String timingFunctionString;
228 RefPtr<TimingFunction> timingFunction = nullptr; 254 RefPtr<TimingFunction> timingFunction = nullptr;
229 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString )) { 255 if (DictionaryHelper::get(keyframeDictionary, "easing", timingFunctionString )) {
230 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti onString, &element.document(), exceptionState); 256 timingFunction = AnimationInputHelpers::parseTimingFunction(timingFuncti onString, &element.document(), exceptionState);
231 if (!timingFunction) 257 if (!timingFunction)
232 return nullptr; 258 return nullptr;
233 } 259 }
(...skipping 10 matching lines...) Expand all
244 Vector<String> keyframeProperties; 270 Vector<String> keyframeProperties;
245 keyframeDictionary.getPropertyNames(keyframeProperties); 271 keyframeDictionary.getPropertyNames(keyframeProperties);
246 for (const auto& property : keyframeProperties) { 272 for (const auto& property : keyframeProperties) {
247 if (property == "offset" 273 if (property == "offset"
248 || property == "composite" 274 || property == "composite"
249 || property == "easing") { 275 || property == "easing") {
250 continue; 276 continue;
251 } 277 }
252 278
253 Vector<String> values; 279 Vector<String> values;
254 bool isList = DictionaryHelper::get(keyframeDictionary, property, values ); 280 if (!getPropertyIndexedKeyframeValues(keyframeDictionary, property, exec utionContext, exceptionState, values))
255 if (!isList) { 281 return nullptr;
suzyh_UTC10 (ex-contributor) 2016/09/13 08:21:21 In other places where we return nullptr, it happen
alancutter (OOO until 2018) 2016/09/13 09:31:28 Added throwTypeError() call and test case.
256 String value;
257 DictionaryHelper::get(keyframeDictionary, property, value);
258 values.append(value);
259 }
260 282
261 size_t numKeyframes = values.size(); 283 size_t numKeyframes = values.size();
262 for (size_t i = 0; i < numKeyframes; ++i) { 284 for (size_t i = 0; i < numKeyframes; ++i) {
263 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); 285 RefPtr<StringKeyframe> keyframe = StringKeyframe::create();
264 286
265 if (frameHasOffset) 287 if (frameHasOffset)
266 keyframe->setOffset(offset); 288 keyframe->setOffset(offset);
267 else if (numKeyframes == 1) 289 else if (numKeyframes == 1)
268 keyframe->setOffset(1.0); 290 keyframe->setOffset(1.0);
269 else 291 else
(...skipping 12 matching lines...) Expand all
282 } 304 }
283 305
284 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); 306 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes);
285 307
286 DCHECK(!exceptionState.hadException()); 308 DCHECK(!exceptionState.hadException());
287 309
288 return createEffectModelFromKeyframes(element, keyframes, exceptionState); 310 return createEffectModelFromKeyframes(element, keyframes, exceptionState);
289 } 311 }
290 312
291 } // namespace blink 313 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/EffectInput.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698