Chromium Code Reviews| 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/DefaultStyleInterpolation.h" | 10 #include "core/animation/DefaultStyleInterpolation.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) | 71 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos iteReplace) |
| 72 , m_value(value) | 72 , m_value(value) |
| 73 { | 73 { |
| 74 ASSERT(!isNull(m_offset)); | 74 ASSERT(!isNull(m_offset)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect, and a template parameter specific converter. | 77 // FIXME: Refactor this into a generic piece that lives in InterpolationEffect, and a template parameter specific converter. |
| 78 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr ame& end, Element* element) const | 78 PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe:: maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyfr ame& end, Element* element) const |
| 79 { | 79 { |
| 80 CSSValue* fromCSSValue = m_value.get(); | 80 CSSValue* fromCSSValue = m_value.get(); |
| 81 | |
|
Eric Willigers
2015/01/28 22:24:45
no need for blank line
| |
| 81 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); | 82 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value(); |
| 82 InterpolationRange range = RangeAll; | 83 InterpolationRange range = RangeAll; |
| 83 bool fallBackToLegacy = false; | 84 bool fallBackToLegacy = false; |
| 84 | 85 |
| 85 if (!CSSPropertyMetadata::isAnimatableProperty(property)) { | 86 if (!CSSPropertyMetadata::isAnimatableProperty(property)) { |
| 86 // FIXME: Remove this once TimingFunction partitioning is implemented fo r all types. | 87 // FIXME: Remove this once TimingFunction partitioning is implemented fo r all types. |
| 87 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningE nabled()) | 88 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningE nabled()) |
| 88 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, p roperty); | 89 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, p roperty); |
| 89 | 90 |
| 90 if (fromCSSValue == toCSSValue) | 91 if (fromCSSValue == toCSSValue) |
| 91 return ConstantStyleInterpolation::create(fromCSSValue, property); | 92 return ConstantStyleInterpolation::create(fromCSSValue, property); |
| 92 | 93 |
| 93 return nullptr; | 94 return nullptr; |
| 94 } | 95 } |
| 95 | 96 |
| 96 // FIXME: Generate this giant switch statement. | 97 // FIXME: Generate this giant switch statement. |
| 97 switch (property) { | 98 switch (property) { |
| 98 case CSSPropertyLineHeight: | 99 case CSSPropertyLineHeight: |
| 99 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue)) | |
| 100 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, RangeNonNegative); | |
| 101 | |
| 102 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue)) | 100 if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyl eInterpolation::canCreateFrom(*toCSSValue)) |
| 103 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); | 101 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, CSSPrimitiveValue::CSS_NUMBER, RangeNonNegative); |
| 104 | 102 // Fall through |
| 105 break; | |
| 106 case CSSPropertyBorderBottomWidth: | 103 case CSSPropertyBorderBottomWidth: |
| 107 case CSSPropertyBorderLeftWidth: | 104 case CSSPropertyBorderLeftWidth: |
| 108 case CSSPropertyBorderRightWidth: | 105 case CSSPropertyBorderRightWidth: |
| 109 case CSSPropertyBorderTopWidth: | 106 case CSSPropertyBorderTopWidth: |
| 107 case CSSPropertyFlexBasis: | |
| 110 case CSSPropertyFontSize: | 108 case CSSPropertyFontSize: |
| 111 case CSSPropertyHeight: | 109 case CSSPropertyHeight: |
| 112 case CSSPropertyMaxHeight: | 110 case CSSPropertyMaxHeight: |
| 113 case CSSPropertyMaxWidth: | 111 case CSSPropertyMaxWidth: |
| 114 case CSSPropertyMinHeight: | 112 case CSSPropertyMinHeight: |
| 115 case CSSPropertyMinWidth: | 113 case CSSPropertyMinWidth: |
| 116 case CSSPropertyMotionPosition: | 114 case CSSPropertyMotionPosition: |
| 117 case CSSPropertyOutlineWidth: | 115 case CSSPropertyOutlineWidth: |
| 118 case CSSPropertyPaddingBottom: | 116 case CSSPropertyPaddingBottom: |
| 119 case CSSPropertyPaddingLeft: | 117 case CSSPropertyPaddingLeft: |
| 120 case CSSPropertyPaddingRight: | 118 case CSSPropertyPaddingRight: |
| 121 case CSSPropertyPaddingTop: | 119 case CSSPropertyPaddingTop: |
| 122 case CSSPropertyPerspective: | 120 case CSSPropertyPerspective: |
| 123 case CSSPropertyShapeMargin: | 121 case CSSPropertyShapeMargin: |
| 122 case CSSPropertyWebkitBorderHorizontalSpacing: | |
| 123 case CSSPropertyWebkitBorderVerticalSpacing: | |
| 124 case CSSPropertyWebkitColumnGap: | |
| 125 case CSSPropertyWebkitColumnWidth: | |
| 124 case CSSPropertyWidth: | 126 case CSSPropertyWidth: |
| 125 range = RangeNonNegative; | 127 range = RangeNonNegative; |
| 126 // Fall through | 128 // Fall through |
| 127 case CSSPropertyBottom: | 129 case CSSPropertyBottom: |
| 128 case CSSPropertyLeft: | 130 case CSSPropertyLeft: |
| 129 case CSSPropertyLetterSpacing: | 131 case CSSPropertyLetterSpacing: |
| 130 case CSSPropertyMarginBottom: | 132 case CSSPropertyMarginBottom: |
| 131 case CSSPropertyMarginLeft: | 133 case CSSPropertyMarginLeft: |
| 132 case CSSPropertyMarginRight: | 134 case CSSPropertyMarginRight: |
| 133 case CSSPropertyMarginTop: | 135 case CSSPropertyMarginTop: |
| 134 case CSSPropertyOutlineOffset: | 136 case CSSPropertyOutlineOffset: |
| 135 case CSSPropertyRight: | 137 case CSSPropertyRight: |
| 136 case CSSPropertyTop: | 138 case CSSPropertyTop: |
| 137 case CSSPropertyVerticalAlign: | 139 case CSSPropertyVerticalAlign: |
| 138 case CSSPropertyWordSpacing: | 140 case CSSPropertyWordSpacing: |
| 139 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue)) | 141 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl eInterpolation::canCreateFrom(*toCSSValue)) |
| 140 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range); | 142 return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range); |
| 141 | 143 |
| 142 // FIXME: Handle keywords e.g. 'none'. | 144 // FIXME: Handle keywords e.g. 'none'. |
| 143 if (property == CSSPropertyPerspective) | 145 if (property == CSSPropertyPerspective) |
| 144 fallBackToLegacy = true; | 146 fallBackToLegacy = true; |
| 145 | |
| 146 // FIXME: Handle keywords e.g. 'smaller', 'larger'. | 147 // FIXME: Handle keywords e.g. 'smaller', 'larger'. |
| 147 if (property == CSSPropertyFontSize) | 148 if (property == CSSPropertyFontSize) |
| 148 fallBackToLegacy = true; | 149 fallBackToLegacy = true; |
| 149 | 150 |
| 150 // FIXME: Handle keywords e.g. 'normal' | 151 // FIXME: Handle keywords e.g. 'normal' |
| 151 if (property == CSSPropertyLetterSpacing) | 152 if (property == CSSPropertyLetterSpacing) |
| 152 fallBackToLegacy = true; | 153 fallBackToLegacy = true; |
| 153 | 154 |
| 154 // FIXME: Handle keywords e.g. 'thick' | 155 // FIXME: Handle keywords e.g. 'thick' |
| 155 if (property == CSSPropertyOutlineWidth) | 156 if (property == CSSPropertyOutlineWidth) |
| 156 fallBackToLegacy = true; | 157 fallBackToLegacy = true; |
| 158 break; | |
| 157 | 159 |
| 160 case CSSPropertyOrphans: | |
| 161 if (range == RangeAll) | |
| 162 range = RangeCeiling; | |
| 163 // Fall through | |
| 164 case CSSPropertyWebkitColumnCount: | |
| 165 case CSSPropertyZIndex: | |
| 166 if (range == RangeAll) | |
| 167 range = RangeFloor; | |
| 168 // Fall through | |
| 169 case CSSPropertyFillOpacity: | |
| 170 case CSSPropertyFloodOpacity: | |
| 171 case CSSPropertyOpacity: | |
| 172 case CSSPropertyShapeImageThreshold: | |
| 173 case CSSPropertyStopOpacity: | |
| 174 case CSSPropertyStrokeOpacity: | |
| 175 if (range == RangeAll) | |
| 176 range = RangeFloatFractions; | |
| 177 // Fall through | |
| 178 case CSSPropertyStrokeMiterlimit: | |
| 179 case CSSPropertyWidows: | |
| 180 if (range == RangeAll) | |
| 181 range = RangeGreaterThanOne; | |
| 182 // Fall through | |
| 183 case CSSPropertyZoom: | |
| 184 if (range == RangeAll) | |
| 185 range = RangeDoubleFractions; | |
| 186 // Fall through | |
| 187 case CSSPropertyFlexGrow: | |
| 188 case CSSPropertyFlexShrink: | |
| 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 } | |
| 194 return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, toCSSPrimitiveValue(fromCSSValue)->primitiveType(), range); | |
| 195 } | |
| 158 break; | 196 break; |
| 159 case CSSPropertyMotionRotation: | |
| 160 { | |
| 161 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpo lation::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); | |
| 162 if (interpolation) | |
| 163 return interpolation.release(); | |
| 164 | 197 |
| 198 case CSSPropertyMotionRotation: { | |
| 199 RefPtrWillBeRawPtr<Interpolation> interpolation = DoubleStyleInterpolati on::maybeCreateFromMotionRotation(*fromCSSValue, *toCSSValue, property); | |
| 200 if (interpolation) | |
| 201 return interpolation.release(); | |
| 165 break; | 202 break; |
|
Eric Willigers
2015/01/22 23:38:57
Unindent this line and the following line.
| |
| 166 } | 203 } |
| 167 case CSSPropertyVisibility: | 204 case CSSPropertyVisibility: |
| 168 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue))) | 205 if (VisibilityStyleInterpolation::canCreateFrom(*fromCSSValue) && Visibi lityStyleInterpolation::canCreateFrom(*toCSSValue) && (VisibilityStyleInterpolat ion::isVisible(*fromCSSValue) || VisibilityStyleInterpolation::isVisible(*toCSSV alue))) |
| 169 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property); | 206 return VisibilityStyleInterpolation::create(*fromCSSValue, *toCSSVal ue, property); |
| 170 | 207 |
| 171 break; | 208 break; |
| 172 | 209 |
| 173 case CSSPropertyBackgroundColor: | 210 case CSSPropertyBackgroundColor: |
| 174 case CSSPropertyBorderBottomColor: | 211 case CSSPropertyBorderBottomColor: |
| 175 case CSSPropertyBorderLeftColor: | 212 case CSSPropertyBorderLeftColor: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue() | 276 if (fromCSSValue->isUnsetValue() || fromCSSValue->isInheritedValue() || from CSSValue->isInitialValue() |
| 240 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue()) | 277 || toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSS Value->isInitialValue()) |
| 241 fallBackToLegacy = true; | 278 fallBackToLegacy = true; |
| 242 | 279 |
| 243 if (fallBackToLegacy) { | 280 if (fallBackToLegacy) { |
| 244 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) { | 281 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve( *fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleRe solve(*toCSSValue)) { |
| 245 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion. | 282 // FIXME: Handle these cases outside of DeferredLegacyStyleInterpola tion. |
| 246 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property); | 283 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSV alue, property); |
| 247 } | 284 } |
| 248 | 285 |
| 249 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. | 286 StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(pr operty, end, element, fromCSSValue, toCSSValue); |
| 250 // FIXME: Remove this cache | |
| 251 ASSERT(element); | |
| 252 if (!m_animatableValueCache) | |
| 253 m_animatableValueCache = StyleResolver::createAnimatableValueSnapsho t(*element, property, *fromCSSValue); | |
| 254 | 287 |
| 255 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatable ValueSnapshot(*element, property, *toCSSValue); | 288 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to StringPropertySpecificKeyframe(end).m_animatableValueCache.release(), property); |
| 256 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to; | |
| 257 | |
| 258 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to .release(), property); | |
| 259 } | 289 } |
| 260 | 290 |
| 261 ASSERT(AnimatableValue::usesDefaultInterpolation( | 291 ASSERT(AnimatableValue::usesDefaultInterpolation( |
| 262 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(), | 292 StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCS SValue).get(), |
| 263 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get())); | 293 StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSV alue).get())); |
| 264 | 294 |
| 265 | |
| 266 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types. | 295 // FIXME: Remove this once TimingFunction partitioning is implemented for al l types. |
| 267 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed()) | 296 if (!RuntimeEnabledFeatures::webAnimationsAPITimingFunctionPartitioningEnabl ed()) |
| 268 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); | 297 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope rty); |
| 269 | 298 |
| 270 if (fromCSSValue == toCSSValue) | 299 if (fromCSSValue == toCSSValue) |
| 271 return ConstantStyleInterpolation::create(fromCSSValue, property); | 300 return ConstantStyleInterpolation::create(fromCSSValue, property); |
| 272 | 301 |
| 273 return nullptr; | 302 return nullptr; |
| 274 | 303 |
| 275 } | 304 } |
| 276 | 305 |
| 306 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here. | |
| 307 // FIXME: Remove this cache | |
| 308 void StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(CSSPr opertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element, CS SValue* fromCSSValue, CSSValue* toCSSValue) const | |
| 309 { | |
| 310 ASSERT(element); | |
| 311 if (!m_animatableValueCache) | |
| 312 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e lement, property, *fromCSSValue); | |
| 313 RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValu eSnapshot(*element, property, *toCSSValue); | |
| 314 toStringPropertySpecificKeyframe(end).m_animatableValueCache = to; | |
| 315 } | |
| 316 | |
| 317 | |
|
Eric Willigers
2015/01/22 23:38:57
only need one blank line here
| |
| 277 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const | 318 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> e asing) const |
| 278 { | 319 { |
| 279 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd)); | 320 return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, An imationEffect::CompositeAdd)); |
| 280 } | 321 } |
| 281 | 322 |
| 282 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const | 323 PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::Prope rtySpecificKeyframe::cloneWithOffset(double offset) const |
| 283 { | 324 { |
| 284 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); | 325 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe( offset, m_easing, m_value.get()); |
| 285 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache; | 326 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima tableValueCache; |
| 286 return adoptPtrWillBeNoop(theClone); | 327 return adoptPtrWillBeNoop(theClone); |
| 287 } | 328 } |
| 288 | 329 |
| 289 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) | 330 void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor) |
| 290 { | 331 { |
| 291 visitor->trace(m_value); | 332 visitor->trace(m_value); |
| 292 visitor->trace(m_animatableValueCache); | 333 visitor->trace(m_animatableValueCache); |
| 293 Keyframe::PropertySpecificKeyframe::trace(visitor); | 334 Keyframe::PropertySpecificKeyframe::trace(visitor); |
| 294 } | 335 } |
| 295 | 336 |
| 296 } | 337 } |
| OLD | NEW |