2022-09-03 22:32:14 +03:00
/*
* Copyright ( c ) 2022 , Andreas Kling < kling @ serenityos . org >
2022-10-06 17:25:08 +03:00
* Copyright ( c ) 2022 , Sam Atkins < atkinssj @ serenityos . org >
2022-09-03 22:32:14 +03:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
2022-09-26 03:03:02 +03:00
# include <LibWeb/Bindings/Intrinsics.h>
2023-08-15 14:16:45 +03:00
# include <LibWeb/Geometry/DOMMatrix.h>
2022-09-03 22:32:14 +03:00
# include <LibWeb/Geometry/DOMPointReadOnly.h>
2023-02-19 20:11:05 +03:00
# include <LibWeb/WebIDL/ExceptionOr.h>
2022-09-03 22:32:14 +03:00
namespace Web : : Geometry {
2023-11-19 21:47:52 +03:00
JS_DEFINE_ALLOCATOR ( DOMPointReadOnly ) ;
2023-08-15 14:16:09 +03:00
JS : : NonnullGCPtr < DOMPointReadOnly > DOMPointReadOnly : : construct_impl ( JS : : Realm & realm , double x , double y , double z , double w )
2022-09-03 22:32:14 +03:00
{
2023-08-13 14:05:26 +03:00
return realm . heap ( ) . allocate < DOMPointReadOnly > ( realm , realm , x , y , z , w ) ;
2022-09-03 22:32:14 +03:00
}
2022-09-26 03:03:02 +03:00
DOMPointReadOnly : : DOMPointReadOnly ( JS : : Realm & realm , double x , double y , double z , double w )
: PlatformObject ( realm )
2022-09-03 22:32:14 +03:00
, m_x ( x )
, m_y ( y )
, m_z ( z )
, m_w ( w )
{
}
2022-10-06 17:25:08 +03:00
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
2023-08-15 14:16:09 +03:00
JS : : NonnullGCPtr < DOMPointReadOnly > DOMPointReadOnly : : from_point ( JS : : VM & vm , DOMPointInit const & other )
2022-10-06 17:25:08 +03:00
{
// The fromPoint(other) static method on DOMPointReadOnly must create a DOMPointReadOnly from the dictionary other.
return construct_impl ( * vm . current_realm ( ) , other . x , other . y , other . z , other . w ) ;
}
2022-09-03 22:32:14 +03:00
DOMPointReadOnly : : ~ DOMPointReadOnly ( ) = default ;
2023-08-15 14:16:45 +03:00
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-matrixtransform
WebIDL : : ExceptionOr < JS : : NonnullGCPtr < DOMPoint > > DOMPointReadOnly : : matrix_transform ( DOMMatrixInit & matrix ) const
{
// 1. Let matrixObject be the result of invoking create a DOMMatrix from the dictionary matrix.
2024-02-17 11:09:53 +03:00
auto matrix_object = TRY ( DOMMatrix : : create_from_dom_matrix_init ( realm ( ) , matrix ) ) ;
2023-08-15 14:16:45 +03:00
// 2. Return the result of invoking transform a point with a matrix, given the current point and matrixObject. The current point does not get modified.
return matrix_object - > transform_point ( * this ) ;
}
2023-08-07 09:41:28 +03:00
void DOMPointReadOnly : : initialize ( JS : : Realm & realm )
2023-01-10 14:28:20 +03:00
{
2023-08-07 09:41:28 +03:00
Base : : initialize ( realm ) ;
2023-11-22 02:55:21 +03:00
set_prototype ( & Bindings : : ensure_web_prototype < Bindings : : DOMPointReadOnlyPrototype > ( realm , " DOMPointReadOnly " _fly_string ) ) ;
2023-01-10 14:28:20 +03:00
}
2022-09-03 22:32:14 +03:00
}