| Index: third_party/WebKit/Source/core/animation/LengthUnitsChecker.h
|
| diff --git a/third_party/WebKit/Source/core/animation/LengthUnitsChecker.h b/third_party/WebKit/Source/core/animation/LengthUnitsChecker.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..65570c489bd4e26a947c56f9d7b54497300560e5
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/animation/LengthUnitsChecker.h
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef LengthUnitsChecker_h
|
| +#define LengthUnitsChecker_h
|
| +
|
| +#include "core/animation/InterpolationType.h"
|
| +#include "core/css/CSSPrimitiveValue.h"
|
| +#include "core/css/resolver/StyleResolverState.h"
|
| +
|
| +namespace blink {
|
| +
|
| +class LengthUnitsChecker : public InterpolationType::ConversionChecker {
|
| +public:
|
| + static PassOwnPtr<LengthUnitsChecker> maybeCreate(CSSLengthArray&& lengthArray, const StyleResolverState& state)
|
| + {
|
| + bool create = false;
|
| + size_t lastIndex = 0;
|
| + for (size_t i = 0; i < lengthArray.values.size(); i++) {
|
| + if (i == CSSPrimitiveValue::UnitTypePercentage || !lengthArray.typeFlags.get(i))
|
| + continue;
|
| + lengthArray.values[i] = lengthUnit(i, state.cssToLengthConversionData());
|
| + create = true;
|
| + lastIndex = i;
|
| + }
|
| + if (!create)
|
| + return nullptr;
|
| + return adoptPtr(new LengthUnitsChecker(std::move(lengthArray), lastIndex));
|
| + }
|
| +
|
| + bool isValid(const InterpolationEnvironment& environment, const InterpolationValue& underlying) const final
|
| + {
|
| + for (size_t i = 0; i <= m_lastIndex; i++) {
|
| + if (i == CSSPrimitiveValue::UnitTypePercentage || !m_lengthArray.typeFlags.get(i))
|
| + continue;
|
| + if (m_lengthArray.values[i] != lengthUnit(i, environment.state().cssToLengthConversionData()))
|
| + return false;
|
| + }
|
| + return true;
|
| + }
|
| +
|
| + static double lengthUnit(size_t lengthUnitType, const CSSToLengthConversionData& conversionData)
|
| + {
|
| + return conversionData.zoomedComputedPixels(1, CSSPrimitiveValue::lengthUnitTypeToUnitType(static_cast<CSSPrimitiveValue::LengthUnitType>(lengthUnitType)));
|
| + }
|
| +
|
| +private:
|
| + LengthUnitsChecker(CSSPrimitiveValue::CSSLengthArray&& lengthArray, size_t lastIndex)
|
| + : m_lengthArray(std::move(lengthArray))
|
| + , m_lastIndex(lastIndex)
|
| + { }
|
| +
|
| + const CSSLengthArray m_lengthArray;
|
| + const size_t m_lastIndex;
|
| +};
|
| +
|
| +} // namespace blink
|
| +
|
| +#endif // LengthUnitsChecker_h
|
|
|