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
|
@@ -70,6 +70,14 @@ void xt_browser_schedule_frame(void);
|
|
|
70
70
|
/** Whether `run()` currently owns the frame loop (the pump then stays idle). */
|
|
71
71
|
int xt_gui_run_active(void);
|
|
72
72
|
|
|
73
|
+
/* Page-level error reporting (error_report.cpp). `xt_gui_invoke` runs one
|
|
74
|
+
* host-invoked callback under a `try` boundary so a throw reaches the window's
|
|
75
|
+
* `error`/`unhandledrejection` surfaces instead of terminating the process. */
|
|
76
|
+
void xt_gui_install_error_handlers(void);
|
|
77
|
+
void xt_gui_report_uncaught(xt_value error);
|
|
78
|
+
int xt_gui_unhandled_rejection(xt_value reason, xt_value promise);
|
|
79
|
+
int xt_gui_invoke(xt_value fn, xt_value thisValue, int32_t argc, xt_value *argv);
|
|
80
|
+
|
|
73
81
|
/* Web Audio objects (`audio.cpp`).
|
|
74
82
|
* `AudioContext.prototype` — also the `instanceof AudioContext` target. */
|
|
75
83
|
xt_value xt_gui_audio_proto(void);
|
|
@@ -244,6 +252,11 @@ struct XtGuiWindow {
|
|
|
244
252
|
/** Resolve a window handle (`this`) to its record, or NULL for a foreign value. */
|
|
245
253
|
XtGuiWindow *xt_gui_window_from_this(xt_value thisValue);
|
|
246
254
|
|
|
255
|
+
/** The most recently created live window, or NULL when none is open. Error
|
|
256
|
+
* reporting uses it because a throw can escape a callback with no window
|
|
257
|
+
* argument. */
|
|
258
|
+
XtGuiWindow *xt_gui_primary_window(void);
|
|
259
|
+
|
|
247
260
|
|
|
248
261
|
/** The `document` handle for `win` (created on first use). */
|
|
249
262
|
xt_value xt_gui_document_handle(XtGuiWindow *win);
|
|
@@ -255,11 +268,14 @@ xt_value xt_gui_node_handle(XtGuiWindow *win, const xtgui::Node *node);
|
|
|
255
268
|
void xt_gui_node_handle_forget(XtGuiWindow *win, const xtgui::Node *node);
|
|
256
269
|
/** Drop every cached handle/listener and bump the document generation. */
|
|
257
270
|
void xt_gui_handles_reset(XtGuiWindow *win);
|
|
258
|
-
/** Deliver `type` to element listeners along the propagation path.
|
|
259
|
-
|
|
271
|
+
/** Deliver `type` to element listeners along the propagation path. Returns
|
|
272
|
+
* true when a listener called `preventDefault()` (the caller then skips the
|
|
273
|
+
* default action). */
|
|
274
|
+
bool xt_gui_emit_dom_event(XtGuiWindow *win, const char *type, const xtgui::Node *target,
|
|
260
275
|
xt_value legacy_payload);
|
|
261
|
-
/** Synthesise a DOM event whose target is `target` (used by element.click()).
|
|
262
|
-
|
|
276
|
+
/** Synthesise a DOM event whose target is `target` (used by element.click()).
|
|
277
|
+
* Returns true when a listener called `preventDefault()`. */
|
|
278
|
+
bool xt_gui_dispatch_to_node(XtGuiWindow *win, const xtgui::Node *target, const char *type);
|
|
263
279
|
/** Apply any pending DOM mutation (restyle/relayout) before a synchronous read. */
|
|
264
280
|
void xt_gui_flush_dom(XtGuiWindow *win);
|
|
265
281
|
/** Run every registered `<script data-xt-id>` body found in the document, in
|
|
@@ -311,6 +327,39 @@ void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float
|
|
|
311
327
|
void xt_gui_dispatch_wheel(XtGuiWindow *win, float x, float y, float delta_x, float delta_y);
|
|
312
328
|
/** Synthesise a key event (`keydown`/`keyup`). */
|
|
313
329
|
void xt_gui_dispatch_key(XtGuiWindow *win, const char *type, const char *key, const char *code);
|
|
330
|
+
/** Synthesise a key event with explicit modifier/repeat flags. */
|
|
331
|
+
void xt_gui_dispatch_key_with_modifiers(XtGuiWindow *win, const char *type, const char *key,
|
|
332
|
+
const char *code, bool repeat, bool ctrl, bool shift,
|
|
333
|
+
bool alt, bool meta);
|
|
334
|
+
|
|
335
|
+
/* -- form controls (`form_input.cpp`) ------------------------------------ */
|
|
336
|
+
|
|
337
|
+
/** Focus `node` (or clear focus when null). Updates the control's focused flag,
|
|
338
|
+
* starts/stops SDL text input and repaints. Returns true when the focus moved. */
|
|
339
|
+
bool xt_gui_set_focus(XtGuiWindow *win, xtgui::Node *node);
|
|
340
|
+
/** Commit `text` as typed input to the focused editable control, dispatching
|
|
341
|
+
* `keypress` then `input`. */
|
|
342
|
+
void xt_gui_text_input(XtGuiWindow *win, const char *text);
|
|
343
|
+
/** IME composing text update (`SDL_EVENT_TEXT_EDITING`): shows `text` at the
|
|
344
|
+
* caret until the commit. */
|
|
345
|
+
void xt_gui_text_editing(XtGuiWindow *win, const char *text, int start, int length);
|
|
346
|
+
/** Synthesise a composition event (`compositionstart`/`update`/`end`). */
|
|
347
|
+
void xt_gui_composition_event(XtGuiWindow *win, const char *type, const char *data);
|
|
348
|
+
/** Default keydown action for the focused editable control (text editing,
|
|
349
|
+
* clipboard, caret movement). Called after the DOM listeners did not cancel. */
|
|
350
|
+
void xt_gui_form_key_down(XtGuiWindow *win, xt_value payload);
|
|
351
|
+
/** Pointer default action (focus/caret placement, checkbox toggle, range drag). */
|
|
352
|
+
void xt_gui_form_pointer(XtGuiWindow *win, const char *type, xtgui::Node *node, float x, float y);
|
|
353
|
+
/** Run a control's activation behaviour (checkbox/radio toggle, select cycle). */
|
|
354
|
+
void xt_gui_form_activate(XtGuiWindow *win, xtgui::Node *node);
|
|
355
|
+
/** Move focus to the next (`forward`) / previous tabbable element. */
|
|
356
|
+
void xt_gui_focus_step(XtGuiWindow *win, bool forward);
|
|
357
|
+
/** Fire `submit` on a `<form>` (no navigation); `submitter` may be null. */
|
|
358
|
+
void xt_gui_form_submit_request(XtGuiWindow *win, xtgui::Node *form, xtgui::Node *submitter);
|
|
359
|
+
/** Reset every control in a `<form>` to its default value/checked state. */
|
|
360
|
+
void xt_gui_form_reset(XtGuiWindow *win, xtgui::Node *form);
|
|
361
|
+
/** Set a control's caret from a viewport x coordinate (click positioning). */
|
|
362
|
+
void xt_gui_form_focus_at(XtGuiWindow *win, xtgui::Node *node, float x);
|
|
314
363
|
/** Translate one physical key (SDL scancode/keycode + modifiers) to the browser
|
|
315
364
|
* `key`/`code` names and dispatch it to the DOM and window listeners. */
|
|
316
365
|
void xt_gui_dispatch_physical_key(XtGuiWindow *win, const char *type, int scancode, int keycode,
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
#include "gui_keymap.h"
|
|
8
8
|
#include "listener_options.h"
|
|
9
9
|
|
|
10
|
+
#include "form_state.h"
|
|
10
11
|
#include "paint.h"
|
|
11
12
|
#include "perf.h"
|
|
12
13
|
|
|
@@ -18,48 +19,6 @@
|
|
|
18
19
|
|
|
19
20
|
using namespace guidev;
|
|
20
21
|
|
|
21
|
-
/* -- window events -------------------------------------------------------- */
|
|
22
|
-
|
|
23
|
-
void xt_gui_emit(XtGuiWindow *win, const char *event) {
|
|
24
|
-
xt_gui_emit_payload(win, event, XT_UNDEFINED);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Drop one window listener (by identity: type + fn + capture). */
|
|
28
|
-
static void remove_window_listener(XtGuiWindow *win, const XtGuiWindowListener &listener) {
|
|
29
|
-
std::vector<XtGuiWindowListener> &listeners = win->window_listeners;
|
|
30
|
-
for (auto it = listeners.begin(); it != listeners.end(); ++it) {
|
|
31
|
-
if (it->type == listener.type && it->capture == listener.capture &&
|
|
32
|
-
xt_truthy(xt_seq(it->fn, listener.fn))) {
|
|
33
|
-
listeners.erase(it);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
void xt_gui_emit_payload(XtGuiWindow *win, const char *event, xt_value payload) {
|
|
40
|
-
if (win == NULL || !XT_IS_OBJECT(win->object)) return;
|
|
41
|
-
xt_value args[1];
|
|
42
|
-
int32_t count = 0;
|
|
43
|
-
if (!XT_IS_UNDEFINED(payload)) {
|
|
44
|
-
args[0] = payload;
|
|
45
|
-
count = 1;
|
|
46
|
-
}
|
|
47
|
-
/* Snapshot the list: a handler may register or remove listeners while it
|
|
48
|
-
* runs, and the DOM runs the batch as it stood when dispatch started. */
|
|
49
|
-
std::vector<XtGuiWindowListener> snapshot = win->window_listeners;
|
|
50
|
-
for (const XtGuiWindowListener &listener : snapshot) {
|
|
51
|
-
if (listener.type != event) continue;
|
|
52
|
-
/* `{ signal }` removes the listener at abort time (checked here, so no
|
|
53
|
-
* callback plumbing is needed inside the signal). */
|
|
54
|
-
if (xt_gui_signal_aborted(listener.signal)) {
|
|
55
|
-
remove_window_listener(win, listener);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (listener.once) remove_window_listener(win, listener);
|
|
59
|
-
if (XT_IS_FUNCTION(listener.fn)) xt_call_with_this(listener.fn, win->object, count, args);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
22
|
void xt_gui_flush_dom(XtGuiWindow *win) {
|
|
64
23
|
if (win == NULL || win->document == nullptr) return;
|
|
65
24
|
bool mutated = win->struct_dirty != 0;
|
|
@@ -187,27 +146,45 @@ void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float
|
|
|
187
146
|
int clicks) {
|
|
188
147
|
if (win == NULL || !win->open) return;
|
|
189
148
|
const xtgui::Node *node = xt_gui_hit_node(win, x, y);
|
|
149
|
+
xtgui::Node *target = const_cast<xtgui::Node *>(node);
|
|
190
150
|
xt_gui_update_hover(win, node);
|
|
151
|
+
bool prevented = false;
|
|
191
152
|
if (win->document != nullptr) {
|
|
192
153
|
if (strcmp(type, "mousedown") == 0) {
|
|
193
|
-
if (
|
|
194
|
-
win
|
|
195
|
-
|
|
154
|
+
if (target != nullptr && xtgui::xt_form_is_focusable(target)) {
|
|
155
|
+
xt_gui_form_pointer(win, "mousedown", target, x, y);
|
|
156
|
+
} else if (target != nullptr && xtgui::xt_form_is_control(target)) {
|
|
157
|
+
/* A disabled/hidden control is not focusable and does not take focus. */
|
|
158
|
+
xt_gui_set_focus(win, nullptr);
|
|
159
|
+
} else {
|
|
160
|
+
xt_gui_set_focus(win, target);
|
|
196
161
|
}
|
|
197
162
|
if (win->document->setActive(node)) {
|
|
198
163
|
win->geometry.dirty = 1;
|
|
199
164
|
win->present_dirty = 1;
|
|
200
165
|
}
|
|
201
166
|
} else if (strcmp(type, "mouseup") == 0) {
|
|
167
|
+
const xtgui::Node *active = win->document->active();
|
|
168
|
+
if (active != nullptr && active->form && active->form->dragging) {
|
|
169
|
+
xt_gui_form_pointer(win, "mouseup", const_cast<xtgui::Node *>(active), x, y);
|
|
170
|
+
}
|
|
202
171
|
if (win->document->setActive(nullptr)) {
|
|
203
172
|
win->geometry.dirty = 1;
|
|
204
173
|
win->present_dirty = 1;
|
|
205
174
|
}
|
|
175
|
+
} else if (strcmp(type, "mousemove") == 0) {
|
|
176
|
+
const xtgui::Node *active = win->document->active();
|
|
177
|
+
if (active != nullptr && active->form && active->form->dragging) {
|
|
178
|
+
xt_gui_form_pointer(win, "mousemove", const_cast<xtgui::Node *>(active), x, y);
|
|
179
|
+
}
|
|
206
180
|
}
|
|
207
181
|
}
|
|
208
182
|
xt_value payload = xt_gui_pointer_payload(type, win, x, y, button, clicks, node);
|
|
209
|
-
if (node != nullptr) xt_gui_emit_dom_event(win, type, node, payload);
|
|
183
|
+
if (node != nullptr) prevented = xt_gui_emit_dom_event(win, type, node, payload);
|
|
210
184
|
xt_gui_emit_payload(win, type, payload);
|
|
185
|
+
if (!prevented && node != nullptr && strcmp(type, "click") == 0) {
|
|
186
|
+
xt_gui_form_pointer(win, "click", target, x, y);
|
|
187
|
+
}
|
|
211
188
|
}
|
|
212
189
|
|
|
213
190
|
void xt_gui_dispatch_wheel(XtGuiWindow *win, float x, float y, float delta_x, float delta_y) {
|
|
@@ -262,12 +239,26 @@ static const xtgui::Node *xt_gui_key_target(XtGuiWindow *win) {
|
|
|
262
239
|
}
|
|
263
240
|
|
|
264
241
|
/** Deliver one fully built keyboard payload to the DOM (bubbling from the
|
|
265
|
-
* focused element / body to `document`) and then to `window` listeners.
|
|
242
|
+
* focused element / body to `document`) and then to `window` listeners. When
|
|
243
|
+
* the DOM did not cancel a `keydown`, run the focused control's editing
|
|
244
|
+
* default action. */
|
|
266
245
|
static void xt_gui_dispatch_key_payload(XtGuiWindow *win, const char *type, xt_value payload) {
|
|
267
246
|
if (win == NULL || !win->open) return;
|
|
268
247
|
const xtgui::Node *node = xt_gui_key_target(win);
|
|
269
|
-
|
|
248
|
+
bool prevented = false;
|
|
249
|
+
if (node != nullptr) prevented = xt_gui_emit_dom_event(win, type, node, payload);
|
|
270
250
|
xt_gui_emit_payload(win, type, payload);
|
|
251
|
+
if (!prevented && strcmp(type, "keydown") == 0) {
|
|
252
|
+
xt_gui_form_key_down(win, payload);
|
|
253
|
+
/* Tab is the one editing command that works from any element, not only a
|
|
254
|
+
* focused text field: move focus along the tabbable order. */
|
|
255
|
+
xt_value key = xt_object_get_cstr(payload, "key");
|
|
256
|
+
if (XT_IS_STRING(key) && strcmp(xt_string_data(key), "Tab") == 0) {
|
|
257
|
+
bool shift = xt_truthy(xt_object_get_cstr(payload, "shiftKey")) ||
|
|
258
|
+
xt_truthy(xt_object_get_cstr(payload, "shift"));
|
|
259
|
+
xt_gui_focus_step(win, !shift);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
271
262
|
}
|
|
272
263
|
|
|
273
264
|
void xt_gui_dispatch_key(XtGuiWindow *win, const char *type, const char *key, const char *code) {
|
|
@@ -275,6 +266,13 @@ void xt_gui_dispatch_key(XtGuiWindow *win, const char *type, const char *key, co
|
|
|
275
266
|
xt_gui_dispatch_key_payload(win, type, payload);
|
|
276
267
|
}
|
|
277
268
|
|
|
269
|
+
void xt_gui_dispatch_key_with_modifiers(XtGuiWindow *win, const char *type, const char *key,
|
|
270
|
+
const char *code, bool repeat, bool ctrl, bool shift,
|
|
271
|
+
bool alt, bool meta) {
|
|
272
|
+
xt_value payload = xt_gui_key_payload(type, key, code, repeat, ctrl, shift, alt, meta);
|
|
273
|
+
xt_gui_dispatch_key_payload(win, type, payload);
|
|
274
|
+
}
|
|
275
|
+
|
|
278
276
|
void xt_gui_dispatch_physical_key(XtGuiWindow *win, const char *type, int scancode, int keycode,
|
|
279
277
|
bool repeat, bool ctrl, bool shift, bool alt, bool meta,
|
|
280
278
|
bool caps_lock) {
|
|
@@ -284,6 +282,10 @@ void xt_gui_dispatch_physical_key(XtGuiWindow *win, const char *type, int scanco
|
|
|
284
282
|
caps_lock, &key, &code);
|
|
285
283
|
xt_value payload = xt_gui_key_payload(type, key.c_str(), code.c_str(), repeat, ctrl, shift, alt,
|
|
286
284
|
meta);
|
|
285
|
+
/* Mark the payload so the editing default action knows the produced text will
|
|
286
|
+
* arrive separately as `SDL_EVENT_TEXT_INPUT` (inserting the US `key` here too
|
|
287
|
+
* would double every character on an IME or non-US layout). */
|
|
288
|
+
xt_object_set(payload, xt_string_from_cstr("__xt_gui_physical"), XT_TRUE);
|
|
287
289
|
xt_gui_dispatch_key_payload(win, type, payload);
|
|
288
290
|
}
|
|
289
291
|
|
|
@@ -302,6 +304,9 @@ void handle_event(const SDL_Event *event) {
|
|
|
302
304
|
if (event->type == SDL_EVENT_WINDOW_RESIZED) {
|
|
303
305
|
XtGuiWindow *win = xt_gui_find_by_window_id(event->window.windowID);
|
|
304
306
|
if (win == NULL || !win->open) return;
|
|
307
|
+
/* `setSize` already applied and emitted the change synchronously; the
|
|
308
|
+
* queued backend event must not deliver the same resize twice. */
|
|
309
|
+
if (win->width == event->window.data1 && win->height == event->window.data2) return;
|
|
305
310
|
win->width = event->window.data1;
|
|
306
311
|
win->height = event->window.data2;
|
|
307
312
|
if (win->document != NULL) win->document->restyle((float)win->width, (float)win->height);
|
|
@@ -327,6 +332,19 @@ void handle_event(const SDL_Event *event) {
|
|
|
327
332
|
return;
|
|
328
333
|
}
|
|
329
334
|
|
|
335
|
+
if (event->type == SDL_EVENT_TEXT_INPUT) {
|
|
336
|
+
XtGuiWindow *win = xt_gui_find_by_window_id(event->text.windowID);
|
|
337
|
+
if (win == NULL || !win->open) return;
|
|
338
|
+
xt_gui_text_input(win, event->text.text);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (event->type == SDL_EVENT_TEXT_EDITING) {
|
|
342
|
+
XtGuiWindow *win = xt_gui_find_by_window_id(event->edit.windowID);
|
|
343
|
+
if (win == NULL || !win->open) return;
|
|
344
|
+
xt_gui_text_editing(win, event->edit.text, event->edit.start, event->edit.length);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
330
348
|
if (event->type == SDL_EVENT_MOUSE_MOTION) {
|
|
331
349
|
XtGuiWindow *win = xt_gui_find_by_window_id(event->motion.windowID);
|
|
332
350
|
xt_gui_dispatch_pointer(win, "mousemove", event->motion.x, event->motion.y, -1, 0);
|
|
@@ -386,7 +404,7 @@ void xt_gui_run_animation_frames(XtGuiWindow *win, double timestamp_ms) {
|
|
|
386
404
|
for (const XtGuiAnimationFrame &frame : frames) {
|
|
387
405
|
if (!win->open) break;
|
|
388
406
|
xt_value arg = xt_number(timestamp_ms);
|
|
389
|
-
|
|
407
|
+
xt_gui_invoke(frame.fn, win->object, 1, &arg);
|
|
390
408
|
}
|
|
391
409
|
frames.clear();
|
|
392
410
|
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
#include "image.h"
|
|
24
24
|
#include "inline_svg.h"
|
|
25
25
|
#include "perf.h"
|
|
26
|
+
#include "form_state.h"
|
|
26
27
|
#include "style_internal.h"
|
|
27
28
|
|
|
28
29
|
namespace xtgui {
|
|
@@ -128,7 +129,12 @@ std::unique_ptr<LayoutBox> buildBoxTree(const Node *node,
|
|
|
128
129
|
}
|
|
129
130
|
if (box->intrinsic_width <= 0.0f) box->intrinsic_width = 300.0f;
|
|
130
131
|
if (box->intrinsic_height <= 0.0f) box->intrinsic_height = 150.0f;
|
|
132
|
+
} else if (node->isElement() && xt_form_is_control(node)) {
|
|
133
|
+
/* A form control is a leaf: its `<option>`/text children are the model, not
|
|
134
|
+
* laid-out boxes (the value is painted from `Node::form`). */
|
|
135
|
+
box->is_control = true;
|
|
131
136
|
}
|
|
137
|
+
if (box->is_control) return box;
|
|
132
138
|
if (box->is_inline_svg) return box;
|
|
133
139
|
|
|
134
140
|
/* `::before` / `::after` boxes are emitted around the DOM children. Only a
|
package/runtime/ext_gui/layout.h
CHANGED
|
@@ -89,6 +89,10 @@ struct LayoutBox {
|
|
|
89
89
|
bool is_canvas = false;
|
|
90
90
|
uint64_t canvas_id = 0;
|
|
91
91
|
|
|
92
|
+
/* `<input>` / `<textarea>` / `<select>`: a leaf box whose content is painted
|
|
93
|
+
* from the node's `FormState` (value, caret, decorations). */
|
|
94
|
+
bool is_control = false;
|
|
95
|
+
|
|
92
96
|
/* Inline `<svg>`: a replaced element whose pixels are the serialized subtree
|
|
93
97
|
* (`svg_markup`), rasterised like an SVG file at the drawn device size. The
|
|
94
98
|
* normal box walk does not descend into its children — they are vector art,
|
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
#include "layout_flow_internal.h"
|
|
10
10
|
|
|
11
|
+
#include "form_state.h"
|
|
12
|
+
|
|
11
13
|
namespace xtgui {
|
|
12
14
|
namespace layout_flow_detail {
|
|
13
15
|
|
|
@@ -44,6 +46,13 @@ float Layouter::verticalEdges(const LayoutBox *box) const {
|
|
|
44
46
|
float Layouter::preferredContentWidth(const LayoutBox *box, float available) const {
|
|
45
47
|
const XtStyle &style = *box->style;
|
|
46
48
|
if (!isAuto(style.width)) return px(style.width, available, style.font_size, 0.0f);
|
|
49
|
+
if (box->is_control) {
|
|
50
|
+
float width = 0.0f;
|
|
51
|
+
float height = 0.0f;
|
|
52
|
+
xt_form_intrinsic_size(box->node, style, &width, &height);
|
|
53
|
+
(void)height;
|
|
54
|
+
if (width > 0.0f) return width;
|
|
55
|
+
}
|
|
47
56
|
if ((box->is_image || box->is_canvas || box->is_inline_svg) && box->intrinsic_width > 0)
|
|
48
57
|
return box->intrinsic_width;
|
|
49
58
|
if (box->is_text) {
|
|
@@ -322,7 +331,20 @@ float Layouter::layoutBlock(LayoutBox *box, float x, float y, float availableWid
|
|
|
322
331
|
}
|
|
323
332
|
|
|
324
333
|
float contentHeight;
|
|
325
|
-
if (
|
|
334
|
+
if (box->is_control) {
|
|
335
|
+
/* Controls are leaves with an intrinsic content height (a line, a textarea's
|
|
336
|
+
* rows, 13px for a checkbox, …); their children are not boxes. */
|
|
337
|
+
float intrinsic_width = 0.0f;
|
|
338
|
+
float intrinsic_height = 0.0f;
|
|
339
|
+
xt_form_intrinsic_size(box->node, style, &intrinsic_width, &intrinsic_height);
|
|
340
|
+
(void)intrinsic_width;
|
|
341
|
+
contentHeight = forcedContentHeight >= 0
|
|
342
|
+
? forcedContentHeight
|
|
343
|
+
: (definiteHeight >= 0 ? definiteHeight : intrinsic_height);
|
|
344
|
+
contentHeight = clampSize(contentHeight, style.min_height, style.max_height,
|
|
345
|
+
availableHeight < 0 ? contentHeight : availableHeight, em);
|
|
346
|
+
if (contentHeight < 0) contentHeight = 0;
|
|
347
|
+
} else if (forcedContentHeight >= 0) {
|
|
326
348
|
layoutChildren(box, contentWidth, availableHeight, forcedContentHeight);
|
|
327
349
|
contentHeight = forcedContentHeight;
|
|
328
350
|
} else {
|
|
@@ -67,7 +67,10 @@ void Layouter::flattenInline(LayoutBox *box, float contentWidth,
|
|
|
67
67
|
float available = contentWidth;
|
|
68
68
|
float intrinsic = preferredContentWidth(box, available);
|
|
69
69
|
setContainingBlock(box, containingBlockAncestor(box));
|
|
70
|
-
|
|
70
|
+
/* An explicit width must go through the normal used-width path so
|
|
71
|
+
* `box-sizing: border-box` can subtract padding and borders. Only an `auto`
|
|
72
|
+
* width needs the shrink-to-fit content width forced here. */
|
|
73
|
+
layoutBlock(box, 0, 0, available, -1, isAuto(style.width) ? intrinsic : -1.0f);
|
|
71
74
|
InlineItem item;
|
|
72
75
|
item.box = box;
|
|
73
76
|
item.style = &style;
|
|
@@ -274,24 +277,53 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
|
|
|
274
277
|
lineDescent = 0;
|
|
275
278
|
};
|
|
276
279
|
|
|
277
|
-
for (
|
|
280
|
+
for (size_t index = 0; index < items.size(); index++) {
|
|
281
|
+
InlineItem &item = items[index];
|
|
278
282
|
if (item.force_break) {
|
|
279
283
|
finalize();
|
|
280
284
|
continue;
|
|
281
285
|
}
|
|
282
286
|
if (item.is_space && line.empty()) continue; // no leading space on a line
|
|
283
|
-
/*
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
287
|
+
/* A `break-word`/`anywhere` word that does not fit is split at the
|
|
288
|
+
* largest prefix the remaining line can hold; the remainder is processed
|
|
289
|
+
* again on the next line. Without this a long token overflowed the box. */
|
|
290
|
+
for (;;) {
|
|
291
|
+
/* Break against the band the line would occupy, then place it. */
|
|
292
|
+
float pendingHeight = std::max(lineAscent + lineDescent, item.height);
|
|
293
|
+
float x0 = 0;
|
|
294
|
+
float x1 = 0;
|
|
295
|
+
band(cursorY, pendingHeight, &x0, &x1);
|
|
296
|
+
float available = x1 - x0;
|
|
297
|
+
bool overflows = lineWidth + item.width > available + 0.001f;
|
|
298
|
+
if (wrap && overflows) {
|
|
299
|
+
bool breakWord = item.style != nullptr &&
|
|
300
|
+
item.style->overflow_wrap != OverflowWrap::Normal;
|
|
301
|
+
if (breakWord && !item.atomic && !item.is_space && item.text.size() > 1) {
|
|
302
|
+
float room = available - lineWidth;
|
|
303
|
+
size_t prefix = fittingPrefix(item.text, *item.style, room);
|
|
304
|
+
if (prefix > 0 && prefix < item.text.size()) {
|
|
305
|
+
InlineItem head = item;
|
|
306
|
+
head.text = item.text.substr(0, prefix);
|
|
307
|
+
head.width = textWidth(head.text, *item.style);
|
|
308
|
+
line.push_back(&head);
|
|
309
|
+
lineWidth += head.width;
|
|
310
|
+
lineAscent = std::max(lineAscent, head.ascent);
|
|
311
|
+
lineDescent = std::max(lineDescent, head.height - head.ascent);
|
|
312
|
+
finalize();
|
|
313
|
+
item.text = item.text.substr(prefix);
|
|
314
|
+
item.width = textWidth(item.text, *item.style);
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!line.empty()) finalize();
|
|
319
|
+
}
|
|
320
|
+
if (item.is_space && line.empty()) break;
|
|
321
|
+
line.push_back(&item);
|
|
322
|
+
lineWidth += item.width;
|
|
323
|
+
lineAscent = std::max(lineAscent, item.ascent);
|
|
324
|
+
lineDescent = std::max(lineDescent, item.height - item.ascent);
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
295
327
|
}
|
|
296
328
|
finalize();
|
|
297
329
|
|
|
@@ -173,6 +173,28 @@ void addTextRuns(const LayoutBox *box, const XtStyle &style, DisplayList &out,
|
|
|
173
173
|
paint_detail::addTextRun(out, fragment.x, fragment.y + ascent, fragment.width,
|
|
174
174
|
fragment.height, fragment.text, spec, base, box->world, clip, style,
|
|
175
175
|
chain, viewportWidth, viewportHeight);
|
|
176
|
+
if (style.text_decoration_line != 0) {
|
|
177
|
+
/* The decoration uses the element's text colour unless the shorthand
|
|
178
|
+
* named one. Dashed/dotted/wavy are currently painted solid; the style
|
|
179
|
+
* is still retained for `getComputedStyle`. */
|
|
180
|
+
Color rule = paint_detail::filterColor(
|
|
181
|
+
chain, style.has_text_decoration_color ? style.text_decoration_color : style.color);
|
|
182
|
+
float thickness = std::max(1.0f, style.font_size / 14.0f);
|
|
183
|
+
float baseline = fragment.y + ascent;
|
|
184
|
+
if (style.text_decoration_line & (uint8_t)TextDecorationLine::Underline) {
|
|
185
|
+
paint_detail::addRect(out, fragment.x, baseline + thickness, fragment.width, thickness,
|
|
186
|
+
0.0f, rule, clip, box->world);
|
|
187
|
+
}
|
|
188
|
+
if (style.text_decoration_line & (uint8_t)TextDecorationLine::Overline) {
|
|
189
|
+
paint_detail::addRect(out, fragment.x, fragment.y, fragment.width, thickness, 0.0f, rule,
|
|
190
|
+
clip, box->world);
|
|
191
|
+
}
|
|
192
|
+
if (style.text_decoration_line & (uint8_t)TextDecorationLine::LineThrough) {
|
|
193
|
+
paint_detail::addRect(out, fragment.x,
|
|
194
|
+
fragment.y + fragment.height * 0.55f - thickness / 2.0f,
|
|
195
|
+
fragment.width, thickness, 0.0f, rule, clip, box->world);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
176
198
|
continue;
|
|
177
199
|
}
|
|
178
200
|
if (fragment.upright) {
|
|
@@ -279,7 +301,10 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
279
301
|
paint_detail::addBoxShadows(out, *box, *style, chain, own, true, viewportWidth,
|
|
280
302
|
viewportHeight);
|
|
281
303
|
paint_detail::addOutline(out, *box, *style, chain, own, viewportWidth, viewportHeight);
|
|
282
|
-
if (box->
|
|
304
|
+
if (box->is_control) {
|
|
305
|
+
paint_detail::xt_paint_form_control(*box, *style, out, contentClip, chain, viewportWidth,
|
|
306
|
+
viewportHeight);
|
|
307
|
+
} else if (box->is_canvas && box->canvas_id != 0 && box->content_width > 0.0f &&
|
|
283
308
|
box->content_height > 0.0f) {
|
|
284
309
|
PaintImage image;
|
|
285
310
|
image.x = box->content_x;
|