mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +00:00
LibWeb: Implement DOMRect(ReadOnly)#fromRect
This will also be used by IntersectionObserver.
This commit is contained in:
parent
1d426df262
commit
6f8afd8cd9
6 changed files with 35 additions and 0 deletions
|
@ -20,6 +20,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::create(JS::Realm& realm,
|
||||||
return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height());
|
return construct_impl(realm, rect.x(), rect.y(), rect.width(), rect.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> DOMRect::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||||
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRect>(realm, realm, other.x, other.y, other.width, other.height));
|
||||||
|
}
|
||||||
|
|
||||||
DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
|
DOMRect::DOMRect(JS::Realm& realm, double x, double y, double width, double height)
|
||||||
: DOMRectReadOnly(realm, x, y, width, height)
|
: DOMRectReadOnly(realm, x, y, width, height)
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,6 +17,7 @@ class DOMRect final : public DOMRectReadOnly {
|
||||||
public:
|
public:
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> create(JS::Realm&, Gfx::FloatRect const&);
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> create(JS::Realm&, Gfx::FloatRect const&);
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRect>> from_rect(JS::VM&, DOMRectInit const&);
|
||||||
|
|
||||||
virtual ~DOMRect() override;
|
virtual ~DOMRect() override;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ interface DOMRect : DOMRectReadOnly {
|
||||||
|
|
||||||
constructor(optional double x = 0, optional double y = 0, optional double width = 0, optional double height = 0);
|
constructor(optional double x = 0, optional double y = 0, optional double width = 0, optional double height = 0);
|
||||||
|
|
||||||
|
[NewObject] static DOMRect fromRect(optional DOMRectInit other = {});
|
||||||
|
|
||||||
attribute double x;
|
attribute double x;
|
||||||
attribute double y;
|
attribute double y;
|
||||||
attribute double width;
|
attribute double width;
|
||||||
|
|
|
@ -15,6 +15,13 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::construc
|
||||||
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height));
|
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, x, y, width, height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#create-a-domrect-from-the-dictionary
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> DOMRectReadOnly::from_rect(JS::VM& vm, Geometry::DOMRectInit const& other)
|
||||||
|
{
|
||||||
|
auto& realm = *vm.current_realm();
|
||||||
|
return MUST_OR_THROW_OOM(realm.heap().allocate<DOMRectReadOnly>(realm, realm, other.x, other.y, other.width, other.height));
|
||||||
|
}
|
||||||
|
|
||||||
DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
|
DOMRectReadOnly::DOMRectReadOnly(JS::Realm& realm, double x, double y, double width, double height)
|
||||||
: PlatformObject(realm)
|
: PlatformObject(realm)
|
||||||
, m_rect(x, y, width, height)
|
, m_rect(x, y, width, height)
|
||||||
|
|
|
@ -12,12 +12,21 @@
|
||||||
|
|
||||||
namespace Web::Geometry {
|
namespace Web::Geometry {
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dictdef-domrectinit
|
||||||
|
struct DOMRectInit {
|
||||||
|
double x { 0.0 };
|
||||||
|
double y { 0.0 };
|
||||||
|
double width { 0.0 };
|
||||||
|
double height { 0.0 };
|
||||||
|
};
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#domrectreadonly
|
// https://drafts.fxtf.org/geometry/#domrectreadonly
|
||||||
class DOMRectReadOnly : public Bindings::PlatformObject {
|
class DOMRectReadOnly : public Bindings::PlatformObject {
|
||||||
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
|
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMRectReadOnly>> from_rect(JS::VM&, DOMRectInit const&);
|
||||||
|
|
||||||
virtual ~DOMRectReadOnly() override;
|
virtual ~DOMRectReadOnly() override;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ interface DOMRectReadOnly {
|
||||||
|
|
||||||
constructor(optional double x = 0, optional double y = 0, optional double width = 0, optional double height = 0);
|
constructor(optional double x = 0, optional double y = 0, optional double width = 0, optional double height = 0);
|
||||||
|
|
||||||
|
[NewObject] static DOMRectReadOnly fromRect(optional DOMRectInit other = {});
|
||||||
|
|
||||||
readonly attribute double x;
|
readonly attribute double x;
|
||||||
readonly attribute double y;
|
readonly attribute double y;
|
||||||
readonly attribute double width;
|
readonly attribute double width;
|
||||||
|
@ -15,3 +17,10 @@ interface DOMRectReadOnly {
|
||||||
readonly attribute double left;
|
readonly attribute double left;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary DOMRectInit {
|
||||||
|
unrestricted double x = 0;
|
||||||
|
unrestricted double y = 0;
|
||||||
|
unrestricted double width = 0;
|
||||||
|
unrestricted double height = 0;
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue