mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 15:18:11 +00:00
LibWeb: Add DOMMatrix and DOMMatrixReadOnly fromMatrix
This commit is contained in:
parent
bbf66ea055
commit
ff1bcc694d
8 changed files with 35 additions and 2 deletions
2
Tests/LibWeb/Text/expected/geometry/dommatrix.txt
Normal file
2
Tests/LibWeb/Text/expected/geometry/dommatrix.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
1. {"a":10,"b":20,"c":30,"d":40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
|
||||||
|
2. {"a":10,"b":20,"c":30,"d":40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
|
15
Tests/LibWeb/Text/input/geometry/dommatrix.html
Normal file
15
Tests/LibWeb/Text/input/geometry/dommatrix.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let testCounter = 1;
|
||||||
|
function testPart(part) {
|
||||||
|
println(`${testCounter++}. ${JSON.stringify(part())}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. Creating a DOMMatrix
|
||||||
|
testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]));
|
||||||
|
|
||||||
|
// 2. Creating a DOMMatrix with fromMatrix
|
||||||
|
testPart(() => DOMMatrix.fromMatrix({ a: 10, b: 20, c: 30, d: 40, e: 50, f: 60 }));
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -73,6 +73,12 @@ void DOMMatrix::initialize(JS::Realm& realm)
|
||||||
set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMMatrixPrototype>(realm, "DOMMatrix"));
|
set_prototype(&Bindings::ensure_web_prototype<Bindings::DOMMatrixPrototype>(realm, "DOMMatrix"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-dommatrix-frommatrix
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> DOMMatrix::from_matrix(JS::VM& vm, DOMMatrixInit other)
|
||||||
|
{
|
||||||
|
return create_from_dom_matrix_2d_init(*vm.current_realm(), other);
|
||||||
|
}
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m11
|
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m11
|
||||||
void DOMMatrix::set_m11(double value)
|
void DOMMatrix::set_m11(double value)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
|
|
||||||
virtual ~DOMMatrix() override;
|
virtual ~DOMMatrix() override;
|
||||||
|
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> from_matrix(JS::VM&, DOMMatrixInit other = {});
|
||||||
|
|
||||||
void set_m11(double value);
|
void set_m11(double value);
|
||||||
void set_m12(double value);
|
void set_m12(double value);
|
||||||
void set_m13(double value);
|
void set_m13(double value);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
interface DOMMatrix : DOMMatrixReadOnly {
|
interface DOMMatrix : DOMMatrixReadOnly {
|
||||||
constructor(optional (DOMString or sequence<unrestricted double>) init);
|
constructor(optional (DOMString or sequence<unrestricted double>) init);
|
||||||
|
|
||||||
// FIXME: [NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {});
|
[NewObject] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {});
|
||||||
// FIXME: [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
|
// FIXME: [NewObject] static DOMMatrix fromFloat32Array(Float32Array array32);
|
||||||
// FIXME: [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);
|
// FIXME: [NewObject] static DOMMatrix fromFloat64Array(Float64Array array64);
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,12 @@ void DOMMatrixReadOnly::initialize_from_create_3d_matrix(double m11, double m12,
|
||||||
// 4. Return matrix
|
// 4. Return matrix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-frommatrix
|
||||||
|
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrixReadOnly>> DOMMatrixReadOnly::from_matrix(JS::VM& vm, DOMMatrixInit& other)
|
||||||
|
{
|
||||||
|
return create_from_dom_matrix_2d_init(*vm.current_realm(), other);
|
||||||
|
}
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-isidentity
|
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-isidentity
|
||||||
bool DOMMatrixReadOnly::is_identity() const
|
bool DOMMatrixReadOnly::is_identity() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
|
|
||||||
virtual ~DOMMatrixReadOnly() override;
|
virtual ~DOMMatrixReadOnly() override;
|
||||||
|
|
||||||
|
static WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrixReadOnly>> from_matrix(JS::VM&, DOMMatrixInit& other);
|
||||||
|
|
||||||
// https://drafts.fxtf.org/geometry/#dommatrix-attributes
|
// https://drafts.fxtf.org/geometry/#dommatrix-attributes
|
||||||
double m11() const { return m_matrix.elements()[0][0]; }
|
double m11() const { return m_matrix.elements()[0][0]; }
|
||||||
double m12() const { return m_matrix.elements()[1][0]; }
|
double m12() const { return m_matrix.elements()[1][0]; }
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
interface DOMMatrixReadOnly {
|
interface DOMMatrixReadOnly {
|
||||||
constructor(optional (DOMString or sequence<unrestricted double>) init);
|
constructor(optional (DOMString or sequence<unrestricted double>) init);
|
||||||
|
|
||||||
// FIXME: [NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other = {});
|
[NewObject] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other = {});
|
||||||
// FIXME: [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
|
// FIXME: [NewObject] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
|
||||||
// FIXME: [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);
|
// FIXME: [NewObject] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue