@native-sdk/cli 0.0.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +176 -0
- package/README.md +50 -1
- package/app.zon +30 -0
- package/assets/icon.icns +0 -0
- package/assets/icon.ico +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +15 -0
- package/assets/native-sdk.entitlements +10 -0
- package/assets/native-sdk.manifest +12 -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 +45 -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,1098 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const geometry = @import("geometry");
|
|
3
|
+
const canvas = @import("canvas");
|
|
4
|
+
const platform = @import("../platform/root.zig");
|
|
5
|
+
const validation = @import("validation.zig");
|
|
6
|
+
const runtime_api = @import("api.zig");
|
|
7
|
+
const canvas_frame_helpers = @import("canvas_frame.zig");
|
|
8
|
+
const canvas_limits = @import("canvas_limits.zig");
|
|
9
|
+
const runtime_canvas_widget_display = @import("canvas_widget_display.zig");
|
|
10
|
+
const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
|
|
11
|
+
const widget_bridge = @import("widget_bridge.zig");
|
|
12
|
+
|
|
13
|
+
const GpuSurfaceInputEvent = runtime_api.GpuSurfaceInputEvent;
|
|
14
|
+
const CanvasWidgetPointerEvent = runtime_api.CanvasWidgetPointerEvent;
|
|
15
|
+
const CanvasWidgetKeyboardEvent = runtime_api.CanvasWidgetKeyboardEvent;
|
|
16
|
+
const CanvasWidgetFileDropEvent = runtime_api.CanvasWidgetFileDropEvent;
|
|
17
|
+
const CanvasWidgetDragEvent = runtime_api.CanvasWidgetDragEvent;
|
|
18
|
+
const validateViewLabel = validation.validateViewLabel;
|
|
19
|
+
const platformCursorFromCanvas = widget_bridge.platformCursorFromCanvas;
|
|
20
|
+
const canvasWidgetPointerEventFromGpuInput = canvas_frame_helpers.canvasWidgetPointerEventFromGpuInput;
|
|
21
|
+
const canvasWidgetKeyboardEventFromGpuInput = canvas_frame_helpers.canvasWidgetKeyboardEventFromGpuInput;
|
|
22
|
+
const canvasWidgetTextInputEventFromGpuInput = canvas_frame_helpers.canvasWidgetTextInputEventFromGpuInput;
|
|
23
|
+
const canvasWidgetEscapeKey = canvas_frame_helpers.canvasWidgetEscapeKey;
|
|
24
|
+
const canvasWidgetKeyboardModifiers = canvas_frame_helpers.canvasWidgetKeyboardModifiers;
|
|
25
|
+
const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
|
|
26
|
+
const canvasWidgetCommandable = canvas_widget_runtime.canvasWidgetCommandable;
|
|
27
|
+
const canvasWidgetCommandFiresOnPointerDown = canvas_widget_runtime.canvasWidgetCommandFiresOnPointerDown;
|
|
28
|
+
const canvasWidgetGroupFocusEdgeFromInput = canvas_widget_runtime.canvasWidgetGroupFocusEdgeFromInput;
|
|
29
|
+
const canvasWidgetSpatialFocusDirection = canvas_widget_runtime.canvasWidgetSpatialFocusDirection;
|
|
30
|
+
const canvasWidgetSpatialFocusAllowed = canvas_widget_runtime.canvasWidgetSpatialFocusAllowed;
|
|
31
|
+
const canvasWidgetGroupDirectionalFocusTarget = canvas_widget_runtime.canvasWidgetGroupDirectionalFocusTarget;
|
|
32
|
+
const canvasWidgetGroupFocusEdgeTarget = canvas_widget_runtime.canvasWidgetGroupFocusEdgeTarget;
|
|
33
|
+
|
|
34
|
+
/// Multi-click chain window: a primary pointer-down within this many
|
|
35
|
+
/// nanoseconds of the previous one (and within the slop below) raises
|
|
36
|
+
/// the click count instead of starting over. 500 ms is the common
|
|
37
|
+
/// platform default double-click speed; the runtime derives the count
|
|
38
|
+
/// itself instead of threading a host click count because (a) the
|
|
39
|
+
/// derivation runs identically on every platform including the null
|
|
40
|
+
/// platform tests, and (b) it reads only fields the session journal
|
|
41
|
+
/// already records (timestamp, point, button), so replay reproduces
|
|
42
|
+
/// the exact same gesture without a journal format change. The
|
|
43
|
+
/// tradeoff — the user's system double-click speed setting is not
|
|
44
|
+
/// consulted — is accepted and pinned here.
|
|
45
|
+
const canvas_widget_multi_click_interval_ns: u64 = 500 * std.time.ns_per_ms;
|
|
46
|
+
|
|
47
|
+
/// Movement slop per axis (canvas points) between chained clicks: a
|
|
48
|
+
/// hand tremor keeps the chain, a click somewhere else breaks it.
|
|
49
|
+
const canvas_widget_multi_click_slop: f32 = 4.0;
|
|
50
|
+
|
|
51
|
+
pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
|
|
52
|
+
return struct {
|
|
53
|
+
pub fn routeCanvasWidgetPointerInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetPointerEvent {
|
|
54
|
+
try validateRuntimeViewParent(self, input_event.window_id);
|
|
55
|
+
try validateViewLabel(input_event.label);
|
|
56
|
+
var pointer = canvasWidgetPointerEventFromGpuInput(input_event) orelse return null;
|
|
57
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
|
|
58
|
+
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
59
|
+
switch (pointer.phase) {
|
|
60
|
+
.move, .up, .cancel => {
|
|
61
|
+
if (self.views[index].canvas_widget_pressed_id != 0) {
|
|
62
|
+
pointer.captured_id = self.views[index].canvas_widget_pressed_id;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
.hover, .down, .wheel => {},
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const route = try self.views[index].widgetLayoutTree().routePointerEventWithTokens(pointer, self.views[index].widget_tokens, output);
|
|
69
|
+
return .{
|
|
70
|
+
.window_id = input_event.window_id,
|
|
71
|
+
.view_label = self.views[index].label,
|
|
72
|
+
.pointer = pointer,
|
|
73
|
+
.target = route.target,
|
|
74
|
+
.press_target = canvasWidgetPressTargetForRoute(self, index, pointer, route),
|
|
75
|
+
.route = route.entries,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// The press target a routed pointer event dispatches to, with the
|
|
80
|
+
/// press-vs-drag disambiguation applied: a release that ends a
|
|
81
|
+
/// static-text selection drag is a selection gesture, not a click,
|
|
82
|
+
/// so it presses no one (the selection it made stays live for
|
|
83
|
+
/// copy). A plain click collapses the selection on `.down`, so it
|
|
84
|
+
/// reaches `.up` collapsed and the press lands normally.
|
|
85
|
+
fn canvasWidgetPressTargetForRoute(
|
|
86
|
+
self: *const Runtime,
|
|
87
|
+
view_index: usize,
|
|
88
|
+
pointer: canvas.WidgetPointerEvent,
|
|
89
|
+
route: canvas.WidgetEventRoute,
|
|
90
|
+
) ?canvas.WidgetHit {
|
|
91
|
+
const press_target = route.press_target orelse return null;
|
|
92
|
+
if (pointer.phase != .up) return press_target;
|
|
93
|
+
const raw = route.target orelse return press_target;
|
|
94
|
+
if (raw.kind != .text) return press_target;
|
|
95
|
+
if (self.views[view_index].canvas_widget_selected_text_id != raw.id) return press_target;
|
|
96
|
+
const node = self.views[view_index].widgetLayoutTree().findById(raw.id) orelse return press_target;
|
|
97
|
+
const selection = node.widget.text_selection orelse return press_target;
|
|
98
|
+
if (selection.isCollapsed(node.widget.text.len)) return press_target;
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// A primary pointer-down whose hit path resolves to a
|
|
103
|
+
/// window-drag region (`window-drag="true"` / `.window_drag`)
|
|
104
|
+
/// hands the gesture to the platform WINDOW instead of the
|
|
105
|
+
/// widget pipeline: the window moves once the pointer actually
|
|
106
|
+
/// moves (a plain click moves nothing) and the platform applies
|
|
107
|
+
/// its double-click titlebar convention (macOS: zoom). The walk
|
|
108
|
+
/// mirrors the press fall-through, so a press-claiming widget
|
|
109
|
+
/// inside the region — a button in a drag header — keeps its
|
|
110
|
+
/// press and this returns false. Returns true when the down was
|
|
111
|
+
/// consumed; the caller then skips widget press/text/focus/
|
|
112
|
+
/// command dispatch for it so no widget is left pressed while
|
|
113
|
+
/// the OS owns the pointer. Platforms without the channel
|
|
114
|
+
/// (`error.UnsupportedService`) degrade to dead space.
|
|
115
|
+
pub fn startCanvasWidgetWindowDragFromPointer(
|
|
116
|
+
self: *Runtime,
|
|
117
|
+
input_event: GpuSurfaceInputEvent,
|
|
118
|
+
pointer_event: CanvasWidgetPointerEvent,
|
|
119
|
+
) anyerror!bool {
|
|
120
|
+
if (pointer_event.pointer.phase != .down or input_event.button != 0) return false;
|
|
121
|
+
const target = pointer_event.target orelse return false;
|
|
122
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return false;
|
|
123
|
+
if (self.views[index].kind != .gpu_surface) return false;
|
|
124
|
+
const layout = self.views[index].widgetLayoutTree();
|
|
125
|
+
if (canvas.widgetWindowDragTargetIndexFromNode(layout, target.index) == null) return false;
|
|
126
|
+
self.options.platform.services.startWindowDrag(pointer_event.window_id) catch |err| switch (err) {
|
|
127
|
+
error.UnsupportedService => return false,
|
|
128
|
+
else => return err,
|
|
129
|
+
};
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Resolve the view's stored (raw) pressed widget id through the
|
|
134
|
+
/// press fall-through walk, so control activation compares the
|
|
135
|
+
/// same resolved ids the press target carries.
|
|
136
|
+
fn canvasWidgetResolvedPressedId(self: *const Runtime, view_index: usize, pressed_id: canvas.ObjectId) canvas.ObjectId {
|
|
137
|
+
if (pressed_id == 0) return 0;
|
|
138
|
+
const layout = self.views[view_index].widgetLayoutTree();
|
|
139
|
+
for (layout.nodes, 0..) |node, node_index| {
|
|
140
|
+
if (node.widget.id != pressed_id) continue;
|
|
141
|
+
const press_index = canvas.widgetPressTargetIndexFromNode(layout, node_index) orelse return 0;
|
|
142
|
+
return layout.nodes[press_index].widget.id;
|
|
143
|
+
}
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
pub fn routeCanvasWidgetKeyboardInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetKeyboardEvent {
|
|
148
|
+
try validateRuntimeViewParent(self, input_event.window_id);
|
|
149
|
+
try validateViewLabel(input_event.label);
|
|
150
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
|
|
151
|
+
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
152
|
+
if (!self.views[index].focused) return null;
|
|
153
|
+
const focused_id = self.views[index].canvas_widget_focused_id;
|
|
154
|
+
if (focused_id == 0) return null;
|
|
155
|
+
// FRAMEWORK BEHAVIOR CHANGE (deliberate, scoped): a QUIETLY
|
|
156
|
+
// focused plain list row routes no keyboard input — keys
|
|
157
|
+
// reach the app as target-less events, exactly as if nothing
|
|
158
|
+
// were focused. Quiet focus is the pointer/programmatic
|
|
159
|
+
// contract (no ring); on a list row it is bookkeeping, not a
|
|
160
|
+
// keyboard cursor, and letting it claim keys made a stale
|
|
161
|
+
// clicked row swallow the arrows/Enter an app-level
|
|
162
|
+
// selection model owns. The Tab-established ring register
|
|
163
|
+
// (focus_visible) keeps today's behavior in full: activation
|
|
164
|
+
// keys select, arrows walk rows. Tree rows (role treeitem)
|
|
165
|
+
// are exempt — their roving-focus keymap is the feature.
|
|
166
|
+
if (canvasWidgetQuietListRowFocus(self, index, focused_id)) return null;
|
|
167
|
+
const keyboard = canvasWidgetKeyboardEventFromGpuInput(input_event, focused_id) orelse return null;
|
|
168
|
+
|
|
169
|
+
const route = try self.views[index].widgetLayoutTree().routeKeyboardEvent(keyboard, output);
|
|
170
|
+
if (route.target == null) return null;
|
|
171
|
+
return .{
|
|
172
|
+
.window_id = input_event.window_id,
|
|
173
|
+
.view_label = self.views[index].label,
|
|
174
|
+
.keyboard = keyboard,
|
|
175
|
+
.target = route.target,
|
|
176
|
+
.route = route.entries,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
pub fn routeCanvasWidgetTextInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetKeyboardEvent {
|
|
181
|
+
try validateRuntimeViewParent(self, input_event.window_id);
|
|
182
|
+
try validateViewLabel(input_event.label);
|
|
183
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
|
|
184
|
+
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
185
|
+
if (!self.views[index].focused) return null;
|
|
186
|
+
const focused_id = self.views[index].canvas_widget_focused_id;
|
|
187
|
+
if (focused_id == 0) return null;
|
|
188
|
+
const keyboard = canvasWidgetTextInputEventFromGpuInput(input_event, focused_id) orelse return null;
|
|
189
|
+
|
|
190
|
+
const route = try self.views[index].widgetLayoutTree().routeKeyboardEvent(keyboard, output);
|
|
191
|
+
if (route.target == null) return null;
|
|
192
|
+
return .{
|
|
193
|
+
.window_id = input_event.window_id,
|
|
194
|
+
.view_label = self.views[index].label,
|
|
195
|
+
.keyboard = keyboard,
|
|
196
|
+
.target = route.target,
|
|
197
|
+
.route = route.entries,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub fn routeCanvasWidgetFileDrop(self: *const Runtime, drop: platform.FileDropEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetFileDropEvent {
|
|
202
|
+
try validateRuntimeViewParent(self, drop.window_id);
|
|
203
|
+
if (drop.view_label.len == 0 or drop.paths.len == 0) return null;
|
|
204
|
+
try validateViewLabel(drop.view_label);
|
|
205
|
+
const point = drop.point orelse return null;
|
|
206
|
+
const index = runtimeFindViewIndex(self, drop.window_id, drop.view_label) orelse return error.ViewNotFound;
|
|
207
|
+
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
208
|
+
|
|
209
|
+
const widget_drop = canvas.WidgetFileDropEvent{
|
|
210
|
+
.point = point,
|
|
211
|
+
.paths = drop.paths,
|
|
212
|
+
};
|
|
213
|
+
const route = try self.views[index].widgetLayoutTree().routeFileDropEvent(widget_drop, output);
|
|
214
|
+
if (route.target == null) return null;
|
|
215
|
+
return .{
|
|
216
|
+
.window_id = drop.window_id,
|
|
217
|
+
.view_label = self.views[index].label,
|
|
218
|
+
.drop = widget_drop,
|
|
219
|
+
.target = route.target,
|
|
220
|
+
.route = route.entries,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
pub fn routeCanvasWidgetDragInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
|
|
225
|
+
try validateRuntimeViewParent(self, input_event.window_id);
|
|
226
|
+
if (input_event.kind != .pointer_drag) return null;
|
|
227
|
+
try validateViewLabel(input_event.label);
|
|
228
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
|
|
229
|
+
if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
|
|
230
|
+
const source_id = self.views[index].canvas_widget_pressed_id;
|
|
231
|
+
if (source_id == 0) return null;
|
|
232
|
+
|
|
233
|
+
const drag = canvas.WidgetDragEvent{
|
|
234
|
+
.source_id = source_id,
|
|
235
|
+
.point = geometry.PointF.init(input_event.x, input_event.y),
|
|
236
|
+
.delta = geometry.OffsetF.init(input_event.delta_x, input_event.delta_y),
|
|
237
|
+
};
|
|
238
|
+
const route = try self.views[index].widgetLayoutTree().routeDragEvent(drag, output);
|
|
239
|
+
if (route.target == null) return null;
|
|
240
|
+
return .{
|
|
241
|
+
.window_id = input_event.window_id,
|
|
242
|
+
.view_label = self.views[index].label,
|
|
243
|
+
.drag = drag,
|
|
244
|
+
.source = route.target,
|
|
245
|
+
.route = route.entries,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// Whether keyboard focus sits QUIETLY (no visible ring) on a
|
|
250
|
+
/// plain list row — the one focus state the keyboard seams above
|
|
251
|
+
/// treat as transparent. Quiet focus lands on rows from pointer
|
|
252
|
+
/// presses and programmatic focus; it exists so activation can
|
|
253
|
+
/// find "the thing the user last touched", not to make the row a
|
|
254
|
+
/// keyboard cursor. Plain means `kind == .list_item` without the
|
|
255
|
+
/// treeitem role: ARIA tree rows carry a roving-focus keymap by
|
|
256
|
+
/// design and keep every key they have today.
|
|
257
|
+
fn canvasWidgetQuietListRowFocus(self: *const Runtime, index: usize, focused_id: canvas.ObjectId) bool {
|
|
258
|
+
if (focused_id == 0) return false;
|
|
259
|
+
if (self.views[index].canvas_widget_focus_visible_id == focused_id) return false;
|
|
260
|
+
const node_index = self.views[index].canvasWidgetNodeIndexById(focused_id) orelse return false;
|
|
261
|
+
const widget = self.views[index].widget_layout_nodes[node_index].widget;
|
|
262
|
+
return widget.kind == .list_item and widget.semantics.role != .treeitem;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/// Stamp the routed pointer event with its click count and
|
|
266
|
+
/// advance the view's multi-click chain. Downs count (a rapid
|
|
267
|
+
/// same-spot primary down raises the count, anything else
|
|
268
|
+
/// restarts at 1); moves and ups carry the count of the press
|
|
269
|
+
/// that started the gesture, so a double-click drag extends by
|
|
270
|
+
/// words all the way to its release. Timestamps of 0 (a host or
|
|
271
|
+
/// test that never stamps them) never chain — such inputs
|
|
272
|
+
/// honestly degrade to single clicks instead of making every
|
|
273
|
+
/// click a double-click.
|
|
274
|
+
pub fn updateCanvasWidgetClickCountFromPointer(self: *Runtime, input_event: GpuSurfaceInputEvent, pointer_event: *CanvasWidgetPointerEvent) void {
|
|
275
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
276
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
277
|
+
switch (pointer_event.pointer.phase) {
|
|
278
|
+
.down => {
|
|
279
|
+
if (input_event.button != 0) {
|
|
280
|
+
// A non-primary press breaks the chain (its own
|
|
281
|
+
// gesture — middle-click — never multi-clicks
|
|
282
|
+
// text; right-click was consumed by the context
|
|
283
|
+
// menu path before reaching here).
|
|
284
|
+
self.views[index].canvas_widget_click_count = 0;
|
|
285
|
+
self.views[index].canvas_widget_click_timestamp_ns = 0;
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const previous_count = self.views[index].canvas_widget_click_count;
|
|
289
|
+
const previous_timestamp = self.views[index].canvas_widget_click_timestamp_ns;
|
|
290
|
+
const previous_point = self.views[index].canvas_widget_click_point;
|
|
291
|
+
const point = pointer_event.pointer.point;
|
|
292
|
+
const chained = previous_count != 0 and
|
|
293
|
+
previous_timestamp != 0 and
|
|
294
|
+
input_event.timestamp_ns >= previous_timestamp and
|
|
295
|
+
input_event.timestamp_ns - previous_timestamp <= canvas_widget_multi_click_interval_ns and
|
|
296
|
+
@abs(point.x - previous_point.x) <= canvas_widget_multi_click_slop and
|
|
297
|
+
@abs(point.y - previous_point.y) <= canvas_widget_multi_click_slop;
|
|
298
|
+
// Clamp at 3: a fourth rapid click repeats the
|
|
299
|
+
// triple behavior, the platform text-view rule.
|
|
300
|
+
const count: u8 = if (chained) @min(previous_count + 1, 3) else 1;
|
|
301
|
+
self.views[index].canvas_widget_click_count = count;
|
|
302
|
+
self.views[index].canvas_widget_click_timestamp_ns = input_event.timestamp_ns;
|
|
303
|
+
self.views[index].canvas_widget_click_point = point;
|
|
304
|
+
pointer_event.pointer.click_count = count;
|
|
305
|
+
},
|
|
306
|
+
.move, .up => {
|
|
307
|
+
pointer_event.pointer.click_count = @max(self.views[index].canvas_widget_click_count, 1);
|
|
308
|
+
},
|
|
309
|
+
.hover, .cancel, .wheel => {},
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
pub fn updateCanvasWidgetFocusFromPointer(self: *Runtime, pointer_event: CanvasWidgetPointerEvent) anyerror!void {
|
|
314
|
+
if (pointer_event.pointer.phase != .down) return;
|
|
315
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
316
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
317
|
+
|
|
318
|
+
// Focus follows the resolved press target (the row a press on
|
|
319
|
+
// plain text lands on), not the raw hit: clicking a list
|
|
320
|
+
// item's label focuses the item, and clicking an editable
|
|
321
|
+
// field (which claims its own presses) focuses the field
|
|
322
|
+
// exactly as before.
|
|
323
|
+
const next_focus_id: canvas.ObjectId = if (pointer_event.press_target) |target| blk: {
|
|
324
|
+
if (self.views[index].widgetLayoutTree().focusTargetById(target.id) != null) break :blk target.id;
|
|
325
|
+
break :blk 0;
|
|
326
|
+
} else 0;
|
|
327
|
+
|
|
328
|
+
// Pointer focus renders quietly for buttons and rows, but an
|
|
329
|
+
// editable text widget shows its focus affordances (ring and
|
|
330
|
+
// caret) however focus arrived — the :focus-visible contract
|
|
331
|
+
// text inputs have on every platform.
|
|
332
|
+
const next_focus_visible_id: canvas.ObjectId = if (pointer_event.press_target) |target| blk: {
|
|
333
|
+
if (target.id == next_focus_id and canvas_widget_runtime.canvasWidgetEditableTextKind(target.kind)) break :blk next_focus_id;
|
|
334
|
+
break :blk 0;
|
|
335
|
+
} else 0;
|
|
336
|
+
|
|
337
|
+
if (self.views[index].canvas_widget_focused_id == next_focus_id and self.views[index].canvas_widget_focus_visible_id == next_focus_visible_id) return;
|
|
338
|
+
const previous_state = self.views[index].canvasWidgetRenderState();
|
|
339
|
+
self.views[index].canvas_widget_focused_id = next_focus_id;
|
|
340
|
+
self.views[index].canvas_widget_focus_visible_id = next_focus_visible_id;
|
|
341
|
+
try invalidateForCanvasWidgetRenderStateChange(self, index, previous_state, self.views[index].canvasWidgetRenderState());
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
pub fn updateCanvasWidgetInteractionFromPointer(self: *Runtime, pointer_event: CanvasWidgetPointerEvent) anyerror!void {
|
|
345
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
346
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
347
|
+
|
|
348
|
+
// Hover and cursor resolve through the hover-target walk (the
|
|
349
|
+
// press fall-through): a composite row is ONE interactive
|
|
350
|
+
// surface, so a pointer over the row's own text/icon/badge
|
|
351
|
+
// children keeps the row's wash and cursor instead of holing
|
|
352
|
+
// them per child. The pressed id stays the RAW hit — static
|
|
353
|
+
// text drag-selection extends against it, so resolving it
|
|
354
|
+
// would break click-drag copy inside pressable rows.
|
|
355
|
+
const layout_tree = self.views[index].widgetLayoutTree();
|
|
356
|
+
const target_id: canvas.ObjectId = if (pointer_event.target) |target| target.id else 0;
|
|
357
|
+
const hover_target = layout_tree.hoverTargetForHit(pointer_event.target);
|
|
358
|
+
const hover_target_id: canvas.ObjectId = if (hover_target) |value| value.id else 0;
|
|
359
|
+
const hit_target = layout_tree.hoverTargetForHit(layout_tree.hitTestWithTokens(pointer_event.pointer.point, self.views[index].widget_tokens));
|
|
360
|
+
const hit_target_id: canvas.ObjectId = if (hit_target) |value| value.id else 0;
|
|
361
|
+
const hit_cursor = platformCursorFromCanvas(layout_tree.cursorForHit(hit_target));
|
|
362
|
+
var next_hovered_id = self.views[index].canvas_widget_hovered_id;
|
|
363
|
+
var next_pressed_id = self.views[index].canvas_widget_pressed_id;
|
|
364
|
+
var next_cursor = self.views[index].canvas_widget_cursor;
|
|
365
|
+
|
|
366
|
+
switch (pointer_event.pointer.phase) {
|
|
367
|
+
.hover, .move => {
|
|
368
|
+
next_hovered_id = hit_target_id;
|
|
369
|
+
next_cursor = hit_cursor;
|
|
370
|
+
},
|
|
371
|
+
.down => {
|
|
372
|
+
next_hovered_id = hover_target_id;
|
|
373
|
+
next_pressed_id = target_id;
|
|
374
|
+
next_cursor = platformCursorFromCanvas(layout_tree.cursorForHit(hover_target));
|
|
375
|
+
},
|
|
376
|
+
.up => {
|
|
377
|
+
next_hovered_id = hit_target_id;
|
|
378
|
+
next_pressed_id = 0;
|
|
379
|
+
next_cursor = hit_cursor;
|
|
380
|
+
},
|
|
381
|
+
.cancel => {
|
|
382
|
+
next_hovered_id = 0;
|
|
383
|
+
next_pressed_id = 0;
|
|
384
|
+
next_cursor = .arrow;
|
|
385
|
+
},
|
|
386
|
+
.wheel => {},
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Hover-detail chrome (chart cursor + floating card) tracks
|
|
390
|
+
// the pointer, but only SNAPPED: the stored point updates
|
|
391
|
+
// whenever the pointer is over a hover-detail widget, and a
|
|
392
|
+
// repaint fires only when the snapped sample index changes —
|
|
393
|
+
// gliding within one sample costs nothing.
|
|
394
|
+
const next_hover_point: ?geometry.PointF = if (pointer_event.pointer.phase != .cancel and
|
|
395
|
+
canvasChartHoverIndexForId(self, index, next_hovered_id, pointer_event.pointer.point) != null)
|
|
396
|
+
pointer_event.pointer.point
|
|
397
|
+
else
|
|
398
|
+
null;
|
|
399
|
+
const hover_detail_changed = !std.meta.eql(
|
|
400
|
+
canvasChartHoverKey(self, index, self.views[index].canvas_widget_hovered_id, self.views[index].canvas_widget_hover_point),
|
|
401
|
+
canvasChartHoverKey(self, index, next_hovered_id, next_hover_point),
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
const interaction_changed = self.views[index].canvas_widget_hovered_id != next_hovered_id or
|
|
405
|
+
self.views[index].canvas_widget_pressed_id != next_pressed_id or
|
|
406
|
+
hover_detail_changed;
|
|
407
|
+
const cursor_changed = self.views[index].canvas_widget_cursor != next_cursor;
|
|
408
|
+
// The stored point only advances when the snapped sample (or
|
|
409
|
+
// any other interaction) changes: hover chrome is a pure
|
|
410
|
+
// function of the snapped index, so a stale point that maps
|
|
411
|
+
// to the same sample renders the same pixels.
|
|
412
|
+
if (!interaction_changed and !cursor_changed) return;
|
|
413
|
+
|
|
414
|
+
const previous_state = self.views[index].canvasWidgetRenderState();
|
|
415
|
+
self.views[index].canvas_widget_hovered_id = next_hovered_id;
|
|
416
|
+
self.views[index].canvas_widget_pressed_id = next_pressed_id;
|
|
417
|
+
self.views[index].canvas_widget_hover_point = next_hover_point;
|
|
418
|
+
self.views[index].canvas_widget_cursor = next_cursor;
|
|
419
|
+
if (cursor_changed) try syncCanvasWidgetCursorForView(self, index);
|
|
420
|
+
if (interaction_changed) try invalidateForCanvasWidgetRenderStateChange(self, index, previous_state, self.views[index].canvasWidgetRenderState());
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/// The (widget id, snapped sample index) pair chart hover chrome
|
|
424
|
+
/// renders for, or null when the id/point pair paints none — the
|
|
425
|
+
/// equality key that gates hover-detail repaints.
|
|
426
|
+
const CanvasChartHoverKey = struct { id: canvas.ObjectId, index: usize };
|
|
427
|
+
|
|
428
|
+
fn canvasChartHoverKey(self: *Runtime, view_index: usize, hovered_id: canvas.ObjectId, point: ?geometry.PointF) ?CanvasChartHoverKey {
|
|
429
|
+
const hover_point = point orelse return null;
|
|
430
|
+
const sample = canvasChartHoverIndexForId(self, view_index, hovered_id, hover_point) orelse return null;
|
|
431
|
+
return .{ .id = hovered_id, .index = sample };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
fn canvasChartHoverIndexForId(self: *Runtime, view_index: usize, hovered_id: canvas.ObjectId, point: geometry.PointF) ?usize {
|
|
435
|
+
if (hovered_id == 0) return null;
|
|
436
|
+
const layout = self.views[view_index].widgetLayoutTree();
|
|
437
|
+
const node = layout.findById(hovered_id) orelse return null;
|
|
438
|
+
var widget = node.widget;
|
|
439
|
+
widget.frame = node.frame;
|
|
440
|
+
return canvas.chartWidgetHoverIndex(widget, self.views[view_index].widget_tokens, point);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
pub fn syncCanvasWidgetCursorForView(self: *Runtime, view_index: usize) anyerror!void {
|
|
444
|
+
if (view_index >= self.view_count) return;
|
|
445
|
+
if (self.views[view_index].kind != .gpu_surface) return;
|
|
446
|
+
try self.options.platform.services.setViewCursor(
|
|
447
|
+
self.views[view_index].window_id,
|
|
448
|
+
self.views[view_index].label,
|
|
449
|
+
self.views[view_index].canvas_widget_cursor,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/// Mirror the view's window-drag regions to the platform (see
|
|
454
|
+
/// `platform.WindowDragRegion`): recompute from the freshly
|
|
455
|
+
/// retained layout on every install and push only when the
|
|
456
|
+
/// mirror actually changed, so a hit-testing platform
|
|
457
|
+
/// (Windows answering `WM_NCHITTEST`) tracks header moves and
|
|
458
|
+
/// visibility flips without being spammed by unrelated
|
|
459
|
+
/// rebuilds. Platforms without the service (macOS, whose drag
|
|
460
|
+
/// path starts from the live pointer gesture) skip even the
|
|
461
|
+
/// collection walk. A view that never had drag regions never
|
|
462
|
+
/// pushes; one whose regions disappeared pushes the empty
|
|
463
|
+
/// mirror once to clear the platform side.
|
|
464
|
+
pub fn syncCanvasWidgetWindowDragRegionsForView(self: *Runtime, view_index: usize) anyerror!void {
|
|
465
|
+
if (view_index >= self.view_count) return;
|
|
466
|
+
if (self.views[view_index].kind != .gpu_surface) return;
|
|
467
|
+
if (self.options.platform.services.set_window_drag_regions_fn == null) return;
|
|
468
|
+
const view = &self.views[view_index];
|
|
469
|
+
var regions: [canvas_limits.max_canvas_widget_window_drag_regions_per_view]platform.WindowDragRegion = undefined;
|
|
470
|
+
const count = collectCanvasWidgetWindowDragRegions(view.widgetLayoutTree(), ®ions);
|
|
471
|
+
if (view.canvas_widget_drag_regions_pushed) {
|
|
472
|
+
if (count == view.canvas_widget_drag_region_count and windowDragRegionsEqual(regions[0..count], view.canvas_widget_drag_regions[0..count])) return;
|
|
473
|
+
} else if (count == 0) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
try self.options.platform.services.setWindowDragRegions(view.window_id, view.label, regions[0..count]);
|
|
477
|
+
@memcpy(view.canvas_widget_drag_regions[0..count], regions[0..count]);
|
|
478
|
+
view.canvas_widget_drag_region_count = count;
|
|
479
|
+
view.canvas_widget_drag_regions_pushed = true;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
pub fn invalidateForCanvasWidgetRenderStateChange(self: *Runtime, view_index: usize, previous: canvas.WidgetRenderState, next: canvas.WidgetRenderState) anyerror!void {
|
|
483
|
+
if (view_index >= self.view_count) return;
|
|
484
|
+
if (self.views[view_index].kind != .gpu_surface) return;
|
|
485
|
+
// Tokens matter here: chart hover chrome (axis gutters, the
|
|
486
|
+
// floating detail card) measures text through the view's
|
|
487
|
+
// live tokens, so the dirty region must measure the same way.
|
|
488
|
+
const local_dirty = self.views[view_index].widgetLayoutTree().renderStateDirtyBoundsWithTokens(previous, next, self.views[view_index].widget_tokens);
|
|
489
|
+
invalidateForCanvasWidgetRenderStateDirty(self, view_index, local_dirty);
|
|
490
|
+
const publish_accessibility = previous.focused_id != next.focused_id;
|
|
491
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwnedWithAccessibility(self, view_index, publish_accessibility);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
pub fn invalidateForCanvasWidgetRenderStateDirty(self: *Runtime, view_index: usize, local_dirty: ?geometry.RectF) void {
|
|
495
|
+
if (view_index >= self.view_count) return;
|
|
496
|
+
if (self.views[view_index].kind != .gpu_surface) return;
|
|
497
|
+
const dirty = local_dirty orelse return;
|
|
498
|
+
if (canvasDirtyRegionForView(self.views[view_index].frame, dirty)) |dirty_region| {
|
|
499
|
+
self.invalidateFor(.state, dirty_region);
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
self.invalidateFor(.state, self.views[view_index].frame);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
pub fn canvasWidgetRenderStateAfterLayout(previous: canvas.WidgetRenderState, layout: canvas.WidgetLayoutTree) canvas.WidgetRenderState {
|
|
506
|
+
const next_focused_id = if (previous.focused_id) |id| if (layout.focusTargetById(id) != null) id else null else null;
|
|
507
|
+
return .{
|
|
508
|
+
.focused_id = next_focused_id,
|
|
509
|
+
.focus_visible_id = if (previous.focus_visible_id) |id| if (next_focused_id != null and next_focused_id.? == id and layout.focusTargetById(id) != null) id else null else null,
|
|
510
|
+
.hovered_id = if (previous.hovered_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
|
|
511
|
+
.pressed_id = if (previous.pressed_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) id else null else null,
|
|
512
|
+
// The hover point rides with the hovered widget: it
|
|
513
|
+
// survives exactly when the hover survives.
|
|
514
|
+
.hover_point = if (previous.hovered_id) |id| if (canvasWidgetInteractionTargetExists(layout, id)) previous.hover_point else null else null,
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
pub fn canvasWidgetRenderStatesEqual(a: canvas.WidgetRenderState, b: canvas.WidgetRenderState) bool {
|
|
519
|
+
return a.focused_id == b.focused_id and
|
|
520
|
+
a.focus_visible_id == b.focus_visible_id and
|
|
521
|
+
a.hovered_id == b.hovered_id and
|
|
522
|
+
a.pressed_id == b.pressed_id and
|
|
523
|
+
canvasOptionalPointsEqual(a.hover_point, b.hover_point);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
fn canvasOptionalPointsEqual(a: ?geometry.PointF, b: ?geometry.PointF) bool {
|
|
527
|
+
if (a) |point_a| {
|
|
528
|
+
const point_b = b orelse return false;
|
|
529
|
+
return point_a.x == point_b.x and point_a.y == point_b.y;
|
|
530
|
+
}
|
|
531
|
+
return b == null;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
pub fn updateCanvasWidgetScrollFromPointer(self: *Runtime, pointer_event: CanvasWidgetPointerEvent) anyerror!void {
|
|
535
|
+
if (pointer_event.pointer.phase != .wheel) return;
|
|
536
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
537
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
538
|
+
|
|
539
|
+
const dirty = try self.views[index].applyCanvasWidgetScrollRoute(pointer_event.route, pointer_event.pointer.delta.dy, .wheel) orelse return;
|
|
540
|
+
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
541
|
+
self.views[index].reconcileCanvasWidgetRenderStateAfterScroll(pointer_event.pointer.point);
|
|
542
|
+
if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
|
|
543
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
544
|
+
self.invalidateFor(.state, dirty_region);
|
|
545
|
+
} else {
|
|
546
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
547
|
+
}
|
|
548
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwnedSkippingAccessibility(self, index);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/// Resolve cmd/ctrl+C/X/V against the view's text state before the
|
|
552
|
+
/// keyboard event reaches the text editor and the app.
|
|
553
|
+
///
|
|
554
|
+
/// - copy: writes the focused editable widget's selection (or the
|
|
555
|
+
/// view's static text selection) through the platform clipboard
|
|
556
|
+
/// seam; no widget state changes.
|
|
557
|
+
/// - cut: copy, then stamp a delete-selection edit onto the routed
|
|
558
|
+
/// keyboard event so runtime widget and app model apply the same
|
|
559
|
+
/// removal.
|
|
560
|
+
/// - paste: reads the clipboard into `paste_buffer`, clamps it to
|
|
561
|
+
/// the view's text capacity (setting `edit_truncated` loudly),
|
|
562
|
+
/// and stamps the insertion onto the routed keyboard event.
|
|
563
|
+
///
|
|
564
|
+
/// Platforms without a clipboard capability report
|
|
565
|
+
/// `UnsupportedService`; the shortcut degrades to a no-op instead
|
|
566
|
+
/// of failing input dispatch.
|
|
567
|
+
pub fn applyCanvasWidgetClipboardShortcut(
|
|
568
|
+
self: *Runtime,
|
|
569
|
+
input_event: GpuSurfaceInputEvent,
|
|
570
|
+
keyboard_event: ?*CanvasWidgetKeyboardEvent,
|
|
571
|
+
paste_buffer: []u8,
|
|
572
|
+
) anyerror!void {
|
|
573
|
+
if (input_event.kind != .key_down) return;
|
|
574
|
+
const action = canvas.widgetKeyboardClipboardAction(.{
|
|
575
|
+
.phase = .key_down,
|
|
576
|
+
.key = input_event.key,
|
|
577
|
+
.modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers),
|
|
578
|
+
}) orelse return;
|
|
579
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return;
|
|
580
|
+
if (self.views[index].kind != .gpu_surface or !self.views[index].focused) return;
|
|
581
|
+
|
|
582
|
+
switch (action) {
|
|
583
|
+
.copy => {
|
|
584
|
+
const text = self.views[index].canvasWidgetCopyText() orelse return;
|
|
585
|
+
self.writeClipboard(text) catch return;
|
|
586
|
+
},
|
|
587
|
+
.cut => {
|
|
588
|
+
const event = keyboard_event orelse return;
|
|
589
|
+
const target = event.target orelse return;
|
|
590
|
+
const text = canvasWidgetEditableSelectionText(self, index, target) orelse return;
|
|
591
|
+
// Never delete text that did not make it onto the
|
|
592
|
+
// clipboard: a failed write turns cut into a no-op.
|
|
593
|
+
self.writeClipboard(text) catch return;
|
|
594
|
+
event.keyboard.edit = .{ .insert_text = "" };
|
|
595
|
+
},
|
|
596
|
+
.paste => {
|
|
597
|
+
const event = keyboard_event orelse return;
|
|
598
|
+
const target = event.target orelse return;
|
|
599
|
+
const node_index = self.views[index].canvasWidgetNodeIndexById(target.id) orelse return;
|
|
600
|
+
const widget = self.views[index].widget_layout_nodes[node_index].widget;
|
|
601
|
+
if (!canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return;
|
|
602
|
+
// An empty or unavailable clipboard pastes nothing.
|
|
603
|
+
const text = self.readClipboard(paste_buffer) catch return;
|
|
604
|
+
if (text.len == 0) return;
|
|
605
|
+
const clamp = canvas_widget_runtime.clampCanvasWidgetPasteText(widget, self.views[index].widget_text_len, text);
|
|
606
|
+
event.keyboard.edit_truncated = clamp.truncated;
|
|
607
|
+
if (clamp.text.len == 0) return;
|
|
608
|
+
event.keyboard.edit = .{ .insert_text = clamp.text };
|
|
609
|
+
},
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
fn canvasWidgetEditableSelectionText(self: *Runtime, view_index: usize, target: canvas.WidgetFocusTarget) ?[]const u8 {
|
|
614
|
+
const node_index = self.views[view_index].canvasWidgetNodeIndexById(target.id) orelse return null;
|
|
615
|
+
const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
|
|
616
|
+
if (!canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return null;
|
|
617
|
+
const range = canvas.widgetTextSelectionRange(widget) orelse return null;
|
|
618
|
+
if (range.isCollapsed(widget.text.len)) return null;
|
|
619
|
+
return widget.text[range.start..range.end];
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
pub fn updateCanvasWidgetTextFromKeyboard(self: *Runtime, keyboard_event: CanvasWidgetKeyboardEvent) anyerror!void {
|
|
623
|
+
const index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse return;
|
|
624
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
625
|
+
const target = keyboard_event.target orelse return;
|
|
626
|
+
const edit = self.views[index].canvasWidgetKeyboardTextEdit(target, keyboard_event.keyboard) orelse return;
|
|
627
|
+
|
|
628
|
+
const dirty = try self.views[index].applyCanvasWidgetTextEdit(target.id, edit) orelse return;
|
|
629
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
630
|
+
self.invalidateFor(.state, dirty_region);
|
|
631
|
+
} else {
|
|
632
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
633
|
+
}
|
|
634
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
pub fn updateCanvasWidgetTextFromPointer(self: *Runtime, pointer_event: *CanvasWidgetPointerEvent) anyerror!void {
|
|
638
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
639
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
640
|
+
|
|
641
|
+
const target_id: canvas.ObjectId = switch (pointer_event.pointer.phase) {
|
|
642
|
+
.down => if (pointer_event.target) |target| target.id else 0,
|
|
643
|
+
.move => self.views[index].canvas_widget_pressed_id,
|
|
644
|
+
else => return,
|
|
645
|
+
};
|
|
646
|
+
// Pressing anywhere outside the selected static text drops
|
|
647
|
+
// the selection (macOS-style single live selection).
|
|
648
|
+
if (pointer_event.pointer.phase == .down and
|
|
649
|
+
self.views[index].canvas_widget_selected_text_id != 0 and
|
|
650
|
+
self.views[index].canvas_widget_selected_text_id != target_id)
|
|
651
|
+
{
|
|
652
|
+
if (try self.views[index].clearCanvasWidgetStaticTextSelection()) |dirty| {
|
|
653
|
+
try invalidateForCanvasWidgetDirty(self, index, dirty);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (target_id == 0) return;
|
|
657
|
+
|
|
658
|
+
// The search field's built-in clear affordance: a press
|
|
659
|
+
// inside the trailing clear region clears through the
|
|
660
|
+
// standard text-edit path instead of placing the caret, and
|
|
661
|
+
// the edit is stamped onto the event so the app's `on_input`
|
|
662
|
+
// hears it (the clipboard cut/paste precedent).
|
|
663
|
+
if (pointer_event.pointer.phase == .down) {
|
|
664
|
+
if (try applyCanvasWidgetClearButtonPress(self, index, target_id, pointer_event.pointer.point)) {
|
|
665
|
+
pointer_event.edit = .clear;
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const dirty = try self.views[index].applyCanvasWidgetTextPointer(
|
|
671
|
+
target_id,
|
|
672
|
+
pointer_event.pointer.point,
|
|
673
|
+
pointer_event.pointer.phase == .move,
|
|
674
|
+
pointer_event.pointer.click_count,
|
|
675
|
+
) orelse return;
|
|
676
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
677
|
+
self.invalidateFor(.state, dirty_region);
|
|
678
|
+
} else {
|
|
679
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
680
|
+
}
|
|
681
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/// Apply the search field's built-in clear when `point` presses
|
|
685
|
+
/// its trailing clear region: the standard text-edit path (so
|
|
686
|
+
/// selection/composition state resets exactly like Escape's
|
|
687
|
+
/// clear). Returns whether the press was consumed.
|
|
688
|
+
fn applyCanvasWidgetClearButtonPress(self: *Runtime, index: usize, target_id: canvas.ObjectId, point: geometry.PointF) anyerror!bool {
|
|
689
|
+
const node_index = self.views[index].canvasWidgetNodeIndexById(target_id) orelse return false;
|
|
690
|
+
const widget = self.views[index].widget_layout_nodes[node_index].widget;
|
|
691
|
+
const hit_rect = canvas.textInputClearButtonHitRect(widget, self.views[index].widget_tokens) orelse return false;
|
|
692
|
+
if (!hit_rect.containsPoint(point)) return false;
|
|
693
|
+
const dirty = try self.views[index].applyCanvasWidgetTextEdit(target_id, .clear) orelse return true;
|
|
694
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
695
|
+
self.invalidateFor(.state, dirty_region);
|
|
696
|
+
} else {
|
|
697
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
698
|
+
}
|
|
699
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
700
|
+
return true;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
pub fn updateCanvasWidgetControlFromPointer(self: *Runtime, pointer_event: CanvasWidgetPointerEvent) anyerror!void {
|
|
704
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
705
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
706
|
+
|
|
707
|
+
// Control activation resolves through the press fall-through:
|
|
708
|
+
// the target is the claiming widget (a press on a list item's
|
|
709
|
+
// text activates the item) and the stored raw pressed id is
|
|
710
|
+
// resolved through the same walk so the two compare equal for
|
|
711
|
+
// one gesture. For controls hit directly (checkbox, slider,
|
|
712
|
+
// chip) both resolve to themselves — behavior is unchanged.
|
|
713
|
+
const resolved_pressed_id = canvasWidgetResolvedPressedId(self, index, self.views[index].canvas_widget_pressed_id);
|
|
714
|
+
const toggle_animation = self.views[index].canvasWidgetToggleAnimationForPointer(
|
|
715
|
+
pointer_event.pointer,
|
|
716
|
+
pointer_event.press_target,
|
|
717
|
+
resolved_pressed_id,
|
|
718
|
+
);
|
|
719
|
+
const dirty = try self.views[index].applyCanvasWidgetControlPointer(
|
|
720
|
+
pointer_event.pointer,
|
|
721
|
+
pointer_event.press_target,
|
|
722
|
+
resolved_pressed_id,
|
|
723
|
+
) orelse return;
|
|
724
|
+
if (toggle_animation) |animation| try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).scheduleCanvasWidgetToggleAnimation(self, index, animation);
|
|
725
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
726
|
+
self.invalidateFor(.state, dirty_region);
|
|
727
|
+
} else {
|
|
728
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
729
|
+
}
|
|
730
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
pub fn updateCanvasWidgetControlFromKeyboard(self: *Runtime, keyboard_event: CanvasWidgetKeyboardEvent) anyerror!void {
|
|
734
|
+
const index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse return;
|
|
735
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
736
|
+
const target = keyboard_event.target orelse return;
|
|
737
|
+
|
|
738
|
+
const toggle_animation = self.views[index].canvasWidgetToggleAnimationForKeyboard(target.id, keyboard_event.keyboard);
|
|
739
|
+
const dirty = try self.views[index].applyCanvasWidgetControlKeyboard(target.id, keyboard_event.keyboard) orelse return;
|
|
740
|
+
if (toggle_animation) |animation| try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).scheduleCanvasWidgetToggleAnimation(self, index, animation);
|
|
741
|
+
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
742
|
+
if (target.kind == .scroll_view) self.views[index].reconcileCanvasWidgetRenderStateAfterScroll(null);
|
|
743
|
+
if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
|
|
744
|
+
if (canvasDirtyRegionForView(self.views[index].frame, dirty)) |dirty_region| {
|
|
745
|
+
self.invalidateFor(.state, dirty_region);
|
|
746
|
+
} else {
|
|
747
|
+
self.invalidateFor(.state, self.views[index].frame);
|
|
748
|
+
}
|
|
749
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, index);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/// Returns the dismissed surface's widget id (0 when nothing was
|
|
753
|
+
/// dismissed). The caller dispatches the `canvas_widget_dismiss`
|
|
754
|
+
/// app event at the END of input processing — an app dispatch
|
|
755
|
+
/// rebuilds the tree, and the rest of the input pipeline still
|
|
756
|
+
/// routes into the current one.
|
|
757
|
+
pub fn dismissCanvasWidgetSurfaceFromPointerInput(self: *Runtime, pointer_event: CanvasWidgetPointerEvent) anyerror!canvas.ObjectId {
|
|
758
|
+
if (pointer_event.pointer.phase != .down) return 0;
|
|
759
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return 0;
|
|
760
|
+
if (self.views[index].kind != .gpu_surface or !self.views[index].focused) return 0;
|
|
761
|
+
const focused_id = self.views[index].canvas_widget_focused_id;
|
|
762
|
+
if (focused_id == 0) return 0;
|
|
763
|
+
|
|
764
|
+
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
765
|
+
const dismissal = try self.views[index].dismissCanvasWidgetSurfaceForPointerOutsideFocusedTarget(focused_id, pointer_event.route) orelse return 0;
|
|
766
|
+
if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
|
|
767
|
+
try invalidateForCanvasWidgetDirty(self, index, dismissal.dirty);
|
|
768
|
+
return dismissal.id;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/// Same contract as the pointer variant: returns the dismissed
|
|
772
|
+
/// surface's id (0 = none); the caller dispatches the app event.
|
|
773
|
+
/// Two keys dismiss: Escape (any dismissible surface, with the
|
|
774
|
+
/// topmost-mounted fallback) and Tab (focus departure — but ONLY
|
|
775
|
+
/// when the keyboard sits inside an open menu or on its trigger;
|
|
776
|
+
/// the menu closes uncommitted and the Tab is consumed, leaving
|
|
777
|
+
/// focus back on the trigger).
|
|
778
|
+
pub fn dismissCanvasWidgetSurfaceFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent) anyerror!canvas.ObjectId {
|
|
779
|
+
if (input_event.kind != .key_down) return 0;
|
|
780
|
+
const escape = canvasWidgetEscapeKey(input_event.key);
|
|
781
|
+
const tab = std.ascii.eqlIgnoreCase(input_event.key, "tab");
|
|
782
|
+
if (!escape and !tab) return 0;
|
|
783
|
+
const modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers);
|
|
784
|
+
if (modifiers.hasNavigationModifier()) return 0;
|
|
785
|
+
// Shift+Tab is still focus departure; Shift+Escape is not a
|
|
786
|
+
// dismissal chord at all.
|
|
787
|
+
if (escape and modifiers.shift) return 0;
|
|
788
|
+
|
|
789
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return 0;
|
|
790
|
+
if (self.views[index].kind != .gpu_surface or !self.views[index].focused) return 0;
|
|
791
|
+
// Deliberately NOT gated on a focused widget: a surface
|
|
792
|
+
// opened from a non-focusable trigger (a text crumb) floats
|
|
793
|
+
// with nothing focused, and Escape must still find it — the
|
|
794
|
+
// view method falls back to the topmost mounted anchored
|
|
795
|
+
// surface when the focus chain yields none.
|
|
796
|
+
const focused_id = self.views[index].canvas_widget_focused_id;
|
|
797
|
+
// Tab-away has no fallback: with nothing focused there is no
|
|
798
|
+
// focus to depart, so an unrelated Tab never tears down a
|
|
799
|
+
// floating menu the way Escape deliberately does.
|
|
800
|
+
if (tab and focused_id == 0) return 0;
|
|
801
|
+
|
|
802
|
+
const previous_cursor = self.views[index].canvas_widget_cursor;
|
|
803
|
+
const dismissal = (if (tab)
|
|
804
|
+
try self.views[index].dismissCanvasWidgetMenuSurfaceForFocusDeparture(focused_id)
|
|
805
|
+
else
|
|
806
|
+
try self.views[index].dismissCanvasWidgetSurfaceFromEscape(focused_id)) orelse return 0;
|
|
807
|
+
if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
|
|
808
|
+
try invalidateForCanvasWidgetDirty(self, index, dismissal.dirty);
|
|
809
|
+
return dismissal.id;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/// Every dismissal source (Escape, outside pointer, automation and
|
|
813
|
+
/// accessibility dismiss actions) delivers the dismissed surface's
|
|
814
|
+
/// id to the app, so a TEA model with an `on_dismiss` handler owns
|
|
815
|
+
/// the close instead of relying on the engine's transient hide.
|
|
816
|
+
pub fn dispatchCanvasWidgetDismissEvent(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, surface_id: canvas.ObjectId) anyerror!void {
|
|
817
|
+
if (surface_id == 0) return;
|
|
818
|
+
try self.dispatchEvent(app, .{ .canvas_widget_dismiss = .{
|
|
819
|
+
.window_id = self.views[view_index].window_id,
|
|
820
|
+
.view_label = self.views[view_index].label,
|
|
821
|
+
.id = surface_id,
|
|
822
|
+
} });
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
pub fn dispatchCanvasWidgetCommandForId(self: *Runtime, app: runtime_api.App(Runtime), view_index: usize, id: canvas.ObjectId) anyerror!void {
|
|
826
|
+
if (view_index >= self.view_count) return error.ViewNotFound;
|
|
827
|
+
const node_index = self.views[view_index].canvasWidgetNodeIndexById(id) orelse return;
|
|
828
|
+
const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
|
|
829
|
+
if (!canvasWidgetCommandable(widget.kind)) return;
|
|
830
|
+
const command = self.views[view_index].canvasWidgetCommand(id) orelse return;
|
|
831
|
+
try self.dispatchCommand(app, .{
|
|
832
|
+
.name = command,
|
|
833
|
+
.source = .native_view,
|
|
834
|
+
.window_id = self.views[view_index].window_id,
|
|
835
|
+
.view_label = self.views[view_index].label,
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
pub fn dispatchCanvasWidgetCommandFromPointer(self: *Runtime, app: runtime_api.App(Runtime), pointer_event: CanvasWidgetPointerEvent) anyerror!void {
|
|
840
|
+
const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
|
|
841
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
842
|
+
const target = pointer_event.target orelse return;
|
|
843
|
+
// Engine-owned command dispatch fires on the resolved press
|
|
844
|
+
// target, so a `command` list item/data cell activates when
|
|
845
|
+
// its text children are pressed. The gesture discipline stays
|
|
846
|
+
// on the raw hit (the same widget must start and end the
|
|
847
|
+
// press); the release may land anywhere within the claiming
|
|
848
|
+
// widget's bounds or the raw target's own bounds.
|
|
849
|
+
const press = pointer_event.press_target orelse return;
|
|
850
|
+
switch (pointer_event.pointer.phase) {
|
|
851
|
+
.down => {
|
|
852
|
+
if (!canvasWidgetCommandFiresOnPointerDown(press.kind)) return;
|
|
853
|
+
if (!canvasWidgetPressReleaseInBounds(press, target, pointer_event.pointer.point)) return;
|
|
854
|
+
try dispatchCanvasWidgetCommandForId(self, app, index, press.id);
|
|
855
|
+
},
|
|
856
|
+
.up => {
|
|
857
|
+
if (canvasWidgetCommandFiresOnPointerDown(press.kind)) return;
|
|
858
|
+
const pressed_id = if (pointer_event.pointer.captured_id != 0) pointer_event.pointer.captured_id else self.views[index].canvas_widget_pressed_id;
|
|
859
|
+
if (pressed_id != target.id) return;
|
|
860
|
+
if (!canvasWidgetPressReleaseInBounds(press, target, pointer_event.pointer.point)) return;
|
|
861
|
+
try dispatchCanvasWidgetCommandForId(self, app, index, press.id);
|
|
862
|
+
},
|
|
863
|
+
.hover, .move, .cancel, .wheel => return,
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
fn canvasWidgetPressReleaseInBounds(press: canvas.WidgetHit, target: canvas.WidgetHit, point: geometry.PointF) bool {
|
|
868
|
+
if (press.bounds.normalized().containsPoint(point)) return true;
|
|
869
|
+
return press.id != target.id and target.bounds.normalized().containsPoint(point);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
pub fn dispatchCanvasWidgetCommandFromKeyboard(self: *Runtime, app: runtime_api.App(Runtime), keyboard_event: CanvasWidgetKeyboardEvent) anyerror!void {
|
|
873
|
+
if (keyboard_event.keyboard.phase != .key_down or keyboard_event.keyboard.modifiers.hasNavigationModifier()) return;
|
|
874
|
+
const target = keyboard_event.target orelse return;
|
|
875
|
+
// Activation keys press any commandable target; the menu-open
|
|
876
|
+
// arrows press select/combobox triggers too — the same keymap
|
|
877
|
+
// the control-intent resolver applies for `on_press`, kept in
|
|
878
|
+
// lockstep so command-string apps open their pickers from the
|
|
879
|
+
// keyboard exactly like TEA apps.
|
|
880
|
+
const arrow_opens = (target.kind == .select or target.kind == .combobox) and
|
|
881
|
+
canvas.isWidgetMenuOpenArrowKey(keyboard_event.keyboard.key) and
|
|
882
|
+
!(target.state.expanded orelse false);
|
|
883
|
+
if (!canvas.isWidgetActivationKey(keyboard_event.keyboard.key) and !arrow_opens) return;
|
|
884
|
+
if (arrow_opens and keyboard_event.keyboard.focus_moved) return;
|
|
885
|
+
const index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse return;
|
|
886
|
+
if (self.views[index].kind != .gpu_surface) return;
|
|
887
|
+
try dispatchCanvasWidgetCommandForId(self, app, index, target.id);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/// Returns true when the key moved keyboard focus to a DIFFERENT
|
|
891
|
+
/// widget — the caller stamps it onto the routed keyboard event
|
|
892
|
+
/// (`focus_moved`) so tree rows can tell selection-follows-focus
|
|
893
|
+
/// arrivals from in-place collapse/expand intents.
|
|
894
|
+
pub fn updateCanvasWidgetFocusFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent) anyerror!bool {
|
|
895
|
+
if (input_event.kind != .key_down) return false;
|
|
896
|
+
const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
|
|
897
|
+
if (self.views[index].kind != .gpu_surface) return false;
|
|
898
|
+
|
|
899
|
+
const current_id: ?canvas.ObjectId = if (self.views[index].canvas_widget_focused_id == 0) null else self.views[index].canvas_widget_focused_id;
|
|
900
|
+
if (std.ascii.eqlIgnoreCase(input_event.key, "tab")) {
|
|
901
|
+
const direction: canvas.WidgetFocusDirection = if (input_event.modifiers.shift) .backward else .forward;
|
|
902
|
+
const target = if (current_id) |id|
|
|
903
|
+
self.views[index].canvasWidgetScopedFocusTarget(id, direction) orelse self.views[index].widgetLayoutTree().focusTarget(current_id, direction) orelse return false
|
|
904
|
+
else
|
|
905
|
+
self.views[index].widgetLayoutTree().focusTarget(current_id, direction) orelse return false;
|
|
906
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
const focused_id = current_id orelse return false;
|
|
910
|
+
const layout = self.views[index].widgetLayoutTree();
|
|
911
|
+
const focused = layout.focusTargetById(focused_id) orelse return false;
|
|
912
|
+
// FRAMEWORK BEHAVIOR CHANGE (deliberate, scoped — the same
|
|
913
|
+
// seam as the keyboard-routing gate below): arrows and
|
|
914
|
+
// Home/End never escalate QUIET focus on a plain list row
|
|
915
|
+
// into the visible ring register. Only Tab (handled above)
|
|
916
|
+
// enters the keyboard-contract; from quiet row focus the
|
|
917
|
+
// navigation keys fall through to the app, whose selection
|
|
918
|
+
// model owns them. Ring-visible rows keep the full group
|
|
919
|
+
// walk unchanged; tree rows are exempt.
|
|
920
|
+
if (canvasWidgetQuietListRowFocus(self, index, focused_id)) return false;
|
|
921
|
+
if (canvasWidgetGroupFocusEdgeFromInput(input_event)) |edge| {
|
|
922
|
+
// A tree row's Home/End jump to the SCOPE's edges (rows
|
|
923
|
+
// nest, so the group edge walk's same-parent rule would
|
|
924
|
+
// stop at one level).
|
|
925
|
+
if (canvas_widget_runtime.canvasWidgetTreeFocusEdgeTarget(layout, focused, edge)) |target| {
|
|
926
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
927
|
+
}
|
|
928
|
+
const target = canvasWidgetGroupFocusEdgeTarget(layout, focused, edge) orelse return false;
|
|
929
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
930
|
+
}
|
|
931
|
+
const direction = canvasWidgetSpatialFocusDirection(input_event) orelse return false;
|
|
932
|
+
// The open-select keymap: ArrowDown/Up on a select/combobox
|
|
933
|
+
// trigger whose anchored menu is MOUNTED moves the keyboard
|
|
934
|
+
// into the menu (the marked row when one is selected, else
|
|
935
|
+
// the first/last row). Without a mounted menu the arrows fall
|
|
936
|
+
// through to the control resolver, which turns them into the
|
|
937
|
+
// trigger's press — the model-owned open.
|
|
938
|
+
if ((focused.kind == .select or focused.kind == .combobox) and (direction == .down or direction == .up)) {
|
|
939
|
+
if (self.views[index].canvasWidgetOwnedMenuSurfaceIndex(focused.index)) |surface_index| {
|
|
940
|
+
if (self.views[index].canvasWidgetMenuSurfaceEntryId(surface_index, direction == .up)) |entry_id| {
|
|
941
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, entry_id);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
// The ARIA tree keymap first: Up/Down walk the scope's
|
|
946
|
+
// visible rows, Left/Right move to parent / first child when
|
|
947
|
+
// they are moves (collapse/expand stay routed intents).
|
|
948
|
+
if (canvas_widget_runtime.canvasWidgetTreeDirectionalFocusTarget(layout, focused, direction)) |target| {
|
|
949
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
950
|
+
}
|
|
951
|
+
if (canvasWidgetGroupDirectionalFocusTarget(layout, focused, direction)) |target| {
|
|
952
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
953
|
+
}
|
|
954
|
+
const target = layout.focusTarget(focused_id, direction) orelse return false;
|
|
955
|
+
if (!canvasWidgetSpatialFocusAllowed(layout, focused, target, direction)) return false;
|
|
956
|
+
return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
fn setCanvasWidgetFocusFromKeyboardMoved(self: *Runtime, view_index: usize, previous_id: ?canvas.ObjectId, target_id: canvas.ObjectId) anyerror!bool {
|
|
960
|
+
try setCanvasWidgetFocusFromKeyboard(self, view_index, target_id);
|
|
961
|
+
const previous = previous_id orelse 0;
|
|
962
|
+
return target_id != 0 and target_id != previous;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
pub fn setCanvasWidgetFocusFromKeyboard(self: *Runtime, view_index: usize, target_id: canvas.ObjectId) anyerror!void {
|
|
966
|
+
if (self.views[view_index].canvas_widget_focused_id == target_id and self.views[view_index].canvas_widget_focus_visible_id == target_id) return;
|
|
967
|
+
const previous_state = self.views[view_index].canvasWidgetRenderState();
|
|
968
|
+
self.views[view_index].canvas_widget_focused_id = target_id;
|
|
969
|
+
self.views[view_index].canvas_widget_focus_visible_id = target_id;
|
|
970
|
+
// Keyboard focus landing on an editable establishes a caret:
|
|
971
|
+
// without a selection the emitters draw no caret line, so a
|
|
972
|
+
// tabbed-into field would render its ring but no insertion
|
|
973
|
+
// point. Collapse at the end of the text, the plain caret
|
|
974
|
+
// placement; a selection the widget already carries survives.
|
|
975
|
+
if (target_id != 0 and self.views[view_index].canEditCanvasWidgetText(target_id)) {
|
|
976
|
+
if (self.views[view_index].canvasWidgetNodeIndexById(target_id)) |node_index| {
|
|
977
|
+
const widget = &self.views[view_index].widget_layout_nodes[node_index].widget;
|
|
978
|
+
if (widget.text_selection == null) {
|
|
979
|
+
widget.text_selection = canvas.TextSelection.collapsed(widget.text.len);
|
|
980
|
+
try self.views[view_index].refreshCanvasWidgetSemantics();
|
|
981
|
+
self.views[view_index].widget_revision += 1;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
try invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
pub fn invalidateForWidgetInvalidations(self: *Runtime, view_frame: geometry.RectF, invalidations: []const canvas.WidgetInvalidation) void {
|
|
989
|
+
var emitted_dirty_region = false;
|
|
990
|
+
for (invalidations) |invalidation| {
|
|
991
|
+
const local_dirty = invalidation.dirty_bounds orelse continue;
|
|
992
|
+
if (canvasDirtyRegionForView(view_frame, local_dirty)) |dirty_region| {
|
|
993
|
+
self.invalidateFor(.state, dirty_region);
|
|
994
|
+
emitted_dirty_region = true;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (!emitted_dirty_region and invalidations.len > 0) self.invalidateFor(.state, null);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
pub fn invalidateForCanvasWidgetDirty(self: *Runtime, view_index: usize, dirty: geometry.RectF) anyerror!void {
|
|
1001
|
+
if (canvasDirtyRegionForView(self.views[view_index].frame, dirty)) |dirty_region| {
|
|
1002
|
+
self.invalidateFor(.state, dirty_region);
|
|
1003
|
+
} else {
|
|
1004
|
+
self.invalidateFor(.state, self.views[view_index].frame);
|
|
1005
|
+
}
|
|
1006
|
+
_ = try runtime_canvas_widget_display.RuntimeCanvasWidgetDisplay(Runtime).refreshCanvasWidgetDisplayListIfOwned(self, view_index);
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
fn validateRuntimeViewParent(self: anytype, window_id: platform.WindowId) !void {
|
|
1012
|
+
const index = runtimeFindWindowIndexById(self, window_id) orelse return error.WindowNotFound;
|
|
1013
|
+
if (!self.windows[index].info.open) return error.WindowNotFound;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
fn runtimeFindWindowIndexById(self: anytype, id: platform.WindowId) ?usize {
|
|
1017
|
+
for (self.windows[0..self.window_count], 0..) |window, index| {
|
|
1018
|
+
if (window.info.id == id) return index;
|
|
1019
|
+
}
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
fn runtimeFindViewIndex(self: anytype, window_id: platform.WindowId, label: []const u8) ?usize {
|
|
1024
|
+
for (self.views[0..self.view_count], 0..) |*view, index| {
|
|
1025
|
+
if (view.open and view.window_id == window_id and std.mem.eql(u8, view.label, label)) return index;
|
|
1026
|
+
}
|
|
1027
|
+
return null;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
fn canvasDirtyRegionForView(view_frame: geometry.RectF, local_dirty: geometry.RectF) ?geometry.RectF {
|
|
1031
|
+
const normalized_view = view_frame.normalized();
|
|
1032
|
+
const surface_bounds = geometry.RectF.init(0, 0, normalized_view.width, normalized_view.height);
|
|
1033
|
+
const clipped = geometry.RectF.intersection(surface_bounds, local_dirty.normalized());
|
|
1034
|
+
if (clipped.isEmpty()) return null;
|
|
1035
|
+
return clipped.translate(.{ .dx = normalized_view.x, .dy = normalized_view.y });
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/// Collect the layout's window-drag region mirror: every visible
|
|
1039
|
+
/// `window_drag` widget's frame, each followed by the frames of the
|
|
1040
|
+
/// press-claiming widgets inside it as `exclusion` entries — the same
|
|
1041
|
+
/// carve-outs `widgetWindowDragTargetIndexFromNode` applies point by
|
|
1042
|
+
/// point, precomputed as rectangles for platforms that answer a native
|
|
1043
|
+
/// hit-test (Windows `WM_NCHITTEST`). Frames are the canvas view's
|
|
1044
|
+
/// local logical coordinates, exactly as retained. Regions are
|
|
1045
|
+
/// appended transactionally: when the output fills mid-region the
|
|
1046
|
+
/// WHOLE region rolls back, because a drag rect without its exclusions
|
|
1047
|
+
/// would hand a button's press to the OS move loop, while a missing
|
|
1048
|
+
/// drag rect only loses dragging on that band.
|
|
1049
|
+
pub fn collectCanvasWidgetWindowDragRegions(layout: canvas.WidgetLayoutTree, output: []platform.WindowDragRegion) usize {
|
|
1050
|
+
var count: usize = 0;
|
|
1051
|
+
for (layout.nodes, 0..) |node, node_index| {
|
|
1052
|
+
if (!canvas.widgetIsWindowDragRegion(node.widget)) continue;
|
|
1053
|
+
if (canvas_widget_runtime.canvasWidgetLayoutNodeHidden(layout, node_index)) continue;
|
|
1054
|
+
if (!canvas_widget_runtime.canvasWidgetLayoutNodeFrameVisible(layout, node_index)) continue;
|
|
1055
|
+
const region_start = count;
|
|
1056
|
+
if (count >= output.len) break;
|
|
1057
|
+
output[count] = .{ .frame = node.frame.normalized() };
|
|
1058
|
+
count += 1;
|
|
1059
|
+
var overflow = false;
|
|
1060
|
+
for (layout.nodes, 0..) |candidate, candidate_index| {
|
|
1061
|
+
if (candidate_index == node_index) continue;
|
|
1062
|
+
if (!canvas.widgetClaimsPress(candidate.widget)) continue;
|
|
1063
|
+
if (canvas_widget_runtime.canvasWidgetLayoutNodeHidden(layout, candidate_index)) continue;
|
|
1064
|
+
if (!canvas_widget_runtime.canvasWidgetLayoutNodeFrameVisible(layout, candidate_index)) continue;
|
|
1065
|
+
if (!canvasWidgetNodeHasAncestor(layout, candidate_index, node_index)) continue;
|
|
1066
|
+
if (count >= output.len) {
|
|
1067
|
+
overflow = true;
|
|
1068
|
+
break;
|
|
1069
|
+
}
|
|
1070
|
+
output[count] = .{ .frame = candidate.frame.normalized(), .exclusion = true };
|
|
1071
|
+
count += 1;
|
|
1072
|
+
}
|
|
1073
|
+
if (overflow) {
|
|
1074
|
+
count = region_start;
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
return count;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
fn canvasWidgetNodeHasAncestor(layout: canvas.WidgetLayoutTree, node_index: usize, ancestor_index: usize) bool {
|
|
1082
|
+
if (node_index >= layout.nodes.len) return false;
|
|
1083
|
+
var current: ?usize = layout.nodes[node_index].parent_index;
|
|
1084
|
+
while (current) |index| {
|
|
1085
|
+
if (index >= layout.nodes.len) return false;
|
|
1086
|
+
if (index == ancestor_index) return true;
|
|
1087
|
+
current = layout.nodes[index].parent_index;
|
|
1088
|
+
}
|
|
1089
|
+
return false;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
fn windowDragRegionsEqual(a: []const platform.WindowDragRegion, b: []const platform.WindowDragRegion) bool {
|
|
1093
|
+
if (a.len != b.len) return false;
|
|
1094
|
+
for (a, b) |left, right| {
|
|
1095
|
+
if (!std.meta.eql(left, right)) return false;
|
|
1096
|
+
}
|
|
1097
|
+
return true;
|
|
1098
|
+
}
|