File: style_timeline.h

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 (117 lines) | stat: -rw-r--r-- 4,355 bytes parent folder | download | duplicates (3)
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
// Copyright 2022 The Chromium Authors
// 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_STYLE_STYLE_TIMELINE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_TIMELINE_H_

#include <optional>
#include <utility>
#include <variant>

#include "base/check_op.h"
#include "base/memory/values_equivalent.h"
#include "third_party/blink/renderer/core/animation/timeline_inset.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/scoped_css_name.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"

namespace blink {

// https://drafts.csswg.org/css-animations-2/#typedef-single-animation-timeline
class CORE_EXPORT StyleTimeline {
 public:
  // https://drafts.csswg.org/scroll-animations-1/#scroll-notation
  class ScrollData {
   public:
    // https://drafts.csswg.org/scroll-animations-1/#valdef-scroll-block
    static TimelineAxis DefaultAxis() { return TimelineAxis::kBlock; }
    // https://drafts.csswg.org/scroll-animations-1/#valdef-scroll-nearest
    static TimelineScroller DefaultScroller() {
      return TimelineScroller::kNearest;
    }

    ScrollData(TimelineAxis axis, TimelineScroller scroller)
        : axis_(axis), scroller_(scroller) {}
    bool operator==(const ScrollData& other) const {
      return axis_ == other.axis_ && scroller_ == other.scroller_;
    }
    bool operator!=(const ScrollData& other) const { return !(*this == other); }

    TimelineAxis GetAxis() const { return axis_; }
    const TimelineScroller& GetScroller() const { return scroller_; }

    bool HasDefaultAxis() const { return axis_ == DefaultAxis(); }
    bool HasDefaultScroller() const { return scroller_ == DefaultScroller(); }

   private:
    TimelineAxis axis_;
    TimelineScroller scroller_;
  };

  // https://drafts.csswg.org/scroll-animations-1/#view-notation
  class ViewData {
   public:
    static TimelineAxis DefaultAxis() { return TimelineAxis::kBlock; }

    ViewData(TimelineAxis axis, TimelineInset inset)
        : axis_(axis), inset_(inset) {}

    bool operator==(const ViewData& other) const {
      return axis_ == other.axis_ && inset_ == other.inset_;
    }
    bool operator!=(const ViewData& other) const { return !(*this == other); }

    TimelineAxis GetAxis() const { return axis_; }
    TimelineInset GetInset() const { return inset_; }
    bool HasDefaultAxis() const { return axis_ == DefaultAxis(); }
    bool HasDefaultInset() const {
      return inset_.GetStart().IsAuto() && inset_.GetEnd().IsAuto();
    }

   private:
    TimelineAxis axis_;
    TimelineInset inset_;
  };

  explicit StyleTimeline(CSSValueID keyword) : data_(keyword) {}
  explicit StyleTimeline(const ScopedCSSName* name)
      : data_(std::in_place_type<Persistent<const ScopedCSSName>>, name) {}
  explicit StyleTimeline(const ScrollData& scroll_data) : data_(scroll_data) {}
  explicit StyleTimeline(const ViewData& view_data) : data_(view_data) {}

  bool operator==(const StyleTimeline& other) const {
    if (IsName() && other.IsName()) {
      return base::ValuesEquivalent(&GetName(), &other.GetName());
    }
    return data_ == other.data_;
  }
  bool operator!=(const StyleTimeline& other) const {
    return !(*this == other);
  }

  bool IsKeyword() const { return std::holds_alternative<CSSValueID>(data_); }
  bool IsName() const {
    return std::holds_alternative<Persistent<const ScopedCSSName>>(data_);
  }
  bool IsScroll() const { return std::holds_alternative<ScrollData>(data_); }
  bool IsView() const { return std::holds_alternative<ViewData>(data_); }

  const CSSValueID& GetKeyword() const { return std::get<CSSValueID>(data_); }
  const ScopedCSSName& GetName() const {
    return *std::get<Persistent<const ScopedCSSName>>(data_);
  }
  const ScrollData& GetScroll() const { return std::get<ScrollData>(data_); }
  const ViewData& GetView() const { return std::get<ViewData>(data_); }

 private:
  std::
      variant<CSSValueID, Persistent<const ScopedCSSName>, ScrollData, ViewData>
          data_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_STYLE_STYLE_TIMELINE_H_