@native-sdk/cli 0.9.1 → 0.9.2
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 +26 -9
- package/build.zig +55 -0
- package/package.json +9 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.ts +3 -1
- package/skill-data/native-ui/SKILL.md +7 -7
- package/skill-data/ts-core/SKILL.md +1 -1
- package/src/app_runner/root.zig +93 -6
- package/src/app_runner/ts_core_main.zig +4 -4
- package/src/app_runner/window_placement.zig +63 -0
- package/src/embed/app_exports.zig +2 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +13 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +26 -2
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +10 -2
- package/src/platform/linux/gtk_host.c +43 -10
- package/src/platform/linux/gtk_host.h +3 -3
- package/src/platform/linux/root.zig +22 -7
- package/src/platform/macos/appkit_host.h +7 -4
- package/src/platform/macos/appkit_host.m +192 -40
- package/src/platform/macos/cef_host.mm +132 -34
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +154 -9
- package/src/platform/null_platform.zig +17 -3
- package/src/platform/null_platform_tests.zig +58 -4
- package/src/platform/root.zig +2 -0
- package/src/platform/types.zig +69 -19
- package/src/platform/windows/root.zig +22 -7
- package/src/platform/windows/webview2_host.cpp +31 -6
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +3 -0
- package/src/runtime/api.zig +6 -0
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/builtin_bridge.zig +5 -2
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +16 -0
- package/src/runtime/effects.zig +14 -14
- package/src/runtime/effects_image_tests.zig +91 -0
- package/src/runtime/gpu_surface_events.zig +25 -2
- package/src/runtime/root.zig +2 -0
- package/src/runtime/session_replay.zig +13 -8
- package/src/runtime/session_tests.zig +111 -4
- package/src/runtime/shell_layout_tests.zig +12 -0
- package/src/runtime/ts_core_host_tests.zig +47 -0
- package/src/runtime/ui_app.zig +9 -3
- package/src/runtime/ui_app_tests.zig +119 -19
- package/src/runtime/ui_app_window_tests.zig +13 -1
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +128 -18
- package/src/tooling/web_engine.zig +1 -1
|
@@ -238,18 +238,20 @@ pub fn canvasWidgetScrollDriverEligible(node: canvas.WidgetLayoutNode) bool {
|
|
|
238
238
|
/// - ITSELF (a directly anchored scroll region is its own surface);
|
|
239
239
|
/// - its own subtree (a scroll region inside an open popover or
|
|
240
240
|
/// modal is above the surface, not beneath it);
|
|
241
|
-
/// - a driver whose
|
|
242
|
-
/// (
|
|
243
|
-
///
|
|
244
|
-
/// overlapping popovers sits above the lower one).
|
|
241
|
+
/// - a driver whose window-level ROOT paints LATER in the floating pass
|
|
242
|
+
/// (window-level surfaces paint by effective layer and then tree order,
|
|
243
|
+
/// so a scroll region inside the topmost surface sits above lower ones).
|
|
245
244
|
fn driverOccluderMask(view: anytype, driver_node: usize, occluder_nodes: []const usize) u32 {
|
|
246
|
-
const
|
|
245
|
+
const driver_window_root = windowSurfaceRootIndex(view, driver_node);
|
|
247
246
|
var mask: u32 = 0;
|
|
248
247
|
for (occluder_nodes, 0..) |occluder_node, bit| {
|
|
249
248
|
if (occluder_node == driver_node) continue;
|
|
250
|
-
if (
|
|
249
|
+
if (driver_window_root) |root| {
|
|
251
250
|
if (occluder_node == root) continue;
|
|
252
|
-
|
|
251
|
+
const layout = view.widgetLayoutTree();
|
|
252
|
+
const root_order = canvas.widgetLayoutWindowSurfaceOrder(layout, root, view.widget_tokens);
|
|
253
|
+
const occluder_order = canvas.widgetLayoutWindowSurfaceOrder(layout, occluder_node, view.widget_tokens);
|
|
254
|
+
if (canvas.widgetPaintOrderLess(occluder_order, root_order)) continue;
|
|
253
255
|
}
|
|
254
256
|
if (nodeIsAncestor(view, occluder_node, driver_node)) continue;
|
|
255
257
|
mask |= @as(u32, 1) << @intCast(bit);
|
|
@@ -268,12 +270,12 @@ fn transformedOccluderFrame(node: canvas.WidgetLayoutNode) geometry.RectF {
|
|
|
268
270
|
return transform.transformRect(frame).normalized();
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
/// The nearest self-or-ancestor node that is
|
|
273
|
+
/// The nearest self-or-ancestor node that is a window-level surface root,
|
|
272
274
|
/// or null for in-flow content.
|
|
273
|
-
fn
|
|
275
|
+
fn windowSurfaceRootIndex(view: anytype, node_index: usize) ?usize {
|
|
274
276
|
var current: ?usize = node_index;
|
|
275
277
|
while (current) |index| {
|
|
276
|
-
if (view.widget_layout_nodes[index].widget
|
|
278
|
+
if (canvas.widgetEscapesAncestorClips(view.widget_layout_nodes[index].widget)) return index;
|
|
277
279
|
current = view.widget_layout_nodes[index].parent_index;
|
|
278
280
|
}
|
|
279
281
|
return null;
|
|
@@ -1481,6 +1481,147 @@ test "user scroll offsets survive rebuilds until the source offset changes" {
|
|
|
1481
1481
|
try std.testing.expectEqual(@as(f32, 18), (try harness.runtime.canvasWidgetLayout(1, "canvas")).findById(1).?.widget.value);
|
|
1482
1482
|
}
|
|
1483
1483
|
|
|
1484
|
+
test "anchored surfaces relayout against restored scroll geometry across rebuilds" {
|
|
1485
|
+
const TestApp = struct {
|
|
1486
|
+
fn app(self: *@This()) App {
|
|
1487
|
+
return .{ .context = self, .name = "gpu-scroll-anchored-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1492
|
+
defer harness.destroy(std.testing.allocator);
|
|
1493
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1494
|
+
var app_state: TestApp = .{};
|
|
1495
|
+
const app = app_state.app();
|
|
1496
|
+
try harness.start(app);
|
|
1497
|
+
_ = try harness.runtime.createView(.{
|
|
1498
|
+
.window_id = 1,
|
|
1499
|
+
.label = "canvas",
|
|
1500
|
+
.kind = .gpu_surface,
|
|
1501
|
+
.frame = geometry.RectF.init(0, 0, 180, 100),
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
const menu_items = [_]canvas.Widget{.{ .id = 5, .kind = .menu_item, .frame = geometry.RectF.init(0, 0, 0, 24), .text = "One" }};
|
|
1505
|
+
const dropdown = canvas.Widget{
|
|
1506
|
+
.id = 4,
|
|
1507
|
+
.kind = .dropdown_menu,
|
|
1508
|
+
.frame = geometry.RectF.init(0, 0, 140, 50),
|
|
1509
|
+
.layout = .{ .anchor = .{} },
|
|
1510
|
+
.children = &menu_items,
|
|
1511
|
+
};
|
|
1512
|
+
const wrap_children = [_]canvas.Widget{
|
|
1513
|
+
.{ .id = 3, .kind = .text, .text = "Files" },
|
|
1514
|
+
dropdown,
|
|
1515
|
+
};
|
|
1516
|
+
const scroll_children = [_]canvas.Widget{
|
|
1517
|
+
.{ .id = 2, .kind = .stack, .frame = geometry.RectF.init(0, 140, 160, 28), .children = &wrap_children },
|
|
1518
|
+
.{ .id = 6, .kind = .panel, .frame = geometry.RectF.init(0, 320, 160, 20) },
|
|
1519
|
+
};
|
|
1520
|
+
const source_root = canvas.Widget{ .id = 1, .kind = .scroll_view, .children = &scroll_children };
|
|
1521
|
+
|
|
1522
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1523
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try canvas.layoutWidgetTree(source_root, geometry.RectF.init(0, 0, 180, 100), &nodes));
|
|
1524
|
+
|
|
1525
|
+
// Bring the trigger near the top. The source rebuild still lays it at
|
|
1526
|
+
// y=140 before the retained offset returns; the anchored pass must run
|
|
1527
|
+
// again and place the full-height menu below the final y=10 trigger.
|
|
1528
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 130");
|
|
1529
|
+
var rebuild_nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1530
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try canvas.layoutWidgetTree(source_root, geometry.RectF.init(0, 0, 180, 100), &rebuild_nodes));
|
|
1531
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1532
|
+
var trigger = retained.findById(2).?.frame;
|
|
1533
|
+
var surface = retained.findById(4).?.frame;
|
|
1534
|
+
try std.testing.expectEqual(@as(f32, 10), trigger.y);
|
|
1535
|
+
try std.testing.expectEqual(trigger.maxY() + 4, surface.y);
|
|
1536
|
+
try std.testing.expectEqual(@as(f32, 50), surface.height);
|
|
1537
|
+
|
|
1538
|
+
// Move the trigger near the bottom and rebuild again. Now the final
|
|
1539
|
+
// geometry must choose the other side and preserve the authored height.
|
|
1540
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 1 -60");
|
|
1541
|
+
var flipped_nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1542
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try canvas.layoutWidgetTree(source_root, geometry.RectF.init(0, 0, 180, 100), &flipped_nodes));
|
|
1543
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1544
|
+
trigger = retained.findById(2).?.frame;
|
|
1545
|
+
surface = retained.findById(4).?.frame;
|
|
1546
|
+
try std.testing.expectEqual(@as(f32, 70), trigger.y);
|
|
1547
|
+
try std.testing.expectEqual(trigger.y - 4 - surface.height, surface.y);
|
|
1548
|
+
try std.testing.expectEqual(@as(f32, 50), surface.height);
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
test "anchored relayout preserves a descendant scroll region across rebuilds" {
|
|
1552
|
+
const TestApp = struct {
|
|
1553
|
+
fn app(self: *@This()) App {
|
|
1554
|
+
return .{ .context = self, .name = "gpu-scroll-anchored-descendant-reconcile", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
|
|
1558
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1559
|
+
defer harness.destroy(std.testing.allocator);
|
|
1560
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1561
|
+
var app_state: TestApp = .{};
|
|
1562
|
+
const app = app_state.app();
|
|
1563
|
+
try harness.start(app);
|
|
1564
|
+
_ = try harness.runtime.createView(.{
|
|
1565
|
+
.window_id = 1,
|
|
1566
|
+
.label = "canvas",
|
|
1567
|
+
.kind = .gpu_surface,
|
|
1568
|
+
.frame = geometry.RectF.init(0, 0, 220, 160),
|
|
1569
|
+
});
|
|
1570
|
+
|
|
1571
|
+
const scroll_content = [_]canvas.Widget{.{
|
|
1572
|
+
.id = 7,
|
|
1573
|
+
.kind = .panel,
|
|
1574
|
+
.frame = geometry.RectF.init(0, 0, 120, 180),
|
|
1575
|
+
}};
|
|
1576
|
+
const popover_children = [_]canvas.Widget{.{
|
|
1577
|
+
.id = 6,
|
|
1578
|
+
.kind = .scroll_view,
|
|
1579
|
+
.frame = geometry.RectF.init(0, 0, 120, 56),
|
|
1580
|
+
.children = &scroll_content,
|
|
1581
|
+
}};
|
|
1582
|
+
const popover = canvas.Widget{
|
|
1583
|
+
.id = 4,
|
|
1584
|
+
.kind = .popover,
|
|
1585
|
+
.frame = geometry.RectF.init(0, 0, 140, 80),
|
|
1586
|
+
.layout = .{ .anchor = .{} },
|
|
1587
|
+
.children = &popover_children,
|
|
1588
|
+
};
|
|
1589
|
+
const trigger_children = [_]canvas.Widget{
|
|
1590
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 140, 28), .text = "Open" },
|
|
1591
|
+
popover,
|
|
1592
|
+
};
|
|
1593
|
+
const source_root = canvas.Widget{
|
|
1594
|
+
.id = 1,
|
|
1595
|
+
.kind = .stack,
|
|
1596
|
+
.frame = geometry.RectF.init(20, 20, 140, 28),
|
|
1597
|
+
.children = &trigger_children,
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1601
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try canvas.layoutWidgetTree(
|
|
1602
|
+
source_root,
|
|
1603
|
+
geometry.RectF.init(0, 0, 220, 160),
|
|
1604
|
+
&nodes,
|
|
1605
|
+
));
|
|
1606
|
+
|
|
1607
|
+
try harness.runtime.dispatchAutomationCommand(app, "widget-wheel canvas 6 24");
|
|
1608
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1609
|
+
try std.testing.expectEqual(@as(f32, 24), retained.findById(6).?.widget.value);
|
|
1610
|
+
const scrolled_content_y = retained.findById(7).?.frame.y;
|
|
1611
|
+
|
|
1612
|
+
// Replaying the anchored surface recovers its authored size, but must
|
|
1613
|
+
// not replay over runtime-owned state inside that surface.
|
|
1614
|
+
var rebuild_nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1615
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", try canvas.layoutWidgetTree(
|
|
1616
|
+
source_root,
|
|
1617
|
+
geometry.RectF.init(0, 0, 220, 160),
|
|
1618
|
+
&rebuild_nodes,
|
|
1619
|
+
));
|
|
1620
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1621
|
+
try std.testing.expectEqual(@as(f32, 24), retained.findById(6).?.widget.value);
|
|
1622
|
+
try std.testing.expectEqual(scrolled_content_y, retained.findById(7).?.frame.y);
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1484
1625
|
test "engine wheel scrolls a windowed virtual list against its declared extent" {
|
|
1485
1626
|
const TestApp = struct {
|
|
1486
1627
|
fn app(self: *@This()) App {
|
|
@@ -1890,10 +2031,18 @@ test "a surface anchored to the scroll region itself never rides its content" {
|
|
|
1890
2031
|
.{ .widget = .{ .id = 1, .kind = .scroll_view, .frame = geometry.RectF.init(0, 0, 180, 72) }, .frame = geometry.RectF.init(0, 0, 180, 72), .depth = 0 },
|
|
1891
2032
|
.{ .widget = .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 160, 200) }, .frame = geometry.RectF.init(0, 0, 160, 200), .depth = 1, .parent_index = 0 },
|
|
1892
2033
|
.{ .widget = .{ .id = 4, .kind = .popover, .frame = geometry.RectF.init(20, 40, 100, 30), .layout = .{ .anchor = .{ .placement = .below } } }, .frame = geometry.RectF.init(20, 40, 100, 30), .depth = 2, .parent_index = 1 },
|
|
1893
|
-
.{ .widget = .{ .id = 3, .kind = .popover, .frame = geometry.RectF.init(10, 72, 100, 30), .layout = .{ .anchor = .{ .placement = .below } } }, .frame = geometry.RectF.init(10, 72, 100, 30), .depth = 1, .parent_index = 0 },
|
|
2034
|
+
.{ .widget = .{ .id = 3, .kind = .popover, .frame = geometry.RectF.init(10, 72, 100, 30), .layout = .{ .anchor = .{ .placement = .below } }, .semantics = .{ .focusable = true } }, .frame = geometry.RectF.init(10, 72, 100, 30), .depth = 1, .parent_index = 0 },
|
|
1894
2035
|
};
|
|
1895
2036
|
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", .{ .nodes = &nodes });
|
|
1896
2037
|
|
|
2038
|
+
// Programmatic reveal recognizes that the target itself is hoisted:
|
|
2039
|
+
// it can take focus without scrolling the region behind it.
|
|
2040
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 3, .action = .focus });
|
|
2041
|
+
var retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
2042
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
|
|
2043
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
|
|
2044
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(10, 72, 100, 30), retained.findById(3).?.frame);
|
|
2045
|
+
|
|
1897
2046
|
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1898
2047
|
.window_id = 1,
|
|
1899
2048
|
.label = "canvas",
|
|
@@ -1904,7 +2053,7 @@ test "a surface anchored to the scroll region itself never rides its content" {
|
|
|
1904
2053
|
.delta_y = 24,
|
|
1905
2054
|
} });
|
|
1906
2055
|
|
|
1907
|
-
|
|
2056
|
+
retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1908
2057
|
try std.testing.expectEqual(@as(f32, 24), retained.findById(1).?.widget.value);
|
|
1909
2058
|
// Content and the content-anchored surface moved up together...
|
|
1910
2059
|
try std.testing.expectEqualDeep(geometry.RectF.init(0, -24, 160, 200), retained.findById(2).?.frame);
|
|
@@ -1913,6 +2062,48 @@ test "a surface anchored to the scroll region itself never rides its content" {
|
|
|
1913
2062
|
try std.testing.expectEqualDeep(geometry.RectF.init(10, 72, 100, 30), retained.findById(3).?.frame);
|
|
1914
2063
|
}
|
|
1915
2064
|
|
|
2065
|
+
test "a root-relative modal nested in a scroll region never rides its content" {
|
|
2066
|
+
const TestApp = struct {
|
|
2067
|
+
fn app(self: *@This()) App {
|
|
2068
|
+
return .{ .context = self, .name = "gpu-widget-modal-scroll", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
2069
|
+
}
|
|
2070
|
+
};
|
|
2071
|
+
|
|
2072
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2073
|
+
defer harness.destroy(std.testing.allocator);
|
|
2074
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2075
|
+
var app_state: TestApp = .{};
|
|
2076
|
+
const app = app_state.app();
|
|
2077
|
+
try harness.start(app);
|
|
2078
|
+
_ = try harness.runtime.createView(.{
|
|
2079
|
+
.window_id = 1,
|
|
2080
|
+
.label = "canvas",
|
|
2081
|
+
.kind = .gpu_surface,
|
|
2082
|
+
.frame = geometry.RectF.init(0, 0, 180, 72),
|
|
2083
|
+
});
|
|
2084
|
+
|
|
2085
|
+
const nodes = [_]canvas.WidgetLayoutNode{
|
|
2086
|
+
.{ .widget = .{ .id = 1, .kind = .scroll_view, .frame = geometry.RectF.init(0, 0, 180, 72) }, .frame = geometry.RectF.init(0, 0, 180, 72), .depth = 0 },
|
|
2087
|
+
.{ .widget = .{ .id = 2, .kind = .panel, .frame = geometry.RectF.init(0, 0, 180, 200) }, .frame = geometry.RectF.init(0, 0, 180, 200), .depth = 1, .parent_index = 0 },
|
|
2088
|
+
.{ .widget = .{ .id = 3, .kind = .dialog, .frame = geometry.RectF.init(40, 16, 100, 40) }, .frame = geometry.RectF.init(40, 16, 100, 40), .depth = 2, .parent_index = 1 },
|
|
2089
|
+
};
|
|
2090
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", .{ .nodes = &nodes });
|
|
2091
|
+
|
|
2092
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2093
|
+
.window_id = 1,
|
|
2094
|
+
.label = "canvas",
|
|
2095
|
+
.timestamp_ns = 1_000_000_000,
|
|
2096
|
+
.kind = .scroll,
|
|
2097
|
+
.x = 20,
|
|
2098
|
+
.y = 20,
|
|
2099
|
+
.delta_y = 24,
|
|
2100
|
+
} });
|
|
2101
|
+
|
|
2102
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
2103
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(0, -24, 180, 200), retained.findById(2).?.frame);
|
|
2104
|
+
try std.testing.expectEqualDeep(geometry.RectF.init(40, 16, 100, 40), retained.findById(3).?.frame);
|
|
2105
|
+
}
|
|
2106
|
+
|
|
1916
2107
|
test "assistive steps on a both-axes region page its live axis" {
|
|
1917
2108
|
const TestApp = struct {
|
|
1918
2109
|
fn app(self: *@This()) App {
|
|
@@ -690,10 +690,11 @@ test "runtime applies source-driven autofocus on the edge, never on the level" {
|
|
|
690
690
|
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focused_id);
|
|
691
691
|
|
|
692
692
|
// An editor MOUNTING with autofocus takes keyboard focus (view focus
|
|
693
|
-
// included) on the rebuild that applies it.
|
|
693
|
+
// included) on the rebuild that applies it. With no source selection,
|
|
694
|
+
// programmatic focus collapses the caret at the END of non-empty text.
|
|
694
695
|
const editing = [_]canvas.Widget{
|
|
695
696
|
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 10, 96, 32), .text = "New" },
|
|
696
|
-
.{ .id = 7, .kind = .text_field, .frame = geometry.RectF.init(10, 56, 200, 32), .autofocus = true },
|
|
697
|
+
.{ .id = 7, .kind = .text_field, .frame = geometry.RectF.init(10, 56, 200, 32), .text = "Draft", .autofocus = true },
|
|
697
698
|
};
|
|
698
699
|
var editing_nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
699
700
|
const editing_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &editing }, geometry.RectF.init(0, 0, 320, 240), &editing_nodes);
|
|
@@ -702,7 +703,7 @@ test "runtime applies source-driven autofocus on the edge, never on the level" {
|
|
|
702
703
|
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
703
704
|
try std.testing.expect(harness.runtime.views[0].focused);
|
|
704
705
|
const focused_layout = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
705
|
-
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(
|
|
706
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(5), focused_layout.findById(7).?.widget.text_selection.?);
|
|
706
707
|
|
|
707
708
|
// The user moves focus; re-applying the SAME layout (flag held true)
|
|
708
709
|
// must not steal it back — edge-triggered, level-ignored.
|
|
@@ -730,6 +731,339 @@ test "runtime applies source-driven autofocus on the edge, never on the level" {
|
|
|
730
731
|
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_widget_focused_id);
|
|
731
732
|
}
|
|
732
733
|
|
|
734
|
+
test "runtime autofocus reveals an offscreen textarea and its end caret" {
|
|
735
|
+
const TestApp = struct {
|
|
736
|
+
fn app(self: *@This()) App {
|
|
737
|
+
return .{ .context = self, .name = "gpu-widget-autofocus-reveal", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
742
|
+
defer harness.destroy(std.testing.allocator);
|
|
743
|
+
harness.null_platform.gpu_surfaces = true;
|
|
744
|
+
var app_state: TestApp = .{};
|
|
745
|
+
try harness.start(app_state.app());
|
|
746
|
+
|
|
747
|
+
_ = try harness.runtime.createView(.{
|
|
748
|
+
.window_id = 1,
|
|
749
|
+
.label = "canvas",
|
|
750
|
+
.kind = .gpu_surface,
|
|
751
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
const text = "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight";
|
|
755
|
+
const children = [_]canvas.Widget{.{
|
|
756
|
+
.id = 2,
|
|
757
|
+
.kind = .textarea,
|
|
758
|
+
.frame = geometry.RectF.init(0, 96, 0, 48),
|
|
759
|
+
.text = text,
|
|
760
|
+
.autofocus = true,
|
|
761
|
+
}};
|
|
762
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
763
|
+
const layout = try canvas.layoutWidgetTree(
|
|
764
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
765
|
+
geometry.RectF.init(0, 0, 180, 64),
|
|
766
|
+
&nodes,
|
|
767
|
+
);
|
|
768
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
769
|
+
|
|
770
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
771
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
772
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
773
|
+
const scroll = retained.findById(1).?;
|
|
774
|
+
const editor = retained.findById(2).?;
|
|
775
|
+
const viewport = scroll.frame.normalized();
|
|
776
|
+
try std.testing.expect(scroll.widget.value > 0);
|
|
777
|
+
try std.testing.expect(editor.frame.y >= viewport.y);
|
|
778
|
+
try std.testing.expect(editor.frame.maxY() <= viewport.maxY());
|
|
779
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(text.len), editor.widget.text_selection.?);
|
|
780
|
+
try std.testing.expect(editor.widget.value > 0);
|
|
781
|
+
|
|
782
|
+
const editor_viewport = canvas.textInputViewportForWidget(editor.widget, harness.runtime.views[0].widget_tokens).?;
|
|
783
|
+
const text_geometry = try harness.runtime.canvasWidgetTextGeometry(1, "canvas", 2);
|
|
784
|
+
const caret = text_geometry.caret_bounds.?;
|
|
785
|
+
try std.testing.expect(caret.y >= editor_viewport.y - 0.001);
|
|
786
|
+
try std.testing.expect(caret.maxY() <= editor_viewport.maxY() + 0.001);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
test "runtime autofocus preserves a source-declared text selection" {
|
|
790
|
+
const TestApp = struct {
|
|
791
|
+
fn app(self: *@This()) App {
|
|
792
|
+
return .{ .context = self, .name = "gpu-widget-autofocus-selection", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
797
|
+
defer harness.destroy(std.testing.allocator);
|
|
798
|
+
harness.null_platform.gpu_surfaces = true;
|
|
799
|
+
var app_state: TestApp = .{};
|
|
800
|
+
try harness.start(app_state.app());
|
|
801
|
+
|
|
802
|
+
_ = try harness.runtime.createView(.{
|
|
803
|
+
.window_id = 1,
|
|
804
|
+
.label = "canvas",
|
|
805
|
+
.kind = .gpu_surface,
|
|
806
|
+
.frame = geometry.RectF.init(0, 0, 240, 120),
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
const selection = canvas.TextSelection{ .anchor = 2, .focus = 8 };
|
|
810
|
+
const children = [_]canvas.Widget{.{
|
|
811
|
+
.id = 2,
|
|
812
|
+
.kind = .text_field,
|
|
813
|
+
.frame = geometry.RectF.init(12, 16, 180, 32),
|
|
814
|
+
.text = "A selected draft",
|
|
815
|
+
.text_selection = selection,
|
|
816
|
+
.autofocus = true,
|
|
817
|
+
}};
|
|
818
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
819
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 240, 120), &nodes);
|
|
820
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
821
|
+
|
|
822
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
823
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
824
|
+
try std.testing.expectEqualDeep(selection, retained.findById(2).?.widget.text_selection.?);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
test "runtime autofocus accepts a focusable virtual scroll-semantic container" {
|
|
828
|
+
const TestApp = struct {
|
|
829
|
+
fn app(self: *@This()) App {
|
|
830
|
+
return .{ .context = self, .name = "gpu-widget-autofocus-virtual-table", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
|
|
834
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
835
|
+
defer harness.destroy(std.testing.allocator);
|
|
836
|
+
harness.null_platform.gpu_surfaces = true;
|
|
837
|
+
var app_state: TestApp = .{};
|
|
838
|
+
try harness.start(app_state.app());
|
|
839
|
+
|
|
840
|
+
_ = try harness.runtime.createView(.{
|
|
841
|
+
.window_id = 1,
|
|
842
|
+
.label = "canvas",
|
|
843
|
+
.kind = .gpu_surface,
|
|
844
|
+
.frame = geometry.RectF.init(0, 0, 240, 80),
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
const children = [_]canvas.Widget{.{
|
|
848
|
+
.id = 2,
|
|
849
|
+
.kind = .table,
|
|
850
|
+
.frame = geometry.RectF.init(0, 96, 0, 80),
|
|
851
|
+
.autofocus = true,
|
|
852
|
+
.layout = .{
|
|
853
|
+
.virtualized = true,
|
|
854
|
+
.virtual_item_count = 20,
|
|
855
|
+
.virtual_item_extent = 24,
|
|
856
|
+
},
|
|
857
|
+
.semantics = .{ .label = "Virtual results" },
|
|
858
|
+
}};
|
|
859
|
+
const root_children = [_]canvas.Widget{.{
|
|
860
|
+
.id = 1,
|
|
861
|
+
.kind = .scroll_view,
|
|
862
|
+
.frame = geometry.RectF.init(0, 0, 240, 80),
|
|
863
|
+
.children = &children,
|
|
864
|
+
}};
|
|
865
|
+
var nodes: [3]canvas.WidgetLayoutNode = undefined;
|
|
866
|
+
const layout = try canvas.layoutWidgetTree(
|
|
867
|
+
.{ .id = 10, .kind = .card, .layout = .{ .clip_content = true }, .children = &root_children },
|
|
868
|
+
geometry.RectF.init(0, 0, 240, 80),
|
|
869
|
+
&nodes,
|
|
870
|
+
);
|
|
871
|
+
try std.testing.expect(!canvas.widgetIsFocusable(layout.nodes[2].widget));
|
|
872
|
+
try std.testing.expect(layout.focusTargetById(2) == null);
|
|
873
|
+
try std.testing.expect(layout.logicalFocusTargetAtIndex(2) != null);
|
|
874
|
+
|
|
875
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
876
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
877
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
878
|
+
try std.testing.expect(retained.findById(1).?.widget.value > 0);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
test "failed automation focus reveal preserves ancestor scroll and prior focus" {
|
|
882
|
+
const TestApp = struct {
|
|
883
|
+
fn app(self: *@This()) App {
|
|
884
|
+
return .{ .context = self, .name = "gpu-widget-focus-fixed-clip", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
889
|
+
defer harness.destroy(std.testing.allocator);
|
|
890
|
+
harness.null_platform.gpu_surfaces = true;
|
|
891
|
+
var app_state: TestApp = .{};
|
|
892
|
+
const app = app_state.app();
|
|
893
|
+
try harness.start(app);
|
|
894
|
+
|
|
895
|
+
_ = try harness.runtime.createView(.{
|
|
896
|
+
.window_id = 1,
|
|
897
|
+
.label = "canvas",
|
|
898
|
+
.kind = .gpu_surface,
|
|
899
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
900
|
+
});
|
|
901
|
+
|
|
902
|
+
const clipped_target = [_]canvas.Widget{.{
|
|
903
|
+
.id = 4,
|
|
904
|
+
.kind = .button,
|
|
905
|
+
.frame = geometry.RectF.init(0, 0, 0, 24),
|
|
906
|
+
.text = "Hidden action",
|
|
907
|
+
}};
|
|
908
|
+
const children = [_]canvas.Widget{
|
|
909
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 0, 32), .text = "Standing focus" },
|
|
910
|
+
.{ .kind = .text, .frame = geometry.RectF.init(0, 0, 0, 64), .text = "Spacer" },
|
|
911
|
+
.{
|
|
912
|
+
.id = 3,
|
|
913
|
+
.kind = .card,
|
|
914
|
+
.frame = geometry.RectF.init(0, 0, 0, 32),
|
|
915
|
+
.layout = .{ .clip_content = true, .padding = .{ .top = 40 } },
|
|
916
|
+
.children = &clipped_target,
|
|
917
|
+
},
|
|
918
|
+
};
|
|
919
|
+
var nodes: [5]canvas.WidgetLayoutNode = undefined;
|
|
920
|
+
const layout = try canvas.layoutWidgetTree(
|
|
921
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
922
|
+
geometry.RectF.init(0, 0, 180, 64),
|
|
923
|
+
&nodes,
|
|
924
|
+
);
|
|
925
|
+
try std.testing.expect(layout.focusTargetById(4) == null);
|
|
926
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
927
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .focus });
|
|
928
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
929
|
+
|
|
930
|
+
try std.testing.expectError(
|
|
931
|
+
error.InvalidCommand,
|
|
932
|
+
harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 4, .action = .focus }),
|
|
933
|
+
);
|
|
934
|
+
|
|
935
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
936
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
|
|
937
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
test "automation focus reveals an offscreen field and its end caret" {
|
|
941
|
+
const TestApp = struct {
|
|
942
|
+
scroll_event_count: u32 = 0,
|
|
943
|
+
last_scroll_id: canvas.ObjectId = 0,
|
|
944
|
+
last_scroll: canvas.ScrollState = .{},
|
|
945
|
+
|
|
946
|
+
fn app(self: *@This()) App {
|
|
947
|
+
return .{ .context = self, .name = "gpu-widget-automation-focus-reveal", .source = platform.WebViewSource.html("<h1>Hello</h1>"), .event_fn = event };
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
951
|
+
_ = runtime;
|
|
952
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
953
|
+
switch (event_value) {
|
|
954
|
+
.canvas_widget_scroll => |scroll_event| {
|
|
955
|
+
self.scroll_event_count += 1;
|
|
956
|
+
self.last_scroll_id = scroll_event.id;
|
|
957
|
+
self.last_scroll = scroll_event.scroll;
|
|
958
|
+
},
|
|
959
|
+
else => {},
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
965
|
+
defer harness.destroy(std.testing.allocator);
|
|
966
|
+
harness.null_platform.gpu_surfaces = true;
|
|
967
|
+
var app_state: TestApp = .{};
|
|
968
|
+
const app = app_state.app();
|
|
969
|
+
try harness.start(app);
|
|
970
|
+
|
|
971
|
+
_ = try harness.runtime.createView(.{
|
|
972
|
+
.window_id = 1,
|
|
973
|
+
.label = "canvas",
|
|
974
|
+
.kind = .gpu_surface,
|
|
975
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
976
|
+
});
|
|
977
|
+
|
|
978
|
+
const text = "This field is deliberately much wider than its viewport";
|
|
979
|
+
const children = [_]canvas.Widget{.{
|
|
980
|
+
.id = 2,
|
|
981
|
+
.kind = .text_field,
|
|
982
|
+
.frame = geometry.RectF.init(0, 96, 96, 32),
|
|
983
|
+
.text = text,
|
|
984
|
+
}};
|
|
985
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
986
|
+
const layout = try canvas.layoutWidgetTree(
|
|
987
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
988
|
+
geometry.RectF.init(0, 0, 180, 64),
|
|
989
|
+
&nodes,
|
|
990
|
+
);
|
|
991
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
992
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focused_id);
|
|
993
|
+
|
|
994
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .focus });
|
|
995
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.scroll_event_count);
|
|
996
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), app_state.last_scroll_id);
|
|
997
|
+
try std.testing.expect(app_state.last_scroll.offset_y > 0);
|
|
998
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.views[0].widget_scroll_event_count);
|
|
999
|
+
|
|
1000
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1001
|
+
const scroll = retained.findById(1).?;
|
|
1002
|
+
const field = retained.findById(2).?;
|
|
1003
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1004
|
+
try std.testing.expect(scroll.widget.value > 0);
|
|
1005
|
+
try std.testing.expect(field.frame.y >= scroll.frame.y);
|
|
1006
|
+
try std.testing.expect(field.frame.maxY() <= scroll.frame.maxY());
|
|
1007
|
+
try std.testing.expectEqualDeep(canvas.TextSelection.collapsed(text.len), field.widget.text_selection.?);
|
|
1008
|
+
try std.testing.expect(field.widget.value > 0);
|
|
1009
|
+
|
|
1010
|
+
const field_viewport = canvas.textInputViewportForWidget(field.widget, harness.runtime.views[0].widget_tokens).?;
|
|
1011
|
+
const text_geometry = try harness.runtime.canvasWidgetTextGeometry(1, "canvas", 2);
|
|
1012
|
+
const caret = text_geometry.caret_bounds.?;
|
|
1013
|
+
try std.testing.expect(caret.x >= field_viewport.x - 0.001);
|
|
1014
|
+
try std.testing.expect(caret.maxX() <= field_viewport.maxX() + 0.001);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
test "failed view focus leaves automation reveal scroll untouched" {
|
|
1018
|
+
const TestApp = struct {
|
|
1019
|
+
fn app(self: *@This()) App {
|
|
1020
|
+
return .{ .context = self, .name = "gpu-widget-focus-reveal-rollback", .source = platform.WebViewSource.html("<h1>Hello</h1>") };
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
|
|
1024
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1025
|
+
defer harness.destroy(std.testing.allocator);
|
|
1026
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1027
|
+
var app_state: TestApp = .{};
|
|
1028
|
+
const app = app_state.app();
|
|
1029
|
+
try harness.start(app);
|
|
1030
|
+
|
|
1031
|
+
_ = try harness.runtime.createView(.{
|
|
1032
|
+
.window_id = 1,
|
|
1033
|
+
.label = "canvas",
|
|
1034
|
+
.kind = .gpu_surface,
|
|
1035
|
+
.frame = geometry.RectF.init(0, 0, 180, 64),
|
|
1036
|
+
.visible = false,
|
|
1037
|
+
});
|
|
1038
|
+
|
|
1039
|
+
const children = [_]canvas.Widget{.{
|
|
1040
|
+
.id = 2,
|
|
1041
|
+
.kind = .button,
|
|
1042
|
+
.frame = geometry.RectF.init(0, 96, 96, 32),
|
|
1043
|
+
.text = "Hidden view action",
|
|
1044
|
+
}};
|
|
1045
|
+
var nodes: [2]canvas.WidgetLayoutNode = undefined;
|
|
1046
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1047
|
+
.{ .id = 1, .kind = .scroll_view, .children = &children },
|
|
1048
|
+
geometry.RectF.init(0, 0, 180, 64),
|
|
1049
|
+
&nodes,
|
|
1050
|
+
);
|
|
1051
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1052
|
+
const before = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1053
|
+
const target_frame = before.findById(2).?.frame;
|
|
1054
|
+
|
|
1055
|
+
try std.testing.expectError(
|
|
1056
|
+
error.UnsupportedViewFocus,
|
|
1057
|
+
harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = 2, .action = .focus }),
|
|
1058
|
+
);
|
|
1059
|
+
|
|
1060
|
+
const retained = try harness.runtime.canvasWidgetLayout(1, "canvas");
|
|
1061
|
+
try std.testing.expectEqual(@as(f32, 0), retained.findById(1).?.widget.value);
|
|
1062
|
+
try std.testing.expectEqualDeep(target_frame, retained.findById(2).?.frame);
|
|
1063
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1064
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.views[0].widget_scroll_event_count);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
733
1067
|
test "runtime keeps programmatic focus quiet on buttons and rings editables" {
|
|
734
1068
|
const TestApp = struct {
|
|
735
1069
|
fn app(self: *@This()) App {
|