CSSKeyframeRule.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CSSKeyframeRule.h"
  7. #include <LibWeb/Bindings/CSSKeyframeRulePrototype.h>
  8. #include <LibWeb/Bindings/Intrinsics.h>
  9. #include <LibWeb/CSS/CSSRuleList.h>
  10. namespace Web::CSS {
  11. JS_DEFINE_ALLOCATOR(CSSKeyframeRule);
  12. JS::NonnullGCPtr<CSSKeyframeRule> CSSKeyframeRule::create(JS::Realm& realm, CSS::Percentage key, Web::CSS::PropertyOwningCSSStyleDeclaration& declarations)
  13. {
  14. return realm.heap().allocate<CSSKeyframeRule>(realm, realm, key, declarations);
  15. }
  16. CSSKeyframeRule::CSSKeyframeRule(JS::Realm& realm, CSS::Percentage key, PropertyOwningCSSStyleDeclaration& declarations)
  17. : CSSRule(realm)
  18. , m_key(key)
  19. , m_declarations(declarations)
  20. {
  21. m_declarations->set_parent_rule(*this);
  22. }
  23. void CSSKeyframeRule::visit_edges(Visitor& visitor)
  24. {
  25. Base::visit_edges(visitor);
  26. visitor.visit(m_declarations);
  27. }
  28. void CSSKeyframeRule::initialize(JS::Realm& realm)
  29. {
  30. Base::initialize(realm);
  31. WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSKeyframeRule);
  32. }
  33. String CSSKeyframeRule::serialized() const
  34. {
  35. StringBuilder builder;
  36. builder.appendff("{}% {{ {} }}", key().value(), style()->serialized());
  37. return MUST(builder.to_string());
  38. }
  39. }