2022-09-03 21:32:14 +02:00
/*
2024-10-04 13:19:50 +02:00
* Copyright ( c ) 2022 , Andreas Kling < andreas @ ladybird . org >
2022-10-06 15:25:08 +01:00
* Copyright ( c ) 2022 , Sam Atkins < atkinssj @ serenityos . org >
2024-03-09 23:02:22 +01:00
* Copyright ( c ) 2024 , Kenneth Myhra < kennethmyhra @ serenityos . org >
2022-09-03 21:32:14 +02:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
2024-04-27 12:09:58 +12:00
# include <LibWeb/Bindings/DOMPointReadOnlyPrototype.h>
2022-09-25 18:03:02 -06:00
# include <LibWeb/Bindings/Intrinsics.h>
2023-08-15 13:16:45 +02:00
# include <LibWeb/Geometry/DOMMatrix.h>
2022-09-03 21:32:14 +02:00
# include <LibWeb/Geometry/DOMPointReadOnly.h>
2024-03-09 23:02:22 +01:00
# include <LibWeb/HTML/StructuredSerialize.h>
2023-02-19 18:11:05 +01:00
# include <LibWeb/WebIDL/ExceptionOr.h>
2022-09-03 21:32:14 +02:00
namespace Web : : Geometry {
2024-11-15 04:01:23 +13:00
GC_DEFINE_ALLOCATOR ( DOMPointReadOnly ) ;
2023-11-19 19:47:52 +01:00
2024-11-15 04:01:23 +13:00
GC : : Ref < DOMPointReadOnly > DOMPointReadOnly : : construct_impl ( JS : : Realm & realm , double x , double y , double z , double w )
2022-09-03 21:32:14 +02:00
{
2024-11-14 05:50:17 +13:00
return realm . create < DOMPointReadOnly > ( realm , x , y , z , w ) ;
2022-09-03 21:32:14 +02:00
}
2024-11-15 04:01:23 +13:00
GC : : Ref < DOMPointReadOnly > DOMPointReadOnly : : create ( JS : : Realm & realm )
2024-03-09 23:02:22 +01:00
{
2024-11-14 05:50:17 +13:00
return realm . create < DOMPointReadOnly > ( realm ) ;
2024-03-09 23:02:22 +01:00
}
2022-09-25 18:03:02 -06:00
DOMPointReadOnly : : DOMPointReadOnly ( JS : : Realm & realm , double x , double y , double z , double w )
: PlatformObject ( realm )
2022-09-03 21:32:14 +02:00
, m_x ( x )
, m_y ( y )
, m_z ( z )
, m_w ( w )
{
}
2024-03-09 23:02:22 +01:00
DOMPointReadOnly : : DOMPointReadOnly ( JS : : Realm & realm )
: PlatformObject ( realm )
{
}
2022-10-06 15:25:08 +01:00
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-frompoint
2024-11-15 04:01:23 +13:00
GC : : Ref < DOMPointReadOnly > DOMPointReadOnly : : from_point ( JS : : VM & vm , DOMPointInit const & other )
2022-10-06 15:25:08 +01: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 21:32:14 +02:00
DOMPointReadOnly : : ~ DOMPointReadOnly ( ) = default ;
2023-08-15 13:16:45 +02:00
// https://drafts.fxtf.org/geometry/#dom-dompointreadonly-matrixtransform
2024-11-15 04:01:23 +13:00
WebIDL : : ExceptionOr < GC : : Ref < DOMPoint > > DOMPointReadOnly : : matrix_transform ( DOMMatrixInit & matrix ) const
2023-08-15 13:16:45 +02:00
{
// 1. Let matrixObject be the result of invoking create a DOMMatrix from the dictionary matrix.
2024-02-17 08:09:53 +00:00
auto matrix_object = TRY ( DOMMatrix : : create_from_dom_matrix_init ( realm ( ) , matrix ) ) ;
2023-08-15 13:16:45 +02: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 08:41:28 +02:00
void DOMPointReadOnly : : initialize ( JS : : Realm & realm )
2023-01-10 06:28:20 -05:00
{
2024-03-16 13:13:08 +01:00
WEB_SET_PROTOTYPE_FOR_INTERFACE ( DOMPointReadOnly ) ;
2025-04-20 16:22:57 +02:00
Base : : initialize ( realm ) ;
2023-01-10 06:28:20 -05:00
}
2025-07-17 09:51:04 -04:00
WebIDL : : ExceptionOr < void > DOMPointReadOnly : : serialization_steps ( HTML : : TransferDataEncoder & serialized , bool , HTML : : SerializationMemory & )
2024-03-09 23:02:22 +01:00
{
// 1. Set serialized.[[X]] to value’ s x coordinate.
2025-07-17 09:51:04 -04:00
serialized . encode ( m_x ) ;
2024-03-09 23:02:22 +01:00
// 2. Set serialized.[[Y]] to value’ s y coordinate.
2025-07-17 09:51:04 -04:00
serialized . encode ( m_y ) ;
2024-03-09 23:02:22 +01:00
// 3. Set serialized.[[Z]] to value’ s z coordinate.
2025-07-17 09:51:04 -04:00
serialized . encode ( m_z ) ;
2024-03-09 23:02:22 +01:00
// 4. Set serialized.[[W]] to value’ s w coordinate.
2025-07-17 09:51:04 -04:00
serialized . encode ( m_w ) ;
2024-03-09 23:02:22 +01:00
return { } ;
}
2025-07-17 09:51:04 -04:00
WebIDL : : ExceptionOr < void > DOMPointReadOnly : : deserialization_steps ( HTML : : TransferDataDecoder & serialized , HTML : : DeserializationMemory & )
2024-03-09 23:02:22 +01:00
{
// 1. Set value’ s x coordinate to serialized.[[X]].
2025-07-17 09:51:04 -04:00
m_x = serialized . decode < double > ( ) ;
2024-03-09 23:02:22 +01:00
// 2. Set value’ s y coordinate to serialized.[[Y]].
2025-07-17 09:51:04 -04:00
m_y = serialized . decode < double > ( ) ;
2024-03-09 23:02:22 +01:00
// 3. Set value’ s z coordinate to serialized.[[Z]].
2025-07-17 09:51:04 -04:00
m_z = serialized . decode < double > ( ) ;
2024-03-09 23:02:22 +01:00
// 4. Set value’ s w coordinate to serialized.[[W]].
2025-07-17 09:51:04 -04:00
m_w = serialized . decode < double > ( ) ;
2024-03-09 23:02:22 +01:00
return { } ;
}
2022-09-03 21:32:14 +02:00
}