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

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

Issue 2524303002: Emit console warning when element.animate() keyframe value fails to parse (Closed)
Patch Set: Review changes Created 4 years 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
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 24 matching lines...) Expand all
35 #include "bindings/core/v8/DictionarySequenceOrDictionary.h" 35 #include "bindings/core/v8/DictionarySequenceOrDictionary.h"
36 #include "core/animation/AnimationInputHelpers.h" 36 #include "core/animation/AnimationInputHelpers.h"
37 #include "core/animation/CompositorAnimations.h" 37 #include "core/animation/CompositorAnimations.h"
38 #include "core/animation/KeyframeEffectModel.h" 38 #include "core/animation/KeyframeEffectModel.h"
39 #include "core/animation/StringKeyframe.h" 39 #include "core/animation/StringKeyframe.h"
40 #include "core/css/CSSStyleSheet.h" 40 #include "core/css/CSSStyleSheet.h"
41 #include "core/dom/Document.h" 41 #include "core/dom/Document.h"
42 #include "core/dom/Element.h" 42 #include "core/dom/Element.h"
43 #include "core/dom/ExceptionCode.h" 43 #include "core/dom/ExceptionCode.h"
44 #include "core/dom/NodeComputedStyle.h" 44 #include "core/dom/NodeComputedStyle.h"
45 #include "core/frame/FrameConsole.h"
46 #include "core/frame/LocalFrame.h"
47 #include "core/inspector/ConsoleMessage.h"
45 #include "wtf/ASCIICType.h" 48 #include "wtf/ASCIICType.h"
46 #include "wtf/HashSet.h" 49 #include "wtf/HashSet.h"
47 #include "wtf/NonCopyingSort.h" 50 #include "wtf/NonCopyingSort.h"
48 51
49 namespace blink { 52 namespace blink {
50 53
51 namespace { 54 namespace {
52 55
53 bool compareKeyframes(const RefPtr<StringKeyframe>& a, 56 bool compareKeyframes(const RefPtr<StringKeyframe>& a,
54 const RefPtr<StringKeyframe>& b) { 57 const RefPtr<StringKeyframe>& b) {
(...skipping 20 matching lines...) Expand all
75 "Keyframes with specified offsets are not sorted"); 78 "Keyframes with specified offsets are not sorted");
76 return false; 79 return false;
77 } 80 }
78 81
79 return true; 82 return true;
80 } 83 }
81 84
82 void setKeyframeValue(Element& element, 85 void setKeyframeValue(Element& element,
83 StringKeyframe& keyframe, 86 StringKeyframe& keyframe,
84 const String& property, 87 const String& property,
85 const String& value) { 88 const String& value,
89 ExecutionContext* executionContext) {
86 StyleSheetContents* styleSheetContents = 90 StyleSheetContents* styleSheetContents =
87 element.document().elementSheet().contents(); 91 element.document().elementSheet().contents();
88 CSSPropertyID cssProperty = 92 CSSPropertyID cssProperty =
89 AnimationInputHelpers::keyframeAttributeToCSSProperty(property, 93 AnimationInputHelpers::keyframeAttributeToCSSProperty(property,
90 element.document()); 94 element.document());
91 if (cssProperty != CSSPropertyInvalid) { 95 if (cssProperty != CSSPropertyInvalid) {
92 if (cssProperty == CSSPropertyVariable) 96 MutableStylePropertySet::SetResult setResult =
93 keyframe.setCSSPropertyValue(AtomicString(property), value, 97 cssProperty == CSSPropertyVariable
94 styleSheetContents); 98 ? keyframe.setCSSPropertyValue(AtomicString(property), value,
95 else 99 styleSheetContents)
96 keyframe.setCSSPropertyValue(cssProperty, value, styleSheetContents); 100 : keyframe.setCSSPropertyValue(cssProperty, value,
101 styleSheetContents);
102 if (!setResult.didParse && executionContext) {
103 Document& document = toDocument(*executionContext);
104 if (document.frame()) {
105 document.frame()->console().addMessage(ConsoleMessage::create(
106 JSMessageSource, WarningMessageLevel,
107 "Invalid keyframe value for property " + property + ": " + value));
108 }
109 }
97 return; 110 return;
98 } 111 }
99 cssProperty = AnimationInputHelpers::keyframeAttributeToPresentationAttribute( 112 cssProperty = AnimationInputHelpers::keyframeAttributeToPresentationAttribute(
100 property, element); 113 property, element);
101 if (cssProperty != CSSPropertyInvalid) { 114 if (cssProperty != CSSPropertyInvalid) {
102 keyframe.setPresentationAttributeValue(cssProperty, value, 115 keyframe.setPresentationAttributeValue(cssProperty, value,
103 styleSheetContents); 116 styleSheetContents);
104 return; 117 return;
105 } 118 }
106 const QualifiedName* svgAttribute = 119 const QualifiedName* svgAttribute =
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 174
162 // Spec: http://w3c.github.io/web-animations/#processing-a-keyframes-argument 175 // Spec: http://w3c.github.io/web-animations/#processing-a-keyframes-argument
163 EffectModel* EffectInput::convert( 176 EffectModel* EffectInput::convert(
164 Element* element, 177 Element* element,
165 const DictionarySequenceOrDictionary& effectInput, 178 const DictionarySequenceOrDictionary& effectInput,
166 ExecutionContext* executionContext, 179 ExecutionContext* executionContext,
167 ExceptionState& exceptionState) { 180 ExceptionState& exceptionState) {
168 if (effectInput.isNull() || !element) 181 if (effectInput.isNull() || !element)
169 return nullptr; 182 return nullptr;
170 183
171 if (effectInput.isDictionarySequence()) 184 if (effectInput.isDictionarySequence()) {
172 return convertArrayForm(*element, effectInput.getAsDictionarySequence(), 185 return convertArrayForm(*element, effectInput.getAsDictionarySequence(),
173 exceptionState); 186 executionContext, exceptionState);
187 }
174 188
175 const Dictionary& dictionary = effectInput.getAsDictionary(); 189 const Dictionary& dictionary = effectInput.getAsDictionary();
176 DictionaryIterator iterator = dictionary.getIterator(executionContext); 190 DictionaryIterator iterator = dictionary.getIterator(executionContext);
177 if (!iterator.isNull()) { 191 if (!iterator.isNull()) {
178 // TODO(alancutter): Convert keyframes during iteration rather than after to 192 // TODO(alancutter): Convert keyframes during iteration rather than after to
179 // match spec. 193 // match spec.
180 Vector<Dictionary> keyframeDictionaries; 194 Vector<Dictionary> keyframeDictionaries;
181 if (exhaustDictionaryIterator(iterator, executionContext, exceptionState, 195 if (exhaustDictionaryIterator(iterator, executionContext, exceptionState,
182 keyframeDictionaries)) 196 keyframeDictionaries)) {
183 return convertArrayForm(*element, keyframeDictionaries, exceptionState); 197 return convertArrayForm(*element, keyframeDictionaries, executionContext,
198 exceptionState);
199 }
184 return nullptr; 200 return nullptr;
185 } 201 }
186 202
187 return convertObjectForm(*element, dictionary, executionContext, 203 return convertObjectForm(*element, dictionary, executionContext,
188 exceptionState); 204 exceptionState);
189 } 205 }
190 206
191 EffectModel* EffectInput::convertArrayForm( 207 EffectModel* EffectInput::convertArrayForm(
192 Element& element, 208 Element& element,
193 const Vector<Dictionary>& keyframeDictionaries, 209 const Vector<Dictionary>& keyframeDictionaries,
210 ExecutionContext* executionContext,
194 ExceptionState& exceptionState) { 211 ExceptionState& exceptionState) {
195 StringKeyframeVector keyframes; 212 StringKeyframeVector keyframes;
196 double lastOffset = 0; 213 double lastOffset = 0;
197 214
198 for (const Dictionary& keyframeDictionary : keyframeDictionaries) { 215 for (const Dictionary& keyframeDictionary : keyframeDictionaries) {
199 RefPtr<StringKeyframe> keyframe = StringKeyframe::create(); 216 RefPtr<StringKeyframe> keyframe = StringKeyframe::create();
200 217
201 Nullable<double> offset; 218 Nullable<double> offset;
202 if (DictionaryHelper::get(keyframeDictionary, "offset", offset) && 219 if (DictionaryHelper::get(keyframeDictionary, "offset", offset) &&
203 !offset.isNull()) { 220 !offset.isNull()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 Vector<String> values; 253 Vector<String> values;
237 if (DictionaryHelper::get(keyframeDictionary, property, values)) { 254 if (DictionaryHelper::get(keyframeDictionary, property, values)) {
238 exceptionState.throwTypeError( 255 exceptionState.throwTypeError(
239 "Lists of values not permitted in array-form list of keyframes"); 256 "Lists of values not permitted in array-form list of keyframes");
240 return nullptr; 257 return nullptr;
241 } 258 }
242 259
243 String value; 260 String value;
244 DictionaryHelper::get(keyframeDictionary, property, value); 261 DictionaryHelper::get(keyframeDictionary, property, value);
245 262
246 setKeyframeValue(element, *keyframe.get(), property, value); 263 setKeyframeValue(element, *keyframe.get(), property, value,
264 executionContext);
247 } 265 }
248 keyframes.append(keyframe); 266 keyframes.append(keyframe);
249 } 267 }
250 268
251 DCHECK(!exceptionState.hadException()); 269 DCHECK(!exceptionState.hadException());
252 270
253 return createEffectModelFromKeyframes(element, keyframes, exceptionState); 271 return createEffectModelFromKeyframes(element, keyframes, exceptionState);
254 } 272 }
255 273
256 static bool getPropertyIndexedKeyframeValues( 274 static bool getPropertyIndexedKeyframeValues(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 else 366 else
349 keyframe->setOffset(i / (numKeyframes - 1.0)); 367 keyframe->setOffset(i / (numKeyframes - 1.0));
350 368
351 if (timingFunction) 369 if (timingFunction)
352 keyframe->setEasing(timingFunction); 370 keyframe->setEasing(timingFunction);
353 371
354 if (compositeString == "add") 372 if (compositeString == "add")
355 keyframe->setComposite(EffectModel::CompositeAdd); 373 keyframe->setComposite(EffectModel::CompositeAdd);
356 // TODO(alancutter): Support "accumulate" keyframe composition. 374 // TODO(alancutter): Support "accumulate" keyframe composition.
357 375
358 setKeyframeValue(element, *keyframe.get(), property, values[i]); 376 setKeyframeValue(element, *keyframe.get(), property, values[i],
377 executionContext);
359 keyframes.append(keyframe); 378 keyframes.append(keyframe);
360 } 379 }
361 } 380 }
362 381
363 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes); 382 std::sort(keyframes.begin(), keyframes.end(), compareKeyframes);
364 383
365 DCHECK(!exceptionState.hadException()); 384 DCHECK(!exceptionState.hadException());
366 385
367 return createEffectModelFromKeyframes(element, keyframes, exceptionState); 386 return createEffectModelFromKeyframes(element, keyframes, exceptionState);
368 } 387 }
369 388
370 } // namespace blink 389 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/EffectInput.h ('k') | third_party/WebKit/Source/core/animation/StringKeyframe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698