@native-sdk/cli 0.11.0 → 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.
- package/build/app.zig +73 -37
- package/build.zig +239 -5
- package/native-sdk.d.ts +5 -1
- package/package.json +13 -12
- package/packages/core/compile-surface/core.ts +30 -0
- package/packages/core/package-lock.json +6 -6
- package/packages/core/package.json +3 -3
- package/packages/core/scripts/scriptc-toolchain.json +44 -44
- package/packages/core/scripts/stage_external_core.mjs +27 -16
- package/packages/core/sdk/core.d.ts +24 -1
- package/packages/core/sdk/core.ts +51 -1
- package/packages/core/sdk/events.d.ts +5 -0
- package/packages/core/sdk/events.ts +10 -0
- package/packages/core/src/bridge_descriptors.ts +3 -3
- package/packages/core/src/checker.ts +20 -0
- package/packages/core/src/cli.ts +2 -11
- package/packages/core/src/context_menus.ts +76 -0
- package/packages/core/src/diagnostics.ts +7 -0
- package/packages/core/src/extent_program.ts +53 -0
- package/packages/core/src/frontend.ts +12 -10
- package/packages/core/src/markup_canonical.ts +140 -0
- package/packages/core/src/markup_construction.ts +189 -0
- package/packages/core/src/markup_display.ts +43 -0
- package/packages/core/src/markup_document.ts +226 -0
- package/packages/core/src/markup_elements.ts +225 -0
- package/packages/core/src/markup_expressions.ts +79 -0
- package/packages/core/src/markup_imports.ts +146 -0
- package/packages/core/src/markup_parser.ts +228 -0
- package/packages/core/src/markup_runtime.ts +93 -0
- package/packages/core/src/markup_scalars.ts +143 -0
- package/packages/core/src/markup_shapes.ts +243 -0
- package/packages/core/src/markup_specialized.ts +242 -0
- package/packages/core/src/markup_text.ts +86 -0
- package/packages/core/src/markup_values.ts +336 -0
- package/packages/core/src/portable_sources.json +24 -0
- package/packages/core/src/registered_font.ts +2 -3
- package/packages/core/src/runtime_policy.ts +24 -0
- package/packages/core/src/scalar_text.ts +1 -3
- package/packages/core/src/scroll_mutation.ts +86 -0
- package/packages/core/src/scroll_tree.ts +86 -0
- package/packages/core/src/service_contract.ts +53 -2
- package/packages/core/src/sqlite_cli.ts +3 -46
- package/packages/core/src/sqlite_codegen.ts +84 -0
- package/packages/core/src/staged_rebuild.ts +60 -0
- package/packages/core/src/view_bridge.ts +161 -0
- package/packages/core/src/view_check.ts +145 -0
- package/packages/core/src/view_evaluator.ts +823 -0
- package/packages/core/src/view_frontend.ts +340 -218
- package/packages/core/src/view_program.ts +221 -0
- package/packages/core/src/view_reload.ts +166 -0
- package/packages/core/src/view_reload_watch.ts +98 -0
- package/packages/core/src/view_sources.ts +34 -0
- package/packages/core/src/virtual_windows.ts +88 -0
- package/packages/core/src/web_panes.ts +67 -0
- package/packages/core/src/widget_continuity.ts +37 -0
- package/packages/core/src/widget_reconcile.ts +63 -0
- package/packages/core/src/widget_retention.ts +62 -0
- package/skill-data/native-ui/SKILL.md +2 -2
- package/skill-data/ts-core/SKILL.md +5 -3
- package/skill-data/ts-services/references/service-surface.md +29 -5
- package/src/app_runner/root.zig +14 -0
- package/src/app_runner/ts_compiled_view.zig +88 -17
- package/src/app_runner/ts_core_main.zig +43 -5
- package/src/app_runner/ts_core_mobile.zig +1 -1
- package/src/automation/server.zig +56 -3
- package/src/embed/host.zig +2 -0
- package/src/embed/tests.zig +2 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/keyboard_input.zig +32 -0
- package/src/platform/linux/root.zig +2 -0
- package/src/platform/macos/appkit_host.h +7 -2
- package/src/platform/macos/appkit_host.m +31 -9
- package/src/platform/macos/cef_host.mm +15 -1
- package/src/platform/macos/global_shortcuts.zig +138 -0
- package/src/platform/macos/key_codes.zig +102 -0
- package/src/platform/macos/keyboard_input.zig +81 -0
- package/src/platform/macos/root.zig +25 -3
- package/src/platform/macos/webview_inspection_test.m +106 -0
- package/src/platform/null_platform.zig +104 -0
- package/src/platform/root.zig +14 -0
- package/src/platform/types.zig +102 -0
- package/src/platform/windows/global_shortcuts.zig +157 -0
- package/src/platform/windows/key_codes.zig +63 -0
- package/src/platform/windows/keyboard_input.zig +136 -0
- package/src/platform/windows/root.zig +15 -0
- package/src/primitives/canvas/decision_reuse.zig +133 -0
- package/src/primitives/canvas/font_ttf.zig +27 -3
- package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
- package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
- package/src/primitives/canvas/fonts/OFL.txt +93 -0
- package/src/primitives/canvas/fonts/README.md +15 -0
- package/src/primitives/canvas/intrinsic_measure_policy.zig +4 -1
- package/src/primitives/canvas/markdown_tests.zig +3 -3
- package/src/primitives/canvas/reference.zig +3 -5
- package/src/primitives/canvas/reference_tests.zig +58 -0
- package/src/primitives/canvas/registered_font_policy.zig +1 -1
- package/src/primitives/canvas/root.zig +7 -4
- package/src/primitives/canvas/text_metrics.zig +32 -39
- package/src/primitives/canvas/text_metrics_tests.zig +52 -7
- package/src/primitives/canvas/text_query_policy.zig +142 -3
- package/src/primitives/canvas/text_scalar_policy.zig +80 -2
- package/src/primitives/canvas/tokens.zig +9 -0
- package/src/primitives/canvas/ui.zig +1 -0
- package/src/primitives/canvas/ui_markup.zig +69 -14
- package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +1407 -23
- package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
- package/src/primitives/canvas/ui_markup_construction.zig +146 -0
- package/src/primitives/canvas/ui_markup_display.zig +82 -0
- package/src/primitives/canvas/ui_markup_document.zig +196 -0
- package/src/primitives/canvas/ui_markup_elements.zig +163 -0
- package/src/primitives/canvas/ui_markup_expr.zig +192 -2
- package/src/primitives/canvas/ui_markup_imports.zig +262 -0
- package/src/primitives/canvas/ui_markup_parser.zig +117 -0
- package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
- package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
- package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
- package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
- package/src/primitives/canvas/ui_markup_text.zig +128 -0
- package/src/primitives/canvas/ui_markup_values.zig +368 -0
- package/src/primitives/canvas/ui_markup_view.zig +2817 -74
- package/src/primitives/canvas/virtual_extent_policy.zig +58 -0
- package/src/primitives/canvas/virtual_extents.zig +47 -33
- package/src/primitives/canvas/widget_metric_policy.zig +4 -1
- package/src/primitives/canvas/widget_runtime.zig +2 -1
- package/src/root.zig +5 -0
- package/src/runtime/api.zig +1 -0
- package/src/runtime/bridge_descriptor_policy.zig +1 -1
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_widget_context_menu.zig +179 -0
- package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
- package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
- package/src/runtime/canvas_widget_runtime.zig +306 -92
- package/src/runtime/context_menu_policy.zig +112 -0
- package/src/runtime/core.zig +14 -0
- package/src/runtime/effects.zig +172 -4
- package/src/runtime/effects_host_tests.zig +25 -0
- package/src/runtime/flow.zig +1 -0
- package/src/runtime/flow_reference.zig +1 -0
- package/src/runtime/global_shortcuts.zig +75 -0
- package/src/runtime/keyboard_input.zig +86 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/scroll_mutation_policy.zig +130 -0
- package/src/runtime/scroll_mutation_runtime.zig +158 -0
- package/src/runtime/scroll_tree_policy.zig +99 -0
- package/src/runtime/session_record.zig +7 -0
- package/src/runtime/staged_rebuild_policy.zig +83 -0
- package/src/runtime/system_services.zig +19 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +126 -0
- package/src/runtime/ts_ui_app.zig +24 -0
- package/src/runtime/ui_app.zig +274 -31
- package/src/runtime/ui_app_tests.zig +48 -179
- package/src/runtime/ui_app_window_tests.zig +133 -0
- package/src/runtime/view_reload.zig +226 -0
- package/src/runtime/view_widget_scroll.zig +30 -21
- package/src/runtime/view_widget_tree.zig +43 -13
- package/src/runtime/virtual_window_policy.zig +128 -0
- package/src/runtime/web_pane_policy.zig +111 -0
- package/src/runtime/web_pane_test_cases.zig +204 -0
- package/src/runtime/widget_continuity_policy.zig +73 -0
- package/src/runtime/widget_reconcile_policy.zig +81 -0
- package/src/runtime/widget_retention_policy.zig +75 -0
- package/src/runtime/window_views.zig +19 -4
- package/src/security/root.zig +1 -0
- package/src/tooling/templates.zig +8 -0
- package/src/tooling/ts_core.zig +84 -1
- package/src/tooling/verbs.zig +79 -15
- package/tools/corewire/core.test.ts +25 -3
- package/tools/corewire/core_abi.zig +4 -0
- package/tools/corewire/core_contract.ts +1 -1
- package/tools/corewire/core_goldens.json +75 -75
- package/tools/corewire/core_projection.ts +3 -2
- package/tools/corewire/emit_mirror.ts +19 -9
- package/tools/corewire/facade_templates.ts +1 -1
- package/tools/corewire/intake.test.ts +4 -0
- package/tools/corewire/intake_goldens.json +50 -50
- package/tools/corewire/invocation.test.ts +4 -0
- package/tools/corewire/invocation_goldens.json +3 -3
- package/tools/corewire/mirror_templates.ts +4 -0
- package/tools/corewire/profile_emission.ts +2 -0
- package/tools/corewire/sidecar.zig +2 -0
|
@@ -3,6 +3,7 @@ const geometry = @import("geometry");
|
|
|
3
3
|
const canvas = @import("canvas");
|
|
4
4
|
const canvas_frame_helpers = @import("canvas_frame.zig");
|
|
5
5
|
const canvas_widget_runtime = @import("canvas_widget_runtime.zig");
|
|
6
|
+
const scroll_mutation = @import("scroll_mutation_runtime.zig");
|
|
6
7
|
|
|
7
8
|
const unionRects = canvas_frame_helpers.unionRects;
|
|
8
9
|
const CanvasWidgetScrollKeyboardTarget = canvas_widget_runtime.CanvasWidgetScrollKeyboardTarget;
|
|
@@ -211,6 +212,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
211
212
|
}
|
|
212
213
|
|
|
213
214
|
pub fn applyCanvasWidgetScrollAxis(self: *RuntimeView, scroll_index: usize, comptime axis: canvas.ScrollAxis, delta: f32, source: CanvasWidgetScrollSource, allow_rubberband: bool) anyerror!?geometry.RectF {
|
|
215
|
+
if (self.widget_tokens.scroll_mutation_policy) |policy| return (try scroll_mutation.run(self, policy, .axis, scroll_index, axis, @intFromEnum(source), delta, 0, 0, allow_rubberband)).dirty;
|
|
214
216
|
if (scroll_index >= self.widget_layout_node_count) return null;
|
|
215
217
|
const scroll_node = self.widget_layout_nodes[scroll_index];
|
|
216
218
|
if (!canvasWidgetScrollableKind(scroll_node.widget.kind)) return null;
|
|
@@ -280,6 +282,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
280
282
|
}
|
|
281
283
|
|
|
282
284
|
fn applyCanvasWidgetTextareaScrollAxis(self: *RuntimeView, scroll_index: usize, comptime axis: canvas.ScrollAxis, delta: f32, source: CanvasWidgetScrollSource) anyerror!?geometry.RectF {
|
|
285
|
+
if (self.widget_tokens.scroll_mutation_policy) |policy| return (try scroll_mutation.run(self, policy, .textarea, scroll_index, axis, @intFromEnum(source), delta, 0, 0, false)).dirty;
|
|
283
286
|
if (scroll_index >= self.widget_layout_node_count) return null;
|
|
284
287
|
const widget = self.widget_layout_nodes[scroll_index].widget;
|
|
285
288
|
if (widget.kind != .textarea) return null;
|
|
@@ -323,6 +326,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
323
326
|
/// values pass through so the bounce is visible), the engine just
|
|
324
327
|
/// follows. Engine velocity is zeroed; the driver owns physics.
|
|
325
328
|
pub fn applyCanvasWidgetScrollDriverOffset(self: *RuntimeView, scroll_index: usize, offset_x: f32, offset_y: f32) anyerror!?geometry.RectF {
|
|
329
|
+
if (self.widget_tokens.scroll_mutation_policy) |policy| return (try scroll_mutation.run(self, policy, .driver, scroll_index, .vertical, 0, 0, offset_x, offset_y, false)).dirty;
|
|
326
330
|
if (scroll_index >= self.widget_layout_node_count) return null;
|
|
327
331
|
const scroll_node = self.widget_layout_nodes[scroll_index];
|
|
328
332
|
if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) return null;
|
|
@@ -358,6 +362,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
358
362
|
}
|
|
359
363
|
|
|
360
364
|
pub fn applyCanvasWidgetScrollKeyboardTarget(self: *RuntimeView, scroll_index: usize, target: CanvasWidgetScrollKeyboardTarget) anyerror!?geometry.RectF {
|
|
365
|
+
if (self.widget_tokens.scroll_mutation_policy) |policy| return (try scroll_mutation.run(self, policy, .keyboard, scroll_index, .vertical, if (target == .start) 0 else 1, 0, 0, 0, false)).dirty;
|
|
361
366
|
if (scroll_index >= self.widget_layout_node_count) return null;
|
|
362
367
|
const scroll_node = self.widget_layout_nodes[scroll_index];
|
|
363
368
|
if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) return null;
|
|
@@ -534,6 +539,19 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
534
539
|
}
|
|
535
540
|
|
|
536
541
|
pub fn stepCanvasWidgetKineticScroll(self: *RuntimeView, dt_ms: f32) anyerror!?geometry.RectF {
|
|
542
|
+
if (self.widget_tokens.scroll_mutation_policy) |policy| {
|
|
543
|
+
var dirty: ?geometry.RectF = null;
|
|
544
|
+
var changed = false;
|
|
545
|
+
const selection = @import("scroll_mutation_policy.zig").kineticSelection(policy, self.widget_layout_nodes[0..self.widget_layout_node_count]);
|
|
546
|
+
for (0..self.widget_layout_node_count) |index| {
|
|
547
|
+
if (!selection.include[index]) continue;
|
|
548
|
+
const result = try scroll_mutation.run(self, policy, .kinetic, index, .vertical, 0, dt_ms, 0, 0, false);
|
|
549
|
+
dirty = unionOptionalRects(dirty, result.dirty);
|
|
550
|
+
changed = changed or result.changed;
|
|
551
|
+
}
|
|
552
|
+
try scroll_mutation.finish(self, policy, changed);
|
|
553
|
+
return dirty;
|
|
554
|
+
}
|
|
537
555
|
var dirty: ?geometry.RectF = null;
|
|
538
556
|
var changed = false;
|
|
539
557
|
|
|
@@ -608,11 +626,12 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
608
626
|
if (scroll_index < self.widget_layout_node_count and self.widget_layout_nodes[scroll_index].widget.layout.virtualized) {
|
|
609
627
|
return @max(viewport.height, canvas.virtualWidgetScrollContentExtentWithTokens(self.widget_layout_nodes[scroll_index].widget, viewport.height, self.widget_tokens));
|
|
610
628
|
}
|
|
611
|
-
return canvas_widget_runtime.
|
|
629
|
+
return canvas_widget_runtime.canvasWidgetLayoutScrollExtentsWithPolicy(
|
|
630
|
+
self.widget_tokens.scroll_tree_policy,
|
|
612
631
|
self.widget_layout_nodes[0..self.widget_layout_node_count],
|
|
613
632
|
scroll_index,
|
|
614
633
|
viewport,
|
|
615
|
-
);
|
|
634
|
+
).dy;
|
|
616
635
|
}
|
|
617
636
|
|
|
618
637
|
/// The horizontal content extent: how far the region's mounted
|
|
@@ -633,11 +652,12 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
633
652
|
}
|
|
634
653
|
if (widget.layout.virtualized) return viewport.width;
|
|
635
654
|
}
|
|
636
|
-
return canvas_widget_runtime.
|
|
655
|
+
return canvas_widget_runtime.canvasWidgetLayoutScrollExtentsWithPolicy(
|
|
656
|
+
self.widget_tokens.scroll_tree_policy,
|
|
637
657
|
self.widget_layout_nodes[0..self.widget_layout_node_count],
|
|
638
658
|
scroll_index,
|
|
639
659
|
viewport,
|
|
640
|
-
);
|
|
660
|
+
).dx;
|
|
641
661
|
}
|
|
642
662
|
|
|
643
663
|
/// Scrolled content carries its descendants — INCLUDING floating
|
|
@@ -647,23 +667,12 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
|
|
|
647
667
|
/// its anchor base is the region's own frame, which never moves
|
|
648
668
|
/// when the content under it does.
|
|
649
669
|
pub fn translateCanvasWidgetScrollDescendants(self: *RuntimeView, scroll_index: usize, offset: geometry.OffsetF) void {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
{
|
|
657
|
-
const subtree_depth = node.depth;
|
|
658
|
-
index += 1;
|
|
659
|
-
while (index < self.widget_layout_node_count and self.widget_layout_nodes[index].depth > subtree_depth) : (index += 1) {}
|
|
660
|
-
continue;
|
|
661
|
-
}
|
|
662
|
-
const translated = node.frame.translate(offset);
|
|
663
|
-
self.widget_layout_nodes[index].frame = translated;
|
|
664
|
-
self.widget_layout_nodes[index].widget.frame = translated;
|
|
665
|
-
index += 1;
|
|
666
|
-
}
|
|
670
|
+
canvas_widget_runtime.translateCanvasWidgetLayoutScrollDescendantsWithPolicy(
|
|
671
|
+
self.widget_tokens.scroll_tree_policy,
|
|
672
|
+
self.widget_layout_nodes[0..self.widget_layout_node_count],
|
|
673
|
+
scroll_index,
|
|
674
|
+
offset,
|
|
675
|
+
);
|
|
667
676
|
}
|
|
668
677
|
|
|
669
678
|
/// Keep the editable field's caret inside its visible span after
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const retention = @import("widget_retention_policy.zig");
|
|
1
2
|
const std = @import("std");
|
|
2
3
|
const geometry = @import("geometry");
|
|
3
4
|
const canvas = @import("canvas");
|
|
@@ -23,10 +24,10 @@ const canvasWidgetInteractionTargetExists = canvas_widget_runtime.canvasWidgetIn
|
|
|
23
24
|
const canvasWidgetLayoutNodeClippedBounds = canvas_widget_runtime.canvasWidgetLayoutNodeClippedBounds;
|
|
24
25
|
const canvasWidgetDismissibleSurfaceKind = canvas_widget_runtime.canvasWidgetDismissibleSurfaceKind;
|
|
25
26
|
const canvasWidgetEditableTextKind = canvas_widget_runtime.canvasWidgetEditableTextKind;
|
|
26
|
-
const collectCanvasWidgetControlReconcileEntries = canvas_widget_runtime.
|
|
27
|
-
const collectCanvasWidgetScrollReconcileEntries = canvas_widget_runtime.
|
|
27
|
+
const collectCanvasWidgetControlReconcileEntries = canvas_widget_runtime.collectCanvasWidgetControlReconcileEntriesWithPolicy;
|
|
28
|
+
const collectCanvasWidgetScrollReconcileEntries = canvas_widget_runtime.collectCanvasWidgetScrollReconcileEntriesWithPolicy;
|
|
28
29
|
const canvasWidgetScrollStateForLayoutNode = canvas_widget_runtime.canvasWidgetScrollStateForLayoutNode;
|
|
29
|
-
const collectCanvasWidgetTextReconcileEntries = canvas_widget_runtime.
|
|
30
|
+
const collectCanvasWidgetTextReconcileEntries = canvas_widget_runtime.collectCanvasWidgetTextReconcileEntriesWithPolicy;
|
|
30
31
|
const canvasWidgetSourceTextFingerprint = canvas_widget_runtime.canvasWidgetSourceTextFingerprint;
|
|
31
32
|
const canvasWidgetLayoutNodeWithControlReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithControlReconcileState;
|
|
32
33
|
const canvasWidgetLayoutNodeWithTextReconcileState = canvas_widget_runtime.canvasWidgetLayoutNodeWithTextReconcileState;
|
|
@@ -58,6 +59,7 @@ fn subsliceOffset(outer: []const u8, inner: []const u8) ?usize {
|
|
|
58
59
|
fn validateWidgetLayoutPoolBudgets(
|
|
59
60
|
layout: canvas.WidgetLayoutTree,
|
|
60
61
|
previous_texts: *const canvas_widget_runtime.CanvasWidgetTextEntryIndex,
|
|
62
|
+
plan: ?*const canvas_widget_runtime.reconcile_policy.Plan,
|
|
61
63
|
) anyerror!void {
|
|
62
64
|
var text_len: usize = 0;
|
|
63
65
|
var span_len: usize = 0;
|
|
@@ -68,7 +70,7 @@ fn validateWidgetLayoutPoolBudgets(
|
|
|
68
70
|
for (layout.nodes, 0..) |node, node_index| {
|
|
69
71
|
// The copy loop charges the RECONCILED node (runtime editor text
|
|
70
72
|
// can outgrow the source's) — mirror the same transform.
|
|
71
|
-
const widget = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, node_index, previous_texts).widget;
|
|
73
|
+
const widget = (if (plan) |actions| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedText(node, actions.entries[node_index], previous_texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, layout, node_index, previous_texts)).widget;
|
|
72
74
|
text_len += widget.text.len + widget.icon.len + widget.command.len + widget.semantics.label.len;
|
|
73
75
|
span_len += widget.spans.len;
|
|
74
76
|
for (widget.spans) |span| {
|
|
@@ -103,6 +105,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
103
105
|
.audit_policy = self.widget_tokens.widget_audit_policy,
|
|
104
106
|
.routing_policy = self.widget_tokens.widget_routing_policy,
|
|
105
107
|
.change_policy = self.widget_tokens.widget_change_policy,
|
|
108
|
+
.retention_policy = self.widget_tokens.widget_retention_policy,
|
|
106
109
|
.text_run_policy = self.widget_tokens.text_run_policy,
|
|
107
110
|
.paint_policy = self.widget_tokens.widget_paint_policy,
|
|
108
111
|
.presentation_policy = self.widget_tokens.widget_presentation_policy,
|
|
@@ -123,7 +126,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
123
126
|
}
|
|
124
127
|
|
|
125
128
|
pub fn copyCanvasWidgetSourceScroll(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
|
|
126
|
-
const entries = canvas_widget_runtime.
|
|
129
|
+
const entries = canvas_widget_runtime.collectCanvasWidgetScrollOffsetEntriesWithPolicy(
|
|
130
|
+
layout.retention_policy orelse self.widget_tokens.widget_retention_policy,
|
|
127
131
|
layout.nodes,
|
|
128
132
|
&self.widget_source_scroll_entries,
|
|
129
133
|
);
|
|
@@ -136,6 +140,13 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
136
140
|
/// previous rebuild — newly mounted editors and freshly flipped
|
|
137
141
|
/// flags focus, level-held flags never re-steal.
|
|
138
142
|
pub fn canvasWidgetAutofocusTarget(self: *RuntimeView, layout: canvas.WidgetLayoutTree) ?canvas.ObjectId {
|
|
143
|
+
var previous: [canvas_limits.max_canvas_widget_autofocus_per_view]struct { id: canvas.ObjectId } = undefined;
|
|
144
|
+
for (self.widget_autofocus_ids[0..self.widget_autofocus_count], 0..) |id, i| previous[i] = .{ .id = id };
|
|
145
|
+
if (retention.collect(layout.retention_policy orelse self.widget_tokens.widget_retention_policy, .autofocus, layout.nodes, previous[0..self.widget_autofocus_count], self.widget_autofocus_ids.len, 0)) |plan| {
|
|
146
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| self.widget_autofocus_ids[i] = layout.nodes[entry.node].widget.id;
|
|
147
|
+
self.widget_autofocus_count = plan.count;
|
|
148
|
+
return if (plan.target) |index| layout.nodes[index].widget.id else null;
|
|
149
|
+
}
|
|
139
150
|
var target: ?canvas.ObjectId = null;
|
|
140
151
|
var new_ids: [canvas_limits.max_canvas_widget_autofocus_per_view]canvas.ObjectId = undefined;
|
|
141
152
|
var new_count: usize = 0;
|
|
@@ -166,7 +177,8 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
166
177
|
}
|
|
167
178
|
|
|
168
179
|
pub fn copyCanvasWidgetSourceControls(self: *RuntimeView, layout: canvas.WidgetLayoutTree) void {
|
|
169
|
-
const entries = canvas_widget_runtime.
|
|
180
|
+
const entries = canvas_widget_runtime.collectCanvasWidgetSourceControlEntriesWithPolicy(
|
|
181
|
+
layout.retention_policy orelse self.widget_tokens.widget_retention_policy,
|
|
170
182
|
layout.nodes,
|
|
171
183
|
&self.widget_source_control_entries,
|
|
172
184
|
);
|
|
@@ -174,6 +186,15 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
174
186
|
}
|
|
175
187
|
|
|
176
188
|
pub fn copyCanvasWidgetSourceText(self: *RuntimeView, layout: canvas.WidgetLayoutTree) anyerror!void {
|
|
189
|
+
if (retention.collect(layout.retention_policy orelse self.widget_tokens.widget_retention_policy, .source_text, layout.nodes, @as([]const CanvasWidgetSourceTextEntry, &.{}), self.widget_source_text_entries.len, 0)) |plan| {
|
|
190
|
+
for (plan.entries[0..plan.count], 0..) |entry, i| {
|
|
191
|
+
const widget = layout.nodes[entry.node].widget;
|
|
192
|
+
const fingerprint = canvasWidgetSourceTextFingerprint(widget.text);
|
|
193
|
+
self.widget_source_text_entries[i] = .{ .id = widget.id, .kind = widget.kind, .text_len = fingerprint.len, .text_hash = fingerprint.hash, .text_selection = widget.text_selection };
|
|
194
|
+
}
|
|
195
|
+
self.widget_source_text_count = plan.count;
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
177
198
|
var entries: [max_canvas_widget_source_text_entries_per_view]CanvasWidgetSourceTextEntry = undefined;
|
|
178
199
|
var entry_count: usize = 0;
|
|
179
200
|
|
|
@@ -215,6 +236,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
215
236
|
|
|
216
237
|
const source_semantics = try layout.collectSemantics(&scratch.source_semantics);
|
|
217
238
|
const previous_control_states = collectCanvasWidgetControlReconcileEntries(
|
|
239
|
+
self.widget_tokens.widget_retention_policy,
|
|
218
240
|
self.widgetLayoutTree().nodes,
|
|
219
241
|
&scratch.control_entries,
|
|
220
242
|
);
|
|
@@ -228,12 +250,14 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
228
250
|
}
|
|
229
251
|
}
|
|
230
252
|
const previous_scroll_states = collectCanvasWidgetScrollReconcileEntries(
|
|
253
|
+
self.widget_tokens.widget_retention_policy,
|
|
231
254
|
self.widgetLayoutTree().nodes,
|
|
232
255
|
self.widget_scroll_states[0..self.widget_layout_node_count],
|
|
233
256
|
&scratch.scroll_entries,
|
|
234
257
|
);
|
|
235
258
|
var previous_text_len: usize = 0;
|
|
236
259
|
const previous_text_states = try collectCanvasWidgetTextReconcileEntries(
|
|
260
|
+
self.widget_tokens.widget_retention_policy,
|
|
237
261
|
self.widgetLayoutTree().nodes,
|
|
238
262
|
self.widgetSourceTextEntries(),
|
|
239
263
|
&scratch.text_entries,
|
|
@@ -261,7 +285,9 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
261
285
|
// errors as the copy path, which stays as the structural
|
|
262
286
|
// backstop; the display-list side already follows this
|
|
263
287
|
// pattern (`copyCanvasDisplayList` counts before it copies).
|
|
264
|
-
|
|
288
|
+
const reconcile_plan = canvas_widget_runtime.canvasWidgetReconcilePlan(self.widget_tokens.widget_reconcile_policy, layout, &index_scratch.controls, &index_scratch.source_controls, &index_scratch.texts);
|
|
289
|
+
const continuity_plan = canvas_widget_runtime.continuity_policy.layout(self.widget_tokens.widget_continuity_policy, layout.nodes, previous_scroll_states, &index_scratch.semantics);
|
|
290
|
+
try validateWidgetLayoutPoolBudgets(layout, &index_scratch.texts, if (reconcile_plan) |*plan| plan else null);
|
|
265
291
|
|
|
266
292
|
// Keyboard-focus return for unmounting anchored surfaces:
|
|
267
293
|
// when the focus sits INSIDE an anchored menu that this
|
|
@@ -314,11 +340,11 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
314
340
|
self.widget_chart_x_labels_len = 0;
|
|
315
341
|
|
|
316
342
|
for (layout.nodes, 0..) |node, layout_index| {
|
|
317
|
-
const text_reconciled = canvasWidgetLayoutNodeWithTextReconcileState(node, layout, layout_index, &index_scratch.texts);
|
|
318
|
-
const text_copy = try self
|
|
319
|
-
const copy = canvasWidgetLayoutNodeWithControlReconcileState(text_copy, layout, layout_index, &index_scratch.controls, &index_scratch.source_controls);
|
|
343
|
+
const text_reconciled = if (reconcile_plan) |*plan| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedText(node, plan.entries[layout_index], &index_scratch.texts) else canvasWidgetLayoutNodeWithTextReconcileState(node, layout, layout_index, &index_scratch.texts);
|
|
344
|
+
const text_copy = try copyWidgetLayoutNodeWithContinuity(self, text_reconciled, &index_scratch.semantics, if (continuity_plan) |plan| plan.actions[layout_index] else null);
|
|
345
|
+
const copy = if (reconcile_plan) |*plan| canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedControl(text_copy, plan.entries[layout_index]) else canvasWidgetLayoutNodeWithControlReconcileState(text_copy, layout, layout_index, &index_scratch.controls, &index_scratch.source_controls);
|
|
320
346
|
self.widget_layout_nodes[self.widget_layout_node_count] = copy;
|
|
321
|
-
self.widget_scroll_states[self.widget_layout_node_count] =
|
|
347
|
+
self.widget_scroll_states[self.widget_layout_node_count] = canvas_widget_runtime.canvasWidgetScrollStateWithPlan(copy, previous_scroll_states, if (continuity_plan) |plan| plan.actions[layout_index] else null);
|
|
322
348
|
self.widget_layout_node_count += 1;
|
|
323
349
|
}
|
|
324
350
|
|
|
@@ -342,7 +368,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
342
368
|
self.applyCanvasTooltipVisibility();
|
|
343
369
|
|
|
344
370
|
const semantics = try self.widgetLayoutTree().collectSemantics(&self.widget_semantics_nodes);
|
|
345
|
-
|
|
371
|
+
canvas_widget_runtime.applyCanvasWidgetSourceScrollSemanticsWithPolicy(self.widget_tokens.widget_continuity_policy, self.widget_semantics_nodes[0..semantics.len], &index_scratch.semantics);
|
|
346
372
|
self.widget_semantics_node_count = semantics.len;
|
|
347
373
|
if (self.canvas_widget_focused_id != 0 and self.widgetLayoutTree().focusTargetById(self.canvas_widget_focused_id) == null) {
|
|
348
374
|
const return_id = if (focus_return_id != 0 and self.widgetLayoutTree().focusTargetById(focus_return_id) != null) focus_return_id else 0;
|
|
@@ -1626,6 +1652,10 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
1626
1652
|
}
|
|
1627
1653
|
|
|
1628
1654
|
pub fn copyWidgetLayoutNode(self: *RuntimeView, node: canvas.WidgetLayoutNode, source_semantics: *const canvas_widget_runtime.CanvasWidgetSemanticsIndex) anyerror!canvas.WidgetLayoutNode {
|
|
1655
|
+
return copyWidgetLayoutNodeWithContinuity(self, node, source_semantics, null);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
fn copyWidgetLayoutNodeWithContinuity(self: *RuntimeView, node: canvas.WidgetLayoutNode, source_semantics: *const canvas_widget_runtime.CanvasWidgetSemanticsIndex, continuity_action: ?u8) anyerror!canvas.WidgetLayoutNode {
|
|
1629
1659
|
var copy = node;
|
|
1630
1660
|
if (node.widget.command.len > 0) try validateCommandName(node.widget.command);
|
|
1631
1661
|
copy.widget.text = try self.copyWidgetText(node.widget.text);
|
|
@@ -1635,7 +1665,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
|
|
|
1635
1665
|
copy.widget.semantics.label = try self.copyWidgetText(node.widget.semantics.label);
|
|
1636
1666
|
copy.widget.context_menu = try self.copyWidgetContextMenu(node.widget.context_menu);
|
|
1637
1667
|
copy.widget.chart = try self.copyWidgetChart(node.widget.chart);
|
|
1638
|
-
copy =
|
|
1668
|
+
copy = canvas_widget_runtime.canvasWidgetLayoutNodeWithPlannedSourceSemantics(copy, source_semantics, continuity_action);
|
|
1639
1669
|
copy.widget.children = &.{};
|
|
1640
1670
|
return copy;
|
|
1641
1671
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
//! Owned virtual-window plans. Compiler output contains bounded ordinals,
|
|
2
|
+
//! never layout/model pointers; copy it before invoking any other policy.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const canvas = @import("canvas");
|
|
5
|
+
const limits = @import("canvas_limits.zig");
|
|
6
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
7
|
+
const max_nodes = limits.max_canvas_widget_nodes_per_view;
|
|
8
|
+
const max_lists = canvas.max_virtual_windows;
|
|
9
|
+
const missing = std.math.maxInt(u32);
|
|
10
|
+
pub const List = struct { node: ?usize, coverage: enum { skip, fixed, variable }, measure: bool, rows: []const u8 };
|
|
11
|
+
pub const Layout = struct {
|
|
12
|
+
bytes: [16 + max_lists * 16 + max_lists * max_nodes * 4]u8 = undefined,
|
|
13
|
+
count: usize,
|
|
14
|
+
pub fn init(policy: Policy, records: []const canvas.VirtualWindowRecord, nodes: []const canvas.WidgetLayoutNode) Layout {
|
|
15
|
+
if (records.len > max_lists or nodes.len > max_nodes) @panic("virtual window plan budget exceeded");
|
|
16
|
+
var request: [16 + (max_lists + max_nodes) * 24]u8 = @splat(0);
|
|
17
|
+
request[0] = 97;
|
|
18
|
+
put(&request, 4, @intCast(records.len));
|
|
19
|
+
put(&request, 8, @intCast(nodes.len));
|
|
20
|
+
for (records, 0..) |record, i| {
|
|
21
|
+
const at = 16 + i * 24;
|
|
22
|
+
integer(&request, at, record.id);
|
|
23
|
+
integer(&request, at + 8, record.item_count);
|
|
24
|
+
put(&request, at + 16, @intFromBool(record.variable));
|
|
25
|
+
}
|
|
26
|
+
for (nodes, 0..) |node, i| {
|
|
27
|
+
const at = 16 + (records.len + i) * 24;
|
|
28
|
+
integer(&request, at, node.widget.id);
|
|
29
|
+
integer(&request, at + 8, node.parent_index orelse 0);
|
|
30
|
+
const viewport = node.frame.inset(node.widget.layout.padding).normalized();
|
|
31
|
+
put(&request, at + 16, @as(u32, @intFromBool(node.parent_index != null)) |
|
|
32
|
+
(@as(u32, @intFromBool(node.widget.layout.anchor != null)) << 1) |
|
|
33
|
+
(@as(u32, @intFromBool(node.widget.semantics.list_item_index != null)) << 2) |
|
|
34
|
+
(@as(u32, @intFromBool(viewport.isEmpty())) << 3));
|
|
35
|
+
}
|
|
36
|
+
var self = Layout{ .count = records.len };
|
|
37
|
+
const length = policy(request[0 .. 16 + (records.len + nodes.len) * 24], &self.bytes);
|
|
38
|
+
if (length < 16 or length > self.bytes.len or !std.mem.eql(u8, self.bytes[0..4], &.{ 97, 0, 0, 0 }) or
|
|
39
|
+
get(&self.bytes, 4) != records.len or get(&self.bytes, 8) > records.len * nodes.len or get(&self.bytes, 12) != 0 or
|
|
40
|
+
length != 16 + records.len * 16 + @as(usize, get(&self.bytes, 8)) * 4) @panic("invalid virtual window layout result");
|
|
41
|
+
var consumed: usize = 0;
|
|
42
|
+
for (records, 0..) |record, i| {
|
|
43
|
+
const at = 16 + i * 16;
|
|
44
|
+
const slot = get(&self.bytes, at);
|
|
45
|
+
const flags = get(&self.bytes, at + 4);
|
|
46
|
+
const coverage = flags & 3;
|
|
47
|
+
const begin = get(&self.bytes, at + 8);
|
|
48
|
+
const count = get(&self.bytes, at + 12);
|
|
49
|
+
if ((slot != missing and (slot >= nodes.len or nodes[slot].widget.id != record.id)) or flags > 6 or coverage > 2 or
|
|
50
|
+
(coverage != 0 and (slot == missing or record.id == 0)) or begin != consumed or count > nodes.len or
|
|
51
|
+
count > get(&self.bytes, 8) - consumed or ((flags & 4 != 0 or count != 0) and (!record.variable or record.item_count == 0 or slot == missing)))
|
|
52
|
+
@panic("invalid virtual window capability");
|
|
53
|
+
var previous: ?usize = null;
|
|
54
|
+
for (0..count) |j| {
|
|
55
|
+
const ordinal = get(&self.bytes, 16 + records.len * 16 + (begin + j) * 4);
|
|
56
|
+
if (ordinal >= nodes.len or (previous != null and ordinal <= previous.?) or nodes[ordinal].parent_index != slot or
|
|
57
|
+
nodes[ordinal].widget.layout.anchor != null or nodes[ordinal].widget.semantics.list_item_index == null)
|
|
58
|
+
@panic("invalid virtual measurement capability");
|
|
59
|
+
previous = ordinal;
|
|
60
|
+
}
|
|
61
|
+
consumed += count;
|
|
62
|
+
}
|
|
63
|
+
if (consumed != get(&self.bytes, 8)) @panic("unclaimed virtual measurement result");
|
|
64
|
+
return self;
|
|
65
|
+
}
|
|
66
|
+
pub fn list(self: *const Layout, index: usize) List {
|
|
67
|
+
std.debug.assert(index < self.count);
|
|
68
|
+
const at = 16 + index * 16;
|
|
69
|
+
const slot = get(&self.bytes, at);
|
|
70
|
+
const begin = 16 + self.count * 16 + @as(usize, get(&self.bytes, at + 8)) * 4;
|
|
71
|
+
return .{ .node = if (slot == missing) null else slot, .coverage = @enumFromInt(get(&self.bytes, at + 4) & 3), .measure = get(&self.bytes, at + 4) & 4 != 0, .rows = self.bytes[begin..][0 .. @as(usize, get(&self.bytes, at + 12)) * 4] };
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
pub fn row(rows: []const u8, index: usize) usize {
|
|
75
|
+
return get(rows, index * 4);
|
|
76
|
+
}
|
|
77
|
+
pub fn contains(policy: Policy, id: u64, records: []const canvas.VirtualWindowRecord) bool {
|
|
78
|
+
if (records.len > max_lists) @panic("virtual identity budget exceeded");
|
|
79
|
+
var request: [16 + max_lists * 8]u8 = @splat(0);
|
|
80
|
+
request[0..2].* = .{ 97, 1 };
|
|
81
|
+
put(&request, 4, @intCast(records.len));
|
|
82
|
+
integer(&request, 8, id);
|
|
83
|
+
for (records, 0..) |record, i| integer(&request, 16 + i * 8, record.id);
|
|
84
|
+
return scalar(policy, request[0 .. 16 + records.len * 8], 1) != 0;
|
|
85
|
+
}
|
|
86
|
+
pub const Retry = enum(u8) { stop, probe, rebuild };
|
|
87
|
+
pub fn retry(policy: Policy, pass: usize, had_correction: bool, undercovered: ?bool) Retry {
|
|
88
|
+
var request: [16]u8 = @splat(0);
|
|
89
|
+
request[0..2].* = .{ 97, 2 };
|
|
90
|
+
put(&request, 4, @intCast(pass));
|
|
91
|
+
put(&request, 8, @as(u32, @intFromBool(had_correction)) |
|
|
92
|
+
(@as(u32, @intFromBool(undercovered != null)) << 1) | (@as(u32, @intFromBool(undercovered orelse false)) << 2));
|
|
93
|
+
return @enumFromInt(scalar(policy, &request, 2));
|
|
94
|
+
}
|
|
95
|
+
pub fn corrected(policy: Policy, deltas: []const f32) bool {
|
|
96
|
+
if (deltas.len > max_lists) @panic("virtual correction budget exceeded");
|
|
97
|
+
var request: [16 + max_lists * 4]u8 = @splat(0);
|
|
98
|
+
request[0..2].* = .{ 97, 3 };
|
|
99
|
+
put(&request, 4, @intCast(deltas.len));
|
|
100
|
+
for (deltas, 0..) |delta, i| put(&request, 16 + i * 4, @bitCast(delta));
|
|
101
|
+
return scalar(policy, request[0 .. 16 + deltas.len * 4], 1) != 0;
|
|
102
|
+
}
|
|
103
|
+
pub fn fixedUndercovered(policy: Policy, record: canvas.VirtualWindowRecord, node: canvas.WidgetLayoutNode) bool {
|
|
104
|
+
const builtin = @import("builtin");
|
|
105
|
+
var request: [72]u8 = @splat(0);
|
|
106
|
+
request[0..2].* = .{ 97, 4 };
|
|
107
|
+
put(&request, 4, (canvas.virtual_extent_policy.numericFlags()) |
|
|
108
|
+
@as(u32, if (builtin.mode == .Debug or builtin.mode == .ReleaseSafe) 2 else 0));
|
|
109
|
+
for ([_]u64{ record.item_count, record.overscan, record.start_index, record.end_index }, 0..) |v, i| integer(&request, 8 + i * 8, v);
|
|
110
|
+
const viewport = node.frame.inset(node.widget.layout.padding).normalized();
|
|
111
|
+
for ([_]f32{ @floatFromInt(record.item_count), node.widget.layout.virtual_item_extent, record.item_extent, record.gap, viewport.height, node.widget.value }, 0..) |v, i|
|
|
112
|
+
put(&request, 40 + i * 4, @bitCast(v));
|
|
113
|
+
return scalar(policy, &request, 1) != 0;
|
|
114
|
+
}
|
|
115
|
+
fn scalar(policy: Policy, request: []const u8, maximum: u8) u8 {
|
|
116
|
+
var out: [1]u8 = undefined;
|
|
117
|
+
if (policy(request, &out) != 1 or out[0] > maximum) @panic("invalid virtual window scalar result");
|
|
118
|
+
return out[0];
|
|
119
|
+
}
|
|
120
|
+
fn put(bytes: []u8, at: usize, value: u32) void {
|
|
121
|
+
std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
|
|
122
|
+
}
|
|
123
|
+
fn get(bytes: []const u8, at: usize) u32 {
|
|
124
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
125
|
+
}
|
|
126
|
+
fn integer(bytes: []u8, at: usize, value: u64) void {
|
|
127
|
+
std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
|
|
128
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
//! Copied pane plans. Native retains complete text, layout and slot storage;
|
|
2
|
+
//! only equality observations, numeric capabilities and bounded ordinals cross.
|
|
3
|
+
const std = @import("std");
|
|
4
|
+
const canvas = @import("canvas");
|
|
5
|
+
const geometry = @import("geometry");
|
|
6
|
+
const limits = @import("canvas_limits.zig");
|
|
7
|
+
pub const Policy = *const fn ([]const u8, []u8) usize;
|
|
8
|
+
// Probe the same constant-zero f32 operation as the native pane owner.
|
|
9
|
+
// Two variable zero operands can select a different sign on the same target.
|
|
10
|
+
fn originNumericFlags() u8 {
|
|
11
|
+
var value: f32 = -0.0;
|
|
12
|
+
std.mem.doNotOptimizeAway(&value);
|
|
13
|
+
return if (@as(u32, @bitCast(@max(value, 0))) == 0x80000000) 4 else 0;
|
|
14
|
+
}
|
|
15
|
+
fn header(comptime length: usize, mode: u8) [length]u8 {
|
|
16
|
+
var bytes: [length]u8 = @splat(0);
|
|
17
|
+
bytes[0..2].* = .{ 99, mode };
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
fn put(bytes: []u8, at: usize, value: u32) void {
|
|
21
|
+
std.mem.writeInt(u32, bytes[at..][0..4], value, .little);
|
|
22
|
+
}
|
|
23
|
+
fn wide(bytes: []u8, at: usize, value: u64) void {
|
|
24
|
+
std.mem.writeInt(u64, bytes[at..][0..8], value, .little);
|
|
25
|
+
}
|
|
26
|
+
fn get(bytes: []const u8, at: usize) u32 {
|
|
27
|
+
return std.mem.readInt(u32, bytes[at..][0..4], .little);
|
|
28
|
+
}
|
|
29
|
+
fn rect(bytes: []u8, at: usize, value: geometry.RectF) void {
|
|
30
|
+
inline for (.{ "x", "y", "width", "height" }, 0..) |field, i| put(bytes, at + i * 4, @bitCast(@field(value, field)));
|
|
31
|
+
}
|
|
32
|
+
fn run(policy: Policy, request: []const u8, result: []u8) void {
|
|
33
|
+
if (policy(request, result) != result.len) @panic("invalid web pane plan length");
|
|
34
|
+
}
|
|
35
|
+
pub const Frame = struct { kind: enum(u32) { missing_anchor, collapsed, apply }, value: geometry.RectF };
|
|
36
|
+
pub fn frame(policy: Policy, nodes: []const canvas.WidgetLayoutNode, explicit: geometry.RectF, anchor: ?[]const u8) Frame {
|
|
37
|
+
const count = if (anchor != null) nodes.len else 0;
|
|
38
|
+
if (count > limits.max_canvas_widget_nodes_per_view) @panic("web pane layout capacity");
|
|
39
|
+
var request = header(32 + limits.max_canvas_widget_nodes_per_view * 20, 0);
|
|
40
|
+
request[2] = originNumericFlags();
|
|
41
|
+
put(&request, 4, @intCast(count));
|
|
42
|
+
put(&request, 8, @intFromBool(anchor != null));
|
|
43
|
+
rect(&request, 16, explicit);
|
|
44
|
+
for (nodes[0..count], 0..) |node, i| {
|
|
45
|
+
const at = 32 + i * 20;
|
|
46
|
+
put(&request, at, @intFromBool(std.mem.eql(u8, node.widget.semantics.label, anchor.?)));
|
|
47
|
+
rect(&request, at + 4, node.frame);
|
|
48
|
+
}
|
|
49
|
+
var out: [24]u8 = undefined;
|
|
50
|
+
run(policy, request[0 .. 32 + count * 20], &out);
|
|
51
|
+
const kind = get(&out, 0);
|
|
52
|
+
const selected = get(&out, 4);
|
|
53
|
+
if (kind > 2 or (kind == 0 and anchor == null) or (selected != std.math.maxInt(u32) and (selected >= count or anchor == null or
|
|
54
|
+
!std.mem.eql(u8, nodes[selected].widget.semantics.label, anchor.?))) or
|
|
55
|
+
(kind == 2 and anchor != null and selected == std.math.maxInt(u32))) @panic("invalid web pane frame capability");
|
|
56
|
+
return .{ .kind = @enumFromInt(kind), .value = .{
|
|
57
|
+
.x = @bitCast(get(&out, 8)),
|
|
58
|
+
.y = @bitCast(get(&out, 12)),
|
|
59
|
+
.width = @bitCast(get(&out, 16)),
|
|
60
|
+
.height = @bitCast(get(&out, 20)),
|
|
61
|
+
} };
|
|
62
|
+
}
|
|
63
|
+
pub const Slot = struct { index: usize, create: bool, label_bytes: usize };
|
|
64
|
+
pub fn slot(policy: Policy, states: anytype, label: []const u8, capacity: usize) ?Slot {
|
|
65
|
+
if (states.len > 4 or capacity > 64) @panic("web pane slot capacity");
|
|
66
|
+
var request = header(32, 1);
|
|
67
|
+
put(&request, 4, @intCast(states.len));
|
|
68
|
+
wide(&request, 8, label.len);
|
|
69
|
+
put(&request, 16, @intCast(capacity));
|
|
70
|
+
for (states, 0..) |state, i| request[20 + i] = @intFromBool(std.mem.eql(u8, state.label_storage[0..state.label_len], label));
|
|
71
|
+
var out: [12]u8 = undefined;
|
|
72
|
+
run(policy, &request, &out);
|
|
73
|
+
const kind = get(&out, 0);
|
|
74
|
+
const index = get(&out, 4);
|
|
75
|
+
const bytes = get(&out, 8);
|
|
76
|
+
if (kind > 2 or bytes > capacity or bytes > label.len or (kind == 1 and (index >= states.len or bytes != 0 or
|
|
77
|
+
!std.mem.eql(u8, states[index].label_storage[0..states[index].label_len], label))) or
|
|
78
|
+
(kind == 2 and (index != states.len or index >= 4))) @panic("invalid web pane slot capability");
|
|
79
|
+
if (kind == 0) {
|
|
80
|
+
if (index != std.math.maxInt(u32) or bytes != 0) @panic("invalid web pane exhausted slot");
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return .{ .index = index, .create = kind == 2, .label_bytes = bytes };
|
|
84
|
+
}
|
|
85
|
+
pub const Patch = packed struct(u8) { frame: bool, url: bool, reserved: u6 = 0 };
|
|
86
|
+
pub fn patch(policy: Policy, actual: geometry.RectF, desired: geometry.RectF, previous_url: []const u8, url: []const u8, previous_token: u64, token: u64) Patch {
|
|
87
|
+
var request = header(64, 2);
|
|
88
|
+
put(&request, 4, @as(u32, @intFromBool(previous_url.len == 0)) | (@as(u32, @intFromBool(std.mem.eql(u8, previous_url, url))) << 1) |
|
|
89
|
+
(@as(u32, @intFromBool(url.len > 0)) << 2));
|
|
90
|
+
rect(&request, 8, desired);
|
|
91
|
+
rect(&request, 24, actual);
|
|
92
|
+
wide(&request, 40, previous_token);
|
|
93
|
+
wide(&request, 48, token);
|
|
94
|
+
var out: [4]u8 = undefined;
|
|
95
|
+
run(policy, &request, &out);
|
|
96
|
+
if (get(&out, 0) > 3) @panic("invalid web pane patch capability");
|
|
97
|
+
return @bitCast(out[0]);
|
|
98
|
+
}
|
|
99
|
+
pub fn commit(policy: Policy, success: bool, length: usize, capacity: usize) ?usize {
|
|
100
|
+
if (capacity > 4096) @panic("web pane URL capacity");
|
|
101
|
+
var request = header(32, 3);
|
|
102
|
+
put(&request, 4, @intFromBool(success));
|
|
103
|
+
wide(&request, 8, length);
|
|
104
|
+
put(&request, 16, @intCast(capacity));
|
|
105
|
+
var out: [8]u8 = undefined;
|
|
106
|
+
run(policy, &request, &out);
|
|
107
|
+
const admitted = get(&out, 0);
|
|
108
|
+
const bytes = get(&out, 4);
|
|
109
|
+
if (admitted > 1 or bytes > length or bytes > capacity or (admitted == 0 and bytes != 0) or (admitted == 1 and !success)) @panic("invalid web pane commit capability");
|
|
110
|
+
return if (admitted == 1) bytes else null;
|
|
111
|
+
}
|