blob: c0888e51241293af9b2895e5ed06dd049e4e375b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
* Copyright (c) 2022, DerpyCrabs <derpycrabs@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Heap/Handle.h>
#include <LibWeb/Geometry/DOMRect.h>
#include <LibWeb/Geometry/DOMRectList.h>
#include <LibWeb/HTML/Window.h>
namespace Web::Geometry {
JS::NonnullGCPtr<DOMRectList> DOMRectList::create(HTML::Window& window, Vector<JS::Handle<DOMRect>> rect_handles)
{
Vector<JS::NonnullGCPtr<DOMRect>> rects;
for (auto& rect : rect_handles)
rects.append(*rect);
return *window.heap().allocate<DOMRectList>(window.realm(), window, move(rects));
}
DOMRectList::DOMRectList(HTML::Window& window, Vector<JS::NonnullGCPtr<DOMRect>> rects)
: Bindings::LegacyPlatformObject(window.cached_web_prototype("DOMRectList"))
, m_rects(move(rects))
{
}
DOMRectList::~DOMRectList() = default;
// https://drafts.fxtf.org/geometry-1/#dom-domrectlist-length
u32 DOMRectList::length() const
{
return m_rects.size();
}
// https://drafts.fxtf.org/geometry-1/#dom-domrectlist-item
DOMRect const* DOMRectList::item(u32 index) const
{
// The item(index) method, when invoked, must return null when
// index is greater than or equal to the number of DOMRect objects associated with the DOMRectList.
// Otherwise, the DOMRect object at index must be returned. Indices are zero-based.
if (index >= m_rects.size())
return nullptr;
return m_rects[index];
}
bool DOMRectList::is_supported_property_index(u32 index) const
{
return index < m_rects.size();
}
JS::Value DOMRectList::item_value(size_t index) const
{
if (index >= m_rects.size())
return JS::js_undefined();
return m_rects[index].ptr();
}
}
|