SVGAnimatedRect.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2024, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/ExceptionOrUtils.h>
  7. #include <LibWeb/Bindings/Intrinsics.h>
  8. #include <LibWeb/Bindings/SVGAnimatedRectPrototype.h>
  9. #include <LibWeb/SVG/SVGAnimatedRect.h>
  10. namespace Web::SVG {
  11. JS_DEFINE_ALLOCATOR(SVGAnimatedRect);
  12. SVGAnimatedRect::SVGAnimatedRect(JS::Realm& realm)
  13. : Bindings::PlatformObject(realm)
  14. {
  15. }
  16. SVGAnimatedRect::~SVGAnimatedRect() = default;
  17. void SVGAnimatedRect::initialize(JS::Realm& realm)
  18. {
  19. Base::initialize(realm);
  20. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGAnimatedRect);
  21. m_base_val = Geometry::DOMRect::create(realm, { 0, 0, 0, 0 });
  22. m_anim_val = Geometry::DOMRect::create(realm, { 0, 0, 0, 0 });
  23. }
  24. void SVGAnimatedRect::visit_edges(Visitor& visitor)
  25. {
  26. Base::visit_edges(visitor);
  27. visitor.visit(m_base_val);
  28. visitor.visit(m_anim_val);
  29. }
  30. JS::GCPtr<Geometry::DOMRect> SVGAnimatedRect::base_val() const
  31. {
  32. if (m_nulled)
  33. return nullptr;
  34. return m_base_val;
  35. }
  36. JS::GCPtr<Geometry::DOMRect> SVGAnimatedRect::anim_val() const
  37. {
  38. if (m_nulled)
  39. return nullptr;
  40. return m_anim_val;
  41. }
  42. void SVGAnimatedRect::set_nulled(bool nulled)
  43. {
  44. m_nulled = nulled;
  45. }
  46. void SVGAnimatedRect::set_base_val(Gfx::DoubleRect const& rect)
  47. {
  48. m_base_val->set_x(rect.x());
  49. m_base_val->set_y(rect.y());
  50. m_base_val->set_width(rect.width());
  51. m_base_val->set_height(rect.height());
  52. }
  53. void SVGAnimatedRect::set_anim_val(Gfx::DoubleRect const& rect)
  54. {
  55. m_anim_val->set_x(rect.x());
  56. m_anim_val->set_y(rect.y());
  57. m_anim_val->set_width(rect.width());
  58. m_anim_val->set_height(rect.height());
  59. }
  60. }