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

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

Issue 2444363002: binding: Replaces DictionaryHelper::get(ScriptValue) with get(Nullable<T>). (Closed)
Patch Set: Applied git-cl-format. Created 4 years, 1 month 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/bindings/core/v8/DictionaryHelperForCore.cpp ('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 13 matching lines...) Expand all
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 "core/animation/EffectInput.h" 31 #include "core/animation/EffectInput.h"
32 32
33 #include "bindings/core/v8/Dictionary.h" 33 #include "bindings/core/v8/Dictionary.h"
34 #include "bindings/core/v8/DictionaryHelperForBindings.h"
34 #include "bindings/core/v8/DictionarySequenceOrDictionary.h" 35 #include "bindings/core/v8/DictionarySequenceOrDictionary.h"
35 #include "core/animation/AnimationInputHelpers.h" 36 #include "core/animation/AnimationInputHelpers.h"
36 #include "core/animation/CompositorAnimations.h" 37 #include "core/animation/CompositorAnimations.h"
37 #include "core/animation/KeyframeEffectModel.h" 38 #include "core/animation/KeyframeEffectModel.h"
38 #include "core/animation/StringKeyframe.h" 39 #include "core/animation/StringKeyframe.h"
39 #include "core/css/CSSStyleSheet.h" 40 #include "core/css/CSSStyleSheet.h"
40 #include "core/dom/Document.h" 41 #include "core/dom/Document.h"
41 #include "core/dom/Element.h" 42 #include "core/dom/Element.h"
42 #include "core/dom/ExceptionCode.h" 43 #include "core/dom/ExceptionCode.h"
43 #include "core/dom/NodeComputedStyle.h" 44 #include "core/dom/NodeComputedStyle.h"
44 #include "wtf/ASCIICType.h" 45 #include "wtf/ASCIICType.h"
45 #include "wtf/HashSet.h" 46 #include "wtf/HashSet.h"
46 #include "wtf/NonCopyingSort.h" 47 #include "wtf/NonCopyingSort.h"
47 48
48 namespace blink { 49 namespace blink {
49 50
50 namespace { 51 namespace {
51 52
52 bool compareKeyframes(const RefPtr<StringKeyframe>& a, 53 bool compareKeyframes(const RefPtr<StringKeyframe>& a,
53 const RefPtr<StringKeyframe>& b) { 54 const RefPtr<StringKeyframe>& b) {
54 return a->offset() < b->offset(); 55 return a->offset() < b->offset();
55 } 56 }
56 57
57 // Gets offset value from keyframeDictionary and returns false if this value was 58 // Validates the value of |offset| and throws an exception if out of range.
58 // invalid. 59 bool checkOffset(double offset,
59 bool getAndCheckOffset(const Dictionary& keyframeDictionary, 60 double lastOffset,
60 double& offset, 61 ExceptionState& exceptionState) {
61 double lastOffset,
62 ExceptionState& exceptionState) {
63 DictionaryHelper::get(keyframeDictionary, "offset", offset);
64
65 // Keyframes with offsets outside the range [0.0, 1.0] are an error. 62 // Keyframes with offsets outside the range [0.0, 1.0] are an error.
66 if (std::isnan(offset)) { 63 if (std::isnan(offset)) {
67 exceptionState.throwTypeError("Non numeric offset provided"); 64 exceptionState.throwTypeError("Non numeric offset provided");
68 return false; 65 return false;
69 } 66 }
70 67
71 if (offset < 0 || offset > 1) { 68 if (offset < 0 || offset > 1) {
72 exceptionState.throwTypeError("Offsets provided outside the range [0, 1]"); 69 exceptionState.throwTypeError("Offsets provided outside the range [0, 1]");
73 return false; 70 return false;
74 } 71 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EffectModel* EffectInput::convertArrayForm( 191 EffectModel* EffectInput::convertArrayForm(
195 Element& element, 192 Element& element,
196 const Vector<Dictionary>& keyframeDictionaries, 193 const Vector<Dictionary>& keyframeDictionaries,
197 ExceptionState& exceptionState) { 194 ExceptionState& exceptionState) {
198 StringKeyframeVector keyframes; 195 StringKeyframeVector keyframes;
199 double lastOffset = 0; 196 double lastOffset = 0;
200 197
201 for (const Dictionary& keyframeDictionary : keyframeDictionaries) { 198 for (const Dictionary& keyframeDictionary : keyframeDictionaries) {
202 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); 199 RefPtr<StringKeyframe> keyframe = StringKeyframe::create();
203 200
204 ScriptValue scriptValue; 201 Nullable<double> offset;
205 bool frameHasOffset = 202 if (DictionaryHelper::get(keyframeDictionary, "offset", offset) &&
206 DictionaryHelper::get(keyframeDictionary, "offset", scriptValue) && 203 !offset.isNull()) {
207 !scriptValue.isNull(); 204 if (!checkOffset(offset.get(), lastOffset, exceptionState))
205 return nullptr;
208 206
209 double offset = 0.0; 207 lastOffset = offset.get();
210 if (frameHasOffset) { 208 keyframe->setOffset(offset.get());
211 if (!getAndCheckOffset(keyframeDictionary, offset, lastOffset,
212 exceptionState))
213 return nullptr;
214 lastOffset = offset;
215 keyframe->setOffset(offset);
216 } 209 }
217 210
218 String compositeString; 211 String compositeString;
219 DictionaryHelper::get(keyframeDictionary, "composite", compositeString); 212 DictionaryHelper::get(keyframeDictionary, "composite", compositeString);
220 if (compositeString == "add") 213 if (compositeString == "add")
221 keyframe->setComposite(EffectModel::CompositeAdd); 214 keyframe->setComposite(EffectModel::CompositeAdd);
222 // TODO(alancutter): Support "accumulate" keyframe composition. 215 // TODO(alancutter): Support "accumulate" keyframe composition.
223 216
224 String timingFunctionString; 217 String timingFunctionString;
225 if (DictionaryHelper::get(keyframeDictionary, "easing", 218 if (DictionaryHelper::get(keyframeDictionary, "easing",
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 String timingFunctionString; 306 String timingFunctionString;
314 RefPtr<TimingFunction> timingFunction = nullptr; 307 RefPtr<TimingFunction> timingFunction = nullptr;
315 if (DictionaryHelper::get(keyframeDictionary, "easing", 308 if (DictionaryHelper::get(keyframeDictionary, "easing",
316 timingFunctionString)) { 309 timingFunctionString)) {
317 timingFunction = AnimationInputHelpers::parseTimingFunction( 310 timingFunction = AnimationInputHelpers::parseTimingFunction(
318 timingFunctionString, &element.document(), exceptionState); 311 timingFunctionString, &element.document(), exceptionState);
319 if (!timingFunction) 312 if (!timingFunction)
320 return nullptr; 313 return nullptr;
321 } 314 }
322 315
323 ScriptValue scriptValue; 316 Nullable<double> offset;
324 bool frameHasOffset = 317 if (DictionaryHelper::get(keyframeDictionary, "offset", offset) &&
325 DictionaryHelper::get(keyframeDictionary, "offset", scriptValue) && 318 !offset.isNull()) {
326 !scriptValue.isNull(); 319 if (!checkOffset(offset.get(), 0.0, exceptionState))
327 double offset = 0.0; 320 return nullptr;
328 if (frameHasOffset && 321 }
329 !getAndCheckOffset(keyframeDictionary, offset, 0.0, exceptionState))
330 return nullptr;
331 322
332 String compositeString; 323 String compositeString;
333 DictionaryHelper::get(keyframeDictionary, "composite", compositeString); 324 DictionaryHelper::get(keyframeDictionary, "composite", compositeString);
334 325
335 Vector<String> keyframeProperties; 326 Vector<String> keyframeProperties;
336 keyframeDictionary.getPropertyNames(keyframeProperties); 327 keyframeDictionary.getPropertyNames(keyframeProperties);
337 for (const auto& property : keyframeProperties) { 328 for (const auto& property : keyframeProperties) {
338 if (property == "offset" || property == "composite" || 329 if (property == "offset" || property == "composite" ||
339 property == "easing") { 330 property == "easing") {
340 continue; 331 continue;
341 } 332 }
342 333
343 Vector<String> values; 334 Vector<String> values;
344 if (!getPropertyIndexedKeyframeValues(keyframeDictionary, property, 335 if (!getPropertyIndexedKeyframeValues(keyframeDictionary, property,
345 executionContext, exceptionState, 336 executionContext, exceptionState,
346 values)) 337 values))
347 return nullptr; 338 return nullptr;
348 339
349 size_t numKeyframes = values.size(); 340 size_t numKeyframes = values.size();
350 for (size_t i = 0; i < numKeyframes; ++i) { 341 for (size_t i = 0; i < numKeyframes; ++i) {
351 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); 342 RefPtr<StringKeyframe> keyframe = StringKeyframe::create();
352 343
353 if (frameHasOffset) 344 if (!offset.isNull())
354 keyframe->setOffset(offset); 345 keyframe->setOffset(offset.get());
355 else if (numKeyframes == 1) 346 else if (numKeyframes == 1)
356 keyframe->setOffset(1.0); 347 keyframe->setOffset(1.0);
357 else 348 else
358 keyframe->setOffset(i / (numKeyframes - 1.0)); 349 keyframe->setOffset(i / (numKeyframes - 1.0));
359 350
360 if (timingFunction) 351 if (timingFunction)
361 keyframe->setEasing(timingFunction); 352 keyframe->setEasing(timingFunction);
362 353
363 if (compositeString == "add") 354 if (compositeString == "add")
364 keyframe->setComposite(EffectModel::CompositeAdd); 355 keyframe->setComposite(EffectModel::CompositeAdd);
365 // TODO(alancutter): Support "accumulate" keyframe composition. 356 // TODO(alancutter): Support "accumulate" keyframe composition.
366 357
367 setKeyframeValue(element, *keyframe.get(), property, values[i]); 358 setKeyframeValue(element, *keyframe.get(), property, values[i]);
368 keyframes.append(keyframe); 359 keyframes.append(keyframe);
369 } 360 }
370 } 361 }
371 362
372 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); 363 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes);
373 364
374 DCHECK(!exceptionState.hadException()); 365 DCHECK(!exceptionState.hadException());
375 366
376 return createEffectModelFromKeyframes(element, keyframes, exceptionState); 367 return createEffectModelFromKeyframes(element, keyframes, exceptionState);
377 } 368 }
378 369
379 } // namespace blink 370 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/DictionaryHelperForCore.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698