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

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

Issue 811993002: Animation: Implement DoubleStyleInterpolation in StringKeyframe (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created more layout tests Created 5 years, 10 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/animation/StringKeyframe.h" 6 #include "core/animation/StringKeyframe.h"
7 7
8 #include "core/animation/ColorStyleInterpolation.h" 8 #include "core/animation/ColorStyleInterpolation.h"
9 #include "core/animation/ConstantStyleInterpolation.h" 9 #include "core/animation/ConstantStyleInterpolation.h"
10 #include "core/animation/DefaultStyleInterpolation.h" 10 #include "core/animation/DefaultStyleInterpolation.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 if (fromCSSValue == toCSSValue) 91 if (fromCSSValue == toCSSValue)
92 return ConstantStyleInterpolation::create(fromCSSValue, property); 92 return ConstantStyleInterpolation::create(fromCSSValue, property);
93 93
94 return nullptr; 94 return nullptr;
95 } 95 }
96 96
97 // FIXME: Generate this giant switch statement. 97 // FIXME: Generate this giant switch statement.
98 switch (property) { 98 switch (property) {
99 case CSSPropertyLineHeight: 99 case CSSPropertyLineHeight:
100 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue))
101 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, RangeNonNegative);
102
103 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue)) 100 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue))
104 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); 101 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative);
105 102 // Fall through
106 break;
107 case CSSPropertyBorderBottomWidth: 103 case CSSPropertyBorderBottomWidth:
108 case CSSPropertyBorderLeftWidth: 104 case CSSPropertyBorderLeftWidth:
109 case CSSPropertyBorderRightWidth: 105 case CSSPropertyBorderRightWidth:
110 case CSSPropertyBorderTopWidth: 106 case CSSPropertyBorderTopWidth:
107 case CSSPropertyFlexBasis:
111 case CSSPropertyFontSize: 108 case CSSPropertyFontSize:
112 case CSSPropertyHeight: 109 case CSSPropertyHeight:
113 case CSSPropertyMaxHeight: 110 case CSSPropertyMaxHeight:
114 case CSSPropertyMaxWidth: 111 case CSSPropertyMaxWidth:
115 case CSSPropertyMinHeight: 112 case CSSPropertyMinHeight:
116 case CSSPropertyMinWidth: 113 case CSSPropertyMinWidth:
117 case CSSPropertyMotionPosition: 114 case CSSPropertyMotionPosition:
118 case CSSPropertyOutlineWidth: 115 case CSSPropertyOutlineWidth:
119 case CSSPropertyPaddingBottom: 116 case CSSPropertyPaddingBottom:
120 case CSSPropertyPaddingLeft: 117 case CSSPropertyPaddingLeft:
121 case CSSPropertyPaddingRight: 118 case CSSPropertyPaddingRight:
122 case CSSPropertyPaddingTop: 119 case CSSPropertyPaddingTop:
123 case CSSPropertyPerspective: 120 case CSSPropertyPerspective:
124 case CSSPropertyShapeMargin: 121 case CSSPropertyShapeMargin:
122 case CSSPropertyWebkitBorderHorizontalSpacing:
123 case CSSPropertyWebkitBorderVerticalSpacing:
124 case CSSPropertyWebkitColumnGap:
125 case CSSPropertyWebkitColumnWidth:
alancutter (OOO until 2018) 2015/02/04 20:24:37 Adding more LengthStyleInterpolation handling shou
jadeg 2015/02/05 23:37:03 Done.
125 case CSSPropertyWidth: 126 case CSSPropertyWidth:
126 range = RangeNonNegative; 127 range = RangeNonNegative;
127 // Fall through 128 // Fall through
128 case CSSPropertyBottom: 129 case CSSPropertyBottom:
129 case CSSPropertyLeft: 130 case CSSPropertyLeft:
130 case CSSPropertyLetterSpacing: 131 case CSSPropertyLetterSpacing:
131 case CSSPropertyMarginBottom: 132 case CSSPropertyMarginBottom:
132 case CSSPropertyMarginLeft: 133 case CSSPropertyMarginLeft:
133 case CSSPropertyMarginRight: 134 case CSSPropertyMarginRight:
134 case CSSPropertyMarginTop: 135 case CSSPropertyMarginTop:
135 case CSSPropertyOutlineOffset: 136 case CSSPropertyOutlineOffset:
136 case CSSPropertyRight: 137 case CSSPropertyRight:
137 case CSSPropertyTop: 138 case CSSPropertyTop:
138 case CSSPropertyVerticalAlign: 139 case CSSPropertyVerticalAlign:
139 case CSSPropertyWordSpacing: 140 case CSSPropertyWordSpacing:
140 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue)) 141 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue))
141 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range); 142 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range);
142 143
143 // FIXME: Handle keywords e.g. 'none'. 144 // FIXME: Handle keywords e.g. 'none'.
144 if (property == CSSPropertyPerspective) 145 if (property == CSSPropertyPerspective)
145 fallBackToLegacy = true; 146 fallBackToLegacy = true;
146
147 // FIXME: Handle keywords e.g. 'smaller', 'larger'. 147 // FIXME: Handle keywords e.g. 'smaller', 'larger'.
148 if (property == CSSPropertyFontSize) 148 if (property == CSSPropertyFontSize)
149 fallBackToLegacy = true; 149 fallBackToLegacy = true;
150 150
151 // FIXME: Handle keywords e.g. 'normal' 151 // FIXME: Handle keywords e.g. 'normal'
152 if (property == CSSPropertyLetterSpacing) 152 if (property == CSSPropertyLetterSpacing)
153 fallBackToLegacy = true; 153 fallBackToLegacy = true;
154 154
155 // FIXME: Handle keywords e.g. 'thick' 155 // FIXME: Handle keywords e.g. 'thick'
156 if (property == CSSPropertyOutlineWidth) 156 if (property == CSSPropertyOutlineWidth)
157 fallBackToLegacy = true; 157 fallBackToLegacy = true;
158 break;
159 case CSSPropertyWidows:
160 case CSSPropertyOrphans:
161 if (range == RangeAll)
162 range = RangeRound;
163 // Fall through
164 case CSSPropertyWebkitColumnCount:
165 if (range == RangeAll)
dstockwell 2015/02/04 11:09:28 This fall through logic is a bit complicated, perh
jadeg 2015/02/05 23:37:03 Done.
166 range = RangeFloor;
dstockwell 2015/02/04 11:09:28 AnimatedStyleBuilder rounds and then clamps greate
jadeg 2015/02/05 23:37:03 Im confused if you mean that I should change the n
167 // Fall through
168 case CSSPropertyZIndex:
169 if (range == RangeAll)
170 range = RangeAbsoluteValueFloor;
171 // Fall through
172 case CSSPropertyShapeImageThreshold:
alancutter (OOO until 2018) 2015/02/04 20:24:37 This should clamp to [0, 1] instead of [0, 1).
jadeg 2015/02/05 23:37:03 Done.
173 case CSSPropertyFillOpacity:
174 case CSSPropertyFloodOpacity:
175 case CSSPropertyOpacity:
176 case CSSPropertyStopOpacity:
177 case CSSPropertyStrokeOpacity:
178 if (range == RangeAll)
179 range = RangeFractions;
dstockwell 2015/02/04 11:09:28 This seems different to AnimatedStyleBuidler. The
jadeg 2015/02/05 23:37:03 Yes now has been changed to RangeZeroToLessThanOne
180 // Fall through
181 case CSSPropertyStrokeMiterlimit:
182 if (range == RangeAll)
183 range = RangeGreaterThanOne;
184 // Fall through
185 case CSSPropertyZoom:
186 if (range == RangeAll)
187 range = RangeGreaterThanZero;
188 // Fall through
189 case CSSPropertyWebkitColumnRuleWidth:
190 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue)) {
191 if (property == CSSPropertyOpacity) {
192 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueC aches(property, end, element, fromCSSValue, toCSSValue);
193 }
alancutter (OOO until 2018) 2015/02/04 20:24:37 No need for braces around single line if body.
jadeg 2015/02/05 23:37:03 Done.
194 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, toCSSPrimitiveValue(fromCSSValue)->primitiveType(), range);
195 }
196 break;
197 case CSSPropertyFlexGrow:
Eric Willigers 2015/02/04 06:16:27 Can we use RangeNonNegative for flex-grow and fl
jadeg 2015/02/05 23:37:02 Done.
198 case CSSPropertyFlexShrink:
199 fallBackToLegacy = true;
200 break;
158 201
159 break; 202 case CSSPropertyMotionRotation: {
160 case CSSPropertyMotionRotation: 203 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpolati on::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property);
161 { 204 if (interpolation)
162 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpo lation::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); 205 return interpolation.release();
163 if (interpolation)
164 return interpolation.release();
165
166 break; 206 break;
167 } 207 }
168 case CSSPropertyVisibility: 208 case CSSPropertyVisibility:
169 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue))) 209 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue)))
170 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property); 210 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property);
171 211
172 break; 212 break;
173 213
174 case CSSPropertyBackgroundColor: 214 case CSSPropertyBackgroundColor:
175 case CSSPropertyBorderBottomColor: 215 case CSSPropertyBorderBottomColor:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue() 294 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue()
255 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue()) 295 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue())
256 fallBackToLegacy = true; 296 fallBackToLegacy = true;
257 297
258 if (fallBackToLegacy) { 298 if (fallBackToLegacy) {
259 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) { 299 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) {
260 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion. 300 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion.
261 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property); 301 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property);
262 } 302 }
263 303
264 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. 304 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(pr operty, end, element, fromCSSValue, toCSSValue);
265 // FIXME: Remove this cache
266 ASSERT(element);
267 if (!m_animatableValueCache)
268 m_animatableValueCache = StyleResolver::createAnimatableValueSnapsho t(*element, property, *fromCSSValue);
269 305
270 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable ValueSnapshot(*element, property, *toCSSValue); 306 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to StringPropertySpecificKeyframe(end).m_animatableValueCache.release(), property);
271 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to;
272
273 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to .release(), property);
274 } 307 }
275 308
276 ASSERT(AnimatableValue::usesDefaultInterpolation( 309 ASSERT(AnimatableValue::usesDefaultInterpolation(
277 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(), 310 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(),
278 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get())); 311 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get()));
279 312
280
281 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types. 313 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types.
282 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed()) 314 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed())
283 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); 315 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty);
284 316
285 if (fromCSSValue == toCSSValue) 317 if (fromCSSValue == toCSSValue)
286 return ConstantStyleInterpolation::create(fromCSSValue, property); 318 return ConstantStyleInterpolation::create(fromCSSValue, property);
287 319
288 return nullptr; 320 return nullptr;
289 321
290 } 322 }
291 323
324 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
325 // FIXME: Remove this cache
326 void StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(CSSPr opertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element, CS SValue* fromCSSValue, CSSValue* toCSSValue) const
alancutter (OOO until 2018) 2015/02/04 20:24:37 element, from and to should be references.
jadeg 2015/02/05 23:37:03 Done.
327 {
328 ASSERT(element);
329 if (!m_animatableValueCache)
330 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e lement, property, *fromCSSValue);
331 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu eSnapshot(*element, property, *toCSSValue);
332 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to;
333 }
334
335
292 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const 336 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const
293 { 337 {
294 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd)); 338 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd));
295 } 339 }
296 340
297 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const 341 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const
298 { 342 {
299 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); 343 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get());
300 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache; 344 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache;
301 return adoptPtrWillBeNoop(theClone); 345 return adoptPtrWillBeNoop(theClone);
302 } 346 }
303 347
304 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) 348 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor)
305 { 349 {
306 visitor->trace(m_value); 350 visitor->trace(m_value);
307 visitor->trace(m_animatableValueCache); 351 visitor->trace(m_animatableValueCache);
308 Keyframe::PropertySpecificKeyframe::trace(visitor); 352 Keyframe::PropertySpecificKeyframe::trace(visitor);
309 } 353 }
310 354
311 } 355 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698