SVGTransformList.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2024, MacDue <macdue@dueutil.tech>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Bindings/Intrinsics.h>
  7. #include <LibWeb/SVG/SVGTransformList.h>
  8. #include <LibWeb/WebIDL/ExceptionOr.h>
  9. namespace Web::SVG {
  10. JS_DEFINE_ALLOCATOR(SVGTransformList);
  11. JS::NonnullGCPtr<SVGTransformList> SVGTransformList::create(JS::Realm& realm)
  12. {
  13. return realm.heap().allocate<SVGTransformList>(realm, realm);
  14. }
  15. SVGTransformList::~SVGTransformList() = default;
  16. SVGTransformList::SVGTransformList(JS::Realm& realm)
  17. : PlatformObject(realm) {};
  18. // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__getItem
  19. WebIDL::ExceptionOr<JS::NonnullGCPtr<SVGTransform>> SVGTransformList::get_item(WebIDL::UnsignedLong index)
  20. {
  21. // 1. If index is greater than or equal to the length of the list, then throw an IndexSizeError.
  22. if (index >= m_transforms.size())
  23. return WebIDL::IndexSizeError::create(realm(), "SVGTransformList index out of bounds"_fly_string);
  24. // 2. Return the element in the list at position index.
  25. return m_transforms.at(index);
  26. }
  27. // https://svgwg.org/svg2-draft/single-page.html#types-__svg__SVGNameList__appendItem
  28. JS::NonnullGCPtr<SVGTransform> SVGTransformList::append_item(JS::NonnullGCPtr<SVGTransform> new_item)
  29. {
  30. // FIXME: This does not implement the steps from the specification.
  31. m_transforms.append(new_item);
  32. return new_item;
  33. }
  34. void SVGTransformList::initialize(JS::Realm& realm)
  35. {
  36. Base::initialize(realm);
  37. WEB_SET_PROTOTYPE_FOR_INTERFACE(SVGTransformList);
  38. }
  39. void SVGTransformList::visit_edges(Cell::Visitor& visitor)
  40. {
  41. Base::visit_edges(visitor);
  42. for (auto transform : m_transforms)
  43. transform->visit_edges(visitor);
  44. }
  45. }