2021-10-08 22:59:15 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2024-03-10 09:02:54 +01:00
|
|
|
* Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org>
|
2021-10-08 22:59:15 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGfx/Rect.h>
|
2022-09-04 01:59:58 +02:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2024-03-10 09:02:54 +01:00
|
|
|
#include <LibWeb/Bindings/Serializable.h>
|
2021-10-08 22:59:15 +02:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
namespace Web::Geometry {
|
|
|
|
|
2023-07-06 23:21:20 +01:00
|
|
|
// 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 };
|
|
|
|
};
|
|
|
|
|
2021-10-08 22:59:15 +02:00
|
|
|
// https://drafts.fxtf.org/geometry/#domrectreadonly
|
2024-03-10 09:02:54 +01:00
|
|
|
class DOMRectReadOnly
|
|
|
|
: public Bindings::PlatformObject
|
|
|
|
, public Bindings::Serializable {
|
2022-09-04 01:59:58 +02:00
|
|
|
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
|
2024-11-15 04:01:23 +13:00
|
|
|
GC_DECLARE_ALLOCATOR(DOMRectReadOnly);
|
2021-10-08 22:59:15 +02:00
|
|
|
|
2022-09-04 01:59:58 +02:00
|
|
|
public:
|
2024-11-15 04:01:23 +13:00
|
|
|
static WebIDL::ExceptionOr<GC::Ref<DOMRectReadOnly>> construct_impl(JS::Realm&, double x = 0, double y = 0, double width = 0, double height = 0);
|
|
|
|
[[nodiscard]] static GC::Ref<DOMRectReadOnly> from_rect(JS::VM&, DOMRectInit const&);
|
|
|
|
static GC::Ref<DOMRectReadOnly> create(JS::Realm&);
|
2021-10-08 22:59:15 +02:00
|
|
|
|
2022-09-04 01:59:58 +02:00
|
|
|
virtual ~DOMRectReadOnly() override;
|
2021-10-08 22:59:15 +02:00
|
|
|
|
|
|
|
double x() const { return m_rect.x(); }
|
|
|
|
double y() const { return m_rect.y(); }
|
|
|
|
double width() const { return m_rect.width(); }
|
|
|
|
double height() const { return m_rect.height(); }
|
|
|
|
|
2024-02-17 08:09:53 +00:00
|
|
|
double top() const
|
|
|
|
{
|
|
|
|
if (isnan(y()) || isnan(height()))
|
|
|
|
return NAN;
|
|
|
|
return min(y(), y() + height());
|
|
|
|
}
|
|
|
|
|
|
|
|
double right() const
|
|
|
|
{
|
|
|
|
if (isnan(x()) || isnan(width()))
|
|
|
|
return NAN;
|
|
|
|
return max(x(), x() + width());
|
|
|
|
}
|
|
|
|
|
|
|
|
double bottom() const
|
|
|
|
{
|
|
|
|
if (isnan(y()) || isnan(height()))
|
|
|
|
return NAN;
|
|
|
|
return max(y(), y() + height());
|
|
|
|
}
|
|
|
|
|
|
|
|
double left() const
|
|
|
|
{
|
|
|
|
if (isnan(x()) || isnan(width()))
|
|
|
|
return NAN;
|
|
|
|
return min(x(), x() + width());
|
|
|
|
}
|
2021-10-08 22:59:15 +02:00
|
|
|
|
2025-07-14 17:15:09 +01:00
|
|
|
virtual HTML::SerializeType serialize_type() const override { return HTML::SerializeType::DOMRectReadOnly; }
|
2025-07-17 09:51:04 -04:00
|
|
|
virtual WebIDL::ExceptionOr<void> serialization_steps(HTML::TransferDataEncoder&, bool for_storage, HTML::SerializationMemory&) override;
|
|
|
|
virtual WebIDL::ExceptionOr<void> deserialization_steps(HTML::TransferDataDecoder&, HTML::DeserializationMemory&) override;
|
2024-03-10 09:02:54 +01:00
|
|
|
|
2021-10-08 22:59:15 +02:00
|
|
|
protected:
|
2022-09-25 18:03:02 -06:00
|
|
|
DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height);
|
2024-03-10 09:02:54 +01:00
|
|
|
explicit DOMRectReadOnly(JS::Realm&);
|
2021-10-08 22:59:15 +02:00
|
|
|
|
2023-08-07 08:41:28 +02:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-10 06:28:20 -05:00
|
|
|
|
2023-08-20 21:48:42 +02:00
|
|
|
Gfx::DoubleRect m_rect;
|
2021-10-08 22:59:15 +02:00
|
|
|
};
|
2025-05-13 07:06:33 -04:00
|
|
|
|
2021-10-08 22:59:15 +02:00
|
|
|
}
|