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

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

Issue 190763007: [WIP] Web Animations API: Constructing an Animation from partial keyframes throws a JS exception (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add FIXME for keyframes at 0 and 1. Created 6 years, 9 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 | « Source/core/animation/EffectInput.h ('k') | Source/core/animation/ElementAnimation.h » ('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 30 matching lines...) Expand all
41 namespace WebCore { 41 namespace WebCore {
42 42
43 static bool checkDocumentAndRenderer(Element* element) 43 static bool checkDocumentAndRenderer(Element* element)
44 { 44 {
45 if (!element->inActiveDocument()) 45 if (!element->inActiveDocument())
46 return false; 46 return false;
47 element->document().updateStyleIfNeeded(); 47 element->document().updateStyleIfNeeded();
48 return element->renderer(); 48 return element->renderer();
49 } 49 }
50 50
51 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, bool unsafe) 51 static bool hasMismatchedKeyframeProperty(Vector<RefPtr<MutableStylePropertySet> > propertySetVector)
dstockwell 2014/03/11 03:28:14 Instead of doing the checks here, we might be able
52 {
53 HashCountedSet<CSSPropertyID> counter;
54 for (size_t i = 0; i < propertySetVector.size(); ++i) {
55 for (size_t j = 0; j < propertySetVector[i]->propertyCount(); ++j) {
56 CSSPropertyID property = propertySetVector[i]->propertyAt(j).id();
57 counter.add(property);
58 }
59 }
60 for (HashCountedSet<CSSPropertyID>::iterator iterator = counter.begin(); ite rator != counter.end(); ++iterator) {
61 if (iterator->value == 1)
62 return true;
63 }
64 return false;
65 }
66
67 PassRefPtrWillBeRawPtr<AnimationEffect> EffectInput::convert(Element* element, c onst Vector<Dictionary>& keyframeDictionaryVector, ExceptionState& exceptionSta te, bool unsafe)
52 { 68 {
53 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at 69 // FIXME: This test will not be neccessary once resolution of keyframe value s occurs at
54 // animation application time. 70 // animation application time.
55 if (!unsafe && !checkDocumentAndRenderer(element)) 71 if (!unsafe && !checkDocumentAndRenderer(element))
56 return nullptr; 72 return nullptr;
57 73
58 // FIXME: Move this code into KeyframeEffectModel, it will be used by the ID L constructor for that class. 74 // FIXME: Move this code into KeyframeEffectModel, it will be used by the ID L constructor for that class.
59 KeyframeEffectModel::KeyframeVector keyframes; 75 KeyframeEffectModel::KeyframeVector keyframes;
60 Vector<RefPtr<MutableStylePropertySet> > propertySetVector; 76 Vector<RefPtr<MutableStylePropertySet> > propertySetVector;
77 bool hasOffsets = false;
78 bool hasOffsetZero = false;
79 bool hasOffsetOne = false;
61 80
62 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) { 81 for (size_t i = 0; i < keyframeDictionaryVector.size(); ++i) {
63 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate(); 82 RefPtr<MutableStylePropertySet> propertySet = MutableStylePropertySet::c reate();
64 propertySetVector.append(propertySet); 83 propertySetVector.append(propertySet);
65 84
66 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create(); 85 RefPtrWillBeRawPtr<Keyframe> keyframe = Keyframe::create();
67 keyframes.append(keyframe); 86 keyframes.append(keyframe);
68 87
69 double offset; 88 double offset;
70 if (keyframeDictionaryVector[i].get("offset", offset)) 89 if (keyframeDictionaryVector[i].get("offset", offset)) {
71 keyframe->setOffset(offset); 90 keyframe->setOffset(offset);
91 hasOffsets = true;
92 if (!offset)
93 hasOffsetZero = true;
94 if (offset == 1)
95 hasOffsetOne = true;
96 }
72 97
73 String compositeString; 98 String compositeString;
74 keyframeDictionaryVector[i].get("composite", compositeString); 99 keyframeDictionaryVector[i].get("composite", compositeString);
75 if (compositeString == "add") 100 if (compositeString == "add")
76 keyframe->setComposite(AnimationEffect::CompositeAdd); 101 keyframe->setComposite(AnimationEffect::CompositeAdd);
77 102
78 String timingFunctionString; 103 String timingFunctionString;
79 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) { 104 if (keyframeDictionaryVector[i].get("easing", timingFunctionString)) {
80 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString); 105 RefPtrWillBeRawPtr<CSSValue> timingFunctionValue = BisonCSSParser::p arseAnimationTimingFunctionValue(timingFunctionString);
81 if (timingFunctionValue) 106 if (timingFunctionValue)
(...skipping 14 matching lines...) Expand all
96 // KeyframeEffectModel, store input keyframes and implement getFrame s. 121 // KeyframeEffectModel, store input keyframes and implement getFrame s.
97 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id)) 122 if (id == CSSPropertyInvalid || !CSSAnimations::isAnimatableProperty (id))
98 continue; 123 continue;
99 124
100 String value; 125 String value;
101 keyframeDictionaryVector[i].get(property, value); 126 keyframeDictionaryVector[i].get(property, value);
102 propertySet->setProperty(id, value); 127 propertySet->setProperty(id, value);
103 } 128 }
104 } 129 }
105 130
131 // FIXME: Web Animations can't yet handle keyframe sets where a property app ears in only one keyframe (called "partial keyframes").
132 // This check can be removed once support for such input is added.
133 if (hasMismatchedKeyframeProperty(propertySetVector))
134 exceptionState.throwDOMException(NotSupportedError, "Keyframe effect con tains properties that appear in only one keyframe.");
135 // FIXME: Web Animations can't yet handle keyframe sets which specify offset s and don't specify keyframes at offset: 0 and offset: 1.
136 // These checks can be removed once support for such input is added.
137 if (hasOffsets && !hasOffsetZero)
138 exceptionState.throwDOMException(NotSupportedError, "Keyframes specify o ffsets, but keyframe with offset: 0 is missing.");
139 if (hasOffsets && !hasOffsetOne)
140 exceptionState.throwDOMException(NotSupportedError, "Keyframes specify o ffsets, but keyframe with offset: 1 is missing.");
141
106 // FIXME: Replace this with code that just parses, when that code is availab le. 142 // FIXME: Replace this with code that just parses, when that code is availab le.
107 return StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes); 143 return StyleResolver::createKeyframeEffectModel(*element, propertySetVector, keyframes);
108 } 144 }
109 145
110 } // namespace WebCore 146 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/animation/EffectInput.h ('k') | Source/core/animation/ElementAnimation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698