OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CSSPositionAxisListInterpolationType.h" | 5 #include "core/animation/CSSPositionAxisListInterpolationType.h" |
6 | 6 |
7 #include "core/animation/LengthInterpolationFunctions.h" | 7 #include "core/animation/LengthInterpolationFunctions.h" |
8 #include "core/animation/ListInterpolationFunctions.h" | 8 #include "core/animation/ListInterpolationFunctions.h" |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSIdentifierValue.h" |
10 #include "core/css/CSSValueList.h" | 10 #include "core/css/CSSValueList.h" |
11 #include "core/css/CSSValuePair.h" | 11 #include "core/css/CSSValuePair.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 InterpolationValue CSSPositionAxisListInterpolationType::convertPositionAxisCSSV
alue(const CSSValue& value) | 15 InterpolationValue CSSPositionAxisListInterpolationType::convertPositionAxisCSSV
alue(const CSSValue& value) |
16 { | 16 { |
17 if (value.isValuePair()) { | 17 if (value.isValuePair()) { |
18 const CSSValuePair& pair = toCSSValuePair(value); | 18 const CSSValuePair& pair = toCSSValuePair(value); |
19 InterpolationValue result = LengthInterpolationFunctions::maybeConvertCS
SValue(pair.second()); | 19 InterpolationValue result = LengthInterpolationFunctions::maybeConvertCS
SValue(pair.second()); |
20 CSSValueID side = toCSSPrimitiveValue(pair.first()).getValueID(); | 20 CSSValueID side = toCSSIdentifierValue(pair.first()).getValueID(); |
21 if (side == CSSValueRight || side == CSSValueBottom) | 21 if (side == CSSValueRight || side == CSSValueBottom) |
22 LengthInterpolationFunctions::subtractFromOneHundredPercent(result); | 22 LengthInterpolationFunctions::subtractFromOneHundredPercent(result); |
23 return result; | 23 return result; |
24 } | 24 } |
25 | 25 |
26 if (!value.isPrimitiveValue()) | 26 if (value.isPrimitiveValue()) |
| 27 return LengthInterpolationFunctions::maybeConvertCSSValue(value); |
| 28 |
| 29 if (!value.isIdentifierValue()) |
27 return nullptr; | 30 return nullptr; |
28 | 31 |
29 const CSSPrimitiveValue& primitveValue = toCSSPrimitiveValue(value); | 32 const CSSIdentifierValue& ident = toCSSIdentifierValue(value); |
30 if (!primitveValue.isValueID()) | 33 switch (ident.getValueID()) { |
31 return LengthInterpolationFunctions::maybeConvertCSSValue(value); | |
32 | |
33 switch (primitveValue.getValueID()) { | |
34 case CSSValueLeft: | 34 case CSSValueLeft: |
35 case CSSValueTop: | 35 case CSSValueTop: |
36 return LengthInterpolationFunctions::createInterpolablePercent(0); | 36 return LengthInterpolationFunctions::createInterpolablePercent(0); |
37 case CSSValueRight: | 37 case CSSValueRight: |
38 case CSSValueBottom: | 38 case CSSValueBottom: |
39 return LengthInterpolationFunctions::createInterpolablePercent(100); | 39 return LengthInterpolationFunctions::createInterpolablePercent(100); |
40 case CSSValueCenter: | 40 case CSSValueCenter: |
41 return LengthInterpolationFunctions::createInterpolablePercent(50); | 41 return LengthInterpolationFunctions::createInterpolablePercent(50); |
42 default: | 42 default: |
43 NOTREACHED(); | 43 NOTREACHED(); |
44 return nullptr; | 44 return nullptr; |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 InterpolationValue CSSPositionAxisListInterpolationType::maybeConvertValue(const
CSSValue& value, const StyleResolverState&, ConversionCheckers&) const | 48 InterpolationValue CSSPositionAxisListInterpolationType::maybeConvertValue(const
CSSValue& value, const StyleResolverState&, ConversionCheckers&) const |
49 { | 49 { |
50 if (!value.isBaseValueList()) { | 50 if (!value.isBaseValueList()) { |
51 return ListInterpolationFunctions::createList(1, [&value](size_t) { | 51 return ListInterpolationFunctions::createList(1, [&value](size_t) { |
52 return convertPositionAxisCSSValue(value); | 52 return convertPositionAxisCSSValue(value); |
53 }); | 53 }); |
54 } | 54 } |
55 | 55 |
56 const CSSValueList& list = toCSSValueList(value); | 56 const CSSValueList& list = toCSSValueList(value); |
57 return ListInterpolationFunctions::createList(list.length(), [&list](size_t
index) { | 57 return ListInterpolationFunctions::createList(list.length(), [&list](size_t
index) { |
58 return convertPositionAxisCSSValue(list.item(index)); | 58 return convertPositionAxisCSSValue(list.item(index)); |
59 }); | 59 }); |
60 } | 60 } |
61 | 61 |
62 } // namespace blink | 62 } // namespace blink |
OLD | NEW |