Chromium Code Reviews| 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/InterpolableValuePromise.h" | |
| 7 | |
| 8 #include "core/css/CSSShadowValue.h" | |
| 9 #include "core/css/Pair.h" | |
| 10 #include "core/css/Rect.h" | |
| 11 #include "core/css/resolver/StyleResolver.h" | |
| 12 | |
| 13 namespace WebCore { | |
| 14 | |
| 15 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValuePromise); | |
| 16 | |
| 17 InterpolableValuePromise::InterpolableValuePromise(Element& element, CSSProperty ID id, PassRefPtrWillBeRawPtr<CSSValue> value) | |
| 18 { | |
| 19 if (requiresLateBinding(*value)) | |
| 20 m_cssValue = value; | |
| 21 else | |
| 22 m_interpolableAnimatableValue = InterpolableAnimatableValue::create(Styl eResolver::applyAndSnapshotAnimatableValue(element, id, value.get())); | |
| 23 } | |
| 24 | |
| 25 void InterpolableValuePromise::trace(Visitor* visitor) | |
| 26 { | |
| 27 visitor->trace(m_cssValue); | |
| 28 visitor->trace(m_interpolableAnimatableValue); | |
| 29 } | |
| 30 | |
| 31 PassOwnPtrWillBeRawPtr<InterpolableValue> InterpolableValuePromise::extract(Styl eResolverState& state, CSSPropertyID id) | |
| 32 { | |
| 33 if (m_interpolableAnimatableValue) | |
| 34 return m_interpolableAnimatableValue->clone(); | |
| 35 | |
| 36 // FIXME: Avoid creating InterpolableAnimatableValues. | |
| 37 return InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAn imatableValue(*state.element(), id, m_cssValue.get(), state.style())); | |
| 38 } | |
| 39 | |
| 40 PassRefPtrWillBeRawPtr<AnimatableValue> InterpolableValuePromise::extractAnimata bleValue() | |
| 41 { | |
| 42 return m_interpolableAnimatableValue ? m_interpolableAnimatableValue->value( ) : 0; | |
| 43 } | |
| 44 | |
| 45 bool InterpolableValuePromise::requiresLateBinding(const CSSPrimitiveValue& prim itiveValue) | |
|
shans
2014/05/08 16:12:58
I think we decided we should come up with a better
| |
| 46 { | |
| 47 if (primitiveValue.isCalculated()) { | |
| 48 CSSLengthArray lengthArray; | |
| 49 CSSPrimitiveValue::zeroLengthArray(lengthArray); | |
| 50 primitiveValue.accumulateLengthArray(lengthArray); | |
| 51 return lengthArray[CSSPrimitiveValue::UnitTypeFontSize] | |
| 52 || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize] | |
| 53 || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize] | |
| 54 || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth] | |
| 55 || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth] | |
| 56 || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight] | |
| 57 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin] | |
| 58 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax]; | |
| 59 } | |
| 60 | |
| 61 if (primitiveValue.isLength()) | |
| 62 return primitiveValue.isFontRelativeLength() || primitiveValue.isViewpor tPercentageLength(); | |
| 63 | |
| 64 if (Pair* pair = primitiveValue.getPairValue()) { | |
| 65 return requiresLateBinding(*pair->first()) | |
| 66 || requiresLateBinding(*pair->second()); | |
| 67 } | |
| 68 | |
| 69 if (Rect* rect = primitiveValue.getRectValue()) { | |
| 70 return requiresLateBinding(*rect->top()) | |
| 71 || requiresLateBinding(*rect->right()) | |
| 72 || requiresLateBinding(*rect->bottom()) | |
| 73 || requiresLateBinding(*rect->left()); | |
| 74 } | |
| 75 | |
| 76 if (Quad* quad = primitiveValue.getQuadValue()) { | |
| 77 return requiresLateBinding(*quad->top()) | |
| 78 || requiresLateBinding(*quad->right()) | |
| 79 || requiresLateBinding(*quad->bottom()) | |
| 80 || requiresLateBinding(*quad->left()); | |
| 81 } | |
| 82 | |
| 83 switch (primitiveValue.getValueID()) { | |
| 84 case CSSValueBolder: | |
| 85 case CSSValueCurrentcolor: | |
| 86 case CSSValueHigher: | |
| 87 case CSSValueLarger: | |
| 88 case CSSValueLighter: | |
| 89 case CSSValueLower: | |
| 90 case CSSValueSmaller: | |
| 91 return true; | |
| 92 default: | |
| 93 return false; | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 bool InterpolableValuePromise::requiresLateBinding(const CSSValue& value) | |
| 98 { | |
| 99 if (value.isPrimitiveValue()) | |
| 100 return requiresLateBinding(toCSSPrimitiveValue(value)); | |
| 101 | |
| 102 if (value.isInheritedValue()) | |
| 103 return true; | |
| 104 | |
| 105 if (value.isValueList()) { | |
| 106 const CSSValueList& valueList = toCSSValueList(value); | |
| 107 size_t length = valueList.length(); | |
| 108 for (size_t index = 0; index < length; ++index) { | |
| 109 if (requiresLateBinding(*valueList.item(index))) | |
| 110 return true; | |
| 111 } | |
| 112 return false; | |
| 113 } | |
| 114 | |
| 115 if (value.isShadowValue()) { | |
| 116 const CSSShadowValue& shadowValue = toCSSShadowValue(value); | |
| 117 return (shadowValue.x && requiresLateBinding(*shadowValue.x)) | |
| 118 || (shadowValue.y && requiresLateBinding(*shadowValue.y)) | |
| 119 || (shadowValue.blur && requiresLateBinding(*shadowValue.blur)) | |
| 120 || (shadowValue.spread && requiresLateBinding(*shadowValue.spread)) | |
| 121 || (shadowValue.style && requiresLateBinding(*shadowValue.style)) | |
| 122 || (shadowValue.color && requiresLateBinding(*shadowValue.color)); | |
| 123 } | |
| 124 | |
| 125 return false; | |
| 126 } | |
| 127 | |
| 128 } | |
| OLD | NEW |