| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef LengthUnitsChecker_h |
| 6 #define LengthUnitsChecker_h |
| 7 |
| 8 #include "core/animation/InterpolationType.h" |
| 9 #include "core/css/CSSPrimitiveValue.h" |
| 10 #include "core/css/resolver/StyleResolverState.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class LengthUnitsChecker : public InterpolationType::ConversionChecker { |
| 15 public: |
| 16 static PassOwnPtr<LengthUnitsChecker> maybeCreate(CSSLengthArray&& lengthArr
ay, const StyleResolverState& state) |
| 17 { |
| 18 bool create = false; |
| 19 size_t lastIndex = 0; |
| 20 for (size_t i = 0; i < lengthArray.values.size(); i++) { |
| 21 if (i == CSSPrimitiveValue::UnitTypePercentage || !lengthArray.typeF
lags.get(i)) |
| 22 continue; |
| 23 lengthArray.values[i] = lengthUnit(i, state.cssToLengthConversionDat
a()); |
| 24 create = true; |
| 25 lastIndex = i; |
| 26 } |
| 27 if (!create) |
| 28 return nullptr; |
| 29 return adoptPtr(new LengthUnitsChecker(std::move(lengthArray), lastIndex
)); |
| 30 } |
| 31 |
| 32 bool isValid(const InterpolationEnvironment& environment, const Interpolatio
nValue& underlying) const final |
| 33 { |
| 34 for (size_t i = 0; i <= m_lastIndex; i++) { |
| 35 if (i == CSSPrimitiveValue::UnitTypePercentage || !m_lengthArray.typ
eFlags.get(i)) |
| 36 continue; |
| 37 if (m_lengthArray.values[i] != lengthUnit(i, environment.state().css
ToLengthConversionData())) |
| 38 return false; |
| 39 } |
| 40 return true; |
| 41 } |
| 42 |
| 43 static double lengthUnit(size_t lengthUnitType, const CSSToLengthConversionD
ata& conversionData) |
| 44 { |
| 45 return conversionData.zoomedComputedPixels(1, CSSPrimitiveValue::lengthU
nitTypeToUnitType(static_cast<CSSPrimitiveValue::LengthUnitType>(lengthUnitType)
)); |
| 46 } |
| 47 |
| 48 private: |
| 49 LengthUnitsChecker(CSSPrimitiveValue::CSSLengthArray&& lengthArray, size_t l
astIndex) |
| 50 : m_lengthArray(std::move(lengthArray)) |
| 51 , m_lastIndex(lastIndex) |
| 52 { } |
| 53 |
| 54 const CSSLengthArray m_lengthArray; |
| 55 const size_t m_lastIndex; |
| 56 }; |
| 57 |
| 58 } // namespace blink |
| 59 |
| 60 #endif // LengthUnitsChecker_h |
| OLD | NEW |