| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/core/animation/StringKeyframe.h" | |
| 6 | |
| 7 #include "sky/engine/core/animation/DefaultStyleInterpolation.h" | |
| 8 #include "sky/engine/core/animation/DeferredLegacyStyleInterpolation.h" | |
| 9 #include "sky/engine/core/animation/LegacyStyleInterpolation.h" | |
| 10 #include "sky/engine/core/animation/LengthStyleInterpolation.h" | |
| 11 #include "sky/engine/core/animation/css/CSSAnimations.h" | |
| 12 #include "sky/engine/core/css/CSSPropertyMetadata.h" | |
| 13 #include "sky/engine/core/css/resolver/StyleResolver.h" | |
| 14 #include "sky/engine/core/rendering/style/RenderStyle.h" | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom) | |
| 19 : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing) | |
| 20 , m_propertySet(copyFrom.m_propertySet->mutableCopy()) | |
| 21 { | |
| 22 } | |
| 23 | |
| 24 void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& valu
e, StyleSheetContents* styleSheetContents) | |
| 25 { | |
| 26 ASSERT(property != CSSPropertyInvalid); | |
| 27 if (CSSAnimations::isAllowedAnimation(property)) | |
| 28 m_propertySet->setProperty(property, value, styleSheetContents); | |
| 29 } | |
| 30 | |
| 31 PropertySet StringKeyframe::properties() const | |
| 32 { | |
| 33 // This is not used in time-critical code, so we probably don't need to | |
| 34 // worry about caching this result. | |
| 35 PropertySet properties; | |
| 36 for (unsigned i = 0; i < m_propertySet->propertyCount(); ++i) | |
| 37 properties.add(m_propertySet->propertyAt(i).id()); | |
| 38 return properties; | |
| 39 } | |
| 40 | |
| 41 PassRefPtr<Keyframe> StringKeyframe::clone() const | |
| 42 { | |
| 43 return adoptRef(new StringKeyframe(*this)); | |
| 44 } | |
| 45 PassOwnPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::createPropertySpe
cificKeyframe(CSSPropertyID property) const | |
| 46 { | |
| 47 return adoptPtr(new PropertySpecificKeyframe(offset(), &easing(), propertyVa
lue(property), composite())); | |
| 48 } | |
| 49 | |
| 50 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::Composite
Operation op) | |
| 51 : Keyframe::PropertySpecificKeyframe(offset, easing, op) | |
| 52 , m_value(value) | |
| 53 { } | |
| 54 | |
| 55 StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset
, PassRefPtr<TimingFunction> easing, CSSValue* value) | |
| 56 : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::Compos
iteReplace) | |
| 57 , m_value(value) | |
| 58 { | |
| 59 ASSERT(!isNull(m_offset)); | |
| 60 } | |
| 61 | |
| 62 PassRefPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::createInterp
olation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe* end, Element
* element) const | |
| 63 { | |
| 64 CSSValue* fromCSSValue = m_value.get(); | |
| 65 CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end)->value(); | |
| 66 ValueRange range = ValueRangeAll; | |
| 67 | |
| 68 if (!CSSPropertyMetadata::isAnimatableProperty(property)) | |
| 69 return DefaultStyleInterpolation::create(fromCSSValue, toCSSValue, prope
rty); | |
| 70 | |
| 71 switch (property) { | |
| 72 case CSSPropertyBorderBottomWidth: | |
| 73 case CSSPropertyBorderLeftWidth: | |
| 74 case CSSPropertyBorderRightWidth: | |
| 75 case CSSPropertyBorderTopWidth: | |
| 76 case CSSPropertyFontSize: | |
| 77 case CSSPropertyHeight: | |
| 78 case CSSPropertyLineHeight: | |
| 79 case CSSPropertyMaxHeight: | |
| 80 case CSSPropertyMaxWidth: | |
| 81 case CSSPropertyMinHeight: | |
| 82 case CSSPropertyMinWidth: | |
| 83 case CSSPropertyOutlineWidth: | |
| 84 case CSSPropertyPaddingBottom: | |
| 85 case CSSPropertyPaddingLeft: | |
| 86 case CSSPropertyPaddingRight: | |
| 87 case CSSPropertyPaddingTop: | |
| 88 case CSSPropertyPerspective: | |
| 89 case CSSPropertyWidth: | |
| 90 range = ValueRangeNonNegative; | |
| 91 // Fall through | |
| 92 case CSSPropertyBottom: | |
| 93 case CSSPropertyLeft: | |
| 94 case CSSPropertyLetterSpacing: | |
| 95 case CSSPropertyMarginBottom: | |
| 96 case CSSPropertyMarginLeft: | |
| 97 case CSSPropertyMarginRight: | |
| 98 case CSSPropertyMarginTop: | |
| 99 case CSSPropertyOutlineOffset: | |
| 100 case CSSPropertyRight: | |
| 101 case CSSPropertyTop: | |
| 102 case CSSPropertyVerticalAlign: | |
| 103 case CSSPropertyWordSpacing: | |
| 104 if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyl
eInterpolation::canCreateFrom(*toCSSValue)) | |
| 105 return LengthStyleInterpolation::create(fromCSSValue, toCSSValue, pr
operty, range); | |
| 106 break; | |
| 107 default: | |
| 108 break; | |
| 109 } | |
| 110 | |
| 111 if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*fro
mCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolv
e(*toCSSValue)) | |
| 112 return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSValue
, property); | |
| 113 | |
| 114 // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here
. | |
| 115 // FIXME: Remove this cache | |
| 116 ASSERT(element); | |
| 117 if (!m_animatableValueCache) | |
| 118 m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*e
lement, property, *fromCSSValue); | |
| 119 | |
| 120 RefPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*e
lement, property, *toCSSValue); | |
| 121 toStringPropertySpecificKeyframe(end)->m_animatableValueCache = to; | |
| 122 | |
| 123 return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to.rel
ease(), property); | |
| 124 } | |
| 125 | |
| 126 PassOwnPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificK
eyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> easing) const | |
| 127 { | |
| 128 return adoptPtr(new PropertySpecificKeyframe(offset, easing, 0, AnimationEff
ect::CompositeAdd)); | |
| 129 } | |
| 130 | |
| 131 PassOwnPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificK
eyframe::cloneWithOffset(double offset) const | |
| 132 { | |
| 133 Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(
offset, m_easing, m_value.get()); | |
| 134 toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_anima
tableValueCache; | |
| 135 return adoptPtr(theClone); | |
| 136 } | |
| 137 | |
| 138 } | |
| OLD | NEW |