mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:47:34 +00:00
LibWeb: Add barebones implementation of DOMPoint and DOMPointReadOnly
This commit is contained in:
parent
5744211001
commit
e883777a18
7 changed files with 131 additions and 0 deletions
44
Userland/Libraries/LibWeb/Geometry/DOMPoint.h
Normal file
44
Userland/Libraries/LibWeb/Geometry/DOMPoint.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Geometry/DOMPointReadOnly.h>
|
||||
|
||||
namespace Web::Geometry {
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#DOMPoint
|
||||
class DOMPoint final : public DOMPointReadOnly {
|
||||
public:
|
||||
using WrapperType = Bindings::DOMPointWrapper;
|
||||
|
||||
static NonnullRefPtr<DOMPoint> create_with_global_object(Bindings::WindowObject&, double x = 0, double y = 0, double z = 0, double w = 0)
|
||||
{
|
||||
return DOMPoint::create(x, y, z, w);
|
||||
}
|
||||
|
||||
static NonnullRefPtr<DOMPoint> create(double x = 0, double y = 0, double z = 0, double w = 0)
|
||||
{
|
||||
return adopt_ref(*new DOMPoint(x, y, z, w));
|
||||
}
|
||||
|
||||
double x() const { return m_x; }
|
||||
double y() const { return m_y; }
|
||||
double z() const { return m_z; }
|
||||
double w() const { return m_w; }
|
||||
|
||||
void set_x(double x) { m_x = x; }
|
||||
void set_y(double y) { m_y = y; }
|
||||
void set_z(double z) { m_z = z; }
|
||||
void set_w(double w) { m_w = w; }
|
||||
|
||||
private:
|
||||
DOMPoint(float x, float y, float z, float w)
|
||||
: DOMPointReadOnly(x, y, z, w)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
12
Userland/Libraries/LibWeb/Geometry/DOMPoint.idl
Normal file
12
Userland/Libraries/LibWeb/Geometry/DOMPoint.idl
Normal file
|
@ -0,0 +1,12 @@
|
|||
#import <Geometry/DOMPointReadOnly.idl>
|
||||
|
||||
interface DOMPoint : DOMPointReadOnly {
|
||||
|
||||
constructor(optional double x = 0, optional double y = 0, optional double z = 0, optional double w = 0);
|
||||
|
||||
attribute double x;
|
||||
attribute double y;
|
||||
attribute double z;
|
||||
attribute double w;
|
||||
|
||||
};
|
53
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
Normal file
53
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Geometry {
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dompointreadonly
|
||||
class DOMPointReadOnly
|
||||
: public RefCounted<DOMPointReadOnly>
|
||||
, public Bindings::Wrappable {
|
||||
public:
|
||||
using WrapperType = Bindings::DOMPointReadOnlyWrapper;
|
||||
|
||||
static NonnullRefPtr<DOMPointReadOnly> create_with_global_object(Bindings::WindowObject&, double x = 0, double y = 0, double z = 0, double w = 0)
|
||||
{
|
||||
return DOMPointReadOnly::create(x, y, z, w);
|
||||
}
|
||||
|
||||
static NonnullRefPtr<DOMPointReadOnly> create(double x = 0, double y = 0, double z = 0, double w = 0)
|
||||
{
|
||||
return adopt_ref(*new DOMPointReadOnly(x, y, z, w));
|
||||
}
|
||||
|
||||
double x() const { return m_x; }
|
||||
double y() const { return m_y; }
|
||||
double z() const { return m_z; }
|
||||
double w() const { return m_w; }
|
||||
|
||||
protected:
|
||||
DOMPointReadOnly(double x, double y, double z, double w)
|
||||
: m_x(x)
|
||||
, m_y(y)
|
||||
, m_z(z)
|
||||
, m_w(w)
|
||||
{
|
||||
}
|
||||
|
||||
double m_x;
|
||||
double m_y;
|
||||
double m_z;
|
||||
double m_w;
|
||||
};
|
||||
|
||||
}
|
10
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl
Normal file
10
Userland/Libraries/LibWeb/Geometry/DOMPointReadOnly.idl
Normal file
|
@ -0,0 +1,10 @@
|
|||
interface DOMPointReadOnly {
|
||||
|
||||
constructor(optional double x = 0, optional double y = 0, optional double z = 0, optional double w = 0);
|
||||
|
||||
readonly attribute double x;
|
||||
readonly attribute double y;
|
||||
readonly attribute double z;
|
||||
readonly attribute double w;
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue