@native-sdk/cli 0.0.0 → 0.4.0
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/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/bin/native.js +156 -0
- package/build/app.zig +716 -0
- package/build.zig +2593 -0
- package/build.zig.zon +24 -0
- package/native-sdk.d.ts +615 -0
- package/package.json +44 -8
- package/skill-data/automation/SKILL.md +248 -0
- package/skill-data/core/SKILL.md +249 -0
- package/skill-data/core/references/app-model-runtime.md +141 -0
- package/skill-data/core/references/bridge-security-native-capabilities.md +230 -0
- package/skill-data/core/references/frontend-assets.md +124 -0
- package/skill-data/core/references/project-anatomy.md +108 -0
- package/skill-data/core/references/web-engines-packaging-debugging.md +199 -0
- package/skill-data/native-ui/SKILL.md +1080 -0
- package/skills/native-sdk/SKILL.md +33 -0
- package/src/app_runner/root.zig +740 -0
- package/src/assets/root.zig +20 -0
- package/src/automation/protocol.zig +285 -0
- package/src/automation/root.zig +13 -0
- package/src/automation/server.zig +506 -0
- package/src/automation/snapshot.zig +1202 -0
- package/src/automation/watcher.zig +165 -0
- package/src/bridge/root.zig +507 -0
- package/src/debug/root.zig +246 -0
- package/src/embed/app_exports.zig +11 -0
- package/src/embed/c_api.zig +793 -0
- package/src/embed/c_exports.zig +10 -0
- package/src/embed/chrome.zig +168 -0
- package/src/embed/conversions.zig +359 -0
- package/src/embed/host.zig +960 -0
- package/src/embed/root.zig +81 -0
- package/src/embed/tests.zig +2552 -0
- package/src/embed/types.zig +382 -0
- package/src/embed/ui_host.zig +289 -0
- package/src/extensions/root.zig +197 -0
- package/src/frontend/root.zig +48 -0
- package/src/js/root.zig +65 -0
- package/src/platform/android/NativeSdkActivity.java +1370 -0
- package/src/platform/android/android_host.c +696 -0
- package/src/platform/android/files.zig +9 -0
- package/src/platform/android/native_sdk_app.h +237 -0
- package/src/platform/ios/files.zig +8 -0
- package/src/platform/ios/native_sdk_app.h +289 -0
- package/src/platform/ios/uikit_host.m +2739 -0
- package/src/platform/linux/cef_host.cpp +599 -0
- package/src/platform/linux/gtk_host.c +5362 -0
- package/src/platform/linux/gtk_host.h +265 -0
- package/src/platform/linux/root.zig +1519 -0
- package/src/platform/macos/appkit_host.h +604 -0
- package/src/platform/macos/appkit_host.m +10392 -0
- package/src/platform/macos/automation_host.h +14 -0
- package/src/platform/macos/automation_host.m +12 -0
- package/src/platform/macos/cef_host.mm +3028 -0
- package/src/platform/macos/root.zig +2260 -0
- package/src/platform/null_platform.zig +2232 -0
- package/src/platform/null_platform_tests.zig +670 -0
- package/src/platform/policy_values.zig +14 -0
- package/src/platform/root.zig +181 -0
- package/src/platform/types.zig +2681 -0
- package/src/platform/windows/cef_host.cpp +3 -0
- package/src/platform/windows/root.zig +1521 -0
- package/src/platform/windows/webview2_host.cpp +6230 -0
- package/src/primitives/app_dirs/root.zig +440 -0
- package/src/primitives/app_manifest/root.zig +109 -0
- package/src/primitives/app_manifest/tests.zig +758 -0
- package/src/primitives/app_manifest/types.zig +587 -0
- package/src/primitives/app_manifest/validation.zig +828 -0
- package/src/primitives/assets/root.zig +520 -0
- package/src/primitives/canvas/a11y_audit.zig +390 -0
- package/src/primitives/canvas/a11y_audit_tests.zig +225 -0
- package/src/primitives/canvas/app_icon.zig +1590 -0
- package/src/primitives/canvas/chart.zig +392 -0
- package/src/primitives/canvas/chart_tests.zig +751 -0
- package/src/primitives/canvas/commands.zig +446 -0
- package/src/primitives/canvas/drawing.zig +309 -0
- package/src/primitives/canvas/equality.zig +316 -0
- package/src/primitives/canvas/events.zig +696 -0
- package/src/primitives/canvas/font_coverage.zig +118 -0
- package/src/primitives/canvas/font_ttf.zig +510 -0
- package/src/primitives/canvas/font_ttf_tests.zig +280 -0
- package/src/primitives/canvas/fonts/Geist-Regular.ttf +0 -0
- package/src/primitives/canvas/fonts/GeistMono-Regular.ttf +0 -0
- package/src/primitives/canvas/frame.zig +679 -0
- package/src/primitives/canvas/frame_metrics.zig +462 -0
- package/src/primitives/canvas/gpu.zig +639 -0
- package/src/primitives/canvas/hash.zig +112 -0
- package/src/primitives/canvas/icons/alert.svg +1 -0
- package/src/primitives/canvas/icons/archive.svg +1 -0
- package/src/primitives/canvas/icons/arrow-down.svg +1 -0
- package/src/primitives/canvas/icons/arrow-right.svg +1 -0
- package/src/primitives/canvas/icons/arrow-up.svg +1 -0
- package/src/primitives/canvas/icons/check-circle.svg +1 -0
- package/src/primitives/canvas/icons/check.svg +1 -0
- package/src/primitives/canvas/icons/chevron-down.svg +1 -0
- package/src/primitives/canvas/icons/chevron-left.svg +1 -0
- package/src/primitives/canvas/icons/chevron-right.svg +1 -0
- package/src/primitives/canvas/icons/chevron-up.svg +1 -0
- package/src/primitives/canvas/icons/circle-dot.svg +1 -0
- package/src/primitives/canvas/icons/clock.svg +1 -0
- package/src/primitives/canvas/icons/copy.svg +1 -0
- package/src/primitives/canvas/icons/download.svg +1 -0
- package/src/primitives/canvas/icons/edit.svg +1 -0
- package/src/primitives/canvas/icons/ellipsis.svg +1 -0
- package/src/primitives/canvas/icons/external-link.svg +1 -0
- package/src/primitives/canvas/icons/eye.svg +1 -0
- package/src/primitives/canvas/icons/file-text.svg +1 -0
- package/src/primitives/canvas/icons/folder-open.svg +1 -0
- package/src/primitives/canvas/icons/folder.svg +1 -0
- package/src/primitives/canvas/icons/git-branch.svg +1 -0
- package/src/primitives/canvas/icons/git-merge.svg +1 -0
- package/src/primitives/canvas/icons/git-pull-request.svg +1 -0
- package/src/primitives/canvas/icons/info.svg +1 -0
- package/src/primitives/canvas/icons/menu.svg +1 -0
- package/src/primitives/canvas/icons/missing.svg +1 -0
- package/src/primitives/canvas/icons/moon.svg +1 -0
- package/src/primitives/canvas/icons/music.svg +1 -0
- package/src/primitives/canvas/icons/panel-left.svg +1 -0
- package/src/primitives/canvas/icons/panel-right.svg +1 -0
- package/src/primitives/canvas/icons/pause.svg +1 -0
- package/src/primitives/canvas/icons/play.svg +1 -0
- package/src/primitives/canvas/icons/plus.svg +1 -0
- package/src/primitives/canvas/icons/refresh-cw.svg +1 -0
- package/src/primitives/canvas/icons/repeat.svg +1 -0
- package/src/primitives/canvas/icons/save.svg +1 -0
- package/src/primitives/canvas/icons/search.svg +1 -0
- package/src/primitives/canvas/icons/send.svg +1 -0
- package/src/primitives/canvas/icons/settings.svg +1 -0
- package/src/primitives/canvas/icons/shuffle.svg +1 -0
- package/src/primitives/canvas/icons/skip-back.svg +1 -0
- package/src/primitives/canvas/icons/skip-forward.svg +1 -0
- package/src/primitives/canvas/icons/sun.svg +1 -0
- package/src/primitives/canvas/icons/terminal.svg +1 -0
- package/src/primitives/canvas/icons/trash.svg +1 -0
- package/src/primitives/canvas/icons/volume.svg +1 -0
- package/src/primitives/canvas/icons/wrench.svg +1 -0
- package/src/primitives/canvas/icons/x-circle.svg +1 -0
- package/src/primitives/canvas/icons/x.svg +1 -0
- package/src/primitives/canvas/icons.zig +249 -0
- package/src/primitives/canvas/layout_audit.zig +744 -0
- package/src/primitives/canvas/layout_audit_tests.zig +426 -0
- package/src/primitives/canvas/markdown.zig +1031 -0
- package/src/primitives/canvas/markdown_hostile_tests.zig +471 -0
- package/src/primitives/canvas/markdown_tests.zig +538 -0
- package/src/primitives/canvas/plan_key_index.zig +120 -0
- package/src/primitives/canvas/png.zig +355 -0
- package/src/primitives/canvas/reference.zig +1457 -0
- package/src/primitives/canvas/reference_blur.zig +104 -0
- package/src/primitives/canvas/reference_memo.zig +322 -0
- package/src/primitives/canvas/reference_paths.zig +184 -0
- package/src/primitives/canvas/reference_tests.zig +1650 -0
- package/src/primitives/canvas/render.zig +747 -0
- package/src/primitives/canvas/render_effects.zig +255 -0
- package/src/primitives/canvas/render_fingerprints.zig +256 -0
- package/src/primitives/canvas/render_generic_resources.zig +376 -0
- package/src/primitives/canvas/render_images.zig +247 -0
- package/src/primitives/canvas/render_layers.zig +260 -0
- package/src/primitives/canvas/render_paths.zig +347 -0
- package/src/primitives/canvas/render_resources.zig +51 -0
- package/src/primitives/canvas/render_tests.zig +3186 -0
- package/src/primitives/canvas/root.zig +744 -0
- package/src/primitives/canvas/serialization.zig +1528 -0
- package/src/primitives/canvas/svg_icon.zig +636 -0
- package/src/primitives/canvas/svg_icon_tests.zig +312 -0
- package/src/primitives/canvas/test_support.zig +422 -0
- package/src/primitives/canvas/testdata/markdown_document.md +83 -0
- package/src/primitives/canvas/tests.zig +30 -0
- package/src/primitives/canvas/text.zig +82 -0
- package/src/primitives/canvas/text_atlas.zig +408 -0
- package/src/primitives/canvas/text_batch_tests.zig +431 -0
- package/src/primitives/canvas/text_interaction.zig +615 -0
- package/src/primitives/canvas/text_layout.zig +1069 -0
- package/src/primitives/canvas/text_layout_cache.zig +281 -0
- package/src/primitives/canvas/text_layout_hash.zig +113 -0
- package/src/primitives/canvas/text_layout_types.zig +128 -0
- package/src/primitives/canvas/text_measure_cache.zig +279 -0
- package/src/primitives/canvas/text_metrics.zig +309 -0
- package/src/primitives/canvas/text_metrics_tests.zig +262 -0
- package/src/primitives/canvas/text_span_tests.zig +608 -0
- package/src/primitives/canvas/text_spans.zig +1010 -0
- package/src/primitives/canvas/text_tests.zig +1949 -0
- package/src/primitives/canvas/themes/geist.zig +470 -0
- package/src/primitives/canvas/tokens.zig +1522 -0
- package/src/primitives/canvas/ui.zig +2686 -0
- package/src/primitives/canvas/ui_markup.zig +3791 -0
- package/src/primitives/canvas/ui_markup_binary.zig +522 -0
- package/src/primitives/canvas/ui_markup_binary_tests.zig +591 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +2565 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1669 -0
- package/src/primitives/canvas/ui_markup_contract.zig +1620 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +953 -0
- package/src/primitives/canvas/ui_markup_edit.zig +416 -0
- package/src/primitives/canvas/ui_markup_edit_tests.zig +341 -0
- package/src/primitives/canvas/ui_markup_expr.zig +1152 -0
- package/src/primitives/canvas/ui_markup_expr_tests.zig +779 -0
- package/src/primitives/canvas/ui_markup_huge_model_tests.zig +505 -0
- package/src/primitives/canvas/ui_markup_reflect.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +1545 -0
- package/src/primitives/canvas/ui_markup_view.zig +2352 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +3709 -0
- package/src/primitives/canvas/ui_provenance.zig +96 -0
- package/src/primitives/canvas/ui_provenance_tests.zig +186 -0
- package/src/primitives/canvas/ui_schema.zig +825 -0
- package/src/primitives/canvas/ui_schema_tests.zig +128 -0
- package/src/primitives/canvas/ui_tests.zig +1432 -0
- package/src/primitives/canvas/vector.zig +919 -0
- package/src/primitives/canvas/vector_tests.zig +547 -0
- package/src/primitives/canvas/virtual_extent_tests.zig +317 -0
- package/src/primitives/canvas/virtual_extents.zig +540 -0
- package/src/primitives/canvas/widget_access.zig +208 -0
- package/src/primitives/canvas/widget_anchored_tests.zig +264 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +3160 -0
- package/src/primitives/canvas/widget_invalidation.zig +748 -0
- package/src/primitives/canvas/widget_layout.zig +2055 -0
- package/src/primitives/canvas/widget_layout_tests.zig +2691 -0
- package/src/primitives/canvas/widget_metrics.zig +228 -0
- package/src/primitives/canvas/widget_render.zig +2534 -0
- package/src/primitives/canvas/widget_render_controls.zig +1563 -0
- package/src/primitives/canvas/widget_render_scroll.zig +136 -0
- package/src/primitives/canvas/widget_render_style.zig +626 -0
- package/src/primitives/canvas/widget_render_surfaces.zig +794 -0
- package/src/primitives/canvas/widget_routing.zig +475 -0
- package/src/primitives/canvas/widget_runtime.zig +307 -0
- package/src/primitives/canvas/widget_runtime_tests.zig +3015 -0
- package/src/primitives/canvas/widget_semantics.zig +480 -0
- package/src/primitives/canvas/widget_semantics_tests.zig +2129 -0
- package/src/primitives/canvas/widget_tests.zig +8 -0
- package/src/primitives/canvas/widget_text_input.zig +351 -0
- package/src/primitives/canvas/widget_text_select.zig +147 -0
- package/src/primitives/canvas/widget_tree.zig +232 -0
- package/src/primitives/canvas/widgets.zig +1319 -0
- package/src/primitives/diagnostics/root.zig +445 -0
- package/src/primitives/geometry/root.zig +889 -0
- package/src/primitives/json/root.zig +272 -0
- package/src/primitives/platform_info/root.zig +450 -0
- package/src/primitives/trace/root.zig +569 -0
- package/src/root.zig +165 -0
- package/src/runtime/api.zig +431 -0
- package/src/runtime/async_bridge.zig +49 -0
- package/src/runtime/automation_commands.zig +686 -0
- package/src/runtime/automation_liveness_tests.zig +140 -0
- package/src/runtime/automation_snapshot.zig +246 -0
- package/src/runtime/automation_widget_dispatch.zig +617 -0
- package/src/runtime/bridge_dispatch_tests.zig +202 -0
- package/src/runtime/bridge_payload.zig +194 -0
- package/src/runtime/bridge_permission_tests.zig +551 -0
- package/src/runtime/bridge_responses.zig +414 -0
- package/src/runtime/builtin_bridge.zig +554 -0
- package/src/runtime/canvas_budget_edge_tests.zig +415 -0
- package/src/runtime/canvas_font_tests.zig +410 -0
- package/src/runtime/canvas_fonts.zig +229 -0
- package/src/runtime/canvas_frame.zig +1734 -0
- package/src/runtime/canvas_frame_animation_tests.zig +609 -0
- package/src/runtime/canvas_frame_cache_tests.zig +333 -0
- package/src/runtime/canvas_frame_helpers.zig +414 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +544 -0
- package/src/runtime/canvas_frame_packet_tests.zig +1353 -0
- package/src/runtime/canvas_frame_patch_tests.zig +1051 -0
- package/src/runtime/canvas_frame_retained_tests.zig +753 -0
- package/src/runtime/canvas_frame_tests.zig +9 -0
- package/src/runtime/canvas_frame_text_layout_budget_tests.zig +149 -0
- package/src/runtime/canvas_image_tests.zig +362 -0
- package/src/runtime/canvas_images.zig +224 -0
- package/src/runtime/canvas_limits.zig +317 -0
- package/src/runtime/canvas_screenshot_tests.zig +289 -0
- package/src/runtime/canvas_widget_accessibility_tests.zig +1494 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +678 -0
- package/src/runtime/canvas_widget_chart_tests.zig +249 -0
- package/src/runtime/canvas_widget_clipboard_tests.zig +399 -0
- package/src/runtime/canvas_widget_context_menu.zig +318 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +462 -0
- package/src/runtime/canvas_widget_control_tests.zig +2164 -0
- package/src/runtime/canvas_widget_disclosure_tests.zig +440 -0
- package/src/runtime/canvas_widget_display.zig +677 -0
- package/src/runtime/canvas_widget_event_tests.zig +1779 -0
- package/src/runtime/canvas_widget_events.zig +1098 -0
- package/src/runtime/canvas_widget_floating_tests.zig +695 -0
- package/src/runtime/canvas_widget_layout_tests.zig +26 -0
- package/src/runtime/canvas_widget_runtime.zig +1335 -0
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +582 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +202 -0
- package/src/runtime/canvas_widget_scroll_tests.zig +1549 -0
- package/src/runtime/canvas_widget_semantics_tests.zig +810 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +1031 -0
- package/src/runtime/canvas_widget_state.zig +798 -0
- package/src/runtime/canvas_widget_text_tests.zig +2104 -0
- package/src/runtime/canvas_widget_window_drag_tests.zig +284 -0
- package/src/runtime/clock.zig +231 -0
- package/src/runtime/core.zig +927 -0
- package/src/runtime/effects.zig +4197 -0
- package/src/runtime/effects_audio_tests.zig +690 -0
- package/src/runtime/effects_clipboard_tests.zig +317 -0
- package/src/runtime/effects_fetch_tests.zig +1031 -0
- package/src/runtime/effects_file_tests.zig +407 -0
- package/src/runtime/effects_tests.zig +1251 -0
- package/src/runtime/flow.zig +1175 -0
- package/src/runtime/frame_profile.zig +221 -0
- package/src/runtime/gpu_surface_events.zig +639 -0
- package/src/runtime/launch_timing.zig +59 -0
- package/src/runtime/markdown_app_tests.zig +224 -0
- package/src/runtime/native_command_event_tests.zig +431 -0
- package/src/runtime/platform_bridge_tests.zig +8 -0
- package/src/runtime/platform_config_tests.zig +392 -0
- package/src/runtime/root.zig +150 -0
- package/src/runtime/runtime_event_tests.zig +1079 -0
- package/src/runtime/session_journal.zig +1522 -0
- package/src/runtime/session_record.zig +332 -0
- package/src/runtime/session_replay.zig +274 -0
- package/src/runtime/session_state.zig +30 -0
- package/src/runtime/session_tests.zig +399 -0
- package/src/runtime/shell_layout.zig +472 -0
- package/src/runtime/shell_layout_tests.zig +1246 -0
- package/src/runtime/shell_view_tests.zig +604 -0
- package/src/runtime/state.zig +110 -0
- package/src/runtime/system_services.zig +392 -0
- package/src/runtime/test_support.zig +79 -0
- package/src/runtime/tests.zig +30 -0
- package/src/runtime/ui_app.zig +3290 -0
- package/src/runtime/ui_app_huge_model_tests.zig +351 -0
- package/src/runtime/ui_app_provenance.zig +370 -0
- package/src/runtime/ui_app_tests.zig +3254 -0
- package/src/runtime/ui_app_virtual_variable_tests.zig +485 -0
- package/src/runtime/ui_app_window_tests.zig +442 -0
- package/src/runtime/validation.zig +206 -0
- package/src/runtime/view.zig +908 -0
- package/src/runtime/view_canvas.zig +850 -0
- package/src/runtime/view_widget_control.zig +433 -0
- package/src/runtime/view_widget_scroll.zig +360 -0
- package/src/runtime/view_widget_text.zig +275 -0
- package/src/runtime/view_widget_tree.zig +843 -0
- package/src/runtime/webview_view_bridge_tests.zig +664 -0
- package/src/runtime/widget_bridge.zig +231 -0
- package/src/runtime/window_command_bridge_tests.zig +403 -0
- package/src/runtime/window_storage.zig +255 -0
- package/src/runtime/window_view_runtime.zig +727 -0
- package/src/runtime/window_views.zig +334 -0
- package/src/security/root.zig +118 -0
- package/src/tooling/android.zig +1172 -0
- package/src/tooling/assets.zig +128 -0
- package/src/tooling/buildgraph.zig +379 -0
- package/src/tooling/cef.zig +671 -0
- package/src/tooling/codesign.zig +172 -0
- package/src/tooling/components/identity_tests.zig +185 -0
- package/src/tooling/components/stepper.zig +113 -0
- package/src/tooling/components/timeline.native +27 -0
- package/src/tooling/components/timeline_item.zig +131 -0
- package/src/tooling/default_icon.icns +0 -0
- package/src/tooling/default_icon.png +0 -0
- package/src/tooling/dev.zig +172 -0
- package/src/tooling/doctor.zig +349 -0
- package/src/tooling/eject_components.zig +170 -0
- package/src/tooling/embedlib.zig +290 -0
- package/src/tooling/ios.zig +528 -0
- package/src/tooling/manifest.zig +1939 -0
- package/src/tooling/package.zig +2388 -0
- package/src/tooling/process_tree.zig +114 -0
- package/src/tooling/raw_manifest.zig +193 -0
- package/src/tooling/root.zig +22 -0
- package/src/tooling/templates.zig +3191 -0
- package/src/tooling/toolchain.zig +371 -0
- package/src/tooling/verbs.zig +204 -0
- package/src/tooling/web_engine.zig +135 -0
- package/src/tooling/xcodeproj.zig +462 -0
- package/src/window_state/root.zig +507 -0
- package/index.js +0 -2
|
@@ -0,0 +1,1779 @@
|
|
|
1
|
+
const support = @import("test_support.zig");
|
|
2
|
+
const std = support.std;
|
|
3
|
+
const geometry = support.geometry;
|
|
4
|
+
const trace = support.trace;
|
|
5
|
+
const json = support.json;
|
|
6
|
+
const canvas = support.canvas;
|
|
7
|
+
const automation = support.automation;
|
|
8
|
+
const bridge = support.bridge;
|
|
9
|
+
const app_manifest = support.app_manifest;
|
|
10
|
+
const platform = support.platform;
|
|
11
|
+
const security = support.security;
|
|
12
|
+
const extensions = support.extensions;
|
|
13
|
+
const window_state = support.window_state;
|
|
14
|
+
const runtime_module = support.runtime_module;
|
|
15
|
+
const bridge_payload = support.bridge_payload;
|
|
16
|
+
const canvas_frame = support.canvas_frame;
|
|
17
|
+
const App = support.App;
|
|
18
|
+
const Runtime = support.Runtime;
|
|
19
|
+
const Options = support.Options;
|
|
20
|
+
const Event = support.Event;
|
|
21
|
+
const LifecycleEvent = support.LifecycleEvent;
|
|
22
|
+
const CommandEvent = support.CommandEvent;
|
|
23
|
+
const Command = support.Command;
|
|
24
|
+
const CommandSource = support.CommandSource;
|
|
25
|
+
const FrameDiagnostics = support.FrameDiagnostics;
|
|
26
|
+
const ShortcutEvent = support.ShortcutEvent;
|
|
27
|
+
const Appearance = support.Appearance;
|
|
28
|
+
const GpuFrame = support.GpuFrame;
|
|
29
|
+
const GpuSurfaceFrameEvent = support.GpuSurfaceFrameEvent;
|
|
30
|
+
const GpuSurfaceResizeEvent = support.GpuSurfaceResizeEvent;
|
|
31
|
+
const GpuSurfaceInputEvent = support.GpuSurfaceInputEvent;
|
|
32
|
+
const CanvasWidgetPointerEvent = support.CanvasWidgetPointerEvent;
|
|
33
|
+
const CanvasWidgetKeyboardEvent = support.CanvasWidgetKeyboardEvent;
|
|
34
|
+
const CanvasWidgetDisplayListChrome = support.CanvasWidgetDisplayListChrome;
|
|
35
|
+
const CanvasPresentationMode = support.CanvasPresentationMode;
|
|
36
|
+
const CanvasPresentationResult = support.CanvasPresentationResult;
|
|
37
|
+
const CanvasWidgetAccessibilityActionKind = support.CanvasWidgetAccessibilityActionKind;
|
|
38
|
+
const CanvasWidgetAccessibilityAction = support.CanvasWidgetAccessibilityAction;
|
|
39
|
+
const CanvasWidgetFileDropEvent = support.CanvasWidgetFileDropEvent;
|
|
40
|
+
const CanvasWidgetDragEvent = support.CanvasWidgetDragEvent;
|
|
41
|
+
const InvalidationReason = support.InvalidationReason;
|
|
42
|
+
const TestHarness = support.TestHarness;
|
|
43
|
+
const max_canvas_commands_per_view = support.max_canvas_commands_per_view;
|
|
44
|
+
const max_canvas_widget_nodes_per_view = support.max_canvas_widget_nodes_per_view;
|
|
45
|
+
const jsonStringField = support.jsonStringField;
|
|
46
|
+
const jsonNumberField = support.jsonNumberField;
|
|
47
|
+
const jsonBoolField = support.jsonBoolField;
|
|
48
|
+
const canvasRenderAnimationFinalOverrideNoop = support.canvasRenderAnimationFinalOverrideNoop;
|
|
49
|
+
const copyInto = support.copyInto;
|
|
50
|
+
const writeViewJson = support.writeViewJson;
|
|
51
|
+
const canvasFrameScratchStorage = support.canvasFrameScratchStorage;
|
|
52
|
+
const runtimeViewInfo = support.runtimeViewInfo;
|
|
53
|
+
const runtimeViewCanvasFrameRenderOverrides = support.runtimeViewCanvasFrameRenderOverrides;
|
|
54
|
+
const runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides = support.runtimeViewCanvasRenderAnimationDirtyBoundsForOverrides;
|
|
55
|
+
const runtimeViewWidgetSemantics = support.runtimeViewWidgetSemantics;
|
|
56
|
+
const runtimeViewSetCanvasWidgetSelected = support.runtimeViewSetCanvasWidgetSelected;
|
|
57
|
+
const runtimeViewCanvasWidgetDirtyBounds = support.runtimeViewCanvasWidgetDirtyBounds;
|
|
58
|
+
const dispatchAutomationWidgetAction = support.dispatchAutomationWidgetAction;
|
|
59
|
+
const shellBoundsForWindow = support.shellBoundsForWindow;
|
|
60
|
+
const reloadWindows = support.reloadWindows;
|
|
61
|
+
const canvasWidgetSemanticsById = support.canvasWidgetSemanticsById;
|
|
62
|
+
const platformWidgetAccessibilityNodeById = support.platformWidgetAccessibilityNodeById;
|
|
63
|
+
const builtinBridgeErrorCode = support.builtinBridgeErrorCode;
|
|
64
|
+
const builtinBridgeErrorMessage = support.builtinBridgeErrorMessage;
|
|
65
|
+
const testViewByLabel = support.testViewByLabel;
|
|
66
|
+
const testCanvasWidgetPartId = support.testCanvasWidgetPartId;
|
|
67
|
+
|
|
68
|
+
test "runtime tracks retained canvas widget cursor intent" {
|
|
69
|
+
const TestApp = struct {
|
|
70
|
+
fn app(self: *@This()) App {
|
|
71
|
+
return .{ .context = self, .name = "gpu-widget-cursor", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
76
|
+
defer harness.destroy(std.testing.allocator);
|
|
77
|
+
harness.null_platform.gpu_surfaces = true;
|
|
78
|
+
var app_state: TestApp = .{};
|
|
79
|
+
const app = app_state.app();
|
|
80
|
+
try harness.start(app);
|
|
81
|
+
|
|
82
|
+
_ = try harness.runtime.createView(.{
|
|
83
|
+
.window_id = 1,
|
|
84
|
+
.label = "canvas",
|
|
85
|
+
.kind = .gpu_surface,
|
|
86
|
+
.frame = geometry.RectF.init(0, 0, 240, 160),
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const children = [_]canvas.Widget{
|
|
90
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 12, 96, 32), .text = "Run" },
|
|
91
|
+
.{ .id = 3, .kind = .text_field, .frame = geometry.RectF.init(10, 52, 140, 32), .text = "Query" },
|
|
92
|
+
.{ .id = 4, .kind = .slider, .frame = geometry.RectF.init(10, 96, 140, 24), .value = 0.5 },
|
|
93
|
+
.{ .id = 5, .kind = .split_divider, .frame = geometry.RectF.init(10, 128, 140, 16) },
|
|
94
|
+
};
|
|
95
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
96
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 160), &nodes);
|
|
97
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
98
|
+
var snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
99
|
+
try std.testing.expectEqual(platform.Cursor.arrow, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
100
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.view_cursor_count);
|
|
101
|
+
|
|
102
|
+
// Buttons follow the NATIVE cursor register: the arrow, exactly like
|
|
103
|
+
// the platform's own controls. Hovering one changes nothing on the
|
|
104
|
+
// cursor channel — no platform write happens — because the pointing
|
|
105
|
+
// hand is a hyperlink affordance, not a control affordance.
|
|
106
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_move, .x = 20, .y = 24 } });
|
|
107
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
108
|
+
try std.testing.expectEqual(platform.Cursor.arrow, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
109
|
+
try std.testing.expectEqual(@as(usize, 0), harness.null_platform.view_cursor_count);
|
|
110
|
+
|
|
111
|
+
// Editable text keeps the I-beam — the first hover that actually
|
|
112
|
+
// moves the channel, so the platform write (with window and label)
|
|
113
|
+
// is observable here.
|
|
114
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_move, .x = 20, .y = 64 } });
|
|
115
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
116
|
+
try std.testing.expectEqual(platform.Cursor.text, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
117
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.view_cursor_count);
|
|
118
|
+
try std.testing.expectEqual(platform.Cursor.text, harness.null_platform.view_cursor);
|
|
119
|
+
try std.testing.expectEqual(@as(platform.WindowId, 1), harness.null_platform.view_cursor_window_id);
|
|
120
|
+
try std.testing.expectEqualStrings("canvas", harness.null_platform.view_cursor_label_storage[0..harness.null_platform.view_cursor_label_len]);
|
|
121
|
+
|
|
122
|
+
const disabled_children = [_]canvas.Widget{
|
|
123
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 12, 96, 32), .text = "Run" },
|
|
124
|
+
.{ .id = 3, .kind = .text_field, .frame = geometry.RectF.init(10, 52, 140, 32), .text = "Query", .state = .{ .disabled = true } },
|
|
125
|
+
.{ .id = 4, .kind = .slider, .frame = geometry.RectF.init(10, 96, 140, 24), .value = 0.5 },
|
|
126
|
+
.{ .id = 5, .kind = .split_divider, .frame = geometry.RectF.init(10, 128, 140, 16) },
|
|
127
|
+
};
|
|
128
|
+
var disabled_nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
129
|
+
const disabled_layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &disabled_children }, geometry.RectF.init(0, 0, 240, 160), &disabled_nodes);
|
|
130
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", disabled_layout);
|
|
131
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
132
|
+
try std.testing.expectEqual(platform.Cursor.arrow, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
133
|
+
try std.testing.expectEqual(@as(usize, 2), harness.null_platform.view_cursor_count);
|
|
134
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.null_platform.view_cursor);
|
|
135
|
+
|
|
136
|
+
// Sliders keep the arrow too — at rest AND during a drag — matching
|
|
137
|
+
// native sliders on every platform. No cursor write fires.
|
|
138
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_move, .x = 20, .y = 108 } });
|
|
139
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
140
|
+
try std.testing.expectEqual(platform.Cursor.arrow, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
141
|
+
try std.testing.expectEqual(@as(usize, 2), harness.null_platform.view_cursor_count);
|
|
142
|
+
|
|
143
|
+
// Split dividers are the resize affordance — that part of the
|
|
144
|
+
// register is unchanged.
|
|
145
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_move, .x = 20, .y = 134 } });
|
|
146
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
147
|
+
const canvas_view = testViewByLabel(snapshot.views, "canvas").?;
|
|
148
|
+
try std.testing.expectEqual(platform.Cursor.resize_horizontal, canvas_view.cursor);
|
|
149
|
+
try std.testing.expectEqual(@as(usize, 3), harness.null_platform.view_cursor_count);
|
|
150
|
+
try std.testing.expectEqual(platform.Cursor.resize_horizontal, harness.null_platform.view_cursor);
|
|
151
|
+
|
|
152
|
+
var view_json_buffer: [4096]u8 = undefined;
|
|
153
|
+
const view_json = try writeViewJson(canvas_view, &view_json_buffer);
|
|
154
|
+
try std.testing.expect(std.mem.indexOf(u8, view_json, "\"cursor\":\"resize_horizontal\"") != null);
|
|
155
|
+
|
|
156
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{ .window_id = 1, .label = "canvas", .kind = .pointer_move, .x = 220, .y = 148 } });
|
|
157
|
+
snapshot = harness.runtime.automationSnapshot("Cursor");
|
|
158
|
+
try std.testing.expectEqual(platform.Cursor.arrow, testViewByLabel(snapshot.views, "canvas").?.cursor);
|
|
159
|
+
try std.testing.expectEqual(@as(usize, 4), harness.null_platform.view_cursor_count);
|
|
160
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.null_platform.view_cursor);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
test "composite list row hovers as one surface: wash, cursor, and pressed wash cover the row" {
|
|
164
|
+
const TestApp = struct {
|
|
165
|
+
fn app(self: *@This()) App {
|
|
166
|
+
return .{ .context = self, .name = "gpu-widget-row-hover", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
171
|
+
defer harness.destroy(std.testing.allocator);
|
|
172
|
+
harness.null_platform.gpu_surfaces = true;
|
|
173
|
+
var app_state: TestApp = .{};
|
|
174
|
+
const app = app_state.app();
|
|
175
|
+
try harness.start(app);
|
|
176
|
+
|
|
177
|
+
_ = try harness.runtime.createView(.{
|
|
178
|
+
.window_id = 1,
|
|
179
|
+
.label = "canvas",
|
|
180
|
+
.kind = .gpu_surface,
|
|
181
|
+
.frame = geometry.RectF.init(0, 0, 320, 160),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// The two-line list row shape (title + snippet) the showcase list
|
|
185
|
+
// panes render: text children are hit targets (selection), but hover
|
|
186
|
+
// must attribute to the row.
|
|
187
|
+
const snippet = canvas.Widget{ .id = 6, .kind = .text, .frame = geometry.RectF.init(0, 0, 160, 20), .text = "Snippet line" };
|
|
188
|
+
const inner_row = canvas.Widget{ .id = 5, .kind = .row, .frame = geometry.RectF.init(0, 0, 0, 20), .children = &.{snippet} };
|
|
189
|
+
const title = canvas.Widget{ .id = 4, .kind = .text, .frame = geometry.RectF.init(0, 0, 120, 20), .text = "Title" };
|
|
190
|
+
const column = canvas.Widget{ .id = 3, .kind = .column, .layout = .{ .gap = 8 }, .children = &.{ title, inner_row } };
|
|
191
|
+
const row = canvas.Widget{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 72), .layout = .{ .padding = geometry.InsetsF.all(10) }, .children = &.{column} };
|
|
192
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
193
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &.{row} }, geometry.RectF.init(0, 0, 320, 160), &nodes);
|
|
194
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
195
|
+
|
|
196
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
197
|
+
const title_frame = retained.findById(4).?.frame.normalized();
|
|
198
|
+
const snippet_frame = retained.findById(6).?.frame.normalized();
|
|
199
|
+
const row_frame = retained.findById(2).?.frame.normalized();
|
|
200
|
+
|
|
201
|
+
// Probe the title interior, the gap between the lines, the snippet
|
|
202
|
+
// interior, and the row's padding corner: every point hovers the ROW
|
|
203
|
+
// and shows the pointer cursor — no dead zones inside one surface.
|
|
204
|
+
const probes = [_]geometry.PointF{
|
|
205
|
+
title_frame.center(),
|
|
206
|
+
.{ .x = title_frame.center().x, .y = (title_frame.maxY() + snippet_frame.y) / 2 },
|
|
207
|
+
snippet_frame.center(),
|
|
208
|
+
.{ .x = row_frame.x + 3, .y = row_frame.y + 3 },
|
|
209
|
+
.{ .x = row_frame.maxX() - 3, .y = snippet_frame.center().y },
|
|
210
|
+
};
|
|
211
|
+
for (probes) |probe| {
|
|
212
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
213
|
+
.window_id = 1,
|
|
214
|
+
.label = "canvas",
|
|
215
|
+
.kind = .pointer_move,
|
|
216
|
+
.x = probe.x,
|
|
217
|
+
.y = probe.y,
|
|
218
|
+
} });
|
|
219
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
220
|
+
// The hover wash is the row's affordance; the cursor stays the
|
|
221
|
+
// native arrow (list rows are controls, not hyperlinks).
|
|
222
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// A press over the snippet lights the row's pressed wash (the render
|
|
226
|
+
// state resolves it through the same fall-through the click takes).
|
|
227
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
228
|
+
.window_id = 1,
|
|
229
|
+
.label = "canvas",
|
|
230
|
+
.kind = .pointer_down,
|
|
231
|
+
.x = snippet_frame.center().x,
|
|
232
|
+
.y = snippet_frame.center().y,
|
|
233
|
+
} });
|
|
234
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
235
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvasWidgetRenderState().pressed_id.?);
|
|
236
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
237
|
+
.window_id = 1,
|
|
238
|
+
.label = "canvas",
|
|
239
|
+
.kind = .pointer_up,
|
|
240
|
+
.x = snippet_frame.center().x,
|
|
241
|
+
.y = snippet_frame.center().y,
|
|
242
|
+
} });
|
|
243
|
+
|
|
244
|
+
// Off the row: hover clears and the cursor stays the arrow it never
|
|
245
|
+
// left (the channel is read from the runtime — the platform write
|
|
246
|
+
// only fires on change, and a row hover never changes it).
|
|
247
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
248
|
+
.window_id = 1,
|
|
249
|
+
.label = "canvas",
|
|
250
|
+
.kind = .pointer_move,
|
|
251
|
+
.x = row_frame.center().x,
|
|
252
|
+
.y = row_frame.maxY() + 20,
|
|
253
|
+
} });
|
|
254
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
255
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
test "runtime dispatches routed canvas widget pointer events" {
|
|
259
|
+
const TestApp = struct {
|
|
260
|
+
raw_input_count: u32 = 0,
|
|
261
|
+
widget_pointer_count: u32 = 0,
|
|
262
|
+
widget_keyboard_count: u32 = 0,
|
|
263
|
+
widget_key_down_count: u32 = 0,
|
|
264
|
+
widget_text_input_count: u32 = 0,
|
|
265
|
+
last_view_label: []const u8 = "",
|
|
266
|
+
last_phase: canvas.WidgetPointerPhase = .hover,
|
|
267
|
+
last_keyboard_phase: canvas.WidgetKeyboardPhase = .key_up,
|
|
268
|
+
last_target_id: canvas.ObjectId = 0,
|
|
269
|
+
last_target_kind: canvas.WidgetKind = .stack,
|
|
270
|
+
last_keyboard_target_id: canvas.ObjectId = 0,
|
|
271
|
+
last_keyboard_target_kind: canvas.WidgetKind = .stack,
|
|
272
|
+
last_route_len: usize = 0,
|
|
273
|
+
last_keyboard_route_len: usize = 0,
|
|
274
|
+
last_keyboard_key: []const u8 = "",
|
|
275
|
+
last_keyboard_text: []const u8 = "",
|
|
276
|
+
last_keyboard_shift: bool = false,
|
|
277
|
+
last_keyboard_super: bool = false,
|
|
278
|
+
|
|
279
|
+
fn app(self: *@This()) App {
|
|
280
|
+
return .{ .context = self, .name = "gpu-widget-input", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
284
|
+
_ = runtime;
|
|
285
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
286
|
+
switch (event_value) {
|
|
287
|
+
.gpu_surface_input => {
|
|
288
|
+
self.raw_input_count += 1;
|
|
289
|
+
},
|
|
290
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
291
|
+
self.widget_pointer_count += 1;
|
|
292
|
+
self.last_view_label = pointer_event.view_label;
|
|
293
|
+
self.last_phase = pointer_event.pointer.phase;
|
|
294
|
+
self.last_route_len = pointer_event.route.len;
|
|
295
|
+
if (pointer_event.target) |target| {
|
|
296
|
+
self.last_target_id = target.id;
|
|
297
|
+
self.last_target_kind = target.kind;
|
|
298
|
+
} else {
|
|
299
|
+
self.last_target_id = 0;
|
|
300
|
+
self.last_target_kind = .stack;
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
.canvas_widget_keyboard => |keyboard_event| {
|
|
304
|
+
self.widget_keyboard_count += 1;
|
|
305
|
+
switch (keyboard_event.keyboard.phase) {
|
|
306
|
+
.key_down => self.widget_key_down_count += 1,
|
|
307
|
+
.text_input => self.widget_text_input_count += 1,
|
|
308
|
+
.key_up => {},
|
|
309
|
+
}
|
|
310
|
+
self.last_view_label = keyboard_event.view_label;
|
|
311
|
+
self.last_keyboard_phase = keyboard_event.keyboard.phase;
|
|
312
|
+
self.last_keyboard_route_len = keyboard_event.route.len;
|
|
313
|
+
self.last_keyboard_key = keyboard_event.keyboard.key;
|
|
314
|
+
self.last_keyboard_text = keyboard_event.keyboard.text;
|
|
315
|
+
self.last_keyboard_shift = keyboard_event.keyboard.modifiers.shift;
|
|
316
|
+
self.last_keyboard_super = keyboard_event.keyboard.modifiers.super;
|
|
317
|
+
if (keyboard_event.target) |target| {
|
|
318
|
+
self.last_keyboard_target_id = target.id;
|
|
319
|
+
self.last_keyboard_target_kind = target.kind;
|
|
320
|
+
} else {
|
|
321
|
+
self.last_keyboard_target_id = 0;
|
|
322
|
+
self.last_keyboard_target_kind = .stack;
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
else => {},
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
331
|
+
defer harness.destroy(std.testing.allocator);
|
|
332
|
+
harness.null_platform.gpu_surfaces = true;
|
|
333
|
+
var app_state: TestApp = .{};
|
|
334
|
+
const app = app_state.app();
|
|
335
|
+
try harness.start(app);
|
|
336
|
+
|
|
337
|
+
_ = try harness.runtime.createView(.{
|
|
338
|
+
.window_id = 1,
|
|
339
|
+
.label = "canvas",
|
|
340
|
+
.kind = .gpu_surface,
|
|
341
|
+
.frame = geometry.RectF.init(0, 0, 240, 160),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const children = [_]canvas.Widget{
|
|
345
|
+
.{
|
|
346
|
+
.id = 2,
|
|
347
|
+
.kind = .button,
|
|
348
|
+
.frame = geometry.RectF.init(10, 12, 96, 32),
|
|
349
|
+
.text = "Run",
|
|
350
|
+
},
|
|
351
|
+
.{
|
|
352
|
+
.id = 3,
|
|
353
|
+
.kind = .text_field,
|
|
354
|
+
.frame = geometry.RectF.init(10, 52, 140, 32),
|
|
355
|
+
.text = "Query",
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
const root = canvas.Widget{
|
|
359
|
+
.id = 1,
|
|
360
|
+
.kind = .panel,
|
|
361
|
+
.children = &children,
|
|
362
|
+
};
|
|
363
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
364
|
+
const layout = try canvas.layoutWidgetTree(root, geometry.RectF.init(0, 0, 240, 160), &nodes);
|
|
365
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
366
|
+
|
|
367
|
+
harness.runtime.invalidated = false;
|
|
368
|
+
harness.runtime.dirty_region_count = 0;
|
|
369
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
370
|
+
.window_id = 1,
|
|
371
|
+
.label = "canvas",
|
|
372
|
+
.kind = .pointer_down,
|
|
373
|
+
.x = 20,
|
|
374
|
+
.y = 24,
|
|
375
|
+
.button = 0,
|
|
376
|
+
} });
|
|
377
|
+
|
|
378
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
379
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.raw_input_count);
|
|
380
|
+
try std.testing.expectEqualStrings("canvas", app_state.last_view_label);
|
|
381
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.down, app_state.last_phase);
|
|
382
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_target_id);
|
|
383
|
+
try std.testing.expectEqual(canvas.WidgetKind.button, app_state.last_target_kind);
|
|
384
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_route_len);
|
|
385
|
+
try std.testing.expect(harness.runtime.views[0].focused);
|
|
386
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
387
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
388
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.pendingDirtyRegions().len);
|
|
389
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 12, 96, 32), harness.runtime.pendingDirtyRegions()[0]);
|
|
390
|
+
|
|
391
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
392
|
+
try std.testing.expectEqual(@as(usize, 3), snapshot.widgets.len);
|
|
393
|
+
try std.testing.expect(!snapshot.widgets[0].focused);
|
|
394
|
+
try std.testing.expect(snapshot.widgets[1].focused);
|
|
395
|
+
try std.testing.expect(snapshot.widgets[1].hovered);
|
|
396
|
+
try std.testing.expect(snapshot.widgets[1].pressed);
|
|
397
|
+
try std.testing.expect(!snapshot.widgets[1].selected);
|
|
398
|
+
try std.testing.expect(!snapshot.widgets[2].focused);
|
|
399
|
+
|
|
400
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
401
|
+
.window_id = 1,
|
|
402
|
+
.label = "canvas",
|
|
403
|
+
.kind = .key_down,
|
|
404
|
+
.key = "enter",
|
|
405
|
+
.modifiers = .{ .shift = true, .primary = true },
|
|
406
|
+
} });
|
|
407
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
408
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_keyboard_count);
|
|
409
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_key_down_count);
|
|
410
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_text_input_count);
|
|
411
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.raw_input_count);
|
|
412
|
+
try std.testing.expectEqual(canvas.WidgetKeyboardPhase.key_down, app_state.last_keyboard_phase);
|
|
413
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
414
|
+
try std.testing.expectEqual(canvas.WidgetKind.button, app_state.last_keyboard_target_kind);
|
|
415
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_keyboard_route_len);
|
|
416
|
+
try std.testing.expectEqualStrings("enter", app_state.last_keyboard_key);
|
|
417
|
+
try std.testing.expectEqualStrings("", app_state.last_keyboard_text);
|
|
418
|
+
try std.testing.expect(app_state.last_keyboard_shift);
|
|
419
|
+
try std.testing.expect(app_state.last_keyboard_super);
|
|
420
|
+
|
|
421
|
+
harness.runtime.invalidated = false;
|
|
422
|
+
harness.runtime.dirty_region_count = 0;
|
|
423
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
424
|
+
.window_id = 1,
|
|
425
|
+
.label = "canvas",
|
|
426
|
+
.kind = .key_down,
|
|
427
|
+
.key = "tab",
|
|
428
|
+
} });
|
|
429
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_keyboard_count);
|
|
430
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_key_down_count);
|
|
431
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_text_input_count);
|
|
432
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.raw_input_count);
|
|
433
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
|
|
434
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_keyboard_target_id);
|
|
435
|
+
try std.testing.expectEqual(canvas.WidgetKind.text_field, app_state.last_keyboard_target_kind);
|
|
436
|
+
try std.testing.expectEqualStrings("tab", app_state.last_keyboard_key);
|
|
437
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
438
|
+
try std.testing.expectEqual(@as(usize, 1), harness.runtime.pendingDirtyRegions().len);
|
|
439
|
+
// Focus dirty bounds include the ring's 2px outside offset.
|
|
440
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(7, 49, 146, 38), harness.runtime.pendingDirtyRegions()[0]);
|
|
441
|
+
|
|
442
|
+
const tab_snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
443
|
+
try std.testing.expect(!tab_snapshot.widgets[1].focused);
|
|
444
|
+
try std.testing.expect(tab_snapshot.widgets[2].focused);
|
|
445
|
+
|
|
446
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
447
|
+
.window_id = 1,
|
|
448
|
+
.label = "canvas",
|
|
449
|
+
.kind = .key_down,
|
|
450
|
+
.key = "a",
|
|
451
|
+
.text = "a",
|
|
452
|
+
} });
|
|
453
|
+
try std.testing.expectEqual(@as(u32, 4), app_state.widget_keyboard_count);
|
|
454
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.widget_key_down_count);
|
|
455
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_text_input_count);
|
|
456
|
+
try std.testing.expectEqual(@as(u32, 4), app_state.raw_input_count);
|
|
457
|
+
try std.testing.expectEqual(canvas.WidgetKeyboardPhase.text_input, app_state.last_keyboard_phase);
|
|
458
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_keyboard_target_id);
|
|
459
|
+
try std.testing.expectEqual(canvas.WidgetKind.text_field, app_state.last_keyboard_target_kind);
|
|
460
|
+
try std.testing.expectEqualStrings("a", app_state.last_keyboard_key);
|
|
461
|
+
try std.testing.expectEqualStrings("a", app_state.last_keyboard_text);
|
|
462
|
+
|
|
463
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
464
|
+
.window_id = 1,
|
|
465
|
+
.label = "canvas",
|
|
466
|
+
.kind = .key_down,
|
|
467
|
+
.key = "a",
|
|
468
|
+
.text = "a",
|
|
469
|
+
.modifiers = .{ .primary = true, .command = true },
|
|
470
|
+
} });
|
|
471
|
+
try std.testing.expectEqual(@as(u32, 5), app_state.widget_keyboard_count);
|
|
472
|
+
try std.testing.expectEqual(@as(u32, 4), app_state.widget_key_down_count);
|
|
473
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_text_input_count);
|
|
474
|
+
try std.testing.expectEqual(@as(u32, 5), app_state.raw_input_count);
|
|
475
|
+
try std.testing.expectEqual(canvas.WidgetKeyboardPhase.key_down, app_state.last_keyboard_phase);
|
|
476
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_keyboard_target_id);
|
|
477
|
+
try std.testing.expectEqual(canvas.WidgetKind.text_field, app_state.last_keyboard_target_kind);
|
|
478
|
+
try std.testing.expectEqualStrings("a", app_state.last_keyboard_key);
|
|
479
|
+
try std.testing.expectEqualStrings("a", app_state.last_keyboard_text);
|
|
480
|
+
try std.testing.expect(app_state.last_keyboard_super);
|
|
481
|
+
|
|
482
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
483
|
+
.window_id = 1,
|
|
484
|
+
.label = "canvas",
|
|
485
|
+
.kind = .key_down,
|
|
486
|
+
.key = "tab",
|
|
487
|
+
.modifiers = .{ .shift = true },
|
|
488
|
+
} });
|
|
489
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.widget_keyboard_count);
|
|
490
|
+
try std.testing.expectEqual(@as(u32, 5), app_state.widget_key_down_count);
|
|
491
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_text_input_count);
|
|
492
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.raw_input_count);
|
|
493
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
494
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
495
|
+
try std.testing.expectEqual(canvas.WidgetKind.button, app_state.last_keyboard_target_kind);
|
|
496
|
+
try std.testing.expect(app_state.last_keyboard_shift);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
test "runtime routes captured canvas pointer drags without outside release activation" {
|
|
500
|
+
const TestApp = struct {
|
|
501
|
+
command_count: u32 = 0,
|
|
502
|
+
widget_pointer_count: u32 = 0,
|
|
503
|
+
last_phase: canvas.WidgetPointerPhase = .hover,
|
|
504
|
+
last_target_id: canvas.ObjectId = 0,
|
|
505
|
+
last_route_len: usize = 0,
|
|
506
|
+
|
|
507
|
+
fn app(self: *@This()) App {
|
|
508
|
+
return .{ .context = self, .name = "gpu-widget-pointer-capture", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
512
|
+
_ = runtime;
|
|
513
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
514
|
+
switch (event_value) {
|
|
515
|
+
.command => self.command_count += 1,
|
|
516
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
517
|
+
self.widget_pointer_count += 1;
|
|
518
|
+
self.last_phase = pointer_event.pointer.phase;
|
|
519
|
+
self.last_route_len = pointer_event.route.len;
|
|
520
|
+
self.last_target_id = if (pointer_event.target) |target| target.id else 0;
|
|
521
|
+
},
|
|
522
|
+
else => {},
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
528
|
+
defer harness.destroy(std.testing.allocator);
|
|
529
|
+
harness.null_platform.gpu_surfaces = true;
|
|
530
|
+
var app_state: TestApp = .{};
|
|
531
|
+
const app = app_state.app();
|
|
532
|
+
try harness.start(app);
|
|
533
|
+
|
|
534
|
+
_ = try harness.runtime.createView(.{
|
|
535
|
+
.window_id = 1,
|
|
536
|
+
.label = "canvas",
|
|
537
|
+
.kind = .gpu_surface,
|
|
538
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
const children = [_]canvas.Widget{
|
|
542
|
+
.{
|
|
543
|
+
.id = 2,
|
|
544
|
+
.kind = .button,
|
|
545
|
+
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
546
|
+
.text = "Run",
|
|
547
|
+
.command = "widget.run",
|
|
548
|
+
},
|
|
549
|
+
.{
|
|
550
|
+
.id = 3,
|
|
551
|
+
.kind = .button,
|
|
552
|
+
.frame = geometry.RectF.init(12, 64, 96, 32),
|
|
553
|
+
.text = "Stop",
|
|
554
|
+
},
|
|
555
|
+
};
|
|
556
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
557
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
558
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
559
|
+
|
|
560
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
561
|
+
.window_id = 1,
|
|
562
|
+
.label = "canvas",
|
|
563
|
+
.kind = .pointer_down,
|
|
564
|
+
.x = 20,
|
|
565
|
+
.y = 28,
|
|
566
|
+
} });
|
|
567
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
568
|
+
|
|
569
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
570
|
+
.window_id = 1,
|
|
571
|
+
.label = "canvas",
|
|
572
|
+
.kind = .pointer_drag,
|
|
573
|
+
.x = 220,
|
|
574
|
+
.y = 28,
|
|
575
|
+
.delta_x = 200,
|
|
576
|
+
} });
|
|
577
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.move, app_state.last_phase);
|
|
578
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_target_id);
|
|
579
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_route_len);
|
|
580
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
581
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
582
|
+
|
|
583
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
584
|
+
.window_id = 1,
|
|
585
|
+
.label = "canvas",
|
|
586
|
+
.kind = .pointer_up,
|
|
587
|
+
.x = 220,
|
|
588
|
+
.y = 28,
|
|
589
|
+
} });
|
|
590
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.up, app_state.last_phase);
|
|
591
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_target_id);
|
|
592
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_route_len);
|
|
593
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
594
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
595
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.command_count);
|
|
596
|
+
|
|
597
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
598
|
+
.window_id = 1,
|
|
599
|
+
.label = "canvas",
|
|
600
|
+
.kind = .pointer_down,
|
|
601
|
+
.x = 20,
|
|
602
|
+
.y = 28,
|
|
603
|
+
} });
|
|
604
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
605
|
+
.window_id = 1,
|
|
606
|
+
.label = "canvas",
|
|
607
|
+
.kind = .pointer_up,
|
|
608
|
+
.x = 20,
|
|
609
|
+
.y = 28,
|
|
610
|
+
} });
|
|
611
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
test "runtime cancels captured canvas widget pointers without activation" {
|
|
615
|
+
const TestApp = struct {
|
|
616
|
+
command_count: u32 = 0,
|
|
617
|
+
raw_input_count: u32 = 0,
|
|
618
|
+
widget_pointer_count: u32 = 0,
|
|
619
|
+
last_phase: canvas.WidgetPointerPhase = .hover,
|
|
620
|
+
last_target_id: canvas.ObjectId = 0,
|
|
621
|
+
last_route_len: usize = 0,
|
|
622
|
+
|
|
623
|
+
fn app(self: *@This()) App {
|
|
624
|
+
return .{ .context = self, .name = "gpu-widget-pointer-cancel", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
628
|
+
_ = runtime;
|
|
629
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
630
|
+
switch (event_value) {
|
|
631
|
+
.command => self.command_count += 1,
|
|
632
|
+
.gpu_surface_input => self.raw_input_count += 1,
|
|
633
|
+
.canvas_widget_pointer => |pointer_event| {
|
|
634
|
+
self.widget_pointer_count += 1;
|
|
635
|
+
self.last_phase = pointer_event.pointer.phase;
|
|
636
|
+
self.last_route_len = pointer_event.route.len;
|
|
637
|
+
self.last_target_id = if (pointer_event.target) |target| target.id else 0;
|
|
638
|
+
},
|
|
639
|
+
else => {},
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
645
|
+
defer harness.destroy(std.testing.allocator);
|
|
646
|
+
harness.null_platform.gpu_surfaces = true;
|
|
647
|
+
var app_state: TestApp = .{};
|
|
648
|
+
const app = app_state.app();
|
|
649
|
+
try harness.start(app);
|
|
650
|
+
|
|
651
|
+
_ = try harness.runtime.createView(.{
|
|
652
|
+
.window_id = 1,
|
|
653
|
+
.label = "canvas",
|
|
654
|
+
.kind = .gpu_surface,
|
|
655
|
+
.frame = geometry.RectF.init(0, 0, 240, 140),
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
const children = [_]canvas.Widget{
|
|
659
|
+
.{
|
|
660
|
+
.id = 2,
|
|
661
|
+
.kind = .button,
|
|
662
|
+
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
663
|
+
.text = "Run",
|
|
664
|
+
.command = "widget.run",
|
|
665
|
+
},
|
|
666
|
+
.{
|
|
667
|
+
.id = 3,
|
|
668
|
+
.kind = .toggle,
|
|
669
|
+
.frame = geometry.RectF.init(12, 64, 96, 32),
|
|
670
|
+
.text = "Live",
|
|
671
|
+
},
|
|
672
|
+
};
|
|
673
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
674
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 140), &nodes);
|
|
675
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
676
|
+
|
|
677
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
678
|
+
.window_id = 1,
|
|
679
|
+
.label = "canvas",
|
|
680
|
+
.kind = .pointer_down,
|
|
681
|
+
.x = 20,
|
|
682
|
+
.y = 28,
|
|
683
|
+
} });
|
|
684
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
685
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
686
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
687
|
+
// A pressed button still shows the native arrow — the cursor channel
|
|
688
|
+
// never leaves arrow for controls, only for links/text/dividers.
|
|
689
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
690
|
+
|
|
691
|
+
harness.runtime.invalidated = false;
|
|
692
|
+
harness.runtime.dirty_region_count = 0;
|
|
693
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
694
|
+
.window_id = 1,
|
|
695
|
+
.label = "canvas",
|
|
696
|
+
.kind = .pointer_cancel,
|
|
697
|
+
.x = 220,
|
|
698
|
+
.y = 28,
|
|
699
|
+
} });
|
|
700
|
+
try std.testing.expectEqual(canvas.WidgetPointerPhase.cancel, app_state.last_phase);
|
|
701
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_target_id);
|
|
702
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_route_len);
|
|
703
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
704
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
705
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
706
|
+
try std.testing.expectEqual(platform.Cursor.arrow, harness.runtime.views[0].canvas_widget_cursor);
|
|
707
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
708
|
+
try std.testing.expect(harness.runtime.pendingDirtyRegions().len > 0);
|
|
709
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.command_count);
|
|
710
|
+
|
|
711
|
+
const cancel_snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
712
|
+
try std.testing.expectEqual(@as(usize, 3), cancel_snapshot.widgets.len);
|
|
713
|
+
try std.testing.expect(cancel_snapshot.widgets[1].focused);
|
|
714
|
+
try std.testing.expect(!cancel_snapshot.widgets[1].hovered);
|
|
715
|
+
try std.testing.expect(!cancel_snapshot.widgets[1].pressed);
|
|
716
|
+
|
|
717
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
718
|
+
.window_id = 1,
|
|
719
|
+
.label = "canvas",
|
|
720
|
+
.kind = .pointer_up,
|
|
721
|
+
.x = 20,
|
|
722
|
+
.y = 28,
|
|
723
|
+
} });
|
|
724
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.command_count);
|
|
725
|
+
|
|
726
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
727
|
+
.window_id = 1,
|
|
728
|
+
.label = "canvas",
|
|
729
|
+
.kind = .pointer_down,
|
|
730
|
+
.x = 20,
|
|
731
|
+
.y = 76,
|
|
732
|
+
} });
|
|
733
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
734
|
+
|
|
735
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
736
|
+
.window_id = 1,
|
|
737
|
+
.label = "canvas",
|
|
738
|
+
.kind = .pointer_cancel,
|
|
739
|
+
.x = 20,
|
|
740
|
+
.y = 76,
|
|
741
|
+
} });
|
|
742
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
743
|
+
.window_id = 1,
|
|
744
|
+
.label = "canvas",
|
|
745
|
+
.kind = .pointer_up,
|
|
746
|
+
.x = 20,
|
|
747
|
+
.y = 76,
|
|
748
|
+
} });
|
|
749
|
+
|
|
750
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
751
|
+
try std.testing.expect(!retained.findById(3).?.widget.state.selected);
|
|
752
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(3).?.widget.value);
|
|
753
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_pressed_id);
|
|
754
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.command_count);
|
|
755
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.widget_pointer_count);
|
|
756
|
+
try std.testing.expectEqual(@as(u32, 6), app_state.raw_input_count);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
test "runtime applies GPU text and IME input to focused canvas text fields" {
|
|
760
|
+
const TestApp = struct {
|
|
761
|
+
widget_keyboard_count: u32 = 0,
|
|
762
|
+
last_keyboard_phase: canvas.WidgetKeyboardPhase = .key_up,
|
|
763
|
+
last_keyboard_target_id: canvas.ObjectId = 0,
|
|
764
|
+
|
|
765
|
+
fn app(self: *@This()) App {
|
|
766
|
+
return .{ .context = self, .name = "gpu-widget-mobile-text-ime", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
770
|
+
_ = runtime;
|
|
771
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
772
|
+
switch (event_value) {
|
|
773
|
+
.canvas_widget_keyboard => |keyboard_event| {
|
|
774
|
+
self.widget_keyboard_count += 1;
|
|
775
|
+
self.last_keyboard_phase = keyboard_event.keyboard.phase;
|
|
776
|
+
if (keyboard_event.target) |target| self.last_keyboard_target_id = target.id;
|
|
777
|
+
},
|
|
778
|
+
else => {},
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
784
|
+
defer harness.destroy(std.testing.allocator);
|
|
785
|
+
harness.null_platform.gpu_surfaces = true;
|
|
786
|
+
var app_state: TestApp = .{};
|
|
787
|
+
const app = app_state.app();
|
|
788
|
+
try harness.start(app);
|
|
789
|
+
|
|
790
|
+
_ = try harness.runtime.createView(.{
|
|
791
|
+
.window_id = 1,
|
|
792
|
+
.label = "canvas",
|
|
793
|
+
.kind = .gpu_surface,
|
|
794
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
const children = [_]canvas.Widget{
|
|
798
|
+
.{
|
|
799
|
+
.id = 2,
|
|
800
|
+
.kind = .text_field,
|
|
801
|
+
.frame = geometry.RectF.init(10, 10, 160, 32),
|
|
802
|
+
.text = "hello",
|
|
803
|
+
.text_selection = canvas.TextSelection{ .anchor = 1, .focus = 4 },
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
807
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
808
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
809
|
+
harness.runtime.views[0].focused = true;
|
|
810
|
+
harness.runtime.views[0].canvas_widget_focused_id = 2;
|
|
811
|
+
|
|
812
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
813
|
+
.window_id = 1,
|
|
814
|
+
.label = "canvas",
|
|
815
|
+
.kind = .text_input,
|
|
816
|
+
.text = "a",
|
|
817
|
+
} });
|
|
818
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
819
|
+
var field = retained.findById(2).?.widget;
|
|
820
|
+
try std.testing.expectEqualStrings("hao", field.text);
|
|
821
|
+
try std.testing.expectEqual(@as(usize, 2), field.text_selection.?.focus);
|
|
822
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_keyboard_count);
|
|
823
|
+
try std.testing.expectEqual(canvas.WidgetKeyboardPhase.text_input, app_state.last_keyboard_phase);
|
|
824
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
825
|
+
|
|
826
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
827
|
+
.window_id = 1,
|
|
828
|
+
.label = "canvas",
|
|
829
|
+
.kind = .ime_set_composition,
|
|
830
|
+
.text = "é",
|
|
831
|
+
.composition_cursor = 2,
|
|
832
|
+
} });
|
|
833
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
834
|
+
field = retained.findById(2).?.widget;
|
|
835
|
+
try std.testing.expectEqualStrings("haéo", field.text);
|
|
836
|
+
try std.testing.expect(field.text_composition != null);
|
|
837
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_keyboard_count);
|
|
838
|
+
|
|
839
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
840
|
+
.window_id = 1,
|
|
841
|
+
.label = "canvas",
|
|
842
|
+
.kind = .ime_commit_composition,
|
|
843
|
+
} });
|
|
844
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
845
|
+
field = retained.findById(2).?.widget;
|
|
846
|
+
try std.testing.expectEqualStrings("haéo", field.text);
|
|
847
|
+
try std.testing.expect(field.text_composition == null);
|
|
848
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.widget_keyboard_count);
|
|
849
|
+
|
|
850
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
851
|
+
.window_id = 1,
|
|
852
|
+
.label = "canvas",
|
|
853
|
+
.kind = .ime_set_composition,
|
|
854
|
+
.text = "ll",
|
|
855
|
+
.composition_cursor = 2,
|
|
856
|
+
} });
|
|
857
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
858
|
+
.window_id = 1,
|
|
859
|
+
.label = "canvas",
|
|
860
|
+
.kind = .ime_cancel_composition,
|
|
861
|
+
} });
|
|
862
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
863
|
+
field = retained.findById(2).?.widget;
|
|
864
|
+
try std.testing.expectEqualStrings("haéo", field.text);
|
|
865
|
+
try std.testing.expect(field.text_composition == null);
|
|
866
|
+
try std.testing.expectEqual(@as(u32, 5), app_state.widget_keyboard_count);
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
test "runtime dispatches opted-in canvas widget drag events" {
|
|
870
|
+
const TestApp = struct {
|
|
871
|
+
raw_input_count: u32 = 0,
|
|
872
|
+
widget_pointer_count: u32 = 0,
|
|
873
|
+
widget_drag_count: u32 = 0,
|
|
874
|
+
last_drag_source_id: canvas.ObjectId = 0,
|
|
875
|
+
last_drag_route_len: usize = 0,
|
|
876
|
+
last_drag_x: f32 = 0,
|
|
877
|
+
last_drag_dx: f32 = 0,
|
|
878
|
+
|
|
879
|
+
fn app(self: *@This()) App {
|
|
880
|
+
return .{ .context = self, .name = "gpu-widget-drag", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
884
|
+
_ = runtime;
|
|
885
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
886
|
+
switch (event_value) {
|
|
887
|
+
.gpu_surface_input => self.raw_input_count += 1,
|
|
888
|
+
.canvas_widget_pointer => self.widget_pointer_count += 1,
|
|
889
|
+
.canvas_widget_drag => |drag_event| {
|
|
890
|
+
self.widget_drag_count += 1;
|
|
891
|
+
self.last_drag_source_id = if (drag_event.source) |source| source.id else 0;
|
|
892
|
+
self.last_drag_route_len = drag_event.route.len;
|
|
893
|
+
self.last_drag_x = drag_event.drag.point.x;
|
|
894
|
+
self.last_drag_dx = drag_event.drag.delta.dx;
|
|
895
|
+
},
|
|
896
|
+
else => {},
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
|
|
901
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
902
|
+
defer harness.destroy(std.testing.allocator);
|
|
903
|
+
harness.null_platform.gpu_surfaces = true;
|
|
904
|
+
var app_state: TestApp = .{};
|
|
905
|
+
const app = app_state.app();
|
|
906
|
+
try harness.start(app);
|
|
907
|
+
|
|
908
|
+
_ = try harness.runtime.createView(.{
|
|
909
|
+
.window_id = 1,
|
|
910
|
+
.label = "canvas",
|
|
911
|
+
.kind = .gpu_surface,
|
|
912
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
913
|
+
});
|
|
914
|
+
|
|
915
|
+
const children = [_]canvas.Widget{
|
|
916
|
+
.{
|
|
917
|
+
.id = 2,
|
|
918
|
+
.kind = .button,
|
|
919
|
+
.frame = geometry.RectF.init(12, 16, 96, 32),
|
|
920
|
+
.text = "Drag",
|
|
921
|
+
.semantics = .{ .actions = .{ .drag = true } },
|
|
922
|
+
},
|
|
923
|
+
.{
|
|
924
|
+
.id = 3,
|
|
925
|
+
.kind = .button,
|
|
926
|
+
.frame = geometry.RectF.init(12, 58, 96, 32),
|
|
927
|
+
.text = "Plain",
|
|
928
|
+
},
|
|
929
|
+
};
|
|
930
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
931
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
932
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
933
|
+
|
|
934
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
935
|
+
.window_id = 1,
|
|
936
|
+
.label = "canvas",
|
|
937
|
+
.kind = .pointer_drag,
|
|
938
|
+
.x = 44,
|
|
939
|
+
.y = 28,
|
|
940
|
+
.delta_x = 12,
|
|
941
|
+
} });
|
|
942
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_drag_count);
|
|
943
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_pointer_count);
|
|
944
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.raw_input_count);
|
|
945
|
+
|
|
946
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
947
|
+
.window_id = 1,
|
|
948
|
+
.label = "canvas",
|
|
949
|
+
.kind = .pointer_down,
|
|
950
|
+
.x = 20,
|
|
951
|
+
.y = 28,
|
|
952
|
+
} });
|
|
953
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
954
|
+
.window_id = 1,
|
|
955
|
+
.label = "canvas",
|
|
956
|
+
.kind = .pointer_drag,
|
|
957
|
+
.x = 64,
|
|
958
|
+
.y = 30,
|
|
959
|
+
.delta_x = 44,
|
|
960
|
+
} });
|
|
961
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
962
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.widget_pointer_count);
|
|
963
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.raw_input_count);
|
|
964
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
965
|
+
try std.testing.expectEqual(@as(usize, 3), app_state.last_drag_route_len);
|
|
966
|
+
try std.testing.expectEqual(@as(f32, 64), app_state.last_drag_x);
|
|
967
|
+
try std.testing.expectEqual(@as(f32, 44), app_state.last_drag_dx);
|
|
968
|
+
|
|
969
|
+
const snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
970
|
+
try std.testing.expect(snapshot.widgets[1].actions.drag);
|
|
971
|
+
try std.testing.expect(!snapshot.widgets[2].actions.drag);
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
test "runtime resizes retained canvas resizable widgets from pointer drag" {
|
|
975
|
+
const TestApp = struct {
|
|
976
|
+
fn app(self: *@This()) App {
|
|
977
|
+
return .{ .context = self, .name = "gpu-widget-resizable-drag", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
982
|
+
defer harness.destroy(std.testing.allocator);
|
|
983
|
+
harness.null_platform.gpu_surfaces = true;
|
|
984
|
+
var app_state: TestApp = .{};
|
|
985
|
+
const app = app_state.app();
|
|
986
|
+
try harness.start(app);
|
|
987
|
+
|
|
988
|
+
_ = try harness.runtime.createView(.{
|
|
989
|
+
.window_id = 1,
|
|
990
|
+
.label = "canvas",
|
|
991
|
+
.kind = .gpu_surface,
|
|
992
|
+
.frame = geometry.RectF.init(0, 0, 260, 120),
|
|
993
|
+
});
|
|
994
|
+
|
|
995
|
+
const resizable = canvas.Widget{
|
|
996
|
+
.id = 2,
|
|
997
|
+
.kind = .resizable,
|
|
998
|
+
.frame = geometry.RectF.init(10, 16, 120, 44),
|
|
999
|
+
.text = "Resizable",
|
|
1000
|
+
.semantics = .{ .label = "Resizable panel" },
|
|
1001
|
+
};
|
|
1002
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
1003
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .stack, .children = &.{resizable} }, geometry.RectF.init(0, 0, 260, 120), &nodes);
|
|
1004
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1005
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
1006
|
+
|
|
1007
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1008
|
+
.window_id = 1,
|
|
1009
|
+
.label = "canvas",
|
|
1010
|
+
.kind = .pointer_down,
|
|
1011
|
+
.x = 126,
|
|
1012
|
+
.y = 38,
|
|
1013
|
+
} });
|
|
1014
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1015
|
+
.window_id = 1,
|
|
1016
|
+
.label = "canvas",
|
|
1017
|
+
.kind = .pointer_drag,
|
|
1018
|
+
.x = 156,
|
|
1019
|
+
.y = 38,
|
|
1020
|
+
.delta_x = 30,
|
|
1021
|
+
} });
|
|
1022
|
+
|
|
1023
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1024
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 16, 150, 44), retained.findById(2).?.frame);
|
|
1025
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 16, 150, 44), retained.findById(2).?.widget.frame);
|
|
1026
|
+
|
|
1027
|
+
var display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1028
|
+
switch (display_list.findCommandById(testCanvasWidgetPartId(2, 5)).?.command) {
|
|
1029
|
+
.draw_line => |line| try std.testing.expect(line.from.x > 152),
|
|
1030
|
+
else => return error.TestUnexpectedResult,
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1034
|
+
.window_id = 1,
|
|
1035
|
+
.label = "canvas",
|
|
1036
|
+
.kind = .pointer_drag,
|
|
1037
|
+
.x = 10,
|
|
1038
|
+
.y = 38,
|
|
1039
|
+
.delta_x = -200,
|
|
1040
|
+
} });
|
|
1041
|
+
|
|
1042
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1043
|
+
try std.testing.expectEqual(@as(f32, 48), retained.findById(2).?.frame.width);
|
|
1044
|
+
|
|
1045
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1046
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1047
|
+
try std.testing.expectEqual(@as(f32, 48), retained.findById(2).?.frame.width);
|
|
1048
|
+
try std.testing.expectEqual(@as(f32, 48), retained.findById(2).?.widget.frame.width);
|
|
1049
|
+
|
|
1050
|
+
display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1051
|
+
switch (display_list.findCommandById(testCanvasWidgetPartId(2, 5)).?.command) {
|
|
1052
|
+
.draw_line => |line| try std.testing.expect(line.from.x < 56),
|
|
1053
|
+
else => return error.TestUnexpectedResult,
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
test "runtime dispatches automation canvas widget actions" {
|
|
1058
|
+
const TestApp = struct {
|
|
1059
|
+
command_count: u32 = 0,
|
|
1060
|
+
widget_keyboard_count: u32 = 0,
|
|
1061
|
+
widget_drag_count: u32 = 0,
|
|
1062
|
+
widget_file_drop_count: u32 = 0,
|
|
1063
|
+
file_drop_count: u32 = 0,
|
|
1064
|
+
raw_input_count: u32 = 0,
|
|
1065
|
+
last_command: []const u8 = "",
|
|
1066
|
+
last_keyboard_target_id: canvas.ObjectId = 0,
|
|
1067
|
+
last_keyboard_key: []const u8 = "",
|
|
1068
|
+
last_drag_source_id: canvas.ObjectId = 0,
|
|
1069
|
+
last_drag_dx: f32 = 0,
|
|
1070
|
+
last_drop_target_id: canvas.ObjectId = 0,
|
|
1071
|
+
last_drop_path_count: usize = 0,
|
|
1072
|
+
last_drop_first_path: []const u8 = "",
|
|
1073
|
+
|
|
1074
|
+
fn app(self: *@This()) App {
|
|
1075
|
+
return .{ .context = self, .name = "gpu-widget-automation-actions", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
1079
|
+
_ = runtime;
|
|
1080
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
1081
|
+
switch (event_value) {
|
|
1082
|
+
.command => |command| {
|
|
1083
|
+
self.command_count += 1;
|
|
1084
|
+
self.last_command = command.name;
|
|
1085
|
+
},
|
|
1086
|
+
.gpu_surface_input => self.raw_input_count += 1,
|
|
1087
|
+
.canvas_widget_keyboard => |keyboard_event| {
|
|
1088
|
+
self.widget_keyboard_count += 1;
|
|
1089
|
+
if (keyboard_event.target) |target| self.last_keyboard_target_id = target.id;
|
|
1090
|
+
self.last_keyboard_key = keyboard_event.keyboard.key;
|
|
1091
|
+
},
|
|
1092
|
+
.canvas_widget_drag => |drag_event| {
|
|
1093
|
+
self.widget_drag_count += 1;
|
|
1094
|
+
if (drag_event.source) |source| self.last_drag_source_id = source.id;
|
|
1095
|
+
self.last_drag_dx = drag_event.drag.delta.dx;
|
|
1096
|
+
},
|
|
1097
|
+
.canvas_widget_file_drop => |drop_event| {
|
|
1098
|
+
self.widget_file_drop_count += 1;
|
|
1099
|
+
if (drop_event.target) |target| self.last_drop_target_id = target.id;
|
|
1100
|
+
self.last_drop_path_count = drop_event.drop.paths.len;
|
|
1101
|
+
self.last_drop_first_path = if (drop_event.drop.paths.len > 0) drop_event.drop.paths[0] else "";
|
|
1102
|
+
},
|
|
1103
|
+
.files_dropped => self.file_drop_count += 1,
|
|
1104
|
+
else => {},
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1110
|
+
defer harness.destroy(std.testing.allocator);
|
|
1111
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1112
|
+
var app_state: TestApp = .{};
|
|
1113
|
+
const app = app_state.app();
|
|
1114
|
+
try harness.start(app);
|
|
1115
|
+
|
|
1116
|
+
_ = try harness.runtime.createView(.{
|
|
1117
|
+
.window_id = 1,
|
|
1118
|
+
.label = "canvas",
|
|
1119
|
+
.kind = .gpu_surface,
|
|
1120
|
+
.frame = geometry.RectF.init(0, 0, 320, 180),
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
const scroll_items = [_]canvas.Widget{
|
|
1124
|
+
.{ .id = 8, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Row one" },
|
|
1125
|
+
.{ .id = 9, .kind = .button, .frame = geometry.RectF.init(0, 64, 0, 32), .text = "Row two" },
|
|
1126
|
+
.{ .id = 10, .kind = .button, .frame = geometry.RectF.init(0, 128, 0, 32), .text = "Row three" },
|
|
1127
|
+
};
|
|
1128
|
+
const children = [_]canvas.Widget{
|
|
1129
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 10, 96, 32), .text = "Run", .command = "widget.run", .semantics = .{ .actions = .{ .drag = true } } },
|
|
1130
|
+
.{ .id = 3, .kind = .checkbox, .frame = geometry.RectF.init(10, 52, 96, 28), .text = "Enabled" },
|
|
1131
|
+
.{ .id = 4, .kind = .slider, .frame = geometry.RectF.init(10, 88, 120, 24), .value = 0.5, .semantics = .{ .label = "Amount" } },
|
|
1132
|
+
.{ .id = 5, .kind = .text_field, .frame = geometry.RectF.init(10, 122, 150, 32), .text = "Draft" },
|
|
1133
|
+
.{ .id = 6, .kind = .list_item, .frame = geometry.RectF.init(170, 10, 120, 32), .text = "Inbox" },
|
|
1134
|
+
.{ .id = 7, .kind = .scroll_view, .frame = geometry.RectF.init(170, 52, 120, 48), .children = &scroll_items },
|
|
1135
|
+
.{ .id = 11, .kind = .button, .frame = geometry.RectF.init(170, 110, 120, 32), .text = "Upload", .semantics = .{ .actions = .{ .drop_files = true } } },
|
|
1136
|
+
.{ .id = 12, .kind = .menu_item, .frame = geometry.RectF.init(170, 146, 120, 28), .text = "Archive" },
|
|
1137
|
+
};
|
|
1138
|
+
var nodes: [13]canvas.WidgetLayoutNode = undefined;
|
|
1139
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
1140
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1141
|
+
|
|
1142
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .press });
|
|
1143
|
+
try std.testing.expect(harness.runtime.views[0].gpu_input_timestamp_ns > 0);
|
|
1144
|
+
try std.testing.expect(harness.runtime.views[0].gpu_pending_input_timestamp_ns > 0);
|
|
1145
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
1146
|
+
try std.testing.expectEqualStrings("widget.run", app_state.last_command);
|
|
1147
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1148
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
1149
|
+
|
|
1150
|
+
// The accessibility press rides the SAME key-driven activation the
|
|
1151
|
+
// automation press verb uses: the app hears the enter key on the
|
|
1152
|
+
// target and the widget's command dispatches through the real
|
|
1153
|
+
// activation path. A direct-command shortcut here would skip the
|
|
1154
|
+
// keyboard channel, and any widget wired through message handlers
|
|
1155
|
+
// instead of a command string would report success while actuating
|
|
1156
|
+
// nothing.
|
|
1157
|
+
const keyboard_count_before_ax_press = app_state.widget_keyboard_count;
|
|
1158
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .press });
|
|
1159
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.command_count);
|
|
1160
|
+
try std.testing.expectEqualStrings("widget.run", app_state.last_command);
|
|
1161
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1162
|
+
try std.testing.expectEqual(keyboard_count_before_ax_press + 1, app_state.widget_keyboard_count);
|
|
1163
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
1164
|
+
try std.testing.expectEqualStrings("enter", app_state.last_keyboard_key);
|
|
1165
|
+
|
|
1166
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .drag, .value = "18 2" });
|
|
1167
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
1168
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
1169
|
+
try std.testing.expectEqual(@as(f32, 18), app_state.last_drag_dx);
|
|
1170
|
+
|
|
1171
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .drag, .text = "8 1" });
|
|
1172
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_drag_count);
|
|
1173
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
1174
|
+
try std.testing.expectEqual(@as(f32, 8), app_state.last_drag_dx);
|
|
1175
|
+
|
|
1176
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .widget_accessibility_action = .{
|
|
1177
|
+
.window_id = 1,
|
|
1178
|
+
.label = "canvas",
|
|
1179
|
+
.id = 2,
|
|
1180
|
+
.action = .drag,
|
|
1181
|
+
} });
|
|
1182
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.widget_drag_count);
|
|
1183
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_drag_source_id);
|
|
1184
|
+
try std.testing.expectEqual(@as(f32, 16), app_state.last_drag_dx);
|
|
1185
|
+
|
|
1186
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .toggle });
|
|
1187
|
+
try std.testing.expectEqual(@as(?f32, 1), runtimeViewWidgetSemantics(&harness.runtime.views[0])[2].value);
|
|
1188
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .drag }));
|
|
1189
|
+
|
|
1190
|
+
// The accessibility toggle is the same space-key toggle: the
|
|
1191
|
+
// retained value flips back AND the app hears the key — an
|
|
1192
|
+
// echo-only flip would leave the model behind and revert on the
|
|
1193
|
+
// next rebuild.
|
|
1194
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 3, .action = .toggle });
|
|
1195
|
+
try std.testing.expectEqual(@as(?f32, 0), runtimeViewWidgetSemantics(&harness.runtime.views[0])[2].value);
|
|
1196
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_keyboard_target_id);
|
|
1197
|
+
try std.testing.expectEqualStrings("space", app_state.last_keyboard_key);
|
|
1198
|
+
|
|
1199
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 4, .action = .increment });
|
|
1200
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.55), runtimeViewWidgetSemantics(&harness.runtime.views[0])[3].value.?, 0.001);
|
|
1201
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 4), app_state.last_keyboard_target_id);
|
|
1202
|
+
try std.testing.expectEqualStrings("arrowright", app_state.last_keyboard_key);
|
|
1203
|
+
|
|
1204
|
+
// The accessibility increment on a slider is the same arrow step
|
|
1205
|
+
// the automation verb dispatches: value moves through the keyboard
|
|
1206
|
+
// intent and the app hears the arrow key on the slider.
|
|
1207
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 4, .action = .increment });
|
|
1208
|
+
try std.testing.expectApproxEqAbs(@as(f32, 0.6), runtimeViewWidgetSemantics(&harness.runtime.views[0])[3].value.?, 0.001);
|
|
1209
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 4), app_state.last_keyboard_target_id);
|
|
1210
|
+
try std.testing.expectEqualStrings("arrowright", app_state.last_keyboard_key);
|
|
1211
|
+
|
|
1212
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 6, .action = .select });
|
|
1213
|
+
try std.testing.expectEqual(@as(?f32, 1), runtimeViewWidgetSemantics(&harness.runtime.views[0])[5].value);
|
|
1214
|
+
|
|
1215
|
+
// A lone menu item in an ACTIONS group (no sibling declares a
|
|
1216
|
+
// committed row): the select action focuses it but mints no
|
|
1217
|
+
// selection — only picker groups with a declared committed row
|
|
1218
|
+
// move one.
|
|
1219
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 12, .action = .select });
|
|
1220
|
+
const selected_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1221
|
+
try std.testing.expect(!selected_layout.findById(12).?.widget.state.selected);
|
|
1222
|
+
try std.testing.expectEqual(@as(f32, 0), selected_layout.findById(12).?.widget.value);
|
|
1223
|
+
|
|
1224
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 7, .action = .increment });
|
|
1225
|
+
var scrolled_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1226
|
+
try std.testing.expectApproxEqAbs(@as(f32, 40.8), scrolled_layout.findById(7).?.widget.value, 0.001);
|
|
1227
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), app_state.last_keyboard_target_id);
|
|
1228
|
+
try std.testing.expectEqualStrings("pagedown", app_state.last_keyboard_key);
|
|
1229
|
+
|
|
1230
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 7, .action = .decrement });
|
|
1231
|
+
scrolled_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1232
|
+
try std.testing.expectEqual(@as(f32, 0.0), scrolled_layout.findById(7).?.widget.value);
|
|
1233
|
+
try std.testing.expectEqualStrings("pageup", app_state.last_keyboard_key);
|
|
1234
|
+
|
|
1235
|
+
// AX scroll steps ride the page keys the automation verbs use, so
|
|
1236
|
+
// the app's keyboard channel hears them like any live page scroll.
|
|
1237
|
+
const keyboard_count_before_ax_scroll = app_state.widget_keyboard_count;
|
|
1238
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 7, .action = .increment });
|
|
1239
|
+
scrolled_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1240
|
+
try std.testing.expectApproxEqAbs(@as(f32, 40.8), scrolled_layout.findById(7).?.widget.value, 0.001);
|
|
1241
|
+
try std.testing.expectEqual(keyboard_count_before_ax_scroll + 1, app_state.widget_keyboard_count);
|
|
1242
|
+
try std.testing.expectEqualStrings("pagedown", app_state.last_keyboard_key);
|
|
1243
|
+
|
|
1244
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 7, .action = .decrement });
|
|
1245
|
+
scrolled_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1246
|
+
try std.testing.expectEqual(@as(f32, 0.0), scrolled_layout.findById(7).?.widget.value);
|
|
1247
|
+
try std.testing.expectEqual(keyboard_count_before_ax_scroll + 2, app_state.widget_keyboard_count);
|
|
1248
|
+
try std.testing.expectEqualStrings("pageup", app_state.last_keyboard_key);
|
|
1249
|
+
|
|
1250
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 11, .action = .drop_files, .value = "/tmp/report.csv /tmp/chart.png" });
|
|
1251
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_file_drop_count);
|
|
1252
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.file_drop_count);
|
|
1253
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 11), app_state.last_drop_target_id);
|
|
1254
|
+
try std.testing.expectEqual(@as(usize, 2), app_state.last_drop_path_count);
|
|
1255
|
+
try std.testing.expectEqualStrings("/tmp/report.csv", app_state.last_drop_first_path);
|
|
1256
|
+
try std.testing.expectEqualStrings("drop:files", harness.null_platform.lastWindowEventName());
|
|
1257
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastWindowEventDetail(), "\"paths\":[\"/tmp/report.csv\",\"/tmp/chart.png\"]") != null);
|
|
1258
|
+
|
|
1259
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 11, .action = .drop_files, .text = "/tmp/accessibility.csv" });
|
|
1260
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_file_drop_count);
|
|
1261
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.file_drop_count);
|
|
1262
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 11), app_state.last_drop_target_id);
|
|
1263
|
+
try std.testing.expectEqual(@as(usize, 1), app_state.last_drop_path_count);
|
|
1264
|
+
try std.testing.expectEqualStrings("/tmp/accessibility.csv", app_state.last_drop_first_path);
|
|
1265
|
+
try std.testing.expect(std.mem.indexOf(u8, harness.null_platform.lastWindowEventDetail(), "\"paths\":[\"/tmp/accessibility.csv\"]") != null);
|
|
1266
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 11, .action = .drop_files }));
|
|
1267
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 11, .action = .drop_files }));
|
|
1268
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .drop_files, .value = "/tmp/report.csv" }));
|
|
1269
|
+
|
|
1270
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .set_text, .value = "Hello world" });
|
|
1271
|
+
try std.testing.expectEqualStrings("Hello world", runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].label);
|
|
1272
|
+
|
|
1273
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .set_composition, .value = "!" });
|
|
1274
|
+
try std.testing.expectEqualStrings("Hello world!", runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_value);
|
|
1275
|
+
try std.testing.expectEqualDeep(canvas.TextRange.init(11, 12), runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_composition.?);
|
|
1276
|
+
|
|
1277
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .commit_composition });
|
|
1278
|
+
try std.testing.expectEqualStrings("Hello world!", runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_value);
|
|
1279
|
+
try std.testing.expect(runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_composition == null);
|
|
1280
|
+
|
|
1281
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .set_composition, .value = " draft" });
|
|
1282
|
+
try std.testing.expectEqualStrings("Hello world! draft", runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_value);
|
|
1283
|
+
try std.testing.expectEqualDeep(canvas.TextRange.init(12, 18), runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_composition.?);
|
|
1284
|
+
|
|
1285
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .cancel_composition });
|
|
1286
|
+
try std.testing.expectEqualStrings("Hello world!", runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_value);
|
|
1287
|
+
try std.testing.expect(runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_composition == null);
|
|
1288
|
+
|
|
1289
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .set_selection, .value = "0 5" });
|
|
1290
|
+
try std.testing.expectEqualDeep(canvas.TextRange.init(0, 5), runtimeViewWidgetSemantics(&harness.runtime.views[0])[4].text_selection.?);
|
|
1291
|
+
const selection_snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1292
|
+
try std.testing.expect(selection_snapshot.widgets[4].actions.set_selection);
|
|
1293
|
+
try std.testing.expectEqualDeep(automation.snapshot.TextRange{ .start = 0, .end = 5 }, selection_snapshot.widgets[4].text_selection.?);
|
|
1294
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 5, .action = .set_selection, .value = "nope" }));
|
|
1295
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .set_selection, .value = "0 1" }));
|
|
1296
|
+
|
|
1297
|
+
try std.testing.expect(app_state.widget_keyboard_count >= 3);
|
|
1298
|
+
try std.testing.expect(app_state.raw_input_count >= 3);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
test "accessibility press actuates widgets wired through message handlers" {
|
|
1302
|
+
// The defect this pins: a widget whose press wiring is a bound
|
|
1303
|
+
// message handler (no `command` string — every markup `on-press`
|
|
1304
|
+
// and Zig-builder `on_press` widget) published `press` to the
|
|
1305
|
+
// platform accessibility tree, and performing it reported success
|
|
1306
|
+
// while dispatching nothing the app could hear. The honest route is
|
|
1307
|
+
// the key-driven activation the automation press verb uses: the app
|
|
1308
|
+
// receives the enter key ON the target, so the same typed dispatch
|
|
1309
|
+
// a keyboard user's activation reaches fires the handler.
|
|
1310
|
+
const TestApp = struct {
|
|
1311
|
+
widget_keyboard_count: u32 = 0,
|
|
1312
|
+
last_keyboard_target_id: canvas.ObjectId = 0,
|
|
1313
|
+
last_keyboard_key: []const u8 = "",
|
|
1314
|
+
|
|
1315
|
+
fn app(self: *@This()) App {
|
|
1316
|
+
return .{ .context = self, .name = "gpu-widget-ax-press-handlers", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
1320
|
+
_ = runtime;
|
|
1321
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
1322
|
+
switch (event_value) {
|
|
1323
|
+
.canvas_widget_keyboard => |keyboard_event| {
|
|
1324
|
+
self.widget_keyboard_count += 1;
|
|
1325
|
+
if (keyboard_event.target) |target| self.last_keyboard_target_id = target.id;
|
|
1326
|
+
self.last_keyboard_key = keyboard_event.keyboard.key;
|
|
1327
|
+
},
|
|
1328
|
+
else => {},
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
|
|
1333
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1334
|
+
defer harness.destroy(std.testing.allocator);
|
|
1335
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1336
|
+
var app_state: TestApp = .{};
|
|
1337
|
+
const app = app_state.app();
|
|
1338
|
+
try harness.start(app);
|
|
1339
|
+
|
|
1340
|
+
_ = try harness.runtime.createView(.{
|
|
1341
|
+
.window_id = 1,
|
|
1342
|
+
.label = "canvas",
|
|
1343
|
+
.kind = .gpu_surface,
|
|
1344
|
+
.frame = geometry.RectF.init(0, 0, 320, 180),
|
|
1345
|
+
});
|
|
1346
|
+
|
|
1347
|
+
const children = [_]canvas.Widget{
|
|
1348
|
+
// A commandless button: the segmented-switcher shape (a tab
|
|
1349
|
+
// that binds on_press and nothing else).
|
|
1350
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 10, 96, 32), .text = "Songs" },
|
|
1351
|
+
// A plain list row with a bound press (the album-card shape):
|
|
1352
|
+
// quiet focus makes plain rows transparent to keys, so the
|
|
1353
|
+
// dispatch must escalate this target to the ring register or
|
|
1354
|
+
// the synthesized enter routes as a target-less event.
|
|
1355
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(10, 52, 200, 40), .text = "Exit Signs", .semantics = .{ .actions = .{ .press = true } } },
|
|
1356
|
+
// No press wiring at all: the runtime must refuse, never
|
|
1357
|
+
// succeed-and-do-nothing.
|
|
1358
|
+
.{ .id = 4, .kind = .text, .frame = geometry.RectF.init(10, 104, 96, 20), .text = "8 of 8" },
|
|
1359
|
+
};
|
|
1360
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1361
|
+
const layout = try canvas.layoutWidgetTree(.{ .id = 1, .kind = .panel, .children = &children }, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
1362
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1363
|
+
|
|
1364
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .press });
|
|
1365
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_keyboard_count);
|
|
1366
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), app_state.last_keyboard_target_id);
|
|
1367
|
+
try std.testing.expectEqualStrings("enter", app_state.last_keyboard_key);
|
|
1368
|
+
|
|
1369
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 3, .action = .press });
|
|
1370
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_keyboard_count);
|
|
1371
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_keyboard_target_id);
|
|
1372
|
+
try std.testing.expectEqualStrings("enter", app_state.last_keyboard_key);
|
|
1373
|
+
// The escalation is observable: the row now holds the ring
|
|
1374
|
+
// register, exactly what a Tab-then-Enter would have left.
|
|
1375
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
1376
|
+
|
|
1377
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 4, .action = .press }));
|
|
1378
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.widget_keyboard_count);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
test "runtime rejects automation canvas widget actions for scroll clipped targets" {
|
|
1382
|
+
const TestApp = struct {
|
|
1383
|
+
widget_drag_count: u32 = 0,
|
|
1384
|
+
widget_file_drop_count: u32 = 0,
|
|
1385
|
+
file_drop_count: u32 = 0,
|
|
1386
|
+
raw_input_count: u32 = 0,
|
|
1387
|
+
last_drag_source_id: canvas.ObjectId = 0,
|
|
1388
|
+
last_drop_target_id: canvas.ObjectId = 0,
|
|
1389
|
+
|
|
1390
|
+
fn app(self: *@This()) App {
|
|
1391
|
+
return .{ .context = self, .name = "gpu-widget-clipped-automation-actions", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
1395
|
+
_ = runtime;
|
|
1396
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
1397
|
+
switch (event_value) {
|
|
1398
|
+
.gpu_surface_input => self.raw_input_count += 1,
|
|
1399
|
+
.canvas_widget_drag => |drag_event| {
|
|
1400
|
+
self.widget_drag_count += 1;
|
|
1401
|
+
if (drag_event.source) |source| self.last_drag_source_id = source.id;
|
|
1402
|
+
},
|
|
1403
|
+
.canvas_widget_file_drop => |drop_event| {
|
|
1404
|
+
self.widget_file_drop_count += 1;
|
|
1405
|
+
if (drop_event.target) |target| self.last_drop_target_id = target.id;
|
|
1406
|
+
},
|
|
1407
|
+
.files_dropped => self.file_drop_count += 1,
|
|
1408
|
+
else => {},
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1414
|
+
defer harness.destroy(std.testing.allocator);
|
|
1415
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1416
|
+
var app_state: TestApp = .{};
|
|
1417
|
+
const app = app_state.app();
|
|
1418
|
+
try harness.start(app);
|
|
1419
|
+
|
|
1420
|
+
_ = try harness.runtime.createView(.{
|
|
1421
|
+
.window_id = 1,
|
|
1422
|
+
.label = "canvas",
|
|
1423
|
+
.kind = .gpu_surface,
|
|
1424
|
+
.frame = geometry.RectF.init(0, 0, 160, 48),
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
const selectable_children = [_]canvas.Widget{
|
|
1428
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Hidden" },
|
|
1429
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Visible" },
|
|
1430
|
+
};
|
|
1431
|
+
var selectable_nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
1432
|
+
const selectable_layout = try canvas.layoutWidgetTree(
|
|
1433
|
+
.{ .id = 1, .kind = .scroll_view, .value = 40, .children = &selectable_children },
|
|
1434
|
+
geometry.RectF.init(0, 0, 160, 48),
|
|
1435
|
+
&selectable_nodes,
|
|
1436
|
+
);
|
|
1437
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", selectable_layout);
|
|
1438
|
+
|
|
1439
|
+
var snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1440
|
+
try std.testing.expect(snapshot.widgets[1].actions.select);
|
|
1441
|
+
try std.testing.expect(snapshot.widgets[2].actions.select);
|
|
1442
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -32, 160, 32), snapshot.widgets[1].bounds);
|
|
1443
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, 16, 160, 32), snapshot.widgets[2].bounds);
|
|
1444
|
+
|
|
1445
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .select }));
|
|
1446
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1447
|
+
try std.testing.expect(!retained.findById(2).?.widget.state.selected);
|
|
1448
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(2).?.widget.value);
|
|
1449
|
+
|
|
1450
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .select });
|
|
1451
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1452
|
+
try std.testing.expect(retained.findById(3).?.widget.state.selected);
|
|
1453
|
+
try std.testing.expectEqual(@as(f32, 1), retained.findById(3).?.widget.value);
|
|
1454
|
+
|
|
1455
|
+
const drag_children = [_]canvas.Widget{
|
|
1456
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Hidden drag", .semantics = .{ .actions = .{ .drag = true } } },
|
|
1457
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Visible drag", .semantics = .{ .actions = .{ .drag = true } } },
|
|
1458
|
+
};
|
|
1459
|
+
var drag_nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
1460
|
+
const drag_layout = try canvas.layoutWidgetTree(
|
|
1461
|
+
.{ .id = 1, .kind = .scroll_view, .value = 40, .children = &drag_children },
|
|
1462
|
+
geometry.RectF.init(0, 0, 160, 48),
|
|
1463
|
+
&drag_nodes,
|
|
1464
|
+
);
|
|
1465
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", drag_layout);
|
|
1466
|
+
|
|
1467
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1468
|
+
try std.testing.expect(snapshot.widgets[1].actions.drag);
|
|
1469
|
+
try std.testing.expect(snapshot.widgets[2].actions.drag);
|
|
1470
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .drag, .value = "8 0" }));
|
|
1471
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_drag_count);
|
|
1472
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.raw_input_count);
|
|
1473
|
+
|
|
1474
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .drag, .value = "8 0" });
|
|
1475
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_drag_count);
|
|
1476
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_drag_source_id);
|
|
1477
|
+
|
|
1478
|
+
const drop_children = [_]canvas.Widget{
|
|
1479
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Hidden drop", .semantics = .{ .actions = .{ .drop_files = true } } },
|
|
1480
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 48, 0, 32), .text = "Visible drop", .semantics = .{ .actions = .{ .drop_files = true } } },
|
|
1481
|
+
};
|
|
1482
|
+
var drop_nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
1483
|
+
const drop_layout = try canvas.layoutWidgetTree(
|
|
1484
|
+
.{ .id = 1, .kind = .scroll_view, .value = 40, .children = &drop_children },
|
|
1485
|
+
geometry.RectF.init(0, 0, 160, 48),
|
|
1486
|
+
&drop_nodes,
|
|
1487
|
+
);
|
|
1488
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", drop_layout);
|
|
1489
|
+
|
|
1490
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1491
|
+
try std.testing.expect(snapshot.widgets[1].actions.drop_files);
|
|
1492
|
+
try std.testing.expect(snapshot.widgets[2].actions.drop_files);
|
|
1493
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .drop_files, .value = "/tmp/hidden.csv" }));
|
|
1494
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.widget_file_drop_count);
|
|
1495
|
+
try std.testing.expectEqual(@as(u32, 0), app_state.file_drop_count);
|
|
1496
|
+
|
|
1497
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .drop_files, .value = "/tmp/visible.csv" });
|
|
1498
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.widget_file_drop_count);
|
|
1499
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.file_drop_count);
|
|
1500
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), app_state.last_drop_target_id);
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
test "runtime rejects automation canvas widget actions for clip content clipped targets" {
|
|
1504
|
+
const TestApp = struct {
|
|
1505
|
+
fn app(self: *@This()) App {
|
|
1506
|
+
return .{ .context = self, .name = "gpu-widget-clip-content-automation-actions", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
|
|
1510
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1511
|
+
defer harness.destroy(std.testing.allocator);
|
|
1512
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1513
|
+
var app_state: TestApp = .{};
|
|
1514
|
+
const app = app_state.app();
|
|
1515
|
+
try harness.start(app);
|
|
1516
|
+
|
|
1517
|
+
_ = try harness.runtime.createView(.{
|
|
1518
|
+
.window_id = 1,
|
|
1519
|
+
.label = "canvas",
|
|
1520
|
+
.kind = .gpu_surface,
|
|
1521
|
+
.frame = geometry.RectF.init(0, 0, 96, 48),
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
const children = [_]canvas.Widget{
|
|
1525
|
+
.{ .id = 2, .kind = .list_item, .frame = geometry.RectF.init(64, 0, 32, 32), .text = "Clipped" },
|
|
1526
|
+
.{ .id = 3, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 32, 32), .text = "Visible" },
|
|
1527
|
+
};
|
|
1528
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
1529
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1530
|
+
.{ .id = 1, .kind = .stack, .layout = .{ .clip_content = true }, .children = &children },
|
|
1531
|
+
geometry.RectF.init(0, 0, 48, 40),
|
|
1532
|
+
&nodes,
|
|
1533
|
+
);
|
|
1534
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1535
|
+
|
|
1536
|
+
var snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1537
|
+
try std.testing.expect(snapshot.widgets[1].actions.select);
|
|
1538
|
+
try std.testing.expect(snapshot.widgets[2].actions.select);
|
|
1539
|
+
|
|
1540
|
+
try std.testing.expectError(error.InvalidCommand, dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 2, .action = .select }));
|
|
1541
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1542
|
+
try std.testing.expect(!retained.findById(2).?.widget.state.selected);
|
|
1543
|
+
|
|
1544
|
+
try dispatchAutomationWidgetAction(&harness.runtime, app, .{ .view_label = "canvas", .id = 3, .action = .select });
|
|
1545
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1546
|
+
try std.testing.expect(retained.findById(3).?.widget.state.selected);
|
|
1547
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1548
|
+
try std.testing.expectEqual(@as(?f32, 1), snapshot.widgets[2].value);
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
test "runtime automation protocol refreshes widget-owned canvas display lists" {
|
|
1552
|
+
const TestApp = struct {
|
|
1553
|
+
fn app(self: *@This()) App {
|
|
1554
|
+
return .{ .context = self, .name = "gpu-widget-automation-display-list", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1559
|
+
defer harness.destroy(std.testing.allocator);
|
|
1560
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1561
|
+
var app_state: TestApp = .{};
|
|
1562
|
+
const app = app_state.app();
|
|
1563
|
+
try harness.start(app);
|
|
1564
|
+
|
|
1565
|
+
_ = try harness.runtime.createView(.{
|
|
1566
|
+
.window_id = 1,
|
|
1567
|
+
.label = "canvas",
|
|
1568
|
+
.kind = .gpu_surface,
|
|
1569
|
+
.frame = geometry.RectF.init(0, 0, 320, 180),
|
|
1570
|
+
});
|
|
1571
|
+
|
|
1572
|
+
const list_items = [_]canvas.Widget{
|
|
1573
|
+
.{ .id = 4, .kind = .list_item, .frame = geometry.RectF.init(0, 0, 0, 30), .text = "Overview" },
|
|
1574
|
+
.{ .id = 5, .kind = .list_item, .frame = geometry.RectF.init(0, 36, 0, 30), .text = "Customers" },
|
|
1575
|
+
};
|
|
1576
|
+
const children = [_]canvas.Widget{
|
|
1577
|
+
.{ .id = 2, .kind = .text_field, .frame = geometry.RectF.init(10, 12, 150, 32), .text = "Draft" },
|
|
1578
|
+
.{ .id = 3, .kind = .list, .frame = geometry.RectF.init(10, 58, 150, 72), .layout = .{ .gap = 6 }, .children = &list_items },
|
|
1579
|
+
};
|
|
1580
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
1581
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
1582
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1583
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayList(1, "canvas", .{});
|
|
1584
|
+
|
|
1585
|
+
var display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1586
|
+
var saw_initial_text = false;
|
|
1587
|
+
var saw_initial_selection = false;
|
|
1588
|
+
for (display_list.commands) |command| {
|
|
1589
|
+
switch (command) {
|
|
1590
|
+
.draw_text => |text| {
|
|
1591
|
+
if (text.id == testCanvasWidgetPartId(2, 3)) {
|
|
1592
|
+
try std.testing.expectEqualStrings("Draft", text.text);
|
|
1593
|
+
saw_initial_text = true;
|
|
1594
|
+
}
|
|
1595
|
+
},
|
|
1596
|
+
.fill_rounded_rect => |fill| {
|
|
1597
|
+
if (fill.id == testCanvasWidgetPartId(5, 1)) saw_initial_selection = true;
|
|
1598
|
+
},
|
|
1599
|
+
else => {},
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
try std.testing.expect(saw_initial_text);
|
|
1603
|
+
try std.testing.expect(!saw_initial_selection);
|
|
1604
|
+
|
|
1605
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 2 set-text Launch");
|
|
1606
|
+
|
|
1607
|
+
display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1608
|
+
var saw_updated_text = false;
|
|
1609
|
+
var saw_stale_text = false;
|
|
1610
|
+
var saw_text_caret = false;
|
|
1611
|
+
for (display_list.commands) |command| {
|
|
1612
|
+
switch (command) {
|
|
1613
|
+
.draw_text => |text| {
|
|
1614
|
+
if (text.id == testCanvasWidgetPartId(2, 4)) {
|
|
1615
|
+
try std.testing.expectEqualStrings("Launch", text.text);
|
|
1616
|
+
saw_updated_text = true;
|
|
1617
|
+
}
|
|
1618
|
+
if (std.mem.eql(u8, text.text, "Draft")) saw_stale_text = true;
|
|
1619
|
+
},
|
|
1620
|
+
.fill_rect => |bar| {
|
|
1621
|
+
if (bar.id == testCanvasWidgetPartId(2, 6)) saw_text_caret = true;
|
|
1622
|
+
},
|
|
1623
|
+
else => {},
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
try std.testing.expect(saw_updated_text);
|
|
1627
|
+
try std.testing.expect(!saw_stale_text);
|
|
1628
|
+
try std.testing.expect(saw_text_caret);
|
|
1629
|
+
|
|
1630
|
+
var snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1631
|
+
try std.testing.expectEqualStrings("Launch", snapshot.widgets[0].text_value);
|
|
1632
|
+
try std.testing.expectEqualDeep(automation.snapshot.TextRange{ .start = 6, .end = 6 }, snapshot.widgets[0].text_selection.?);
|
|
1633
|
+
|
|
1634
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 5 select");
|
|
1635
|
+
|
|
1636
|
+
display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1637
|
+
var saw_selected_item_fill = false;
|
|
1638
|
+
for (display_list.commands) |command| {
|
|
1639
|
+
switch (command) {
|
|
1640
|
+
.fill_rounded_rect => |fill| {
|
|
1641
|
+
if (fill.id == testCanvasWidgetPartId(5, 1)) saw_selected_item_fill = true;
|
|
1642
|
+
},
|
|
1643
|
+
else => {},
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
try std.testing.expect(saw_selected_item_fill);
|
|
1647
|
+
|
|
1648
|
+
snapshot = harness.runtime.automationSnapshot("Widgets");
|
|
1649
|
+
try std.testing.expect(!snapshot.widgets[2].selected);
|
|
1650
|
+
try std.testing.expect(snapshot.widgets[3].selected);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
test "runtime preserves canvas chrome when widget-owned display lists refresh" {
|
|
1654
|
+
const TestApp = struct {
|
|
1655
|
+
fn app(self: *@This()) App {
|
|
1656
|
+
return .{ .context = self, .name = "gpu-widget-chrome-display-list", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1661
|
+
defer harness.destroy(std.testing.allocator);
|
|
1662
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1663
|
+
var app_state: TestApp = .{};
|
|
1664
|
+
const app = app_state.app();
|
|
1665
|
+
try harness.start(app);
|
|
1666
|
+
|
|
1667
|
+
_ = try harness.runtime.createView(.{
|
|
1668
|
+
.window_id = 1,
|
|
1669
|
+
.label = "canvas",
|
|
1670
|
+
.kind = .gpu_surface,
|
|
1671
|
+
.frame = geometry.RectF.init(0, 0, 320, 180),
|
|
1672
|
+
});
|
|
1673
|
+
|
|
1674
|
+
const children = [_]canvas.Widget{
|
|
1675
|
+
.{ .id = 2, .kind = .text_field, .frame = geometry.RectF.init(24, 24, 150, 32), .text = "Draft" },
|
|
1676
|
+
};
|
|
1677
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
1678
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
1679
|
+
|
|
1680
|
+
const stops = [_]canvas.GradientStop{
|
|
1681
|
+
.{ .offset = 0, .color = canvas.Color.rgb8(48, 111, 237) },
|
|
1682
|
+
.{ .offset = 1, .color = canvas.Color.rgb8(16, 185, 129) },
|
|
1683
|
+
};
|
|
1684
|
+
var commands: [max_canvas_commands_per_view]canvas.CanvasCommand = undefined;
|
|
1685
|
+
var builder = canvas.Builder.init(&commands);
|
|
1686
|
+
try builder.drawText(.{
|
|
1687
|
+
.id = 10,
|
|
1688
|
+
.font_id = 1,
|
|
1689
|
+
.size = 12,
|
|
1690
|
+
.origin = geometry.PointF.init(16, 16),
|
|
1691
|
+
.color = canvas.Color.rgb8(18, 24, 38),
|
|
1692
|
+
.text = "Chrome header",
|
|
1693
|
+
});
|
|
1694
|
+
try layout.emitDisplayList(&builder, .{});
|
|
1695
|
+
try builder.fillRect(.{
|
|
1696
|
+
.id = 11,
|
|
1697
|
+
.rect = geometry.RectF.init(16, 148, 288, 12),
|
|
1698
|
+
.fill = .{ .linear_gradient = .{
|
|
1699
|
+
.start = geometry.PointF.init(16, 148),
|
|
1700
|
+
.end = geometry.PointF.init(304, 148),
|
|
1701
|
+
.stops = &stops,
|
|
1702
|
+
} },
|
|
1703
|
+
});
|
|
1704
|
+
|
|
1705
|
+
_ = try harness.runtime.setCanvasDisplayList(1, "canvas", builder.displayList());
|
|
1706
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1707
|
+
_ = try harness.runtime.emitCanvasWidgetDisplayListWithChrome(1, "canvas", .{}, .{
|
|
1708
|
+
.prefix_command_count = 1,
|
|
1709
|
+
.suffix_command_count = 1,
|
|
1710
|
+
});
|
|
1711
|
+
|
|
1712
|
+
var display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1713
|
+
try std.testing.expectEqual(@as(usize, 5), display_list.commandCount());
|
|
1714
|
+
switch (display_list.findCommandById(10).?.command) {
|
|
1715
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Chrome header", text.text),
|
|
1716
|
+
else => return error.UnexpectedCanvasCommand,
|
|
1717
|
+
}
|
|
1718
|
+
try std.testing.expect(display_list.findCommandById(11) != null);
|
|
1719
|
+
try std.testing.expect(display_list.findCommandById(testCanvasWidgetPartId(2, 3)) != null);
|
|
1720
|
+
|
|
1721
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-action canvas 2 set-text Launch");
|
|
1722
|
+
|
|
1723
|
+
display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1724
|
+
switch (display_list.findCommandById(10).?.command) {
|
|
1725
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Chrome header", text.text),
|
|
1726
|
+
else => return error.UnexpectedCanvasCommand,
|
|
1727
|
+
}
|
|
1728
|
+
try std.testing.expect(display_list.findCommandById(11) != null);
|
|
1729
|
+
switch (display_list.findCommandById(testCanvasWidgetPartId(2, 4)).?.command) {
|
|
1730
|
+
.draw_text => |text| try std.testing.expectEqualStrings("Launch", text.text),
|
|
1731
|
+
else => return error.UnexpectedCanvasCommand,
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
test "runtime reserves widget-owned canvas display list command headroom" {
|
|
1736
|
+
const TestApp = struct {
|
|
1737
|
+
fn app(self: *@This()) App {
|
|
1738
|
+
return .{ .context = self, .name = "gpu-widget-display-list-headroom", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
|
|
1742
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1743
|
+
defer harness.destroy(std.testing.allocator);
|
|
1744
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1745
|
+
var app_state: TestApp = .{};
|
|
1746
|
+
try harness.start(app_state.app());
|
|
1747
|
+
|
|
1748
|
+
_ = try harness.runtime.createView(.{
|
|
1749
|
+
.window_id = 1,
|
|
1750
|
+
.label = "canvas",
|
|
1751
|
+
.kind = .gpu_surface,
|
|
1752
|
+
.frame = geometry.RectF.init(0, 0, 320, 180),
|
|
1753
|
+
});
|
|
1754
|
+
|
|
1755
|
+
var nodes: [1]canvas.WidgetLayoutNode = undefined;
|
|
1756
|
+
const layout = try canvas.layoutWidgetTree(.{
|
|
1757
|
+
.id = 2,
|
|
1758
|
+
.kind = .text,
|
|
1759
|
+
.frame = geometry.RectF.init(16, 16, 120, 20),
|
|
1760
|
+
.text = "Headroom",
|
|
1761
|
+
}, geometry.RectF.init(0, 0, 320, 180), &nodes);
|
|
1762
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1763
|
+
|
|
1764
|
+
var info = try harness.runtime.emitCanvasWidgetDisplayListWithChrome(1, "canvas", .{}, .{
|
|
1765
|
+
.reserved_command_count = max_canvas_commands_per_view - 1,
|
|
1766
|
+
});
|
|
1767
|
+
try std.testing.expectEqual(@as(usize, 1), info.canvas_command_count);
|
|
1768
|
+
|
|
1769
|
+
try std.testing.expectError(error.CanvasCommandLimitReached, harness.runtime.emitCanvasWidgetDisplayListWithChrome(1, "canvas", .{}, .{
|
|
1770
|
+
.reserved_command_count = max_canvas_commands_per_view,
|
|
1771
|
+
}));
|
|
1772
|
+
|
|
1773
|
+
const display_list = try harness.runtime.canvasDisplayList(1, "canvas");
|
|
1774
|
+
try std.testing.expectEqual(@as(usize, 1), display_list.commandCount());
|
|
1775
|
+
try std.testing.expect(display_list.findCommandById(testCanvasWidgetPartId(2, 1)) != null);
|
|
1776
|
+
|
|
1777
|
+
info = try harness.runtime.emitCanvasWidgetDisplayListWithChrome(1, "canvas", .{}, .{});
|
|
1778
|
+
try std.testing.expectEqual(@as(usize, 1), info.canvas_command_count);
|
|
1779
|
+
}
|