| // Copyright 2021 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_ASPECT_RATIO_H_ |
| #define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_ASPECT_RATIO_H_ |
| |
| #include <memory> |
| #include "third_party/blink/renderer/core/animation/interpolable_value.h" |
| #include "third_party/blink/renderer/core/style/style_aspect_ratio.h" |
| |
| namespace blink { |
| |
| // Represents a blink::StyleAspectRatio, converted into its logarithm for |
| // interpolation. |
| class CORE_EXPORT InterpolableAspectRatio final : public InterpolableValue { |
| public: |
| explicit InterpolableAspectRatio(const FloatSize& ratio); |
| explicit InterpolableAspectRatio(std::unique_ptr<InterpolableValue> value) |
| : value_(std::move(value)) {} |
| |
| static std::unique_ptr<InterpolableAspectRatio> MaybeCreate( |
| const StyleAspectRatio&); |
| |
| FloatSize GetRatio() const; |
| |
| // InterpolableValue implementation: |
| void Interpolate(const InterpolableValue& to, |
| const double progress, |
| InterpolableValue& result) const final; |
| bool IsAspectRatio() 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; |
| void AssertCanInterpolateWith(const InterpolableValue& other) const final; |
| |
| private: |
| InterpolableAspectRatio* RawClone() const final { |
| return new InterpolableAspectRatio(value_->Clone()); |
| } |
| InterpolableAspectRatio* RawCloneAndZero() const final { |
| return new InterpolableAspectRatio(value_->CloneAndZero()); |
| } |
| |
| // Interpolable aspect ratio value is stored and interpolated as the log of |
| // the real aspect ratio. |
| std::unique_ptr<InterpolableValue> value_; |
| }; |
| |
| template <> |
| struct DowncastTraits<InterpolableAspectRatio> { |
| static bool AllowFrom(const InterpolableValue& interpolable_value) { |
| return interpolable_value.IsAspectRatio(); |
| } |
| }; |
| |
| } // namespace blink |
| |
| #endif // THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_INTERPOLABLE_ASPECT_RATIO_H_ |