blob: 02ce93022dc423ae838091f9646667133f568ffb (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// 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_INTERPOLABLE_LENGTH_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_LENGTH_H_
#include <memory>
#include "third_party/blink/renderer/core/animation/interpolation_value.h"
#include "third_party/blink/renderer/core/animation/pairwise_interpolation_value.h"
#include "third_party/blink/renderer/core/css/css_primitive_value.h"
#include "third_party/blink/renderer/platform/geometry/length.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
namespace blink {
class CSSToLengthConversionData;
class CSSMathExpressionNode;
class CORE_EXPORT InterpolableLength final : public InterpolableValue {
public:
~InterpolableLength() final {}
InterpolableLength(CSSLengthArray&& length_array);
explicit InterpolableLength(const CSSMathExpressionNode& expression);
static std::unique_ptr<InterpolableLength> CreatePixels(double pixels);
static std::unique_ptr<InterpolableLength> CreatePercent(double pixels);
static std::unique_ptr<InterpolableLength> CreateNeutral();
static std::unique_ptr<InterpolableLength> MaybeConvertCSSValue(
const CSSValue& value);
static std::unique_ptr<InterpolableLength> MaybeConvertLength(
const Length& length,
float zoom);
static PairwiseInterpolationValue MergeSingles(
std::unique_ptr<InterpolableValue> start,
std::unique_ptr<InterpolableValue> end);
Length CreateLength(const CSSToLengthConversionData& conversion_data,
ValueRange range) const;
// Unlike CreateLength() this preserves all specified unit types via calc()
// expressions.
const CSSPrimitiveValue* CreateCSSValue(ValueRange range) const;
void SetHasPercentage();
bool HasPercentage() const;
void SubtractFromOneHundredPercent();
std::unique_ptr<InterpolableLength> Clone() const {
return std::unique_ptr<InterpolableLength>(RawClone());
}
std::unique_ptr<InterpolableLength> CloneAndZero() const {
return std::unique_ptr<InterpolableLength>(RawCloneAndZero());
}
// InterpolableValue:
void Interpolate(const InterpolableValue& to,
const double progress,
InterpolableValue& result) const final;
bool IsLength() const final { return true; }
bool Equals(const InterpolableValue& other) const final {
NOTREACHED();
return false;
}
void Scale(double scale) final;
void Add(const InterpolableValue& other) final;
// We override this to avoid two passes in the case of LengthArrays.
void ScaleAndAdd(double scale, const InterpolableValue& other) final;
void AssertCanInterpolateWith(const InterpolableValue& other) const final;
private:
InterpolableLength* RawClone() const final;
InterpolableLength* RawCloneAndZero() const final {
return new InterpolableLength(CSSLengthArray());
}
bool IsLengthArray() const { return type_ == Type::kLengthArray; }
bool IsExpression() const { return type_ == Type::kExpression; }
void SetLengthArray(CSSLengthArray&& length_array);
void SetExpression(const CSSMathExpressionNode& expression);
const CSSMathExpressionNode& AsExpression() const;
enum class Type { kLengthArray, kExpression };
Type type_;
CSSLengthArray length_array_;
Persistent<const CSSMathExpressionNode> expression_;
};
template <>
struct DowncastTraits<InterpolableLength> {
static bool AllowFrom(const InterpolableValue& interpolable_value) {
return interpolable_value.IsLength();
}
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_LENGTH_H_
|