summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/core/animation/css_transform_origin_interpolation_type.h
blob: 60e18eef12fa6ff0a0f5e90fdf61875d4aad0888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 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 THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_TRANSFORM_ORIGIN_INTERPOLATION_TYPE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_TRANSFORM_ORIGIN_INTERPOLATION_TYPE_H_

#include "third_party/blink/renderer/core/animation/css_length_list_interpolation_type.h"
#include "third_party/blink/renderer/core/animation/css_position_axis_list_interpolation_type.h"
#include "third_party/blink/renderer/core/animation/interpolable_length.h"
#include "third_party/blink/renderer/core/animation/list_interpolation_functions.h"
#include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
#include "third_party/blink/renderer/core/css/css_value_list.h"

namespace blink {

class CSSTransformOriginInterpolationType
    : public CSSLengthListInterpolationType {
 public:
  CSSTransformOriginInterpolationType(PropertyHandle property)
      : CSSLengthListInterpolationType(property) {}

 private:
  InterpolationValue MaybeConvertValue(const CSSValue& value,
                                       const StyleResolverState*,
                                       ConversionCheckers&) const final {
    const CSSValueList& list = To<CSSValueList>(value);
    DCHECK_GE(list.length(), 2u);
    return ListInterpolationFunctions::CreateList(
        3, [&list](wtf_size_t index) {
          if (index == list.length()) {
            return InterpolationValue(InterpolableLength::MaybeConvertCSSValue(
                *CSSNumericLiteralValue::Create(
                    0, CSSPrimitiveValue::UnitType::kPixels)));
          }
          const CSSValue& item = list.Item(index);
          if (index < 2)
            return CSSPositionAxisListInterpolationType::
                ConvertPositionAxisCSSValue(item);
          return InterpolationValue(
              InterpolableLength::MaybeConvertCSSValue(item));
        });
  }
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_CSS_TRANSFORM_ORIGIN_INTERPOLATION_TYPE_H_