CSSKeyframeRule.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/NonnullRefPtr.h>
  8. #include <LibWeb/CSS/CSSRule.h>
  9. #include <LibWeb/CSS/CSSStyleDeclaration.h>
  10. #include <LibWeb/CSS/Percentage.h>
  11. #include <LibWeb/Forward.h>
  12. #include <LibWeb/WebIDL/ExceptionOr.h>
  13. namespace Web::CSS {
  14. // https://drafts.csswg.org/css-animations/#interface-csskeyframerule
  15. class CSSKeyframeRule final : public CSSRule {
  16. WEB_PLATFORM_OBJECT(CSSKeyframeRule, CSSRule);
  17. public:
  18. static WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSKeyframeRule>> create(JS::Realm& realm, CSS::Percentage key, CSSStyleDeclaration& declarations)
  19. {
  20. return MUST_OR_THROW_OOM(realm.heap().allocate<CSSKeyframeRule>(realm, realm, key, declarations));
  21. }
  22. virtual ~CSSKeyframeRule() = default;
  23. virtual Type type() const override { return Type::Keyframe; };
  24. CSS::Percentage key() const { return m_key; }
  25. JS::NonnullGCPtr<CSSStyleDeclaration> style() const { return m_declarations; }
  26. DeprecatedString key_text() const
  27. {
  28. return m_key.to_string().release_value_but_fixme_should_propagate_errors().to_deprecated_string();
  29. }
  30. void set_key_text(DeprecatedString const& key_text)
  31. {
  32. dbgln("FIXME: CSSKeyframeRule::set_key_text is not implemented: {}", key_text);
  33. }
  34. private:
  35. CSSKeyframeRule(JS::Realm& realm, CSS::Percentage key, CSSStyleDeclaration& declarations)
  36. : CSSRule(realm)
  37. , m_key(key)
  38. , m_declarations(declarations)
  39. {
  40. }
  41. virtual void visit_edges(Visitor&) override;
  42. virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
  43. virtual DeprecatedString serialized() const override;
  44. CSS::Percentage m_key;
  45. JS::NonnullGCPtr<CSSStyleDeclaration> m_declarations;
  46. };
  47. template<>
  48. inline bool CSSRule::fast_is<CSSKeyframeRule>() const { return type() == CSSRule::Type::Keyframe; }
  49. }