File: transition_keyframe.h

package info (click to toggle)
chromium 90.0.4430.212-1~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,450,632 kB
  • sloc: cpp: 19,832,434; javascript: 2,948,838; ansic: 2,312,399; python: 1,464,622; xml: 584,121; java: 514,189; asm: 470,557; objc: 83,463; perl: 77,861; sh: 77,030; cs: 70,789; fortran: 24,137; tcl: 18,916; php: 18,872; makefile: 16,848; ruby: 16,721; pascal: 13,150; sql: 10,199; yacc: 7,507; lex: 1,313; lisp: 840; awk: 329; jsp: 39; sed: 19
file content (131 lines) | stat: -rw-r--r-- 4,947 bytes parent folder | download | duplicates (2)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2017 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_TRANSITION_KEYFRAME_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_ANIMATION_TRANSITION_KEYFRAME_H_

#include "third_party/blink/renderer/core/animation/css/compositor_keyframe_value.h"
#include "third_party/blink/renderer/core/animation/keyframe.h"
#include "third_party/blink/renderer/core/animation/typed_interpolation_value.h"
#include "third_party/blink/renderer/core/core_export.h"

namespace blink {

// An implementation of Keyframe specifically for CSS Transitions.
//
// TransitionKeyframes are a simple form of keyframe, which only have one
// (property, value) pair. CSS Transitions do not support SVG attributes, so the
// property will always be a CSSPropertyID (for CSS properties and presentation
// attributes) or an AtomicString (for custom CSS properties).
class CORE_EXPORT TransitionKeyframe : public Keyframe {
 public:
  TransitionKeyframe(const PropertyHandle& property) : property_(property) {
    DCHECK(!property.IsSVGAttribute());
  }

  TransitionKeyframe(const TransitionKeyframe& copy_from)
      : Keyframe(copy_from.offset_, copy_from.composite_, copy_from.easing_),
        property_(copy_from.property_),
        value_(copy_from.value_->Clone()),
        compositor_value_(copy_from.compositor_value_) {}

  void SetValue(std::unique_ptr<TypedInterpolationValue> value) {
    // Speculative CHECK to help investigate crbug.com/826627. The theory is
    // that |SetValue| is being called with a |value| that has no underlying
    // InterpolableValue. This then would later cause a crash in the
    // TransitionInterpolation constructor.
    // TODO(crbug.com/826627): Revert once bug is fixed.
    CHECK(!!value->Value());
    value_ = std::move(value);
  }
  void SetCompositorValue(CompositorKeyframeValue*);
  PropertyHandleSet Properties() const final;

  void AddKeyframePropertiesToV8Object(V8ObjectBuilder&,
                                       Element*) const override;

  void Trace(Visitor*) const override;

  class PropertySpecificKeyframe : public Keyframe::PropertySpecificKeyframe {
   public:
    PropertySpecificKeyframe(double offset,
                             scoped_refptr<TimingFunction> easing,
                             EffectModel::CompositeOperation composite,
                             std::unique_ptr<TypedInterpolationValue> value,
                             CompositorKeyframeValue* compositor_value)
        : Keyframe::PropertySpecificKeyframe(offset,
                                             std::move(easing),
                                             composite),
          value_(std::move(value)),
          compositor_value_(compositor_value) {}

    const CompositorKeyframeValue* GetCompositorKeyframeValue() const final {
      return compositor_value_;
    }

    bool IsNeutral() const final { return false; }
    bool IsRevert() const final { return false; }
    Keyframe::PropertySpecificKeyframe* NeutralKeyframe(
        double offset,
        scoped_refptr<TimingFunction> easing) const final {
      NOTREACHED();
      return nullptr;
    }
    Interpolation* CreateInterpolation(
        const PropertyHandle&,
        const Keyframe::PropertySpecificKeyframe& other) const final;

    bool IsTransitionPropertySpecificKeyframe() const final { return true; }

    const TypedInterpolationValue* GetValue() const { return value_.get(); }

    void Trace(Visitor*) const override;

   private:
    Keyframe::PropertySpecificKeyframe* CloneWithOffset(
        double offset) const final {
      return MakeGarbageCollected<PropertySpecificKeyframe>(
          offset, easing_, composite_, value_->Clone(), compositor_value_);
    }

    std::unique_ptr<TypedInterpolationValue> value_;
    Member<CompositorKeyframeValue> compositor_value_;
  };

 private:
  bool IsTransitionKeyframe() const final { return true; }

  Keyframe* Clone() const final {
    return MakeGarbageCollected<TransitionKeyframe>(*this);
  }

  Keyframe::PropertySpecificKeyframe* CreatePropertySpecificKeyframe(
      const PropertyHandle&,
      EffectModel::CompositeOperation effect_composite,
      double offset) const final;

  PropertyHandle property_;
  std::unique_ptr<TypedInterpolationValue> value_;
  Member<CompositorKeyframeValue> compositor_value_;
};

using TransitionPropertySpecificKeyframe =
    TransitionKeyframe::PropertySpecificKeyframe;

template <>
struct DowncastTraits<TransitionKeyframe> {
  static bool AllowFrom(const Keyframe& value) {
    return value.IsTransitionKeyframe();
  }
};
template <>
struct DowncastTraits<TransitionPropertySpecificKeyframe> {
  static bool AllowFrom(const Keyframe::PropertySpecificKeyframe& value) {
    return value.IsTransitionPropertySpecificKeyframe();
  }
};

}  // namespace blink

#endif