2021-10-08 17:59:15 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2024-03-10 05:02:54 -03:00
|
|
|
* Copyright (c) 2024, Kenneth Myhra <kennethmyhra@serenityos.org>
|
2021-10-08 17:59:15 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <LibGfx/Rect.h>
|
2022-09-03 20:59:58 -03:00
|
|
|
#include <LibWeb/Bindings/PlatformObject.h>
|
2024-03-10 05:02:54 -03:00
|
|
|
#include <LibWeb/Bindings/Serializable.h>
|
2021-10-08 17:59:15 -03:00
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::Geometry {
|
|
|
|
|
|
2023-07-06 19:21:20 -03: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 17:59:15 -03:00
|
|
|
// https://drafts.fxtf.org/geometry/#domrectreadonly
|
2024-03-10 05:02:54 -03:00
|
|
|
class DOMRectReadOnly
|
|
|
|
|
: public Bindings::PlatformObject
|
|
|
|
|
, public Bindings::Serializable {
|
2022-09-03 20:59:58 -03:00
|
|
|
WEB_PLATFORM_OBJECT(DOMRectReadOnly, Bindings::PlatformObject);
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DECLARE_ALLOCATOR(DOMRectReadOnly);
|
2021-10-08 17:59:15 -03:00
|
|
|
|
2022-09-03 20:59:58 -03:00
|
|
|
public:
|
2024-11-14 12:01:23 -03: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 17:59:15 -03:00
|
|
|
|
2022-09-03 20:59:58 -03:00
|
|
|
virtual ~DOMRectReadOnly() override;
|
2021-10-08 17:59:15 -03: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 05:09:53 -03: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 17:59:15 -03:00
|
|
|
|
2025-07-14 13:15:09 -03:00
|
|
|
virtual HTML::SerializeType serialize_type() const override { return HTML::SerializeType::DOMRectReadOnly; }
|
2025-07-17 10:51:04 -03: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 05:02:54 -03:00
|
|
|
|
2021-10-08 17:59:15 -03:00
|
|
|
protected:
|
2022-09-25 21:03:02 -03:00
|
|
|
DOMRectReadOnly(JS::Realm&, double x, double y, double width, double height);
|
2024-03-10 05:02:54 -03:00
|
|
|
explicit DOMRectReadOnly(JS::Realm&);
|
2021-10-08 17:59:15 -03:00
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
virtual void initialize(JS::Realm&) override;
|
2023-01-10 08:28:20 -03:00
|
|
|
|
2023-08-20 16:48:42 -03:00
|
|
|
Gfx::DoubleRect m_rect;
|
2021-10-08 17:59:15 -03:00
|
|
|
};
|
2025-05-13 08:06:33 -03:00
|
|
|
|
2021-10-08 17:59:15 -03:00
|
|
|
}
|