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 "core/animation/InterpolationType.h" | 8 #include "core/animation/InterpolationType.h" |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
11 #include "wtf/PtrUtil.h" | |
12 #include <memory> | |
13 | 11 |
14 namespace blink { | 12 namespace blink { |
15 | 13 |
16 class LengthUnitsChecker : public InterpolationType::ConversionChecker { | 14 class LengthUnitsChecker : public InterpolationType::ConversionChecker { |
17 public: | 15 public: |
18 static std::unique_ptr<LengthUnitsChecker> maybeCreate(CSSLengthArray&& leng
thArray, const StyleResolverState& state) | 16 static PassOwnPtr<LengthUnitsChecker> maybeCreate(CSSLengthArray&& lengthArr
ay, const StyleResolverState& state) |
19 { | 17 { |
20 bool create = false; | 18 bool create = false; |
21 size_t lastIndex = 0; | 19 size_t lastIndex = 0; |
22 for (size_t i = 0; i < lengthArray.values.size(); i++) { | 20 for (size_t i = 0; i < lengthArray.values.size(); i++) { |
23 if (i == CSSPrimitiveValue::UnitTypePercentage || !lengthArray.typeF
lags.get(i)) | 21 if (i == CSSPrimitiveValue::UnitTypePercentage || !lengthArray.typeF
lags.get(i)) |
24 continue; | 22 continue; |
25 lengthArray.values[i] = lengthUnit(i, state.cssToLengthConversionDat
a()); | 23 lengthArray.values[i] = lengthUnit(i, state.cssToLengthConversionDat
a()); |
26 create = true; | 24 create = true; |
27 lastIndex = i; | 25 lastIndex = i; |
28 } | 26 } |
29 if (!create) | 27 if (!create) |
30 return nullptr; | 28 return nullptr; |
31 return wrapUnique(new LengthUnitsChecker(std::move(lengthArray), lastInd
ex)); | 29 return adoptPtr(new LengthUnitsChecker(std::move(lengthArray), lastIndex
)); |
32 } | 30 } |
33 | 31 |
34 bool isValid(const InterpolationEnvironment& environment, const Interpolatio
nValue& underlying) const final | 32 bool isValid(const InterpolationEnvironment& environment, const Interpolatio
nValue& underlying) const final |
35 { | 33 { |
36 for (size_t i = 0; i <= m_lastIndex; i++) { | 34 for (size_t i = 0; i <= m_lastIndex; i++) { |
37 if (i == CSSPrimitiveValue::UnitTypePercentage || !m_lengthArray.typ
eFlags.get(i)) | 35 if (i == CSSPrimitiveValue::UnitTypePercentage || !m_lengthArray.typ
eFlags.get(i)) |
38 continue; | 36 continue; |
39 if (m_lengthArray.values[i] != lengthUnit(i, environment.state().css
ToLengthConversionData())) | 37 if (m_lengthArray.values[i] != lengthUnit(i, environment.state().css
ToLengthConversionData())) |
40 return false; | 38 return false; |
41 } | 39 } |
(...skipping 11 matching lines...) Expand all Loading... |
53 , m_lastIndex(lastIndex) | 51 , m_lastIndex(lastIndex) |
54 { } | 52 { } |
55 | 53 |
56 const CSSLengthArray m_lengthArray; | 54 const CSSLengthArray m_lengthArray; |
57 const size_t m_lastIndex; | 55 const size_t m_lastIndex; |
58 }; | 56 }; |
59 | 57 |
60 } // namespace blink | 58 } // namespace blink |
61 | 59 |
62 #endif // LengthUnitsChecker_h | 60 #endif // LengthUnitsChecker_h |
OLD | NEW |