ladybird/Userland/Libraries/LibWeb/Geometry/DOMRect.h
Andreas Kling 6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00

50 lines
1.4 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Geometry/DOMRectReadOnly.h>
namespace Web::Geometry {
// https://drafts.fxtf.org/geometry/#DOMRect
class DOMRect final
: public DOMRectReadOnly {
public:
using WrapperType = Bindings::DOMRectWrapper;
static NonnullRefPtr<DOMRect> create_with_global_object(HTML::Window&, double x = 0, double y = 0, double width = 0, double height = 0)
{
return DOMRect::create(x, y, width, height);
}
static NonnullRefPtr<DOMRect> create(double x = 0, double y = 0, double width = 0, double height = 0)
{
return adopt_ref(*new DOMRect(x, y, width, height));
}
static NonnullRefPtr<DOMRect> create(Gfx::FloatRect const& rect)
{
return adopt_ref(*new DOMRect(rect.x(), rect.y(), rect.width(), rect.height()));
}
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(); }
void set_x(double x) { m_rect.set_x(x); }
void set_y(double y) { m_rect.set_y(y); }
void set_width(double width) { m_rect.set_width(width); }
void set_height(double height) { m_rect.set_height(height); }
private:
DOMRect(float x, float y, float width, float height)
: DOMRectReadOnly(x, y, width, height)
{
}
};
}