| OLD | NEW |
| 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/DeferredLegacyStyleInterpolation.h" | 10 #include "core/animation/DeferredLegacyStyleInterpolation.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 , m_value(value) | 69 , m_value(value) |
| 70 { } | 70 { } |
| 71 | 71 |
| 72 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value) | 72 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value) |
| 73 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos
iteReplace) | 73 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos
iteReplace) |
| 74 , m_value(value) | 74 , m_value(value) |
| 75 { | 75 { |
| 76 ASSERT(!isNull(m_offset)); | 76 ASSERT(!isNull(m_offset)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 namespace { |
| 80 InterpolationRange setRange(CSSPropertyID id) |
| 81 { |
| 82 switch (id) { |
| 83 case CSSPropertyOrphans: |
| 84 case CSSPropertyWebkitColumnCount: |
| 85 case CSSPropertyWidows: |
| 86 return RangeRoundGreaterThanOrEqualToOne; |
| 87 case CSSPropertyWebkitColumnRuleWidth: |
| 88 case CSSPropertyZIndex: |
| 89 return RangeRound; |
| 90 case CSSPropertyFloodOpacity: |
| 91 case CSSPropertyStopOpacity: |
| 92 case CSSPropertyStrokeOpacity: |
| 93 case CSSPropertyShapeImageThreshold: |
| 94 return RangeZeroToOne; |
| 95 case CSSPropertyFillOpacity: |
| 96 case CSSPropertyOpacity: |
| 97 return RangeOpacityFIXME; |
| 98 case CSSPropertyStrokeMiterlimit: |
| 99 return RangeGreaterThanOrEqualToOne; |
| 100 case CSSPropertyZoom: |
| 101 return RangePositive; |
| 102 default: |
| 103 ASSERT_NOT_REACHED(); |
| 104 return RangeAll; |
| 105 } |
| 106 } |
| 107 |
| 108 } // namespace |
| 109 |
| 79 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect,
and a template parameter specific converter. | 110 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect,
and a template parameter specific converter. |
| 80 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr
ame& end, Element* element) const | 111 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr
ame& end, Element* element) const |
| 81 { | 112 { |
| 82 CSSValue* fromCSSValue = m_value.get(); | 113 CSSValue* fromCSSValue = m_value.get(); |
| 83 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); | 114 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); |
| 84 InterpolationRange range = RangeAll; | 115 InterpolationRange range = RangeAll; |
| 85 bool fallBackToLegacy = false; | 116 bool fallBackToLegacy = false; |
| 86 | 117 |
| 87 // FIXME: Remove this flag once we can rely on legacy's behaviour being corr
ect. | 118 // FIXME: Remove this flag once we can rely on legacy's behaviour being corr
ect. |
| 88 bool forceDefaultInterpolation = false; | 119 bool forceDefaultInterpolation = false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 101 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, RangeNonNegative); | 132 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, RangeNonNegative); |
| 102 | 133 |
| 103 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl
eInterpolation::canCreateFrom(*toCSSValue)) | 134 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl
eInterpolation::canCreateFrom(*toCSSValue)) |
| 104 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); | 135 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); |
| 105 | 136 |
| 106 break; | 137 break; |
| 107 case CSSPropertyBorderBottomWidth: | 138 case CSSPropertyBorderBottomWidth: |
| 108 case CSSPropertyBorderLeftWidth: | 139 case CSSPropertyBorderLeftWidth: |
| 109 case CSSPropertyBorderRightWidth: | 140 case CSSPropertyBorderRightWidth: |
| 110 case CSSPropertyBorderTopWidth: | 141 case CSSPropertyBorderTopWidth: |
| 111 case CSSPropertyFlexBasis: | |
| 112 case CSSPropertyFontSize: | 142 case CSSPropertyFontSize: |
| 113 case CSSPropertyHeight: | 143 case CSSPropertyHeight: |
| 114 case CSSPropertyMaxHeight: | 144 case CSSPropertyMaxHeight: |
| 115 case CSSPropertyMaxWidth: | 145 case CSSPropertyMaxWidth: |
| 116 case CSSPropertyMinHeight: | 146 case CSSPropertyMinHeight: |
| 117 case CSSPropertyMinWidth: | 147 case CSSPropertyMinWidth: |
| 118 case CSSPropertyMotionPosition: | 148 case CSSPropertyMotionPosition: |
| 119 case CSSPropertyOutlineWidth: | 149 case CSSPropertyOutlineWidth: |
| 120 case CSSPropertyPaddingBottom: | 150 case CSSPropertyPaddingBottom: |
| 121 case CSSPropertyPaddingLeft: | 151 case CSSPropertyPaddingLeft: |
| 122 case CSSPropertyPaddingRight: | 152 case CSSPropertyPaddingRight: |
| 123 case CSSPropertyPaddingTop: | 153 case CSSPropertyPaddingTop: |
| 124 case CSSPropertyPerspective: | 154 case CSSPropertyPerspective: |
| 125 case CSSPropertyShapeMargin: | 155 case CSSPropertyShapeMargin: |
| 126 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 127 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 128 case CSSPropertyWebkitColumnGap: | |
| 129 case CSSPropertyWebkitColumnWidth: | |
| 130 case CSSPropertyWidth: | 156 case CSSPropertyWidth: |
| 131 range = RangeNonNegative; | 157 range = RangeNonNegative; |
| 132 // Fall through | 158 // Fall through |
| 133 case CSSPropertyBottom: | 159 case CSSPropertyBottom: |
| 134 case CSSPropertyLeft: | 160 case CSSPropertyLeft: |
| 135 case CSSPropertyLetterSpacing: | 161 case CSSPropertyLetterSpacing: |
| 136 case CSSPropertyMarginBottom: | 162 case CSSPropertyMarginBottom: |
| 137 case CSSPropertyMarginLeft: | 163 case CSSPropertyMarginLeft: |
| 138 case CSSPropertyMarginRight: | 164 case CSSPropertyMarginRight: |
| 139 case CSSPropertyMarginTop: | 165 case CSSPropertyMarginTop: |
| 140 case CSSPropertyOutlineOffset: | 166 case CSSPropertyOutlineOffset: |
| 141 case CSSPropertyRight: | 167 case CSSPropertyRight: |
| 142 case CSSPropertyTop: | 168 case CSSPropertyTop: |
| 143 case CSSPropertyVerticalAlign: | 169 case CSSPropertyVerticalAlign: |
| 144 case CSSPropertyWordSpacing: | 170 case CSSPropertyWordSpacing: |
| 145 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) | 171 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) |
| 146 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, range); | 172 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, range); |
| 147 | 173 |
| 148 // FIXME: Handle keywords e.g. 'none'. | 174 // FIXME: Handle keywords e.g. 'none'. |
| 149 if (property == CSSPropertyPerspective) | 175 if (property == CSSPropertyPerspective) |
| 150 fallBackToLegacy = true; | 176 fallBackToLegacy = true; |
| 151 | |
| 152 // FIXME: Handle keywords e.g. 'smaller', 'larger'. | 177 // FIXME: Handle keywords e.g. 'smaller', 'larger'. |
| 153 if (property == CSSPropertyFontSize) | 178 if (property == CSSPropertyFontSize) |
| 154 fallBackToLegacy = true; | 179 fallBackToLegacy = true; |
| 155 | 180 |
| 156 // FIXME: Handle keywords e.g. 'normal' | 181 // FIXME: Handle keywords e.g. 'normal' |
| 157 if (property == CSSPropertyLetterSpacing) | 182 if (property == CSSPropertyLetterSpacing) |
| 158 fallBackToLegacy = true; | 183 fallBackToLegacy = true; |
| 159 | 184 |
| 160 // FIXME: Handle keywords e.g. 'thick' | 185 // FIXME: Handle keywords e.g. 'thick' |
| 161 if (property == CSSPropertyOutlineWidth) | 186 if (property == CSSPropertyOutlineWidth) |
| 162 fallBackToLegacy = true; | 187 fallBackToLegacy = true; |
| 188 break; |
| 189 case CSSPropertyOrphans: |
| 190 case CSSPropertyWidows: |
| 191 case CSSPropertyZIndex: |
| 192 case CSSPropertyWebkitColumnCount: |
| 193 case CSSPropertyShapeImageThreshold: |
| 194 case CSSPropertyFillOpacity: |
| 195 case CSSPropertyFloodOpacity: |
| 196 case CSSPropertyOpacity: |
| 197 case CSSPropertyStopOpacity: |
| 198 case CSSPropertyStrokeOpacity: |
| 199 case CSSPropertyStrokeMiterlimit: |
| 200 case CSSPropertyZoom: |
| 201 case CSSPropertyWebkitColumnRuleWidth: |
| 202 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl
eInterpolation::canCreateFrom(*toCSSValue)) { |
| 203 if (property == CSSPropertyOpacity) |
| 204 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueC
aches(property, end, element, *fromCSSValue, *toCSSValue); |
| 205 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue,
property, toCSSPrimitiveValue(fromCSSValue)->primitiveType(), setRange(property)
); |
| 206 } |
| 207 break; |
| 163 | 208 |
| 164 break; | 209 case CSSPropertyMotionRotation: { |
| 165 case CSSPropertyMotionRotation: | 210 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpolati
on::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); |
| 166 { | 211 if (interpolation) |
| 167 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpo
lation::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); | 212 return interpolation.release(); |
| 168 if (interpolation) | |
| 169 return interpolation.release(); | |
| 170 | |
| 171 break; | 213 break; |
| 172 } | 214 } |
| 173 case CSSPropertyVisibility: | 215 case CSSPropertyVisibility: |
| 174 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi
lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat
ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV
alue))) | 216 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi
lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat
ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV
alue))) |
| 175 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal
ue, property); | 217 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal
ue, property); |
| 176 | 218 |
| 177 break; | 219 break; |
| 178 | 220 |
| 179 case CSSPropertyBackgroundColor: | 221 case CSSPropertyBackgroundColor: |
| 180 case CSSPropertyBorderBottomColor: | 222 case CSSPropertyBorderBottomColor: |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from
CSSValue->isInitialValue() | 337 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from
CSSValue->isInitialValue() |
| 296 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS
Value->isInitialValue()) | 338 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS
Value->isInitialValue()) |
| 297 fallBackToLegacy = true; | 339 fallBackToLegacy = true; |
| 298 | 340 |
| 299 if (fallBackToLegacy) { | 341 if (fallBackToLegacy) { |
| 300 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(
*fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe
solve(*toCSSValue)) { | 342 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(
*fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe
solve(*toCSSValue)) { |
| 301 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola
tion. | 343 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola
tion. |
| 302 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV
alue, property); | 344 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV
alue, property); |
| 303 } | 345 } |
| 304 | 346 |
| 305 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements
here. | 347 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(pr
operty, end, element, *fromCSSValue, *toCSSValue); |
| 306 // FIXME: Remove this cache | |
| 307 ASSERT(element); | |
| 308 if (!m_animatableValueCache) | |
| 309 m_animatableValueCache = StyleResolver::createAnimatableValueSnapsho
t(*element, property, *fromCSSValue); | |
| 310 | 348 |
| 311 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable
ValueSnapshot(*element, property, *toCSSValue); | 349 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to
StringPropertySpecificKeyframe(end).m_animatableValueCache.release(), property); |
| 312 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to; | |
| 313 | |
| 314 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to
.release(), property); | |
| 315 } | 350 } |
| 316 | 351 |
| 317 ASSERT(AnimatableValue::usesDefaultInterpolation( | 352 ASSERT(AnimatableValue::usesDefaultInterpolation( |
| 318 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS
SValue).get(), | 353 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS
SValue).get(), |
| 319 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV
alue).get())); | 354 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV
alue).get())); |
| 320 | 355 |
| 321 return nullptr; | 356 return nullptr; |
| 322 | 357 |
| 323 } | 358 } |
| 324 | 359 |
| 360 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. |
| 361 // FIXME: Remove this cache |
| 362 void StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(CSSPr
opertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element, CS
SValue& fromCSSValue, CSSValue& toCSSValue) const |
| 363 { |
| 364 ASSERT(element); |
| 365 if (!m_animatableValueCache) |
| 366 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e
lement, property, fromCSSValue); |
| 367 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu
eSnapshot(*element, property, toCSSValue); |
| 368 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to; |
| 369 } |
| 370 |
| 371 |
| 325 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e
asing) const | 372 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e
asing) const |
| 326 { | 373 { |
| 327 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An
imationEffect::CompositeAdd)); | 374 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An
imationEffect::CompositeAdd)); |
| 328 } | 375 } |
| 329 | 376 |
| 330 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::cloneWithOffset(double offset) const | 377 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope
rtySpecificKeyframe::cloneWithOffset(double offset) const |
| 331 { | 378 { |
| 332 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(
offset, m_easing, m_value.get()); | 379 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(
offset, m_easing, m_value.get()); |
| 333 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima
tableValueCache; | 380 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima
tableValueCache; |
| 334 return adoptPtrWillBeNoop(theClone); | 381 return adoptPtrWillBeNoop(theClone); |
| 335 } | 382 } |
| 336 | 383 |
| 337 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) | 384 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) |
| 338 { | 385 { |
| 339 visitor->trace(m_value); | 386 visitor->trace(m_value); |
| 340 visitor->trace(m_animatableValueCache); | 387 visitor->trace(m_animatableValueCache); |
| 341 Keyframe::PropertySpecificKeyframe::trace(visitor); | 388 Keyframe::PropertySpecificKeyframe::trace(visitor); |
| 342 } | 389 } |
| 343 | 390 |
| 344 } | 391 } |
| OLD | NEW |