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

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

Issue 373423002: Split Dictionary's get and convert into DictionaryHelper. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/AnimationTest.cpp ('k') | Source/core/animation/TimingInput.cpp » ('j') | 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 StringKeyframeVector keyframes; 54 StringKeyframeVector keyframes;
55 bool everyFrameHasOffset = true; 55 bool everyFrameHasOffset = true;
56 bool looselySortedByOffset = true; 56 bool looselySortedByOffset = true;
57 double lastOffset = -std::numeric_limits<double>::infinity(); 57 double lastOffset = -std::numeric_limits<double>::infinity();
58 58
59 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { 59 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
60 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create(); 60 RefPtrWillBeRawPtr<StringKeyframe> keyframe = StringKeyframe::create();
61 61
62 bool frameHasOffset = false; 62 bool frameHasOffset = false;
63 double offset; 63 double offset;
64 if (keyframeDictionaryVector[i].get("offset", offset)) { 64 if (DictionaryHelper::get(keyframeDictionaryVector[i], "offset", offset) ) {
65 // Keyframes with offsets outside the range [0.0, 1.0] are ignored. 65 // Keyframes with offsets outside the range [0.0, 1.0] are ignored.
66 if (std::isnan(offset) || offset < 0 || offset > 1) 66 if (std::isnan(offset) || offset < 0 || offset > 1)
67 continue; 67 continue;
68 68
69 frameHasOffset = true; 69 frameHasOffset = true;
70 // The JS value null gets converted to 0 so we need to check whether the original value is null. 70 // The JS value null gets converted to 0 so we need to check whether the original value is null.
71 if (offset == 0) { 71 if (offset == 0) {
72 ScriptValue scriptValue; 72 ScriptValue scriptValue;
73 if (keyframeDictionaryVector[i].get("offset", scriptValue) && sc riptValue.isNull()) 73 if (DictionaryHelper::get(keyframeDictionaryVector[i], "offset", scriptValue) && scriptValue.isNull())
74 frameHasOffset = false; 74 frameHasOffset = false;
75 } 75 }
76 if (frameHasOffset) { 76 if (frameHasOffset) {
77 keyframe->setOffset(offset); 77 keyframe->setOffset(offset);
78 if (offset < lastOffset) 78 if (offset < lastOffset)
79 looselySortedByOffset = false; 79 looselySortedByOffset = false;
80 lastOffset = offset; 80 lastOffset = offset;
81 } 81 }
82 } 82 }
83 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset; 83 everyFrameHasOffset = everyFrameHasOffset && frameHasOffset;
84 84
85 keyframes.append(keyframe); 85 keyframes.append(keyframe);
86 86
87 String compositeString; 87 String compositeString;
88 keyframeDictionaryVector[i].get("composite", compositeString); 88 DictionaryHelper::get(keyframeDictionaryVector[i], "composite", composit eString);
89 if (compositeString == "add") 89 if (compositeString == "add")
90 keyframe->setComposite(AnimationEffect::CompositeAdd); 90 keyframe->setComposite(AnimationEffect::CompositeAdd);
91 91
92 String timingFunctionString; 92 String timingFunctionString;
93 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { 93 if (DictionaryHelper::get(keyframeDictionaryVector[i], "easing", timingF unctionString)) {
94 if (RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParse r::parseAnimationTimingFunctionValue(timingFunctionString)) 94 if (RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParse r::parseAnimationTimingFunctionValue(timingFunctionString))
95 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(ti mingFunctionValue.get(), true)); 95 keyframe->setEasing(CSSToStyleMap::mapAnimationTimingFunction(ti mingFunctionValue.get(), true));
96 } 96 }
97 97
98 Vector<String> keyframeProperties; 98 Vector<String> keyframeProperties;
99 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties); 99 keyframeDictionaryVector[i].getOwnPropertyNames(keyframeProperties);
100 for (size_t j = 0; j < keyframeProperties.size(); ++j) { 100 for (size_t j = 0; j < keyframeProperties.size(); ++j) {
101 String property = keyframeProperties[j]; 101 String property = keyframeProperties[j];
102 CSSPropertyID id = camelCaseCSSPropertyNameToID(property); 102 CSSPropertyID id = camelCaseCSSPropertyNameToID(property);
103 if (id == CSSPropertyInvalid) 103 if (id == CSSPropertyInvalid)
104 continue; 104 continue;
105 String value; 105 String value;
106 keyframeDictionaryVector[i].get(property, value); 106 DictionaryHelper::get(keyframeDictionaryVector[i], property, value);
107 keyframe->setPropertyValue(id, value, styleSheetContents); 107 keyframe->setPropertyValue(id, value, styleSheetContents);
108 } 108 }
109 } 109 }
110 110
111 if (!looselySortedByOffset) { 111 if (!looselySortedByOffset) {
112 if (!everyFrameHasOffset) { 112 if (!everyFrameHasOffset) {
113 exceptionState.throwDOMException(InvalidModificationError, "Keyframe s are not loosely sorted by offset."); 113 exceptionState.throwDOMException(InvalidModificationError, "Keyframe s are not loosely sorted by offset.");
114 return nullptr; 114 return nullptr;
115 } 115 }
116 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs ets); 116 nonCopyingSort(keyframes.begin(), keyframes.end(), Keyframe::compareOffs ets);
117 } 117 }
118 118
119 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes); 119 RefPtrWillBeRawPtr<StringKeyframeEffectModel> keyframeEffectModel = StringKe yframeEffectModel::create(keyframes);
120 if (!keyframeEffectModel->isReplaceOnly()) { 120 if (!keyframeEffectModel->isReplaceOnly()) {
121 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported."); 121 exceptionState.throwDOMException(NotSupportedError, "Partial keyframes a re not supported.");
122 return nullptr; 122 return nullptr;
123 } 123 }
124 keyframeEffectModel->forceConversionsToAnimatableValues(element); 124 keyframeEffectModel->forceConversionsToAnimatableValues(element);
125 125
126 return keyframeEffectModel; 126 return keyframeEffectModel;
127 } 127 }
128 128
129 } // namespace WebCore 129 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationTest.cpp ('k') | Source/core/animation/TimingInput.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698