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 "core/animation/DeferredLegacyStyleInterpolation.h" |
| 6 |
| 7 #include "core/animation/ElementAnimations.h" |
| 8 #include "core/animation/css/CSSAnimatableValueFactory.h" |
| 9 #include "core/css/CSSBasicShapeValues.h" |
| 10 #include "core/css/CSSImageValue.h" |
| 11 #include "core/css/CSSPrimitiveValue.h" |
| 12 #include "core/css/CSSQuadValue.h" |
| 13 #include "core/css/CSSSVGDocumentValue.h" |
| 14 #include "core/css/CSSShadowValue.h" |
| 15 #include "core/css/CSSValueList.h" |
| 16 #include "core/css/CSSValuePair.h" |
| 17 #include "core/css/resolver/StyleResolver.h" |
| 18 #include "core/css/resolver/StyleResolverState.h" |
| 19 |
| 20 namespace blink { |
| 21 |
| 22 void DeferredLegacyStyleInterpolation::apply(StyleResolverState& state) const |
| 23 { |
| 24 if (m_outdated || !state.element()->elementAnimations() || !state.element()-
>elementAnimations()->isAnimationStyleChange()) { |
| 25 RefPtr<AnimatableValue> startAnimatableValue; |
| 26 RefPtr<AnimatableValue> endAnimatableValue; |
| 27 |
| 28 // Snapshot underlying values for neutral keyframes first because non-ne
utral keyframes will mutate the StyleResolverState. |
| 29 if (!m_endCSSValue) { |
| 30 endAnimatableValue = StyleResolver::createAnimatableValueSnapshot(st
ate, m_id, m_endCSSValue.get()); |
| 31 startAnimatableValue = StyleResolver::createAnimatableValueSnapshot(
state, m_id, m_startCSSValue.get()); |
| 32 } else { |
| 33 startAnimatableValue = StyleResolver::createAnimatableValueSnapshot(
state, m_id, m_startCSSValue.get()); |
| 34 endAnimatableValue = StyleResolver::createAnimatableValueSnapshot(st
ate, m_id, m_endCSSValue.get()); |
| 35 } |
| 36 |
| 37 m_innerInterpolation = LegacyStyleInterpolation::create(startAnimatableV
alue, endAnimatableValue, m_id); |
| 38 m_outdated = false; |
| 39 } |
| 40 |
| 41 m_innerInterpolation->interpolate(m_currentIteration, m_currentFraction); |
| 42 m_innerInterpolation->apply(state); |
| 43 } |
| 44 |
| 45 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSValue& value) |
| 46 { |
| 47 // FIXME: should not require resolving styles for inherit/initial/unset. |
| 48 if (value.isCSSWideKeyword()) |
| 49 return true; |
| 50 if (value.isBasicShapeCircleValue()) |
| 51 return interpolationRequiresStyleResolve(toCSSBasicShapeCircleValue(valu
e)); |
| 52 if (value.isBasicShapeEllipseValue()) |
| 53 return interpolationRequiresStyleResolve(toCSSBasicShapeEllipseValue(val
ue)); |
| 54 if (value.isBasicShapePolygonValue()) |
| 55 return interpolationRequiresStyleResolve(toCSSBasicShapePolygonValue(val
ue)); |
| 56 if (value.isBasicShapeInsetValue()) |
| 57 return interpolationRequiresStyleResolve(toCSSBasicShapeInsetValue(value
)); |
| 58 if (value.isColorValue()) |
| 59 return false; |
| 60 if (value.isStringValue() || value.isURIValue() || value.isCustomIdentValue(
)) |
| 61 return false; |
| 62 if (value.isPrimitiveValue()) |
| 63 return interpolationRequiresStyleResolve(toCSSPrimitiveValue(value)); |
| 64 if (value.isQuadValue()) |
| 65 return interpolationRequiresStyleResolve(toCSSQuadValue(value)); |
| 66 if (value.isValueList()) |
| 67 return interpolationRequiresStyleResolve(toCSSValueList(value)); |
| 68 if (value.isValuePair()) |
| 69 return interpolationRequiresStyleResolve(toCSSValuePair(value)); |
| 70 if (value.isImageValue()) |
| 71 return interpolationRequiresStyleResolve(toCSSImageValue(value)); |
| 72 if (value.isShadowValue()) |
| 73 return interpolationRequiresStyleResolve(toCSSShadowValue(value)); |
| 74 if (value.isSVGDocumentValue()) |
| 75 return interpolationRequiresStyleResolve(toCSSSVGDocumentValue(value)); |
| 76 // FIXME: consider other custom types. |
| 77 return true; |
| 78 } |
| 79 |
| 80 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSPrimitiveValue& primitiveValue) |
| 81 { |
| 82 // FIXME: consider other types. |
| 83 if (primitiveValue.isNumber() || primitiveValue.isPercentage() || primitiveV
alue.isAngle()) |
| 84 return false; |
| 85 |
| 86 if (primitiveValue.isLength()) |
| 87 return primitiveValue.isFontRelativeLength() || primitiveValue.isViewpor
tPercentageLength(); |
| 88 |
| 89 if (primitiveValue.isCalculated()) { |
| 90 CSSLengthArray lengthArray; |
| 91 primitiveValue.accumulateLengthArray(lengthArray); |
| 92 return lengthArray.values[CSSPrimitiveValue::UnitTypeFontSize] != 0 |
| 93 || lengthArray.values[CSSPrimitiveValue::UnitTypeFontXSize] != 0 |
| 94 || lengthArray.values[CSSPrimitiveValue::UnitTypeRootFontSize] != 0 |
| 95 || lengthArray.values[CSSPrimitiveValue::UnitTypeZeroCharacterWidth]
!= 0 |
| 96 || lengthArray.values[CSSPrimitiveValue::UnitTypeViewportWidth] != 0 |
| 97 || lengthArray.values[CSSPrimitiveValue::UnitTypeViewportHeight] !=
0 |
| 98 || lengthArray.values[CSSPrimitiveValue::UnitTypeViewportMin] != 0 |
| 99 || lengthArray.values[CSSPrimitiveValue::UnitTypeViewportMax] != 0; |
| 100 } |
| 101 |
| 102 CSSValueID id = primitiveValue.getValueID(); |
| 103 bool isColor = ((id >= CSSValueAqua && id <= CSSValueTransparent) |
| 104 || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) |
| 105 || id == CSSValueGrey); |
| 106 return (id != CSSValueNone) && !isColor; |
| 107 } |
| 108 |
| 109 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSImageValue& imageValue) |
| 110 { |
| 111 return false; |
| 112 } |
| 113 |
| 114 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSShadowValue& shadowValue) |
| 115 { |
| 116 return (shadowValue.x && interpolationRequiresStyleResolve(*shadowValue.x)) |
| 117 || (shadowValue.y && interpolationRequiresStyleResolve(*shadowValue.y)) |
| 118 || (shadowValue.blur && interpolationRequiresStyleResolve(*shadowValue.b
lur)) |
| 119 || (shadowValue.spread && interpolationRequiresStyleResolve(*shadowValue
.spread)) |
| 120 || (shadowValue.style && interpolationRequiresStyleResolve(*shadowValue.
style)) |
| 121 || (shadowValue.color && interpolationRequiresStyleResolve(*shadowValue.
color)); |
| 122 } |
| 123 |
| 124 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSSVGDocumentValue& documentValue) |
| 125 { |
| 126 return true; |
| 127 } |
| 128 |
| 129 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSValueList& valueList) |
| 130 { |
| 131 size_t length = valueList.length(); |
| 132 for (size_t index = 0; index < length; ++index) { |
| 133 if (interpolationRequiresStyleResolve(*valueList.item(index))) |
| 134 return true; |
| 135 } |
| 136 return false; |
| 137 } |
| 138 |
| 139 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSValuePair& pair) |
| 140 { |
| 141 return interpolationRequiresStyleResolve(pair.first()) |
| 142 || interpolationRequiresStyleResolve(pair.second()); |
| 143 } |
| 144 |
| 145 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSBasicShapeCircleValue& shape) |
| 146 { |
| 147 // FIXME: Should inspect the members. |
| 148 return false; |
| 149 } |
| 150 |
| 151 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSBasicShapeEllipseValue& shape) |
| 152 { |
| 153 // FIXME: Should inspect the members. |
| 154 return false; |
| 155 } |
| 156 |
| 157 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSBasicShapePolygonValue& shape) |
| 158 { |
| 159 // FIXME: Should inspect the members. |
| 160 return false; |
| 161 } |
| 162 |
| 163 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSBasicShapeInsetValue& shape) |
| 164 { |
| 165 // FIXME: Should inspect the members. |
| 166 return false; |
| 167 } |
| 168 |
| 169 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSQuadValue& quad) |
| 170 { |
| 171 return interpolationRequiresStyleResolve(*quad.top()) |
| 172 || interpolationRequiresStyleResolve(*quad.right()) |
| 173 || interpolationRequiresStyleResolve(*quad.bottom()) |
| 174 || interpolationRequiresStyleResolve(*quad.left()); |
| 175 } |
| 176 |
| 177 } // namespace blink |
OLD | NEW |