mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-26 04:02:27 +00:00
LibWeb: Add {,de}serialization steps for DOMRect
This commit is contained in:
parent
9f5fa4f4a0
commit
94c6389fc0
Notes:
sideshowbarker
2024-07-17 02:39:10 +09:00
Author: https://github.com/kennethmyhra
Commit: 94c6389fc0
Pull-request: https://github.com/SerenityOS/serenity/pull/23538
Reviewed-by: https://github.com/ADKaster
5 changed files with 23 additions and 0 deletions
|
@ -18,3 +18,5 @@ instanceOf DOMPoint: true
|
|||
DOMPoint: {"x":10,"y":20,"z":30,"w":40}
|
||||
instanceOf DOMRectReadOnly: true
|
||||
DOMRectReadOnly: {"x":10,"y":20,"width":30,"height":40,"top":20,"right":40,"bottom":60,"left":10}
|
||||
instanceOf DOMRect: true
|
||||
DOMRect: {"x":10,"y":20,"width":30,"height":40,"top":20,"right":40,"bottom":60,"left":10}
|
||||
|
|
|
@ -39,6 +39,10 @@
|
|||
println(`instanceOf DOMRectReadOnly: ${domRectReadOnly instanceof DOMRectReadOnly}`);
|
||||
println(`DOMRectReadOnly: ${JSON.stringify(domRectReadOnly)}`);
|
||||
|
||||
let domRect = structuredClone(new DOMRect(10, 20, 30, 40));
|
||||
println(`instanceOf DOMRect: ${domRect instanceof DOMRect}`);
|
||||
println(`DOMRect: ${JSON.stringify(domRect)}`);
|
||||
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -22,6 +22,11 @@ JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm, Gfx::FloatRect const
|
|||
return realm.heap().allocate<DOMRect>(realm, realm, rect.x(), rect.y(), rect.width(), rect.height());
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<DOMRect> DOMRect::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<DOMRect>(realm, realm);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
||||
JS::NonnullGCPtr<DOMRect> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||
{
|
||||
|
@ -34,6 +39,11 @@ DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double heig
|
|||
{
|
||||
}
|
||||
|
||||
DOMRect::DOMRect(JS::Realm& realm)
|
||||
: DOMRectReadOnly(realm)
|
||||
{
|
||||
}
|
||||
|
||||
DOMRect::~DOMRect() = default;
|
||||
|
||||
void DOMRect::initialize(JS::Realm& realm)
|
||||
|
|
|
@ -18,6 +18,7 @@ class DOMRect final : public DOMRectReadOnly {
|
|||
public:
|
||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRect> create(JS::Realm&, Gfx::FloatRect const&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRect> create(JS::Realm&);
|
||||
[[nodiscard]] static JS::NonnullGCPtr<DOMRect> from_rect(JS::VM&, DOMRectInit const&);
|
||||
|
||||
virtual ~DOMRect() override;
|
||||
|
@ -32,8 +33,11 @@ public:
|
|||
void set_width(double width) { m_rect.set_width(width); }
|
||||
void set_height(double height) { m_rect.set_height(height); }
|
||||
|
||||
virtual StringView interface_name() const override { return "DOMRect"sv; }
|
||||
|
||||
private:
|
||||
DOMRect(JS::Realm&, double x, double y, double width, double height);
|
||||
explicit DOMRect(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <LibWeb/Geometry/DOMMatrixReadOnly.h>
|
||||
#include <LibWeb/Geometry/DOMPoint.h>
|
||||
#include <LibWeb/Geometry/DOMPointReadOnly.h>
|
||||
#include <LibWeb/Geometry/DOMRect.h>
|
||||
#include <LibWeb/Geometry/DOMRectReadOnly.h>
|
||||
#include <LibWeb/HTML/MessagePort.h>
|
||||
#include <LibWeb/HTML/StructuredSerialize.h>
|
||||
|
@ -978,6 +979,8 @@ private:
|
|||
return Geometry::DOMPoint::create(realm);
|
||||
if (interface_name == "DOMRectReadOnly"sv)
|
||||
return Geometry::DOMRectReadOnly::create(realm);
|
||||
if (interface_name == "DOMRect"sv)
|
||||
return Geometry::DOMRect::create(realm);
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue