blob: 39ad35236166a3562bc99d519ab7dee256ee3847 (
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
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright 2015 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.
#include "third_party/blink/renderer/core/animation/svg_rect_interpolation_type.h"
#include <memory>
#include <utility>
#include "third_party/blink/renderer/core/animation/interpolation_environment.h"
#include "third_party/blink/renderer/core/animation/string_keyframe.h"
#include "third_party/blink/renderer/core/svg/svg_rect.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"
namespace blink {
enum RectComponentIndex : unsigned {
kRectX,
kRectY,
kRectWidth,
kRectHeight,
kRectComponentIndexCount,
};
InterpolationValue SVGRectInterpolationType::MaybeConvertNeutral(
const InterpolationValue&,
ConversionCheckers&) const {
auto result = std::make_unique<InterpolableList>(kRectComponentIndexCount);
for (wtf_size_t i = 0; i < kRectComponentIndexCount; i++)
result->Set(i, std::make_unique<InterpolableNumber>(0));
return InterpolationValue(std::move(result));
}
InterpolationValue SVGRectInterpolationType::MaybeConvertSVGValue(
const SVGPropertyBase& svg_value) const {
if (svg_value.GetType() != kAnimatedRect)
return nullptr;
const SVGRect& rect = ToSVGRect(svg_value);
auto result = std::make_unique<InterpolableList>(kRectComponentIndexCount);
result->Set(kRectX, std::make_unique<InterpolableNumber>(rect.X()));
result->Set(kRectY, std::make_unique<InterpolableNumber>(rect.Y()));
result->Set(kRectWidth, std::make_unique<InterpolableNumber>(rect.Width()));
result->Set(kRectHeight, std::make_unique<InterpolableNumber>(rect.Height()));
return InterpolationValue(std::move(result));
}
SVGPropertyBase* SVGRectInterpolationType::AppliedSVGValue(
const InterpolableValue& interpolable_value,
const NonInterpolableValue*) const {
const InterpolableList& list = ToInterpolableList(interpolable_value);
auto* result = MakeGarbageCollected<SVGRect>();
result->SetX(ToInterpolableNumber(list.Get(kRectX))->Value());
result->SetY(ToInterpolableNumber(list.Get(kRectY))->Value());
result->SetWidth(ToInterpolableNumber(list.Get(kRectWidth))->Value());
result->SetHeight(ToInterpolableNumber(list.Get(kRectHeight))->Value());
return result;
}
} // namespace blink
|