CSSKeyframesRule.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/FlyString.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <LibJS/Heap/GCPtr.h>
  10. #include <LibWeb/CSS/CSSKeyframeRule.h>
  11. #include <LibWeb/CSS/CSSRule.h>
  12. #include <LibWeb/Forward.h>
  13. #include <LibWeb/WebIDL/ExceptionOr.h>
  14. namespace Web::CSS {
  15. // https://drafts.csswg.org/css-animations/#interface-csskeyframesrule
  16. class CSSKeyframesRule final : public CSSRule {
  17. WEB_PLATFORM_OBJECT(CSSKeyframesRule, CSSRule);
  18. JS_DECLARE_ALLOCATOR(CSSKeyframesRule);
  19. public:
  20. [[nodiscard]] static JS::NonnullGCPtr<CSSKeyframesRule> create(JS::Realm&, FlyString name, JS::MarkedVector<JS::NonnullGCPtr<CSSKeyframeRule>>);
  21. virtual ~CSSKeyframesRule() = default;
  22. virtual Type type() const override { return Type::Keyframes; }
  23. Vector<JS::NonnullGCPtr<CSSKeyframeRule>> const& keyframes() const { return m_keyframes; }
  24. FlyString const& name() const { return m_name; }
  25. size_t length() { return m_keyframes.size(); }
  26. void set_name(String const& name) { m_name = name; }
  27. private:
  28. CSSKeyframesRule(JS::Realm& realm, FlyString name, JS::MarkedVector<JS::NonnullGCPtr<CSSKeyframeRule>> keyframes)
  29. : CSSRule(realm)
  30. , m_name(move(name))
  31. , m_keyframes(move(keyframes))
  32. {
  33. }
  34. virtual void visit_edges(Visitor&) override;
  35. virtual void initialize(JS::Realm&) override;
  36. virtual String serialized() const override;
  37. FlyString m_name;
  38. Vector<JS::NonnullGCPtr<CSSKeyframeRule>> m_keyframes;
  39. };
  40. template<>
  41. inline bool CSSRule::fast_is<CSSKeyframesRule>() const { return type() == CSSRule::Type::Keyframes; }
  42. }