@native-sdk/cli 0.10.1 → 0.11.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.
Files changed (555) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +393 -97
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +2030 -83
  8. package/native-sdk.d.ts +5 -1
  9. package/package.json +20 -14
  10. package/packages/core/compile-surface/core.ts +164 -72
  11. package/packages/core/package-lock.json +75 -357
  12. package/packages/core/package.json +25 -4
  13. package/packages/core/scripts/compiler_command.mjs +17 -12
  14. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  15. package/packages/core/scripts/gen_declarations.mjs +3 -2
  16. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  17. package/packages/core/scripts/install_scriptc.mjs +182 -0
  18. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  19. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  20. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  21. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  22. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  23. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  24. package/packages/core/scripts/run_native_tests.mjs +22 -0
  25. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  26. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  27. package/packages/core/scripts/stage_external_core.mjs +68 -1
  28. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  29. package/packages/core/sdk/bytes.d.ts +2 -0
  30. package/packages/core/sdk/bytes.ts +86 -0
  31. package/packages/core/sdk/core.d.ts +332 -5
  32. package/packages/core/sdk/core.ts +371 -85
  33. package/packages/core/sdk/events.d.ts +252 -0
  34. package/packages/core/sdk/events.ts +240 -2
  35. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  36. package/packages/core/sdk/internal/image_identity.ts +71 -0
  37. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  38. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  39. package/packages/core/sdk/text.d.ts +27 -0
  40. package/packages/core/sdk/text.ts +206 -15
  41. package/packages/core/sdk/theme.d.ts +251 -0
  42. package/packages/core/sdk/theme.ts +267 -0
  43. package/packages/core/src/authorization.ts +137 -0
  44. package/packages/core/src/automation_commands.ts +201 -0
  45. package/packages/core/src/automation_interactions.ts +92 -0
  46. package/packages/core/src/bridge_descriptors.ts +104 -0
  47. package/packages/core/src/builtin_coordination.ts +172 -0
  48. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  49. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  50. package/packages/core/src/canvas_scene_observation.ts +145 -0
  51. package/packages/core/src/chart_content.ts +161 -0
  52. package/packages/core/src/chart_plans.ts +432 -0
  53. package/packages/core/src/checker.ts +186 -19
  54. package/packages/core/src/cli.ts +2 -11
  55. package/packages/core/src/code_content.ts +580 -0
  56. package/packages/core/src/command_coordination.ts +140 -0
  57. package/packages/core/src/component_composition.ts +94 -0
  58. package/packages/core/src/component_construction.ts +149 -0
  59. package/packages/core/src/context_menus.ts +76 -0
  60. package/packages/core/src/contract.ts +25 -7
  61. package/packages/core/src/control_appearance.ts +232 -0
  62. package/packages/core/src/control_commands.ts +115 -0
  63. package/packages/core/src/control_content.ts +105 -0
  64. package/packages/core/src/control_geometry.ts +107 -0
  65. package/packages/core/src/control_payloads.ts +119 -0
  66. package/packages/core/src/control_primitives.ts +134 -0
  67. package/packages/core/src/devhost.ts +82 -7
  68. package/packages/core/src/devhost_journal.mjs +30 -7
  69. package/packages/core/src/diagnostics.ts +7 -0
  70. package/packages/core/src/effect_plans.ts +71 -0
  71. package/packages/core/src/extent_program.ts +53 -0
  72. package/packages/core/src/flow_measurement.ts +121 -0
  73. package/packages/core/src/font_registry.ts +37 -0
  74. package/packages/core/src/frontend.ts +12 -10
  75. package/packages/core/src/glyph_atlas.ts +86 -0
  76. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  77. package/packages/core/src/gpu_planning.ts +123 -0
  78. package/packages/core/src/gpu_presentation.ts +55 -0
  79. package/packages/core/src/host_flow.ts +89 -0
  80. package/packages/core/src/host_input_regions.ts +165 -0
  81. package/packages/core/src/image_registry.ts +66 -0
  82. package/packages/core/src/indicator_plans.ts +132 -0
  83. package/packages/core/src/infer.ts +150 -8
  84. package/packages/core/src/input_composition.ts +116 -0
  85. package/packages/core/src/intrinsic_measure.ts +100 -0
  86. package/packages/core/src/layout_coordination.ts +207 -0
  87. package/packages/core/src/leaf_plans.ts +134 -0
  88. package/packages/core/src/markup_canonical.ts +140 -0
  89. package/packages/core/src/markup_construction.ts +189 -0
  90. package/packages/core/src/markup_development.ts +160 -0
  91. package/packages/core/src/markup_display.ts +43 -0
  92. package/packages/core/src/markup_document.ts +226 -0
  93. package/packages/core/src/markup_elements.ts +225 -0
  94. package/packages/core/src/markup_expressions.ts +79 -0
  95. package/packages/core/src/markup_imports.ts +146 -0
  96. package/packages/core/src/markup_parser.ts +228 -0
  97. package/packages/core/src/markup_runtime.ts +93 -0
  98. package/packages/core/src/markup_scalars.ts +143 -0
  99. package/packages/core/src/markup_shapes.ts +243 -0
  100. package/packages/core/src/markup_specialized.ts +242 -0
  101. package/packages/core/src/markup_text.ts +86 -0
  102. package/packages/core/src/markup_values.ts +336 -0
  103. package/packages/core/src/measurement_coordination.ts +185 -0
  104. package/packages/core/src/modules.ts +1 -1
  105. package/packages/core/src/motion_sampling.ts +100 -0
  106. package/packages/core/src/paragraph_layout.ts +192 -0
  107. package/packages/core/src/portable_sources.json +98 -0
  108. package/packages/core/src/portable_sources.ts +17 -0
  109. package/packages/core/src/registered_font.ts +92 -0
  110. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  111. package/packages/core/src/render_coordination.ts +170 -0
  112. package/packages/core/src/render_resources.ts +234 -0
  113. package/packages/core/src/runtime_policy.ts +3954 -0
  114. package/packages/core/src/scalar_text.ts +82 -0
  115. package/packages/core/src/scroll_mutation.ts +86 -0
  116. package/packages/core/src/scroll_tree.ts +86 -0
  117. package/packages/core/src/service_contract.ts +55 -3
  118. package/packages/core/src/session_codecs.ts +309 -0
  119. package/packages/core/src/shell_admission.ts +126 -0
  120. package/packages/core/src/shell_coordination.ts +93 -0
  121. package/packages/core/src/sqlite_cli.ts +14 -46
  122. package/packages/core/src/sqlite_codegen.ts +84 -0
  123. package/packages/core/src/staged_rebuild.ts +60 -0
  124. package/packages/core/src/status_validation.ts +232 -0
  125. package/packages/core/src/stream_policy.ts +63 -0
  126. package/packages/core/src/surface_recipes.ts +136 -0
  127. package/packages/core/src/system_admission.ts +60 -0
  128. package/packages/core/src/terminal_paint.ts +436 -0
  129. package/packages/core/src/text_document_width.ts +81 -0
  130. package/packages/core/src/text_measurement_cache.ts +69 -0
  131. package/packages/core/src/text_query_layout.ts +179 -0
  132. package/packages/core/src/text_run_layout.ts +410 -0
  133. package/packages/core/src/text_span_queries.ts +355 -0
  134. package/packages/core/src/typed_ast.ts +18 -1
  135. package/packages/core/src/types.ts +7 -5
  136. package/packages/core/src/vector_effects.ts +98 -0
  137. package/packages/core/src/vector_raster.ts +243 -0
  138. package/packages/core/src/view_bridge.ts +161 -0
  139. package/packages/core/src/view_check.ts +145 -0
  140. package/packages/core/src/view_components.ts +2415 -0
  141. package/packages/core/src/view_coordination.ts +198 -0
  142. package/packages/core/src/view_evaluator.ts +823 -0
  143. package/packages/core/src/view_frontend.ts +1102 -0
  144. package/packages/core/src/view_program.ts +221 -0
  145. package/packages/core/src/view_reload.ts +166 -0
  146. package/packages/core/src/view_reload_watch.ts +98 -0
  147. package/packages/core/src/view_sources.ts +34 -0
  148. package/packages/core/src/virtual_windows.ts +88 -0
  149. package/packages/core/src/web_panes.ts +67 -0
  150. package/packages/core/src/widget_audits.ts +202 -0
  151. package/packages/core/src/widget_changes.ts +258 -0
  152. package/packages/core/src/widget_continuity.ts +37 -0
  153. package/packages/core/src/widget_metrics.ts +139 -0
  154. package/packages/core/src/widget_motion.ts +171 -0
  155. package/packages/core/src/widget_paint.ts +272 -0
  156. package/packages/core/src/widget_paint_walk.ts +203 -0
  157. package/packages/core/src/widget_presentation.ts +141 -0
  158. package/packages/core/src/widget_reconcile.ts +63 -0
  159. package/packages/core/src/widget_retention.ts +62 -0
  160. package/packages/core/src/widget_routing.ts +262 -0
  161. package/packages/core/src/window_lifecycle.ts +92 -0
  162. package/packages/core/testing/index.ts +430 -0
  163. package/schemas/app.schema.json +13 -0
  164. package/skill-data/core/SKILL.md +2 -2
  165. package/skill-data/native-ui/SKILL.md +77 -18
  166. package/skill-data/ts-core/SKILL.md +117 -11
  167. package/skill-data/ts-services/SKILL.md +1 -1
  168. package/skill-data/ts-services/references/service-surface.md +288 -144
  169. package/src/app_runner/root.zig +39 -12
  170. package/src/app_runner/ts_compiled_view.zig +1702 -0
  171. package/src/app_runner/ts_core_main.zig +185 -14
  172. package/src/app_runner/ts_core_mobile.zig +25 -13
  173. package/src/automation/server.zig +57 -6
  174. package/src/automation/snapshot.zig +9 -637
  175. package/src/automation/snapshot_reference.zig +656 -0
  176. package/src/automation/snapshot_serialization.zig +566 -0
  177. package/src/embed/host.zig +2 -0
  178. package/src/embed/tests.zig +2 -0
  179. package/src/embed/ui_host.zig +2 -0
  180. package/src/platform/keyboard_input.zig +32 -0
  181. package/src/platform/linux/gtk_host.c +36 -24
  182. package/src/platform/linux/gtk_pixels.h +118 -0
  183. package/src/platform/linux/gtk_pixels_test.c +241 -0
  184. package/src/platform/linux/root.zig +4 -0
  185. package/src/platform/macos/appkit_host.h +7 -2
  186. package/src/platform/macos/appkit_host.m +219 -39
  187. package/src/platform/macos/cef_host.mm +15 -1
  188. package/src/platform/macos/global_shortcuts.zig +138 -0
  189. package/src/platform/macos/key_codes.zig +102 -0
  190. package/src/platform/macos/keyboard_input.zig +81 -0
  191. package/src/platform/macos/pointer_motion_test.m +96 -0
  192. package/src/platform/macos/root.zig +25 -3
  193. package/src/platform/macos/scroll_driver_test.m +105 -0
  194. package/src/platform/macos/spectrum_bins.h +34 -0
  195. package/src/platform/macos/spectrum_bins_test.c +56 -0
  196. package/src/platform/macos/text_keyboard_test.m +80 -0
  197. package/src/platform/macos/webview_inspection_test.m +106 -0
  198. package/src/platform/macos/widget_focus_test.m +66 -0
  199. package/src/platform/null_platform.zig +130 -2
  200. package/src/platform/null_platform_tests.zig +13 -0
  201. package/src/platform/root.zig +15 -0
  202. package/src/platform/types.zig +115 -0
  203. package/src/platform/windows/global_shortcuts.zig +157 -0
  204. package/src/platform/windows/key_codes.zig +63 -0
  205. package/src/platform/windows/keyboard_input.zig +136 -0
  206. package/src/platform/windows/root.zig +17 -0
  207. package/src/platform/windows/webview2_host.cpp +7 -2
  208. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  209. package/src/primitives/app_manifest/root.zig +2 -0
  210. package/src/primitives/app_manifest/tests.zig +4 -1
  211. package/src/primitives/app_manifest/validation.zig +2 -0
  212. package/src/primitives/canvas/a11y_audit.zig +3 -1
  213. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  214. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  215. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  216. package/src/primitives/canvas/code_content_policy.zig +162 -0
  217. package/src/primitives/canvas/commands.zig +29 -1
  218. package/src/primitives/canvas/component_composition.zig +125 -0
  219. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  220. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  221. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  222. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  223. package/src/primitives/canvas/control_command_policy.zig +75 -0
  224. package/src/primitives/canvas/control_content_policy.zig +90 -0
  225. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  226. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  227. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  228. package/src/primitives/canvas/decision_reuse.zig +133 -0
  229. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  230. package/src/primitives/canvas/events.zig +1027 -1
  231. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  232. package/src/primitives/canvas/font_ttf.zig +27 -3
  233. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  234. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  235. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  236. package/src/primitives/canvas/fonts/README.md +15 -0
  237. package/src/primitives/canvas/frame.zig +92 -23
  238. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  239. package/src/primitives/canvas/gpu.zig +10 -0
  240. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  241. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  242. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  243. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  244. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  245. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  246. package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
  247. package/src/primitives/canvas/layout_audit.zig +5 -2
  248. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  249. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  250. package/src/primitives/canvas/markdown.zig +13 -3
  251. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  252. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  253. package/src/primitives/canvas/markdown_tests.zig +3 -3
  254. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  255. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  256. package/src/primitives/canvas/reference.zig +15 -11
  257. package/src/primitives/canvas/reference_tests.zig +58 -0
  258. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  259. package/src/primitives/canvas/render.zig +48 -0
  260. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  261. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  262. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  263. package/src/primitives/canvas/render_effects.zig +14 -0
  264. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  265. package/src/primitives/canvas/render_images.zig +14 -0
  266. package/src/primitives/canvas/render_layers.zig +14 -0
  267. package/src/primitives/canvas/render_override_policy.zig +119 -0
  268. package/src/primitives/canvas/render_paths.zig +14 -0
  269. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  270. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  271. package/src/primitives/canvas/root.zig +107 -4
  272. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  273. package/src/primitives/canvas/serialization.zig +8 -1
  274. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  275. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  276. package/src/primitives/canvas/terminal_grid.zig +10 -696
  277. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  278. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  279. package/src/primitives/canvas/text.zig +1 -0
  280. package/src/primitives/canvas/text_atlas.zig +113 -0
  281. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  282. package/src/primitives/canvas/text_document_policy.zig +120 -0
  283. package/src/primitives/canvas/text_layout.zig +51 -2
  284. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  285. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  286. package/src/primitives/canvas/text_layout_types.zig +3 -0
  287. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  288. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  289. package/src/primitives/canvas/text_metrics.zig +53 -37
  290. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  291. package/src/primitives/canvas/text_query_policy.zig +295 -0
  292. package/src/primitives/canvas/text_run_policy.zig +252 -0
  293. package/src/primitives/canvas/text_scalar_policy.zig +234 -0
  294. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  295. package/src/primitives/canvas/text_spans.zig +280 -8
  296. package/src/primitives/canvas/text_tests.zig +10 -0
  297. package/src/primitives/canvas/tokens.zig +47 -0
  298. package/src/primitives/canvas/ui.zig +251 -83
  299. package/src/primitives/canvas/ui_markup.zig +207 -46
  300. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  301. package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
  302. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  303. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  304. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  305. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  306. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  307. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  308. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  309. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  310. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  311. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  312. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  313. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  314. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  315. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  316. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  317. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  318. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  319. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  320. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  321. package/src/primitives/canvas/ui_markup_view.zig +3026 -57
  322. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  323. package/src/primitives/canvas/ui_schema.zig +13 -1
  324. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  325. package/src/primitives/canvas/ui_tests.zig +1 -0
  326. package/src/primitives/canvas/vector.zig +36 -2
  327. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  328. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  329. package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
  330. package/src/primitives/canvas/virtual_extents.zig +113 -3
  331. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  332. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  333. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  334. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  335. package/src/primitives/canvas/widget_layout.zig +673 -128
  336. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  337. package/src/primitives/canvas/widget_metric_policy.zig +129 -0
  338. package/src/primitives/canvas/widget_metrics.zig +45 -6
  339. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  340. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  341. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  342. package/src/primitives/canvas/widget_render.zig +744 -74
  343. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  344. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  345. package/src/primitives/canvas/widget_render_style.zig +94 -0
  346. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  347. package/src/primitives/canvas/widget_routing.zig +75 -0
  348. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  349. package/src/primitives/canvas/widget_runtime.zig +21 -1
  350. package/src/primitives/canvas/widget_semantics.zig +25 -0
  351. package/src/primitives/canvas/widget_text_input.zig +86 -23
  352. package/src/primitives/canvas/widget_text_select.zig +1 -0
  353. package/src/primitives/canvas/widget_tree.zig +8 -1
  354. package/src/primitives/canvas/widgets.zig +42 -12
  355. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  356. package/src/root.zig +26 -0
  357. package/src/runtime/accessibility_policy.zig +122 -0
  358. package/src/runtime/api.zig +29 -0
  359. package/src/runtime/app_dispatch_policy.zig +68 -0
  360. package/src/runtime/authorization_policy.zig +150 -0
  361. package/src/runtime/automation_command_policy.zig +241 -0
  362. package/src/runtime/automation_interaction_policy.zig +107 -0
  363. package/src/runtime/automation_snapshot.zig +52 -22
  364. package/src/runtime/automation_snapshot_reference.zig +290 -0
  365. package/src/runtime/automation_widget_dispatch.zig +267 -355
  366. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  367. package/src/runtime/blob_policy.zig +58 -0
  368. package/src/runtime/blob_reference.zig +64 -0
  369. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  370. package/src/runtime/bridge_payload.zig +2 -0
  371. package/src/runtime/builtin_bridge.zig +180 -44
  372. package/src/runtime/builtin_coordination_policy.zig +121 -0
  373. package/src/runtime/callback_policy_test_reference.zig +97 -0
  374. package/src/runtime/canvas_drag_policy.zig +94 -0
  375. package/src/runtime/canvas_fonts.zig +38 -10
  376. package/src/runtime/canvas_frame.zig +590 -134
  377. package/src/runtime/canvas_frame_helpers.zig +1 -0
  378. package/src/runtime/canvas_hover_policy.zig +131 -0
  379. package/src/runtime/canvas_images.zig +59 -30
  380. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  381. package/src/runtime/canvas_limits.zig +1 -1
  382. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  383. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  384. package/src/runtime/canvas_widget_context_menu.zig +183 -4
  385. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  386. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  387. package/src/runtime/canvas_widget_display.zig +110 -9
  388. package/src/runtime/canvas_widget_events.zig +718 -328
  389. package/src/runtime/canvas_widget_runtime.zig +720 -150
  390. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  391. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  392. package/src/runtime/canvas_widget_state.zig +93 -56
  393. package/src/runtime/channel_sources.zig +80 -0
  394. package/src/runtime/command_policy.zig +161 -0
  395. package/src/runtime/component_policy.zig +83 -0
  396. package/src/runtime/context_menu_policy.zig +112 -0
  397. package/src/runtime/core.zig +170 -6
  398. package/src/runtime/desktop_files.zig +189 -0
  399. package/src/runtime/effects.zig +638 -33
  400. package/src/runtime/effects_host_tests.zig +25 -0
  401. package/src/runtime/effects_tests.zig +28 -0
  402. package/src/runtime/file_policy_test_reference.zig +113 -0
  403. package/src/runtime/flow.zig +419 -341
  404. package/src/runtime/flow_reference.zig +1427 -0
  405. package/src/runtime/font_registry_policy.zig +72 -0
  406. package/src/runtime/frame_profile.zig +24 -33
  407. package/src/runtime/global_shortcuts.zig +75 -0
  408. package/src/runtime/gpu_surface_events.zig +97 -35
  409. package/src/runtime/host_event_pump.zig +303 -0
  410. package/src/runtime/host_event_pump_reference.zig +268 -0
  411. package/src/runtime/host_flow_policy.zig +155 -0
  412. package/src/runtime/host_input_regions_policy.zig +156 -0
  413. package/src/runtime/image_registry_policy.zig +94 -0
  414. package/src/runtime/input_composition_policy.zig +138 -0
  415. package/src/runtime/journal_policy.zig +66 -0
  416. package/src/runtime/journal_reference.zig +53 -0
  417. package/src/runtime/keyboard_input.zig +86 -0
  418. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  419. package/src/runtime/markup_development_policy.zig +91 -0
  420. package/src/runtime/media_surface.zig +40 -1
  421. package/src/runtime/motion_sampling_policy.zig +159 -0
  422. package/src/runtime/recording_policy.zig +42 -0
  423. package/src/runtime/render_animation_policy.zig +206 -0
  424. package/src/runtime/replay_policy.zig +66 -0
  425. package/src/runtime/replay_policy_reference.zig +326 -0
  426. package/src/runtime/replay_progress_policy.zig +64 -0
  427. package/src/runtime/replay_progress_reference.zig +34 -0
  428. package/src/runtime/request_policy_test_reference.zig +188 -0
  429. package/src/runtime/root.zig +16 -0
  430. package/src/runtime/scroll_mutation_policy.zig +130 -0
  431. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  432. package/src/runtime/scroll_tree_policy.zig +99 -0
  433. package/src/runtime/session_blobs.zig +157 -58
  434. package/src/runtime/session_blobs_reference.zig +692 -0
  435. package/src/runtime/session_codec.zig +361 -0
  436. package/src/runtime/session_codec_reference.zig +1027 -0
  437. package/src/runtime/session_journal.zig +246 -983
  438. package/src/runtime/session_record.zig +231 -45
  439. package/src/runtime/session_replay.zig +157 -415
  440. package/src/runtime/session_tests.zig +552 -0
  441. package/src/runtime/shell_admission_policy.zig +225 -0
  442. package/src/runtime/shell_coordination_policy.zig +138 -0
  443. package/src/runtime/shell_layout.zig +126 -1
  444. package/src/runtime/snapshot_policy.zig +60 -0
  445. package/src/runtime/snapshot_reference.zig +64 -0
  446. package/src/runtime/staged_rebuild_policy.zig +83 -0
  447. package/src/runtime/state.zig +16 -0
  448. package/src/runtime/status_validation.zig +190 -0
  449. package/src/runtime/system_admission_policy.zig +140 -0
  450. package/src/runtime/system_services.zig +65 -36
  451. package/src/runtime/tests.zig +2 -0
  452. package/src/runtime/ts_canvas_hooks.zig +261 -0
  453. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  454. package/src/runtime/ts_canvas_icons.zig +234 -0
  455. package/src/runtime/ts_core_host.zig +2451 -411
  456. package/src/runtime/ts_core_host_tests.zig +1982 -0
  457. package/src/runtime/ts_test_host.zig +699 -0
  458. package/src/runtime/ts_ui_app.zig +1111 -45
  459. package/src/runtime/ui_app.zig +1381 -650
  460. package/src/runtime/ui_app_provenance.zig +147 -5
  461. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  462. package/src/runtime/ui_app_tests.zig +667 -188
  463. package/src/runtime/ui_app_window_tests.zig +222 -0
  464. package/src/runtime/view.zig +25 -0
  465. package/src/runtime/view_canvas.zig +30 -6
  466. package/src/runtime/view_coordination_policy.zig +147 -0
  467. package/src/runtime/view_reload.zig +226 -0
  468. package/src/runtime/view_widget_control.zig +51 -14
  469. package/src/runtime/view_widget_scroll.zig +46 -26
  470. package/src/runtime/view_widget_text.zig +153 -68
  471. package/src/runtime/view_widget_tree.zig +503 -69
  472. package/src/runtime/virtual_window_policy.zig +128 -0
  473. package/src/runtime/web_pane_policy.zig +111 -0
  474. package/src/runtime/web_pane_test_cases.zig +204 -0
  475. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  476. package/src/runtime/widget_continuity_policy.zig +73 -0
  477. package/src/runtime/widget_motion_policy.zig +238 -0
  478. package/src/runtime/widget_reconcile_policy.zig +81 -0
  479. package/src/runtime/widget_retention_policy.zig +75 -0
  480. package/src/runtime/window_command_bridge_tests.zig +63 -0
  481. package/src/runtime/window_lifecycle_policy.zig +127 -0
  482. package/src/runtime/window_storage.zig +74 -8
  483. package/src/runtime/window_view_runtime.zig +148 -33
  484. package/src/runtime/window_views.zig +179 -11
  485. package/src/security/root.zig +1 -0
  486. package/src/tooling/components/identity_tests.zig +62 -36
  487. package/src/tooling/components/stepper.native +24 -0
  488. package/src/tooling/components/stepper.zig +0 -19
  489. package/src/tooling/components/timeline-item.native +22 -0
  490. package/src/tooling/components/timeline.native +5 -3
  491. package/src/tooling/components/timeline_item.zig +0 -32
  492. package/src/tooling/eject_components.zig +76 -8
  493. package/src/tooling/ios.zig +66 -12
  494. package/src/tooling/manifest.zig +35 -0
  495. package/src/tooling/raw_manifest.zig +6 -0
  496. package/src/tooling/templates.zig +23 -3
  497. package/src/tooling/ts_core.zig +97 -4
  498. package/src/tooling/verbs.zig +87 -1
  499. package/tools/corewire/build_profile.mjs +54 -0
  500. package/tools/corewire/contract_intake.ts +303 -0
  501. package/tools/corewire/contract_intake.zig +82 -0
  502. package/tools/corewire/core.test.ts +188 -0
  503. package/tools/corewire/core_abi.zig +55 -0
  504. package/tools/corewire/core_cases.ts +233 -0
  505. package/tools/corewire/core_contract.ts +407 -0
  506. package/tools/corewire/core_emission.ts +136 -0
  507. package/tools/corewire/core_emission.zig +69 -0
  508. package/tools/corewire/core_goldens.json +3110 -0
  509. package/tools/corewire/core_policy.ts +14 -0
  510. package/tools/corewire/core_policy.zig +48 -0
  511. package/tools/corewire/core_projection.ts +361 -0
  512. package/tools/corewire/core_vocabulary.ts +6 -0
  513. package/tools/corewire/emit.zig +19 -1590
  514. package/tools/corewire/emit_facade.ts +714 -0
  515. package/tools/corewire/emit_facade.zig +10 -3752
  516. package/tools/corewire/emit_mirror.ts +300 -0
  517. package/tools/corewire/emit_profile.ts +50 -0
  518. package/tools/corewire/emit_service.ts +331 -0
  519. package/tools/corewire/emit_service.zig +23 -842
  520. package/tools/corewire/entry.test.ts +95 -0
  521. package/tools/corewire/entry_coordination.ts +127 -0
  522. package/tools/corewire/entry_coordination.zig +190 -0
  523. package/tools/corewire/facade_templates.ts +85 -0
  524. package/tools/corewire/filesystem.test.ts +166 -0
  525. package/tools/corewire/filesystem_coordination.ts +213 -0
  526. package/tools/corewire/filesystem_coordination.zig +245 -0
  527. package/tools/corewire/intake.test.ts +39 -0
  528. package/tools/corewire/intake_cases.ts +55 -0
  529. package/tools/corewire/intake_goldens.json +12237 -0
  530. package/tools/corewire/invocation.test.ts +28 -0
  531. package/tools/corewire/invocation.ts +175 -0
  532. package/tools/corewire/invocation.zig +136 -0
  533. package/tools/corewire/invocation_cases.ts +60 -0
  534. package/tools/corewire/invocation_fixture.ts +33 -0
  535. package/tools/corewire/invocation_goldens.json +1143 -0
  536. package/tools/corewire/invocation_tests.zig +111 -0
  537. package/tools/corewire/invocation_usage.ts +2 -0
  538. package/tools/corewire/lossless_projection.ts +96 -0
  539. package/tools/corewire/main.zig +7 -680
  540. package/tools/corewire/main_reference.zig +415 -0
  541. package/tools/corewire/mirror_templates.ts +59 -0
  542. package/tools/corewire/profile.test.ts +248 -0
  543. package/tools/corewire/profile.zig +56 -0
  544. package/tools/corewire/profile_emission.ts +204 -0
  545. package/tools/corewire/profile_library.json +29 -0
  546. package/tools/corewire/profile_tests.zig +136 -0
  547. package/tools/corewire/service.test.ts +75 -0
  548. package/tools/corewire/service_cases.ts +61 -0
  549. package/tools/corewire/service_contract.zig +40 -146
  550. package/tools/corewire/service_goldens.json +650 -0
  551. package/tools/corewire/service_projection.zig +52 -0
  552. package/tools/corewire/service_templates.ts +14 -0
  553. package/tools/corewire/shim_rt.zig +9 -0
  554. package/tools/corewire/sidecar.zig +269 -1438
  555. package/tools/corewire/emit_profile.zig +0 -521
@@ -1,3 +1,7 @@
1
+ const host_regions = @import("host_input_regions_policy.zig");
2
+ const input_composition = @import("input_composition_policy.zig");
3
+ const drag_policy = @import("canvas_drag_policy.zig");
4
+ const keyboard_focus = @import("canvas_keyboard_focus_policy.zig");
1
5
  const std = @import("std");
2
6
  const geometry = @import("geometry");
3
7
  const canvas = @import("canvas");
@@ -18,7 +22,7 @@ const CanvasWidgetPointerEvent = runtime_api.CanvasWidgetPointerEvent;
18
22
  const CanvasWidgetKeyboardEvent = runtime_api.CanvasWidgetKeyboardEvent;
19
23
  const CanvasWidgetFileDropEvent = runtime_api.CanvasWidgetFileDropEvent;
20
24
  const CanvasWidgetDragEvent = runtime_api.CanvasWidgetDragEvent;
21
- const validateViewLabel = validation.validateViewLabel;
25
+
22
26
  const platformCursorFromCanvas = widget_bridge.platformCursorFromCanvas;
23
27
  const canvasWidgetPointerEventFromGpuInput = canvas_frame_helpers.canvasWidgetPointerEventFromGpuInput;
24
28
  const canvasWidgetKeyboardEventFromGpuInput = canvas_frame_helpers.canvasWidgetKeyboardEventFromGpuInput;
@@ -28,11 +32,6 @@ const canvasWidgetKeyboardModifiers = canvas_frame_helpers.canvasWidgetKeyboardM
28
32
  const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetInteractionTargetExists;
29
33
  const canvasWidgetCommandable = canvas_widget_runtime.canvasWidgetCommandable;
30
34
  const canvasWidgetCommandFiresOnPointerDown = canvas_widget_runtime.canvasWidgetCommandFiresOnPointerDown;
31
- const canvasWidgetGroupFocusEdgeFromInput = canvas_widget_runtime.canvasWidgetGroupFocusEdgeFromInput;
32
- const canvasWidgetSpatialFocusDirection = canvas_widget_runtime.canvasWidgetSpatialFocusDirection;
33
- const canvasWidgetSpatialFocusAllowed = canvas_widget_runtime.canvasWidgetSpatialFocusAllowed;
34
- const canvasWidgetGroupDirectionalFocusTarget = canvas_widget_runtime.canvasWidgetGroupDirectionalFocusTarget;
35
- const canvasWidgetGroupFocusEdgeTarget = canvas_widget_runtime.canvasWidgetGroupFocusEdgeTarget;
36
35
 
37
36
  /// Multi-click chain window: a primary pointer-down within this many
38
37
  /// nanoseconds of the previous one (and within the slop below) raises
@@ -63,10 +62,14 @@ pub fn canvasWidgetDragCrossedSlop(delta: geometry.OffsetF) bool {
63
62
 
64
63
  pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
65
64
  return struct {
65
+ fn normalizedInput(self: *const Runtime, input: GpuSurfaceInputEvent) ?input_composition.Program {
66
+ const index = runtimeFindViewIndex(self, input.window_id, input.label) orelse return null;
67
+ return input_composition.plan(self.views[index].canvas_widget_surface_scope_policy, .normalize, input, .{});
68
+ }
66
69
  pub fn routeCanvasWidgetPointerInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetPointerEvent {
67
70
  try validateRuntimeViewParent(self, input_event.window_id);
68
- try validateViewLabel(input_event.label);
69
- var pointer = canvasWidgetPointerEventFromGpuInput(input_event) orelse return null;
71
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, input_event.label);
72
+ var pointer = (if (normalizedInput(self, input_event)) |program| input_composition.pointerEvent(program, input_event) else canvasWidgetPointerEventFromGpuInput(input_event)) orelse return null;
70
73
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
71
74
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
72
75
  switch (pointer.phase) {
@@ -96,12 +99,40 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
96
99
  /// made stays live for copy). A plain click collapses the
97
100
  /// selection on `.down`, so it reaches `.up` collapsed and the
98
101
  /// press lands normally.
99
- fn canvasWidgetPressTargetForRoute(
102
+ pub fn canvasWidgetPressTargetForRoute(
100
103
  self: *const Runtime,
101
104
  view_index: usize,
102
105
  pointer: canvas.WidgetPointerEvent,
103
106
  route: canvas.WidgetEventRoute,
104
107
  ) ?canvas.WidgetHit {
108
+ const view = &self.views[view_index];
109
+ if (view.canvas_widget_surface_scope_policy) |policy| {
110
+ var facts: u8 = @intFromBool(route.press_target != null);
111
+ var kind: u16 = 0;
112
+ if (route.target) |raw| {
113
+ kind = canvas.widgetKindCode(raw.kind);
114
+ facts |= 2 | (@as(u8, @intFromBool(view.canvas_widget_selected_text_id == raw.id)) << 2) |
115
+ (@as(u8, @intFromBool(view.canvas_widget_selected_text_group_id != 0)) << 3) |
116
+ (@as(u8, @intFromBool(view.canvas_widget_selected_text_group_anchor != view.canvas_widget_selected_text_group_focus)) << 4);
117
+ // Resolve only the storage capability described by the raw hit.
118
+ if (raw.kind == .text or raw.kind == .terminal) {
119
+ if (view.widgetLayoutTree().findById(raw.id)) |node| {
120
+ if (raw.kind == .text) {
121
+ if (node.widget.text_selection) |selection| {
122
+ facts |= @as(u8, @intFromBool(!selection.isCollapsed(node.widget.text.len))) << 5;
123
+ }
124
+ } else if (node.widget.terminal.grid) |grid| {
125
+ facts |= @as(u8, @intFromBool(grid.selection_active)) << 6;
126
+ }
127
+ }
128
+ }
129
+ }
130
+ var request = [5]u8{ 32, @intFromEnum(pointer.phase), facts, 0, 0 };
131
+ std.mem.writeInt(u16, request[3..5], kind, .little);
132
+ var result: [1]u8 = undefined;
133
+ if (policy(&request, &result) != result.len or result[0] > 1) @panic("invalid compiled selection press result");
134
+ return if (result[0] != 0) route.press_target else null;
135
+ }
105
136
  const press_target = route.press_target orelse return null;
106
137
  if (pointer.phase != .up) return press_target;
107
138
  const raw = route.target orelse return press_target;
@@ -172,7 +203,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
172
203
 
173
204
  pub fn routeCanvasWidgetKeyboardInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetKeyboardEvent {
174
205
  try validateRuntimeViewParent(self, input_event.window_id);
175
- try validateViewLabel(input_event.label);
206
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, input_event.label);
176
207
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
177
208
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
178
209
  if (!self.views[index].focused) return null;
@@ -190,7 +221,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
190
221
  // keys select, arrows walk rows. Tree rows (role treeitem)
191
222
  // are exempt — their roving-focus keymap is the feature.
192
223
  if (canvasWidgetQuietListRowFocus(self, index, focused_id)) return null;
193
- const keyboard = canvasWidgetKeyboardEventFromGpuInput(input_event, focused_id) orelse return null;
224
+ const keyboard = (if (normalizedInput(self, input_event)) |program| input_composition.keyboardEvent(program, input_event, focused_id, false) else canvasWidgetKeyboardEventFromGpuInput(input_event, focused_id)) orelse return null;
194
225
 
195
226
  const route = try self.views[index].widgetLayoutTree().routeKeyboardEvent(keyboard, output);
196
227
  if (route.target == null) return null;
@@ -205,7 +236,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
205
236
 
206
237
  pub fn routeCanvasWidgetTextInput(self: *const Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetKeyboardEvent {
207
238
  try validateRuntimeViewParent(self, input_event.window_id);
208
- try validateViewLabel(input_event.label);
239
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, input_event.label);
209
240
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
210
241
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
211
242
  if (!self.views[index].focused) return null;
@@ -221,7 +252,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
221
252
  // text_input is the sequence's own resolution — the hosts
222
253
  // never deliver ordinary typing while a composition is open.
223
254
  const ime_owner = self.views[index].canvas_widget_ime_owner_id;
224
- const target_id = switch (input_event.kind) {
255
+ const target_id = if (input_composition.plan(self.views[index].canvas_widget_surface_scope_policy, .target, input_event, input_composition.observations(self, &self.views[index]))) |program| program.target else switch (input_event.kind) {
225
256
  .ime_set_composition, .ime_commit_composition, .ime_cancel_composition, .text_input => id: {
226
257
  if (ime_owner != 0) {
227
258
  if (tree.findById(ime_owner)) |node| {
@@ -239,10 +270,12 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
239
270
  // text fall through to the app's target-less `on_text` seam
240
271
  // instead of being routed to a widget that drops it — the
241
272
  // terminal-with-a-focused-button case.
242
- if (tree.findById(target_id)) |node| {
243
- if (!canvas.isWidgetTextEntry(node.widget)) return null;
273
+ if (self.views[index].canvas_widget_surface_scope_policy == null) {
274
+ if (tree.findById(target_id)) |node| {
275
+ if (!canvas.isWidgetTextEntry(node.widget)) return null;
276
+ }
244
277
  }
245
- const keyboard = canvasWidgetTextInputEventFromGpuInput(input_event, target_id) orelse return null;
278
+ const keyboard = (if (normalizedInput(self, input_event)) |program| input_composition.keyboardEvent(program, input_event, target_id, true) else canvasWidgetTextInputEventFromGpuInput(input_event, target_id)) orelse return null;
246
279
 
247
280
  const route = try tree.routeKeyboardEvent(keyboard, output);
248
281
  if (route.target == null) return null;
@@ -258,7 +291,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
258
291
  pub fn routeCanvasWidgetFileDrop(self: *const Runtime, drop: platform.FileDropEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetFileDropEvent {
259
292
  try validateRuntimeViewParent(self, drop.window_id);
260
293
  if (drop.view_label.len == 0 or drop.paths.len == 0) return null;
261
- try validateViewLabel(drop.view_label);
294
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, drop.view_label);
262
295
  const point = drop.point orelse return null;
263
296
  const index = runtimeFindViewIndex(self, drop.window_id, drop.view_label) orelse return error.ViewNotFound;
264
297
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
@@ -280,17 +313,21 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
280
313
 
281
314
  pub fn routeCanvasWidgetDragInput(self: *Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
282
315
  try validateRuntimeViewParent(self, input_event.window_id);
283
- try validateViewLabel(input_event.label);
316
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, input_event.label);
284
317
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
285
318
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
286
319
  const previous_render_state = self.views[index].canvasWidgetRenderState();
287
320
 
288
- if (input_event.kind == .pointer_down) {
321
+ const policy = self.views[index].canvas_widget_surface_scope_policy;
322
+ const active_source = self.views[index].canvas_widget_drag_source_id;
323
+ const admission = drag_policy.decide(policy, .{ .stage = .admission, .phase = drag_policy.inputPhase(input_event.kind), .facts = @as(u8, if (active_source != 0) 1 else 0) | @as(u8, if (input_event.pointer_id == self.views[index].canvas_widget_drag_pointer_id) 2 else 0) |
324
+ @as(u8, if (self.views[index].canvas_widget_pressed_id != 0) 4 else 0) });
325
+ if (admission == 0) return null;
326
+ if (admission == 1) {
289
327
  // A live drag belongs to the pointer that crossed slop. A
290
328
  // second contact may still run the ordinary pointer pipeline,
291
329
  // but it cannot silently erase the first contact's preview or
292
330
  // strand the app after its phase-0 Msg.
293
- if (self.views[index].canvas_widget_drag_source_id != 0) return null;
294
331
  self.views[index].canvas_widget_drag_source_id = 0;
295
332
  self.views[index].canvas_widget_drag_source_attached = false;
296
333
  self.views[index].canvas_widget_drag_pointer_id = input_event.pointer_id;
@@ -308,22 +345,11 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
308
345
  }
309
346
  return null;
310
347
  }
311
- if (input_event.kind != .pointer_drag and input_event.kind != .pointer_up and input_event.kind != .pointer_cancel) return null;
312
- // Pointer capture is per sequence. An unrelated touch/pen/mouse
313
- // edge must not move or terminate the candidate/live drag.
314
- if (input_event.pointer_id != self.views[index].canvas_widget_drag_pointer_id) return null;
315
-
316
- const active_source = self.views[index].canvas_widget_drag_source_id;
317
- // A release/cancel belongs to the drag channel only after motion
318
- // crossed the slop and installed an active source. Until then it
319
- // is the terminal edge of an ordinary click (or an abandoned
320
- // press), so it must not arm a landing from the zero origin.
321
- if (active_source == 0 and input_event.kind != .pointer_drag) {
348
+ if (admission == 2) {
322
349
  self.views[index].canvas_widget_drag_pointer_id = 0;
323
350
  return null;
324
351
  }
325
- const candidate_source = if (active_source != 0) active_source else self.views[index].canvas_widget_pressed_id;
326
- if (candidate_source == 0) return null;
352
+ const candidate_source = if (admission & 16 != 0) active_source else self.views[index].canvas_widget_pressed_id;
327
353
 
328
354
  const point = geometry.PointF.init(input_event.x, input_event.y);
329
355
  const phase: canvas.WidgetDragPhase = switch (input_event.kind) {
@@ -343,7 +369,9 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
343
369
  ),
344
370
  };
345
371
  const route = try self.views[index].widgetLayoutTree().routeDragEvent(drag, output);
346
- if (route.target == null) {
372
+ const action = drag_policy.decide(policy, .{ .stage = .route, .phase = drag_policy.dragPhase(phase), .delta = drag.delta, .facts = @as(u8, if (active_source != 0) 1 else 0) | @as(u8, if (route.target != null) 2 else 0) |
373
+ @as(u8, if (self.views[index].canvas_widget_drag_source_hit != null) 4 else 0) });
374
+ if (action & 15 == 4 or action & 15 == 5) {
347
375
  // A source removed, hidden, or disabled after a live change
348
376
  // still owes the consumer one terminal phase. Its last valid
349
377
  // hit/route are POD snapshots owned by the view, so they stay
@@ -357,14 +385,14 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
357
385
  self.views[index].canvas_widget_drag_delta = .{};
358
386
  self.views[index].canvas_widget_drag_source_hit = null;
359
387
  self.views[index].canvas_widget_drag_route_len = 0;
360
- if (active_source != 0) self.views[index].canvas_widget_pressed_id = 0;
388
+ if (action & 32 != 0) self.views[index].canvas_widget_pressed_id = 0;
361
389
  self.views[index].canvas_widget_drag_landing_source_id = 0;
362
390
  self.views[index].canvas_widget_drag_landing_origin = .{};
363
391
  const next_render_state = self.views[index].canvasWidgetRenderState();
364
392
  if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
365
393
  try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
366
394
  }
367
- if (active_source != 0 and captured_source != null) {
395
+ if (action & 15 == 5) {
368
396
  drag.source_id = captured_source.?.id;
369
397
  drag.phase = .cancel;
370
398
  return .{
@@ -383,7 +411,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
383
411
  // pointer-drag fidelity. Do not promote it into runtime drag state:
384
412
  // UiApp filters these change messages, and a matching release
385
413
  // remains a press because no active source was installed.
386
- if (active_source == 0 and !canvasWidgetDragCrossedSlop(drag.delta)) {
414
+ if (action == 6) {
387
415
  return .{
388
416
  .window_id = input_event.window_id,
389
417
  .view_label = self.views[index].label,
@@ -403,10 +431,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
403
431
  // phases where the source itself moves into (or back from) the
404
432
  // reserved slot.
405
433
  self.views[index].canvas_widget_drag_layout_motion_armed = true;
406
- if (phase == .change) {
434
+ if (action & 15 == 7) {
407
435
  self.views[index].canvas_widget_drag_landing_source_id = 0;
408
436
  self.views[index].canvas_widget_drag_landing_origin = .{};
409
- if (active_source == 0) {
437
+ if (action & 64 != 0) {
410
438
  const source_bounds = route.target.?.bounds.normalized();
411
439
  self.views[index].canvas_widget_drag_source_origin = geometry.PointF.init(source_bounds.x, source_bounds.y);
412
440
  }
@@ -449,16 +477,15 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
449
477
  /// app's phase-2 rebuild can therefore restore the source slot while
450
478
  /// the card under the pointer eases back into it.
451
479
  pub fn routeCanvasWidgetDragCancelFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent, output: []canvas.WidgetEventRouteEntry) anyerror!?CanvasWidgetDragEvent {
452
- if (input_event.kind != .key_down or !canvasWidgetEscapeKey(input_event.key)) return null;
453
- const modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers);
454
- if (modifiers.shift or modifiers.hasNavigationModifier()) return null;
480
+ const policy = if (runtimeFindViewIndex(self, input_event.window_id, input_event.label)) |view_index| self.views[view_index].canvas_widget_surface_scope_policy else null;
481
+ if (drag_policy.decide(policy, .{ .stage = .escape, .phase = if (input_event.kind == .key_down) 0 else 4, .facts = @intFromBool(if (normalizedInput(self, input_event)) |program| program.has(2) else canvasWidgetEscapeKey(input_event.key)), .modifiers = drag_policy.modifiers(input_event.modifiers) }) == 0) return null;
455
482
 
456
483
  try validateRuntimeViewParent(self, input_event.window_id);
457
- try validateViewLabel(input_event.label);
484
+ try @import("shell_admission_policy.zig").label(self.shell_admission_policy, 0, input_event.label);
458
485
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return error.ViewNotFound;
459
486
  if (self.views[index].kind != .gpu_surface) return error.InvalidViewOptions;
460
487
  const source_id = self.views[index].canvas_widget_drag_source_id;
461
- if (source_id == 0) return null;
488
+ if (drag_policy.decide(policy, .{ .stage = .source, .facts = @intFromBool(source_id != 0) }) == 0) return null;
462
489
 
463
490
  const previous_render_state = self.views[index].canvasWidgetRenderState();
464
491
  const delta = self.views[index].canvas_widget_drag_delta;
@@ -473,7 +500,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
473
500
  .delta = delta,
474
501
  };
475
502
  const route = try self.views[index].widgetLayoutTree().routeDragEvent(drag, output);
476
- if (route.target == null) {
503
+ const action = drag_policy.decide(policy, .{ .stage = .route, .phase = 3, .delta = delta, .facts = 1 | @as(u8, if (route.target != null) 2 else 0) | @as(u8, if (self.views[index].canvas_widget_drag_source_hit != null) 4 else 0) });
504
+ if (action & 15 == 4 or action & 15 == 5) {
477
505
  const captured_source = self.views[index].canvas_widget_drag_source_hit;
478
506
  const captured_route = self.views[index].canvas_widget_drag_route_entries[0..self.views[index].canvas_widget_drag_route_len];
479
507
  self.views[index].canvas_widget_drag_source_id = 0;
@@ -490,7 +518,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
490
518
  if (!canvasWidgetRenderStatesEqual(previous_render_state, next_render_state)) {
491
519
  try invalidateForCanvasWidgetRenderStateChange(self, index, previous_render_state, next_render_state);
492
520
  }
493
- if (captured_source) |source| {
521
+ if (action & 15 == 5) {
522
+ const source = captured_source.?;
494
523
  drag.source_id = source.id;
495
524
  return .{
496
525
  .window_id = input_event.window_id,
@@ -541,10 +570,33 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
541
570
  /// treeitem role: ARIA tree rows carry a roving-focus keymap by
542
571
  /// design and keep every key they have today.
543
572
  fn canvasWidgetQuietListRowFocus(self: *const Runtime, index: usize, focused_id: canvas.ObjectId) bool {
544
- if (focused_id == 0) return false;
545
- if (self.views[index].canvas_widget_focus_visible_id == focused_id) return false;
546
- const node_index = self.views[index].canvasWidgetNodeIndexById(focused_id) orelse return false;
547
- const widget = self.views[index].widget_layout_nodes[node_index].widget;
573
+ return canvasWidgetKeyboardFocusParticipation(self, index, focused_id, 0);
574
+ }
575
+
576
+ /// Shared keyboard participation for routed focus and explicit
577
+ /// keyboard actions. Exact ids and retained nodes stay native;
578
+ /// compiled views own the classification through copied bytes.
579
+ pub fn canvasWidgetKeyboardFocusParticipation(self: *const Runtime, index: usize, id: canvas.ObjectId, stage: u8) bool {
580
+ const view = &self.views[index];
581
+ if (view.canvas_widget_surface_scope_policy) |policy| {
582
+ var facts: u8 = @as(u8, @intFromBool(id != 0)) |
583
+ (@as(u8, @intFromBool(view.canvas_widget_focus_visible_id == id)) << 1);
584
+ var kind: u16 = 0;
585
+ if (view.canvasWidgetNodeIndexById(id)) |node_index| {
586
+ const widget = view.widget_layout_nodes[node_index].widget;
587
+ facts |= 4 | (@as(u8, @intFromBool(widget.semantics.role == .treeitem)) << 3);
588
+ kind = canvas.widgetKindCode(widget.kind);
589
+ }
590
+ var request = [5]u8{ 33, stage, facts, 0, 0 };
591
+ std.mem.writeInt(u16, request[3..5], kind, .little);
592
+ var result: [1]u8 = undefined;
593
+ if (policy(&request, &result) != result.len or result[0] > 1) @panic("invalid compiled keyboard participation result");
594
+ return result[0] != 0;
595
+ }
596
+ if (stage == 0 and id == 0) return false;
597
+ if (view.canvas_widget_focus_visible_id == id) return false;
598
+ const node_index = view.canvasWidgetNodeIndexById(id) orelse return false;
599
+ const widget = view.widget_layout_nodes[node_index].widget;
548
600
  return widget.kind == .list_item and widget.semantics.role != .treeitem;
549
601
  }
550
602
 
@@ -560,6 +612,47 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
560
612
  pub fn updateCanvasWidgetClickCountFromPointer(self: *Runtime, input_event: GpuSurfaceInputEvent, pointer_event: *CanvasWidgetPointerEvent) void {
561
613
  const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
562
614
  if (self.views[index].kind != .gpu_surface) return;
615
+ if (self.views[index].canvas_widget_surface_scope_policy) |policy| {
616
+ const view = &self.views[index];
617
+ const point = pointer_event.pointer.point;
618
+ const target_id: canvas.ObjectId = if (pointer_event.press_target) |target| target.id else if (pointer_event.target) |target| target.id else 0;
619
+ var facts: u8 = @intFromBool(input_event.button == 0);
620
+ if (pointer_event.pointer.phase == .down and input_event.button == 0) {
621
+ const ordered = input_event.timestamp_ns >= view.canvas_widget_click_timestamp_ns;
622
+ facts |= (@as(u8, @intFromBool(view.canvas_widget_click_timestamp_ns != 0)) << 1) |
623
+ (@as(u8, @intFromBool(pointer_event.pointer.pointer_id == view.canvas_widget_click_pointer_id)) << 2) |
624
+ (@as(u8, @intFromBool(target_id == view.canvas_widget_click_target_id)) << 3) |
625
+ (@as(u8, @intFromBool(ordered)) << 4) |
626
+ (@as(u8, @intFromBool(ordered and input_event.timestamp_ns - view.canvas_widget_click_timestamp_ns <= canvas_widget_multi_click_interval_ns)) << 5) |
627
+ (@as(u8, @intFromBool(@abs(point.x - view.canvas_widget_click_point.x) <= canvas_widget_multi_click_slop)) << 6) |
628
+ (@as(u8, @intFromBool(@abs(point.y - view.canvas_widget_click_point.y) <= canvas_widget_multi_click_slop)) << 7);
629
+ }
630
+ const request = [4]u8{ 31, @intFromEnum(pointer_event.pointer.phase), view.canvas_widget_click_count, facts };
631
+ var result: [2]u8 = undefined;
632
+ if (policy(&request, &result) != result.len or result[0] > 3 or result[1] > 3 or
633
+ ((result[0] == 0 or result[0] == 1) and result[1] != 0) or
634
+ ((result[0] == 2 or result[0] == 3) and result[1] == 0)) @panic("invalid compiled click sequence result");
635
+ switch (result[0]) {
636
+ 0 => {},
637
+ 1 => {
638
+ view.canvas_widget_click_count = 0;
639
+ view.canvas_widget_click_timestamp_ns = 0;
640
+ view.canvas_widget_click_pointer_id = 0;
641
+ view.canvas_widget_click_target_id = 0;
642
+ },
643
+ 2 => {
644
+ view.canvas_widget_click_count = result[1];
645
+ view.canvas_widget_click_timestamp_ns = input_event.timestamp_ns;
646
+ view.canvas_widget_click_point = point;
647
+ view.canvas_widget_click_pointer_id = pointer_event.pointer.pointer_id;
648
+ view.canvas_widget_click_target_id = target_id;
649
+ pointer_event.pointer.click_count = result[1];
650
+ },
651
+ 3 => pointer_event.pointer.click_count = result[1],
652
+ else => unreachable,
653
+ }
654
+ return;
655
+ }
563
656
  switch (pointer_event.pointer.phase) {
564
657
  .down => {
565
658
  if (input_event.button != 0) {
@@ -621,7 +714,17 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
621
714
  // item's label focuses the item, and clicking an editable
622
715
  // field (which claims its own presses) focuses the field
623
716
  // exactly as before.
624
- const next_focus_id: canvas.ObjectId = if (pointer_event.press_target) |target| blk: {
717
+ var focus_action: [1]u8 = undefined;
718
+ const press = pointer_event.press_target;
719
+ var focus_compiled = false;
720
+ if (self.views[index].canvas_widget_surface_scope_policy != null) {
721
+ const focus_facts = @as(u8, @intFromBool(press != null)) |
722
+ (@as(u8, @intFromBool(if (press) |target| self.views[index].widgetLayoutTree().focusTargetById(target.id) != null else false)) << 1);
723
+ focus_compiled = compiledCanvasPointerIntent(&self.views[index], 0, .down, focus_facts, if (press) |target| canvas.widgetKindCode(target.kind) else 0, &focus_action);
724
+ }
725
+ const next_focus_id: canvas.ObjectId = if (focus_compiled)
726
+ (if ((focus_action[0] & 1) != 0) press.?.id else 0)
727
+ else if (pointer_event.press_target) |target| blk: {
625
728
  if (self.views[index].widgetLayoutTree().focusTargetById(target.id) != null) break :blk target.id;
626
729
  break :blk 0;
627
730
  } else 0;
@@ -630,7 +733,9 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
630
733
  // editable text widget shows its focus affordances (ring and
631
734
  // caret) however focus arrived — the :focus-visible contract
632
735
  // text inputs have on every platform.
633
- const next_focus_visible_id: canvas.ObjectId = if (pointer_event.press_target) |target| blk: {
736
+ const next_focus_visible_id: canvas.ObjectId = if (focus_compiled)
737
+ (if ((focus_action[0] & 2) != 0) next_focus_id else 0)
738
+ else if (pointer_event.press_target) |target| blk: {
634
739
  if (target.id == next_focus_id and canvas_widget_runtime.canvasWidgetShowsPointerFocusRing(target.kind)) break :blk next_focus_id;
635
740
  break :blk 0;
636
741
  } else 0;
@@ -641,8 +746,14 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
641
746
  // converts a keyboard ring into the caret contract, which
642
747
  // never reveals tooltips — Base UI's focus-visible guard
643
748
  // against click-focus opens).
644
- self.views[index].canvas_widget_focus_visible_keyboard = false;
645
- 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;
749
+ if (focus_compiled and (focus_action[0] & 8) == 0) return;
750
+ if (!focus_compiled or (focus_action[0] & 4) != 0) self.views[index].canvas_widget_focus_visible_keyboard = false;
751
+ const changed = @as(u8, @intFromBool(self.views[index].canvas_widget_focused_id != next_focus_id)) |
752
+ (@as(u8, @intFromBool(self.views[index].canvas_widget_focus_visible_id != next_focus_visible_id)) << 1);
753
+ var commit: [1]u8 = undefined;
754
+ if (compiledCanvasPointerIntent(&self.views[index], 5, .hover, changed, 0, &commit)) {
755
+ if (commit[0] == 0) return;
756
+ } else if (changed == 0) return;
646
757
  const previous_state = self.views[index].canvasWidgetRenderState();
647
758
  self.views[index].canvas_widget_focused_id = next_focus_id;
648
759
  self.views[index].canvas_widget_focus_visible_id = next_focus_visible_id;
@@ -698,7 +809,33 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
698
809
  // mouse's proof.
699
810
  const hover_pointer_proven = self.views[index].canvas_widget_hover_pointer_live and
700
811
  self.views[index].canvas_widget_hover_pointer_id == pointer_event.pointer.pointer_id;
701
- switch (pointer_event.pointer.phase) {
812
+ const intent_facts = @as(u8, @intFromBool(hover_pointer_proven)) |
813
+ (@as(u8, @intFromBool(pointer_event.pointer.pointer_id & platform.touch_pointer_id_bit != 0)) << 1) |
814
+ (@as(u8, @intFromBool(geometry.RectF.fromSize(self.views[index].gpu_size).containsPoint(pointer_event.pointer.point))) << 2);
815
+ var intent: [4]u8 = undefined;
816
+ if (compiledCanvasPointerIntent(&self.views[index], 1, pointer_event.pointer.phase, intent_facts, 0, &intent)) {
817
+ next_hovered_id = switch (intent[0]) {
818
+ 0 => next_hovered_id,
819
+ 1 => 0,
820
+ 2 => hover_target_id,
821
+ 3 => hit_target_id,
822
+ else => unreachable,
823
+ };
824
+ next_pressed_id = switch (intent[1]) {
825
+ 0 => next_pressed_id,
826
+ 1 => 0,
827
+ 2 => target_id,
828
+ else => unreachable,
829
+ };
830
+ next_cursor = switch (intent[2]) {
831
+ 0 => next_cursor,
832
+ 1 => .arrow,
833
+ 2 => platformCursorFromCanvas(layout_tree.cursorForHit(hover_target)),
834
+ 3 => hit_cursor,
835
+ else => unreachable,
836
+ };
837
+ applyCanvasPointerContainment(&self.views[index], intent[3], pointer_event.pointer.pointer_id, pointer_event.pointer.point, hover_raw_hit);
838
+ } else switch (pointer_event.pointer.phase) {
702
839
  .hover, .move => {
703
840
  next_hovered_id = hit_target_id;
704
841
  next_cursor = hit_cursor;
@@ -787,8 +924,14 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
787
924
  // whenever the pointer is over a hover-detail widget, and a
788
925
  // repaint fires only when the snapped sample index changes —
789
926
  // gliding within one sample costs nothing.
790
- const next_hover_point: ?geometry.PointF = if (pointer_event.pointer.phase != .cancel and
791
- canvasChartHoverIndexForId(self, index, next_hovered_id, pointer_event.pointer.point) != null)
927
+ const chart_sample_present = pointer_event.pointer.phase != .cancel and
928
+ canvasChartHoverIndexForId(self, index, next_hovered_id, pointer_event.pointer.point) != null;
929
+ var point_action: [1]u8 = undefined;
930
+ const keep_point = if (compiledCanvasPointerIntent(&self.views[index], 2, pointer_event.pointer.phase, @intFromBool(chart_sample_present), 0, &point_action))
931
+ point_action[0] != 0
932
+ else
933
+ chart_sample_present;
934
+ const next_hover_point: ?geometry.PointF = if (keep_point)
792
935
  pointer_event.pointer.point
793
936
  else
794
937
  null;
@@ -819,15 +962,69 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
819
962
  // any other interaction) changes: hover chrome is a pure
820
963
  // function of the snapped index, so a stale point that maps
821
964
  // to the same sample renders the same pixels.
822
- if (!interaction_changed and !cursor_changed) return;
965
+ const commit_facts = @as(u8, @intFromBool(self.views[index].canvas_widget_hovered_id != next_hovered_id)) |
966
+ (@as(u8, @intFromBool(self.views[index].canvas_widget_pressed_id != next_pressed_id)) << 1) |
967
+ (@as(u8, @intFromBool(hover_detail_changed)) << 2) | (@as(u8, @intFromBool(cursor_changed)) << 3);
968
+ var commit_action: [1]u8 = undefined;
969
+ const commit_compiled = compiledCanvasPointerIntent(&self.views[index], 3, .hover, commit_facts, 0, &commit_action);
970
+ if (commit_compiled) {
971
+ if ((commit_action[0] & 1) == 0) return;
972
+ } else if (!interaction_changed and !cursor_changed) return;
823
973
 
824
974
  const previous_state = self.views[index].canvasWidgetRenderState();
825
975
  self.views[index].canvas_widget_hovered_id = next_hovered_id;
826
976
  self.views[index].canvas_widget_pressed_id = next_pressed_id;
827
977
  self.views[index].canvas_widget_hover_point = next_hover_point;
828
978
  self.views[index].canvas_widget_cursor = next_cursor;
829
- if (cursor_changed) try syncCanvasWidgetCursorForView(self, index);
830
- if (interaction_changed) try invalidateForCanvasWidgetRenderStateChange(self, index, previous_state, self.views[index].canvasWidgetRenderState());
979
+ if (if (commit_compiled) (commit_action[0] & 2) != 0 else cursor_changed) try syncCanvasWidgetCursorForView(self, index);
980
+ if (if (commit_compiled) (commit_action[0] & 4) != 0 else interaction_changed) try invalidateForCanvasWidgetRenderStateChange(self, index, previous_state, self.views[index].canvasWidgetRenderState());
981
+ }
982
+
983
+ fn compiledCanvasPointerIntent(view: anytype, stage: u8, phase: canvas.WidgetPointerPhase, facts: u8, kind: u16, output: []u8) bool {
984
+ const policy = view.canvas_widget_surface_scope_policy orelse return false;
985
+ var request = [6]u8{ 29, stage, @intFromEnum(phase), facts, 0, 0 };
986
+ std.mem.writeInt(u16, request[4..6], kind, .little);
987
+ if (policy(&request, output) != output.len) @panic("invalid compiled pointer intent result");
988
+ if (stage == 1) {
989
+ if (output.len != 4 or output[0] > 3 or output[1] > 2 or output[2] > 3 or output[3] > 31)
990
+ @panic("invalid compiled pointer intent selectors");
991
+ } else {
992
+ const limit: u8 = if (stage == 0) 15 else if (stage == 3) 7 else if (stage == 4) 24 else 1;
993
+ if (output.len != 1 or output[0] > limit or (stage == 4 and output[0] != 0 and output[0] != 24))
994
+ @panic("invalid compiled pointer intent action");
995
+ }
996
+ return true;
997
+ }
998
+
999
+ fn applyCanvasPointerContainment(view: anytype, actions: u8, pointer_id: u64, point: geometry.PointF, hit: ?canvas.WidgetHit) void {
1000
+ if ((actions & 1) != 0) {
1001
+ view.canvas_widget_hover_pointer_live = true;
1002
+ view.canvas_widget_hover_pointer_id = pointer_id;
1003
+ }
1004
+ if ((actions & 2) != 0) view.canvas_widget_hover_pointer_position = point;
1005
+ if ((actions & 4) != 0) view.setCanvasWidgetHoverMsgChainForHit(hit);
1006
+ if ((actions & 8) != 0) view.canvas_widget_hover_msg_chain_len = 0;
1007
+ if ((actions & 16) != 0) view.canvas_widget_hover_pointer_live = false;
1008
+ }
1009
+
1010
+ pub fn retireCanvasWidgetHoverForConsumedPointer(view: anytype, input: GpuSurfaceInputEvent, inside: bool) void {
1011
+ const proven = view.canvas_widget_hover_pointer_live and view.canvas_widget_hover_pointer_id == input.pointer_id;
1012
+ const phase: canvas.WidgetPointerPhase = switch (input.kind) {
1013
+ .pointer_move => .hover,
1014
+ .pointer_down => .down,
1015
+ .pointer_drag => .move,
1016
+ .pointer_up => .up,
1017
+ .pointer_cancel => .cancel,
1018
+ else => return,
1019
+ };
1020
+ const facts = @as(u8, @intFromBool(proven)) | (@as(u8, @intFromBool(inside)) << 2);
1021
+ var action: [1]u8 = undefined;
1022
+ if (compiledCanvasPointerIntent(view, 4, phase, facts, 0, &action)) {
1023
+ applyCanvasPointerContainment(view, action[0], input.pointer_id, .{ .x = input.x, .y = input.y }, null);
1024
+ } else if (proven and (input.kind == .pointer_cancel or input.kind == .pointer_up and !inside)) {
1025
+ view.canvas_widget_hover_msg_chain_len = 0;
1026
+ view.canvas_widget_hover_pointer_live = false;
1027
+ }
831
1028
  }
832
1029
 
833
1030
  /// The (widget id, snapped sample index) pair chart hover chrome
@@ -1041,12 +1238,21 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1041
1238
  // transition resolution, per cause.
1042
1239
  switch (cause) {
1043
1240
  .pointer => |event| {
1241
+ const phase: u8 = switch (event.phase) {
1242
+ .hover => 0,
1243
+ .down => 1,
1244
+ .move => 2,
1245
+ .up => 3,
1246
+ .cancel => 4,
1247
+ .wheel => 5,
1248
+ };
1044
1249
  const had_pointer_shown = view.canvas_tooltip_shown_id != 0 and !view.canvas_tooltip_shown_from_focus;
1045
1250
  // Hover transitions step the machine (a pointer
1046
1251
  // gliding within one trigger is free); the armed
1047
1252
  // delay itself fires on presented-frame timestamps
1048
1253
  // in advanceCanvasTooltipIntentForFrame.
1049
- if (view.canvas_widget_hovered_id != event.next_hovered_id) {
1254
+ const hover_changed = view.canvas_widget_hovered_id != event.next_hovered_id;
1255
+ if (canvasTooltipReconcileNeeded(view, .hover_change, @intFromBool(hover_changed), hover_changed)) {
1050
1256
  try updateCanvasTooltipIntentForHoverChange(self, view_index, event.next_hovered_id, event.point);
1051
1257
  }
1052
1258
  // While a pointer-shown tooltip is up, EVERY move
@@ -1055,7 +1261,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1055
1261
  // usually changes no hover target (the tooltip is
1056
1262
  // deliberately not hit-tested), so the transition
1057
1263
  // gate above cannot see it.
1058
- if (event.phase == .hover or event.phase == .move) {
1264
+ const travels = event.phase == .hover or event.phase == .move;
1265
+ if (canvasTooltipReconcileNeeded(view, .pointer_travel, phase, travels)) {
1059
1266
  try updateCanvasTooltipIntentForPointerTravel(self, view_index, event.next_hovered_id, event.point);
1060
1267
  // Content-hold release reprocessing: when this
1061
1268
  // move hid the held tooltip (travel left both
@@ -1071,7 +1278,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1071
1278
  // pointer is honestly on that trigger NOW.
1072
1279
  // Idempotent when the transition above already
1073
1280
  // armed it.
1074
- if (had_pointer_shown and view.canvas_tooltip_shown_id == 0 and event.next_hovered_id != 0) {
1281
+ const release_facts: u8 = @as(u8, @intFromBool(had_pointer_shown)) |
1282
+ (@as(u8, @intFromBool(view.canvas_tooltip_shown_id != 0)) << 1) |
1283
+ (@as(u8, @intFromBool(event.next_hovered_id != 0)) << 2);
1284
+ if (canvasTooltipReconcileNeeded(view, .content_release, release_facts, had_pointer_shown and view.canvas_tooltip_shown_id == 0 and event.next_hovered_id != 0)) {
1075
1285
  try updateCanvasTooltipIntentForHoverChange(self, view_index, event.next_hovered_id, event.point);
1076
1286
  }
1077
1287
  }
@@ -1080,7 +1290,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1080
1290
  // alike (after the hover step above, so a down that
1081
1291
  // also moved the hover cannot re-arm or warm past
1082
1292
  // the press).
1083
- if (event.phase == .down) {
1293
+ const down = event.phase == .down;
1294
+ if (canvasTooltipReconcileNeeded(view, .press, phase, down)) {
1084
1295
  try updateCanvasTooltipIntentForPress(self, view_index);
1085
1296
  }
1086
1297
  },
@@ -1090,7 +1301,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1090
1301
  // still dismisses ("pointer-down dismisses" is
1091
1302
  // documented for ANY down — shadcn's Base UI-backed
1092
1303
  // default; macOS help tags vanish on any click).
1093
- if (event.down) try updateCanvasTooltipIntentForPress(self, view_index);
1304
+ if (canvasTooltipReconcileNeeded(view, .press, if (event.down) 1 else 3, event.down))
1305
+ try updateCanvasTooltipIntentForPress(self, view_index);
1094
1306
  },
1095
1307
  // `.pointer_cancel` — the pointer LEAVING the view —
1096
1308
  // short-circuits ahead of any transition gate: its
@@ -1121,7 +1333,9 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1121
1333
  // Pointer-owned tooltips are untouched — hover holds
1122
1334
  // them, and a focus move says nothing about the pointer.
1123
1335
  .programmatic_focus => {
1124
- if (view.canvas_tooltip_shown_id != 0 and view.canvas_tooltip_shown_from_focus) {
1336
+ if (view.applyCompiledCanvasTooltipIntent(.programmatic_focus, 0, 0, false)) |changed| {
1337
+ if (changed) try commitCanvasTooltipVisibility(self, view_index);
1338
+ } else if (view.canvas_tooltip_shown_id != 0 and view.canvas_tooltip_shown_from_focus) {
1125
1339
  view.canvas_tooltip_shown_id = 0;
1126
1340
  view.canvas_tooltip_shown_owner_id = 0;
1127
1341
  view.canvas_tooltip_shown_from_focus = false;
@@ -1140,16 +1354,20 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1140
1354
  // is a stale affordance, and its semantics node would
1141
1355
  // keep claiming visible in the a11y tree.
1142
1356
  .view_blur => {
1143
- const had_shown = view.canvas_tooltip_shown_id != 0;
1144
- view.canvas_tooltip_armed_id = 0;
1145
- view.canvas_tooltip_armed_owner_id = 0;
1146
- view.canvas_tooltip_deadline_ns = 0;
1147
- view.canvas_tooltip_warm_until_ns = 0;
1148
- view.canvas_tooltip_transit_deadline_ns = 0;
1149
- view.canvas_tooltip_shown_id = 0;
1150
- view.canvas_tooltip_shown_owner_id = 0;
1151
- view.canvas_tooltip_shown_from_focus = false;
1152
- if (had_shown) try commitCanvasTooltipVisibility(self, view_index);
1357
+ if (view.applyCompiledCanvasTooltipIntent(.blur, 0, 0, false)) |changed| {
1358
+ if (changed) try commitCanvasTooltipVisibility(self, view_index);
1359
+ } else {
1360
+ const had_shown = view.canvas_tooltip_shown_id != 0;
1361
+ view.canvas_tooltip_armed_id = 0;
1362
+ view.canvas_tooltip_armed_owner_id = 0;
1363
+ view.canvas_tooltip_deadline_ns = 0;
1364
+ view.canvas_tooltip_warm_until_ns = 0;
1365
+ view.canvas_tooltip_transit_deadline_ns = 0;
1366
+ view.canvas_tooltip_shown_id = 0;
1367
+ view.canvas_tooltip_shown_owner_id = 0;
1368
+ view.canvas_tooltip_shown_from_focus = false;
1369
+ if (had_shown) try commitCanvasTooltipVisibility(self, view_index);
1370
+ }
1153
1371
  },
1154
1372
  }
1155
1373
 
@@ -1160,11 +1378,41 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1160
1378
  // an app that receives no further input. The per-frame pump
1161
1379
  // in planCanvasFrameForView takes over from the first
1162
1380
  // planned frame.
1163
- if (view.canvasTooltipIntentArmed()) {
1381
+ const frame_facts: u8 = @as(u8, @intFromBool(view.canvas_tooltip_armed_id != 0)) |
1382
+ (@as(u8, @intFromBool(view.canvas_tooltip_transit_deadline_ns != 0)) << 1);
1383
+ if (canvasTooltipReconcileNeeded(view, .frame, frame_facts, view.canvasTooltipIntentArmed())) {
1164
1384
  self.invalidateFor(.state, view.frame);
1165
1385
  }
1166
1386
  }
1167
1387
 
1388
+ const CanvasTooltipReconcileStage = enum(u8) {
1389
+ hover_change,
1390
+ pointer_travel,
1391
+ content_release,
1392
+ press,
1393
+ point_source,
1394
+ adoption_point,
1395
+ moved_hover,
1396
+ hover_binding_owner,
1397
+ changed_binding,
1398
+ focus_binding_owner,
1399
+ reseed,
1400
+ frame,
1401
+ };
1402
+
1403
+ fn compiledCanvasTooltipReconcileAction(view: anytype, stage: CanvasTooltipReconcileStage, facts: u8) ?u8 {
1404
+ const policy = view.canvas_widget_tooltip_policy orelse return null;
1405
+ const request = [3]u8{ 26, @intFromEnum(stage), facts };
1406
+ var response: [1]u8 = undefined;
1407
+ if (policy(&request, &response) != response.len or response[0] > @as(u8, if (stage == .point_source) 2 else 1))
1408
+ @panic("invalid compiled tooltip reconciliation action");
1409
+ return response[0];
1410
+ }
1411
+
1412
+ fn canvasTooltipReconcileNeeded(view: anytype, stage: CanvasTooltipReconcileStage, facts: u8, native_reference: bool) bool {
1413
+ return if (compiledCanvasTooltipReconcileAction(view, stage, facts)) |action| action != 0 else native_reference;
1414
+ }
1415
+
1168
1416
  /// How a content-moved reconcile treats the transition step:
1169
1417
  /// scrolls are deliberately corridor-free (immediate-hide
1170
1418
  /// semantics — the pointer did not move, the content did, and a
@@ -1200,7 +1448,17 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1200
1448
  // 2. Hover re-hit-test from the stored position (the wheel
1201
1449
  // passes its live point; whichever is used is the truth the
1202
1450
  // rest of this reconcile measures against).
1203
- const effective_point = live_point orelse view.canvas_last_pointer_position orelse {
1451
+ const point_facts: u8 = @as(u8, @intFromBool(live_point != null)) |
1452
+ (@as(u8, @intFromBool(view.canvas_last_pointer_position != null)) << 1);
1453
+ const point_source = compiledCanvasTooltipReconcileAction(view, .point_source, point_facts) orelse
1454
+ @as(u8, if (live_point != null) 1 else if (view.canvas_last_pointer_position != null) 2 else 0);
1455
+ const selected_point = switch (point_source) {
1456
+ 0 => null,
1457
+ 1 => live_point orelse @panic("missing compiled tooltip live point"),
1458
+ 2 => view.canvas_last_pointer_position orelse @panic("missing compiled tooltip stored point"),
1459
+ else => unreachable,
1460
+ };
1461
+ const effective_point = selected_point orelse {
1204
1462
  view.reconcileCanvasWidgetRenderStateAfterScroll(null);
1205
1463
  try closeCanvasTooltipPointerIntent(self, view_index);
1206
1464
  // A keyboard-only session has no pointer to place, but
@@ -1234,7 +1492,20 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1234
1492
  // continuous scrolls or rebuilds re-arm the bounded grace
1235
1493
  // forever under a stationary pointer.
1236
1494
  var held_released = false;
1237
- if (view.canvas_tooltip_shown_id != 0 and !view.canvas_tooltip_shown_from_focus) {
1495
+ if (view.canvas_widget_tooltip_policy != null) {
1496
+ const facts: u16 = @as(u16, @intFromBool(view.canvas_tooltip_shown_id != 0)) |
1497
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_from_focus)) << 1) |
1498
+ (@as(u16, @intFromBool(next_hovered_id != 0 and next_hovered_id == view.canvas_tooltip_shown_owner_id)) << 2) |
1499
+ (@as(u16, @intFromBool(canvasTooltipShownContentContains(view, effective_point))) << 3);
1500
+ const actions = compiledCanvasTooltipPointerActions(view, 4, facts, 11);
1501
+ if ((actions & 1) != 0) view.canvas_tooltip_transit_deadline_ns = 0;
1502
+ if ((actions & 2) != 0) view.canvas_tooltip_pointer_from = effective_point;
1503
+ if ((actions & 8) != 0) {
1504
+ hideShownCanvasTooltipWithWarmth(view, canvasRenderAnimationStartNsForView(view));
1505
+ try commitCanvasTooltipVisibility(self, view_index);
1506
+ held_released = true;
1507
+ }
1508
+ } else if (view.canvas_tooltip_shown_id != 0 and !view.canvas_tooltip_shown_from_focus) {
1238
1509
  const on_owner = next_hovered_id != 0 and next_hovered_id == view.canvas_tooltip_shown_owner_id;
1239
1510
  if (on_owner or canvasTooltipShownContentContains(view, effective_point)) {
1240
1511
  view.canvas_tooltip_pointer_from = effective_point;
@@ -1249,21 +1520,13 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1249
1520
  // 4. Transition resolution. Scroll transitions run
1250
1521
  // point-blind (no corridor — see the mode doc above);
1251
1522
  // adoption's pass the stored point through.
1252
- const transition_point: ?geometry.PointF = switch (cause) {
1253
- .scroll => null,
1254
- .adoption => effective_point,
1255
- };
1256
- if (next_hovered_id != previous_hovered_id) {
1257
- try updateCanvasTooltipIntentForHoverChange(self, view_index, next_hovered_id, transition_point);
1258
- } else if (held_released and next_hovered_id != 0) {
1259
- // Content-hold release reprocessing, the content-moved
1260
- // shape: the hold broke while the hover id stayed put
1261
- // on a trigger the pointer had reached THROUGH the
1262
- // tooltip's frame. That id was recorded under stale
1263
- // ownership — the frame claimed the hover — so it never
1264
- // stepped the machine; reprocess it as a fresh
1265
- // transition so the trigger under the pointer arms (or
1266
- // warm-shows) per the normal rules.
1523
+ const adoption = cause == .adoption;
1524
+ const transition_point: ?geometry.PointF = if (canvasTooltipReconcileNeeded(view, .adoption_point, @intFromBool(adoption), adoption)) effective_point else null;
1525
+ const hover_changed = next_hovered_id != previous_hovered_id;
1526
+ const transition_facts: u8 = @as(u8, @intFromBool(hover_changed)) |
1527
+ (@as(u8, @intFromBool(held_released)) << 1) |
1528
+ (@as(u8, @intFromBool(next_hovered_id != 0)) << 2);
1529
+ if (canvasTooltipReconcileNeeded(view, .moved_hover, transition_facts, hover_changed or (held_released and next_hovered_id != 0))) {
1267
1530
  try updateCanvasTooltipIntentForHoverChange(self, view_index, next_hovered_id, transition_point);
1268
1531
  }
1269
1532
  // Binding-change step, adoption only: the transition gate
@@ -1313,9 +1576,13 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1313
1576
  // pointer activity keeps the instant-show courtesy.
1314
1577
  switch (cause) {
1315
1578
  .adoption => |bindings| {
1316
- if (bindings.hovered_owner_id != 0 and next_hovered_id == bindings.hovered_owner_id) {
1579
+ const owner_facts: u8 = @as(u8, @intFromBool(bindings.hovered_owner_id != 0)) |
1580
+ (@as(u8, @intFromBool(next_hovered_id == bindings.hovered_owner_id)) << 1);
1581
+ if (canvasTooltipReconcileNeeded(view, .hover_binding_owner, owner_facts, bindings.hovered_owner_id != 0 and next_hovered_id == bindings.hovered_owner_id)) {
1317
1582
  const adopted_tooltip_id = view.canvasWidgetOwnedTooltipIdForOwner(next_hovered_id);
1318
- if (adopted_tooltip_id != 0 and adopted_tooltip_id != bindings.hovered_tooltip_id) {
1583
+ const binding_facts: u8 = @as(u8, @intFromBool(adopted_tooltip_id != 0)) |
1584
+ (@as(u8, @intFromBool(adopted_tooltip_id != bindings.hovered_tooltip_id)) << 1);
1585
+ if (canvasTooltipReconcileNeeded(view, .changed_binding, binding_facts, adopted_tooltip_id != 0 and adopted_tooltip_id != bindings.hovered_tooltip_id)) {
1319
1586
  try updateCanvasTooltipIntentForHoverChange(self, view_index, next_hovered_id, transition_point);
1320
1587
  }
1321
1588
  }
@@ -1326,8 +1593,12 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1326
1593
  // Whichever position drove this reconcile re-seeds the
1327
1594
  // corridor apex for whatever the step armed or warm-showed,
1328
1595
  // so a later leave fans out from the truth.
1329
- if (next_hovered_id != 0 and (view.canvas_tooltip_armed_owner_id == next_hovered_id or
1330
- (view.canvas_tooltip_shown_owner_id == next_hovered_id and !view.canvas_tooltip_shown_from_focus)))
1596
+ const reseed_facts: u8 = @as(u8, @intFromBool(next_hovered_id != 0)) |
1597
+ (@as(u8, @intFromBool(view.canvas_tooltip_armed_owner_id == next_hovered_id)) << 1) |
1598
+ (@as(u8, @intFromBool(view.canvas_tooltip_shown_owner_id == next_hovered_id)) << 2) |
1599
+ (@as(u8, @intFromBool(view.canvas_tooltip_shown_from_focus)) << 3);
1600
+ if (canvasTooltipReconcileNeeded(view, .reseed, reseed_facts, next_hovered_id != 0 and (view.canvas_tooltip_armed_owner_id == next_hovered_id or
1601
+ (view.canvas_tooltip_shown_owner_id == next_hovered_id and !view.canvas_tooltip_shown_from_focus))))
1331
1602
  {
1332
1603
  view.canvas_tooltip_pointer_from = effective_point;
1333
1604
  }
@@ -1351,11 +1622,16 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1351
1622
  /// rebuild path must stay silent).
1352
1623
  fn reconcileCanvasTooltipIntentForAdoptedFocusBinding(self: *Runtime, view_index: usize, bindings: CanvasTooltipAdoptionBindingSnapshot) anyerror!void {
1353
1624
  const view = &self.views[view_index];
1354
- if (bindings.focus_visible_owner_id == 0) return;
1355
- if (!view.focused or !view.canvas_widget_focus_visible_keyboard) return;
1356
- if (view.canvas_widget_focus_visible_id != bindings.focus_visible_owner_id) return;
1625
+ const owner_facts: u8 = @as(u8, @intFromBool(bindings.focus_visible_owner_id != 0)) |
1626
+ (@as(u8, @intFromBool(view.focused)) << 1) |
1627
+ (@as(u8, @intFromBool(view.canvas_widget_focus_visible_keyboard)) << 2) |
1628
+ (@as(u8, @intFromBool(view.canvas_widget_focus_visible_id == bindings.focus_visible_owner_id)) << 3);
1629
+ if (!canvasTooltipReconcileNeeded(view, .focus_binding_owner, owner_facts, bindings.focus_visible_owner_id != 0 and view.focused and view.canvas_widget_focus_visible_keyboard and
1630
+ view.canvas_widget_focus_visible_id == bindings.focus_visible_owner_id)) return;
1357
1631
  const adopted_tooltip_id = view.canvasWidgetOwnedTooltipIdForOwner(bindings.focus_visible_owner_id);
1358
- if (adopted_tooltip_id == 0 or adopted_tooltip_id == bindings.focus_visible_tooltip_id) return;
1632
+ const binding_facts: u8 = @as(u8, @intFromBool(adopted_tooltip_id != 0)) |
1633
+ (@as(u8, @intFromBool(adopted_tooltip_id != bindings.focus_visible_tooltip_id)) << 1);
1634
+ if (!canvasTooltipReconcileNeeded(view, .changed_binding, binding_facts, adopted_tooltip_id != 0 and adopted_tooltip_id != bindings.focus_visible_tooltip_id)) return;
1359
1635
  try updateCanvasTooltipIntentForFocusVisibleChange(self, view_index, bindings.focus_visible_owner_id);
1360
1636
  }
1361
1637
 
@@ -1397,6 +1673,41 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1397
1673
  };
1398
1674
  const tooltip_id: canvas.ObjectId = if (tooltip_index) |node_index| view.widget_layout_nodes[node_index].widget.id else 0;
1399
1675
 
1676
+ if (view.canvas_widget_tooltip_policy != null) {
1677
+ const delay_ns = if (tooltip_index) |i| canvasTooltipShowDelayNs(view.widget_layout_nodes[i].widget, view.widget_tokens) else 0;
1678
+ const facts: u16 = @as(u16, @intFromBool(view.canvas_tooltip_shown_id != 0)) |
1679
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_from_focus)) << 1) |
1680
+ (@as(u16, @intFromBool(tooltip_id != 0)) << 2) |
1681
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_id == tooltip_id)) << 3) |
1682
+ (@as(u16, @intFromBool(view.canvas_tooltip_armed_id != 0)) << 4) |
1683
+ (@as(u16, @intFromBool(view.canvas_tooltip_armed_id == tooltip_id)) << 5) |
1684
+ (@as(u16, @intFromBool(canvasTooltipShownContentContains(view, point))) << 6) |
1685
+ (@as(u16, @intFromBool(canvasTooltipTravelRegionContains(view, point))) << 7) |
1686
+ (@as(u16, @intFromBool(canvasTooltipIntentActionAllowed(self, view_index))) << 8) |
1687
+ (@as(u16, @intFromBool(delay_ns == 0)) << 9) |
1688
+ (@as(u16, @intFromBool(now_ns < view.canvas_tooltip_warm_until_ns)) << 10) |
1689
+ (@as(u16, @intFromBool(canvasTooltipWarmWindowNs(view.widget_tokens) != 0)) << 11);
1690
+ const actions = compiledCanvasTooltipPointerActions(view, 0, facts, 15);
1691
+ if ((actions & (4 | 8)) != 0 and (tooltip_id == 0 or !canvasTooltipIntentActionAllowed(self, view_index)))
1692
+ @panic("ineligible compiled tooltip pointer reveal");
1693
+ if ((actions & 2) != 0) hideShownCanvasTooltipWithWarmth(view, now_ns);
1694
+ if ((actions & 1) != 0) clearCanvasTooltipArm(view);
1695
+ if ((actions & 4) != 0) {
1696
+ view.canvas_tooltip_shown_id = tooltip_id;
1697
+ view.canvas_tooltip_shown_owner_id = next_hovered_id;
1698
+ view.canvas_tooltip_shown_from_focus = false;
1699
+ clearCanvasTooltipArm(view);
1700
+ view.canvas_tooltip_transit_deadline_ns = 0;
1701
+ if (point) |value| view.canvas_tooltip_pointer_from = value;
1702
+ } else if ((actions & 8) != 0) {
1703
+ view.canvas_tooltip_armed_id = tooltip_id;
1704
+ view.canvas_tooltip_armed_owner_id = next_hovered_id;
1705
+ view.canvas_tooltip_deadline_ns = now_ns + delay_ns;
1706
+ if (point) |value| view.canvas_tooltip_pointer_from = value;
1707
+ }
1708
+ if ((actions & (2 | 4)) != 0) try commitCanvasTooltipVisibility(self, view_index);
1709
+ return;
1710
+ }
1400
1711
  var shown_changed = false;
1401
1712
  // The pointer sitting inside the shown tooltip's own frame
1402
1713
  // holds it open (WCAG 1.4.13: hover-revealed content must be
@@ -1497,6 +1808,22 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1497
1808
  /// deterministic (Base UI's safe polygon is unbounded).
1498
1809
  fn updateCanvasTooltipIntentForPointerTravel(self: *Runtime, view_index: usize, next_hovered_id: canvas.ObjectId, point: geometry.PointF) anyerror!void {
1499
1810
  const view = &self.views[view_index];
1811
+ if (view.canvas_widget_tooltip_policy != null) {
1812
+ const facts: u16 = @as(u16, @intFromBool(view.canvas_tooltip_shown_id != 0)) |
1813
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_from_focus)) << 1) |
1814
+ (@as(u16, @intFromBool(next_hovered_id != 0 and next_hovered_id == view.canvas_tooltip_shown_owner_id)) << 2) |
1815
+ (@as(u16, @intFromBool(canvasTooltipShownContentContains(view, point))) << 3) |
1816
+ (@as(u16, @intFromBool(canvasTooltipTravelRegionContains(view, point))) << 4);
1817
+ const actions = compiledCanvasTooltipPointerActions(view, 1, facts, 15);
1818
+ if ((actions & 1) != 0) view.canvas_tooltip_transit_deadline_ns = 0;
1819
+ if ((actions & 2) != 0) view.canvas_tooltip_pointer_from = point;
1820
+ if ((actions & 4) != 0) view.canvas_tooltip_transit_deadline_ns = canvasRenderAnimationStartNsForView(view) + tooltip_transit_grace_ms * std.time.ns_per_ms;
1821
+ if ((actions & 8) != 0) {
1822
+ hideShownCanvasTooltipWithWarmth(view, canvasRenderAnimationStartNsForView(view));
1823
+ try commitCanvasTooltipVisibility(self, view_index);
1824
+ }
1825
+ return;
1826
+ }
1500
1827
  if (view.canvas_tooltip_shown_id == 0 or view.canvas_tooltip_shown_from_focus) {
1501
1828
  view.canvas_tooltip_transit_deadline_ns = 0;
1502
1829
  return;
@@ -1516,6 +1843,22 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1516
1843
  try commitCanvasTooltipVisibility(self, view_index);
1517
1844
  }
1518
1845
 
1846
+ /// The existing callback copies the borrowed result before another
1847
+ /// compiled call; neither input nor output escapes or resets the cycle.
1848
+ fn compiledCanvasTooltipPointerActions(view: anytype, cause: u8, facts: u16, allowed: u8) u8 {
1849
+ const request = [4]u8{ 25, cause, @truncate(facts), @truncate(facts >> 8) };
1850
+ var output: [1]u8 = undefined;
1851
+ if (view.canvas_widget_tooltip_policy.?(&request, &output) != output.len or (output[0] & ~allowed) != 0)
1852
+ @panic("invalid compiled tooltip pointer result");
1853
+ return output[0];
1854
+ }
1855
+
1856
+ fn clearCanvasTooltipArm(view: anytype) void {
1857
+ view.canvas_tooltip_armed_id = 0;
1858
+ view.canvas_tooltip_armed_owner_id = 0;
1859
+ view.canvas_tooltip_deadline_ns = 0;
1860
+ }
1861
+
1519
1862
  /// Hide the pointer-shown tooltip and open the shared warm
1520
1863
  /// window — the one pointer-hide shape every path shares. Any
1521
1864
  /// in-flight transit grace dies with the tooltip it was holding.
@@ -1658,6 +2001,36 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1658
2001
  /// frames coming while a delay is armed.
1659
2002
  pub fn advanceCanvasTooltipIntentForFrame(self: *Runtime, view_index: usize, timestamp_ns: u64) anyerror!void {
1660
2003
  const view = &self.views[view_index];
2004
+ if (view.canvas_widget_tooltip_policy != null) {
2005
+ const allowed = canvasTooltipIntentActionAllowed(self, view_index);
2006
+ const facts: u16 = @as(u16, @intFromBool(allowed)) |
2007
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_id != 0)) << 1) |
2008
+ (@as(u16, @intFromBool(view.canvas_tooltip_shown_from_focus)) << 2) |
2009
+ (@as(u16, @intFromBool(view.canvas_tooltip_transit_deadline_ns != 0 and timestamp_ns >= view.canvas_tooltip_transit_deadline_ns)) << 3);
2010
+ const expiry = compiledCanvasTooltipPointerActions(view, 2, facts, 3);
2011
+ if ((expiry & 1) != 0) {
2012
+ clearCanvasTooltipArm(view);
2013
+ view.canvas_tooltip_transit_deadline_ns = 0;
2014
+ return;
2015
+ }
2016
+ if ((expiry & 2) != 0) {
2017
+ hideShownCanvasTooltipWithWarmth(view, timestamp_ns);
2018
+ try commitCanvasTooltipVisibility(self, view_index);
2019
+ }
2020
+ const promote_facts: u16 = @as(u16, @intFromBool(view.canvas_tooltip_armed_id != 0)) |
2021
+ (@as(u16, @intFromBool(timestamp_ns >= view.canvas_tooltip_deadline_ns)) << 1);
2022
+ if (compiledCanvasTooltipPointerActions(view, 3, promote_facts, 1) != 0) {
2023
+ if (!allowed or view.canvas_tooltip_armed_id == 0 or timestamp_ns < view.canvas_tooltip_deadline_ns)
2024
+ @panic("ineligible compiled tooltip deadline promotion");
2025
+ view.canvas_tooltip_shown_id = view.canvas_tooltip_armed_id;
2026
+ view.canvas_tooltip_shown_owner_id = view.canvas_tooltip_armed_owner_id;
2027
+ view.canvas_tooltip_shown_from_focus = false;
2028
+ clearCanvasTooltipArm(view);
2029
+ view.canvas_tooltip_transit_deadline_ns = 0;
2030
+ try commitCanvasTooltipVisibility(self, view_index);
2031
+ }
2032
+ return;
2033
+ }
1661
2034
  // A suppressed view promotes nothing: with the arm paths
1662
2035
  // gated on the same predicate and both suppression edges
1663
2036
  // (app deactivation, window key-loss) resetting the armed
@@ -1788,6 +2161,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1788
2161
 
1789
2162
  fn updateCanvasTooltipIntentForPress(self: *Runtime, view_index: usize) anyerror!void {
1790
2163
  const view = &self.views[view_index];
2164
+ if (view.applyCompiledCanvasTooltipIntent(.press, 0, 0, false)) |changed| {
2165
+ if (changed) try commitCanvasTooltipVisibility(self, view_index);
2166
+ return;
2167
+ }
1791
2168
  view.canvas_tooltip_armed_id = 0;
1792
2169
  view.canvas_tooltip_armed_owner_id = 0;
1793
2170
  view.canvas_tooltip_deadline_ns = 0;
@@ -1823,6 +2200,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1823
2200
  };
1824
2201
  const tooltip_id: canvas.ObjectId = if (tooltip_index) |node_index| view.widget_layout_nodes[node_index].widget.id else 0;
1825
2202
 
2203
+ if (view.applyCompiledCanvasTooltipIntent(.focus, tooltip_id, focus_visible_id, canvasTooltipIntentActionAllowed(self, view_index))) |changed| {
2204
+ if (changed) try commitCanvasTooltipVisibility(self, view_index);
2205
+ return;
2206
+ }
1826
2207
  var shown_changed = false;
1827
2208
  if (view.canvas_tooltip_shown_id != 0 and view.canvas_tooltip_shown_from_focus and view.canvas_tooltip_shown_id != tooltip_id) {
1828
2209
  view.canvas_tooltip_shown_id = 0;
@@ -1896,6 +2277,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
1896
2277
  break :blk view.widget_layout_nodes[tooltip_index].widget.id;
1897
2278
  };
1898
2279
  if (tooltip_id == 0) return;
2280
+ if (view.applyCompiledCanvasTooltipIntent(.activation, tooltip_id, target.id, false)) |changed| {
2281
+ if (changed) try commitCanvasTooltipVisibility(self, index);
2282
+ return;
2283
+ }
1899
2284
  var matched = false;
1900
2285
  if (view.canvas_tooltip_armed_id == tooltip_id) {
1901
2286
  view.canvas_tooltip_armed_id = 0;
@@ -2013,10 +2398,20 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2013
2398
  if (self.options.platform.services.set_window_drag_regions_fn == null) return;
2014
2399
  const view = &self.views[view_index];
2015
2400
  var regions: [canvas_limits.max_canvas_widget_window_drag_regions_per_view]platform.WindowDragRegion = undefined;
2016
- const count = collectCanvasWidgetWindowDragRegions(view.widgetLayoutTree(), &regions);
2017
- if (view.canvas_widget_drag_regions_pushed) {
2401
+ const compiled = host_regions.plan(view.canvas_widget_surface_scope_policy, .drag, .{
2402
+ .nodes = view.widgetLayoutTree().nodes,
2403
+ .drag_service = true,
2404
+ .drag_pushed = view.canvas_widget_drag_regions_pushed,
2405
+ .previous = view.canvas_widget_drag_regions[0..view.canvas_widget_drag_region_count],
2406
+ });
2407
+ const count = if (compiled) |program| count: {
2408
+ if (program.detail == 0) return;
2409
+ @memcpy(regions[0..program.region_count], program.regions[0..program.region_count]);
2410
+ break :count program.region_count;
2411
+ } else collectCanvasWidgetWindowDragRegions(view.widgetLayoutTree(), &regions);
2412
+ if (compiled == null and view.canvas_widget_drag_regions_pushed) {
2018
2413
  if (count == view.canvas_widget_drag_region_count and windowDragRegionsEqual(regions[0..count], view.canvas_widget_drag_regions[0..count])) return;
2019
- } else if (count == 0) {
2414
+ } else if (compiled == null and count == 0) {
2020
2415
  return;
2021
2416
  }
2022
2417
  try self.options.platform.services.setWindowDragRegions(view.window_id, view.label, regions[0..count]);
@@ -2118,6 +2513,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2118
2513
  /// courtesy earned by a pointer we cannot place.
2119
2514
  fn closeCanvasTooltipPointerIntent(self: *Runtime, view_index: usize) anyerror!void {
2120
2515
  const view = &self.views[view_index];
2516
+ if (view.applyCompiledCanvasTooltipIntent(.pointer_close, 0, 0, false)) |changed| {
2517
+ if (changed) try commitCanvasTooltipVisibility(self, view_index);
2518
+ return;
2519
+ }
2121
2520
  view.canvas_tooltip_armed_id = 0;
2122
2521
  view.canvas_tooltip_armed_owner_id = 0;
2123
2522
  view.canvas_tooltip_deadline_ns = 0;
@@ -2171,7 +2570,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2171
2570
  const index = runtimeFindViewIndex(self, pointer_event.window_id, pointer_event.view_label) orelse return;
2172
2571
  if (self.views[index].kind != .gpu_surface) return;
2173
2572
 
2174
- const dirty = try self.views[index].applyCanvasWidgetScrollRoute(pointer_event.route, pointer_event.pointer.delta, .wheel) orelse return;
2573
+ const source: runtime_view.CanvasWidgetScrollSource = if (pointer_event.pointer.scroll_is_detented) .detented_wheel else .wheel;
2574
+ const dirty = try self.views[index].applyCanvasWidgetScrollRoute(pointer_event.route, pointer_event.pointer.delta, source) orelse return;
2175
2575
  const previous_cursor = self.views[index].canvas_widget_cursor;
2176
2576
  try reconcileCanvasWidgetRenderStateAfterScrollWithTooltipIntent(self, index, pointer_event.pointer.point);
2177
2577
  if (previous_cursor != self.views[index].canvas_widget_cursor) try syncCanvasWidgetCursorForView(self, index);
@@ -2210,13 +2610,18 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2210
2610
  paste_buffer: []u8,
2211
2611
  ) anyerror!void {
2212
2612
  if (input_event.kind != .key_down) return;
2213
- const action = canvas.widgetKeyboardClipboardAction(.{
2214
- .phase = .key_down,
2215
- .key = input_event.key,
2216
- .modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers),
2217
- }) orelse return;
2218
2613
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return;
2219
2614
  if (self.views[index].kind != .gpu_surface or !self.views[index].focused) return;
2615
+ const keyboard = canvas.WidgetKeyboardEvent{
2616
+ .phase = .key_down,
2617
+ .key = input_event.key,
2618
+ .modifiers = if (normalizedInput(self, input_event)) |program| program.keyboardModifiers() else canvasWidgetKeyboardModifiers(input_event.modifiers),
2619
+ };
2620
+ const focused_index = self.views[index].canvasWidgetNodeIndexById(self.views[index].canvas_widget_focused_id);
2621
+ const action = (if (focused_index) |node_index|
2622
+ canvas.widgetKeyboardClipboardActionForWidget(self.views[index].widget_layout_nodes[node_index].widget, keyboard)
2623
+ else
2624
+ canvas.widgetKeyboardClipboardAction(keyboard)) orelse return;
2220
2625
 
2221
2626
  switch (action) {
2222
2627
  .copy => {
@@ -2275,8 +2680,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2275
2680
  const node_index = self.views[view_index].canvasWidgetNodeIndexById(target.id) orelse return null;
2276
2681
  const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
2277
2682
  if (!canvas_widget_runtime.canvasWidgetEditableTextKind(widget.kind) or widget.state.disabled) return null;
2278
- const range = canvas.widgetTextSelectionRange(widget) orelse return null;
2279
- if (range.isCollapsed(widget.text.len)) return null;
2683
+ const range = canvas.widgetTextClipboardState(widget).selection orelse return null;
2280
2684
  return widget.text[range.start..range.end];
2281
2685
  }
2282
2686
 
@@ -2299,6 +2703,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2299
2703
  const index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse return;
2300
2704
  if (self.views[index].kind != .gpu_surface) return;
2301
2705
  const target = keyboard_event.target orelse return;
2706
+ const target_node = self.views[index].widgetLayoutTree().findById(target.id) orelse return;
2302
2707
  const history_shortcut = if (!keyboard_event.history_replay)
2303
2708
  self.views[index].canvasWidgetTextHistoryShortcut(target, keyboard_event.keyboard)
2304
2709
  else
@@ -2326,7 +2731,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2326
2731
  const edit = if (keyboard_event.history_replay)
2327
2732
  derived
2328
2733
  else
2329
- canvas.sanitizedSingleLineTextInputEvent(target.kind, derived) orelse {
2734
+ canvas.sanitizedTextInputEventForWidget(target_node.widget, derived) orelse {
2330
2735
  keyboard_event.keyboard.edit = null;
2331
2736
  return;
2332
2737
  };
@@ -2342,6 +2747,23 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2342
2747
  try self.views[index].applyCanvasWidgetTextEditWithoutHistory(target.id, edit) orelse return
2343
2748
  else
2344
2749
  try self.views[index].applyCanvasWidgetTextEdit(target.id, edit) orelse return;
2750
+ // Keyboard Escape closes this editor's composition directly. It
2751
+ // must release the native IME owner too, or later text intended
2752
+ // for a newly focused editor still routes to the canceled one.
2753
+ // Host IME cancel events keep their separate converted-commit
2754
+ // grace (cancel followed by text_input), handled by GPU routing.
2755
+ var escape_facts = input_composition.observations(self, &self.views[index]);
2756
+ escape_facts.claimed = edit == .cancel_composition;
2757
+ escape_facts.routed_id = target.id;
2758
+ const escape_input = GpuSurfaceInputEvent{ .window_id = keyboard_event.window_id, .label = keyboard_event.view_label, .kind = if (keyboard_event.keyboard.phase == .key_down) .key_down else .text_input };
2759
+ if (input_composition.plan(self.views[index].canvas_widget_surface_scope_policy, .escape, escape_input, escape_facts)) |program| {
2760
+ input_composition.installWidget(&self.views[index], program);
2761
+ } else if (edit == .cancel_composition and keyboard_event.keyboard.phase == .key_down and
2762
+ self.views[index].canvas_widget_ime_owner_id == target.id)
2763
+ {
2764
+ self.views[index].canvas_widget_ime_owner_id = 0;
2765
+ self.views[index].canvas_widget_ime_commit_grace = .none;
2766
+ }
2345
2767
  if (keyboard_event.history_replay) {
2346
2768
  self.views[index].commitCanvasWidgetTextHistoryReplayIfComplete(
2347
2769
  target,
@@ -2543,10 +2965,10 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2543
2965
  /// focus back on the trigger).
2544
2966
  pub fn dismissCanvasWidgetSurfaceFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent) anyerror!canvas.ObjectId {
2545
2967
  if (input_event.kind != .key_down) return 0;
2546
- const escape = canvasWidgetEscapeKey(input_event.key);
2968
+ const escape = if (normalizedInput(self, input_event)) |program| program.has(2) else canvasWidgetEscapeKey(input_event.key);
2547
2969
  const tab = std.ascii.eqlIgnoreCase(input_event.key, "tab");
2548
2970
  if (!escape and !tab) return 0;
2549
- const modifiers = canvasWidgetKeyboardModifiers(input_event.modifiers);
2971
+ const modifiers = if (normalizedInput(self, input_event)) |program| program.keyboardModifiers() else canvasWidgetKeyboardModifiers(input_event.modifiers);
2550
2972
  if (modifiers.hasNavigationModifier()) return 0;
2551
2973
  // Shift+Tab is still focus departure; Shift+Escape is not a
2552
2974
  // dismissal chord at all.
@@ -2592,7 +3014,8 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2592
3014
  if (view_index >= self.view_count) return error.ViewNotFound;
2593
3015
  const node_index = self.views[view_index].canvasWidgetNodeIndexById(id) orelse return;
2594
3016
  const widget = self.views[view_index].widget_layout_nodes[node_index].widget;
2595
- if (!canvasWidgetCommandable(widget.kind)) return;
3017
+ const eligible = compiledCanvasCommandActivation(&self.views[view_index], 0, 0, 0, 0, widget.kind) orelse canvasWidgetCommandable(widget.kind);
3018
+ if (!eligible) return;
2596
3019
  const command = self.views[view_index].canvasWidgetCommand(id) orelse return;
2597
3020
  try self.dispatchCommand(app, .{
2598
3021
  .name = command,
@@ -2613,21 +3036,27 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2613
3036
  // press); the release may land anywhere within the claiming
2614
3037
  // widget's bounds or the raw target's own bounds.
2615
3038
  const press = pointer_event.press_target orelse return;
2616
- switch (pointer_event.pointer.phase) {
3039
+ if (self.views[index].canvas_widget_surface_scope_policy != null) {
3040
+ const pressed_id = if (pointer_event.pointer.captured_id != 0) pointer_event.pointer.captured_id else self.views[index].canvas_widget_pressed_id;
3041
+ const facts: u8 = @as(u8, @intFromBool(pressed_id == target.id)) |
3042
+ (@as(u8, @intFromBool(press.id != target.id)) << 1) |
3043
+ (@as(u8, @intFromBool(press.bounds.normalized().containsPoint(pointer_event.pointer.point))) << 2) |
3044
+ (@as(u8, @intFromBool(target.bounds.normalized().containsPoint(pointer_event.pointer.point))) << 3);
3045
+ if (!compiledCanvasCommandActivation(&self.views[index], 1, @intFromEnum(pointer_event.pointer.phase), 0, facts, press.kind).?) return;
3046
+ } else switch (pointer_event.pointer.phase) {
2617
3047
  .down => {
2618
3048
  if (!canvasWidgetCommandFiresOnPointerDown(press.kind)) return;
2619
3049
  if (!canvasWidgetPressReleaseInBounds(press, target, pointer_event.pointer.point)) return;
2620
- try dispatchCanvasWidgetCommandForId(self, app, index, press.id);
2621
3050
  },
2622
3051
  .up => {
2623
3052
  if (canvasWidgetCommandFiresOnPointerDown(press.kind)) return;
2624
3053
  const pressed_id = if (pointer_event.pointer.captured_id != 0) pointer_event.pointer.captured_id else self.views[index].canvas_widget_pressed_id;
2625
3054
  if (pressed_id != target.id) return;
2626
3055
  if (!canvasWidgetPressReleaseInBounds(press, target, pointer_event.pointer.point)) return;
2627
- try dispatchCanvasWidgetCommandForId(self, app, index, press.id);
2628
3056
  },
2629
3057
  .hover, .move, .cancel, .wheel => return,
2630
3058
  }
3059
+ try dispatchCanvasWidgetCommandForId(self, app, index, press.id);
2631
3060
  }
2632
3061
 
2633
3062
  fn canvasWidgetPressReleaseInBounds(press: canvas.WidgetHit, target: canvas.WidgetHit, point: geometry.PointF) bool {
@@ -2636,37 +3065,50 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2636
3065
  }
2637
3066
 
2638
3067
  pub fn dispatchCanvasWidgetCommandFromKeyboard(self: *Runtime, app: runtime_api.App(Runtime), keyboard_event: CanvasWidgetKeyboardEvent) anyerror!void {
2639
- if (keyboard_event.keyboard.phase != .key_down or keyboard_event.keyboard.modifiers.hasNavigationModifier()) return;
2640
3068
  const target = keyboard_event.target orelse return;
2641
- // Activation keys press any commandable target; the menu-open
2642
- // arrows press select/combobox triggers too — the same keymap
2643
- // the control-intent resolver applies for `on_press`, kept in
2644
- // lockstep so command-string apps open their pickers from the
2645
- // keyboard exactly like TEA apps.
2646
- const arrow_opens = (target.kind == .select or target.kind == .combobox) and
2647
- canvas.isWidgetMenuOpenArrowKey(keyboard_event.keyboard.key) and
2648
- !(target.state.expanded orelse false);
2649
- if (!canvas.isWidgetActivationKey(keyboard_event.keyboard.key) and !arrow_opens) return;
2650
- if (arrow_opens and keyboard_event.keyboard.focus_moved) return;
2651
3069
  const index = runtimeFindViewIndex(self, keyboard_event.window_id, keyboard_event.view_label) orelse return;
2652
3070
  if (self.views[index].kind != .gpu_surface) return;
3071
+ if (self.views[index].canvas_widget_surface_scope_policy != null) {
3072
+ const key: u8 = if (std.ascii.eqlIgnoreCase(keyboard_event.keyboard.key, "space")) 1 else if (std.ascii.eqlIgnoreCase(keyboard_event.keyboard.key, "enter")) 2 else if (std.ascii.eqlIgnoreCase(keyboard_event.keyboard.key, "arrowup")) 3 else if (std.ascii.eqlIgnoreCase(keyboard_event.keyboard.key, "arrowdown")) 4 else 0;
3073
+ const facts: u8 = @as(u8, @intFromBool(keyboard_event.keyboard.modifiers.hasNavigationModifier())) |
3074
+ (@as(u8, @intFromBool(target.state.expanded orelse false)) << 1) |
3075
+ (@as(u8, @intFromBool(keyboard_event.keyboard.focus_moved)) << 2);
3076
+ if (!compiledCanvasCommandActivation(&self.views[index], 2, @intFromEnum(keyboard_event.keyboard.phase), key, facts, target.kind).?) return;
3077
+ } else {
3078
+ if (keyboard_event.keyboard.phase != .key_down or keyboard_event.keyboard.modifiers.hasNavigationModifier()) return;
3079
+ const arrow_opens = (target.kind == .select or target.kind == .combobox) and
3080
+ canvas.isWidgetMenuOpenArrowKey(keyboard_event.keyboard.key) and !(target.state.expanded orelse false);
3081
+ if (!canvas.isWidgetActivationKey(keyboard_event.keyboard.key) and !arrow_opens) return;
3082
+ if (arrow_opens and keyboard_event.keyboard.focus_moved) return;
3083
+ }
2653
3084
  try dispatchCanvasWidgetCommandForId(self, app, index, target.id);
2654
3085
  }
2655
3086
 
3087
+ fn compiledCanvasCommandActivation(view: anytype, stage: u8, phase: u8, key: u8, facts: u8, kind: canvas.WidgetKind) ?bool {
3088
+ const policy = view.canvas_widget_surface_scope_policy orelse return null;
3089
+ var request = [7]u8{ 30, stage, phase, key, facts, 0, 0 };
3090
+ std.mem.writeInt(u16, request[5..7], canvas.widgetKindCode(kind), .little);
3091
+ var result: [1]u8 = undefined;
3092
+ if (policy(&request, &result) != result.len or result[0] > 1) @panic("invalid compiled command activation result");
3093
+ return result[0] != 0;
3094
+ }
3095
+
2656
3096
  /// Returns true for an auto-repeat or release belonging to the
2657
3097
  /// physical Tab gesture that moved focus into a Tab-owning editor.
2658
3098
  /// The caller suppresses that transition; the release also
2659
3099
  /// retires the gesture latch.
2660
3100
  pub fn consumeCanvasWidgetTabInputFocusEntry(self: *Runtime, input_event: GpuSurfaceInputEvent) bool {
2661
- if (input_event.kind != .key_down and input_event.kind != .key_up) return false;
2662
- if (!std.ascii.eqlIgnoreCase(input_event.key, "tab")) return false;
2663
3101
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
2664
- if (self.views[index].kind != .gpu_surface) return false;
2665
- if (!self.views[index].canvas_widget_tab_input_focus_entry_held) return false;
2666
- if (input_event.kind == .key_up) {
2667
- self.views[index].canvas_widget_tab_input_focus_entry_held = false;
2668
- }
2669
- return true;
3102
+ const view = &self.views[index];
3103
+ if (view.kind != .gpu_surface) return false;
3104
+ const decision = keyboard_focus.decide(view.canvas_widget_surface_scope_policy, .{
3105
+ .stage = .lifetime,
3106
+ .a = keyboard_focus.phase(input_event),
3107
+ .b = keyboard_focus.key(input_event.key),
3108
+ .facts = @intFromBool(view.canvas_widget_tab_input_focus_entry_held),
3109
+ });
3110
+ if (decision == 2) view.canvas_widget_tab_input_focus_entry_held = false;
3111
+ return decision != 0;
2670
3112
  }
2671
3113
 
2672
3114
  /// Consume the physical V release paired with a terminal Paste
@@ -2678,6 +3120,14 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2678
3120
  /// the clipboard pass later in this input cycle re-arms it when
2679
3121
  /// that fresh down is another terminal Paste.
2680
3122
  pub fn consumeCanvasWidgetTerminalPasteKeyLifetime(self: *Runtime, input_event: GpuSurfaceInputEvent) bool {
3123
+ if (runtimeFindViewIndex(self, input_event.window_id, input_event.label)) |i| {
3124
+ var facts = input_composition.observations(self, &self.views[i]);
3125
+ facts.latch = self.views[i].canvas_widget_terminal_paste_v_held;
3126
+ if (input_composition.plan(self.views[i].canvas_widget_surface_scope_policy, .paste, input_event, facts)) |program| {
3127
+ if (program.has(2048)) self.views[i].canvas_widget_terminal_paste_v_held = false;
3128
+ return program.has(8192);
3129
+ }
3130
+ }
2681
3131
  if (input_event.kind != .key_down and input_event.kind != .key_up) return false;
2682
3132
  if (!std.ascii.eqlIgnoreCase(input_event.key, "v")) return false;
2683
3133
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
@@ -2692,186 +3142,127 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2692
3142
  /// (`focus_moved`) so tree rows can tell selection-follows-focus
2693
3143
  /// arrivals from in-place collapse/expand intents.
2694
3144
  pub fn updateCanvasWidgetFocusFromKeyboardInput(self: *Runtime, input_event: GpuSurfaceInputEvent) anyerror!bool {
2695
- if (input_event.kind != .key_down) return false;
2696
3145
  const index = runtimeFindViewIndex(self, input_event.window_id, input_event.label) orelse return false;
2697
- if (self.views[index].kind != .gpu_surface) return false;
2698
-
2699
- const current_id: ?canvas.ObjectId = if (self.views[index].canvas_widget_focused_id == 0) null else self.views[index].canvas_widget_focused_id;
2700
- const layout = self.views[index].widgetLayoutTree();
2701
- if (std.ascii.eqlIgnoreCase(input_event.key, "tab")) {
2702
- // Live terminals own Tab/Shift+Tab as input; editable code
2703
- // owns plain Tab as indentation while Shift+Tab remains an
2704
- // accessible way to leave the editor.
2705
- if (current_id) |id| {
2706
- if (layout.focusTargetById(id)) |current| {
2707
- if (canvasWidgetTerminalOwnsTabInput(layout, current)) return false;
2708
- if (!input_event.modifiers.shift and
2709
- !input_event.modifiers.primary and
2710
- !input_event.modifiers.command and
2711
- !input_event.modifiers.control and
2712
- !input_event.modifiers.option and
2713
- canvasWidgetCodeEditorOwnsTabInput(layout, current))
2714
- {
2715
- return false;
3146
+ const view = &self.views[index];
3147
+ if (view.kind != .gpu_surface) return false;
3148
+ const policy = view.canvas_widget_surface_scope_policy;
3149
+ const layout = view.widgetLayoutTree();
3150
+ const current_id: ?canvas.ObjectId = if (view.canvas_widget_focused_id == 0) null else view.canvas_widget_focused_id;
3151
+ const focused = if (current_id) |id| layout.focusTargetById(id) else null;
3152
+ const owner_facts: u16 = if (focused) |target| @as(u16, if (canvasWidgetTerminalOwnsTabInput(layout, target)) 1 else 0) |
3153
+ @as(u16, if (canvasWidgetCodeEditorOwnsTabInput(layout, target)) 2 else 0) else 0;
3154
+ const intent: keyboard_focus.Intent = @enumFromInt(keyboard_focus.decide(policy, .{
3155
+ .stage = .intent,
3156
+ .a = keyboard_focus.phase(input_event),
3157
+ .b = keyboard_focus.key(input_event.key),
3158
+ .c = keyboard_focus.modifiers(input_event),
3159
+ .facts = owner_facts,
3160
+ }));
3161
+ if (intent == .none) return false;
3162
+ const direction = keyboard_focus.direction(intent);
3163
+ const edge: canvas_widget_runtime.CanvasWidgetGroupFocusEdge = if (intent == .end) .last else .first;
3164
+ const focus_visible = keyboard_focus.decide(policy, .{ .stage = .visibility, .a = @intFromEnum(intent), .facts = @intFromBool(current_id != null and view.canvas_widget_focus_visible_id == current_id.?) }) != 0;
3165
+ const F = keyboard_focus.Facts;
3166
+ const base: u16 = @as(u16, if (focused != null) F.focused else 0) |
3167
+ @as(u16, if (intent != .tab and intent != .back_tab and current_id != null and canvasWidgetQuietListRowFocus(self, index, current_id.?)) F.quiet else 0) |
3168
+ @as(u16, if (focused != null and canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(layout, focused.?.index) != null) F.radio_scope else 0);
3169
+ var facts = base;
3170
+ var action: keyboard_focus.Action = .stop;
3171
+ var target: ?canvas.WidgetFocusTarget = null;
3172
+ var target_id: canvas.ObjectId = 0;
3173
+ var initial_id: canvas.ObjectId = 0;
3174
+ var attempts: usize = 0;
3175
+ var moved = false;
3176
+ while (true) {
3177
+ action = @enumFromInt(keyboard_focus.decide(policy, .{ .stage = .coordinate, .a = @intFromEnum(intent), .b = @intFromEnum(action), .kind = if (focused) |value| value.kind else null, .facts = facts }));
3178
+ facts = base;
3179
+ switch (action) {
3180
+ .stop => return false,
3181
+ .moved => return true,
3182
+ .capture_tab => {
3183
+ view.canvas_widget_tab_input_focus_entry_held = true;
3184
+ return true;
3185
+ },
3186
+ .tab_target, .tab_visible, .tab_fallback => {
3187
+ const previous_target = target_id;
3188
+ const next = switch (action) {
3189
+ .tab_target => view.canvasWidgetRovingTabTarget(current_id, direction),
3190
+ .tab_visible => blk: {
3191
+ const node_index = view.canvasWidgetNodeIndexById(target_id) orelse break :blk null;
3192
+ const scope = canvas_widget_runtime.canvasWidgetRovingTabScope(layout, node_index) orelse break :blk null;
3193
+ break :blk canvas_widget_runtime.canvasWidgetRovingTabVisibleEntryTarget(layout, scope);
3194
+ },
3195
+ .tab_fallback => view.canvasWidgetRovingTabTarget(target_id, direction),
3196
+ else => unreachable,
3197
+ };
3198
+ if (next) |value| {
3199
+ target = value;
3200
+ target_id = value.id;
2716
3201
  }
2717
- }
2718
- }
2719
- const direction: canvas.WidgetFocusDirection = if (input_event.modifiers.shift) .backward else .forward;
2720
- var target = self.views[index].canvasWidgetRovingTabTarget(current_id, direction) orelse return false;
2721
- var moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, true);
2722
- if (!moved and target.id != (current_id orelse 0)) {
2723
- // A selected radio may be a valid LOGICAL group entry
2724
- // while fully hidden by a fixed clip. The focus setter
2725
- // first gave every runtime scroll ancestor a chance to
2726
- // reveal it; if it is still unreachable, keep the group
2727
- // in the Tab order through a visible radio. When the
2728
- // entire group is clipped, continue the one-stop walk
2729
- // from the failed entry to the next visible control.
2730
- if (self.views[index].canvasWidgetNodeIndexById(target.id)) |target_index| {
2731
- if (canvas_widget_runtime.canvasWidgetRovingTabScope(layout, target_index)) |scope| {
2732
- if (canvas_widget_runtime.canvasWidgetRovingTabVisibleEntryTarget(layout, scope)) |visible| {
2733
- if (visible.id != target.id) {
2734
- target = visible;
2735
- moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, true);
2736
- }
2737
- }
3202
+ facts |= keyboardFocusCandidateFacts(target_id, current_id, previous_target, initial_id, next != null, true);
3203
+ },
3204
+ .tab_commit, .tab_visible_commit, .tab_fallback_commit, .commit, .radio_commit => {
3205
+ if (action == .radio_commit) attempts += 1;
3206
+ moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target_id, focus_visible);
3207
+ facts |= keyboardFocusCandidateFacts(target_id, current_id, 0, initial_id, true, attempts < view.widget_layout_node_count);
3208
+ if (moved) facts |= F.moved;
3209
+ },
3210
+ .tab_finish => {
3211
+ if (moved) facts |= F.moved;
3212
+ if (target) |value| if (canvasWidgetTerminalOwnsTabInput(layout, value) or canvasWidgetCodeEditorOwnsTabInput(layout, value)) {
3213
+ facts |= F.owner;
3214
+ };
3215
+ },
3216
+ .menu => {
3217
+ const current = focused orelse return false;
3218
+ const surface = view.canvasWidgetOwnedMenuSurfaceIndex(current.index);
3219
+ const entry = if (surface) |surface_index| view.canvasWidgetMenuSurfaceEntryId(surface_index, direction == .up) else null;
3220
+ if (entry) |id| target_id = id;
3221
+ facts |= keyboardFocusCandidateFacts(target_id, current_id, 0, 0, entry != null, true);
3222
+ },
3223
+ .tree_edge, .group_edge, .tree, .group, .spatial => {
3224
+ const current = focused orelse return false;
3225
+ const next = switch (action) {
3226
+ .tree_edge => canvas_widget_runtime.canvasWidgetTreeFocusEdgeTarget(layout, current, edge),
3227
+ .group_edge => canvas_widget_runtime.canvasWidgetGroupFocusEdgeTargetWithPolicy(layout, current, edge, policy),
3228
+ .tree => canvas_widget_runtime.canvasWidgetTreeDirectionalFocusTarget(layout, current, direction),
3229
+ .group => canvas_widget_runtime.canvasWidgetGroupDirectionalFocusTargetWithPolicy(layout, current, direction, policy),
3230
+ .spatial => layout.focusTarget(current_id, direction),
3231
+ else => unreachable,
3232
+ };
3233
+ if (next) |value| {
3234
+ target = value;
3235
+ target_id = value.id;
3236
+ initial_id = value.id;
3237
+ if (action == .spatial and canvas_widget_runtime.canvasWidgetSpatialFocusAllowedWithPolicy(layout, current, value, direction, policy)) facts |= F.allowed;
2738
3238
  }
2739
- }
2740
- if (!moved) {
2741
- const fallback = self.views[index].canvasWidgetRovingTabTarget(target.id, direction) orelse return false;
2742
- if (fallback.id == target.id) return false;
2743
- target = fallback;
2744
- moved = try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, true);
2745
- }
2746
- }
2747
- if (moved and
2748
- (canvasWidgetTerminalOwnsTabInput(layout, target) or
2749
- canvasWidgetCodeEditorOwnsTabInput(layout, target)))
2750
- {
2751
- // The key-down entered this input owner through focus
2752
- // traversal. Hold that classification through repeats
2753
- // and key-up so the gesture never becomes editor input.
2754
- self.views[index].canvas_widget_tab_input_focus_entry_held = true;
2755
- }
2756
- return moved;
2757
- }
2758
-
2759
- const focused_id = current_id orelse return false;
2760
- const focused = layout.focusTargetById(focused_id) orelse return false;
2761
- // Roving within a composite preserves how focus ENTERED it:
2762
- // pointer/programmatic entry stays quiet, while a ring earned
2763
- // through Tab follows the active descendant. Arrow/Home/End
2764
- // are not themselves a fresh focus-visible entry.
2765
- const preserve_focus_visible = self.views[index].canvas_widget_focus_visible_id == focused_id;
2766
- // FRAMEWORK BEHAVIOR CHANGE (deliberate, scoped — the same
2767
- // seam as the keyboard-routing gate below): arrows and
2768
- // Home/End never escalate QUIET focus on a plain list row
2769
- // into the visible ring register. Only Tab (handled above)
2770
- // enters the keyboard-contract; from quiet row focus the
2771
- // navigation keys fall through to the app, whose selection
2772
- // model owns them. Tree rows are exempt from that fallthrough
2773
- // because the runtime owns their ARIA keymap; the roving move
2774
- // below still preserves quiet versus focus-visible entry.
2775
- if (canvasWidgetQuietListRowFocus(self, index, focused_id)) return false;
2776
- if (canvasWidgetGroupFocusEdgeFromInput(input_event)) |edge| {
2777
- // A tree row's Home/End jump to the SCOPE's edges (rows
2778
- // nest, so the group edge walk's same-parent rule would
2779
- // stop at one level).
2780
- if (canvas_widget_runtime.canvasWidgetTreeFocusEdgeTarget(layout, focused, edge)) |target| {
2781
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2782
- }
2783
- const target = canvasWidgetGroupFocusEdgeTarget(layout, focused, edge) orelse return false;
2784
- if (focused.kind == .radio and canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(layout, focused.index) != null) {
2785
- const retry_direction: canvas.WidgetFocusDirection = switch (edge) {
2786
- .first => .right,
2787
- .last => .left,
2788
- };
2789
- return try setCanvasWidgetRadioGroupFocusFromKeyboardMoved(
2790
- self,
2791
- index,
2792
- current_id,
2793
- target,
2794
- retry_direction,
2795
- preserve_focus_visible,
2796
- );
2797
- }
2798
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2799
- }
2800
- const direction = canvasWidgetSpatialFocusDirection(input_event) orelse return false;
2801
- // The open-menu keymap: ArrowDown/Up on a menu-owning trigger
2802
- // whose anchored surface is MOUNTED moves the keyboard into
2803
- // the menu (the marked row when one is selected, else the
2804
- // first/last row). Select/combobox and ordinary menu buttons
2805
- // share this ownership contract; the surface relationship,
2806
- // not an example-specific key handler, identifies the popup.
2807
- // Without a mounted menu, select/combobox arrows fall through
2808
- // to the control resolver for the model-owned open.
2809
- if (canvasWidgetAnchoredMenuTriggerKind(focused.kind) and (direction == .down or direction == .up)) {
2810
- if (self.views[index].canvasWidgetOwnedMenuSurfaceIndex(focused.index)) |surface_index| {
2811
- if (self.views[index].canvasWidgetMenuSurfaceEntryId(surface_index, direction == .up)) |entry_id| {
2812
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, entry_id, preserve_focus_visible);
2813
- }
2814
- }
2815
- }
2816
- // The ARIA tree keymap first: Up/Down walk the scope's
2817
- // visible rows, Left/Right move to parent / first child when
2818
- // they are moves (collapse/expand stay routed intents).
2819
- if (canvas_widget_runtime.canvasWidgetTreeDirectionalFocusTarget(layout, focused, direction)) |target| {
2820
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2821
- }
2822
- if (canvasWidgetGroupDirectionalFocusTarget(layout, focused, direction)) |target| {
2823
- if (focused.kind == .radio and canvas_widget_runtime.canvasWidgetRadioGroupScopeIndex(layout, focused.index) != null) {
2824
- return try setCanvasWidgetRadioGroupFocusFromKeyboardMoved(
2825
- self,
2826
- index,
2827
- current_id,
2828
- target,
2829
- direction,
2830
- preserve_focus_visible,
2831
- );
3239
+ facts |= keyboardFocusCandidateFacts(target_id, current_id, 0, initial_id, next != null, attempts < view.widget_layout_node_count);
3240
+ },
3241
+ .radio_next => {
3242
+ const previous_target = target_id;
3243
+ const next = canvas_widget_runtime.canvasWidgetRadioGroupDirectionalFocusTarget(view.widgetLayoutTree(), target orelse return false, direction);
3244
+ if (next) |value| {
3245
+ target = value;
3246
+ target_id = value.id;
3247
+ }
3248
+ facts |= keyboardFocusCandidateFacts(target_id, current_id, previous_target, initial_id, next != null, attempts < view.widget_layout_node_count);
3249
+ },
2832
3250
  }
2833
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2834
3251
  }
2835
- const target = layout.focusTarget(focused_id, direction) orelse return false;
2836
- if (!canvasWidgetSpatialFocusAllowed(layout, focused, target, direction)) return false;
2837
- return try setCanvasWidgetFocusFromKeyboardMoved(self, index, current_id, target.id, preserve_focus_visible);
2838
3252
  }
2839
3253
 
2840
- fn setCanvasWidgetFocusFromKeyboardMoved(self: *Runtime, view_index: usize, previous_id: ?canvas.ObjectId, target_id: canvas.ObjectId, focus_visible: bool) anyerror!bool {
2841
- try setCanvasWidgetFocusFromKeyboardWithVisibility(self, view_index, target_id, focus_visible);
2842
- const previous = previous_id orelse 0;
2843
- return target_id != 0 and target_id != previous and self.views[view_index].canvas_widget_focused_id == target_id;
3254
+ fn keyboardFocusCandidateFacts(target_id: canvas.ObjectId, current_id: ?canvas.ObjectId, previous_target: canvas.ObjectId, initial_id: canvas.ObjectId, present: bool, budget: bool) u16 {
3255
+ const F = keyboard_focus.Facts;
3256
+ return @as(u16, if (present) F.present else 0) | @as(u16, if (target_id != (current_id orelse 0)) F.different else 0) |
3257
+ @as(u16, if (target_id == previous_target) F.same else 0) | @as(u16, if (target_id == initial_id) F.initial else 0) |
3258
+ @as(u16, if (target_id != 0) F.nonzero else 0) | @as(u16, if (budget) F.budget else 0);
2844
3259
  }
2845
3260
 
2846
- /// Logical radio traversal admits scroll-clipped targets so the
2847
- /// focus setter can reveal them. A fixed clip cannot be scrolled;
2848
- /// after such a candidate stays unreachable, continue around the
2849
- /// same nearest group until a visible radio accepts focus or the
2850
- /// bounded walk returns to its starting point.
2851
- fn setCanvasWidgetRadioGroupFocusFromKeyboardMoved(
2852
- self: *Runtime,
2853
- view_index: usize,
2854
- previous_id: ?canvas.ObjectId,
2855
- initial_target: canvas.WidgetFocusTarget,
2856
- direction: canvas.WidgetFocusDirection,
2857
- focus_visible: bool,
2858
- ) anyerror!bool {
2859
- const previous = previous_id orelse 0;
2860
- var target = initial_target;
2861
- var attempts: usize = 0;
2862
- while (attempts < self.views[view_index].widget_layout_node_count) : (attempts += 1) {
2863
- if (target.id == 0 or target.id == previous) return false;
2864
- if (try setCanvasWidgetFocusFromKeyboardMoved(self, view_index, previous_id, target.id, focus_visible)) return true;
2865
-
2866
- const next = canvas_widget_runtime.canvasWidgetRadioGroupDirectionalFocusTarget(
2867
- self.views[view_index].widgetLayoutTree(),
2868
- target,
2869
- direction,
2870
- ) orelse return false;
2871
- if (next.id == target.id or next.id == initial_target.id) return false;
2872
- target = next;
2873
- }
2874
- return false;
3261
+ fn setCanvasWidgetFocusFromKeyboardMoved(self: *Runtime, view_index: usize, previous_id: ?canvas.ObjectId, target_id: canvas.ObjectId, focus_visible: bool) anyerror!bool {
3262
+ try setCanvasWidgetFocusFromKeyboardWithVisibility(self, view_index, target_id, focus_visible);
3263
+ const facts: u16 = @as(u16, if (target_id != 0) 1 else 0) | @as(u16, if (target_id != (previous_id orelse 0)) 2 else 0) |
3264
+ @as(u16, if (self.views[view_index].canvas_widget_focused_id == target_id) 4 else 0);
3265
+ return keyboard_focus.decide(self.views[view_index].canvas_widget_surface_scope_policy, .{ .stage = .moved, .facts = facts }) != 0;
2875
3266
  }
2876
3267
 
2877
3268
  pub fn setCanvasWidgetFocusFromKeyboard(self: *Runtime, view_index: usize, target_id: canvas.ObjectId) anyerror!void {
@@ -2931,8 +3322,13 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2931
3322
  }
2932
3323
 
2933
3324
  fn setCanvasWidgetFocusFromKeyboardWithVisibility(self: *Runtime, view_index: usize, target_id: canvas.ObjectId, focus_visible: bool) anyerror!void {
2934
- const next_focus_visible_id: canvas.ObjectId = if (focus_visible) target_id else 0;
2935
- if (self.views[view_index].canvas_widget_focused_id == target_id and self.views[view_index].canvas_widget_focus_visible_id == next_focus_visible_id) return;
3325
+ const view = &self.views[view_index];
3326
+ const desired_ring: canvas.ObjectId = if (focus_visible) target_id else 0;
3327
+ const facts: u16 = @as(u16, if (view.canvas_widget_focused_id == target_id) 1 else 0) |
3328
+ @as(u16, if (view.canvas_widget_focus_visible_id == desired_ring) 2 else 0) | @as(u16, if (target_id != 0) 4 else 0);
3329
+ const decision = keyboard_focus.decide(view.canvas_widget_surface_scope_policy, .{ .stage = .commit, .a = @intFromBool(focus_visible), .facts = facts });
3330
+ if (decision & 1 == 0) return;
3331
+ const next_focus_visible_id: canvas.ObjectId = if (decision & 2 != 0) target_id else 0;
2936
3332
 
2937
3333
  const reveal = try revealCanvasWidgetFocusTarget(self, view_index, target_id) orelse return;
2938
3334
  const previous_state = self.views[view_index].canvasWidgetRenderState();
@@ -2945,7 +3341,7 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2945
3341
  // that intent where it dismisses — the register clears
2946
3342
  // there and only a fresh arrival through this write
2947
3343
  // re-grants it.
2948
- self.views[view_index].canvas_widget_focus_visible_keyboard = next_focus_visible_id != 0;
3344
+ self.views[view_index].canvas_widget_focus_visible_keyboard = decision & 4 != 0;
2949
3345
  // Keyboard focus-visible is the tooltip's second reveal
2950
3346
  // path: landing on a tooltip-owning trigger shows it
2951
3347
  // immediately, moving on hides the previous one (the
@@ -2956,14 +3352,15 @@ pub fn RuntimeCanvasWidgetEvents(comptime Runtime: type) type {
2956
3352
  // tabbed-into field would render its ring but no insertion
2957
3353
  // point. Collapse at the end of the text, the plain caret
2958
3354
  // placement; a selection the widget already carries survives.
2959
- if (target_id != 0 and self.views[view_index].canEditCanvasWidgetText(target_id)) {
2960
- if (self.views[view_index].canvasWidgetNodeIndexById(target_id)) |node_index| {
2961
- const widget = &self.views[view_index].widget_layout_nodes[node_index].widget;
2962
- if (widget.text_selection == null) {
2963
- widget.text_selection = canvas.TextSelection.collapsed(widget.text.len);
2964
- try self.views[view_index].refreshCanvasWidgetSemantics();
2965
- self.views[view_index].widget_revision += 1;
2966
- }
3355
+ const node_index = view.canvasWidgetNodeIndexById(target_id);
3356
+ const caret_facts: u16 = @as(u16, if (target_id != 0) 1 else 0) | @as(u16, if (view.canEditCanvasWidgetText(target_id)) 2 else 0) |
3357
+ @as(u16, if (node_index != null and view.widget_layout_nodes[node_index.?].widget.text_selection == null) 4 else 0);
3358
+ if (keyboard_focus.decide(view.canvas_widget_surface_scope_policy, .{ .stage = .caret, .facts = caret_facts }) != 0) {
3359
+ if (node_index) |editable_index| {
3360
+ const widget = &view.widget_layout_nodes[editable_index].widget;
3361
+ widget.text_selection = canvas.TextSelection.collapsed(widget.text.len);
3362
+ try self.views[view_index].refreshCanvasWidgetSemantics();
3363
+ self.views[view_index].widget_revision += 1;
2967
3364
  }
2968
3365
  }
2969
3366
  try invalidateForCanvasWidgetRenderStateChange(self, view_index, previous_state, self.views[view_index].canvasWidgetRenderState());
@@ -3028,13 +3425,6 @@ fn canvasWidgetCodeEditorOwnsTabInput(layout: canvas.WidgetLayoutTree, target: c
3028
3425
  return widget.runtime_flags.code_editor and !widget.state.disabled;
3029
3426
  }
3030
3427
 
3031
- fn canvasWidgetAnchoredMenuTriggerKind(kind: canvas.WidgetKind) bool {
3032
- return switch (kind) {
3033
- .button, .icon_button, .select, .combobox => true,
3034
- else => false,
3035
- };
3036
- }
3037
-
3038
3428
  fn canvasDirtyRegionForView(view_frame: geometry.RectF, local_dirty: geometry.RectF) ?geometry.RectF {
3039
3429
  const normalized_view = view_frame.normalized();
3040
3430
  const surface_bounds = geometry.RectF.init(0, 0, normalized_view.width, normalized_view.height);