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

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: Apply all of Alan and Doug's changes 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 , m_value(value) 68 , m_value(value)
69 { } 69 { }
70 70
71 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value) 71 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset , PassRefPtr<TimingFunction> easing, CSSValue* value)
72 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) 72 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace)
73 , m_value(value) 73 , m_value(value)
74 { 74 {
75 ASSERT(!isNull(m_offset)); 75 ASSERT(!isNull(m_offset));
76 } 76 }
77 77
78 namespace {
79 void setRange(InterpolationRange* range, InterpolationRange setTo)
alancutter (OOO until 2018) 2015/02/06 07:26:12 This should be a reference.
dstockwell 2015/02/06 10:44:47 This is not what I meant. Instead I was suggesting
jadeg 2015/02/09 00:07:13 Done.
80 {
81 if (*range == RangeAll)
82 *range = setTo;
83 }
84
85 } // namespace
86
78 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect, and a template parameter specific converter. 87 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect, and a template parameter specific converter.
79 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr ame& end, Element* element) const 88 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr ame& end, Element* element) const
80 { 89 {
81 CSSValue* fromCSSValue = m_value.get(); 90 CSSValue* fromCSSValue = m_value.get();
82 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); 91 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value();
83 InterpolationRange range = RangeAll; 92 InterpolationRange range = RangeAll;
84 bool fallBackToLegacy = false; 93 bool fallBackToLegacy = false;
85 94
86 if (!CSSPropertyMetadata::isAnimatableProperty(property)) { 95 if (!CSSPropertyMetadata::isAnimatableProperty(property)) {
87 // FIXME: Remove this once TimingFunction partitioning is implemented fo r all types. 96 // FIXME: Remove this once TimingFunction partitioning is implemented fo r all types.
88 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningE nabled()) 97 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningE nabled())
89 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, p roperty); 98 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, p roperty);
90 99
91 if (fromCSSValue == toCSSValue) 100 if (fromCSSValue == toCSSValue)
92 return ConstantStyleInterpolation::create(fromCSSValue, property); 101 return ConstantStyleInterpolation::create(fromCSSValue, property);
93 102
94 return nullptr; 103 return nullptr;
95 } 104 }
96 105
97 // FIXME: Generate this giant switch statement. 106 // FIXME: Generate this giant switch statement.
98 switch (property) { 107 switch (property) {
99 case CSSPropertyLineHeight: 108 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)) 109 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue))
104 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); 110 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative);
105 111 // Fall through
106 break;
107 case CSSPropertyBorderBottomWidth: 112 case CSSPropertyBorderBottomWidth:
108 case CSSPropertyBorderLeftWidth: 113 case CSSPropertyBorderLeftWidth:
109 case CSSPropertyBorderRightWidth: 114 case CSSPropertyBorderRightWidth:
110 case CSSPropertyBorderTopWidth: 115 case CSSPropertyBorderTopWidth:
111 case CSSPropertyFontSize: 116 case CSSPropertyFontSize:
112 case CSSPropertyHeight: 117 case CSSPropertyHeight:
113 case CSSPropertyMaxHeight: 118 case CSSPropertyMaxHeight:
114 case CSSPropertyMaxWidth: 119 case CSSPropertyMaxWidth:
115 case CSSPropertyMinHeight: 120 case CSSPropertyMinHeight:
116 case CSSPropertyMinWidth: 121 case CSSPropertyMinWidth:
(...skipping 19 matching lines...) Expand all
136 case CSSPropertyRight: 141 case CSSPropertyRight:
137 case CSSPropertyTop: 142 case CSSPropertyTop:
138 case CSSPropertyVerticalAlign: 143 case CSSPropertyVerticalAlign:
139 case CSSPropertyWordSpacing: 144 case CSSPropertyWordSpacing:
140 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue)) 145 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue))
141 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range); 146 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range);
142 147
143 // FIXME: Handle keywords e.g. 'none'. 148 // FIXME: Handle keywords e.g. 'none'.
144 if (property == CSSPropertyPerspective) 149 if (property == CSSPropertyPerspective)
145 fallBackToLegacy = true; 150 fallBackToLegacy = true;
146
147 // FIXME: Handle keywords e.g. 'smaller', 'larger'. 151 // FIXME: Handle keywords e.g. 'smaller', 'larger'.
148 if (property == CSSPropertyFontSize) 152 if (property == CSSPropertyFontSize)
149 fallBackToLegacy = true; 153 fallBackToLegacy = true;
150 154
151 // FIXME: Handle keywords e.g. 'normal' 155 // FIXME: Handle keywords e.g. 'normal'
152 if (property == CSSPropertyLetterSpacing) 156 if (property == CSSPropertyLetterSpacing)
153 fallBackToLegacy = true; 157 fallBackToLegacy = true;
154 158
155 // FIXME: Handle keywords e.g. 'thick' 159 // FIXME: Handle keywords e.g. 'thick'
156 if (property == CSSPropertyOutlineWidth) 160 if (property == CSSPropertyOutlineWidth)
157 fallBackToLegacy = true; 161 fallBackToLegacy = true;
162 break;
163 case CSSPropertyFlexGrow:
164 case CSSPropertyFlexShrink:
165 setRange(&range, RangeNonNegative);
166 // Fall through
167 case CSSPropertyWidows:
168 case CSSPropertyOrphans:
169 case CSSPropertyZIndex:
170 setRange(&range, RangeRound);
171 // Fall through
172 case CSSPropertyWebkitColumnCount:
173 setRange(&range, RangeFloor);
dstockwell 2015/02/06 10:44:48 RangeFloor seems wrong, in AnimatedStyleBuilder.cp
jadeg 2015/02/09 00:07:13 Done.
174 // Fall through
175 case CSSPropertyShapeImageThreshold:
176 setRange(&range, RangeZeroToOne);
177 // Fall through
178 case CSSPropertyFillOpacity:
dstockwell 2015/02/06 10:44:48 Flood/Stop/Stroke should be ZeroToOne (as in Anima
jadeg 2015/02/09 00:07:13 Done.
179 case CSSPropertyFloodOpacity:
180 case CSSPropertyOpacity:
181 case CSSPropertyStopOpacity:
182 case CSSPropertyStrokeOpacity:
183 setRange(&range, RangeZeroToLessThanOne);
184 // Fall through
185 case CSSPropertyStrokeMiterlimit:
186 setRange(&range, RangeGreaterThanOrEqualToOne);
187 // Fall through
188 case CSSPropertyZoom:
189 setRange(&range, RangePositive);
190 // Fall through
191 case CSSPropertyWebkitColumnRuleWidth:
dstockwell 2015/02/06 10:44:47 CSSPropertyColumnRuleWidth should be rounded (as i
jadeg 2015/02/09 00:07:13 Done.
192 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue)) {
193 if (property == CSSPropertyOpacity)
194 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueC aches(property, end, element, *fromCSSValue, *toCSSValue);
195 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, toCSSPrimitiveValue(fromCSSValue)->primitiveType(), range);
196 }
197 break;
158 198
159 break; 199 case CSSPropertyMotionRotation: {
160 case CSSPropertyMotionRotation: 200 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpolati on::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property);
161 { 201 if (interpolation)
162 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpo lation::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); 202 return interpolation.release();
163 if (interpolation)
164 return interpolation.release();
165
166 break; 203 break;
167 } 204 }
168 case CSSPropertyVisibility: 205 case CSSPropertyVisibility:
169 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue))) 206 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue)))
170 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property); 207 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property);
171 208
172 break; 209 break;
173 210
174 case CSSPropertyBackgroundColor: 211 case CSSPropertyBackgroundColor:
175 case CSSPropertyBorderBottomColor: 212 case CSSPropertyBorderBottomColor:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue() 291 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue()
255 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue()) 292 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue())
256 fallBackToLegacy = true; 293 fallBackToLegacy = true;
257 294
258 if (fallBackToLegacy) { 295 if (fallBackToLegacy) {
259 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) { 296 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) {
260 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion. 297 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion.
261 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property); 298 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property);
262 } 299 }
263 300
264 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. 301 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 302
270 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable ValueSnapshot(*element, property, *toCSSValue); 303 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 } 304 }
275 305
276 ASSERT(AnimatableValue::usesDefaultInterpolation( 306 ASSERT(AnimatableValue::usesDefaultInterpolation(
277 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(), 307 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(),
278 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get())); 308 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get()));
279 309
280
281 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types. 310 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types.
282 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed()) 311 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed())
283 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); 312 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty);
284 313
285 if (fromCSSValue == toCSSValue) 314 if (fromCSSValue == toCSSValue)
286 return ConstantStyleInterpolation::create(fromCSSValue, property); 315 return ConstantStyleInterpolation::create(fromCSSValue, property);
287 316
288 return nullptr; 317 return nullptr;
289 318
290 } 319 }
291 320
321 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
322 // FIXME: Remove this cache
323 void StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(CSSPr opertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element, CS SValue& fromCSSValue, CSSValue& toCSSValue) const
324 {
325 ASSERT(element);
326 if (!m_animatableValueCache)
327 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e lement, property, fromCSSValue);
328 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu eSnapshot(*element, property, toCSSValue);
329 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to;
330 }
331
332
292 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const 333 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const
293 { 334 {
294 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd)); 335 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd));
295 } 336 }
296 337
297 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const 338 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const
298 { 339 {
299 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); 340 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get());
300 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache; 341 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache;
301 return adoptPtrWillBeNoop(theClone); 342 return adoptPtrWillBeNoop(theClone);
302 } 343 }
303 344
304 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) 345 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor)
305 { 346 {
306 visitor->trace(m_value); 347 visitor->trace(m_value);
307 visitor->trace(m_animatableValueCache); 348 visitor->trace(m_animatableValueCache);
308 Keyframe::PropertySpecificKeyframe::trace(visitor); 349 Keyframe::PropertySpecificKeyframe::trace(visitor);
309 } 350 }
310 351
311 } 352 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698