xbintsc 0.6.10 → 0.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/checker/globals.js +2 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/state.js +3 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +3 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/compiler.js +1 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/node/crypto/index.js +12 -1
- package/dist/src/extensions/node/crypto/index.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +26 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +37 -1
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
- package/dist/tests/e2e/crypto-random.test.js +63 -0
- package/dist/tests/e2e/crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/date-parse.test.js +27 -1
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
- package/dist/tests/e2e/gui-dom.test.js +29 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-form.test.d.ts +9 -0
- package/dist/tests/e2e/gui-form.test.js +359 -0
- package/dist/tests/e2e/gui-form.test.js.map +1 -0
- package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/gui-style.test.js +82 -0
- package/dist/tests/e2e/gui-style.test.js.map +1 -1
- package/dist/tests/e2e/gui-unsupported.test.js +4 -3
- package/dist/tests/e2e/gui-unsupported.test.js.map +1 -1
- package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
- package/dist/tests/e2e/json-parse-errors.test.js +48 -0
- package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/gui/api.md +8 -2
- package/doc/gui/dom.md +21 -12
- package/doc/gui/input.md +74 -3
- package/doc/implemented/node/crypto.md +8 -0
- package/doc/implemented/node/fs.md +1 -1
- package/doc/implemented/stdlib.md +10 -2
- package/doc/zh-CN/gui/api.md +8 -2
- package/doc/zh-CN/gui/dom.md +17 -11
- package/doc/zh-CN/gui/input.md +65 -4
- package/doc/zh-CN/implemented/node/crypto.md +6 -0
- package/doc/zh-CN/implemented/node/fs.md +1 -1
- package/doc/zh-CN/implemented/stdlib.md +10 -2
- package/package.json +7 -7
- package/runtime/ext_gui/css_match.cpp +21 -1
- package/runtime/ext_gui/css_selector.cpp +2 -2
- package/runtime/ext_gui/document.cpp +12 -0
- package/runtime/ext_gui/dom.h +41 -2
- package/runtime/ext_gui/dom_api_document.cpp +28 -0
- package/runtime/ext_gui/dom_api_events.cpp +17 -14
- package/runtime/ext_gui/dom_api_form.cpp +567 -0
- package/runtime/ext_gui/dom_api_internal.h +46 -214
- package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
- package/runtime/ext_gui/dom_api_node.cpp +10 -3
- package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
- package/runtime/ext_gui/dom_api_proto.cpp +45 -0
- package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
- package/runtime/ext_gui/dom_parse.cpp +114 -1
- package/runtime/ext_gui/form_focus.cpp +293 -0
- package/runtime/ext_gui/form_input.cpp +448 -0
- package/runtime/ext_gui/form_internal.h +30 -0
- package/runtime/ext_gui/form_shared.cpp +126 -0
- package/runtime/ext_gui/form_state.cpp +536 -0
- package/runtime/ext_gui/form_state.h +97 -0
- package/runtime/ext_gui/gui_engine.h +40 -4
- package/runtime/ext_gui/gui_events.cpp +63 -48
- package/runtime/ext_gui/layout.cpp +6 -0
- package/runtime/ext_gui/layout.h +4 -0
- package/runtime/ext_gui/layout_flow.cpp +23 -1
- package/runtime/ext_gui/paint.cpp +4 -1
- package/runtime/ext_gui/paint_form.cpp +389 -0
- package/runtime/ext_gui/paint_internal.h +6 -0
- package/runtime/ext_gui/style_print.cpp +30 -0
- package/runtime/ext_gui/style_ua.cpp +42 -0
- package/runtime/ext_gui/warnings.cpp +5 -7
- package/runtime/ext_gui/window.cpp +31 -55
- package/runtime/ext_gui/window_diagnostics.cpp +58 -0
- package/runtime/ext_gui/window_emit.cpp +51 -0
- package/runtime/ext_node/crypto/crypto.c +3 -2
- package/runtime/ext_node/crypto/crypto_hash.h +13 -0
- package/runtime/ext_node/crypto/crypto_random.c +339 -0
- package/runtime/ext_node/fs/async_worker.c +1 -1
- package/runtime/ext_node/fs/fs_ops.c +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +65 -0
- package/runtime/rt.h +27 -0
- package/runtime/xt_crypto.c +132 -0
- package/runtime/xt_random.c +143 -0
- package/runtime/xt_regex/matcher.inc +9 -28
- package/runtime/xt_regex/parser.inc +65 -2
- package/runtime/xt_regex/types.inc +11 -1
- package/runtime/xt_regex.h +6 -2
- package/runtime/xt_stdlib/dispatch.inc +2 -0
- package/runtime/xt_stdlib/math.inc +1 -1
- package/runtime/xt_stdlib2/date.inc +204 -4
- package/runtime/xt_stdlib2/json.inc +4 -546
- package/runtime/xt_stdlib2/json_parse.inc +347 -0
- package/runtime/xt_stdlib2/json_stringify.inc +368 -0
- package/runtime/xt_stdlib2/regexp-match.inc +6 -11
- package/runtime/xt_stdlib2.c +0 -4
- package/runtime/xt_typed_array/elements.inc +6 -1
- package/src/checker/globals.ts +2 -0
- package/src/codegen/generator/state.ts +3 -0
- package/src/codegen/generator/tables.ts +3 -0
- package/src/driver/compiler.ts +1 -1
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/crypto/index.ts +12 -1
|
@@ -35,17 +35,19 @@
|
|
|
35
35
|
|
|
36
36
|
## JSON
|
|
37
37
|
|
|
38
|
-
- `JSON.parse` 支持 `reviver`。
|
|
38
|
+
- `JSON.parse` 支持 `reviver`;畸形输入(错误数字/字符串、尾随内容、缺少分隔符)会抛出可捕获的 `SyntaxError`,而不是返回 `undefined`。
|
|
39
39
|
- `JSON.stringify` 支持函数或数组 `replacer`、`toJSON`,以及 `space`(数字或字符串,最多 10 个单位)。`undefined` / 函数 / symbol 值遵循标准省略规则。
|
|
40
40
|
- 对象键按插入序输出,整数键按数值排序;循环引用抛错。
|
|
41
41
|
|
|
42
42
|
## Date
|
|
43
43
|
|
|
44
44
|
- `Date` 基于 `gmtime_r`;`Date.parse` / `new Date(string)` 支持 ISO 8601 解析。
|
|
45
|
+
- `toLocaleDateString` / `toLocaleTimeString` / `toLocaleString` 按本地时间格式化(`M/D/YYYY`、`h:mm:ss AM`);支持少量 options(`weekday`/`year`/`month`/`day`/`hour`/`minute`/`second`/`hour12`)。另有 `toDateString` / `toTimeString` / `toUTCString`;无效日期格式化为 `Invalid Date`。
|
|
45
46
|
|
|
46
47
|
## RegExp
|
|
47
48
|
|
|
48
|
-
- `RegExp`
|
|
49
|
+
- `RegExp` 在所有宿主上都使用运行时自带的 POSIX ERE 兼容匹配器(`regcomp` / `regexec` 风格),因此结果不依赖平台 libc。捕获组可经 `exec` / `match` / `replace` / `split` / `search` 使用。
|
|
50
|
+
- 量词支持 `*`、`+`、`?` 以及计数形式 `{n}`、`{n,}`、`{n,m}`(可带惰性 `?` 后缀)。`{x}`、`{,2}` 这类畸形花括号组保持字面量,与 JavaScript 一致;`{2,1}` 这类倒置范围同样按字面量处理,而不是报错。
|
|
49
51
|
- 匹配按字节进行,且 `/g` / `/y` 的 `lastIndex` 不被读取 —— 见[运行时偏差](../unimplemented/deviations.md)。
|
|
50
52
|
|
|
51
53
|
## Symbol
|
|
@@ -90,3 +92,9 @@
|
|
|
90
92
|
- `btoa` / `atob` base64 编解码(核心全局函数,并非 Node 扩展专属)。
|
|
91
93
|
- `structuredClone`:数组、对象、`Map`、`Set`、`Date`、`RegExp` 与类型化数组,保留循环引用与共享引用;函数、symbol、Promise、生成器会被拒绝。
|
|
92
94
|
- 定时器、`queueMicrotask` 与 `performance.now` 见[异步、Promise 与生成器](./async.md);`fetch` 见 [fetch](./fetch.md)。
|
|
95
|
+
|
|
96
|
+
## 全局 crypto
|
|
97
|
+
|
|
98
|
+
- `crypto.getRandomValues(typedArray)` 从操作系统 CSPRNG 填充整数类型化数组(最多 65 536 字节)并返回;`crypto.randomUUID()` 返回 v4 UUID 字符串。`crypto` 也是一等对象,方法可脱离对象使用(`const uuid = crypto.randomUUID`)。
|
|
99
|
+
- `Math.random` 使用由操作系统 CSPRNG 播种的 xoshiro256** 流(53 位随机性),不再使用 C `rand()`。
|
|
100
|
+
- Node 的 `crypto.randomBytes` / `randomInt` / `randomFillSync` / `pbkdf2Sync` 见 [node/crypto](../implemented/node/crypto.md)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xbintsc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12",
|
|
4
4
|
"description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"vitest": "^2.1.8"
|
|
73
73
|
},
|
|
74
74
|
"optionalDependencies": {
|
|
75
|
-
"@xbintsc/linux-x64": "0.6.
|
|
76
|
-
"@xbintsc/linux-arm64": "0.6.
|
|
77
|
-
"@xbintsc/darwin-x64": "0.6.
|
|
78
|
-
"@xbintsc/darwin-arm64": "0.6.
|
|
79
|
-
"@xbintsc/win32-x64": "0.6.
|
|
80
|
-
"@xbintsc/win32-arm64": "0.6.
|
|
75
|
+
"@xbintsc/linux-x64": "0.6.12",
|
|
76
|
+
"@xbintsc/linux-arm64": "0.6.12",
|
|
77
|
+
"@xbintsc/darwin-x64": "0.6.12",
|
|
78
|
+
"@xbintsc/darwin-arm64": "0.6.12",
|
|
79
|
+
"@xbintsc/win32-x64": "0.6.12",
|
|
80
|
+
"@xbintsc/win32-arm64": "0.6.12"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=22"
|
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
#include <cstdlib>
|
|
8
8
|
#include <memory>
|
|
9
9
|
|
|
10
|
+
#include "form_state.h"
|
|
11
|
+
|
|
10
12
|
namespace xtgui {
|
|
11
13
|
|
|
12
14
|
namespace {
|
|
@@ -96,6 +98,9 @@ bool matchPseudo(const Node *node, const std::string &pseudo, const MatchState &
|
|
|
96
98
|
/* The engine has no keyboard modality tracking, so focus-visible is the same
|
|
97
99
|
* as focus (a mouse click also shows the focus ring). */
|
|
98
100
|
if (pseudo == "focus-visible") return node == state.focus;
|
|
101
|
+
/* `:focus-within` matches the focused element and every ancestor, which is
|
|
102
|
+
* what lets a form card highlight while one of its fields has focus. */
|
|
103
|
+
if (pseudo == "focus-within") return isHoverTarget(node, state.focus);
|
|
99
104
|
if (pseudo == "active") return isHoverTarget(node, state.active);
|
|
100
105
|
if (pseudo == "empty") {
|
|
101
106
|
for (const std::unique_ptr<Node> &child : node->children) {
|
|
@@ -105,7 +110,22 @@ bool matchPseudo(const Node *node, const std::string &pseudo, const MatchState &
|
|
|
105
110
|
return true;
|
|
106
111
|
}
|
|
107
112
|
if (pseudo == "disabled") return node->attr("disabled") != nullptr;
|
|
108
|
-
if (pseudo == "checked")
|
|
113
|
+
if (pseudo == "checked") {
|
|
114
|
+
/* The live state, not the default `checked` attribute: a checkbox toggled
|
|
115
|
+
* by a click must match `:checked` immediately. */
|
|
116
|
+
if (node->isTag("input") && (xt_form_type(node) == "checkbox" ||
|
|
117
|
+
xt_form_type(node) == "radio")) {
|
|
118
|
+
return xt_form_checked(node);
|
|
119
|
+
}
|
|
120
|
+
if (node->isTag("option")) {
|
|
121
|
+
const Node *select = node->parent;
|
|
122
|
+
while (select != nullptr && !(select->isElement() && select->isTag("select"))) {
|
|
123
|
+
select = select->parent;
|
|
124
|
+
}
|
|
125
|
+
if (select != nullptr) return xt_form_selected_option(select) == node;
|
|
126
|
+
}
|
|
127
|
+
return node->attr("checked") != nullptr;
|
|
128
|
+
}
|
|
109
129
|
if (pseudo.rfind("nth-child(", 0) == 0) {
|
|
110
130
|
return matchesNth(node->elementIndex() + 1, pseudo.substr(10, pseudo.size() - 11));
|
|
111
131
|
}
|
|
@@ -19,8 +19,8 @@ namespace {
|
|
|
19
19
|
const std::unordered_set<std::string> &supportedPseudoClasses() {
|
|
20
20
|
static const std::unordered_set<std::string> names = {
|
|
21
21
|
"active", "checked", "disabled", "empty", "first-child", "focus",
|
|
22
|
-
"focus-visible", "hover", "last-child", "not",
|
|
23
|
-
"root",
|
|
22
|
+
"focus-visible", "focus-within", "hover", "last-child", "not",
|
|
23
|
+
"nth-child", "only-child", "root",
|
|
24
24
|
};
|
|
25
25
|
return names;
|
|
26
26
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
#include "document.h"
|
|
6
6
|
|
|
7
|
+
#include "form_state.h"
|
|
7
8
|
#include "warnings.h"
|
|
8
9
|
|
|
9
10
|
#include <cmath>
|
|
@@ -73,10 +74,21 @@ void XtDocument::load(const std::string &html, float viewportWidth, float viewpo
|
|
|
73
74
|
restyle(viewportWidth, viewportHeight);
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
namespace {
|
|
78
|
+
void initialiseFormControls(Node *node) {
|
|
79
|
+
if (node == nullptr) return;
|
|
80
|
+
if (node->isElement() && xt_form_is_control(node)) xt_form_init(node);
|
|
81
|
+
for (const std::unique_ptr<Node> &child : node->children) {
|
|
82
|
+
initialiseFormControls(child.get());
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} // namespace
|
|
86
|
+
|
|
76
87
|
void XtDocument::restyle(float viewportWidth, float viewportHeight) {
|
|
77
88
|
viewportWidth_ = viewportWidth;
|
|
78
89
|
viewportHeight_ = viewportHeight;
|
|
79
90
|
g_perf_frame.restyles += 1;
|
|
91
|
+
if (root_ != nullptr) initialiseFormControls(root_.get());
|
|
80
92
|
if (root_ != nullptr) {
|
|
81
93
|
MatchState state;
|
|
82
94
|
state.hover = hover_;
|
package/runtime/ext_gui/dom.h
CHANGED
|
@@ -26,6 +26,40 @@ struct Attr {
|
|
|
26
26
|
std::string value;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/** Editable/checkable state of a form control (`<input>`, `<textarea>`,
|
|
30
|
+
* `<select>`). The browser keeps this in the element's internal value, separate
|
|
31
|
+
* from the `value`/`checked` *attributes*; the engine does the same so
|
|
32
|
+
* `<input value="a">` (the default) and `el.value = "b"` (the live value) do not
|
|
33
|
+
* overwrite each other. */
|
|
34
|
+
struct FormState {
|
|
35
|
+
std::string value;
|
|
36
|
+
bool initialized = false;
|
|
37
|
+
/** `checkbox`/`radio` state (the `checked` attribute is only the default). */
|
|
38
|
+
bool checked = false;
|
|
39
|
+
bool checked_initialized = false;
|
|
40
|
+
/** Selection in UTF-16 code units, like the DOM's `selectionStart`/`End`. */
|
|
41
|
+
int selection_start = 0;
|
|
42
|
+
int selection_end = 0;
|
|
43
|
+
/** 0 = none, 1 = forward, -1 = backward (`selectionDirection`). */
|
|
44
|
+
int selection_direction = 0;
|
|
45
|
+
bool focused = false;
|
|
46
|
+
/** Text value when focus arrived, so `change` fires only if it changed. */
|
|
47
|
+
std::string focus_value;
|
|
48
|
+
bool focus_value_valid = false;
|
|
49
|
+
/** IME composition: `composition` is displayed at the selection until the
|
|
50
|
+
* `compositionend` commit inserts it into `value`. */
|
|
51
|
+
bool composing = false;
|
|
52
|
+
std::string composition;
|
|
53
|
+
int composition_start = 0;
|
|
54
|
+
int composition_end = 0;
|
|
55
|
+
/** `<select>`: index of the selected `<option>`, or -1 when it has none. */
|
|
56
|
+
int selected_index = -1;
|
|
57
|
+
/** Range drag in progress (paint and pointer dispatch share it). */
|
|
58
|
+
bool dragging = false;
|
|
59
|
+
/** `<textarea>` first visible line (reserved; the engine paints from line 0). */
|
|
60
|
+
int scroll_top = 0;
|
|
61
|
+
};
|
|
62
|
+
|
|
29
63
|
/** A DOM node. Element/text/document are one type to keep the tree simple. */
|
|
30
64
|
struct Node {
|
|
31
65
|
NodeType type = NodeType::Element;
|
|
@@ -38,6 +72,8 @@ struct Node {
|
|
|
38
72
|
std::vector<Attr> attrs;
|
|
39
73
|
Node *parent = nullptr;
|
|
40
74
|
std::vector<std::unique_ptr<Node>> children;
|
|
75
|
+
/** Form-control state, allocated only for `<input>`/`<textarea>`/`<select>`. */
|
|
76
|
+
std::unique_ptr<FormState> form;
|
|
41
77
|
|
|
42
78
|
/* -- generated content (`::before` / `::after`) -------------------------
|
|
43
79
|
* A pseudo-element is a synthetic node owned by the document's per-restyle
|
|
@@ -83,8 +119,11 @@ struct Node {
|
|
|
83
119
|
int elementSiblingCount() const;
|
|
84
120
|
};
|
|
85
121
|
|
|
86
|
-
/** Parse an HTML document/fragment. Returns a Document node (never NULL).
|
|
87
|
-
|
|
122
|
+
/** Parse an HTML document/fragment. Returns a Document node (never NULL).
|
|
123
|
+
* `synthesize_structure` wraps a fragment in the implicit `<html>`/`<head>`/
|
|
124
|
+
* `<body>`; `innerHTML`/`insertAdjacentHTML` pass false because their result is
|
|
125
|
+
* inserted under an existing element. */
|
|
126
|
+
std::unique_ptr<Node> xt_html_parse(const std::string &html, bool synthesize_structure = true);
|
|
88
127
|
|
|
89
128
|
/** Serialize a subtree; used by diagnostics and tests. */
|
|
90
129
|
std::string xt_dom_to_string(const Node *node);
|
|
@@ -226,6 +226,15 @@ METHOD(doc_body_get) {
|
|
|
226
226
|
return xt_gui_node_handle(win, find_by_tag(win->document->root(), "body"));
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
METHOD(doc_head_get) {
|
|
230
|
+
(void)env;
|
|
231
|
+
(void)argc;
|
|
232
|
+
(void)argv;
|
|
233
|
+
XtGuiWindow *win = resolve_window(self);
|
|
234
|
+
if (win == nullptr || win->document == nullptr) return XT_UNDEFINED;
|
|
235
|
+
return xt_gui_node_handle(win, find_by_tag(win->document->root(), "head"));
|
|
236
|
+
}
|
|
237
|
+
|
|
229
238
|
METHOD(doc_document_element_get) {
|
|
230
239
|
(void)env;
|
|
231
240
|
(void)argc;
|
|
@@ -235,6 +244,25 @@ METHOD(doc_document_element_get) {
|
|
|
235
244
|
return xt_gui_node_handle(win, find_by_tag(win->document->root(), "html"));
|
|
236
245
|
}
|
|
237
246
|
|
|
247
|
+
/** `document.activeElement`: the focused element, or `<body>` when nothing is
|
|
248
|
+
* focused (a browser never answers "none" for a parsed document). A focus
|
|
249
|
+
* pointer left on a detached node falls back to the body too. */
|
|
250
|
+
METHOD(doc_active_element_get) {
|
|
251
|
+
(void)env;
|
|
252
|
+
(void)argc;
|
|
253
|
+
(void)argv;
|
|
254
|
+
XtGuiWindow *win = resolve_window(self);
|
|
255
|
+
if (win == nullptr || win->document == nullptr) return XT_NULL;
|
|
256
|
+
const xtgui::Node *root = win->document->root();
|
|
257
|
+
const xtgui::Node *focus = win->document->focus();
|
|
258
|
+
if (focus != nullptr && root != nullptr && root->contains(focus)) {
|
|
259
|
+
return xt_gui_node_handle(win, focus);
|
|
260
|
+
}
|
|
261
|
+
if (const xtgui::Node *body = find_by_tag(root, "body")) return xt_gui_node_handle(win, body);
|
|
262
|
+
if (const xtgui::Node *html = find_by_tag(root, "html")) return xt_gui_node_handle(win, html);
|
|
263
|
+
return XT_NULL;
|
|
264
|
+
}
|
|
265
|
+
|
|
238
266
|
#undef METHOD
|
|
239
267
|
|
|
240
268
|
} // namespace domapi
|
|
@@ -26,10 +26,11 @@ static xt_value make_dom_event(XtGuiWindow *win, const char *type, const xtgui::
|
|
|
26
26
|
xt_object_set(event, xt_string_from_cstr("timeStamp"), xt_number((double)SDL_GetTicks()));
|
|
27
27
|
if (XT_IS_OBJECT(legacy)) {
|
|
28
28
|
static const char *const fields[] = {
|
|
29
|
-
"x",
|
|
30
|
-
"deltaX",
|
|
31
|
-
"shift",
|
|
32
|
-
"metaKey",
|
|
29
|
+
"x", "y", "clientX", "clientY", "button", "clicks",
|
|
30
|
+
"deltaX", "deltaY", "key", "code", "repeat", "ctrl",
|
|
31
|
+
"shift", "alt", "meta", "ctrlKey", "shiftKey", "altKey",
|
|
32
|
+
"metaKey", "data", "inputType", "isComposing", "value", "charCode",
|
|
33
|
+
"keyCode", "relatedTarget", "detail", "submitter",
|
|
33
34
|
};
|
|
34
35
|
for (const char *field : fields) {
|
|
35
36
|
xt_value value = xt_object_get_cstr(legacy, field);
|
|
@@ -174,11 +175,11 @@ METHOD(event_composed_path) {
|
|
|
174
175
|
|
|
175
176
|
} // namespace domapi
|
|
176
177
|
|
|
177
|
-
|
|
178
|
+
bool xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node *target,
|
|
178
179
|
xt_value legacy) {
|
|
179
180
|
using namespace domapi;
|
|
180
|
-
if (win == nullptr || win->document == nullptr || target == nullptr) return;
|
|
181
|
-
if (win->node_listeners.empty()) return;
|
|
181
|
+
if (win == nullptr || win->document == nullptr || target == nullptr) return false;
|
|
182
|
+
if (win->node_listeners.empty()) return false;
|
|
182
183
|
std::vector<xtgui::Node *> path;
|
|
183
184
|
for (xtgui::Node *node = const_cast<xtgui::Node *>(target); node != nullptr; node = node->parent) {
|
|
184
185
|
path.push_back(node);
|
|
@@ -196,25 +197,27 @@ void xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node
|
|
|
196
197
|
for (xtgui::Node *node : path) xt_array_push(handlePath, xt_gui_node_handle(win, node));
|
|
197
198
|
xt_object_set(event, xt_string_from_cstr("__xt_gui_path"), handlePath);
|
|
198
199
|
bool bubbles = value_truthy(xt_object_get_cstr(event, "bubbles"));
|
|
200
|
+
bool stopped = false;
|
|
199
201
|
/* Capture phase: root -> target. */
|
|
200
|
-
for (auto it = path.rbegin(); it != path.rend(); ++it) {
|
|
202
|
+
for (auto it = path.rbegin(); it != path.rend() && !stopped; ++it) {
|
|
201
203
|
int32_t phase = *it == target ? 2 : 1;
|
|
202
|
-
if (call_node_listeners(win, *it, type, event, true, phase))
|
|
204
|
+
if (call_node_listeners(win, *it, type, event, true, phase)) stopped = true;
|
|
203
205
|
}
|
|
204
206
|
/* Bubble phase: target -> root; a non-bubbling event stops after the target
|
|
205
207
|
* (its non-capture listeners still run there). */
|
|
206
|
-
for (auto it = path.begin(); it != path.end(); ++it) {
|
|
208
|
+
for (auto it = path.begin(); it != path.end() && !stopped; ++it) {
|
|
207
209
|
if (!bubbles && *it != target) break;
|
|
208
210
|
int32_t phase = *it == target ? 2 : 3;
|
|
209
|
-
if (call_node_listeners(win, *it, type, event, false, phase))
|
|
211
|
+
if (call_node_listeners(win, *it, type, event, false, phase)) stopped = true;
|
|
210
212
|
}
|
|
213
|
+
return value_truthy(xt_object_get_cstr(event, "defaultPrevented"));
|
|
211
214
|
}
|
|
212
215
|
|
|
213
|
-
|
|
214
|
-
if (win == nullptr || target == nullptr) return;
|
|
216
|
+
bool xt_gui_dispatch_to_node(XtGuiWindow *win, const xtgui::Node *target, const char *type) {
|
|
217
|
+
if (win == nullptr || target == nullptr) return false;
|
|
215
218
|
xt_value legacy = xt_object_new();
|
|
216
219
|
xt_object_set(legacy, xt_string_from_cstr("type"), xt_string_from_cstr(type));
|
|
217
220
|
std::string describe = xtgui::xt_dom_describe(target);
|
|
218
221
|
xt_object_set(legacy, xt_string_from_cstr("target"), xt_string_from_cstr(describe.c_str()));
|
|
219
|
-
xt_gui_emit_dom_event(win, type, target, legacy);
|
|
222
|
+
return xt_gui_emit_dom_event(win, type, target, legacy);
|
|
220
223
|
}
|