mirror of
https://github.com/RGBCube/serenity
synced 2025-05-23 23:55:06 +00:00
LibWeb: Implement Geometry::DOMRectList
Implement DOMRectList that is used as a return type of getClientRects functions on Element and Range.
This commit is contained in:
parent
0532d7d255
commit
2f828231c4
7 changed files with 101 additions and 0 deletions
|
@ -2295,6 +2295,7 @@ void generate_implementation(IDL::Interface const& interface)
|
||||||
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
||||||
#include <LibWeb/Bindings/CommentWrapper.h>
|
#include <LibWeb/Bindings/CommentWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
||||||
|
#include <LibWeb/Bindings/DOMRectListWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMRectWrapper.h>
|
#include <LibWeb/Bindings/DOMRectWrapper.h>
|
||||||
#include <LibWeb/Bindings/DocumentFragmentWrapper.h>
|
#include <LibWeb/Bindings/DocumentFragmentWrapper.h>
|
||||||
#include <LibWeb/Bindings/DocumentTypeWrapper.h>
|
#include <LibWeb/Bindings/DocumentTypeWrapper.h>
|
||||||
|
@ -3462,6 +3463,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
|
||||||
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
||||||
#include <LibWeb/Bindings/CommentWrapper.h>
|
#include <LibWeb/Bindings/CommentWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
||||||
|
#include <LibWeb/Bindings/DOMRectListWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMRectWrapper.h>
|
#include <LibWeb/Bindings/DOMRectWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMStringMapWrapper.h>
|
#include <LibWeb/Bindings/DOMStringMapWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMTokenListWrapper.h>
|
#include <LibWeb/Bindings/DOMTokenListWrapper.h>
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
#include <LibWeb/Bindings/DOMParserConstructor.h>
|
#include <LibWeb/Bindings/DOMParserConstructor.h>
|
||||||
#include <LibWeb/Bindings/DOMParserPrototype.h>
|
#include <LibWeb/Bindings/DOMParserPrototype.h>
|
||||||
#include <LibWeb/Bindings/DOMRectConstructor.h>
|
#include <LibWeb/Bindings/DOMRectConstructor.h>
|
||||||
|
#include <LibWeb/Bindings/DOMRectListConstructor.h>
|
||||||
|
#include <LibWeb/Bindings/DOMRectListPrototype.h>
|
||||||
#include <LibWeb/Bindings/DOMRectPrototype.h>
|
#include <LibWeb/Bindings/DOMRectPrototype.h>
|
||||||
#include <LibWeb/Bindings/DOMRectReadOnlyConstructor.h>
|
#include <LibWeb/Bindings/DOMRectReadOnlyConstructor.h>
|
||||||
#include <LibWeb/Bindings/DOMRectReadOnlyPrototype.h>
|
#include <LibWeb/Bindings/DOMRectReadOnlyPrototype.h>
|
||||||
|
@ -338,6 +340,7 @@
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(DOMImplementation) \
|
ADD_WINDOW_OBJECT_INTERFACE(DOMImplementation) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(DOMParser) \
|
ADD_WINDOW_OBJECT_INTERFACE(DOMParser) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(DOMRect) \
|
ADD_WINDOW_OBJECT_INTERFACE(DOMRect) \
|
||||||
|
ADD_WINDOW_OBJECT_INTERFACE(DOMRectList) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(DOMRectReadOnly) \
|
ADD_WINDOW_OBJECT_INTERFACE(DOMRectReadOnly) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(DOMStringMap) \
|
ADD_WINDOW_OBJECT_INTERFACE(DOMStringMap) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(Element) \
|
ADD_WINDOW_OBJECT_INTERFACE(Element) \
|
||||||
|
|
|
@ -95,6 +95,7 @@ set(SOURCES
|
||||||
Encoding/TextEncoder.cpp
|
Encoding/TextEncoder.cpp
|
||||||
Fetch/AbstractOperations.cpp
|
Fetch/AbstractOperations.cpp
|
||||||
FontCache.cpp
|
FontCache.cpp
|
||||||
|
Geometry/DOMRectList.cpp
|
||||||
HTML/AttributeNames.cpp
|
HTML/AttributeNames.cpp
|
||||||
HTML/BrowsingContext.cpp
|
HTML/BrowsingContext.cpp
|
||||||
HTML/BrowsingContextContainer.cpp
|
HTML/BrowsingContextContainer.cpp
|
||||||
|
@ -420,6 +421,7 @@ libweb_js_wrapper(DOM/ShadowRoot)
|
||||||
libweb_js_wrapper(DOM/Text)
|
libweb_js_wrapper(DOM/Text)
|
||||||
libweb_js_wrapper(Encoding/TextEncoder)
|
libweb_js_wrapper(Encoding/TextEncoder)
|
||||||
libweb_js_wrapper(Geometry/DOMRect)
|
libweb_js_wrapper(Geometry/DOMRect)
|
||||||
|
libweb_js_wrapper(Geometry/DOMRectList)
|
||||||
libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
||||||
libweb_js_wrapper(HTML/CanvasGradient)
|
libweb_js_wrapper(HTML/CanvasGradient)
|
||||||
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
||||||
|
|
|
@ -118,6 +118,7 @@ class TextEncoder;
|
||||||
|
|
||||||
namespace Web::Geometry {
|
namespace Web::Geometry {
|
||||||
class DOMRect;
|
class DOMRect;
|
||||||
|
class DOMRectList;
|
||||||
class DOMRectReadOnly;
|
class DOMRectReadOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,6 +346,7 @@ class DocumentWrapper;
|
||||||
class DOMExceptionWrapper;
|
class DOMExceptionWrapper;
|
||||||
class DOMImplementationWrapper;
|
class DOMImplementationWrapper;
|
||||||
class DOMParserWrapper;
|
class DOMParserWrapper;
|
||||||
|
class DOMRectListWrapper;
|
||||||
class DOMRectReadOnlyWrapper;
|
class DOMRectReadOnlyWrapper;
|
||||||
class DOMRectWrapper;
|
class DOMRectWrapper;
|
||||||
class DOMStringMapWrapper;
|
class DOMStringMapWrapper;
|
||||||
|
|
39
Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp
Normal file
39
Userland/Libraries/LibWeb/Geometry/DOMRectList.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, DerpyCrabs <derpycrabs@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Geometry/DOMRect.h>
|
||||||
|
#include <LibWeb/Geometry/DOMRectList.h>
|
||||||
|
|
||||||
|
namespace Web::Geometry {
|
||||||
|
|
||||||
|
DOMRectList::DOMRectList(NonnullRefPtrVector<DOMRect>&& rects)
|
||||||
|
: m_rects(move(rects))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
Userland/Libraries/LibWeb/Geometry/DOMRectList.h
Normal file
47
Userland/Libraries/LibWeb/Geometry/DOMRectList.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, DerpyCrabs <derpycrabs@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Noncopyable.h>
|
||||||
|
#include <AK/NonnullRefPtrVector.h>
|
||||||
|
#include <AK/RefCounted.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
|
#include <LibWeb/Bindings/Wrappable.h>
|
||||||
|
#include <LibWeb/Forward.h>
|
||||||
|
#include <LibWeb/Geometry/DOMRect.h>
|
||||||
|
|
||||||
|
namespace Web::Geometry {
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry-1/#DOMRectList
|
||||||
|
class DOMRectList final
|
||||||
|
: public RefCounted<DOMRectList>
|
||||||
|
, public Bindings::Wrappable {
|
||||||
|
AK_MAKE_NONCOPYABLE(DOMRectList);
|
||||||
|
AK_MAKE_NONMOVABLE(DOMRectList);
|
||||||
|
|
||||||
|
public:
|
||||||
|
using WrapperType = Bindings::DOMRectListWrapper;
|
||||||
|
|
||||||
|
static NonnullRefPtr<DOMRectList> create(NonnullRefPtrVector<DOMRect>&& rects)
|
||||||
|
{
|
||||||
|
return adopt_ref(*new DOMRectList(move(rects)));
|
||||||
|
}
|
||||||
|
|
||||||
|
~DOMRectList() = default;
|
||||||
|
|
||||||
|
u32 length() const;
|
||||||
|
DOMRect const* item(u32 index) const;
|
||||||
|
|
||||||
|
bool is_supported_property_index(u32) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DOMRectList(NonnullRefPtrVector<DOMRect>&& rects);
|
||||||
|
|
||||||
|
NonnullRefPtrVector<DOMRect> m_rects;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
6
Userland/Libraries/LibWeb/Geometry/DOMRectList.idl
Normal file
6
Userland/Libraries/LibWeb/Geometry/DOMRectList.idl
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
[Exposed=Window]
|
||||||
|
interface DOMRectList {
|
||||||
|
getter DOMRect? item(unsigned long index);
|
||||||
|
readonly attribute unsigned long length;
|
||||||
|
iterable<DOMRect>;
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue