OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/animation/CSSLengthListInterpolationType.h" | 5 #include "core/animation/CSSLengthListInterpolationType.h" |
6 | 6 |
7 #include "core/animation/CSSLengthInterpolationType.h" | 7 #include "core/animation/CSSLengthInterpolationType.h" |
8 #include "core/animation/LengthListPropertyFunctions.h" | 8 #include "core/animation/LengthListPropertyFunctions.h" |
9 #include "core/animation/ListInterpolationFunctions.h" | 9 #include "core/animation/ListInterpolationFunctions.h" |
10 #include "core/animation/UnderlyingLengthChecker.h" | 10 #include "core/animation/UnderlyingLengthChecker.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 if (lengthList.isEmpty()) | 38 if (lengthList.isEmpty()) |
39 return nullptr; | 39 return nullptr; |
40 | 40 |
41 return ListInterpolationFunctions::createList(lengthList.size(), [&lengthLis
t, zoom](size_t index) { | 41 return ListInterpolationFunctions::createList(lengthList.size(), [&lengthLis
t, zoom](size_t index) { |
42 return CSSLengthInterpolationType::maybeConvertLength(lengthList[index],
zoom); | 42 return CSSLengthInterpolationType::maybeConvertLength(lengthList[index],
zoom); |
43 }); | 43 }); |
44 } | 44 } |
45 | 45 |
46 InterpolationValue CSSLengthListInterpolationType::maybeConvertInitial() const | 46 InterpolationValue CSSLengthListInterpolationType::maybeConvertInitial() const |
47 { | 47 { |
48 return maybeConvertLengthList(LengthListPropertyFunctions::getInitialLengthL
ist(cssProperty()), 1); | 48 Vector<Length> initialLengthList; |
| 49 if (!LengthListPropertyFunctions::getInitialLengthList(cssProperty(), initia
lLengthList)) |
| 50 return nullptr; |
| 51 return maybeConvertLengthList(initialLengthList, 1); |
49 } | 52 } |
50 | 53 |
51 class ParentLengthListChecker : public InterpolationType::ConversionChecker { | 54 class ParentLengthListChecker : public InterpolationType::ConversionChecker { |
52 public: | 55 public: |
53 ~ParentLengthListChecker() final {} | 56 ~ParentLengthListChecker() final {} |
54 | 57 |
55 static PassOwnPtr<ParentLengthListChecker> create(CSSPropertyID property, co
nst Vector<Length>& inheritedLengthList) | 58 static PassOwnPtr<ParentLengthListChecker> create(CSSPropertyID property, co
nst Vector<Length>& inheritedLengthList) |
56 { | 59 { |
57 return adoptPtr(new ParentLengthListChecker(property, inheritedLengthLis
t)); | 60 return adoptPtr(new ParentLengthListChecker(property, inheritedLengthLis
t)); |
58 } | 61 } |
59 | 62 |
60 private: | 63 private: |
61 ParentLengthListChecker(CSSPropertyID property, const Vector<Length>& inheri
tedLengthList) | 64 ParentLengthListChecker(CSSPropertyID property, const Vector<Length>& inheri
tedLengthList) |
62 : m_property(property) | 65 : m_property(property) |
63 , m_inheritedLengthList(inheritedLengthList) | 66 , m_inheritedLengthList(inheritedLengthList) |
64 { } | 67 { } |
65 | 68 |
66 bool isValid(const InterpolationEnvironment& environment, const Interpolatio
nValue& underlying) const final | 69 bool isValid(const InterpolationEnvironment& environment, const Interpolatio
nValue& underlying) const final |
67 { | 70 { |
68 return m_inheritedLengthList == LengthListPropertyFunctions::getLengthLi
st(m_property, *environment.state().parentStyle()); | 71 Vector<Length> inheritedLengthList; |
| 72 LengthListPropertyFunctions::getLengthList(m_property, *environment.stat
e().parentStyle(), inheritedLengthList); |
| 73 return m_inheritedLengthList == inheritedLengthList; |
69 } | 74 } |
70 | 75 |
71 CSSPropertyID m_property; | 76 CSSPropertyID m_property; |
72 Vector<Length> m_inheritedLengthList; | 77 Vector<Length> m_inheritedLengthList; |
73 }; | 78 }; |
74 | 79 |
75 InterpolationValue CSSLengthListInterpolationType::maybeConvertInherit(const Sty
leResolverState& state, ConversionCheckers& conversionCheckers) const | 80 InterpolationValue CSSLengthListInterpolationType::maybeConvertInherit(const Sty
leResolverState& state, ConversionCheckers& conversionCheckers) const |
76 { | 81 { |
77 if (!state.parentStyle()) | 82 Vector<Length> inheritedLengthList; |
| 83 bool success = LengthListPropertyFunctions::getLengthList(cssProperty(), *st
ate.parentStyle(), inheritedLengthList); |
| 84 conversionCheckers.append(ParentLengthListChecker::create(cssProperty(), inh
eritedLengthList)); |
| 85 if (!success) |
78 return nullptr; | 86 return nullptr; |
79 | |
80 Vector<Length> inheritedLengthList = LengthListPropertyFunctions::getLengthL
ist(cssProperty(), *state.parentStyle()); | |
81 conversionCheckers.append(ParentLengthListChecker::create(cssProperty(), inh
eritedLengthList)); | |
82 return maybeConvertLengthList(inheritedLengthList, state.parentStyle()->effe
ctiveZoom()); | 87 return maybeConvertLengthList(inheritedLengthList, state.parentStyle()->effe
ctiveZoom()); |
83 } | 88 } |
84 | 89 |
85 InterpolationValue CSSLengthListInterpolationType::maybeConvertValue(const CSSVa
lue& value, const StyleResolverState&, ConversionCheckers&) const | 90 InterpolationValue CSSLengthListInterpolationType::maybeConvertValue(const CSSVa
lue& value, const StyleResolverState&, ConversionCheckers&) const |
86 { | 91 { |
87 if (!value.isBaseValueList()) | 92 if (!value.isBaseValueList()) |
88 return nullptr; | 93 return nullptr; |
89 | 94 |
90 const CSSValueList& list = toCSSValueList(value); | 95 const CSSValueList& list = toCSSValueList(value); |
91 return ListInterpolationFunctions::createList(list.length(), [&list](size_t
index) { | 96 return ListInterpolationFunctions::createList(list.length(), [&list](size_t
index) { |
92 return CSSLengthInterpolationType::maybeConvertCSSValue(*list.item(index
)); | 97 return CSSLengthInterpolationType::maybeConvertCSSValue(*list.item(index
)); |
93 }); | 98 }); |
94 } | 99 } |
95 | 100 |
96 PairwiseInterpolationValue CSSLengthListInterpolationType::mergeSingleConversion
s(InterpolationValue& start, InterpolationValue& end) const | 101 PairwiseInterpolationValue CSSLengthListInterpolationType::mergeSingleConversion
s(InterpolationValue& start, InterpolationValue& end) const |
97 { | 102 { |
98 return ListInterpolationFunctions::mergeSingleConversions(start, end, CSSLen
gthInterpolationType::staticMergeSingleConversions); | 103 return ListInterpolationFunctions::mergeSingleConversions(start, end, CSSLen
gthInterpolationType::staticMergeSingleConversions); |
99 } | 104 } |
100 | 105 |
101 InterpolationValue CSSLengthListInterpolationType::maybeConvertUnderlyingValue(c
onst InterpolationEnvironment& environment) const | 106 InterpolationValue CSSLengthListInterpolationType::maybeConvertUnderlyingValue(c
onst InterpolationEnvironment& environment) const |
102 { | 107 { |
103 Vector<Length> underlyingLengthList = LengthListPropertyFunctions::getLength
List(cssProperty(), *environment.state().style()); | 108 Vector<Length> underlyingLengthList; |
| 109 if (!LengthListPropertyFunctions::getLengthList(cssProperty(), *environment.
state().style(), underlyingLengthList)) |
| 110 return nullptr; |
104 return maybeConvertLengthList(underlyingLengthList, environment.state().styl
e()->effectiveZoom()); | 111 return maybeConvertLengthList(underlyingLengthList, environment.state().styl
e()->effectiveZoom()); |
105 } | 112 } |
106 | 113 |
107 void CSSLengthListInterpolationType::composite(UnderlyingValueOwner& underlyingV
alueOwner, double underlyingFraction, const InterpolationValue& value) const | 114 void CSSLengthListInterpolationType::composite(UnderlyingValueOwner& underlyingV
alueOwner, double underlyingFraction, const InterpolationValue& value) const |
108 { | 115 { |
109 ListInterpolationFunctions::composite(underlyingValueOwner, underlyingFracti
on, *this, value, | 116 ListInterpolationFunctions::composite(underlyingValueOwner, underlyingFracti
on, *this, value, |
110 CSSLengthInterpolationType::nonInterpolableValuesAreCompatible, | 117 CSSLengthInterpolationType::nonInterpolableValuesAreCompatible, |
111 CSSLengthInterpolationType::composite); | 118 CSSLengthInterpolationType::composite); |
112 } | 119 } |
113 | 120 |
114 void CSSLengthListInterpolationType::apply(const InterpolableValue& interpolable
Value, const NonInterpolableValue* nonInterpolableValue, InterpolationEnvironmen
t& environment) const | 121 void CSSLengthListInterpolationType::apply(const InterpolableValue& interpolable
Value, const NonInterpolableValue* nonInterpolableValue, InterpolationEnvironmen
t& environment) const |
115 { | 122 { |
116 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); | 123 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); |
117 const size_t length = interpolableList.length(); | 124 const size_t length = interpolableList.length(); |
118 ASSERT(length > 0); | 125 ASSERT(length > 0); |
119 const NonInterpolableList& nonInterpolableList = toNonInterpolableList(*nonI
nterpolableValue); | 126 const NonInterpolableList& nonInterpolableList = toNonInterpolableList(*nonI
nterpolableValue); |
120 ASSERT(nonInterpolableList.length() == length); | 127 ASSERT(nonInterpolableList.length() == length); |
121 Vector<Length> result(length); | 128 Vector<Length> result(length); |
122 for (size_t i = 0; i < length; i++) { | 129 for (size_t i = 0; i < length; i++) { |
123 result[i] = CSSLengthInterpolationType::resolveInterpolableLength( | 130 result[i] = CSSLengthInterpolationType::resolveInterpolableLength( |
124 *interpolableList.get(i), | 131 *interpolableList.get(i), |
125 nonInterpolableList.get(i), | 132 nonInterpolableList.get(i), |
126 environment.state().cssToLengthConversionData(), | 133 environment.state().cssToLengthConversionData(), |
127 m_valueRange); | 134 m_valueRange); |
128 } | 135 } |
129 LengthListPropertyFunctions::setLengthList(cssProperty(), *environment.state
().style(), std::move(result)); | 136 LengthListPropertyFunctions::setLengthList(cssProperty(), *environment.state
().style(), std::move(result)); |
130 } | 137 } |
131 | 138 |
132 } // namespace blink | 139 } // namespace blink |
OLD | NEW |