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 "config.h" |
| 6 #include "core/animation/interpolation/DeferredLegacyStyleInterpolation.h" |
| 7 |
| 8 #include "core/animation/interpolation/LegacyStyleInterpolation.h" |
| 9 #include "core/css/CSSImageValue.h" |
| 10 #include "core/css/CSSPrimitiveValue.h" |
| 11 #include "core/css/CSSSVGDocumentValue.h" |
| 12 #include "core/css/CSSShadowValue.h" |
| 13 #include "core/css/CSSValueList.h" |
| 14 #include "core/css/Pair.h" |
| 15 #include "core/css/Rect.h" |
| 16 #include "core/css/resolver/StyleResolver.h" |
| 17 #include "core/css/resolver/StyleResolverState.h" |
| 18 |
| 19 namespace WebCore { |
| 20 |
| 21 void DeferredLegacyStyleInterpolation::apply(StyleResolverState& state) const |
| 22 { |
| 23 RefPtrWillBeRawPtr<LegacyStyleInterpolation> innerInterpolation = LegacyStyl
eInterpolation::create( |
| 24 StyleResolver::createAnimatableValueSnapshot(*state.element(), m_id, *m_
startCSSValue, *state.style()), |
| 25 StyleResolver::createAnimatableValueSnapshot(*state.element(), m_id, *m_
endCSSValue, *state.style()), |
| 26 m_id); |
| 27 innerInterpolation->interpolate(m_cachedIteration, m_cachedFraction); |
| 28 innerInterpolation->apply(state); |
| 29 } |
| 30 |
| 31 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSValue& value) |
| 32 { |
| 33 switch (value.cssValueType()) { |
| 34 case CSSValue::CSS_INHERIT: |
| 35 return true; |
| 36 case CSSValue::CSS_PRIMITIVE_VALUE: |
| 37 return interpolationRequiresStyleResolve(toCSSPrimitiveValue(value)); |
| 38 case CSSValue::CSS_VALUE_LIST: |
| 39 return interpolationRequiresStyleResolve(toCSSValueList(value)); |
| 40 case CSSValue::CSS_CUSTOM: |
| 41 if (value.isImageValue()) |
| 42 return interpolationRequiresStyleResolve(toCSSImageValue(value)); |
| 43 if (value.isShadowValue()) |
| 44 return interpolationRequiresStyleResolve(toCSSShadowValue(value)); |
| 45 if (value.isSVGDocumentValue()) |
| 46 return interpolationRequiresStyleResolve(toCSSSVGDocumentValue(value
)); |
| 47 // FIXME: consider other custom types. |
| 48 return true; |
| 49 case CSSValue::CSS_INITIAL: |
| 50 // FIXME: should not require resolving styles for initial. |
| 51 return true; |
| 52 default: |
| 53 ASSERT_NOT_REACHED(); |
| 54 return true; |
| 55 } |
| 56 } |
| 57 |
| 58 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSPrimitiveValue& primitiveValue) |
| 59 { |
| 60 // FIXME: consider other types. |
| 61 if (primitiveValue.isNumber() || primitiveValue.isPercentage() || primitiveV
alue.isAngle() || primitiveValue.isRGBColor() || primitiveValue.isURI()) |
| 62 return false; |
| 63 |
| 64 if (primitiveValue.isLength()) |
| 65 return primitiveValue.isFontRelativeLength() || primitiveValue.isViewpor
tPercentageLength(); |
| 66 |
| 67 if (primitiveValue.isCalculated()) { |
| 68 CSSLengthArray lengthArray(CSSPrimitiveValue::LengthUnitTypeCount); |
| 69 primitiveValue.accumulateLengthArray(lengthArray); |
| 70 return lengthArray[CSSPrimitiveValue::UnitTypeFontSize] != 0 |
| 71 || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize] != 0 |
| 72 || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize] != 0 |
| 73 || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth] != 0 |
| 74 || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth] != 0 |
| 75 || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight] != 0 |
| 76 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin] != 0 |
| 77 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax] != 0; |
| 78 } |
| 79 |
| 80 if (Pair* pair = primitiveValue.getPairValue()) { |
| 81 return interpolationRequiresStyleResolve(*pair->first()) |
| 82 || interpolationRequiresStyleResolve(*pair->second()); |
| 83 } |
| 84 |
| 85 if (Rect* rect = primitiveValue.getRectValue()) { |
| 86 return interpolationRequiresStyleResolve(*rect->top()) |
| 87 || interpolationRequiresStyleResolve(*rect->right()) |
| 88 || interpolationRequiresStyleResolve(*rect->bottom()) |
| 89 || interpolationRequiresStyleResolve(*rect->left()); |
| 90 } |
| 91 |
| 92 if (Quad* quad = primitiveValue.getQuadValue()) { |
| 93 return interpolationRequiresStyleResolve(*quad->top()) |
| 94 || interpolationRequiresStyleResolve(*quad->right()) |
| 95 || interpolationRequiresStyleResolve(*quad->bottom()) |
| 96 || interpolationRequiresStyleResolve(*quad->left()); |
| 97 } |
| 98 |
| 99 CSSValueID id = primitiveValue.getValueID(); |
| 100 bool isColor = ((id >= CSSValueAqua && id <= CSSValueTransparent) |
| 101 || (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) |
| 102 || id == CSSValueGrey); |
| 103 return (id != CSSValueNone) && !isColor; |
| 104 } |
| 105 |
| 106 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSImageValue& imageValue) |
| 107 { |
| 108 return false; |
| 109 } |
| 110 |
| 111 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSShadowValue& shadowValue) |
| 112 { |
| 113 return (shadowValue.x && interpolationRequiresStyleResolve(*shadowValue.x)) |
| 114 || (shadowValue.y && interpolationRequiresStyleResolve(*shadowValue.y)) |
| 115 || (shadowValue.blur && interpolationRequiresStyleResolve(*shadowValue.b
lur)) |
| 116 || (shadowValue.spread && interpolationRequiresStyleResolve(*shadowValue
.spread)) |
| 117 || (shadowValue.style && interpolationRequiresStyleResolve(*shadowValue.
style)) |
| 118 || (shadowValue.color && interpolationRequiresStyleResolve(*shadowValue.
color)); |
| 119 } |
| 120 |
| 121 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSSVGDocumentValue& documentValue) |
| 122 { |
| 123 return true; |
| 124 } |
| 125 |
| 126 bool DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(const C
SSValueList& valueList) |
| 127 { |
| 128 size_t length = valueList.length(); |
| 129 for (size_t index = 0; index < length; ++index) { |
| 130 if (interpolationRequiresStyleResolve(*valueList.item(index))) |
| 131 return true; |
| 132 } |
| 133 return false; |
| 134 } |
| 135 |
| 136 void DeferredLegacyStyleInterpolation::trace(Visitor* visitor) |
| 137 { |
| 138 StyleInterpolation::trace(visitor); |
| 139 visitor->trace(m_startCSSValue); |
| 140 visitor->trace(m_endCSSValue); |
| 141 } |
| 142 |
| 143 } |
OLD | NEW |