xbintsc 0.6.10 → 0.6.13
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/ast/expressions.d.ts +6 -0
- package/dist/src/checker/globals.js +2 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-infer.js +1 -1
- package/dist/src/checker/type-infer.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/codegen/generator/calls/literals.js +4 -1
- package/dist/src/codegen/generator/calls/literals.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +3 -1
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +2 -6
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +9 -0
- package/dist/src/codegen/generator/expressions/primary.js +44 -7
- package/dist/src/codegen/generator/expressions/primary.js.map +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/bundler/commonjs.js +1 -1
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/symbols.js +6 -0
- package/dist/src/driver/bundler/symbols.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/src/extensions/node/index.js +2 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/readline/index.d.ts +12 -0
- package/dist/src/extensions/node/readline/index.js +27 -0
- package/dist/src/extensions/node/readline/index.js.map +1 -0
- package/dist/src/parser/declarations/functions.js +6 -0
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/literals.js +1 -1
- package/dist/src/parser/literals.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-modules.test.js +22 -0
- package/dist/tests/e2e/compile-modules.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 +44 -1
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +61 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +40 -1
- package/dist/tests/e2e/gui-css-coverage.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-features.test.js +100 -0
- package/dist/tests/e2e/gui-css-features.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +63 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-errors.test.d.ts +11 -0
- package/dist/tests/e2e/gui-errors.test.js +68 -0
- package/dist/tests/e2e/gui-errors.test.js.map +1 -0
- 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/gui-webgl2-shadow-sampler.test.js +7 -1
- package/dist/tests/e2e/gui-webgl2-shadow-sampler.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +4 -0
- package/dist/tests/e2e/harness.js +2 -0
- package/dist/tests/e2e/harness.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/dist/tests/e2e/readline.test.d.ts +7 -0
- package/dist/tests/e2e/readline.test.js +73 -0
- package/dist/tests/e2e/readline.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 +24 -3
- package/doc/gui/dom.md +28 -14
- package/doc/gui/input.md +74 -3
- package/doc/gui/known-issues.md +2 -1
- package/doc/gui/layout.md +5 -1
- package/doc/implemented/node/crypto.md +8 -0
- package/doc/implemented/node/fs.md +1 -1
- package/doc/implemented/node/readline.md +34 -0
- package/doc/implemented/node.md +1 -0
- package/doc/implemented/stdlib.md +10 -2
- package/doc/unimplemented/node/modules.md +2 -3
- package/doc/unimplemented/node.md +2 -2
- package/doc/zh-CN/gui/api.md +20 -3
- package/doc/zh-CN/gui/dom.md +23 -13
- package/doc/zh-CN/gui/input.md +65 -4
- package/doc/zh-CN/gui/known-issues.md +2 -1
- package/doc/zh-CN/gui/layout.md +4 -1
- 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/node/readline.md +33 -0
- package/doc/zh-CN/implemented/node.md +1 -0
- package/doc/zh-CN/implemented/stdlib.md +10 -2
- package/doc/zh-CN/unimplemented/node/modules.md +1 -2
- package/doc/zh-CN/unimplemented/node.md +2 -2
- package/package.json +7 -7
- package/runtime/ext_gui/browser_abort.cpp +2 -2
- package/runtime/ext_gui/browser_loop.cpp +1 -0
- package/runtime/ext_gui/browser_media.cpp +1 -1
- 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_canvas_image.cpp +2 -1
- package/runtime/ext_gui/dom_api_document.cpp +28 -0
- package/runtime/ext_gui/dom_api_events.cpp +18 -15
- package/runtime/ext_gui/dom_api_form.cpp +567 -0
- package/runtime/ext_gui/dom_api_internal.h +48 -214
- package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
- package/runtime/ext_gui/dom_api_node.cpp +28 -15
- package/runtime/ext_gui/dom_api_node_read.cpp +28 -1
- package/runtime/ext_gui/dom_api_proto.cpp +47 -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/error_report.cpp +166 -0
- 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.cpp +16 -0
- package/runtime/ext_gui/gui_engine.h +53 -4
- package/runtime/ext_gui/gui_events.cpp +67 -49
- 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/layout_inline.cpp +46 -14
- package/runtime/ext_gui/paint.cpp +26 -1
- package/runtime/ext_gui/paint_form.cpp +389 -0
- package/runtime/ext_gui/paint_internal.h +6 -0
- package/runtime/ext_gui/script.cpp +1 -1
- package/runtime/ext_gui/style.cpp +1 -0
- package/runtime/ext_gui/style.h +13 -0
- package/runtime/ext_gui/style_print.cpp +129 -0
- package/runtime/ext_gui/style_text.cpp +79 -0
- package/runtime/ext_gui/style_ua.cpp +42 -0
- package/runtime/ext_gui/warnings.cpp +5 -7
- package/runtime/ext_gui/webgl_texture.cpp +0 -8
- package/runtime/ext_gui/window.cpp +52 -62
- 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 +67 -0
- package/runtime/ext_node/readline/readline.c +572 -0
- package/runtime/rt.h +42 -0
- package/runtime/rt_internal.h +3 -2
- package/runtime/xt_crypto.c +132 -0
- package/runtime/xt_io/exception.inc +29 -6
- package/runtime/xt_loop.c +36 -1
- package/runtime/xt_promise.c +26 -2
- 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 +206 -6
- 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 +2 -6
- package/runtime/xt_url.c +0 -6
- package/runtime/xt_url_object.c +1 -1
- package/src/ast/expressions.ts +6 -0
- package/src/checker/globals.ts +2 -0
- package/src/checker/type-infer.ts +1 -1
- package/src/codegen/generator/calls/literals.ts +4 -1
- package/src/codegen/generator/expressions/assignment.ts +3 -1
- package/src/codegen/generator/expressions/operators.ts +2 -6
- package/src/codegen/generator/expressions/primary.ts +58 -6
- package/src/codegen/generator/state.ts +3 -0
- package/src/codegen/generator/tables.ts +3 -0
- package/src/driver/bundler/commonjs.ts +1 -1
- package/src/driver/bundler/symbols.ts +6 -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
- package/src/extensions/node/index.ts +2 -0
- package/src/extensions/node/readline/index.ts +31 -0
- package/src/parser/declarations/functions.ts +6 -0
- package/src/parser/literals.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xbintsc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
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.13",
|
|
76
|
+
"@xbintsc/linux-arm64": "0.6.13",
|
|
77
|
+
"@xbintsc/darwin-x64": "0.6.13",
|
|
78
|
+
"@xbintsc/darwin-arm64": "0.6.13",
|
|
79
|
+
"@xbintsc/win32-x64": "0.6.13",
|
|
80
|
+
"@xbintsc/win32-arm64": "0.6.13"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=22"
|
|
@@ -58,14 +58,14 @@ void call_abort_listener(xt_value fn, xt_value signal) {
|
|
|
58
58
|
xt_object_set(event, xt_string_from_cstr("defaultPrevented"), XT_FALSE);
|
|
59
59
|
if (XT_IS_FUNCTION(fn)) {
|
|
60
60
|
xt_value args[1] = {event};
|
|
61
|
-
|
|
61
|
+
xt_gui_invoke(fn, signal, 1, args);
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
if (XT_IS_OBJECT(fn)) {
|
|
65
65
|
xt_value handler = xt_object_get_cstr(fn, "handleEvent");
|
|
66
66
|
if (XT_IS_FUNCTION(handler)) {
|
|
67
67
|
xt_value args[1] = {event};
|
|
68
|
-
|
|
68
|
+
xt_gui_invoke(handler, fn, 1, args);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -75,6 +75,7 @@ xt_value browser_tick(xt_value self, xt_value env, int32_t argc, xt_value *argv)
|
|
|
75
75
|
if (record == NULL || !record->open) return XT_UNDEFINED;
|
|
76
76
|
xt_gui_pump_events();
|
|
77
77
|
xt_gui_render_window(record);
|
|
78
|
+
xt_promise_report_unhandled();
|
|
78
79
|
if (record->open && !record->animation_frames.empty()) arm_tick();
|
|
79
80
|
return XT_UNDEFINED;
|
|
80
81
|
}
|
|
@@ -54,7 +54,7 @@ void remove_listener(xt_value self, xt_value fn) {
|
|
|
54
54
|
void call_change_listener(xt_value fn, xt_value list, xt_value event) {
|
|
55
55
|
if (!XT_IS_FUNCTION(fn)) return;
|
|
56
56
|
xt_value args[1] = {event};
|
|
57
|
-
|
|
57
|
+
xt_gui_invoke(fn, list, 1, args);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
#define METHOD(name) xt_value name(xt_value self, xt_value env, int32_t argc, xt_value *argv)
|
|
@@ -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);
|
|
@@ -114,7 +114,8 @@ xt_value blob_callback(xt_value self, xt_value env, int32_t argc, xt_value *argv
|
|
|
114
114
|
xt_value fn = xt_closure_env(env, 0);
|
|
115
115
|
xt_value blob = xt_closure_env(env, 1);
|
|
116
116
|
xt_value args[1] = {blob};
|
|
117
|
-
|
|
117
|
+
xt_gui_invoke(fn, XT_UNDEFINED, 1, args);
|
|
118
|
+
return XT_UNDEFINED;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
121
|
} // namespace
|
|
@@ -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);
|
|
@@ -116,7 +117,7 @@ static bool call_node_listeners(XtGuiWindow *win, xtgui::Node *node, const char
|
|
|
116
117
|
xt_object_set(event, xt_string_from_cstr("__xt_gui_passive"),
|
|
117
118
|
listener.passive ? XT_TRUE : XT_FALSE);
|
|
118
119
|
xt_value args[1] = {event};
|
|
119
|
-
|
|
120
|
+
xt_gui_invoke(listener.fn, self, 1, args);
|
|
120
121
|
xt_object_set(event, xt_string_from_cstr("__xt_gui_passive"), previousPassive);
|
|
121
122
|
if (value_truthy(xt_object_get_cstr(event, "__stopImmediate"))) return true;
|
|
122
123
|
if (value_truthy(xt_object_get_cstr(event, "__stop"))) return true;
|
|
@@ -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
|
}
|