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 #ifndef LengthUnitsChecker_h | 5 #ifndef LengthUnitsChecker_h |
6 #define LengthUnitsChecker_h | 6 #define LengthUnitsChecker_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include "core/animation/InterpolationType.h" | 9 #include "core/animation/CSSInterpolationType.h" |
10 #include "core/css/CSSPrimitiveValue.h" | 10 #include "core/css/CSSPrimitiveValue.h" |
11 #include "core/css/resolver/StyleResolverState.h" | 11 #include "core/css/resolver/StyleResolverState.h" |
12 #include "platform/wtf/PtrUtil.h" | 12 #include "platform/wtf/PtrUtil.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class LengthUnitsChecker : public InterpolationType::ConversionChecker { | 16 class LengthUnitsChecker : public CSSInterpolationType::CSSConversionChecker { |
17 public: | 17 public: |
18 static std::unique_ptr<LengthUnitsChecker> MaybeCreate( | 18 static std::unique_ptr<LengthUnitsChecker> MaybeCreate( |
19 CSSLengthArray&& length_array, | 19 CSSLengthArray&& length_array, |
20 const StyleResolverState& state) { | 20 const StyleResolverState& state) { |
21 bool create = false; | 21 bool create = false; |
22 size_t last_index = 0; | 22 size_t last_index = 0; |
23 for (size_t i = 0; i < length_array.values.size(); i++) { | 23 for (size_t i = 0; i < length_array.values.size(); i++) { |
24 if (i == CSSPrimitiveValue::kUnitTypePercentage || | 24 if (i == CSSPrimitiveValue::kUnitTypePercentage || |
25 !length_array.type_flags.Get(i)) | 25 !length_array.type_flags.Get(i)) |
26 continue; | 26 continue; |
27 length_array.values[i] = LengthUnit(i, state.CssToLengthConversionData()); | 27 length_array.values[i] = LengthUnit(i, state.CssToLengthConversionData()); |
28 create = true; | 28 create = true; |
29 last_index = i; | 29 last_index = i; |
30 } | 30 } |
31 if (!create) | 31 if (!create) |
32 return nullptr; | 32 return nullptr; |
33 return WTF::WrapUnique( | 33 return WTF::WrapUnique( |
34 new LengthUnitsChecker(std::move(length_array), last_index)); | 34 new LengthUnitsChecker(std::move(length_array), last_index)); |
35 } | 35 } |
36 | 36 |
37 bool IsValid(const InterpolationEnvironment& environment, | 37 bool IsValid(const StyleResolverState& state, |
38 const InterpolationValue& underlying) const final { | 38 const InterpolationValue& underlying) const final { |
39 for (size_t i = 0; i <= last_index_; i++) { | 39 for (size_t i = 0; i <= last_index_; i++) { |
40 if (i == CSSPrimitiveValue::kUnitTypePercentage || | 40 if (i == CSSPrimitiveValue::kUnitTypePercentage || |
41 !length_array_.type_flags.Get(i)) | 41 !length_array_.type_flags.Get(i)) |
42 continue; | 42 continue; |
43 if (length_array_.values[i] != | 43 if (length_array_.values[i] != |
44 LengthUnit(i, environment.GetState().CssToLengthConversionData())) | 44 LengthUnit(i, state.CssToLengthConversionData())) |
45 return false; | 45 return false; |
46 } | 46 } |
47 return true; | 47 return true; |
48 } | 48 } |
49 | 49 |
50 static double LengthUnit(size_t length_unit_type, | 50 static double LengthUnit(size_t length_unit_type, |
51 const CSSToLengthConversionData& conversion_data) { | 51 const CSSToLengthConversionData& conversion_data) { |
52 return conversion_data.ZoomedComputedPixels( | 52 return conversion_data.ZoomedComputedPixels( |
53 1, | 53 1, |
54 CSSPrimitiveValue::LengthUnitTypeToUnitType( | 54 CSSPrimitiveValue::LengthUnitTypeToUnitType( |
55 static_cast<CSSPrimitiveValue::LengthUnitType>(length_unit_type))); | 55 static_cast<CSSPrimitiveValue::LengthUnitType>(length_unit_type))); |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 LengthUnitsChecker(CSSPrimitiveValue::CSSLengthArray&& length_array, | 59 LengthUnitsChecker(CSSPrimitiveValue::CSSLengthArray&& length_array, |
60 size_t last_index) | 60 size_t last_index) |
61 : length_array_(std::move(length_array)), last_index_(last_index) {} | 61 : length_array_(std::move(length_array)), last_index_(last_index) {} |
62 | 62 |
63 const CSSLengthArray length_array_; | 63 const CSSLengthArray length_array_; |
64 const size_t last_index_; | 64 const size_t last_index_; |
65 }; | 65 }; |
66 | 66 |
67 } // namespace blink | 67 } // namespace blink |
68 | 68 |
69 #endif // LengthUnitsChecker_h | 69 #endif // LengthUnitsChecker_h |
OLD | NEW |