OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/animation/AnimatableLength.h" | 32 #include "core/animation/AnimatableLength.h" |
33 | 33 |
34 #include "core/css/CSSPrimitiveValueMappings.h" | 34 #include "core/css/CSSPrimitiveValueMappings.h" |
35 #include "platform/CalculationValue.h" | 35 #include "platform/CalculationValue.h" |
36 #include "platform/animation/AnimationUtilities.h" | 36 #include "platform/animation/AnimationUtilities.h" |
37 | 37 |
38 namespace WebCore { | 38 namespace WebCore { |
39 | 39 |
40 PassRefPtr<AnimatableLength> AnimatableLength::create(CSSValue* value) | 40 PassRefPtrWillBeRawPtr<AnimatableLength> AnimatableLength::create(CSSValue* valu
e) |
41 { | 41 { |
42 ASSERT(canCreateFrom(value)); | 42 ASSERT(canCreateFrom(value)); |
43 if (value->isPrimitiveValue()) { | 43 if (value->isPrimitiveValue()) { |
44 CSSPrimitiveValue* primitiveValue = WebCore::toCSSPrimitiveValue(value); | 44 CSSPrimitiveValue* primitiveValue = WebCore::toCSSPrimitiveValue(value); |
45 const CSSCalcValue* calcValue = primitiveValue->cssCalcValue(); | 45 const CSSCalcValue* calcValue = primitiveValue->cssCalcValue(); |
46 if (calcValue) | 46 if (calcValue) |
47 return create(calcValue->expressionNode(), primitiveValue); | 47 return create(calcValue->expressionNode(), primitiveValue); |
48 NumberUnitType unitType; | 48 NumberUnitType unitType; |
49 bool isPrimitiveLength = primitiveUnitToNumberType(primitiveValue->primi
tiveType(), unitType); | 49 bool isPrimitiveLength = primitiveUnitToNumberType(primitiveValue->primi
tiveType(), unitType); |
50 ASSERT_UNUSED(isPrimitiveLength, isPrimitiveLength); | 50 ASSERT_UNUSED(isPrimitiveLength, isPrimitiveLength); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return toCSSPrimitiveValue(range)->convertToLength<AnyConversion>(conversion
Data); | 90 return toCSSPrimitiveValue(range)->convertToLength<AnyConversion>(conversion
Data); |
91 } | 91 } |
92 | 92 |
93 bool AnimatableLength::usesDefaultInterpolationWith(const AnimatableValue* value
) const | 93 bool AnimatableLength::usesDefaultInterpolationWith(const AnimatableValue* value
) const |
94 { | 94 { |
95 const AnimatableLength* length = toAnimatableLength(value); | 95 const AnimatableLength* length = toAnimatableLength(value); |
96 NumberUnitType type = commonUnitType(length); | 96 NumberUnitType type = commonUnitType(length); |
97 return type == UnitTypeCalc && (isViewportUnit() || length->isViewportUnit()
); | 97 return type == UnitTypeCalc && (isViewportUnit() || length->isViewportUnit()
); |
98 } | 98 } |
99 | 99 |
100 PassRefPtr<AnimatableValue> AnimatableLength::interpolateTo(const AnimatableValu
e* value, double fraction) const | 100 PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableLength::interpolateTo(const An
imatableValue* value, double fraction) const |
101 { | 101 { |
102 const AnimatableLength* length = toAnimatableLength(value); | 102 const AnimatableLength* length = toAnimatableLength(value); |
103 NumberUnitType type = commonUnitType(length); | 103 NumberUnitType type = commonUnitType(length); |
104 if (type != UnitTypeCalc) | 104 if (type != UnitTypeCalc) |
105 return AnimatableLength::create(blend(m_number, length->m_number, fracti
on), type); | 105 return AnimatableLength::create(blend(m_number, length->m_number, fracti
on), type); |
106 | 106 |
107 // FIXME(crbug.com/168840): Support for viewport units in calc needs to be a
dded before we can blend them with other units. | 107 // FIXME(crbug.com/168840): Support for viewport units in calc needs to be a
dded before we can blend them with other units. |
108 if (isViewportUnit() || length->isViewportUnit()) | 108 if (isViewportUnit() || length->isViewportUnit()) |
109 return defaultInterpolateTo(this, value, fraction); | 109 return defaultInterpolateTo(this, value, fraction); |
110 | 110 |
111 return AnimatableLength::create(scale(1 - fraction).get(), length->scale(fra
ction).get()); | 111 return AnimatableLength::create(scale(1 - fraction).get(), length->scale(fra
ction).get()); |
112 } | 112 } |
113 | 113 |
114 PassRefPtr<AnimatableValue> AnimatableLength::addWith(const AnimatableValue* val
ue) const | 114 PassRefPtrWillBeRawPtr<AnimatableValue> AnimatableLength::addWith(const Animatab
leValue* value) const |
115 { | 115 { |
116 // Optimization for adding with 0. | 116 // Optimization for adding with 0. |
117 if (isUnitlessZero()) | 117 if (isUnitlessZero()) |
118 return takeConstRef(value); | 118 return takeConstRef(value); |
119 | 119 |
120 const AnimatableLength* length = toAnimatableLength(value); | 120 const AnimatableLength* length = toAnimatableLength(value); |
121 if (length->isUnitlessZero()) | 121 if (length->isUnitlessZero()) |
122 return takeConstRef(this); | 122 return takeConstRef(this); |
123 | 123 |
124 NumberUnitType type = commonUnitType(length); | 124 NumberUnitType type = commonUnitType(length); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 { | 159 { |
160 if (!m_cachedCSSPrimitiveValue || !isCompatibleWithRange(m_cachedCSSPrimitiv
eValue.get(), range)) { | 160 if (!m_cachedCSSPrimitiveValue || !isCompatibleWithRange(m_cachedCSSPrimitiv
eValue.get(), range)) { |
161 if (isCalc()) | 161 if (isCalc()) |
162 m_cachedCSSPrimitiveValue = CSSPrimitiveValue::create(CSSCalcValue::
create(m_calcExpression, range == AllValues ? ValueRangeAll : ValueRangeNonNegat
ive)); | 162 m_cachedCSSPrimitiveValue = CSSPrimitiveValue::create(CSSCalcValue::
create(m_calcExpression, range == AllValues ? ValueRangeAll : ValueRangeNonNegat
ive)); |
163 else | 163 else |
164 m_cachedCSSPrimitiveValue = CSSPrimitiveValue::create(clampedNumber(
range), static_cast<CSSPrimitiveValue::UnitTypes>(numberTypeToPrimitiveUnit(m_un
itType))); | 164 m_cachedCSSPrimitiveValue = CSSPrimitiveValue::create(clampedNumber(
range), static_cast<CSSPrimitiveValue::UnitTypes>(numberTypeToPrimitiveUnit(m_un
itType))); |
165 } | 165 } |
166 return m_cachedCSSPrimitiveValue; | 166 return m_cachedCSSPrimitiveValue; |
167 } | 167 } |
168 | 168 |
169 PassRefPtr<AnimatableLength> AnimatableLength::scale(double factor) const | 169 PassRefPtrWillBeRawPtr<AnimatableLength> AnimatableLength::scale(double factor)
const |
170 { | 170 { |
171 if (isCalc()) { | 171 if (isCalc()) { |
172 return AnimatableLength::create(CSSCalcValue::createExpressionNode( | 172 return AnimatableLength::create(CSSCalcValue::createExpressionNode( |
173 m_calcExpression, | 173 m_calcExpression, |
174 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(factor,
CSSPrimitiveValue::CSS_NUMBER)), | 174 CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(factor,
CSSPrimitiveValue::CSS_NUMBER)), |
175 CalcMultiply)); | 175 CalcMultiply)); |
176 } | 176 } |
177 return AnimatableLength::create(m_number * factor, m_unitType); | 177 return AnimatableLength::create(m_number * factor, m_unitType); |
178 } | 178 } |
179 | 179 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return CSSPrimitiveValue::CSS_VMIN; | 238 return CSSPrimitiveValue::CSS_VMIN; |
239 case UnitTypeViewportMax: | 239 case UnitTypeViewportMax: |
240 return CSSPrimitiveValue::CSS_VMAX; | 240 return CSSPrimitiveValue::CSS_VMAX; |
241 case UnitTypeCalc: | 241 case UnitTypeCalc: |
242 return CSSPrimitiveValue::CSS_UNKNOWN; | 242 return CSSPrimitiveValue::CSS_UNKNOWN; |
243 } | 243 } |
244 ASSERT_NOT_REACHED(); | 244 ASSERT_NOT_REACHED(); |
245 return CSSPrimitiveValue::CSS_UNKNOWN; | 245 return CSSPrimitiveValue::CSS_UNKNOWN; |
246 } | 246 } |
247 | 247 |
| 248 void AnimatableLength::trace(Visitor* visitor) |
| 249 { |
| 250 visitor->trace(m_calcExpression); |
| 251 visitor->trace(m_cachedCSSPrimitiveValue); |
| 252 } |
| 253 |
248 } // namespace WebCore | 254 } // namespace WebCore |
OLD | NEW |