File: transition_keyframe.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (123 lines) | stat: -rw-r--r-- 4,869 bytes parent folder | download | duplicates (5)
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
// Copyright 2017 The Chromium Authors
// 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/transition_keyframe.h"

#include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h"
#include "third_party/blink/renderer/core/animation/animation_input_helpers.h"
#include "third_party/blink/renderer/core/animation/animation_utils.h"
#include "third_party/blink/renderer/core/animation/compositor_animations.h"
#include "third_party/blink/renderer/core/animation/css_interpolation_environment.h"
#include "third_party/blink/renderer/core/animation/interpolation_type.h"
#include "third_party/blink/renderer/core/animation/interpolation_types_map.h"
#include "third_party/blink/renderer/core/animation/pairwise_interpolation_value.h"
#include "third_party/blink/renderer/core/animation/property_handle.h"
#include "third_party/blink/renderer/core/animation/transition_interpolation.h"
#include "third_party/blink/renderer/core/css/properties/css_property_ref.h"
#include "third_party/blink/renderer/core/css/resolver/style_resolver.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/style/computed_style.h"

namespace blink {

namespace {

class PropertyIterator : public Keyframe::VirtualPropertyIterator {
 public:
  explicit PropertyIterator(const PropertyHandle* property)
      : property_(property) {}
  ~PropertyIterator() override = default;
  void Advance(const Keyframe*) override { property_ = nullptr; }
  PropertyHandle Deref(const Keyframe*) const override { return *property_; }
  bool AtEnd(const Keyframe*) const override { return !property_; }

 private:
  const PropertyHandle* property_ = nullptr;
};

}  // namespace

Keyframe::PropertyIteratorWrapper
TransitionKeyframe::IterableTransitionKeyframeProperty::begin() const {
  return Keyframe::PropertyIteratorWrapper(
      nullptr, std::make_unique<PropertyIterator>(&property_));
}

void TransitionKeyframe::SetCompositorValue(
    CompositorKeyframeValue* compositor_value) {
  DCHECK_EQ(Property().GetCSSProperty().IsCompositableProperty(),
            static_cast<bool>(compositor_value));
  compositor_value_ = compositor_value;
}

void TransitionKeyframe::AddKeyframePropertiesToV8Object(
    V8ObjectBuilder& object_builder,
    Element* element) const {
  Keyframe::AddKeyframePropertiesToV8Object(object_builder, element);

  // TODO(crbug.com/933761): Fix resolution of the style in the case where the
  // target element has been removed.
  if (!element)
    return;

  Document& document = element->GetDocument();
  StyleResolverState state(document, *element);
  state.SetStyle(document.GetStyleResolver().InitialStyle());
  state.EnsureParentStyle();
  InterpolationTypesMap map(document.GetPropertyRegistry(), document);
  CSSInterpolationEnvironment environment(map, state);
  value_->GetType()->Apply(value_->GetInterpolableValue(),
                           value_->GetNonInterpolableValue(), environment);

  const ComputedStyle* style = state.TakeStyle();
  String property_value =
      AnimationUtils::KeyframeValueFromComputedStyle(
          Property(), *style, document, element->GetLayoutObject())
          ->CssText();

  String property_name =
      AnimationInputHelpers::PropertyHandleToKeyframeAttribute(Property());
  object_builder.AddString(property_name, property_value);
}

void TransitionKeyframe::Trace(Visitor* visitor) const {
  visitor->Trace(value_);
  visitor->Trace(compositor_value_);
  Keyframe::Trace(visitor);
}

Keyframe::PropertySpecificKeyframe*
TransitionKeyframe::CreatePropertySpecificKeyframe(
    const PropertyHandle& property,
    EffectModel::CompositeOperation effect_composite,
    double offset) const {
  DCHECK(property == Property());
  DCHECK(offset == offset_);
  EffectModel::CompositeOperation composite =
      composite_.value_or(effect_composite);
  return MakeGarbageCollected<PropertySpecificKeyframe>(
      CheckedOffset(), &Easing(), composite, value_->Clone(),
      compositor_value_);
}

Interpolation*
TransitionKeyframe::PropertySpecificKeyframe::CreateInterpolation(
    const PropertyHandle& property,
    const Keyframe::PropertySpecificKeyframe& other_super_class) const {
  const auto& other = To<TransitionPropertySpecificKeyframe>(other_super_class);
  DCHECK(value_->GetType() == other.value_->GetType());
  return MakeGarbageCollected<TransitionInterpolation>(
      property, value_->GetType(), value_->Value().Clone(),
      other.value_->Value().Clone(), compositor_value_,
      other.compositor_value_);
}

void TransitionKeyframe::PropertySpecificKeyframe::Trace(
    Visitor* visitor) const {
  visitor->Trace(value_);
  visitor->Trace(compositor_value_);
  Keyframe::PropertySpecificKeyframe::Trace(visitor);
}

}  // namespace blink