Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(568)

Side by Side Diff: Source/core/animation/LegacyStyleInterpolation.cpp

Issue 273683005: Web Animations API: Deferred computation of interpolated values (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge IVP into LSI Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/LegacyStyleInterpolation.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/AnimatedStyleBuilder.h"
12 #include "core/css/resolver/StyleResolver.h"
13 #include "core/css/resolver/StyleResolverState.h"
14
15 namespace WebCore {
16
17 PassRefPtrWillBeRawPtr<LegacyStyleInterpolation> LegacyStyleInterpolation::creat e(CSSValue& start, CSSValue& end, CSSPropertyID id, Element& element)
18 {
19 if (interpolationRequiresStyleResolve(start) || interpolationRequiresStyleRe solve(end))
20 return adoptRefWillBeNoop(new LegacyStyleInterpolation(&start, &end, id) );
21 return create(
22 InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnima tableValue(element, id, start)),
23 InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnima tableValue(element, id, end)),
24 id);
25 }
26
27 void LegacyStyleInterpolation::apply(StyleResolverState& state) const
28 {
29 if (!m_interpolationRequiresStyleResolve)
30 return AnimatedStyleBuilder::applyProperty(m_id, state, toInterpolableAn imatableValue(m_cachedValue.get())->value());
31
32 OwnPtrWillBeRawPtr<InterpolableValue> start = InterpolableAnimatableValue::c reate(StyleResolver::applyAndSnapshotAnimatableValue(*state.element(), m_id, *m_ startCSSValue, state.style()));
33 OwnPtrWillBeRawPtr<InterpolableValue> end = InterpolableAnimatableValue::cre ate(StyleResolver::applyAndSnapshotAnimatableValue(*state.element(), m_id, *m_en dCSSValue, state.style()));
34 OwnPtrWillBeRawPtr<InterpolableValue> interpolated = start->interpolate(*end , m_cachedFraction);
35 AnimatedStyleBuilder::applyProperty(m_id, state, toInterpolableAnimatableVal ue(interpolated.get())->value());
36 }
37
38 bool LegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSValue& value)
39 {
40 if (value.isPrimitiveValue())
41 return interpolationRequiresStyleResolve(toCSSPrimitiveValue(value));
42
43 if (value.isInheritedValue())
44 return true;
45
46 if (value.isValueList()) {
47 const CSSValueList& valueList = toCSSValueList(value);
48 size_t length = valueList.length();
49 for (size_t index = 0; index < length; ++index) {
50 if (interpolationRequiresStyleResolve(*valueList.item(index)))
51 return true;
52 }
53 return false;
54 }
55
56 if (value.isShadowValue()) {
57 const CSSShadowValue& shadowValue = toCSSShadowValue(value);
58 return (shadowValue.x && interpolationRequiresStyleResolve(*shadowValue. x))
59 || (shadowValue.y && interpolationRequiresStyleResolve(*shadowValue. y))
60 || (shadowValue.blur && interpolationRequiresStyleResolve(*shadowVal ue.blur))
61 || (shadowValue.spread && interpolationRequiresStyleResolve(*shadowV alue.spread))
62 || (shadowValue.style && interpolationRequiresStyleResolve(*shadowVa lue.style))
63 || (shadowValue.color && interpolationRequiresStyleResolve(*shadowVa lue.color));
64 }
65
66 return false;
dstockwell 2014/05/09 05:57:09 Which cases aren't handled here? Can this be a swi
67 }
68
69 bool LegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSPrimit iveValue& primitiveValue)
70 {
71 if (primitiveValue.isCalculated()) {
72 CSSLengthArray lengthArray;
73 CSSPrimitiveValue::zeroLengthArray(lengthArray);
74 primitiveValue.accumulateLengthArray(lengthArray);
75 return lengthArray[CSSPrimitiveValue::UnitTypeFontSize]
dstockwell 2014/05/09 05:57:09 Clearer to use != 0 here.
76 || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize]
77 || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize]
78 || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth]
79 || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth]
80 || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight]
81 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin]
82 || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax];
dstockwell 2014/05/09 05:57:09 Presumably this logic should live somewhere else?
83 }
84
85 if (primitiveValue.isLength())
86 return primitiveValue.isFontRelativeLength() || primitiveValue.isViewpor tPercentageLength();
87
88 if (Pair* pair = primitiveValue.getPairValue()) {
89 return interpolationRequiresStyleResolve(*pair->first())
90 || interpolationRequiresStyleResolve(*pair->second());
91 }
92
93 if (Rect* rect = primitiveValue.getRectValue()) {
94 return interpolationRequiresStyleResolve(*rect->top())
95 || interpolationRequiresStyleResolve(*rect->right())
96 || interpolationRequiresStyleResolve(*rect->bottom())
97 || interpolationRequiresStyleResolve(*rect->left());
98 }
99
100 if (Quad* quad = primitiveValue.getQuadValue()) {
101 return interpolationRequiresStyleResolve(*quad->top())
102 || interpolationRequiresStyleResolve(*quad->right())
103 || interpolationRequiresStyleResolve(*quad->bottom())
104 || interpolationRequiresStyleResolve(*quad->left());
105 }
106
107 switch (primitiveValue.getValueID()) {
108 case CSSValueBolder:
109 case CSSValueCurrentcolor:
110 case CSSValueHigher:
111 case CSSValueLarger:
112 case CSSValueLighter:
113 case CSSValueLower:
114 case CSSValueSmaller:
115 return true;
116 default:
dstockwell 2014/05/09 05:57:09 How do we avoid hitting other important cases?
117 return false;
118 }
119 }
120
121 void LegacyStyleInterpolation::trace(Visitor* visitor)
122 {
123 StyleInterpolation::trace(visitor);
124 visitor->trace(m_startCSSValue);
125 visitor->trace(m_endCSSValue);
126 }
127
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698