DOMRectList.cpp 1000 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright (c) 2022, DerpyCrabs <derpycrabs@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibWeb/Geometry/DOMRect.h>
  7. #include <LibWeb/Geometry/DOMRectList.h>
  8. namespace Web::Geometry {
  9. DOMRectList::DOMRectList(NonnullRefPtrVector<DOMRect>&& rects)
  10. : m_rects(move(rects))
  11. {
  12. }
  13. // https://drafts.fxtf.org/geometry-1/#dom-domrectlist-length
  14. u32 DOMRectList::length() const
  15. {
  16. return m_rects.size();
  17. }
  18. // https://drafts.fxtf.org/geometry-1/#dom-domrectlist-item
  19. DOMRect const* DOMRectList::item(u32 index) const
  20. {
  21. // The item(index) method, when invoked, must return null when
  22. // index is greater than or equal to the number of DOMRect objects associated with the DOMRectList.
  23. // Otherwise, the DOMRect object at index must be returned. Indices are zero-based.
  24. if (index >= m_rects.size())
  25. return nullptr;
  26. return &m_rects[index];
  27. }
  28. bool DOMRectList::is_supported_property_index(u32 index) const
  29. {
  30. return index < m_rects.size();
  31. }
  32. }