@native-sdk/cli 0.5.4 → 0.6.1
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/build/app.zig +50 -1
- package/build.zig +588 -32
- package/build.zig.zon +7 -0
- package/native-sdk.d.ts +3 -1
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/rt/rt.zig +280 -8
- package/packages/core/sdk/core.ts +481 -2
- package/packages/core/sdk/events.ts +17 -8
- package/packages/core/src/checker.ts +305 -2
- package/packages/core/src/diagnostics.ts +12 -0
- package/packages/core/src/emitter.ts +599 -3
- package/packages/core/src/typed_ast.ts +51 -4
- package/packages/core/src/types.ts +34 -1
- package/skill-data/native-ui/SKILL.md +39 -2
- package/skill-data/ts-core/SKILL.md +4 -2
- package/src/app_runner/root.zig +32 -10
- package/src/automation/layout_fingerprint.zig +160 -0
- package/src/automation/protocol.zig +82 -33
- package/src/automation/root.zig +1 -0
- package/src/automation/server.zig +1 -1
- package/src/automation/snapshot.zig +68 -9
- package/src/automation/watcher.zig +1 -1
- package/src/embed/host.zig +5 -0
- package/src/embed/ui_host.zig +13 -0
- package/src/platform/linux/gtk_host.c +527 -13
- package/src/platform/linux/gtk_host.h +25 -0
- package/src/platform/linux/root.zig +280 -7
- package/src/platform/macos/appkit_host.h +104 -6
- package/src/platform/macos/appkit_host.m +1368 -74
- package/src/platform/macos/cef_host.mm +110 -1
- package/src/platform/macos/root.zig +287 -7
- package/src/platform/null_platform.zig +398 -4
- package/src/platform/null_platform_tests.zig +35 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +386 -14
- package/src/platform/windows/root.zig +298 -9
- package/src/platform/windows/webview2_host.cpp +330 -5
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/canvas/a11y_audit.zig +33 -11
- package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
- package/src/primitives/canvas/drawing.zig +25 -0
- package/src/primitives/canvas/equality.zig +8 -0
- package/src/primitives/canvas/events.zig +103 -16
- package/src/primitives/canvas/frame.zig +125 -1
- package/src/primitives/canvas/layout_audit.zig +22 -5
- package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
- package/src/primitives/canvas/render_tests.zig +13 -10
- package/src/primitives/canvas/root.zig +48 -0
- package/src/primitives/canvas/terminal_box.zig +471 -0
- package/src/primitives/canvas/terminal_grid.zig +978 -0
- package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_tests.zig +39 -4
- package/src/primitives/canvas/tokens.zig +115 -12
- package/src/primitives/canvas/ui.zig +524 -5
- package/src/primitives/canvas/ui_markup.zig +195 -2
- package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
- package/src/primitives/canvas/ui_markup_contract.zig +88 -5
- package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
- package/src/primitives/canvas/ui_markup_tests.zig +149 -0
- package/src/primitives/canvas/ui_markup_view.zig +191 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
- package/src/primitives/canvas/ui_schema.zig +97 -17
- package/src/primitives/canvas/ui_schema_tests.zig +18 -11
- package/src/primitives/canvas/ui_tests.zig +141 -9
- package/src/primitives/canvas/widget_access.zig +28 -2
- package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
- package/src/primitives/canvas/widget_invalidation.zig +81 -1
- package/src/primitives/canvas/widget_layout.zig +59 -11
- package/src/primitives/canvas/widget_layout_tests.zig +125 -4
- package/src/primitives/canvas/widget_render.zig +272 -18
- package/src/primitives/canvas/widget_render_scroll.zig +108 -27
- package/src/primitives/canvas/widget_routing.zig +59 -7
- package/src/primitives/canvas/widget_runtime.zig +23 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
- package/src/primitives/canvas/widget_semantics.zig +119 -11
- package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
- package/src/primitives/canvas/widget_tree.zig +17 -0
- package/src/primitives/canvas/widgets.zig +132 -0
- package/src/root.zig +16 -0
- package/src/runtime/api.zig +76 -6
- package/src/runtime/automation_commands.zig +20 -1
- package/src/runtime/automation_snapshot.zig +25 -1
- package/src/runtime/automation_widget_dispatch.zig +73 -8
- package/src/runtime/bridge_payload.zig +1 -0
- package/src/runtime/canvas_frame.zig +62 -7
- package/src/runtime/canvas_frame_animation_tests.zig +5 -4
- package/src/runtime/canvas_frame_helpers.zig +190 -1
- package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
- package/src/runtime/canvas_frame_patch_tests.zig +161 -10
- package/src/runtime/canvas_frame_retained_tests.zig +5 -2
- package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
- package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
- package/src/runtime/canvas_widget_context_menu.zig +269 -32
- package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
- package/src/runtime/canvas_widget_display.zig +1 -1
- package/src/runtime/canvas_widget_event_tests.zig +1823 -0
- package/src/runtime/canvas_widget_events.zig +268 -26
- package/src/runtime/canvas_widget_runtime.zig +213 -29
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
- package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
- package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
- package/src/runtime/canvas_widget_state.zig +6 -0
- package/src/runtime/canvas_widget_text_tests.zig +1 -1
- package/src/runtime/core.zig +73 -2
- package/src/runtime/effects.zig +6389 -54
- package/src/runtime/effects_channel_tests.zig +3519 -0
- package/src/runtime/effects_pty_tests.zig +1362 -0
- package/src/runtime/effects_tests.zig +14 -9
- package/src/runtime/effects_video_tests.zig +3609 -0
- package/src/runtime/flow.zig +25 -4
- package/src/runtime/gpu_surface_events.zig +475 -15
- package/src/runtime/media_surface.zig +116 -11
- package/src/runtime/media_surface_tests.zig +61 -0
- package/src/runtime/pty.zig +1252 -0
- package/src/runtime/pty_windows.zig +1780 -0
- package/src/runtime/root.zig +25 -0
- package/src/runtime/runtime_event_tests.zig +20 -1
- package/src/runtime/session_journal.zig +367 -61
- package/src/runtime/session_record.zig +16 -0
- package/src/runtime/session_replay.zig +395 -11
- package/src/runtime/session_tests.zig +114 -19
- package/src/runtime/terminal_session.zig +1569 -0
- package/src/runtime/terminal_session_tests.zig +450 -0
- package/src/runtime/terminal_vt_ghostty.zig +15 -0
- package/src/runtime/terminal_vt_stub.zig +13 -0
- package/src/runtime/tests.zig +6 -0
- package/src/runtime/ts_core_host.zig +980 -140
- package/src/runtime/ts_core_host_tests.zig +1059 -1
- package/src/runtime/ts_ui_app.zig +16 -5
- package/src/runtime/ui_app.zig +2338 -67
- package/src/runtime/ui_app_tests.zig +3171 -744
- package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
- package/src/runtime/ui_app_window_tests.zig +268 -0
- package/src/runtime/view.zig +190 -2
- package/src/runtime/view_widget_scroll.zig +218 -68
- package/src/runtime/view_widget_text.zig +11 -2
- package/src/runtime/view_widget_tree.zig +111 -3
- package/src/runtime/window_storage.zig +45 -2
- package/src/runtime/window_view_runtime.zig +34 -2
- package/src/runtime/window_views.zig +1 -0
- package/src/terminal_session_tests_root.zig +15 -0
- package/src/tooling/templates.zig +25 -7
|
@@ -130,6 +130,8 @@ enum EventKind {
|
|
|
130
130
|
kTimer = 16,
|
|
131
131
|
kAppearance = 17,
|
|
132
132
|
kAudio = 18,
|
|
133
|
+
kContextMenuAction = 19,
|
|
134
|
+
kViewFocused = 20,
|
|
133
135
|
};
|
|
134
136
|
|
|
135
137
|
constexpr uint32_t kShortcutModifierPrimary = 1u << 0;
|
|
@@ -161,6 +163,11 @@ constexpr UINT kAudioSessionMessage = WM_APP + 45;
|
|
|
161
163
|
* loop starves it far below the contract cadence, while posted messages
|
|
162
164
|
* keep their place in the queue. */
|
|
163
165
|
constexpr UINT kAudioSpectrumMessage = WM_APP + 46;
|
|
166
|
+
/* Posted by native_sdk_windows_show_context_menu (loop thread, but mid
|
|
167
|
+
* event dispatch); the window procedure presents the pending app context
|
|
168
|
+
* menu on a fresh loop turn — the same deferral the macOS host's
|
|
169
|
+
* dispatch_async performs before popUpMenuPositioningItem. */
|
|
170
|
+
constexpr UINT kShowContextMenuMessage = WM_APP + 47;
|
|
164
171
|
constexpr const char *kAssetVirtualOrigin = "https://native-sdk-app.localhost";
|
|
165
172
|
|
|
166
173
|
constexpr int kViewWebView = 0;
|
|
@@ -246,6 +253,21 @@ struct WindowsEvent {
|
|
|
246
253
|
* from -60 dBFS at 0 to full scale at 255). Zeros on every other
|
|
247
254
|
* event kind — every emit site value-initializes the struct. */
|
|
248
255
|
uint8_t audio_bands[32];
|
|
256
|
+
/* kContextMenuAction payload (the macOS host's field names):
|
|
257
|
+
* widget_id echoes the request's correlation token, menu_item_id is
|
|
258
|
+
* the selected item's id (0 = dismissed without a selection). */
|
|
259
|
+
uint64_t widget_id;
|
|
260
|
+
uint32_t menu_item_id;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/* One context-menu entry crossing the C ABI (the same shape the macOS
|
|
264
|
+
* host takes). */
|
|
265
|
+
struct WindowsContextMenuItem {
|
|
266
|
+
uint32_t item_id;
|
|
267
|
+
const char *label;
|
|
268
|
+
size_t label_len;
|
|
269
|
+
int enabled;
|
|
270
|
+
int separator;
|
|
249
271
|
};
|
|
250
272
|
|
|
251
273
|
struct WindowsOpenDialogOpts {
|
|
@@ -422,9 +444,21 @@ struct NativeView {
|
|
|
422
444
|
int gpu_nonblank = 0;
|
|
423
445
|
uint32_t gpu_sample_color = 0;
|
|
424
446
|
int gpu_pointer_down = 0;
|
|
447
|
+
/* TrackMouseEvent(TME_LEAVE) armed for the current hover session:
|
|
448
|
+
* set on the first WM_MOUSEMOVE, cleared by the WM_MOUSELEAVE it
|
|
449
|
+
* buys, re-armed by the next move. */
|
|
450
|
+
int gpu_mouse_tracking = 0;
|
|
425
451
|
double gpu_pointer_x = 0;
|
|
426
452
|
double gpu_pointer_y = 0;
|
|
427
453
|
WCHAR gpu_pending_high_surrogate = 0;
|
|
454
|
+
/* The WM_KEYDOWN just dispatched a registered shortcut, so every
|
|
455
|
+
* already-translated WM_CHAR trailing it belongs to the SAME
|
|
456
|
+
* keystroke and must not also type (AltGr raises Ctrl+Alt, so an
|
|
457
|
+
* AltGr chord that matches a ctrl+alt accelerator would otherwise
|
|
458
|
+
* both fire the accelerator and insert its composed text). Holds
|
|
459
|
+
* across the whole translated burst; the next WM_KEYDOWN or
|
|
460
|
+
* WM_KEYUP disarms it. */
|
|
461
|
+
bool gpu_shortcut_ate_char = false;
|
|
428
462
|
/* UTF-8 preedit last sent as ime_set_composition; empty = no active
|
|
429
463
|
* composition. Mirrors gpu_preedit_text in the GTK host and markedText
|
|
430
464
|
* in the AppKit host. */
|
|
@@ -555,6 +589,27 @@ struct AudioState {
|
|
|
555
589
|
std::shared_ptr<AudioDownloadCancel> download_cancel;
|
|
556
590
|
};
|
|
557
591
|
|
|
592
|
+
/* The one pending app context menu (menus are modal, so one at a time):
|
|
593
|
+
* copied out of the service call's borrowed request memory, presented on
|
|
594
|
+
* the next loop turn by the window procedure. */
|
|
595
|
+
struct PendingContextMenu {
|
|
596
|
+
bool active = false;
|
|
597
|
+
uint64_t window_id = 0;
|
|
598
|
+
std::string view_label;
|
|
599
|
+
/* Pointer location in LOGICAL points, view-local (the same space the
|
|
600
|
+
* gpu-surface input path reports in). */
|
|
601
|
+
double x = 0;
|
|
602
|
+
double y = 0;
|
|
603
|
+
uint64_t token = 0;
|
|
604
|
+
struct Item {
|
|
605
|
+
uint32_t id = 0;
|
|
606
|
+
std::string label;
|
|
607
|
+
bool enabled = true;
|
|
608
|
+
bool separator = false;
|
|
609
|
+
};
|
|
610
|
+
std::vector<Item> items;
|
|
611
|
+
};
|
|
612
|
+
|
|
558
613
|
struct Host {
|
|
559
614
|
HINSTANCE instance = GetModuleHandleW(nullptr);
|
|
560
615
|
std::string app_name;
|
|
@@ -592,6 +647,7 @@ struct Host {
|
|
|
592
647
|
bool com_initialized = false;
|
|
593
648
|
AudioState audio;
|
|
594
649
|
AudioSpectrumState spectrum;
|
|
650
|
+
PendingContextMenu context_menu;
|
|
595
651
|
std::shared_ptr<HostLifetime> lifetime = std::make_shared<HostLifetime>();
|
|
596
652
|
};
|
|
597
653
|
|
|
@@ -1159,6 +1215,18 @@ static std::string extractHtmlClipboardFragment(const std::string &payload) {
|
|
|
1159
1215
|
|
|
1160
1216
|
static UINT dpiForWindow(HWND hwnd);
|
|
1161
1217
|
|
|
1218
|
+
/* A Win32 top-level window keeps keyboard ownership while focus lives
|
|
1219
|
+
* in any of its native child views. GetFocus() returns the CHILD HWND in
|
|
1220
|
+
* that case (GPU surfaces and hosted controls alike), so direct equality
|
|
1221
|
+
* with window.hwnd falsely reports the owning window blurred exactly
|
|
1222
|
+
* while its child is receiving keyboard input. Walking to GA_ROOT makes
|
|
1223
|
+
* the window-level flag match Win32's active focus tree. */
|
|
1224
|
+
static bool windowOwnsKeyboardFocus(const Window &window) {
|
|
1225
|
+
if (!window.hwnd) return false;
|
|
1226
|
+
HWND focused = GetFocus();
|
|
1227
|
+
return focused && GetAncestor(focused, GA_ROOT) == window.hwnd;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1162
1230
|
static void emit(Host *host, const Window &window, EventKind kind) {
|
|
1163
1231
|
if (!host || !host->callback) return;
|
|
1164
1232
|
RECT rect = {};
|
|
@@ -1177,7 +1245,7 @@ static void emit(Host *host, const Window &window, EventKind kind) {
|
|
|
1177
1245
|
event.x = window.x;
|
|
1178
1246
|
event.y = window.y;
|
|
1179
1247
|
event.open = window.hwnd != nullptr;
|
|
1180
|
-
event.focused = window
|
|
1248
|
+
event.focused = windowOwnsKeyboardFocus(window);
|
|
1181
1249
|
event.hidden = window.policy_hidden ? 1 : 0;
|
|
1182
1250
|
event.label = window.label.c_str();
|
|
1183
1251
|
event.label_len = window.label.size();
|
|
@@ -1226,6 +1294,24 @@ static std::string shortcutKeyFromWParam(WPARAM wparam) {
|
|
|
1226
1294
|
case VK_RIGHT: return "arrowright";
|
|
1227
1295
|
case VK_UP: return "arrowup";
|
|
1228
1296
|
case VK_DOWN: return "arrowdown";
|
|
1297
|
+
case VK_DELETE: return "delete";
|
|
1298
|
+
case VK_HOME: return "home";
|
|
1299
|
+
case VK_END: return "end";
|
|
1300
|
+
case VK_PRIOR: return "pageup";
|
|
1301
|
+
case VK_NEXT: return "pagedown";
|
|
1302
|
+
case VK_INSERT: return "insert";
|
|
1303
|
+
case VK_F1: return "f1";
|
|
1304
|
+
case VK_F2: return "f2";
|
|
1305
|
+
case VK_F3: return "f3";
|
|
1306
|
+
case VK_F4: return "f4";
|
|
1307
|
+
case VK_F5: return "f5";
|
|
1308
|
+
case VK_F6: return "f6";
|
|
1309
|
+
case VK_F7: return "f7";
|
|
1310
|
+
case VK_F8: return "f8";
|
|
1311
|
+
case VK_F9: return "f9";
|
|
1312
|
+
case VK_F10: return "f10";
|
|
1313
|
+
case VK_F11: return "f11";
|
|
1314
|
+
case VK_F12: return "f12";
|
|
1229
1315
|
case VK_OEM_PLUS: return "=";
|
|
1230
1316
|
case VK_OEM_MINUS: return "-";
|
|
1231
1317
|
case VK_OEM_COMMA: return ",";
|
|
@@ -1300,6 +1386,18 @@ static std::string shortcutKeyLabel(const std::string &key) {
|
|
|
1300
1386
|
if (key == "arrowright") return "Right";
|
|
1301
1387
|
if (key == "arrowup") return "Up";
|
|
1302
1388
|
if (key == "arrowdown") return "Down";
|
|
1389
|
+
if (key == "delete") return "Del";
|
|
1390
|
+
if (key == "home") return "Home";
|
|
1391
|
+
if (key == "end") return "End";
|
|
1392
|
+
if (key == "pageup") return "PgUp";
|
|
1393
|
+
if (key == "pagedown") return "PgDn";
|
|
1394
|
+
if (key == "insert") return "Ins";
|
|
1395
|
+
if (key.size() >= 2 && key.size() <= 3 && key[0] == 'f' &&
|
|
1396
|
+
std::isdigit(static_cast<unsigned char>(key[1]))) {
|
|
1397
|
+
std::string label = key;
|
|
1398
|
+
label[0] = 'F';
|
|
1399
|
+
return label;
|
|
1400
|
+
}
|
|
1303
1401
|
return key;
|
|
1304
1402
|
}
|
|
1305
1403
|
|
|
@@ -1411,7 +1509,7 @@ static void showTrayMenu(Host *host, HWND hwnd) {
|
|
|
1411
1509
|
}
|
|
1412
1510
|
|
|
1413
1511
|
static bool emitShortcutForWindow(Host *host, const Window *window, WPARAM wparam) {
|
|
1414
|
-
if (!host || host->shortcuts.empty()) return false;
|
|
1512
|
+
if (!host || (host->shortcuts.empty() && host->menus.empty())) return false;
|
|
1415
1513
|
if (!window) return false;
|
|
1416
1514
|
std::string key = shortcutKeyFromWParam(wparam);
|
|
1417
1515
|
if (key.empty()) return false;
|
|
@@ -1434,6 +1532,26 @@ static bool emitShortcutForWindow(Host *host, const Window *window, WPARAM wpara
|
|
|
1434
1532
|
host->callback(host->callback_context, &event);
|
|
1435
1533
|
return true;
|
|
1436
1534
|
}
|
|
1535
|
+
/* Menu accelerators dispatch from the same keydown path: a menu
|
|
1536
|
+
* item's key+modifiers is a keyboard binding whose event is the
|
|
1537
|
+
* item's menu command, exactly as if the item were clicked. The
|
|
1538
|
+
* other platforms get this from their menu systems (AppKit key
|
|
1539
|
+
* equivalents, GTK accels); here the message loop is that system. */
|
|
1540
|
+
for (const Menu &menu : host->menus) {
|
|
1541
|
+
for (const MenuItem &item : menu.items) {
|
|
1542
|
+
if (item.separator || !item.enabled || item.key.empty()) continue;
|
|
1543
|
+
if (item.key != key) continue;
|
|
1544
|
+
if (!shortcutModifiersMatch(item.modifiers, allow_implicit_shift)) continue;
|
|
1545
|
+
if (!host->callback) return true;
|
|
1546
|
+
WindowsEvent event = {};
|
|
1547
|
+
event.kind = kMenuCommand;
|
|
1548
|
+
event.window_id = window->id;
|
|
1549
|
+
event.command_name = item.command.c_str();
|
|
1550
|
+
event.command_name_len = item.command.size();
|
|
1551
|
+
host->callback(host->callback_context, &event);
|
|
1552
|
+
return true;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1437
1555
|
}
|
|
1438
1556
|
return false;
|
|
1439
1557
|
}
|
|
@@ -1872,6 +1990,63 @@ static NativeView *gpuSurfaceViewForHwnd(Host *host, HWND hwnd) {
|
|
|
1872
1990
|
return nullptr;
|
|
1873
1991
|
}
|
|
1874
1992
|
|
|
1993
|
+
/* Present the pending app context menu — the tray menu's popup
|
|
1994
|
+
* discipline (SetForegroundWindow, TPM_RETURNCMD | TPM_NONOTIFY, the
|
|
1995
|
+
* WM_NULL post) applied to the runtime's declared items. Runs from the
|
|
1996
|
+
* kShowContextMenuMessage case in the window procedure, so it is on the
|
|
1997
|
+
* message-loop thread but on a FRESH loop turn, never nested inside the
|
|
1998
|
+
* input dispatch that requested it. TrackPopupMenu blocks in its own
|
|
1999
|
+
* modal message loop until the user picks or dismisses (the same shape
|
|
2000
|
+
* as the macOS host's popUpMenuPositioningItem nested tracking loop),
|
|
2001
|
+
* and TPM_RETURNCMD hands the selection back inline — the
|
|
2002
|
+
* kContextMenuAction event is emitted right after it returns, selection
|
|
2003
|
+
* or dismissal (menu_item_id 0) alike, exactly the payload the macOS
|
|
2004
|
+
* host emits so replay is shape-identical across platforms. */
|
|
2005
|
+
static void showAppContextMenu(Host *host, HWND hwnd) {
|
|
2006
|
+
if (!host || !host->context_menu.active) return;
|
|
2007
|
+
PendingContextMenu request = std::move(host->context_menu);
|
|
2008
|
+
host->context_menu = PendingContextMenu{};
|
|
2009
|
+
HMENU menu = CreatePopupMenu();
|
|
2010
|
+
if (!menu) return;
|
|
2011
|
+
for (const PendingContextMenu::Item &item : request.items) {
|
|
2012
|
+
if (item.separator) {
|
|
2013
|
+
AppendMenuW(menu, MF_SEPARATOR, 0, nullptr);
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
UINT flags = MF_STRING;
|
|
2017
|
+
if (!item.enabled) flags |= MF_GRAYED;
|
|
2018
|
+
std::wstring label = widen(item.label);
|
|
2019
|
+
AppendMenuW(menu, flags, item.id, label.c_str());
|
|
2020
|
+
}
|
|
2021
|
+
/* The request's point is LOGICAL view-local (the exact coordinates
|
|
2022
|
+
* the gpu-surface input path reported the click in, which divides
|
|
2023
|
+
* physical client pixels by gpuSurfaceScale on the way out): invert
|
|
2024
|
+
* that scale against the presenting view's HWND — the gpu-surface
|
|
2025
|
+
* child when the label resolves, the top-level client area otherwise
|
|
2026
|
+
* — then map to screen for TrackPopupMenu. */
|
|
2027
|
+
HWND target = hwnd;
|
|
2028
|
+
if (!request.view_label.empty()) {
|
|
2029
|
+
auto view = host->native_views.find(nativeViewKey(request.window_id, request.view_label));
|
|
2030
|
+
if (view != host->native_views.end() && view->second.hwnd) target = view->second.hwnd;
|
|
2031
|
+
}
|
|
2032
|
+
const double scale = gpuSurfaceScale(target);
|
|
2033
|
+
POINT point = { (LONG)lround(request.x * scale), (LONG)lround(request.y * scale) };
|
|
2034
|
+
ClientToScreen(target, &point);
|
|
2035
|
+
SetForegroundWindow(hwnd);
|
|
2036
|
+
UINT command_id = TrackPopupMenu(menu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_RIGHTBUTTON, point.x, point.y, 0, hwnd, nullptr);
|
|
2037
|
+
DestroyMenu(menu);
|
|
2038
|
+
WindowsEvent event = {};
|
|
2039
|
+
event.kind = kContextMenuAction;
|
|
2040
|
+
event.window_id = request.window_id;
|
|
2041
|
+
event.view_label = request.view_label.c_str();
|
|
2042
|
+
event.view_label_len = request.view_label.size();
|
|
2043
|
+
event.timestamp_ns = gpuTimestampNs();
|
|
2044
|
+
event.widget_id = request.token;
|
|
2045
|
+
event.menu_item_id = command_id;
|
|
2046
|
+
if (host->callback) host->callback(host->callback_context, &event);
|
|
2047
|
+
PostMessageW(hwnd, WM_NULL, 0, 0);
|
|
2048
|
+
}
|
|
2049
|
+
|
|
1875
2050
|
/* ------------------------------------------------------------------------
|
|
1876
2051
|
* Hidden-titlebar window chrome (the Win32 custom-frame pattern).
|
|
1877
2052
|
*
|
|
@@ -2539,6 +2714,13 @@ static std::string gpuSurfaceKeyName(WPARAM wparam) {
|
|
|
2539
2714
|
}
|
|
2540
2715
|
|
|
2541
2716
|
static void gpuSurfaceCharInput(Host *host, NativeView &view, WPARAM wparam) {
|
|
2717
|
+
/* A keystroke a registered shortcut consumed never ALSO types: the
|
|
2718
|
+
* message loop translated its WM_CHAR(s) before the accelerator
|
|
2719
|
+
* could refuse them. The latch holds for the WHOLE translated burst
|
|
2720
|
+
* — one keystroke can post several UTF-16 units (ligature layouts,
|
|
2721
|
+
* surrogate pairs) — and is bounded by the message sequence, not a
|
|
2722
|
+
* count: the next WM_KEYDOWN or WM_KEYUP disarms it. */
|
|
2723
|
+
if (view.gpu_shortcut_ate_char) return;
|
|
2542
2724
|
const WCHAR unit = (WCHAR)wparam;
|
|
2543
2725
|
std::wstring wide;
|
|
2544
2726
|
if (unit >= 0xD800 && unit <= 0xDBFF) {
|
|
@@ -2556,8 +2738,15 @@ static void gpuSurfaceCharInput(Host *host, NativeView &view, WPARAM wparam) {
|
|
|
2556
2738
|
wide.push_back(unit);
|
|
2557
2739
|
}
|
|
2558
2740
|
/* Control/alt chords produce control characters or menu accelerators,
|
|
2559
|
-
* not text; mirror the GTK path, which skips text for modified keys.
|
|
2560
|
-
|
|
2741
|
+
* not text; mirror the GTK path, which skips text for modified keys.
|
|
2742
|
+
* EXCEPT AltGr: Windows raises Ctrl+Alt together for it, and an
|
|
2743
|
+
* AltGr-composed printable (AltGr+Q -> "@" on German layouts) IS
|
|
2744
|
+
* committed text — the one chord whose WM_CHAR must flow, or those
|
|
2745
|
+
* layouts lose the character entirely (an AltGr chord a shortcut
|
|
2746
|
+
* consumed was already discarded above). Win alone still gates. */
|
|
2747
|
+
const bool altgr = keyDown(VK_CONTROL) && keyDown(VK_MENU);
|
|
2748
|
+
if (!altgr && (keyDown(VK_CONTROL) || keyDown(VK_MENU))) return;
|
|
2749
|
+
if (keyDown(VK_LWIN) || keyDown(VK_RWIN)) return;
|
|
2561
2750
|
const std::string text = narrow(wide);
|
|
2562
2751
|
if (text.empty()) return;
|
|
2563
2752
|
emitGpuSurfaceInput(host, view, kGpuInputTextInput, view.gpu_pointer_x, view.gpu_pointer_y, 0, 0, 0, "", text.c_str(), gpuModifierFlags());
|
|
@@ -2667,6 +2856,18 @@ static LRESULT CALLBACK gpuSurfaceProc(HWND hwnd, UINT message, WPARAM wparam, L
|
|
|
2667
2856
|
return 0;
|
|
2668
2857
|
}
|
|
2669
2858
|
case WM_MOUSEMOVE: {
|
|
2859
|
+
/* Win32 only reports the pointer LEAVING the client area on
|
|
2860
|
+
* request: arm TME_LEAVE once per hover session so the
|
|
2861
|
+
* WM_MOUSELEAVE below can retire hover state (washes, hover
|
|
2862
|
+
* Msgs, tooltip intent) the way the AppKit host's
|
|
2863
|
+
* mouseExited does. */
|
|
2864
|
+
if (!view->gpu_mouse_tracking) {
|
|
2865
|
+
TRACKMOUSEEVENT track = {};
|
|
2866
|
+
track.cbSize = sizeof(track);
|
|
2867
|
+
track.dwFlags = TME_LEAVE;
|
|
2868
|
+
track.hwndTrack = hwnd;
|
|
2869
|
+
if (TrackMouseEvent(&track)) view->gpu_mouse_tracking = 1;
|
|
2870
|
+
}
|
|
2670
2871
|
const double x = (double)(short)LOWORD(lparam) / scale;
|
|
2671
2872
|
const double y = (double)(short)HIWORD(lparam) / scale;
|
|
2672
2873
|
view->gpu_pointer_x = x;
|
|
@@ -2675,6 +2876,46 @@ static LRESULT CALLBACK gpuSurfaceProc(HWND hwnd, UINT message, WPARAM wparam, L
|
|
|
2675
2876
|
emitGpuSurfaceInput(host, *view, kind, x, y, 0, 0, 0, "", "", gpuModifierFlags());
|
|
2676
2877
|
return 0;
|
|
2677
2878
|
}
|
|
2879
|
+
case WM_MOUSELEAVE: {
|
|
2880
|
+
view->gpu_mouse_tracking = 0;
|
|
2881
|
+
/* The pointer left the client area without a press in
|
|
2882
|
+
* flight: the window-leave edge, reported as the same
|
|
2883
|
+
* pointer cancel a capture loss emits. A captured drag
|
|
2884
|
+
* keeps receiving moves outside the window and settles
|
|
2885
|
+
* through its own up/capture-change instead. One
|
|
2886
|
+
* exception: in-canvas window-drag regions answer
|
|
2887
|
+
* WM_NCHITTEST with HTTRANSPARENT (the parent drags), so
|
|
2888
|
+
* the OS reports a "leave" the moment the cursor enters
|
|
2889
|
+
* one while it still sits over this canvas. That hand-off
|
|
2890
|
+
* is recognized by BOTH tests below - the cursor is still
|
|
2891
|
+
* geometrically inside our rectangle AND the window now
|
|
2892
|
+
* owning the point is one of our own ancestors (hit-test
|
|
2893
|
+
* transparency forwards to the parent chain). A cursor
|
|
2894
|
+
* inside our rectangle but owned by a SIBLING child (an
|
|
2895
|
+
* overlapping WebView pane) is a genuine departure and
|
|
2896
|
+
* must cancel, or hover strands until a later move. */
|
|
2897
|
+
if (!view->gpu_pointer_down) {
|
|
2898
|
+
POINT screen = {};
|
|
2899
|
+
bool suppressed = false;
|
|
2900
|
+
if (GetCursorPos(&screen)) {
|
|
2901
|
+
POINT client = screen;
|
|
2902
|
+
RECT rect = {};
|
|
2903
|
+
if (ScreenToClient(hwnd, &client) && GetClientRect(hwnd, &rect) && PtInRect(&rect, client)) {
|
|
2904
|
+
const HWND owner = WindowFromPoint(screen);
|
|
2905
|
+
for (HWND walk = GetParent(hwnd); walk; walk = GetParent(walk)) {
|
|
2906
|
+
if (walk == owner) {
|
|
2907
|
+
suppressed = true;
|
|
2908
|
+
break;
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
if (!suppressed) {
|
|
2914
|
+
emitGpuSurfaceInput(host, *view, kGpuInputPointerCancel, view->gpu_pointer_x, view->gpu_pointer_y, 0, 0, 0, "", "", gpuModifierFlags());
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
return 0;
|
|
2918
|
+
}
|
|
2678
2919
|
case WM_CAPTURECHANGED:
|
|
2679
2920
|
if (view->gpu_pointer_down) {
|
|
2680
2921
|
view->gpu_pointer_down = 0;
|
|
@@ -2701,7 +2942,18 @@ static LRESULT CALLBACK gpuSurfaceProc(HWND hwnd, UINT message, WPARAM wparam, L
|
|
|
2701
2942
|
}
|
|
2702
2943
|
case WM_KEYDOWN:
|
|
2703
2944
|
case WM_SYSKEYDOWN: {
|
|
2704
|
-
|
|
2945
|
+
/* A fresh keystroke re-disarms the one-shot: a shortcut that
|
|
2946
|
+
* translated to no WM_CHAR (F-keys) must not leave it armed
|
|
2947
|
+
* to eat a later ordinary character. */
|
|
2948
|
+
view->gpu_shortcut_ate_char = false;
|
|
2949
|
+
if (emitShortcutForHwnd(host, GetAncestor(hwnd, GA_ROOT), wparam)) {
|
|
2950
|
+
/* The keystroke was consumed as a shortcut; its
|
|
2951
|
+
* already-translated WM_CHAR (posted by the message
|
|
2952
|
+
* loop's TranslateMessage before this dispatch) must
|
|
2953
|
+
* not ALSO type — one keystroke, one action. */
|
|
2954
|
+
view->gpu_shortcut_ate_char = true;
|
|
2955
|
+
return 0;
|
|
2956
|
+
}
|
|
2705
2957
|
const std::string key = gpuSurfaceKeyName(wparam);
|
|
2706
2958
|
if (!key.empty()) {
|
|
2707
2959
|
emitGpuSurfaceInput(host, *view, kGpuInputKeyDown, view->gpu_pointer_x, view->gpu_pointer_y, 0, 0, 0, key.c_str(), "", gpuModifierFlags());
|
|
@@ -2710,6 +2962,9 @@ static LRESULT CALLBACK gpuSurfaceProc(HWND hwnd, UINT message, WPARAM wparam, L
|
|
|
2710
2962
|
}
|
|
2711
2963
|
case WM_KEYUP:
|
|
2712
2964
|
case WM_SYSKEYUP: {
|
|
2965
|
+
/* The shortcut keystroke's translated burst ended with its
|
|
2966
|
+
* release: disarm the char latch (see gpuSurfaceCharInput). */
|
|
2967
|
+
view->gpu_shortcut_ate_char = false;
|
|
2713
2968
|
const std::string key = gpuSurfaceKeyName(wparam);
|
|
2714
2969
|
if (!key.empty()) {
|
|
2715
2970
|
emitGpuSurfaceInput(host, *view, kGpuInputKeyUp, view->gpu_pointer_x, view->gpu_pointer_y, 0, 0, 0, key.c_str(), "", gpuModifierFlags());
|
|
@@ -4014,6 +4269,7 @@ static const GUID kNativeSdkIID_EnvironmentCompletedHandler = {0x4e8a3389, 0xc9d
|
|
|
4014
4269
|
static const GUID kNativeSdkIID_ControllerCompletedHandler = {0x6c4819f3, 0xc9b7, 0x4260, {0x81, 0x27, 0xc9, 0xf5, 0xbd, 0xe7, 0xf6, 0x8c}};
|
|
4015
4270
|
static const GUID kNativeSdkIID_WebMessageReceivedHandler = {0x57213f19, 0x00e6, 0x49fa, {0x8e, 0x07, 0x89, 0x8e, 0xa0, 0x1e, 0xcb, 0xd2}};
|
|
4016
4271
|
static const GUID kNativeSdkIID_AcceleratorKeyPressedHandler = {0xb29c7e28, 0xfa79, 0x41a8, {0x8e, 0x44, 0x65, 0x81, 0x1c, 0x76, 0xdc, 0xb2}};
|
|
4272
|
+
static const GUID kNativeSdkIID_FocusChangedHandler = {0x05ea24bd, 0x6452, 0x4926, {0x90, 0x14, 0x4b, 0x82, 0xb4, 0x98, 0x13, 0x5d}};
|
|
4017
4273
|
static const GUID kNativeSdkIID_WebResourceRequestedHandler = {0xab00b74c, 0x15f1, 0x4646, {0x80, 0xe8, 0xe7, 0x63, 0x41, 0xd2, 0x5d, 0x71}};
|
|
4018
4274
|
static const GUID kNativeSdkIID_NavigationStartingHandler = {0x9adbe429, 0xf36d, 0x432b, {0x9d, 0xdc, 0xf8, 0x88, 0x1f, 0xbd, 0x76, 0xe3}};
|
|
4019
4275
|
|
|
@@ -4030,6 +4286,9 @@ template <> struct WebView2HandlerIid<ICoreWebView2WebMessageReceivedEventHandle
|
|
|
4030
4286
|
template <> struct WebView2HandlerIid<ICoreWebView2AcceleratorKeyPressedEventHandler> {
|
|
4031
4287
|
static const GUID &value() { return kNativeSdkIID_AcceleratorKeyPressedHandler; }
|
|
4032
4288
|
};
|
|
4289
|
+
template <> struct WebView2HandlerIid<ICoreWebView2FocusChangedEventHandler> {
|
|
4290
|
+
static const GUID &value() { return kNativeSdkIID_FocusChangedHandler; }
|
|
4291
|
+
};
|
|
4033
4292
|
template <> struct WebView2HandlerIid<ICoreWebView2WebResourceRequestedEventHandler> {
|
|
4034
4293
|
static const GUID &value() { return kNativeSdkIID_WebResourceRequestedHandler; }
|
|
4035
4294
|
};
|
|
@@ -4368,6 +4627,23 @@ static bool createChildWebView(Host *host, const std::string &key) {
|
|
|
4368
4627
|
controller->put_Bounds(bounds);
|
|
4369
4628
|
controller->put_ZoomFactor(found->second.zoom);
|
|
4370
4629
|
controller->put_IsVisible(TRUE);
|
|
4630
|
+
EventRegistrationToken focus_token = {};
|
|
4631
|
+
controller->add_GotFocus(Callback<ICoreWebView2FocusChangedEventHandler>(
|
|
4632
|
+
[host, key, lifetime](ICoreWebView2Controller *, IUnknown *) -> HRESULT {
|
|
4633
|
+
auto token = lifetime.lock();
|
|
4634
|
+
if (!token) return S_OK;
|
|
4635
|
+
std::lock_guard<std::recursive_mutex> guard(token->mutex);
|
|
4636
|
+
if (!token->alive || !host->callback) return S_OK;
|
|
4637
|
+
auto focused = host->webviews.find(key);
|
|
4638
|
+
if (focused == host->webviews.end()) return S_OK;
|
|
4639
|
+
WindowsEvent event = {};
|
|
4640
|
+
event.kind = kViewFocused;
|
|
4641
|
+
event.window_id = focused->second.window_id;
|
|
4642
|
+
event.view_label = focused->second.label.c_str();
|
|
4643
|
+
event.view_label_len = focused->second.label.size();
|
|
4644
|
+
host->callback(host->callback_context, &event);
|
|
4645
|
+
return S_OK;
|
|
4646
|
+
}).Get(), &focus_token);
|
|
4371
4647
|
if (found->second.webview) {
|
|
4372
4648
|
if (found->second.bridge_enabled) {
|
|
4373
4649
|
found->second.webview->AddScriptToExecuteOnDocumentCreated(nativeSdkBridgeScript(), nullptr);
|
|
@@ -4734,6 +5010,9 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
|
|
|
4734
5010
|
case kAudioSpectrumMessage:
|
|
4735
5011
|
if (host) audioHandleSpectrumMessage(host, wparam);
|
|
4736
5012
|
return 0;
|
|
5013
|
+
case kShowContextMenuMessage:
|
|
5014
|
+
if (host) showAppContextMenu(host, hwnd);
|
|
5015
|
+
return 0;
|
|
4737
5016
|
case kNotificationCallbackMessage:
|
|
4738
5017
|
if (host && host->tray_active) {
|
|
4739
5018
|
UINT tray_event = LOWORD(lparam);
|
|
@@ -4827,6 +5106,18 @@ static LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wparam, LPARA
|
|
|
4827
5106
|
return 0;
|
|
4828
5107
|
case WM_SETFOCUS:
|
|
4829
5108
|
case WM_KILLFOCUS:
|
|
5109
|
+
if (host) {
|
|
5110
|
+
/* Native child views own Win32 focus directly. Project
|
|
5111
|
+
* their focus edges onto the owning top-level window so
|
|
5112
|
+
* runtime key-window state follows child-to-child and
|
|
5113
|
+
* cross-window focus moves, not only the rare edges
|
|
5114
|
+
* delivered to the top-level HWND itself. */
|
|
5115
|
+
HWND root = GetAncestor(hwnd, GA_ROOT);
|
|
5116
|
+
for (auto &entry : host->windows) {
|
|
5117
|
+
if (entry.second.hwnd == root) emit(host, entry.second, kWindowFrame);
|
|
5118
|
+
}
|
|
5119
|
+
}
|
|
5120
|
+
return 0;
|
|
4830
5121
|
case WM_MOVE:
|
|
4831
5122
|
if (host) {
|
|
4832
5123
|
for (auto &entry : host->windows) {
|
|
@@ -5875,6 +6166,40 @@ int native_sdk_windows_note_gpu_surface_input(Host *host, uint64_t window_id, co
|
|
|
5875
6166
|
return 1;
|
|
5876
6167
|
}
|
|
5877
6168
|
|
|
6169
|
+
/* Queue the app context menu for presentation. Called on the loop
|
|
6170
|
+
* thread mid event dispatch (the runtime asks from inside its input
|
|
6171
|
+
* handling), so the request is copied out of the caller's borrowed
|
|
6172
|
+
* memory and presentation defers to a fresh loop turn via PostMessageW —
|
|
6173
|
+
* the same two-step the macOS host performs (its dispatch_async before
|
|
6174
|
+
* popUpMenuPositioningItem). The window procedure's
|
|
6175
|
+
* kShowContextMenuMessage case runs showAppContextMenu, whose
|
|
6176
|
+
* TrackPopupMenu blocks in its own modal loop and whose selection (or
|
|
6177
|
+
* dismissal) emits the kContextMenuAction event carrying `token`. */
|
|
6178
|
+
int native_sdk_windows_show_context_menu(Host *host, uint64_t window_id, const char *label, size_t label_len, double x, double y, uint64_t token, const WindowsContextMenuItem *items, size_t count) {
|
|
6179
|
+
if (!host || !items || count == 0) return 0;
|
|
6180
|
+
auto found = host->windows.find(window_id);
|
|
6181
|
+
if (found == host->windows.end() || !found->second.hwnd) return 0;
|
|
6182
|
+
PendingContextMenu pending;
|
|
6183
|
+
pending.active = true;
|
|
6184
|
+
pending.window_id = window_id;
|
|
6185
|
+
pending.view_label = slice(label, label_len);
|
|
6186
|
+
pending.x = x;
|
|
6187
|
+
pending.y = y;
|
|
6188
|
+
pending.token = token;
|
|
6189
|
+
pending.items.reserve(count);
|
|
6190
|
+
for (size_t index = 0; index < count; index++) {
|
|
6191
|
+
PendingContextMenu::Item item;
|
|
6192
|
+
item.id = items[index].item_id;
|
|
6193
|
+
item.label = slice(items[index].label, items[index].label_len);
|
|
6194
|
+
item.enabled = items[index].enabled != 0;
|
|
6195
|
+
item.separator = items[index].separator != 0;
|
|
6196
|
+
pending.items.push_back(std::move(item));
|
|
6197
|
+
}
|
|
6198
|
+
host->context_menu = std::move(pending);
|
|
6199
|
+
PostMessageW(found->second.hwnd, kShowContextMenuMessage, 0, 0);
|
|
6200
|
+
return 1;
|
|
6201
|
+
}
|
|
6202
|
+
|
|
5878
6203
|
int native_sdk_windows_present_gpu_surface_pixels(Host *host, uint64_t window_id, const char *label, size_t label_len, size_t width, size_t height, double scale, int has_dirty_rect, double dirty_x, double dirty_y, double dirty_width, double dirty_height, const uint8_t *rgba8, size_t rgba8_len) {
|
|
5879
6204
|
(void)scale;
|
|
5880
6205
|
(void)has_dirty_rect;
|
|
@@ -690,6 +690,24 @@ fn validateShortcutKey(key: []const u8) ValidationError!void {
|
|
|
690
690
|
"arrowright",
|
|
691
691
|
"arrowup",
|
|
692
692
|
"arrowdown",
|
|
693
|
+
"delete",
|
|
694
|
+
"home",
|
|
695
|
+
"end",
|
|
696
|
+
"pageup",
|
|
697
|
+
"pagedown",
|
|
698
|
+
"insert",
|
|
699
|
+
"f1",
|
|
700
|
+
"f2",
|
|
701
|
+
"f3",
|
|
702
|
+
"f4",
|
|
703
|
+
"f5",
|
|
704
|
+
"f6",
|
|
705
|
+
"f7",
|
|
706
|
+
"f8",
|
|
707
|
+
"f9",
|
|
708
|
+
"f10",
|
|
709
|
+
"f11",
|
|
710
|
+
"f12",
|
|
693
711
|
};
|
|
694
712
|
for (&specials) |special| {
|
|
695
713
|
if (std.ascii.eqlIgnoreCase(key, special)) return;
|
|
@@ -207,10 +207,17 @@ fn widgetClipsForAudit(widget: Widget) bool {
|
|
|
207
207
|
return widget_tree.widgetClipsContent(widget) or widget.layout.virtualized;
|
|
208
208
|
}
|
|
209
209
|
|
|
210
|
-
///
|
|
211
|
-
/// reachable after a scroll, so
|
|
210
|
+
/// Whether a scroll scope carries content into view along each axis:
|
|
211
|
+
/// content past a granted axis's fold is reachable after a scroll, so a
|
|
212
|
+
/// full-clip on that axis never counts. A horizontal-only shelf grants
|
|
213
|
+
/// x and NOT y — an offscreen-right tile is reachable, a below-viewport
|
|
214
|
+
/// one is genuinely stranded.
|
|
212
215
|
fn scopeScrollsVertically(widget: Widget) bool {
|
|
213
|
-
return widget.kind == .scroll_view or widget.layout.virtualized;
|
|
216
|
+
return (widget.kind == .scroll_view and widget.scroll_axes.scrollsVertically()) or widget.layout.virtualized;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
fn scopeScrollsHorizontally(widget: Widget) bool {
|
|
220
|
+
return widget.kind == .scroll_view and widget.scroll_axes.scrollsHorizontally() and !widget.layout.virtualized;
|
|
214
221
|
}
|
|
215
222
|
|
|
216
223
|
fn auditFocusReachable(layout: WidgetLayoutTree, node_index: usize, sink: *FindingSink) void {
|
|
@@ -221,14 +228,17 @@ fn auditFocusReachable(layout: WidgetLayoutTree, node_index: usize, sink: *Findi
|
|
|
221
228
|
|
|
222
229
|
const frame = node.frame.normalized();
|
|
223
230
|
var current = node_index;
|
|
224
|
-
// Once the walk crosses a
|
|
225
|
-
//
|
|
226
|
-
// carries it into every OUTER scope's band, so
|
|
227
|
-
//
|
|
228
|
-
// scroll region — windowed virtual lists included —
|
|
229
|
-
//
|
|
230
|
-
// re-flag
|
|
231
|
+
// Once the walk crosses a scrolling scope, the widget's layout-space
|
|
232
|
+
// position ALONG THAT AXIS is scroll content, not screen geometry:
|
|
233
|
+
// scrolling carries it into every OUTER scope's band, so full-clips
|
|
234
|
+
// on that axis stop counting from there up (below-the-fold rows in
|
|
235
|
+
// a long scroll region — windowed virtual lists included — and
|
|
236
|
+
// offscreen-right tiles on a horizontal shelf are reachable by
|
|
237
|
+
// design; a pane clipping the scroll's frame must not re-flag
|
|
238
|
+
// them). Each axis tracks independently: a horizontal shelf forgives
|
|
239
|
+
// x overhang while a below-viewport button inside it stays flagged.
|
|
231
240
|
var scrolls_vertically = false;
|
|
241
|
+
var scrolls_horizontally = false;
|
|
232
242
|
while (true) {
|
|
233
243
|
// Anchored floating widgets escape every ancestor clip (the
|
|
234
244
|
// routing layer keeps focus targets inside open overlays live).
|
|
@@ -239,14 +249,26 @@ fn auditFocusReachable(layout: WidgetLayoutTree, node_index: usize, sink: *Findi
|
|
|
239
249
|
const scope = parent.frame.normalized();
|
|
240
250
|
const outside_x = frame.maxX() <= scope.x or frame.x >= scope.maxX();
|
|
241
251
|
const outside_y = frame.maxY() <= scope.y or frame.y >= scope.maxY();
|
|
252
|
+
const parent_scrolls_horizontally = scopeScrollsHorizontally(parent.widget);
|
|
242
253
|
const vertical_scroll_scope = scrolls_vertically or scopeScrollsVertically(parent.widget);
|
|
243
|
-
const
|
|
254
|
+
const horizontal_scroll_scope = scrolls_horizontally or parent_scrolls_horizontally;
|
|
255
|
+
// A horizontal scroll forgives only what scrolling can
|
|
256
|
+
// REVEAL. Offsets clamp at zero, so content wholly BEFORE
|
|
257
|
+
// the origin in content space (layout x plus the region's
|
|
258
|
+
// own offset, checkable exactly at the immediate scope) is
|
|
259
|
+
// stranded on the leading side forever.
|
|
260
|
+
const stranded_leading_x = parent_scrolls_horizontally and !scrolls_horizontally and
|
|
261
|
+
frame.maxX() + parent.widget.value_x <= scope.x;
|
|
262
|
+
const unreachable_here = (outside_x and !horizontal_scroll_scope) or
|
|
263
|
+
(outside_y and !vertical_scroll_scope) or
|
|
264
|
+
stranded_leading_x;
|
|
244
265
|
if (unreachable_here) {
|
|
245
266
|
sink.append(.{ .rule = .focus_unreachable, .node_index = node_index, .other_index = parent_index });
|
|
246
267
|
return;
|
|
247
268
|
}
|
|
248
269
|
}
|
|
249
270
|
if (scopeScrollsVertically(parent.widget)) scrolls_vertically = true;
|
|
271
|
+
if (scopeScrollsHorizontally(parent.widget)) scrolls_horizontally = true;
|
|
250
272
|
current = parent_index;
|
|
251
273
|
}
|
|
252
274
|
}
|
|
@@ -190,6 +190,26 @@ test "below-the-fold scroll content stays reachable through OUTER clip scopes" {
|
|
|
190
190
|
try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.focus_unreachable, issues.findings[0].rule);
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
test "a horizontal shelf forgives offscreen-right tiles and still flags below-viewport content" {
|
|
194
|
+
var nodes: [32]canvas.WidgetLayoutNode = undefined;
|
|
195
|
+
var storage: [8]a11y_audit.A11yAuditFinding = undefined;
|
|
196
|
+
|
|
197
|
+
// A horizontal-only scroll region: a tile past its RIGHT edge is
|
|
198
|
+
// scroll content (reachable by design), while a button fully below
|
|
199
|
+
// the viewport is genuinely stranded — nothing scrolls vertically
|
|
200
|
+
// to reveal it.
|
|
201
|
+
const root = Widget{ .kind = .column, .children = &.{
|
|
202
|
+
.{ .kind = .scroll_view, .id = 2, .scroll_axes = .horizontal, .frame = geometry.RectF.init(0, 0, 400, 80), .children = &.{
|
|
203
|
+
.{ .kind = .button, .id = 3, .text = "Visible", .frame = geometry.RectF.init(0, 0, 140, 60) },
|
|
204
|
+
.{ .kind = .button, .id = 4, .text = "Offscreen right", .frame = geometry.RectF.init(500, 0, 140, 60) },
|
|
205
|
+
.{ .kind = .button, .id = 5, .text = "Below the shelf", .frame = geometry.RectF.init(0, 120, 140, 30) },
|
|
206
|
+
} },
|
|
207
|
+
} };
|
|
208
|
+
const issues = try auditTree(root, window, &nodes, &storage);
|
|
209
|
+
try std.testing.expectEqual(@as(usize, 1), issues.total);
|
|
210
|
+
try std.testing.expectEqual(a11y_audit.A11yAuditRuleKind.focus_unreachable, issues.findings[0].rule);
|
|
211
|
+
}
|
|
212
|
+
|
|
193
213
|
test "the formatter names the path, the role, and the fix" {
|
|
194
214
|
var nodes: [16]canvas.WidgetLayoutNode = undefined;
|
|
195
215
|
var storage: [8]a11y_audit.A11yAuditFinding = undefined;
|
|
@@ -207,6 +207,31 @@ pub const ImageFit = enum {
|
|
|
207
207
|
cover,
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
+
/// The `contain` destination rect: the largest `source_width` x
|
|
211
|
+
/// `source_height`-proportioned rect that fits inside `dst`, centered —
|
|
212
|
+
/// the remainder is the caller's letterbox/pillarbox. Non-positive
|
|
213
|
+
/// source dimensions (an unloaded stream) answer the whole `dst`
|
|
214
|
+
/// unchanged, so callers never divide by zero on unknown geometry.
|
|
215
|
+
pub fn containDestinationRect(dst: geometry.RectF, source_width: f32, source_height: f32) geometry.RectF {
|
|
216
|
+
const normalized = dst.normalized();
|
|
217
|
+
if (normalized.isEmpty() or source_width <= 0 or source_height <= 0) return normalized;
|
|
218
|
+
const source_aspect = source_width / source_height;
|
|
219
|
+
const dst_aspect = normalized.width / normalized.height;
|
|
220
|
+
var width = normalized.width;
|
|
221
|
+
var height = normalized.height;
|
|
222
|
+
if (dst_aspect > source_aspect) {
|
|
223
|
+
width = height * source_aspect;
|
|
224
|
+
} else {
|
|
225
|
+
height = width / source_aspect;
|
|
226
|
+
}
|
|
227
|
+
return geometry.RectF.init(
|
|
228
|
+
normalized.x + (normalized.width - width) * 0.5,
|
|
229
|
+
normalized.y + (normalized.height - height) * 0.5,
|
|
230
|
+
width,
|
|
231
|
+
height,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
210
235
|
pub const ImageSampling = enum {
|
|
211
236
|
nearest,
|
|
212
237
|
linear,
|