Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Full support of CanvasContext2D.Path2D #684

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a6156d8
feat: support Path2D to js
edmond-l-20230331 Mar 20, 2024
3e1300c
fix: fix compile.
andycall Mar 20, 2024
aa2e9ee
feat: support dynamic fill parameters.
andycall Sep 16, 2024
a1c41c0
feat: Path2D support copy and SVG path constructor
jwxbond Oct 16, 2024
413f9b4
feat: add Path2D test case
jwxbond Oct 17, 2024
ec10153
feat: feat: add Path2D test case with Matrix
jwxbond Oct 17, 2024
13e841e
Fix: Path2D constructor
jwxbond Oct 19, 2024
9b423b2
feat: add Path2D.roundRect API
jwxbond Oct 19, 2024
21da2c8
feat: add Path2D.roundRect API
jwxbond Oct 22, 2024
aa682e4
feat: roundRect work when width or height is negative
jwxbond Oct 22, 2024
128087b
feat: add test case roundRect
jwxbond Oct 23, 2024
730872a
fix: roundRect set scale 0.6
jwxbond Oct 23, 2024
7c3dd70
feat: support DOMMatrixReadonly
jwxbond Oct 24, 2024
06dc554
fix: fix compile.
andycall Oct 24, 2024
e79f886
feat: DOMMatrix & DOMMatrix add properties & methods
jwxbond Oct 27, 2024
0a3098b
feat: DOMMatrixReadonly methods implement
jwxbond Oct 27, 2024
58c4911
feat: DOMMatrixReadonly methods implement
jwxbond Oct 27, 2024
df50a53
fix: fix dom matrix created from dart side.
andycall Oct 27, 2024
75da5d3
feat: DOMMatrixReadonly update & add multiply
jwxbond Oct 28, 2024
eadeee0
feat: addPath support DOMMatrix
jwxbond Oct 29, 2024
76e53eb
Feat: DOMMatrix multiply
jwxbond Oct 29, 2024
26f4f11
fix: compile error
jwxbond Oct 29, 2024
e4d04ad
Feat: DOMMatrixReadonly rotate/scale/translate
jwxbond Oct 30, 2024
ed65049
Fix: compile error
jwxbond Oct 30, 2024
68e0cad
feat: add DOMPoint & DOMPointReadonly
jwxbond Oct 30, 2024
f2b8299
feat: add scaleNonUniform
jwxbond Oct 30, 2024
bf4be1b
feat: add test DOMMatrix
jwxbond Oct 31, 2024
e6498bb
feat: add transformPoint
jwxbond Nov 1, 2024
e156839
Fix: add constructor with binding object
jwxbond Nov 1, 2024
3228100
Fix: compile error
jwxbond Nov 1, 2024
ed77d44
feat: update add transformPoint
jwxbond Nov 2, 2024
9bca98e
Fix: transformPoint
jwxbond Nov 2, 2024
2916639
feat: DOMPoint add instance method matrixTransform
jwxbond Nov 2, 2024
2c53b37
feat: update for api with optional params
jwxbond Nov 4, 2024
4d76525
fix: rotateFromVector
jwxbond Nov 4, 2024
cd5e492
Fix: rotateAxisAngle
jwxbond Nov 4, 2024
68d71ab
Fix: fix some issue
jwxbond Nov 6, 2024
e1ce832
refactor: `DOMMatrixReadonly` to `DOMMatrixReadOnly`
jwxbond Nov 6, 2024
89f68d7
refactor: `DOMPointReadonly` to `DOMPointReadOnly`
jwxbond Nov 6, 2024
0871f6d
feat: support DOMMatrix & DOMPoint init with dictionary
jwxbond Nov 8, 2024
d11529c
Fix: qjs_union_doubledom_point_init.cc compile error
jwxbond Nov 8, 2024
63fd89a
feat: add fromMatrix
jwxbond Nov 8, 2024
ea5a1fa
feat: dom_matrix
jwxbond Nov 8, 2024
d751f7f
feat: support generate staticMethod from TSDL.
andycall Nov 8, 2024
c691c51
feat: implement formMatrix in dart
jwxbond Nov 9, 2024
d7fb6b7
feat: support DOMPoint.fromPoint
jwxbond Nov 9, 2024
68e4248
Chore: remove console.log
jwxbond Nov 9, 2024
e0feb8a
Fix: NaN assert_equals
jwxbond Nov 9, 2024
fa29999
feat: add testcase
jwxbond Nov 10, 2024
4087515
feat: test case use DOMMatrixReadOnly & DOMPointReadOnly
jwxbond Nov 10, 2024
e8c549f
feat: add context2d snapshot
jwxbond Nov 10, 2024
d79448c
fix: fix test spec mistake
andycall Nov 10, 2024
2fa53a9
fix: fix DOMMatrix.fromMatrix.
andycall Nov 10, 2024
880d16d
fix: fix DOMPoint.fromPoint.
andycall Nov 10, 2024
b5cf622
fix: fix windows build error.
andycall Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,11 @@ if (${WEBF_JS_ENGINE} MATCHES "quickjs")
core/html/canvas/canvas_rendering_context_2d.cc
core/html/canvas/canvas_gradient.cc
core/html/canvas/canvas_pattern.cc
core/html/canvas/path_2d.cc
core/geometry/dom_matrix.cc
core/geometry/dom_matrix_readonly.cc
core/geometry/dom_matrix_read_only.cc
core/geometry/dom_point.cc
core/geometry/dom_point_read_only.cc
core/html/forms/html_button_element.cc
core/html/forms/html_input_element.cc
core/html/forms/html_form_element.cc
Expand Down Expand Up @@ -545,11 +548,18 @@ if (${WEBF_JS_ENGINE} MATCHES "quickjs")
out/qjs_canvas_rendering_context.cc
out/qjs_canvas_gradient.cc
out/qjs_canvas_pattern.cc
out/qjs_path_2d.cc
out/qjs_dom_matrix_init.cc
out/qjs_dom_matrix.cc
out/qjs_dom_matrix_readonly.cc
out/qjs_union_dom_string_sequencedouble.cc
out/qjs_dom_matrix_read_only.cc
out/qjs_dom_point_init.cc
out/qjs_dom_point.cc
out/qjs_dom_point_read_only.cc
out/qjs_union_double_sequencedouble.cc
out/qjs_unionhtml_image_elementhtml_canvas_element.cc
out/qjs_union_dom_stringcanvas_gradient.cc
out/qjs_union_sequencedoubledom_matrix_init.cc
out/qjs_union_doubledom_point_init.cc
out/canvas_types.cc
out/qjs_html_button_element.cc
out/qjs_html_input_element.cc
Expand All @@ -560,6 +570,7 @@ if (${WEBF_JS_ENGINE} MATCHES "quickjs")
out/qjs_promise_rejection_event_init.cc
out/qjs_unionevent_listener_options_boolean.cc
out/qjs_unionadd_event_listener_options_boolean.cc
out/qjs_unionpath_2_d_dom_string.cc
out/qjs_html_template_element.cc
out/qjs_html_unknown_element.cc
out/qjs_performance.cc
Expand Down
10 changes: 8 additions & 2 deletions bridge/bindings/qjs/binding_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "qjs_bounding_client_rect.h"
#include "qjs_canvas_gradient.h"
#include "qjs_canvas_pattern.h"
#include "qjs_path_2d.h"
#include "qjs_canvas_rendering_context.h"
#include "qjs_canvas_rendering_context_2d.h"
#include "qjs_character_data.h"
Expand All @@ -23,7 +24,9 @@
#include "qjs_document.h"
#include "qjs_document_fragment.h"
#include "qjs_dom_matrix.h"
#include "qjs_dom_matrix_readonly.h"
#include "qjs_dom_matrix_read_only.h"
#include "qjs_dom_point.h"
#include "qjs_dom_point_read_only.h"
#include "qjs_dom_string_map.h"
#include "qjs_dom_token_list.h"
#include "qjs_element.h"
Expand Down Expand Up @@ -163,8 +166,11 @@ void InstallBindings(ExecutingContext* context) {
QJSCanvasRenderingContext2D::Install(context);
QJSCanvasPattern::Install(context);
QJSCanvasGradient::Install(context);
QJSDOMMatrixReadonly::Install(context);
QJSPath2D::Install(context);
QJSDOMMatrixReadOnly::Install(context);
QJSDOMMatrix::Install(context);
QJSDOMPointReadOnly::Install(context);
QJSDOMPoint::Install(context);
QJSCSSStyleDeclaration::Install(context);
QJSInlineCssStyleDeclaration::Install(context);
QJSComputedCssStyleDeclaration::Install(context);
Expand Down
5 changes: 4 additions & 1 deletion bridge/bindings/qjs/wrapper_type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ enum {
JS_CLASS_CANVAS_RENDERING_CONTEXT_2_D,
JS_CLASS_CANVAS_GRADIENT,
JS_CLASS_CANVAS_PATTERN,
JS_CLASS_PATH_2_D,
JS_CLASS_DOM_MATRIX,
JS_CLASS_DOM_MATRIX_READONLY,
JS_CLASS_DOM_MATRIX_READ_ONLY,
JS_CLASS_DOM_POINT,
JS_CLASS_DOM_POINT_READ_ONLY,
JS_CLASS_HTML_TEMPLATE_ELEMENT,
JS_CLASS_HTML_UNKNOWN_ELEMENT,
JS_CLASS_HTML_INPUT_ELEMENT,
Expand Down
45 changes: 44 additions & 1 deletion bridge/core/binding_call_methods.json5
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"x",
"y",
"z",
"w",
"screen",
"target",
"accessKey",
Expand Down Expand Up @@ -104,6 +105,7 @@
"lineTo",
"moveTo",
"rect",
"roundRect",
"restore",
"resetTransform",
"rotate",
Expand All @@ -114,6 +116,7 @@
"scale",
"strokeText",
"setTransform",
"addPath",
"transform",
"translate",
"reset",
Expand Down Expand Up @@ -179,6 +182,46 @@
"dir",
"pageXOffset",
"pageYOffset",
"title"
"title",
"is2D",
"isIdentity",
"m11",
"m12",
"m13",
"m14",
"m21",
"m22",
"m23",
"m24",
"m31",
"m32",
"m33",
"m34",
"m41",
"m42",
"m43",
"m44",
"a",
"b",
"c",
"d",
"e",
"f",
"flipX",
"flipY",
"inverse",
"multiply",
"rotateAxisAngle",
"rotateFromVector",
"scale3d",
"scaleNonUniform",
"skewX",
"skewY",
"toFloat32Array",
"toFloat64Array",
"toJSON",
"toString",
"transformPoint",
"matrixTransform"
]
}
6 changes: 5 additions & 1 deletion bridge/core/binding_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ enum BindingMethodCallOperations {
kAsyncAnonymousFunction,
};

enum CreateBindingObjectType { kCreateDOMMatrix = 0 };
enum CreateBindingObjectType {
kCreateDOMMatrix = 0,
kCreatePath2D = 1,
kCreateDOMPoint = 2,
};

struct BindingObjectPromiseContext : public DartReadable {
ExecutingContext* context;
Expand Down
25 changes: 20 additions & 5 deletions bridge/core/frame/module_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,25 @@ ScriptValue ModuleManager::__webf_invoke_module__(ExecutingContext* context,
ExceptionState& exception) {
NativeValue params = params_value.ToNative(context->ctx(), exception);

if (exception.HasException()) {
NativeValue* result = __webf_invoke_module__(context, module_name, method, params, callback, exception);
if (result == nullptr) {
return ScriptValue::Empty(context->ctx());
}

ScriptValue return_value = ScriptValue(context->ctx(), *result);
dart_free(result);
return return_value;
}
NativeValue* ModuleManager::__webf_invoke_module__(ExecutingContext* context,
const AtomicString& module_name,
const AtomicString& method,
NativeValue& params,
const std::shared_ptr<QJSFunction>& callback,
ExceptionState& exception) {
if (exception.HasException()) {
return nullptr;
}

NativeValue* result;
auto module_name_string = module_name.ToNativeString(context->ctx());
auto method_name_string = method.ToNativeString(context->ctx());
Expand All @@ -165,12 +180,12 @@ ScriptValue ModuleManager::__webf_invoke_module__(ExecutingContext* context,
context->dartIsolateContext()->profiler()->FinishTrackLinkSteps();

if (result == nullptr) {
return ScriptValue::Empty(context->ctx());
return nullptr;
}

ScriptValue return_value = ScriptValue(context->ctx(), *result);
dart_free(result);
return return_value;
// ScriptValue return_value = ScriptValue(context->ctx(), *result);
// dart_free(result);
return result;
}

void ModuleManager::__webf_add_module_listener__(ExecutingContext* context,
Expand Down
8 changes: 8 additions & 0 deletions bridge/core/frame/module_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "bindings/qjs/qjs_function.h"
#include "module_callback.h"

#include <webf_bridge.h>

namespace webf {

class ModuleContext {
Expand Down Expand Up @@ -37,6 +39,12 @@ class ModuleManager {
ScriptValue& params_value,
const std::shared_ptr<QJSFunction>& callback,
ExceptionState& exception);
static NativeValue* __webf_invoke_module__(ExecutingContext* context,
const AtomicString& module_name,
const AtomicString& method,
NativeValue& params_value,
const std::shared_ptr<QJSFunction>& callback,
ExceptionState& exception);
static void __webf_add_module_listener__(ExecutingContext* context,
const AtomicString& module_name,
const std::shared_ptr<QJSFunction>& handler,
Expand Down
18 changes: 15 additions & 3 deletions bridge/core/geometry/dom_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
*/

#include "dom_matrix.h"
#include "core/executing_context.h"

namespace webf {

DOMMatrix* DOMMatrix::Create(ExecutingContext* context,
const std::shared_ptr<QJSUnionDomStringSequenceDouble>& init,
const std::shared_ptr<QJSUnionSequenceDoubleDOMMatrixInit>& init,
ExceptionState& exception_state) {
return MakeGarbageCollected<DOMMatrix>(context, init, exception_state);
}

DOMMatrix* DOMMatrix::Create(webf::ExecutingContext* context, webf::ExceptionState& exception_state) {
return MakeGarbageCollected<DOMMatrix>(context, exception_state);
}

DOMMatrix::DOMMatrix(webf::ExecutingContext* context, webf::ExceptionState& exception_state):
DOMMatrixReadOnly(context, exception_state) {}

DOMMatrix::DOMMatrix(ExecutingContext* context,
const std::shared_ptr<QJSUnionDomStringSequenceDouble>& init,
const std::shared_ptr<QJSUnionSequenceDoubleDOMMatrixInit>& init,
ExceptionState& exception_state)
: DOMMatrixReadonly(context, init, exception_state) {}
: DOMMatrixReadOnly(context, init, exception_state) {}

DOMMatrix::DOMMatrix(webf::ExecutingContext* context, webf::NativeBindingObject* native_binding_object): DOMMatrixReadOnly(context, native_binding_object) {

}

} // namespace webf
8 changes: 6 additions & 2 deletions bridge/core/geometry/dom_matrix.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
interface DOMMatrix extends DOMMatrixReadonly {
new(init: string | double[]): DOMMatrix;
import {DOMMatrixInit} from "./dom_matrix_init";
import {DOMMatrixReadOnly} from "./dom_matrix_read_only";

interface DOMMatrix extends DOMMatrixReadOnly {
fromMatrix(matrix: DOMMatrix): StaticMethod<DOMMatrix>;
new(init?: number[] | DOMMatrixInit): DOMMatrix;
}
22 changes: 18 additions & 4 deletions bridge/core/geometry/dom_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,39 @@
#ifndef WEBF_CORE_HTML_CANVAS_DOM_MATRIX_H_
#define WEBF_CORE_HTML_CANVAS_DOM_MATRIX_H_

#include "dom_matrix_readonly.h"
#include "dom_matrix_read_only.h"

namespace webf {

class DOMMatrix : public DOMMatrixReadonly {
class DOMMatrix : public DOMMatrixReadOnly {
DEFINE_WRAPPERTYPEINFO();

public:
using ImplType = DOMMatrix*;
static DOMMatrix* Create(ExecutingContext* context,
const std::shared_ptr<QJSUnionSequenceDoubleDOMMatrixInit>& init,
ExceptionState& exception_state);
static DOMMatrix* Create(ExecutingContext* context,
const std::shared_ptr<QJSUnionDomStringSequenceDouble>& init,
ExceptionState& exception_state);

DOMMatrix() = delete;
explicit DOMMatrix(ExecutingContext* context,
const std::shared_ptr<QJSUnionDomStringSequenceDouble>& init,
ExceptionState& exception_state);
explicit DOMMatrix(ExecutingContext* context,
const std::shared_ptr<QJSUnionSequenceDoubleDOMMatrixInit>& init,
ExceptionState& exception_state);
explicit DOMMatrix(ExecutingContext* context,
NativeBindingObject* native_binding_object);

[[nodiscard]]
bool IsDOMMatrix() const override { return true; }

private:
};
template <>
struct DowncastTraits<DOMMatrix> {
static bool AllowFrom(const DOMMatrixReadOnly& matrix) { return matrix.IsDOMMatrix(); }
};

} // namespace webf

Expand Down
22 changes: 22 additions & 0 deletions bridge/core/geometry/dom_matrix_init.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-ignore
@Dictionary()
export interface DOMMatrixInit {
m11: number,
m12: number,
m13: number,
m14: number,
m21: number,
m22: number,
m23: number,
m24: number,
m31: number,
m32: number,
m33: number,
m34: number,
m41: number,
m42: number,
m43: number,
m44: number,
is2D: boolean,
isIdentity: boolean,
}
Loading
Loading