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