@native-sdk/cli 0.5.0 → 0.5.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 +198 -13
- package/build/ts_run.mjs +58 -19
- package/build.zig +42 -0
- package/package.json +13 -9
- package/packages/core/package-lock.json +4 -3
- package/packages/core/package.json +3 -2
- package/packages/core/src/typed_ast.ts +11 -1
- package/skill-data/native-ui/SKILL.md +2 -2
- package/src/platform/types.zig +9 -0
- package/src/platform/windows/webview2_host.cpp +24 -0
- package/src/primitives/canvas/layout_audit.zig +5 -5
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tokens.zig +185 -7
- package/src/primitives/canvas/ui.zig +27 -5
- package/src/primitives/canvas/ui_markup.zig +27 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +127 -0
- package/src/primitives/canvas/ui_markup_tests.zig +47 -0
- package/src/primitives/canvas/ui_markup_view.zig +10 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +78 -0
- package/src/primitives/canvas/ui_schema.zig +15 -1
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_builtin_tests.zig +439 -5
- package/src/primitives/canvas/widget_layout.zig +142 -3
- package/src/primitives/canvas/widget_layout_tests.zig +82 -0
- package/src/primitives/canvas/widget_metrics.zig +16 -8
- package/src/primitives/canvas/widget_tree.zig +14 -2
- package/src/primitives/canvas/widgets.zig +12 -0
- package/src/runtime/automation_widget_dispatch.zig +95 -28
- package/src/runtime/canvas_frame.zig +15 -0
- package/src/runtime/canvas_widget_anchored_tests.zig +253 -65
- package/src/runtime/canvas_widget_context_menu.zig +3 -2
- package/src/runtime/canvas_widget_events.zig +1271 -3
- package/src/runtime/canvas_widget_floating_tests.zig +2801 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +1 -1
- package/src/runtime/canvas_widget_state.zig +82 -5
- package/src/runtime/core.zig +30 -0
- package/src/runtime/effects.zig +1037 -133
- package/src/runtime/effects_fetch_tests.zig +42 -0
- package/src/runtime/effects_file_tests.zig +220 -0
- package/src/runtime/effects_tests.zig +287 -0
- package/src/runtime/flow.zig +24 -1
- package/src/runtime/gpu_surface_events.zig +44 -5
- package/src/runtime/session_journal.zig +25 -13
- package/src/runtime/session_record.zig +166 -0
- package/src/runtime/session_tests.zig +453 -0
- package/src/runtime/ui_app.zig +137 -39
- package/src/runtime/ui_app_tests.zig +681 -0
- package/src/runtime/ui_app_window_tests.zig +182 -0
- package/src/runtime/view.zig +86 -0
- package/src/runtime/view_widget_text.zig +18 -1
- package/src/runtime/view_widget_tree.zig +339 -20
- package/src/runtime/widget_bridge.zig +26 -0
- package/src/runtime/window_storage.zig +61 -15
- package/src/runtime/window_view_runtime.zig +13 -0
- package/src/runtime/window_views.zig +6 -0
- package/src/tooling/package.zig +311 -8
- package/src/tooling/templates.zig +97 -9
- package/src/tooling/ts_core.zig +626 -13
- package/src/tooling/verbs.zig +88 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const support = @import("test_support.zig");
|
|
2
|
+
const canvas_limits = @import("canvas_limits.zig");
|
|
3
|
+
const max_canvas_widget_anchored_per_view = canvas_limits.max_canvas_widget_anchored_per_view;
|
|
2
4
|
const std = support.std;
|
|
3
5
|
const geometry = support.geometry;
|
|
4
6
|
const trace = support.trace;
|
|
@@ -693,3 +695,2802 @@ test "runtime clears canvas widget interaction state when layout replacement dis
|
|
|
693
695
|
try std.testing.expect(!snapshot.widgets[0].hovered);
|
|
694
696
|
try std.testing.expect(!snapshot.widgets[0].pressed);
|
|
695
697
|
}
|
|
698
|
+
|
|
699
|
+
// -------------------------------------------- anchored-tooltip hover intent
|
|
700
|
+
//
|
|
701
|
+
// Anchored tooltips are RUNTIME-owned presentation chrome: the model never
|
|
702
|
+
// hears hover, and visibility steps only on journaled input timestamps and
|
|
703
|
+
// presented-frame timestamps (never a wall clock), so every scenario below
|
|
704
|
+
// is also a replay-determinism statement.
|
|
705
|
+
|
|
706
|
+
const TooltipMsg = union(enum) { pressed };
|
|
707
|
+
const TooltipUi = canvas.Ui(TooltipMsg);
|
|
708
|
+
|
|
709
|
+
/// Three toolbar triggers, each owning an anchored tooltip through the
|
|
710
|
+
/// stack-wraps-trigger-plus-surface pattern the dropdown uses. The third
|
|
711
|
+
/// declares `tooltip_delay = 0` (markup `tooltip-delay="0"`), the
|
|
712
|
+
/// instant-show escape hatch.
|
|
713
|
+
fn buildTooltipToolbar(ui: *TooltipUi) TooltipUi.Node {
|
|
714
|
+
return ui.row(.{ .gap = 12, .padding = 16 }, .{
|
|
715
|
+
ui.el(.stack, .{}, .{
|
|
716
|
+
ui.button(.{}, "Bold"),
|
|
717
|
+
ui.el(.tooltip, .{ .text = "Bold the selection", .anchor = .above }, .{}),
|
|
718
|
+
}),
|
|
719
|
+
ui.el(.stack, .{}, .{
|
|
720
|
+
ui.button(.{}, "Italic"),
|
|
721
|
+
ui.el(.tooltip, .{ .text = "Italicize the selection", .anchor = .above }, .{}),
|
|
722
|
+
}),
|
|
723
|
+
ui.el(.stack, .{}, .{
|
|
724
|
+
ui.button(.{}, "Link"),
|
|
725
|
+
ui.el(.tooltip, .{ .text = "Insert a link", .anchor = .above, .tooltip_delay = 0 }, .{}),
|
|
726
|
+
}),
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
const TooltipToolbar = struct {
|
|
731
|
+
button_ids: [3]canvas.ObjectId,
|
|
732
|
+
button_centers: [3]geometry.PointF,
|
|
733
|
+
tooltip_ids: [3]canvas.ObjectId,
|
|
734
|
+
};
|
|
735
|
+
|
|
736
|
+
fn installTooltipToolbar(harness: anytype, app: App, arena: std.mem.Allocator) !TooltipToolbar {
|
|
737
|
+
harness.null_platform.gpu_surfaces = true;
|
|
738
|
+
try harness.start(app);
|
|
739
|
+
_ = try harness.runtime.createView(.{
|
|
740
|
+
.window_id = 1,
|
|
741
|
+
.label = "canvas",
|
|
742
|
+
.kind = .gpu_surface,
|
|
743
|
+
.frame = geometry.RectF.init(0, 0, 420, 160),
|
|
744
|
+
});
|
|
745
|
+
var ui = TooltipUi.init(arena);
|
|
746
|
+
const tree = try ui.finalize(buildTooltipToolbar(&ui));
|
|
747
|
+
var nodes: [16]canvas.WidgetLayoutNode = undefined;
|
|
748
|
+
const layout = try canvas.layoutWidgetTree(tree.root, geometry.RectF.init(0, 0, 420, 160), &nodes);
|
|
749
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
750
|
+
|
|
751
|
+
var toolbar: TooltipToolbar = .{ .button_ids = @splat(0), .button_centers = @splat(geometry.PointF.zero()), .tooltip_ids = @splat(0) };
|
|
752
|
+
var button_count: usize = 0;
|
|
753
|
+
var tooltip_count: usize = 0;
|
|
754
|
+
const view = &harness.runtime.views[0];
|
|
755
|
+
for (view.widget_layout_nodes[0..view.widget_layout_node_count]) |node| {
|
|
756
|
+
switch (node.widget.kind) {
|
|
757
|
+
.button => {
|
|
758
|
+
toolbar.button_ids[button_count] = node.widget.id;
|
|
759
|
+
toolbar.button_centers[button_count] = node.frame.center();
|
|
760
|
+
button_count += 1;
|
|
761
|
+
},
|
|
762
|
+
.tooltip => {
|
|
763
|
+
toolbar.tooltip_ids[tooltip_count] = node.widget.id;
|
|
764
|
+
tooltip_count += 1;
|
|
765
|
+
},
|
|
766
|
+
else => {},
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
try std.testing.expectEqual(@as(usize, 3), button_count);
|
|
770
|
+
try std.testing.expectEqual(@as(usize, 3), tooltip_count);
|
|
771
|
+
return toolbar;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
fn tooltipHover(harness: anytype, app: App, point: geometry.PointF, timestamp_ns: u64) !void {
|
|
775
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
776
|
+
.window_id = 1,
|
|
777
|
+
.label = "canvas",
|
|
778
|
+
.kind = .pointer_move,
|
|
779
|
+
.x = point.x,
|
|
780
|
+
.y = point.y,
|
|
781
|
+
.timestamp_ns = timestamp_ns,
|
|
782
|
+
} });
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
fn tooltipFrame(harness: anytype, app: App, timestamp_ns: u64) !void {
|
|
786
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
787
|
+
.window_id = 1,
|
|
788
|
+
.label = "canvas",
|
|
789
|
+
.size = geometry.SizeF.init(420, 160),
|
|
790
|
+
.timestamp_ns = timestamp_ns,
|
|
791
|
+
} });
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
fn tooltipHidden(harness: anytype, tooltip_id: canvas.ObjectId) !bool {
|
|
795
|
+
const view = &harness.runtime.views[0];
|
|
796
|
+
const node_index = view.canvasWidgetNodeIndexById(tooltip_id) orelse return error.TestUnexpectedResult;
|
|
797
|
+
return view.widget_layout_nodes[node_index].widget.semantics.hidden;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const tooltip_t0: u64 = 10_000_000_000;
|
|
801
|
+
const tooltip_ms: u64 = std.time.ns_per_ms;
|
|
802
|
+
|
|
803
|
+
test "sweeping across tooltip triggers shows nothing" {
|
|
804
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
805
|
+
defer harness.destroy(std.testing.allocator);
|
|
806
|
+
const TestApp = struct {
|
|
807
|
+
fn app(self: *@This()) App {
|
|
808
|
+
return .{ .context = self, .name = "gpu-tooltip-sweep", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
var app_state: TestApp = .{};
|
|
812
|
+
const app = app_state.app();
|
|
813
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
814
|
+
defer arena.deinit();
|
|
815
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
816
|
+
|
|
817
|
+
// Anchored tooltips adopt hidden: nothing is shown before any hover.
|
|
818
|
+
for (toolbar.tooltip_ids[0..2]) |tooltip_id| {
|
|
819
|
+
try std.testing.expect(try tooltipHidden(harness, tooltip_id));
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// The pointer crosses Bold and Italic 80ms apart — well under the
|
|
823
|
+
// 600ms intent delay — with a presented frame after each move. No
|
|
824
|
+
// tooltip frame paints anywhere along the sweep.
|
|
825
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
826
|
+
try tooltipFrame(harness, app, tooltip_t0 + 16 * tooltip_ms);
|
|
827
|
+
try tooltipHover(harness, app, toolbar.button_centers[1], tooltip_t0 + 80 * tooltip_ms);
|
|
828
|
+
try tooltipFrame(harness, app, tooltip_t0 + 96 * tooltip_ms);
|
|
829
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 160 * tooltip_ms);
|
|
830
|
+
try tooltipFrame(harness, app, tooltip_t0 + 176 * tooltip_ms);
|
|
831
|
+
|
|
832
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
833
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
834
|
+
for (toolbar.tooltip_ids[0..2]) |tooltip_id| {
|
|
835
|
+
try std.testing.expect(try tooltipHidden(harness, tooltip_id));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
test "hover dwell past the delay shows the anchored tooltip on the frame clock" {
|
|
840
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
841
|
+
defer harness.destroy(std.testing.allocator);
|
|
842
|
+
const TestApp = struct {
|
|
843
|
+
fn app(self: *@This()) App {
|
|
844
|
+
return .{ .context = self, .name = "gpu-tooltip-dwell", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
var app_state: TestApp = .{};
|
|
848
|
+
const app = app_state.app();
|
|
849
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
850
|
+
defer arena.deinit();
|
|
851
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
852
|
+
|
|
853
|
+
// Hover arms the delay; frames keep painting while it runs (the
|
|
854
|
+
// pump), but the tooltip stays hidden short of the deadline.
|
|
855
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
856
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
857
|
+
try tooltipFrame(harness, app, tooltip_t0 + 100 * tooltip_ms);
|
|
858
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
859
|
+
|
|
860
|
+
// An armed delay keeps the frame channel alive so the deadline can
|
|
861
|
+
// fire without any further input.
|
|
862
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
863
|
+
|
|
864
|
+
// The first presented frame at/past the deadline shows the tooltip —
|
|
865
|
+
// a deterministic frame on the recorded clock.
|
|
866
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
867
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
868
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
869
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
870
|
+
|
|
871
|
+
// Leaving the trigger hides it again.
|
|
872
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 900 * tooltip_ms);
|
|
873
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
874
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
test "leaving the trigger before the delay disarms the tooltip" {
|
|
878
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
879
|
+
defer harness.destroy(std.testing.allocator);
|
|
880
|
+
const TestApp = struct {
|
|
881
|
+
fn app(self: *@This()) App {
|
|
882
|
+
return .{ .context = self, .name = "gpu-tooltip-disarm", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
var app_state: TestApp = .{};
|
|
886
|
+
const app = app_state.app();
|
|
887
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
888
|
+
defer arena.deinit();
|
|
889
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
890
|
+
|
|
891
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
892
|
+
try tooltipFrame(harness, app, tooltip_t0 + 300 * tooltip_ms);
|
|
893
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
894
|
+
|
|
895
|
+
// Off the trigger before the deadline: disarmed for good — frames
|
|
896
|
+
// past the would-be deadline change nothing.
|
|
897
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 400 * tooltip_ms);
|
|
898
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
899
|
+
try tooltipFrame(harness, app, tooltip_t0 + 800 * tooltip_ms);
|
|
900
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
901
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
test "the warm window transfers instantly between triggers and expires" {
|
|
905
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
906
|
+
defer harness.destroy(std.testing.allocator);
|
|
907
|
+
const TestApp = struct {
|
|
908
|
+
fn app(self: *@This()) App {
|
|
909
|
+
return .{ .context = self, .name = "gpu-tooltip-warm", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
var app_state: TestApp = .{};
|
|
913
|
+
const app = app_state.app();
|
|
914
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
915
|
+
defer arena.deinit();
|
|
916
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
917
|
+
|
|
918
|
+
// Earn the first tooltip with a full dwell.
|
|
919
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
920
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
921
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
922
|
+
|
|
923
|
+
// Move to the sibling inside the warm window: Bold's tooltip hides
|
|
924
|
+
// and Italic's shows IMMEDIATELY — no delay, no frame needed.
|
|
925
|
+
try tooltipHover(harness, app, toolbar.button_centers[1], tooltip_t0 + 900 * tooltip_ms);
|
|
926
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
927
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
928
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
929
|
+
|
|
930
|
+
// Leaving re-warms; a return WITHIN the window is instant again.
|
|
931
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 1000 * tooltip_ms);
|
|
932
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
933
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 1200 * tooltip_ms);
|
|
934
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
935
|
+
|
|
936
|
+
// Leave and let the warm window LAPSE: the next trigger waits the
|
|
937
|
+
// full delay again.
|
|
938
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 1300 * tooltip_ms);
|
|
939
|
+
try tooltipHover(harness, app, toolbar.button_centers[1], tooltip_t0 + 2000 * tooltip_ms);
|
|
940
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
941
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
942
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2700 * tooltip_ms);
|
|
943
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
test "tooltip-delay zero restores the instant hover show" {
|
|
947
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
948
|
+
defer harness.destroy(std.testing.allocator);
|
|
949
|
+
const TestApp = struct {
|
|
950
|
+
fn app(self: *@This()) App {
|
|
951
|
+
return .{ .context = self, .name = "gpu-tooltip-instant", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
var app_state: TestApp = .{};
|
|
955
|
+
const app = app_state.app();
|
|
956
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
957
|
+
defer arena.deinit();
|
|
958
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
959
|
+
|
|
960
|
+
// Link declares tooltip_delay = 0: the hover event itself shows the
|
|
961
|
+
// tooltip, no dwell, no warm window, no frame in between.
|
|
962
|
+
try tooltipHover(harness, app, toolbar.button_centers[2], tooltip_t0);
|
|
963
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
964
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
965
|
+
|
|
966
|
+
// And leaving hides it just as immediately.
|
|
967
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 50 * tooltip_ms);
|
|
968
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
969
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
fn tooltipNodeFrame(harness: anytype, widget_id: canvas.ObjectId) !geometry.RectF {
|
|
973
|
+
const view = &harness.runtime.views[0];
|
|
974
|
+
const node_index = view.canvasWidgetNodeIndexById(widget_id) orelse return error.TestUnexpectedResult;
|
|
975
|
+
return view.widget_layout_nodes[node_index].frame;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
test "pointer travels into hoverable tooltip content and it stays open until leaving both" {
|
|
979
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
980
|
+
defer harness.destroy(std.testing.allocator);
|
|
981
|
+
const TestApp = struct {
|
|
982
|
+
fn app(self: *@This()) App {
|
|
983
|
+
return .{ .context = self, .name = "gpu-tooltip-hoverable", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
var app_state: TestApp = .{};
|
|
987
|
+
const app = app_state.app();
|
|
988
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
989
|
+
defer arena.deinit();
|
|
990
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
991
|
+
|
|
992
|
+
// Earn Bold's tooltip with a full dwell.
|
|
993
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
994
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
995
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
996
|
+
|
|
997
|
+
// The anchored tooltip floats ABOVE the trigger with a gap between
|
|
998
|
+
// them; crossing that gap (a point between the tooltip's bottom
|
|
999
|
+
// edge and the trigger's top edge, inside the transit corridor)
|
|
1000
|
+
// must not hide it — WCAG 1.4.13 wants hover-revealed content
|
|
1001
|
+
// reachable by pointer, and Base UI tooltips default `hoverable`.
|
|
1002
|
+
const tooltip_frame = try tooltipNodeFrame(harness, toolbar.tooltip_ids[0]);
|
|
1003
|
+
const trigger_frame = try tooltipNodeFrame(harness, toolbar.button_ids[0]);
|
|
1004
|
+
try std.testing.expect(tooltip_frame.maxY() < trigger_frame.y);
|
|
1005
|
+
const gap_point = geometry.PointF{
|
|
1006
|
+
.x = toolbar.button_centers[0].x,
|
|
1007
|
+
.y = (tooltip_frame.maxY() + trigger_frame.y) / 2,
|
|
1008
|
+
};
|
|
1009
|
+
try tooltipHover(harness, app, gap_point, tooltip_t0 + 700 * tooltip_ms);
|
|
1010
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1011
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1012
|
+
|
|
1013
|
+
// Frames inside the transit bound change nothing.
|
|
1014
|
+
try tooltipFrame(harness, app, tooltip_t0 + 800 * tooltip_ms);
|
|
1015
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1016
|
+
|
|
1017
|
+
// Arriving inside the tooltip's own frame holds it open outright
|
|
1018
|
+
// (the tooltip stays out of hit-testing; the hold is the intent
|
|
1019
|
+
// machine's geometric test), and gliding within it stays free.
|
|
1020
|
+
try tooltipHover(harness, app, tooltip_frame.center(), tooltip_t0 + 850 * tooltip_ms);
|
|
1021
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1022
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_transit_deadline_ns);
|
|
1023
|
+
try tooltipHover(harness, app, .{ .x = tooltip_frame.center().x + 4, .y = tooltip_frame.center().y }, tooltip_t0 + 2000 * tooltip_ms);
|
|
1024
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1025
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1026
|
+
|
|
1027
|
+
// Leaving BOTH regions (away from the corridor) hides on the move
|
|
1028
|
+
// itself, with the usual pointer-hide warm window: the neighboring
|
|
1029
|
+
// trigger explains itself instantly.
|
|
1030
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 2100 * tooltip_ms);
|
|
1031
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1032
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1033
|
+
try tooltipHover(harness, app, toolbar.button_centers[1], tooltip_t0 + 2200 * tooltip_ms);
|
|
1034
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
test "a pointer parked in the anchor gap resolves the transit on the frame clock" {
|
|
1038
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1039
|
+
defer harness.destroy(std.testing.allocator);
|
|
1040
|
+
const TestApp = struct {
|
|
1041
|
+
fn app(self: *@This()) App {
|
|
1042
|
+
return .{ .context = self, .name = "gpu-tooltip-transit", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1043
|
+
}
|
|
1044
|
+
};
|
|
1045
|
+
var app_state: TestApp = .{};
|
|
1046
|
+
const app = app_state.app();
|
|
1047
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1048
|
+
defer arena.deinit();
|
|
1049
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1050
|
+
|
|
1051
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
1052
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
1053
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1054
|
+
|
|
1055
|
+
const tooltip_frame = try tooltipNodeFrame(harness, toolbar.tooltip_ids[0]);
|
|
1056
|
+
const trigger_frame = try tooltipNodeFrame(harness, toolbar.button_ids[0]);
|
|
1057
|
+
const gap_point = geometry.PointF{
|
|
1058
|
+
.x = toolbar.button_centers[0].x,
|
|
1059
|
+
.y = (tooltip_frame.maxY() + trigger_frame.y) / 2,
|
|
1060
|
+
};
|
|
1061
|
+
try tooltipHover(harness, app, gap_point, tooltip_t0 + 700 * tooltip_ms);
|
|
1062
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1063
|
+
|
|
1064
|
+
// The transit is BOUNDED: it holds while frames stay inside the
|
|
1065
|
+
// grace, keeps the frame channel pumping so the deadline can fire
|
|
1066
|
+
// without further input, and a pointer that parks in the gap
|
|
1067
|
+
// resolves on the recorded frame clock — hidden, with the usual
|
|
1068
|
+
// pointer-hide warm window (replay hits the same frame).
|
|
1069
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_transit_deadline_ns != 0);
|
|
1070
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1071
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1000 * tooltip_ms);
|
|
1072
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1073
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1101 * tooltip_ms);
|
|
1074
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1075
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1076
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
test "a collinear apex holds only the corridor's segment, never the infinite line" {
|
|
1080
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1081
|
+
defer harness.destroy(std.testing.allocator);
|
|
1082
|
+
const TestApp = struct {
|
|
1083
|
+
fn app(self: *@This()) App {
|
|
1084
|
+
return .{ .context = self, .name = "gpu-tooltip-degenerate", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
var app_state: TestApp = .{};
|
|
1088
|
+
const app = app_state.app();
|
|
1089
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1090
|
+
defer arena.deinit();
|
|
1091
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1092
|
+
|
|
1093
|
+
// Earn Bold's tooltip with a full dwell, then park the pointer ON
|
|
1094
|
+
// the trigger's top edge: still the owner (top edge is inclusive),
|
|
1095
|
+
// so the corridor apex re-seeds EXACTLY collinear with that edge —
|
|
1096
|
+
// the degenerate-fan setup, since the apex-to-adjacent-corner
|
|
1097
|
+
// triangle over the trigger's top edge now has zero area.
|
|
1098
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
1099
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
1100
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1101
|
+
const trigger_frame = try tooltipNodeFrame(harness, toolbar.button_ids[0]);
|
|
1102
|
+
const tooltip_frame = try tooltipNodeFrame(harness, toolbar.tooltip_ids[0]);
|
|
1103
|
+
const edge_apex = geometry.PointF{ .x = toolbar.button_centers[0].x, .y = trigger_frame.y };
|
|
1104
|
+
try tooltipHover(harness, app, edge_apex, tooltip_t0 + 700 * tooltip_ms);
|
|
1105
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1106
|
+
try std.testing.expectEqual(edge_apex.x, harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
1107
|
+
try std.testing.expectEqual(edge_apex.y, harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
1108
|
+
|
|
1109
|
+
// The NORMAL corridor still works from this apex: stepping into the
|
|
1110
|
+
// anchor gap keeps the tooltip up on the bounded grace, and a frame
|
|
1111
|
+
// inside the grace changes nothing.
|
|
1112
|
+
const gap_point = geometry.PointF{
|
|
1113
|
+
.x = toolbar.button_centers[0].x,
|
|
1114
|
+
.y = (tooltip_frame.maxY() + trigger_frame.y) / 2,
|
|
1115
|
+
};
|
|
1116
|
+
try tooltipHover(harness, app, gap_point, tooltip_t0 + 750 * tooltip_ms);
|
|
1117
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1118
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_transit_deadline_ns != 0);
|
|
1119
|
+
try tooltipFrame(harness, app, tooltip_t0 + 800 * tooltip_ms);
|
|
1120
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1121
|
+
|
|
1122
|
+
// Motion ALONG the apex's collinear line, beyond the trigger's
|
|
1123
|
+
// actual corners (into the row padding left of Bold): the collapsed
|
|
1124
|
+
// triangle contains only its boundary segment, so this is OUTSIDE
|
|
1125
|
+
// the corridor — the tooltip hides on the move itself with the
|
|
1126
|
+
// usual pointer-hide warmth instead of re-arming the grace forever
|
|
1127
|
+
// along the infinite line.
|
|
1128
|
+
try std.testing.expect(trigger_frame.x > 4);
|
|
1129
|
+
const along_line = geometry.PointF{ .x = 2, .y = trigger_frame.y };
|
|
1130
|
+
try tooltipHover(harness, app, along_line, tooltip_t0 + 850 * tooltip_ms);
|
|
1131
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1132
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1133
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
1134
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_transit_deadline_ns);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
test "pointer cancel dismisses the content-held tooltip immediately, focus-shown survives" {
|
|
1138
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1139
|
+
defer harness.destroy(std.testing.allocator);
|
|
1140
|
+
const TestApp = struct {
|
|
1141
|
+
fn app(self: *@This()) App {
|
|
1142
|
+
return .{ .context = self, .name = "gpu-tooltip-cancel-held", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
var app_state: TestApp = .{};
|
|
1146
|
+
const app = app_state.app();
|
|
1147
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1148
|
+
defer arena.deinit();
|
|
1149
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1150
|
+
|
|
1151
|
+
// Earn Bold's tooltip, then park the pointer INSIDE the tooltip's
|
|
1152
|
+
// own frame: the content hold — and, because the tooltip is not a
|
|
1153
|
+
// hit target, hovered_id is already 0 here, so a cancel-to-0 is no
|
|
1154
|
+
// hover transition and the transition gate alone cannot see it.
|
|
1155
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
1156
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
1157
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1158
|
+
const tooltip_frame = try tooltipNodeFrame(harness, toolbar.tooltip_ids[0]);
|
|
1159
|
+
try tooltipHover(harness, app, tooltip_frame.center(), tooltip_t0 + 700 * tooltip_ms);
|
|
1160
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1161
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1162
|
+
|
|
1163
|
+
// The pointer leaves the view: cancel's immediate-hide semantics
|
|
1164
|
+
// hold for the content-held tooltip too — hidden on the cancel
|
|
1165
|
+
// itself, warm window closed, stored position gone, and no frame
|
|
1166
|
+
// ever resurrects it.
|
|
1167
|
+
try tooltipPointer(harness, app, .pointer_cancel, tooltip_frame.center(), tooltip_t0 + 800 * tooltip_ms);
|
|
1168
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1169
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1170
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1171
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_transit_deadline_ns);
|
|
1172
|
+
try std.testing.expect(harness.runtime.views[0].canvas_last_pointer_position == null);
|
|
1173
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1500 * tooltip_ms);
|
|
1174
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1175
|
+
|
|
1176
|
+
// A FOCUS-shown tooltip survives a pointer cancel: the keyboard
|
|
1177
|
+
// holds it, and the pointer's departure says nothing about it —
|
|
1178
|
+
// unlike view blur, where the keyboard itself leaves.
|
|
1179
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1600 * tooltip_ms);
|
|
1180
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1181
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1182
|
+
try tooltipPointer(harness, app, .pointer_cancel, .{ .x = 5, .y = 150 }, tooltip_t0 + 1700 * tooltip_ms);
|
|
1183
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1184
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1185
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
/// A scrollable toolbar column: a scroll_view whose two stacks each
|
|
1189
|
+
/// wrap a trigger button and its anchored tooltip, viewport 40 points
|
|
1190
|
+
/// tall so a 40-point scroll swaps which trigger sits under a
|
|
1191
|
+
/// stationary pointer. Explicit ids; `first_delay_zero` opts the first
|
|
1192
|
+
/// tooltip into instant show for the tests that need a shown tooltip
|
|
1193
|
+
/// without a dwell.
|
|
1194
|
+
fn installTooltipScrollFixture(harness: anytype, app: App, first_delay_zero: bool) !void {
|
|
1195
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1196
|
+
try harness.start(app);
|
|
1197
|
+
_ = try harness.runtime.createView(.{
|
|
1198
|
+
.window_id = 1,
|
|
1199
|
+
.label = "canvas",
|
|
1200
|
+
.kind = .gpu_surface,
|
|
1201
|
+
.frame = geometry.RectF.init(0, 0, 160, 40),
|
|
1202
|
+
});
|
|
1203
|
+
const first_children = [_]canvas.Widget{
|
|
1204
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "One" },
|
|
1205
|
+
.{ .id = 5, .kind = .tooltip, .text = "First action", .tooltip_delay_ms = if (first_delay_zero) 0 else -1, .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1206
|
+
};
|
|
1207
|
+
const second_children = [_]canvas.Widget{
|
|
1208
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "Two" },
|
|
1209
|
+
.{ .id = 7, .kind = .tooltip, .text = "Second action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1210
|
+
};
|
|
1211
|
+
const stacks = [_]canvas.Widget{
|
|
1212
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 160, 32), .children = &first_children },
|
|
1213
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 48, 160, 32), .children = &second_children },
|
|
1214
|
+
};
|
|
1215
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1216
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1217
|
+
.{ .id = 1, .kind = .scroll_view, .children = &stacks },
|
|
1218
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
1219
|
+
&nodes,
|
|
1220
|
+
);
|
|
1221
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
fn tooltipScroll(harness: anytype, app: App, delta_y: f32, timestamp_ns: u64) !void {
|
|
1225
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1226
|
+
.window_id = 1,
|
|
1227
|
+
.label = "canvas",
|
|
1228
|
+
.kind = .scroll,
|
|
1229
|
+
.x = 12,
|
|
1230
|
+
.y = 12,
|
|
1231
|
+
.delta_y = delta_y,
|
|
1232
|
+
.timestamp_ns = timestamp_ns,
|
|
1233
|
+
} });
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
test "wheel scroll steps the tooltip intent machine like a pointer move" {
|
|
1237
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1238
|
+
defer harness.destroy(std.testing.allocator);
|
|
1239
|
+
const TestApp = struct {
|
|
1240
|
+
fn app(self: *@This()) App {
|
|
1241
|
+
return .{ .context = self, .name = "gpu-tooltip-scroll", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1242
|
+
}
|
|
1243
|
+
};
|
|
1244
|
+
var app_state: TestApp = .{};
|
|
1245
|
+
const app = app_state.app();
|
|
1246
|
+
try installTooltipScrollFixture(harness, app, false);
|
|
1247
|
+
|
|
1248
|
+
// Hover trigger One: its tooltip arms the default delay.
|
|
1249
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 12 }, tooltip_t0);
|
|
1250
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1251
|
+
|
|
1252
|
+
// Scrolling One out from under the stationary pointer disarms it,
|
|
1253
|
+
// and trigger Two arriving under the pointer arms per normal — the
|
|
1254
|
+
// same transition a real pointer move onto Two would step.
|
|
1255
|
+
try tooltipScroll(harness, app, 40, tooltip_t0 + 100 * tooltip_ms);
|
|
1256
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1257
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1258
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
1259
|
+
|
|
1260
|
+
// The scroll-armed dwell completes on the frame clock like any other.
|
|
1261
|
+
try tooltipFrame(harness, app, tooltip_t0 + 700 * tooltip_ms);
|
|
1262
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1263
|
+
try std.testing.expect(!try tooltipHidden(harness, 7));
|
|
1264
|
+
|
|
1265
|
+
// Scrolling back swaps triggers again: the SHOWN tooltip hides with
|
|
1266
|
+
// the usual warm window, so One's tooltip shows instantly.
|
|
1267
|
+
try tooltipScroll(harness, app, -40, tooltip_t0 + 800 * tooltip_ms);
|
|
1268
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1269
|
+
try std.testing.expect(try tooltipHidden(harness, 7));
|
|
1270
|
+
try std.testing.expect(!try tooltipHidden(harness, 5));
|
|
1271
|
+
|
|
1272
|
+
// A scroll that leaves the pointer over neither trigger (the
|
|
1273
|
+
// scroll view's own gap) hides the shown tooltip on the scroll
|
|
1274
|
+
// itself (point-blind semantics: the content moved, not the
|
|
1275
|
+
// pointer — no transit corridor applies).
|
|
1276
|
+
try tooltipScroll(harness, app, 24, tooltip_t0 + 900 * tooltip_ms);
|
|
1277
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1278
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1279
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
1280
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
test "keyboard scrolling re-hit-tests the stationary pointer against the post-scroll tree" {
|
|
1284
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1285
|
+
defer harness.destroy(std.testing.allocator);
|
|
1286
|
+
const TestApp = struct {
|
|
1287
|
+
fn app(self: *@This()) App {
|
|
1288
|
+
return .{ .context = self, .name = "gpu-tooltip-scroll-key", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
var app_state: TestApp = .{};
|
|
1292
|
+
const app = app_state.app();
|
|
1293
|
+
try installTooltipScrollFixture(harness, app, true);
|
|
1294
|
+
|
|
1295
|
+
// Focus the scroll view with a click on trigger-free space, then
|
|
1296
|
+
// earn One's tooltip (delay 0) with a hover; the click's press
|
|
1297
|
+
// reset already ran, so the hover re-earns cleanly.
|
|
1298
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 12, .y = 36 }, tooltip_t0);
|
|
1299
|
+
try tooltipPointer(harness, app, .pointer_up, .{ .x = 12, .y = 36 }, tooltip_t0 + 20 * tooltip_ms);
|
|
1300
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1301
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 12 }, tooltip_t0 + 50 * tooltip_ms);
|
|
1302
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1303
|
+
|
|
1304
|
+
// End scrolls the focused scroll view to its bottom. The keyboard
|
|
1305
|
+
// scroll carries no pointer position of its own, so the reconcile
|
|
1306
|
+
// re-hit-tests the STORED one (the pointer is stationary at 12,12):
|
|
1307
|
+
// trigger One scrolled out from under it — its tooltip hides with
|
|
1308
|
+
// the usual warm window — and trigger Two arrived under it, so the
|
|
1309
|
+
// warm window transfers the show exactly as a wheel scroll (or a
|
|
1310
|
+
// real pointer move) would. Kinetic steps and native drivers share
|
|
1311
|
+
// this exact reconcile.
|
|
1312
|
+
try tooltipKey(harness, app, "end", tooltip_t0 + 100 * tooltip_ms);
|
|
1313
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1314
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1315
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
1316
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
1317
|
+
try std.testing.expect(!try tooltipHidden(harness, 7));
|
|
1318
|
+
|
|
1319
|
+
// Home scrolls back to the top: Two leaves from under the pointer,
|
|
1320
|
+
// One returns beneath it, and the warm transfer swaps the shown
|
|
1321
|
+
// tooltip back — symmetric with the wheel path's sweep.
|
|
1322
|
+
try tooltipKey(harness, app, "home", tooltip_t0 + 200 * tooltip_ms);
|
|
1323
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1324
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1325
|
+
try std.testing.expect(try tooltipHidden(harness, 7));
|
|
1326
|
+
try std.testing.expect(!try tooltipHidden(harness, 5));
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
test "a keyboard scroll hides the shown tooltip whose trigger stays partially visible but slid off the pointer" {
|
|
1330
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1331
|
+
defer harness.destroy(std.testing.allocator);
|
|
1332
|
+
const TestApp = struct {
|
|
1333
|
+
fn app(self: *@This()) App {
|
|
1334
|
+
return .{ .context = self, .name = "gpu-tooltip-scroll-partial", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
var app_state: TestApp = .{};
|
|
1338
|
+
const app = app_state.app();
|
|
1339
|
+
// Tall triggers in a short viewport: a page scroll leaves One
|
|
1340
|
+
// PARTIALLY visible, the exact hole the old point-blind
|
|
1341
|
+
// reconciliation fell into — the trigger still existed in the
|
|
1342
|
+
// interactive tree, so hover ownership (and the shown tooltip)
|
|
1343
|
+
// was retained even though the stationary pointer no longer sat
|
|
1344
|
+
// on it.
|
|
1345
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1346
|
+
try harness.start(app);
|
|
1347
|
+
_ = try harness.runtime.createView(.{
|
|
1348
|
+
.window_id = 1,
|
|
1349
|
+
.label = "canvas",
|
|
1350
|
+
.kind = .gpu_surface,
|
|
1351
|
+
.frame = geometry.RectF.init(0, 0, 160, 40),
|
|
1352
|
+
});
|
|
1353
|
+
const first_children = [_]canvas.Widget{
|
|
1354
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 36), .text = "One" },
|
|
1355
|
+
.{ .id = 5, .kind = .tooltip, .text = "First action", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1356
|
+
};
|
|
1357
|
+
const second_children = [_]canvas.Widget{
|
|
1358
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 36), .text = "Two" },
|
|
1359
|
+
.{ .id = 7, .kind = .tooltip, .text = "Second action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1360
|
+
};
|
|
1361
|
+
const stacks = [_]canvas.Widget{
|
|
1362
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 8, 160, 36), .children = &first_children },
|
|
1363
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 78, 160, 36), .children = &second_children },
|
|
1364
|
+
};
|
|
1365
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1366
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1367
|
+
.{ .id = 1, .kind = .scroll_view, .children = &stacks },
|
|
1368
|
+
geometry.RectF.init(0, 0, 160, 40),
|
|
1369
|
+
&nodes,
|
|
1370
|
+
);
|
|
1371
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1372
|
+
|
|
1373
|
+
// Focus the scroll view via the gap above One, then earn One's
|
|
1374
|
+
// tooltip (delay 0) with the pointer parked at (12, 26).
|
|
1375
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 12, .y = 4 }, tooltip_t0);
|
|
1376
|
+
try tooltipPointer(harness, app, .pointer_up, .{ .x = 12, .y = 4 }, tooltip_t0 + 20 * tooltip_ms);
|
|
1377
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1378
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 26 }, tooltip_t0 + 50 * tooltip_ms);
|
|
1379
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1380
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1381
|
+
|
|
1382
|
+
// PageDown slides One up so it stays partially visible but ends
|
|
1383
|
+
// above the stationary pointer, which now sits in the gap between
|
|
1384
|
+
// the triggers: hover moves to the scroll view and the shown
|
|
1385
|
+
// tooltip hides — ownership follows the re-hit-test, not the
|
|
1386
|
+
// trigger's mere survival.
|
|
1387
|
+
try tooltipKey(harness, app, "pagedown", tooltip_t0 + 100 * tooltip_ms);
|
|
1388
|
+
try std.testing.expect(harness.runtime.views[0].canvasWidgetNodeIndexById(2) != null);
|
|
1389
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1390
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1391
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
1392
|
+
|
|
1393
|
+
// Let the pointer-hide warm window lapse, then PageDown again:
|
|
1394
|
+
// trigger Two scrolls UNDER the stored pointer position and arms
|
|
1395
|
+
// the normal delay — a fresh dwell, not a warm transfer.
|
|
1396
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
1397
|
+
try tooltipKey(harness, app, "pagedown", tooltip_t0 + 2100 * tooltip_ms);
|
|
1398
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1399
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1400
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
1401
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1402
|
+
// The corridor apex re-seeded to the stored position, so the
|
|
1403
|
+
// eventual leave fans out from where the pointer really is.
|
|
1404
|
+
try std.testing.expectEqual(@as(f32, 12), harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
1405
|
+
try std.testing.expectEqual(@as(f32, 26), harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
test "point-blind scrolls without a trustworthy pointer position close tooltip intent" {
|
|
1409
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1410
|
+
defer harness.destroy(std.testing.allocator);
|
|
1411
|
+
const TestApp = struct {
|
|
1412
|
+
fn app(self: *@This()) App {
|
|
1413
|
+
return .{ .context = self, .name = "gpu-tooltip-scroll-blind", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
var app_state: TestApp = .{};
|
|
1417
|
+
const app = app_state.app();
|
|
1418
|
+
try installTooltipScrollFixture(harness, app, true);
|
|
1419
|
+
|
|
1420
|
+
// The pointer LEAVES the view mid-conversation: earn One's tooltip,
|
|
1421
|
+
// then the exit's pointer_cancel closes the whole pointer-owned
|
|
1422
|
+
// conversation (shown tooltip AND warm window — no courtesy for a
|
|
1423
|
+
// pointer that left) and clears the stored position.
|
|
1424
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 12, .y = 36 }, tooltip_t0);
|
|
1425
|
+
try tooltipPointer(harness, app, .pointer_up, .{ .x = 12, .y = 36 }, tooltip_t0 + 20 * tooltip_ms);
|
|
1426
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 12 }, tooltip_t0 + 50 * tooltip_ms);
|
|
1427
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1428
|
+
try tooltipPointer(harness, app, .pointer_cancel, .{ .x = 12, .y = 12 }, tooltip_t0 + 100 * tooltip_ms);
|
|
1429
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1430
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1431
|
+
try std.testing.expect(harness.runtime.views[0].canvas_last_pointer_position == null);
|
|
1432
|
+
|
|
1433
|
+
// A keyboard scroll now has no position to re-hit-test: the
|
|
1434
|
+
// pointer's tooltip conversation CLOSES — the warm window included
|
|
1435
|
+
// (an instant re-show is earned by a pointer we cannot place) —
|
|
1436
|
+
// instead of guessing where the departed pointer might be. Seed a
|
|
1437
|
+
// smoldering warm window directly (cancel already closed the real
|
|
1438
|
+
// one) so the blind scroll's own close stays observable.
|
|
1439
|
+
harness.runtime.views[0].canvas_tooltip_warm_until_ns = tooltip_t0 + 5000 * tooltip_ms;
|
|
1440
|
+
try tooltipKey(harness, app, "end", tooltip_t0 + 200 * tooltip_ms);
|
|
1441
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1442
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1443
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1444
|
+
|
|
1445
|
+
// A KEYBOARD-ONLY session (no pointer event ever): the store was
|
|
1446
|
+
// never seeded, so a point-blind scroll closes whatever intent is
|
|
1447
|
+
// pending rather than inventing a hover. Seed an armed dwell
|
|
1448
|
+
// directly to make the close observable.
|
|
1449
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1450
|
+
.window_id = 1,
|
|
1451
|
+
.label = "canvas",
|
|
1452
|
+
.kind = .key_down,
|
|
1453
|
+
.key = "home",
|
|
1454
|
+
.timestamp_ns = tooltip_t0 + 300 * tooltip_ms,
|
|
1455
|
+
} });
|
|
1456
|
+
harness.runtime.views[0].canvas_last_pointer_position = null;
|
|
1457
|
+
harness.runtime.views[0].canvas_tooltip_armed_id = 5;
|
|
1458
|
+
harness.runtime.views[0].canvas_tooltip_armed_owner_id = 2;
|
|
1459
|
+
harness.runtime.views[0].canvas_tooltip_deadline_ns = tooltip_t0 + 1000 * tooltip_ms;
|
|
1460
|
+
try tooltipKey(harness, app, "end", tooltip_t0 + 400 * tooltip_ms);
|
|
1461
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1462
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
1463
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
fn tooltipKey(harness: anytype, app: App, key: []const u8, timestamp_ns: u64) !void {
|
|
1467
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1468
|
+
.window_id = 1,
|
|
1469
|
+
.label = "canvas",
|
|
1470
|
+
.kind = .key_down,
|
|
1471
|
+
.key = key,
|
|
1472
|
+
.timestamp_ns = timestamp_ns,
|
|
1473
|
+
} });
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
fn tooltipPointer(harness: anytype, app: App, kind: platform.GpuSurfaceInputKind, point: geometry.PointF, timestamp_ns: u64) !void {
|
|
1477
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1478
|
+
.window_id = 1,
|
|
1479
|
+
.label = "canvas",
|
|
1480
|
+
.kind = kind,
|
|
1481
|
+
.x = point.x,
|
|
1482
|
+
.y = point.y,
|
|
1483
|
+
.timestamp_ns = timestamp_ns,
|
|
1484
|
+
} });
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
test "keyboard focus-visible shows the tooltip immediately, blur hides it, escape dismisses it" {
|
|
1488
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1489
|
+
defer harness.destroy(std.testing.allocator);
|
|
1490
|
+
const TestApp = struct {
|
|
1491
|
+
fn app(self: *@This()) App {
|
|
1492
|
+
return .{ .context = self, .name = "gpu-tooltip-focus", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1493
|
+
}
|
|
1494
|
+
};
|
|
1495
|
+
var app_state: TestApp = .{};
|
|
1496
|
+
const app = app_state.app();
|
|
1497
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1498
|
+
defer arena.deinit();
|
|
1499
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1500
|
+
|
|
1501
|
+
// Tab reaches Bold with the visible ring: its tooltip shows on the
|
|
1502
|
+
// key itself — keyboard navigation is deliberate, no dwell, no
|
|
1503
|
+
// frame in between (shadcn's Base UI-backed instant focus open).
|
|
1504
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
1505
|
+
try std.testing.expectEqual(toolbar.button_ids[0], harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
1506
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1507
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1508
|
+
|
|
1509
|
+
// Focus moving on hides Bold's tooltip and shows Italic's, both
|
|
1510
|
+
// immediately.
|
|
1511
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 50 * tooltip_ms);
|
|
1512
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1513
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1514
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
1515
|
+
|
|
1516
|
+
// A focus hide never warms the pointer's skip window: hovering Bold
|
|
1517
|
+
// now ARMS the full delay instead of showing instantly — and the
|
|
1518
|
+
// pointer arming (or later leaving) another trigger leaves the
|
|
1519
|
+
// focus-shown tooltip alone.
|
|
1520
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 100 * tooltip_ms);
|
|
1521
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1522
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1523
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 150 * tooltip_ms);
|
|
1524
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1525
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1526
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
1527
|
+
|
|
1528
|
+
// Escape dismisses the focus-shown tooltip and keeps the keyboard
|
|
1529
|
+
// on the trigger; nothing re-reveals without a new focus arrival.
|
|
1530
|
+
try tooltipKey(harness, app, "escape", tooltip_t0 + 200 * tooltip_ms);
|
|
1531
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1532
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
1533
|
+
try std.testing.expectEqual(toolbar.button_ids[1], harness.runtime.views[0].canvas_widget_focused_id);
|
|
1534
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
1535
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1536
|
+
|
|
1537
|
+
// Tabbing away and back re-earns the reveal.
|
|
1538
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1000 * tooltip_ms);
|
|
1539
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
test "programmatic focus hides the focus-shown tooltip and reveals nothing, pointer-shown unaffected" {
|
|
1543
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1544
|
+
defer harness.destroy(std.testing.allocator);
|
|
1545
|
+
const TestApp = struct {
|
|
1546
|
+
fn app(self: *@This()) App {
|
|
1547
|
+
return .{ .context = self, .name = "gpu-tooltip-programmatic-focus", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
var app_state: TestApp = .{};
|
|
1551
|
+
const app = app_state.app();
|
|
1552
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1553
|
+
defer arena.deinit();
|
|
1554
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1555
|
+
|
|
1556
|
+
// Tab earns Bold's focus-shown tooltip through the keyboard seam.
|
|
1557
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
1558
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1559
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1560
|
+
|
|
1561
|
+
// An accessibility `focus` action (the same direct write autofocus
|
|
1562
|
+
// and automation focus funnel through) moves focus to Italic:
|
|
1563
|
+
// programmatic focus is the pointer contract, so Bold's focus-owned
|
|
1564
|
+
// tooltip HIDES and Italic's does NOT reveal — the click-focus
|
|
1565
|
+
// exclusion's rationale (only keyboard focus-visible opens).
|
|
1566
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = toolbar.button_ids[1], .action = .focus });
|
|
1567
|
+
try std.testing.expectEqual(toolbar.button_ids[1], harness.runtime.views[0].canvas_widget_focused_id);
|
|
1568
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
1569
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1570
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1571
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
1572
|
+
|
|
1573
|
+
// A hide without warmth: hovering another trigger now arms the full
|
|
1574
|
+
// delay instead of showing instantly.
|
|
1575
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 100 * tooltip_ms);
|
|
1576
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1577
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1578
|
+
|
|
1579
|
+
// POINTER-shown tooltips are unaffected by focus moves: earn Link's
|
|
1580
|
+
// tooltip by hover (delay 0), then move focus programmatically —
|
|
1581
|
+
// hover still holds it.
|
|
1582
|
+
try tooltipHover(harness, app, toolbar.button_centers[2], tooltip_t0 + 200 * tooltip_ms);
|
|
1583
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1584
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1585
|
+
_ = try harness.runtime.dispatchCanvasWidgetAccessibilityAction(app, 1, "canvas", .{ .id = toolbar.button_ids[0], .action = .focus });
|
|
1586
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1587
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1588
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
/// The autofocus fixture: two buttons owning anchored tooltips through
|
|
1592
|
+
/// the stack-wraps-trigger pattern. `second_autofocus` flips the second
|
|
1593
|
+
/// button's autofocus flag on — the edge the NEXT rebuild's
|
|
1594
|
+
/// source-driven focus move fires on.
|
|
1595
|
+
fn setTooltipAutofocusLayout(harness: anytype, second_autofocus: bool) !void {
|
|
1596
|
+
const first_children = [_]canvas.Widget{
|
|
1597
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "One" },
|
|
1598
|
+
.{ .id = 5, .kind = .tooltip, .text = "First action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1599
|
+
};
|
|
1600
|
+
const second_children = [_]canvas.Widget{
|
|
1601
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "Two", .autofocus = second_autofocus },
|
|
1602
|
+
.{ .id = 7, .kind = .tooltip, .text = "Second action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1603
|
+
};
|
|
1604
|
+
const stacks = [_]canvas.Widget{
|
|
1605
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 160, 32), .children = &first_children },
|
|
1606
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 48, 160, 32), .children = &second_children },
|
|
1607
|
+
};
|
|
1608
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1609
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1610
|
+
.{ .id = 1, .kind = .stack, .children = &stacks },
|
|
1611
|
+
geometry.RectF.init(0, 0, 160, 120),
|
|
1612
|
+
&nodes,
|
|
1613
|
+
);
|
|
1614
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
test "autofocus arriving on a rebuild hides the focus-shown tooltip and reveals nothing" {
|
|
1618
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1619
|
+
defer harness.destroy(std.testing.allocator);
|
|
1620
|
+
const TestApp = struct {
|
|
1621
|
+
fn app(self: *@This()) App {
|
|
1622
|
+
return .{ .context = self, .name = "gpu-tooltip-autofocus", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
var app_state: TestApp = .{};
|
|
1626
|
+
const app = app_state.app();
|
|
1627
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1628
|
+
try harness.start(app);
|
|
1629
|
+
_ = try harness.runtime.createView(.{
|
|
1630
|
+
.window_id = 1,
|
|
1631
|
+
.label = "canvas",
|
|
1632
|
+
.kind = .gpu_surface,
|
|
1633
|
+
.frame = geometry.RectF.init(0, 0, 160, 120),
|
|
1634
|
+
});
|
|
1635
|
+
try setTooltipAutofocusLayout(harness, false);
|
|
1636
|
+
|
|
1637
|
+
// Tab reaches One with the ring: its tooltip is focus-shown.
|
|
1638
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
1639
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1640
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1641
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1642
|
+
|
|
1643
|
+
// A rebuild flips Two's autofocus on (edge-triggered): the
|
|
1644
|
+
// source-driven focus move is programmatic — One's focus-owned
|
|
1645
|
+
// tooltip hides, Two's does not reveal, and Two takes focus
|
|
1646
|
+
// quietly (no ring; not keyboard focus-visible).
|
|
1647
|
+
try setTooltipAutofocusLayout(harness, true);
|
|
1648
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_focused_id);
|
|
1649
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
1650
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1651
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
1652
|
+
try std.testing.expect(try tooltipHidden(harness, 7));
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
test "a press cancels the armed tooltip and dismisses the shown one without leaving warmth" {
|
|
1656
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1657
|
+
defer harness.destroy(std.testing.allocator);
|
|
1658
|
+
const TestApp = struct {
|
|
1659
|
+
fn app(self: *@This()) App {
|
|
1660
|
+
return .{ .context = self, .name = "gpu-tooltip-press", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
var app_state: TestApp = .{};
|
|
1664
|
+
const app = app_state.app();
|
|
1665
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1666
|
+
defer arena.deinit();
|
|
1667
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1668
|
+
|
|
1669
|
+
// Press mid-dwell: the armed intent cancels on the down, and the
|
|
1670
|
+
// would-be deadline passing changes nothing (no reveal mid- or
|
|
1671
|
+
// post-activation).
|
|
1672
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
1673
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1674
|
+
try tooltipPointer(harness, app, .pointer_down, toolbar.button_centers[0], tooltip_t0 + 100 * tooltip_ms);
|
|
1675
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1676
|
+
try tooltipPointer(harness, app, .pointer_up, toolbar.button_centers[0], tooltip_t0 + 150 * tooltip_ms);
|
|
1677
|
+
try tooltipFrame(harness, app, tooltip_t0 + 800 * tooltip_ms);
|
|
1678
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1679
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1680
|
+
|
|
1681
|
+
// Earn the tooltip, then press its trigger: dismissed immediately,
|
|
1682
|
+
// and the press closes the warm window — the SAME unbroken hover
|
|
1683
|
+
// never re-shows, and a leave-and-return must re-earn the delay
|
|
1684
|
+
// instead of showing instantly.
|
|
1685
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 900 * tooltip_ms);
|
|
1686
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 2000 * tooltip_ms);
|
|
1687
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2600 * tooltip_ms);
|
|
1688
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1689
|
+
try tooltipPointer(harness, app, .pointer_down, toolbar.button_centers[0], tooltip_t0 + 2700 * tooltip_ms);
|
|
1690
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1691
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1692
|
+
try tooltipPointer(harness, app, .pointer_up, toolbar.button_centers[0], tooltip_t0 + 2750 * tooltip_ms);
|
|
1693
|
+
try tooltipFrame(harness, app, tooltip_t0 + 3400 * tooltip_ms);
|
|
1694
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1695
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1696
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 150 }, tooltip_t0 + 3500 * tooltip_ms);
|
|
1697
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 3550 * tooltip_ms);
|
|
1698
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1699
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
test "keyboard activation dismisses the focus-shown tooltip like a press" {
|
|
1703
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1704
|
+
defer harness.destroy(std.testing.allocator);
|
|
1705
|
+
const TestApp = struct {
|
|
1706
|
+
fn app(self: *@This()) App {
|
|
1707
|
+
return .{ .context = self, .name = "gpu-tooltip-activate", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1708
|
+
}
|
|
1709
|
+
};
|
|
1710
|
+
var app_state: TestApp = .{};
|
|
1711
|
+
const app = app_state.app();
|
|
1712
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1713
|
+
defer arena.deinit();
|
|
1714
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1715
|
+
|
|
1716
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
1717
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1718
|
+
|
|
1719
|
+
// Enter on the focused trigger counts as a press: the tooltip
|
|
1720
|
+
// dismisses and stays down while focus rests on the trigger.
|
|
1721
|
+
try tooltipKey(harness, app, "enter", tooltip_t0 + 100 * tooltip_ms);
|
|
1722
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1723
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1724
|
+
try std.testing.expectEqual(toolbar.button_ids[0], harness.runtime.views[0].canvas_widget_focused_id);
|
|
1725
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
1726
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1727
|
+
|
|
1728
|
+
// The next focus arrival still reveals (activation dismissed one
|
|
1729
|
+
// tooltip, not the register).
|
|
1730
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1000 * tooltip_ms);
|
|
1731
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
test "view blur resets tooltip state and re-stamps hidden, keyboard- and pointer-shown alike" {
|
|
1735
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1736
|
+
defer harness.destroy(std.testing.allocator);
|
|
1737
|
+
const TestApp = struct {
|
|
1738
|
+
fn app(self: *@This()) App {
|
|
1739
|
+
return .{ .context = self, .name = "gpu-tooltip-view-blur", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1740
|
+
}
|
|
1741
|
+
};
|
|
1742
|
+
var app_state: TestApp = .{};
|
|
1743
|
+
const app = app_state.app();
|
|
1744
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1745
|
+
defer arena.deinit();
|
|
1746
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1747
|
+
_ = try harness.runtime.createView(.{
|
|
1748
|
+
.window_id = 1,
|
|
1749
|
+
.label = "other",
|
|
1750
|
+
.kind = .gpu_surface,
|
|
1751
|
+
.frame = geometry.RectF.init(0, 200, 420, 80),
|
|
1752
|
+
});
|
|
1753
|
+
|
|
1754
|
+
// Tab reveals the focus-shown tooltip on the canvas view.
|
|
1755
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
1756
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1757
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1758
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1759
|
+
|
|
1760
|
+
// Focus moving to a SIBLING VIEW blurs the canvas: the keyboard
|
|
1761
|
+
// left the whole surface, so the focus-shown tooltip hides, the
|
|
1762
|
+
// machine resets, and the semantics tree carries no stale
|
|
1763
|
+
// visible-tooltip node.
|
|
1764
|
+
try harness.runtime.focusView(1, "other");
|
|
1765
|
+
try std.testing.expect(!harness.runtime.views[0].focused);
|
|
1766
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1767
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
1768
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1769
|
+
for (runtimeViewWidgetSemantics(&harness.runtime.views[0])) |node| {
|
|
1770
|
+
try std.testing.expect(node.id != toolbar.tooltip_ids[0]);
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// The pointer-owned register resets too: earn Link's instant
|
|
1774
|
+
// tooltip plus an armed dwell on Bold's, then blur — shown hides,
|
|
1775
|
+
// armed disarms, and the warm window closes (a later hover in the
|
|
1776
|
+
// returned-to view re-earns the full delay).
|
|
1777
|
+
try harness.runtime.focusView(1, "canvas");
|
|
1778
|
+
try tooltipHover(harness, app, toolbar.button_centers[2], tooltip_t0 + 100 * tooltip_ms);
|
|
1779
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1780
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0 + 150 * tooltip_ms);
|
|
1781
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1782
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
1783
|
+
try harness.runtime.focusView(1, "other");
|
|
1784
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1785
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
1786
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1787
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1788
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
test "a secondary-button down dismisses the shown tooltip and the context menu still presents" {
|
|
1792
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1793
|
+
defer harness.destroy(std.testing.allocator);
|
|
1794
|
+
const TestApp = struct {
|
|
1795
|
+
fn app(self: *@This()) App {
|
|
1796
|
+
return .{ .context = self, .name = "gpu-tooltip-right-click", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
var app_state: TestApp = .{};
|
|
1800
|
+
const app = app_state.app();
|
|
1801
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1802
|
+
try harness.start(app);
|
|
1803
|
+
_ = try harness.runtime.createView(.{
|
|
1804
|
+
.window_id = 1,
|
|
1805
|
+
.label = "canvas",
|
|
1806
|
+
.kind = .gpu_surface,
|
|
1807
|
+
.frame = geometry.RectF.init(0, 0, 320, 200),
|
|
1808
|
+
});
|
|
1809
|
+
|
|
1810
|
+
// A trigger that declares a context menu AND owns an anchored
|
|
1811
|
+
// tooltip (delay 0 so the hover itself shows it).
|
|
1812
|
+
const items = [_]canvas.WidgetContextMenuItem{
|
|
1813
|
+
.{ .label = "Rename" },
|
|
1814
|
+
.{ .label = "Delete" },
|
|
1815
|
+
};
|
|
1816
|
+
const children = [_]canvas.Widget{
|
|
1817
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 80, 96, 32), .text = "Run", .context_menu = &items },
|
|
1818
|
+
.{ .id = 3, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
1819
|
+
};
|
|
1820
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
1821
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 200), &nodes);
|
|
1822
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1823
|
+
|
|
1824
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 96 }, tooltip_t0);
|
|
1825
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1826
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
1827
|
+
|
|
1828
|
+
// The secondary down is consumed by the context-menu gesture and
|
|
1829
|
+
// never reaches the widget press pipeline — but "pointer-down
|
|
1830
|
+
// dismisses" holds for every button: the tooltip is gone (warm
|
|
1831
|
+
// window included) and the native menu presents over clean glass.
|
|
1832
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
1833
|
+
.window_id = 1,
|
|
1834
|
+
.label = "canvas",
|
|
1835
|
+
.kind = .pointer_down,
|
|
1836
|
+
.button = 1,
|
|
1837
|
+
.x = 58,
|
|
1838
|
+
.y = 96,
|
|
1839
|
+
.timestamp_ns = tooltip_t0 + 100 * tooltip_ms,
|
|
1840
|
+
} });
|
|
1841
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1842
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
1843
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1844
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.context_menu_request_count);
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
test "a window-drag down dismisses the shown tooltip before the OS takes the pointer" {
|
|
1848
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1849
|
+
defer harness.destroy(std.testing.allocator);
|
|
1850
|
+
const TestApp = struct {
|
|
1851
|
+
fn app(self: *@This()) App {
|
|
1852
|
+
return .{ .context = self, .name = "gpu-tooltip-window-drag", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1853
|
+
}
|
|
1854
|
+
};
|
|
1855
|
+
var app_state: TestApp = .{};
|
|
1856
|
+
const app = app_state.app();
|
|
1857
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1858
|
+
try harness.start(app);
|
|
1859
|
+
_ = try harness.runtime.createView(.{
|
|
1860
|
+
.window_id = 1,
|
|
1861
|
+
.label = "canvas",
|
|
1862
|
+
.kind = .gpu_surface,
|
|
1863
|
+
.frame = geometry.RectF.init(0, 0, 320, 200),
|
|
1864
|
+
});
|
|
1865
|
+
|
|
1866
|
+
// A hidden-titlebar shape: a window-drag header row above a trigger
|
|
1867
|
+
// that owns an anchored tooltip (delay 0).
|
|
1868
|
+
const trigger_children = [_]canvas.Widget{
|
|
1869
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(10, 80, 96, 32), .text = "Run" },
|
|
1870
|
+
.{ .id = 4, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
1871
|
+
};
|
|
1872
|
+
const children = [_]canvas.Widget{
|
|
1873
|
+
.{ .id = 2, .kind = .row, .frame = geometry.RectF.init(0, 0, 320, 40), .window_drag = true },
|
|
1874
|
+
.{ .id = 5, .kind = .stack, .frame = geometry.RectF.init(0, 40, 320, 160), .children = &trigger_children },
|
|
1875
|
+
};
|
|
1876
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
1877
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 200), &nodes);
|
|
1878
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1879
|
+
|
|
1880
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 136 }, tooltip_t0);
|
|
1881
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1882
|
+
|
|
1883
|
+
// The primary down on the drag header hands the gesture to the OS
|
|
1884
|
+
// and skips the whole widget press pipeline — but the press reset
|
|
1885
|
+
// still runs: no tooltip may float while the window moves.
|
|
1886
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 160, .y = 20 }, tooltip_t0 + 100 * tooltip_ms);
|
|
1887
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.window_drag_start_count);
|
|
1888
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1889
|
+
try std.testing.expect(try tooltipHidden(harness, 4));
|
|
1890
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
test "a content-to-gap transit armed by a 0-to-0 hover still pumps the idle frame clock" {
|
|
1894
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1895
|
+
defer harness.destroy(std.testing.allocator);
|
|
1896
|
+
const TestApp = struct {
|
|
1897
|
+
fn app(self: *@This()) App {
|
|
1898
|
+
return .{ .context = self, .name = "gpu-tooltip-transit-idle", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
var app_state: TestApp = .{};
|
|
1902
|
+
const app = app_state.app();
|
|
1903
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
1904
|
+
defer arena.deinit();
|
|
1905
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
1906
|
+
|
|
1907
|
+
// Earn Bold's tooltip, then park INSIDE its frame: the content
|
|
1908
|
+
// hold, with hovered_id == 0 (the tooltip is not a hit target).
|
|
1909
|
+
try tooltipHover(harness, app, toolbar.button_centers[0], tooltip_t0);
|
|
1910
|
+
try tooltipFrame(harness, app, tooltip_t0 + 600 * tooltip_ms);
|
|
1911
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1912
|
+
const tooltip_frame = try tooltipNodeFrame(harness, toolbar.tooltip_ids[0]);
|
|
1913
|
+
const trigger_frame = try tooltipNodeFrame(harness, toolbar.button_ids[0]);
|
|
1914
|
+
try tooltipHover(harness, app, tooltip_frame.center(), tooltip_t0 + 700 * tooltip_ms);
|
|
1915
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1916
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_transit_deadline_ns);
|
|
1917
|
+
|
|
1918
|
+
// Step from the content into the anchor gap: hover stays 0 on BOTH
|
|
1919
|
+
// sides (0 -> 0), so nothing about the interaction state changes —
|
|
1920
|
+
// the transit grace this move arms is the ONLY new fact. The pump
|
|
1921
|
+
// obligation must derive from the pending deadline itself, or an
|
|
1922
|
+
// idle app never plans the frame the deadline needs to fire on.
|
|
1923
|
+
harness.runtime.invalidated = false;
|
|
1924
|
+
const gap_point = geometry.PointF{
|
|
1925
|
+
.x = toolbar.button_centers[0].x,
|
|
1926
|
+
.y = (tooltip_frame.maxY() + trigger_frame.y) / 2,
|
|
1927
|
+
};
|
|
1928
|
+
try tooltipHover(harness, app, gap_point, tooltip_t0 + 800 * tooltip_ms);
|
|
1929
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1930
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_transit_deadline_ns != 0);
|
|
1931
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1932
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
1933
|
+
|
|
1934
|
+
// With ZERO further interaction, the grace resolves on the frame
|
|
1935
|
+
// clock: a frame inside the bound changes nothing, the first frame
|
|
1936
|
+
// past it hides with the usual pointer-hide warmth.
|
|
1937
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1000 * tooltip_ms);
|
|
1938
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1939
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1201 * tooltip_ms);
|
|
1940
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1941
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
1942
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
test "a scroll re-checks the content hold even when the hover id is unchanged" {
|
|
1946
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
1947
|
+
defer harness.destroy(std.testing.allocator);
|
|
1948
|
+
const TestApp = struct {
|
|
1949
|
+
fn app(self: *@This()) App {
|
|
1950
|
+
return .{ .context = self, .name = "gpu-tooltip-scroll-held", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
var app_state: TestApp = .{};
|
|
1954
|
+
const app = app_state.app();
|
|
1955
|
+
harness.null_platform.gpu_surfaces = true;
|
|
1956
|
+
try harness.start(app);
|
|
1957
|
+
_ = try harness.runtime.createView(.{
|
|
1958
|
+
.window_id = 1,
|
|
1959
|
+
.label = "canvas",
|
|
1960
|
+
.kind = .gpu_surface,
|
|
1961
|
+
.frame = geometry.RectF.init(0, 0, 160, 120),
|
|
1962
|
+
});
|
|
1963
|
+
// A scroll view tall enough that the first trigger's below-anchored
|
|
1964
|
+
// tooltip sits fully inside the viewport, with a second stack far
|
|
1965
|
+
// enough down to give the scroll range.
|
|
1966
|
+
const first_children = [_]canvas.Widget{
|
|
1967
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "One" },
|
|
1968
|
+
.{ .id = 5, .kind = .tooltip, .text = "First action", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1969
|
+
};
|
|
1970
|
+
const second_children = [_]canvas.Widget{
|
|
1971
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "Two" },
|
|
1972
|
+
.{ .id = 7, .kind = .tooltip, .text = "Second action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
1973
|
+
};
|
|
1974
|
+
const stacks = [_]canvas.Widget{
|
|
1975
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 160, 32), .children = &first_children },
|
|
1976
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 80, 160, 32), .children = &second_children },
|
|
1977
|
+
};
|
|
1978
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
1979
|
+
const layout = try canvas.layoutWidgetTree(
|
|
1980
|
+
.{ .id = 1, .kind = .scroll_view, .children = &stacks },
|
|
1981
|
+
geometry.RectF.init(0, 0, 160, 60),
|
|
1982
|
+
&nodes,
|
|
1983
|
+
);
|
|
1984
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
1985
|
+
|
|
1986
|
+
// Show instantly (delay 0), then park INSIDE the tooltip's frame:
|
|
1987
|
+
// the hold. Beneath the frame sits the scroll view itself, so the
|
|
1988
|
+
// hover id is 1 — and stays 1 through the scroll below.
|
|
1989
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 16 }, tooltip_t0);
|
|
1990
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1991
|
+
const held_frame = try tooltipNodeFrame(harness, 5);
|
|
1992
|
+
const held_point = held_frame.center();
|
|
1993
|
+
try std.testing.expect(held_point.y > 32 and held_point.y < 60);
|
|
1994
|
+
try tooltipHover(harness, app, held_point, tooltip_t0 + 100 * tooltip_ms);
|
|
1995
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
1996
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
1997
|
+
|
|
1998
|
+
// Wheel-scroll the content up under the stationary pointer: the
|
|
1999
|
+
// tooltip's frame slides away while the re-hit-test still lands on
|
|
2000
|
+
// the scroll view — the hover id is UNCHANGED on both sides, the
|
|
2001
|
+
// exact state a transition gate can never see. The containment
|
|
2002
|
+
// re-check keys on the frame, not the id: the hold breaks and the
|
|
2003
|
+
// tooltip hides on the scroll itself, usual warmth.
|
|
2004
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2005
|
+
.window_id = 1,
|
|
2006
|
+
.label = "canvas",
|
|
2007
|
+
.kind = .scroll,
|
|
2008
|
+
.x = held_point.x,
|
|
2009
|
+
.y = held_point.y,
|
|
2010
|
+
.delta_y = 20,
|
|
2011
|
+
.timestamp_ns = tooltip_t0 + 200 * tooltip_ms,
|
|
2012
|
+
} });
|
|
2013
|
+
const scrolled_frame = try tooltipNodeFrame(harness, 5);
|
|
2014
|
+
try std.testing.expect(!scrolled_frame.containsPoint(held_point));
|
|
2015
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2016
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2017
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
2018
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
test "leaving tooltip content onto the trigger beneath reprocesses it as a fresh transition" {
|
|
2022
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2023
|
+
defer harness.destroy(std.testing.allocator);
|
|
2024
|
+
const TestApp = struct {
|
|
2025
|
+
fn app(self: *@This()) App {
|
|
2026
|
+
return .{ .context = self, .name = "gpu-tooltip-held-release", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
var app_state: TestApp = .{};
|
|
2030
|
+
const app = app_state.app();
|
|
2031
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2032
|
+
try harness.start(app);
|
|
2033
|
+
_ = try harness.runtime.createView(.{
|
|
2034
|
+
.window_id = 1,
|
|
2035
|
+
.label = "canvas",
|
|
2036
|
+
.kind = .gpu_surface,
|
|
2037
|
+
.frame = geometry.RectF.init(0, 0, 160, 200),
|
|
2038
|
+
});
|
|
2039
|
+
// Trigger One's below-anchored tooltip floats OVER the top of the
|
|
2040
|
+
// tall trigger Two beneath it, so a pointer inside the tooltip's
|
|
2041
|
+
// frame already records hover on Two — ownership the frame claims.
|
|
2042
|
+
const first_children = [_]canvas.Widget{
|
|
2043
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "One" },
|
|
2044
|
+
.{ .id = 5, .kind = .tooltip, .text = "First action", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .below } } },
|
|
2045
|
+
};
|
|
2046
|
+
const second_children = [_]canvas.Widget{
|
|
2047
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 80), .text = "Two" },
|
|
2048
|
+
.{ .id = 7, .kind = .tooltip, .text = "Second action", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
2049
|
+
};
|
|
2050
|
+
const stacks = [_]canvas.Widget{
|
|
2051
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 160, 32), .children = &first_children },
|
|
2052
|
+
.{ .id = 6, .kind = .stack, .frame = geometry.RectF.init(0, 40, 160, 80), .children = &second_children },
|
|
2053
|
+
};
|
|
2054
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
2055
|
+
const layout = try canvas.layoutWidgetTree(
|
|
2056
|
+
.{ .id = 1, .kind = .stack, .children = &stacks },
|
|
2057
|
+
geometry.RectF.init(0, 0, 160, 200),
|
|
2058
|
+
&nodes,
|
|
2059
|
+
);
|
|
2060
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2061
|
+
// Zero the warm window so the reprocessed trigger observably ARMS
|
|
2062
|
+
// its dwell (with the default warm window it would warm-show
|
|
2063
|
+
// instantly — also correct, but indistinguishable from a stale
|
|
2064
|
+
// instant carry-over of One's show).
|
|
2065
|
+
harness.runtime.views[0].widget_tokens.metrics.tooltip_warm_window_ms = 0;
|
|
2066
|
+
|
|
2067
|
+
// Show One's tooltip, then move INTO its frame over Two: hover
|
|
2068
|
+
// records Two, but the hover reached Two THROUGH the tooltip's
|
|
2069
|
+
// frame, so Two's own tooltip must not arm while the hold lasts.
|
|
2070
|
+
try tooltipHover(harness, app, .{ .x = 80, .y = 16 }, tooltip_t0);
|
|
2071
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2072
|
+
const tooltip_frame = try tooltipNodeFrame(harness, 5);
|
|
2073
|
+
const overlap_point = geometry.PointF{ .x = tooltip_frame.center().x, .y = @max(tooltip_frame.y + 4, 44) };
|
|
2074
|
+
try std.testing.expect(tooltip_frame.containsPoint(overlap_point));
|
|
2075
|
+
try std.testing.expect(overlap_point.y > 40);
|
|
2076
|
+
try tooltipHover(harness, app, overlap_point, tooltip_t0 + 100 * tooltip_ms);
|
|
2077
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2078
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2079
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2080
|
+
|
|
2081
|
+
// Exit the tooltip's frame downward, still on Two: no hover
|
|
2082
|
+
// TRANSITION exists (Two was already recorded), but the hold's
|
|
2083
|
+
// release is a fresh fact — One hides, and Two is reprocessed as a
|
|
2084
|
+
// fresh transition so its dwell arms without a leave-and-re-enter.
|
|
2085
|
+
// "No transition" was measured against stale ownership (the frame
|
|
2086
|
+
// claimed the hover), not against user intent.
|
|
2087
|
+
const exit_point = geometry.PointF{ .x = 80, .y = tooltip_frame.maxY() + 20 };
|
|
2088
|
+
try std.testing.expect(exit_point.y < 120);
|
|
2089
|
+
harness.runtime.invalidated = false;
|
|
2090
|
+
try tooltipHover(harness, app, exit_point, tooltip_t0 + 200 * tooltip_ms);
|
|
2091
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2092
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2093
|
+
try std.testing.expect(try tooltipHidden(harness, 5));
|
|
2094
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2095
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2096
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_deadline_ns != 0);
|
|
2097
|
+
// The armed dwell obligates the pump even though this move changed
|
|
2098
|
+
// no interaction state (hover stayed on Two).
|
|
2099
|
+
try std.testing.expect(harness.runtime.invalidated);
|
|
2100
|
+
|
|
2101
|
+
// The reprocessed dwell completes on the frame clock like any
|
|
2102
|
+
// other — earned by Two's own declaration.
|
|
2103
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
2104
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2105
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
2106
|
+
try std.testing.expect(!try tooltipHidden(harness, 7));
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
test "a consumed secondary-button stream updates the stored position for point-blind reconciliation" {
|
|
2110
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2111
|
+
defer harness.destroy(std.testing.allocator);
|
|
2112
|
+
const TestApp = struct {
|
|
2113
|
+
fn app(self: *@This()) App {
|
|
2114
|
+
return .{ .context = self, .name = "gpu-tooltip-secondary-position", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
var app_state: TestApp = .{};
|
|
2118
|
+
const app = app_state.app();
|
|
2119
|
+
try installTooltipScrollFixture(harness, app, true);
|
|
2120
|
+
|
|
2121
|
+
// Focus the scroll view, then earn One's tooltip (delay 0): the
|
|
2122
|
+
// stored position is the hover's (12, 12).
|
|
2123
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 12, .y = 36 }, tooltip_t0);
|
|
2124
|
+
try tooltipPointer(harness, app, .pointer_up, .{ .x = 12, .y = 36 }, tooltip_t0 + 20 * tooltip_ms);
|
|
2125
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 1), harness.runtime.views[0].canvas_widget_focused_id);
|
|
2126
|
+
try tooltipHover(harness, app, .{ .x = 12, .y = 12 }, tooltip_t0 + 50 * tooltip_ms);
|
|
2127
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 5), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2128
|
+
|
|
2129
|
+
// The secondary down is consumed by the context-menu gesture and
|
|
2130
|
+
// never reaches the widget interaction pipeline — but the pointer
|
|
2131
|
+
// MOVED to press there, so the stored position must follow it (and
|
|
2132
|
+
// the down still dismisses, warm window included).
|
|
2133
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2134
|
+
.window_id = 1,
|
|
2135
|
+
.label = "canvas",
|
|
2136
|
+
.kind = .pointer_down,
|
|
2137
|
+
.button = 1,
|
|
2138
|
+
.x = 12,
|
|
2139
|
+
.y = 4,
|
|
2140
|
+
.timestamp_ns = tooltip_t0 + 100 * tooltip_ms,
|
|
2141
|
+
} });
|
|
2142
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2143
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
2144
|
+
const down_position = harness.runtime.views[0].canvas_last_pointer_position orelse return error.TestUnexpectedResult;
|
|
2145
|
+
try std.testing.expectEqual(@as(f32, 12), down_position.x);
|
|
2146
|
+
try std.testing.expectEqual(@as(f32, 4), down_position.y);
|
|
2147
|
+
|
|
2148
|
+
// The consumed MOVES of the same stream keep the store fresh too.
|
|
2149
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
2150
|
+
.window_id = 1,
|
|
2151
|
+
.label = "canvas",
|
|
2152
|
+
.kind = .pointer_move,
|
|
2153
|
+
.button = 1,
|
|
2154
|
+
.x = 12,
|
|
2155
|
+
.y = 20,
|
|
2156
|
+
.timestamp_ns = tooltip_t0 + 150 * tooltip_ms,
|
|
2157
|
+
} });
|
|
2158
|
+
const move_position = harness.runtime.views[0].canvas_last_pointer_position orelse return error.TestUnexpectedResult;
|
|
2159
|
+
try std.testing.expectEqual(@as(f32, 12), move_position.x);
|
|
2160
|
+
try std.testing.expectEqual(@as(f32, 20), move_position.y);
|
|
2161
|
+
|
|
2162
|
+
// A point-blind keyboard scroll now re-hit-tests the FRESH
|
|
2163
|
+
// coordinate: End scrolls trigger Two under (12, 20) — a stale
|
|
2164
|
+
// (12, 12)-era store from before the consumed stream would have
|
|
2165
|
+
// resolved differently — and Two arms its normal dwell.
|
|
2166
|
+
try tooltipKey(harness, app, "end", tooltip_t0 + 200 * tooltip_ms);
|
|
2167
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2168
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 7), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2169
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2170
|
+
try std.testing.expectEqual(@as(f32, 12), harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
2171
|
+
try std.testing.expectEqual(@as(f32, 20), harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
test "a window-drag consumed down updates the stored position" {
|
|
2175
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2176
|
+
defer harness.destroy(std.testing.allocator);
|
|
2177
|
+
const TestApp = struct {
|
|
2178
|
+
fn app(self: *@This()) App {
|
|
2179
|
+
return .{ .context = self, .name = "gpu-tooltip-drag-position", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
var app_state: TestApp = .{};
|
|
2183
|
+
const app = app_state.app();
|
|
2184
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2185
|
+
try harness.start(app);
|
|
2186
|
+
_ = try harness.runtime.createView(.{
|
|
2187
|
+
.window_id = 1,
|
|
2188
|
+
.label = "canvas",
|
|
2189
|
+
.kind = .gpu_surface,
|
|
2190
|
+
.frame = geometry.RectF.init(0, 0, 320, 200),
|
|
2191
|
+
});
|
|
2192
|
+
const trigger_children = [_]canvas.Widget{
|
|
2193
|
+
.{ .id = 3, .kind = .button, .frame = geometry.RectF.init(10, 80, 96, 32), .text = "Run" },
|
|
2194
|
+
.{ .id = 4, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
2195
|
+
};
|
|
2196
|
+
const children = [_]canvas.Widget{
|
|
2197
|
+
.{ .id = 2, .kind = .row, .frame = geometry.RectF.init(0, 0, 320, 40), .window_drag = true },
|
|
2198
|
+
.{ .id = 5, .kind = .stack, .frame = geometry.RectF.init(0, 40, 320, 160), .children = &trigger_children },
|
|
2199
|
+
};
|
|
2200
|
+
var nodes: [6]canvas.WidgetLayoutNode = undefined;
|
|
2201
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 320, 200), &nodes);
|
|
2202
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2203
|
+
|
|
2204
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 136 }, tooltip_t0);
|
|
2205
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 4), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2206
|
+
|
|
2207
|
+
// The down on the drag header hands the gesture to the OS and skips
|
|
2208
|
+
// the widget interaction pipeline — but it is the last position the
|
|
2209
|
+
// view will hear before the OS owns the pointer, so the store must
|
|
2210
|
+
// record it: a later point-blind reconcile hit-tests where the
|
|
2211
|
+
// pointer really went down, not where it hovered before.
|
|
2212
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 160, .y = 20 }, tooltip_t0 + 100 * tooltip_ms);
|
|
2213
|
+
try std.testing.expectEqual(@as(usize, 1), harness.null_platform.window_drag_start_count);
|
|
2214
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2215
|
+
const stored = harness.runtime.views[0].canvas_last_pointer_position orelse return error.TestUnexpectedResult;
|
|
2216
|
+
try std.testing.expectEqual(@as(f32, 160), stored.x);
|
|
2217
|
+
try std.testing.expectEqual(@as(f32, 20), stored.y);
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
/// A raw-widget tooltip fixture with EXPLICIT ids (the rebuild tests
|
|
2221
|
+
/// swap trees, so ids must be author-controlled): a stack wrapping a
|
|
2222
|
+
/// trigger button (id 2) and its anchored tooltip (id 3),
|
|
2223
|
+
/// tooltip-delay 0 so the hover itself shows it.
|
|
2224
|
+
fn tooltipRebuildChildren(trigger_id: canvas.ObjectId, disabled: bool) [2]canvas.Widget {
|
|
2225
|
+
return .{
|
|
2226
|
+
.{
|
|
2227
|
+
.id = trigger_id,
|
|
2228
|
+
.kind = .button,
|
|
2229
|
+
.frame = geometry.RectF.init(10, 40, 96, 32),
|
|
2230
|
+
.text = "Run",
|
|
2231
|
+
.state = .{ .disabled = disabled },
|
|
2232
|
+
},
|
|
2233
|
+
.{
|
|
2234
|
+
.id = 3,
|
|
2235
|
+
.kind = .tooltip,
|
|
2236
|
+
.text = "Runs the job",
|
|
2237
|
+
.tooltip_delay_ms = 0,
|
|
2238
|
+
.layout = .{ .anchor = .{ .placement = .above } },
|
|
2239
|
+
},
|
|
2240
|
+
};
|
|
2241
|
+
}
|
|
2242
|
+
|
|
2243
|
+
fn installTooltipRebuildFixture(harness: anytype, app: App) !void {
|
|
2244
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2245
|
+
try harness.start(app);
|
|
2246
|
+
_ = try harness.runtime.createView(.{
|
|
2247
|
+
.window_id = 1,
|
|
2248
|
+
.label = "canvas",
|
|
2249
|
+
.kind = .gpu_surface,
|
|
2250
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
2251
|
+
});
|
|
2252
|
+
const children = tooltipRebuildChildren(2, false);
|
|
2253
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2254
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
2255
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2256
|
+
|
|
2257
|
+
// Hover the trigger: delay 0 shows the tooltip on the move itself.
|
|
2258
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
2259
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2260
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
fn expectTooltipRebuildReset(harness: anytype, app: App, replacement: []const canvas.Widget) !void {
|
|
2264
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2265
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = replacement }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
2266
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2267
|
+
|
|
2268
|
+
// The owning trigger is gone (removed, rekeyed, or disabled): the
|
|
2269
|
+
// adoption prune resets the whole intent slot and re-stamps the
|
|
2270
|
+
// surviving tooltip node hidden — no stale semantics.hidden=false.
|
|
2271
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2272
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2273
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
2274
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2275
|
+
|
|
2276
|
+
// And nothing appears later: frames past any would-be deadline
|
|
2277
|
+
// leave the tooltip down.
|
|
2278
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
2279
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2280
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
test "a rebuild that removes the tooltip's trigger resets the shown tooltip" {
|
|
2284
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2285
|
+
defer harness.destroy(std.testing.allocator);
|
|
2286
|
+
const TestApp = struct {
|
|
2287
|
+
fn app(self: *@This()) App {
|
|
2288
|
+
return .{ .context = self, .name = "gpu-tooltip-owner-gone", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
var app_state: TestApp = .{};
|
|
2292
|
+
const app = app_state.app();
|
|
2293
|
+
try installTooltipRebuildFixture(harness, app);
|
|
2294
|
+
|
|
2295
|
+
// The tooltip node SURVIVES the rebuild; only its trigger vanishes.
|
|
2296
|
+
const replacement = [_]canvas.Widget{tooltipRebuildChildren(2, false)[1]};
|
|
2297
|
+
try expectTooltipRebuildReset(harness, app, &replacement);
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
test "a rebuild that rekeys the tooltip's trigger resets the shown tooltip" {
|
|
2301
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2302
|
+
defer harness.destroy(std.testing.allocator);
|
|
2303
|
+
const TestApp = struct {
|
|
2304
|
+
fn app(self: *@This()) App {
|
|
2305
|
+
return .{ .context = self, .name = "gpu-tooltip-owner-rekeyed", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
var app_state: TestApp = .{};
|
|
2309
|
+
const app = app_state.app();
|
|
2310
|
+
try installTooltipRebuildFixture(harness, app);
|
|
2311
|
+
|
|
2312
|
+
// Same structure, new trigger id: a new id is a new widget, so the
|
|
2313
|
+
// intent earned against the old one does not transfer — the shown
|
|
2314
|
+
// slot resets and the warm window closes with it. The replacement
|
|
2315
|
+
// declares the DEFAULT delay so the distinction stays observable:
|
|
2316
|
+
// the new widget sits under the stationary pointer, and the
|
|
2317
|
+
// adoption re-hit-test treats it exactly like a trigger scrolled
|
|
2318
|
+
// under the pointer — it earns a FRESH dwell (owner re-recorded
|
|
2319
|
+
// against the new id), never an instant carry-over of the old
|
|
2320
|
+
// widget's show.
|
|
2321
|
+
var replacement = tooltipRebuildChildren(9, false);
|
|
2322
|
+
replacement[1].tooltip_delay_ms = -1;
|
|
2323
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2324
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &replacement }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
2325
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2326
|
+
|
|
2327
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2328
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2329
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
2330
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2331
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2332
|
+
|
|
2333
|
+
// The fresh dwell completes on the frame clock like any other —
|
|
2334
|
+
// earned by the new widget's own declaration, not inherited.
|
|
2335
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
2336
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2337
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
2338
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
test "a rebuild that disables the tooltip's trigger resets the shown tooltip" {
|
|
2342
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2343
|
+
defer harness.destroy(std.testing.allocator);
|
|
2344
|
+
const TestApp = struct {
|
|
2345
|
+
fn app(self: *@This()) App {
|
|
2346
|
+
return .{ .context = self, .name = "gpu-tooltip-owner-disabled", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
var app_state: TestApp = .{};
|
|
2350
|
+
const app = app_state.app();
|
|
2351
|
+
try installTooltipRebuildFixture(harness, app);
|
|
2352
|
+
|
|
2353
|
+
// A disabled trigger leaves hover (and focus) routing entirely, so
|
|
2354
|
+
// no interaction could ever hide the tooltip again: the prune must
|
|
2355
|
+
// not wait for one.
|
|
2356
|
+
const replacement = tooltipRebuildChildren(2, true);
|
|
2357
|
+
try expectTooltipRebuildReset(harness, app, &replacement);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
test "a failed adoption leaves the shown tooltip's registers coherent and hideable" {
|
|
2361
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2362
|
+
defer harness.destroy(std.testing.allocator);
|
|
2363
|
+
const TestApp = struct {
|
|
2364
|
+
fn app(self: *@This()) App {
|
|
2365
|
+
return .{ .context = self, .name = "gpu-tooltip-adoption-failure", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2366
|
+
}
|
|
2367
|
+
};
|
|
2368
|
+
var app_state: TestApp = .{};
|
|
2369
|
+
const app = app_state.app();
|
|
2370
|
+
try installTooltipRebuildFixture(harness, app);
|
|
2371
|
+
|
|
2372
|
+
// A replacement that BOTH breaks the shown binding (trigger 2 is
|
|
2373
|
+
// gone) AND blows the retained anchored-surface budget, so
|
|
2374
|
+
// adoption fails inside copyWidgetLayoutTree — after the pre-diff
|
|
2375
|
+
// visibility stamp, before anything destructive. The old
|
|
2376
|
+
// register-mutating prune ran ahead of this failure: it cleared
|
|
2377
|
+
// the shown slot while the OLD tree stayed retained and stamped
|
|
2378
|
+
// visible — a tooltip no transition could ever hide again.
|
|
2379
|
+
var overflow_children: [max_canvas_widget_anchored_per_view + 1]canvas.Widget = undefined;
|
|
2380
|
+
for (&overflow_children, 0..) |*widget, child_index| {
|
|
2381
|
+
widget.* = .{
|
|
2382
|
+
.id = @intCast(100 + child_index),
|
|
2383
|
+
.kind = .tooltip,
|
|
2384
|
+
.text = "Overflow",
|
|
2385
|
+
.layout = .{ .anchor = .{ .placement = .above } },
|
|
2386
|
+
};
|
|
2387
|
+
}
|
|
2388
|
+
var overflow_nodes: [max_canvas_widget_anchored_per_view + 2]canvas.WidgetLayoutNode = undefined;
|
|
2389
|
+
const overflow_layout = try canvas.layoutWidgetTree(
|
|
2390
|
+
.{ .kind = .stack, .children = &overflow_children },
|
|
2391
|
+
geometry.RectF.init(0, 0, 220, 120),
|
|
2392
|
+
&overflow_nodes,
|
|
2393
|
+
);
|
|
2394
|
+
try std.testing.expectError(
|
|
2395
|
+
error.WidgetAnchoredSurfaceLimitReached,
|
|
2396
|
+
harness.runtime.setCanvasWidgetLayout(1, "canvas", overflow_layout),
|
|
2397
|
+
);
|
|
2398
|
+
|
|
2399
|
+
// The failed adoption changed NOTHING: the old tree is still
|
|
2400
|
+
// retained with its tooltip visibly shown, and the registers still
|
|
2401
|
+
// own that stamp.
|
|
2402
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2403
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
2404
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2405
|
+
|
|
2406
|
+
// And the tooltip stays HIDEABLE through a normal transition: the
|
|
2407
|
+
// pointer leaving the trigger hides it exactly as if the failed
|
|
2408
|
+
// rebuild never happened.
|
|
2409
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 110 }, tooltip_t0 + 200 * tooltip_ms);
|
|
2410
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2411
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
/// The rebuild-relocation fixture: a wrapper stack at an
|
|
2415
|
+
/// author-controlled x carrying the trigger (id 2) and its anchored
|
|
2416
|
+
/// tooltip (id 3) — same ids at every position, so a rebuild that
|
|
2417
|
+
/// moves the stack relocates the SAME binding instead of breaking it
|
|
2418
|
+
/// (the prune keeps it; only geometry changed).
|
|
2419
|
+
fn setTooltipRelocationLayout(harness: anytype, trigger_x: f32, delay_ms: i32) !void {
|
|
2420
|
+
const children = [_]canvas.Widget{
|
|
2421
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 96, 32), .text = "Run" },
|
|
2422
|
+
.{ .id = 3, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = delay_ms, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
2423
|
+
};
|
|
2424
|
+
const stacks = [_]canvas.Widget{
|
|
2425
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(trigger_x, 60, 96, 32), .children = &children },
|
|
2426
|
+
};
|
|
2427
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2428
|
+
const layout = try canvas.layoutWidgetTree(
|
|
2429
|
+
.{ .id = 1, .kind = .stack, .children = &stacks },
|
|
2430
|
+
geometry.RectF.init(0, 0, 320, 160),
|
|
2431
|
+
&nodes,
|
|
2432
|
+
);
|
|
2433
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
fn installTooltipRelocationView(harness: anytype, app: App) !void {
|
|
2437
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2438
|
+
try harness.start(app);
|
|
2439
|
+
_ = try harness.runtime.createView(.{
|
|
2440
|
+
.window_id = 1,
|
|
2441
|
+
.label = "canvas",
|
|
2442
|
+
.kind = .gpu_surface,
|
|
2443
|
+
.frame = geometry.RectF.init(0, 0, 320, 160),
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
test "a rebuild that relocates the same-ID trigger away from the stationary pointer disarms and hides" {
|
|
2448
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2449
|
+
defer harness.destroy(std.testing.allocator);
|
|
2450
|
+
const TestApp = struct {
|
|
2451
|
+
fn app(self: *@This()) App {
|
|
2452
|
+
return .{ .context = self, .name = "gpu-tooltip-relocate-away", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2453
|
+
}
|
|
2454
|
+
};
|
|
2455
|
+
var app_state: TestApp = .{};
|
|
2456
|
+
const app = app_state.app();
|
|
2457
|
+
try installTooltipRelocationView(harness, app);
|
|
2458
|
+
try setTooltipRelocationLayout(harness, 10, -1);
|
|
2459
|
+
|
|
2460
|
+
// Arm the default dwell on the trigger, then rebuild with the SAME
|
|
2461
|
+
// ids relocated away from the stationary pointer: identity survives
|
|
2462
|
+
// the prune, but the re-hit-test sees the pointer over nothing —
|
|
2463
|
+
// the armed intent disarms on the rebuild itself, and frames past
|
|
2464
|
+
// the would-be deadline reveal nothing.
|
|
2465
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 76 }, tooltip_t0);
|
|
2466
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2467
|
+
try setTooltipRelocationLayout(harness, 180, -1);
|
|
2468
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2469
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2470
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
2471
|
+
try tooltipFrame(harness, app, tooltip_t0 + 800 * tooltip_ms);
|
|
2472
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2473
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2474
|
+
|
|
2475
|
+
// Earn the SHOWN tooltip back in place, then relocate again: the
|
|
2476
|
+
// shown tooltip hides on the rebuild itself — no pointer event, no
|
|
2477
|
+
// frame needed — with the usual pointer-hide warmth (the content
|
|
2478
|
+
// moved, not the pointer: no transit corridor applies).
|
|
2479
|
+
try setTooltipRelocationLayout(harness, 10, -1);
|
|
2480
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 76 }, tooltip_t0 + 900 * tooltip_ms);
|
|
2481
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1500 * tooltip_ms);
|
|
2482
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2483
|
+
try setTooltipRelocationLayout(harness, 180, -1);
|
|
2484
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2485
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2486
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
2487
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2500 * tooltip_ms);
|
|
2488
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
test "a rebuild that moves a trigger under the stored pointer arms the normal dwell" {
|
|
2492
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2493
|
+
defer harness.destroy(std.testing.allocator);
|
|
2494
|
+
const TestApp = struct {
|
|
2495
|
+
fn app(self: *@This()) App {
|
|
2496
|
+
return .{ .context = self, .name = "gpu-tooltip-relocate-under", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2497
|
+
}
|
|
2498
|
+
};
|
|
2499
|
+
var app_state: TestApp = .{};
|
|
2500
|
+
const app = app_state.app();
|
|
2501
|
+
try installTooltipRelocationView(harness, app);
|
|
2502
|
+
try setTooltipRelocationLayout(harness, 180, -1);
|
|
2503
|
+
|
|
2504
|
+
// Park the pointer over empty space (seeding the stored position,
|
|
2505
|
+
// earning no warmth), then rebuild with the trigger relocated
|
|
2506
|
+
// UNDER it: the re-hit-test arms the normal dwell — owner recorded,
|
|
2507
|
+
// corridor apex seeded from the stored truth — and the dwell
|
|
2508
|
+
// completes on the frame clock like any other.
|
|
2509
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 76 }, tooltip_t0);
|
|
2510
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2511
|
+
try setTooltipRelocationLayout(harness, 10, -1);
|
|
2512
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2513
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2514
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2515
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_deadline_ns != 0);
|
|
2516
|
+
try std.testing.expectEqual(@as(f32, 58), harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
2517
|
+
try std.testing.expectEqual(@as(f32, 76), harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
2518
|
+
try tooltipFrame(harness, app, tooltip_t0 + 700 * tooltip_ms);
|
|
2519
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2520
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
test "a rebuild re-checks the content hold against the tooltip's new frame" {
|
|
2524
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2525
|
+
defer harness.destroy(std.testing.allocator);
|
|
2526
|
+
const TestApp = struct {
|
|
2527
|
+
fn app(self: *@This()) App {
|
|
2528
|
+
return .{ .context = self, .name = "gpu-tooltip-relocate-held", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
var app_state: TestApp = .{};
|
|
2532
|
+
const app = app_state.app();
|
|
2533
|
+
try installTooltipRelocationView(harness, app);
|
|
2534
|
+
try setTooltipRelocationLayout(harness, 10, 0);
|
|
2535
|
+
|
|
2536
|
+
// Show instantly (delay 0) and park the pointer INSIDE the
|
|
2537
|
+
// tooltip's frame: the content hold, with hovered_id == 0 (the
|
|
2538
|
+
// tooltip is not a hit target) — the exact state no hover
|
|
2539
|
+
// transition can see.
|
|
2540
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 76 }, tooltip_t0);
|
|
2541
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2542
|
+
const held_point = (try tooltipNodeFrame(harness, 3)).center();
|
|
2543
|
+
try tooltipHover(harness, app, held_point, tooltip_t0 + 100 * tooltip_ms);
|
|
2544
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2545
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2546
|
+
|
|
2547
|
+
// An unchanged rebuild keeps the hold: the containment re-check
|
|
2548
|
+
// against the (same) adopted frame still passes and re-seeds the
|
|
2549
|
+
// corridor apex from the stored position.
|
|
2550
|
+
try setTooltipRelocationLayout(harness, 10, 0);
|
|
2551
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2552
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2553
|
+
try std.testing.expectEqual(held_point.x, harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
2554
|
+
try std.testing.expectEqual(held_point.y, harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
2555
|
+
|
|
2556
|
+
// A rebuild that MOVES the tooltip's frame out from under the
|
|
2557
|
+
// stationary pointer breaks the hold honestly: hidden on the
|
|
2558
|
+
// rebuild itself, usual warmth, and no frame resurrects it.
|
|
2559
|
+
try setTooltipRelocationLayout(harness, 180, 0);
|
|
2560
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2561
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2562
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
2563
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1000 * tooltip_ms);
|
|
2564
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2565
|
+
}
|
|
2566
|
+
|
|
2567
|
+
test "a rebuild without a trustworthy pointer position closes pointer intent, focus-shown survives" {
|
|
2568
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2569
|
+
defer harness.destroy(std.testing.allocator);
|
|
2570
|
+
const TestApp = struct {
|
|
2571
|
+
fn app(self: *@This()) App {
|
|
2572
|
+
return .{ .context = self, .name = "gpu-tooltip-relocate-blind", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2573
|
+
}
|
|
2574
|
+
};
|
|
2575
|
+
var app_state: TestApp = .{};
|
|
2576
|
+
const app = app_state.app();
|
|
2577
|
+
try installTooltipRelocationView(harness, app);
|
|
2578
|
+
try setTooltipRelocationLayout(harness, 10, -1);
|
|
2579
|
+
|
|
2580
|
+
// A keyboard-only session: tab earns the focus-shown tooltip, and
|
|
2581
|
+
// a rebuild (no stored pointer position anywhere) leaves it alone —
|
|
2582
|
+
// the keyboard holds it; the blind close is pointer-owned only.
|
|
2583
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
2584
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2585
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
2586
|
+
try setTooltipRelocationLayout(harness, 180, -1);
|
|
2587
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2588
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
2589
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2590
|
+
|
|
2591
|
+
// Pointer-owned intent with no position to re-hit-test closes on
|
|
2592
|
+
// the rebuild — the blind-scroll policy. Seed an armed dwell and a
|
|
2593
|
+
// warm window directly (no pointer event may seed the store).
|
|
2594
|
+
harness.runtime.views[0].canvas_tooltip_armed_id = 3;
|
|
2595
|
+
harness.runtime.views[0].canvas_tooltip_armed_owner_id = 2;
|
|
2596
|
+
harness.runtime.views[0].canvas_tooltip_deadline_ns = tooltip_t0 + 1000 * tooltip_ms;
|
|
2597
|
+
harness.runtime.views[0].canvas_tooltip_warm_until_ns = tooltip_t0 + 5000 * tooltip_ms;
|
|
2598
|
+
try setTooltipRelocationLayout(harness, 10, -1);
|
|
2599
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2600
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2601
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
2602
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
2603
|
+
// And the focus-shown tooltip still stands after the pointer-owned
|
|
2604
|
+
// close.
|
|
2605
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2606
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
test "an unchanged rebuild with a hidden anchored tooltip diffs clean" {
|
|
2610
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2611
|
+
defer harness.destroy(std.testing.allocator);
|
|
2612
|
+
const TestApp = struct {
|
|
2613
|
+
fn app(self: *@This()) App {
|
|
2614
|
+
return .{ .context = self, .name = "gpu-tooltip-rebuild-clean", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2615
|
+
}
|
|
2616
|
+
};
|
|
2617
|
+
var app_state: TestApp = .{};
|
|
2618
|
+
const app = app_state.app();
|
|
2619
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2620
|
+
try harness.start(app);
|
|
2621
|
+
_ = try harness.runtime.createView(.{
|
|
2622
|
+
.window_id = 1,
|
|
2623
|
+
.label = "canvas",
|
|
2624
|
+
.kind = .gpu_surface,
|
|
2625
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
2626
|
+
});
|
|
2627
|
+
const children = tooltipRebuildChildren(2, false);
|
|
2628
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2629
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
2630
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2631
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2632
|
+
|
|
2633
|
+
// Rebuild the byte-identical tree: the runtime's own hidden stamp
|
|
2634
|
+
// is applied to the reconciled scratch BEFORE the diff, so the
|
|
2635
|
+
// rebuild reports NO invalidation and accumulates no dirty region —
|
|
2636
|
+
// the source's authored visibility never reaches the diff.
|
|
2637
|
+
harness.runtime.invalidated = false;
|
|
2638
|
+
harness.runtime.dirty_region_count = 0;
|
|
2639
|
+
const frame_requests_before = harness.null_platform.gpu_surface_frame_request_count;
|
|
2640
|
+
var rebuild_nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2641
|
+
const rebuild_layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 120), &rebuild_nodes);
|
|
2642
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", rebuild_layout);
|
|
2643
|
+
|
|
2644
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
2645
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
2646
|
+
// Exactly the one settle request every rebuild performs
|
|
2647
|
+
// unconditionally (widget-revision bookkeeping, tooltip or not):
|
|
2648
|
+
// the hidden tooltip adds nothing on top of it.
|
|
2649
|
+
try std.testing.expectEqual(frame_requests_before + 1, harness.null_platform.gpu_surface_frame_request_count);
|
|
2650
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
test "a shown tooltip keeps its visible state across an unchanged rebuild without flicker" {
|
|
2654
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2655
|
+
defer harness.destroy(std.testing.allocator);
|
|
2656
|
+
const TestApp = struct {
|
|
2657
|
+
fn app(self: *@This()) App {
|
|
2658
|
+
return .{ .context = self, .name = "gpu-tooltip-rebuild-shown", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
var app_state: TestApp = .{};
|
|
2662
|
+
const app = app_state.app();
|
|
2663
|
+
try installTooltipRebuildFixture(harness, app);
|
|
2664
|
+
|
|
2665
|
+
// Rebuild the same tree while the tooltip is SHOWN: the pre-diff
|
|
2666
|
+
// prune (against the reconciled tree) keeps the binding alive, so
|
|
2667
|
+
// the pre-diff stamp marks the scratch tooltip VISIBLE and the
|
|
2668
|
+
// diff stays clean — the retained node never passes through a
|
|
2669
|
+
// hidden state, so there is no hide-then-show frame pair to paint.
|
|
2670
|
+
harness.runtime.invalidated = false;
|
|
2671
|
+
harness.runtime.dirty_region_count = 0;
|
|
2672
|
+
const children = tooltipRebuildChildren(2, false);
|
|
2673
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2674
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &children }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
2675
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2676
|
+
|
|
2677
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2678
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2679
|
+
try std.testing.expect(!harness.runtime.invalidated);
|
|
2680
|
+
try std.testing.expectEqual(@as(usize, 0), harness.runtime.pendingDirtyRegions().len);
|
|
2681
|
+
|
|
2682
|
+
// And the frame clock advancing past any stale deadline changes
|
|
2683
|
+
// nothing: the rebuild carried no armed state to fire.
|
|
2684
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
2685
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2686
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
// ------------------------------------------- adoption binding changes
|
|
2690
|
+
//
|
|
2691
|
+
// A reactive rebuild that ADDS, REPLACES, or REKEYS a tooltip beneath
|
|
2692
|
+
// an owner whose own ID is stable produces no hover delta (the
|
|
2693
|
+
// re-hit-test resolves the same trigger) and no stale register (there
|
|
2694
|
+
// was no intent bound to the NEW tooltip for the prune to validate),
|
|
2695
|
+
// so only the adoption binding-change step can see it. These tests pin
|
|
2696
|
+
// the matrix — mount/replace/unmount x hovered/focus-visible x
|
|
2697
|
+
// armed/shown — plus the unchanged-binding rebuild staying inert.
|
|
2698
|
+
|
|
2699
|
+
/// Stable-owner binding fixture: the trigger keeps id 2 in every
|
|
2700
|
+
/// variant while the tooltip beneath it mounts (`tooltip_id` != 0),
|
|
2701
|
+
/// unmounts (0), or rekeys (a different id). `trigger_kind` lets the
|
|
2702
|
+
/// provenance test swap the button for an editable field.
|
|
2703
|
+
fn setTooltipBindingLayoutInWindow(runtime: *Runtime, window_id: platform.WindowId, trigger_kind: canvas.WidgetKind, tooltip_id: canvas.ObjectId, delay_ms: i32) !void {
|
|
2704
|
+
var children: [2]canvas.Widget = undefined;
|
|
2705
|
+
children[0] = .{
|
|
2706
|
+
.id = 2,
|
|
2707
|
+
.kind = trigger_kind,
|
|
2708
|
+
.frame = geometry.RectF.init(10, 40, 96, 32),
|
|
2709
|
+
.text = "Run",
|
|
2710
|
+
};
|
|
2711
|
+
var child_count: usize = 1;
|
|
2712
|
+
if (tooltip_id != 0) {
|
|
2713
|
+
children[child_count] = .{
|
|
2714
|
+
.id = tooltip_id,
|
|
2715
|
+
.kind = .tooltip,
|
|
2716
|
+
.text = "Runs the job",
|
|
2717
|
+
.tooltip_delay_ms = delay_ms,
|
|
2718
|
+
.layout = .{ .anchor = .{ .placement = .above } },
|
|
2719
|
+
};
|
|
2720
|
+
child_count += 1;
|
|
2721
|
+
}
|
|
2722
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
2723
|
+
const layout = try canvas.layoutWidgetTree(
|
|
2724
|
+
.{ .kind = .stack, .children = children[0..child_count] },
|
|
2725
|
+
geometry.RectF.init(0, 0, 220, 120),
|
|
2726
|
+
&nodes,
|
|
2727
|
+
);
|
|
2728
|
+
_ = try runtime.setCanvasWidgetLayout(window_id, "canvas", layout);
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
fn setTooltipBindingLayout(harness: anytype, trigger_kind: canvas.WidgetKind, tooltip_id: canvas.ObjectId, delay_ms: i32) !void {
|
|
2732
|
+
try setTooltipBindingLayoutInWindow(&harness.runtime, 1, trigger_kind, tooltip_id, delay_ms);
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
fn installTooltipBindingView(harness: anytype, app: App) !void {
|
|
2736
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2737
|
+
try harness.start(app);
|
|
2738
|
+
_ = try harness.runtime.createView(.{
|
|
2739
|
+
.window_id = 1,
|
|
2740
|
+
.label = "canvas",
|
|
2741
|
+
.kind = .gpu_surface,
|
|
2742
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
2743
|
+
});
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2746
|
+
test "a tooltip mounting beneath the hovered trigger mid-hover arms the fresh dwell" {
|
|
2747
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2748
|
+
defer harness.destroy(std.testing.allocator);
|
|
2749
|
+
const TestApp = struct {
|
|
2750
|
+
fn app(self: *@This()) App {
|
|
2751
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-mount", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
var app_state: TestApp = .{};
|
|
2755
|
+
const app = app_state.app();
|
|
2756
|
+
try installTooltipBindingView(harness, app);
|
|
2757
|
+
try setTooltipBindingLayout(harness, .button, 0, 0);
|
|
2758
|
+
|
|
2759
|
+
// Hover the bare trigger: nothing exists to arm.
|
|
2760
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
2761
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_hovered_id);
|
|
2762
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2763
|
+
|
|
2764
|
+
// The rebuild mounts the tooltip beneath the SAME trigger id: no
|
|
2765
|
+
// hover delta, no stale register — only the binding-change step
|
|
2766
|
+
// can arm it, and mounting mid-hover never insta-shows (the dwell
|
|
2767
|
+
// is the intent filter; a rebuild proves nothing about the user).
|
|
2768
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
2769
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2770
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2771
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2772
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2773
|
+
// Corridor apex seeded from the stored position, per normal arming.
|
|
2774
|
+
try std.testing.expectEqual(@as(f32, 58), harness.runtime.views[0].canvas_tooltip_pointer_from.x);
|
|
2775
|
+
try std.testing.expectEqual(@as(f32, 56), harness.runtime.views[0].canvas_tooltip_pointer_from.y);
|
|
2776
|
+
const deadline = harness.runtime.views[0].canvas_tooltip_deadline_ns;
|
|
2777
|
+
try std.testing.expect(deadline != 0);
|
|
2778
|
+
|
|
2779
|
+
// Movement WITHIN the trigger before the dwell behaves normally:
|
|
2780
|
+
// gliding within one trigger is free — same armed id, same
|
|
2781
|
+
// deadline, still hidden.
|
|
2782
|
+
try tooltipHover(harness, app, .{ .x = 70, .y = 60 }, tooltip_t0 + 100 * tooltip_ms);
|
|
2783
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2784
|
+
try std.testing.expectEqual(deadline, harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
2785
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2786
|
+
|
|
2787
|
+
// The dwell completes on the frame clock like any other.
|
|
2788
|
+
try tooltipFrame(harness, app, tooltip_t0 + 700 * tooltip_ms);
|
|
2789
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2790
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
2791
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
test "a rebuild that rekeys the tooltip beneath a shown trigger hides the old and re-earns the dwell" {
|
|
2795
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2796
|
+
defer harness.destroy(std.testing.allocator);
|
|
2797
|
+
const TestApp = struct {
|
|
2798
|
+
fn app(self: *@This()) App {
|
|
2799
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-rekey", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
var app_state: TestApp = .{};
|
|
2803
|
+
const app = app_state.app();
|
|
2804
|
+
try installTooltipBindingView(harness, app);
|
|
2805
|
+
try setTooltipBindingLayout(harness, .button, 3, 0);
|
|
2806
|
+
|
|
2807
|
+
// Delay 0: the hover itself shows tooltip 3.
|
|
2808
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
2809
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2810
|
+
|
|
2811
|
+
// Rekey the tooltip under the stable, still-hovered trigger: the
|
|
2812
|
+
// prune kills the old binding (a new id is a new widget) and
|
|
2813
|
+
// closes the warm window with it — no instant carry-over of the
|
|
2814
|
+
// old widget's show — and the binding-change step re-earns the
|
|
2815
|
+
// NEW tooltip through its own declared dwell.
|
|
2816
|
+
try setTooltipBindingLayout(harness, .button, 9, -1);
|
|
2817
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2818
|
+
try std.testing.expect(try tooltipHidden(harness, 9));
|
|
2819
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
2820
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2821
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2822
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_deadline_ns != 0);
|
|
2823
|
+
|
|
2824
|
+
// The fresh dwell completes on the frame clock.
|
|
2825
|
+
try tooltipFrame(harness, app, tooltip_t0 + 700 * tooltip_ms);
|
|
2826
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2827
|
+
try std.testing.expect(!try tooltipHidden(harness, 9));
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
test "a tooltip mounting beneath the focus-visible trigger reveals immediately" {
|
|
2831
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2832
|
+
defer harness.destroy(std.testing.allocator);
|
|
2833
|
+
const TestApp = struct {
|
|
2834
|
+
fn app(self: *@This()) App {
|
|
2835
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-focus", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2836
|
+
}
|
|
2837
|
+
};
|
|
2838
|
+
var app_state: TestApp = .{};
|
|
2839
|
+
const app = app_state.app();
|
|
2840
|
+
try installTooltipBindingView(harness, app);
|
|
2841
|
+
try setTooltipBindingLayout(harness, .button, 0, 0);
|
|
2842
|
+
|
|
2843
|
+
// Tab reaches the bare trigger: the ring stands, nothing reveals.
|
|
2844
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
2845
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2846
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2847
|
+
|
|
2848
|
+
// The rebuild mounts the tooltip beneath the standing KEYBOARD
|
|
2849
|
+
// focus-visible: it reveals on the rebuild itself — no dwell, no
|
|
2850
|
+
// frame — because focus is the user's standing intent (shadcn's
|
|
2851
|
+
// Base UI-backed instant focus-visible open). A keyboard-only
|
|
2852
|
+
// session has no stored pointer position, so this also pins the
|
|
2853
|
+
// blind-close path still running the focus half.
|
|
2854
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
2855
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2856
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_shown_owner_id);
|
|
2857
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
2858
|
+
try std.testing.expect(!try tooltipHidden(harness, 3));
|
|
2859
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2860
|
+
|
|
2861
|
+
// Rekey under the focus-SHOWN tooltip: the old binding dies in the
|
|
2862
|
+
// prune (old hides), and the new one re-earns per the FOCUS rule —
|
|
2863
|
+
// immediately, keyboard focus still standing.
|
|
2864
|
+
try setTooltipBindingLayout(harness, .button, 9, -1);
|
|
2865
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2866
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
2867
|
+
try std.testing.expect(!try tooltipHidden(harness, 9));
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
test "a tooltip mounting beneath a pointer-established ring arms the dwell, never the focus reveal" {
|
|
2871
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2872
|
+
defer harness.destroy(std.testing.allocator);
|
|
2873
|
+
const TestApp = struct {
|
|
2874
|
+
fn app(self: *@This()) App {
|
|
2875
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-caret", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2876
|
+
}
|
|
2877
|
+
};
|
|
2878
|
+
var app_state: TestApp = .{};
|
|
2879
|
+
const app = app_state.app();
|
|
2880
|
+
try installTooltipBindingView(harness, app);
|
|
2881
|
+
try setTooltipBindingLayout(harness, .text_field, 0, 0);
|
|
2882
|
+
|
|
2883
|
+
// Click INTO the editable: ring and caret however focus arrived
|
|
2884
|
+
// (the caret contract), but the provenance is the POINTER's.
|
|
2885
|
+
try tooltipPointer(harness, app, .pointer_down, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
2886
|
+
try tooltipPointer(harness, app, .pointer_up, .{ .x = 58, .y = 56 }, tooltip_t0 + 20 * tooltip_ms);
|
|
2887
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2888
|
+
|
|
2889
|
+
// The rebuild mounts the tooltip beneath that ring: NO immediate
|
|
2890
|
+
// reveal (Base UI's focus-visible guard against click-focus opens
|
|
2891
|
+
// extends to adoption-time bindings) — but the pointer honestly
|
|
2892
|
+
// rests on the trigger, so the HOVER half arms the normal dwell.
|
|
2893
|
+
try setTooltipBindingLayout(harness, .text_field, 3, -1);
|
|
2894
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2895
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2896
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2897
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
/// Two focus stops — the first trigger owns a rekeyable tooltip
|
|
2901
|
+
/// (`tooltip_id`), the second is a bare button — so Tab can genuinely
|
|
2902
|
+
/// LEAVE the trigger and return: a fresh keyboard arrival, not the
|
|
2903
|
+
/// early-returned in-place move a single-focusable tree would produce.
|
|
2904
|
+
fn setTooltipDismissalLayout(harness: anytype, tooltip_id: canvas.ObjectId) !void {
|
|
2905
|
+
const trigger_children = [_]canvas.Widget{
|
|
2906
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(0, 0, 160, 32), .text = "Run" },
|
|
2907
|
+
.{ .id = tooltip_id, .kind = .tooltip, .text = "Runs the job", .layout = .{ .anchor = .{ .placement = .below } } },
|
|
2908
|
+
};
|
|
2909
|
+
const stacks = [_]canvas.Widget{
|
|
2910
|
+
.{ .id = 4, .kind = .stack, .frame = geometry.RectF.init(0, 0, 160, 32), .children = &trigger_children },
|
|
2911
|
+
.{ .id = 6, .kind = .button, .frame = geometry.RectF.init(0, 80, 160, 32), .text = "Other" },
|
|
2912
|
+
};
|
|
2913
|
+
var nodes: [8]canvas.WidgetLayoutNode = undefined;
|
|
2914
|
+
const layout = try canvas.layoutWidgetTree(
|
|
2915
|
+
.{ .id = 1, .kind = .stack, .children = &stacks },
|
|
2916
|
+
geometry.RectF.init(0, 0, 220, 120),
|
|
2917
|
+
&nodes,
|
|
2918
|
+
);
|
|
2919
|
+
_ = try harness.runtime.setCanvasWidgetLayout(1, "canvas", layout);
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
test "keyboard activation's dismissal holds through the activation's own rebuild rekeying the tooltip" {
|
|
2923
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2924
|
+
defer harness.destroy(std.testing.allocator);
|
|
2925
|
+
const TestApp = struct {
|
|
2926
|
+
fn app(self: *@This()) App {
|
|
2927
|
+
return .{ .context = self, .name = "gpu-tooltip-activate-rekey", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2928
|
+
}
|
|
2929
|
+
};
|
|
2930
|
+
var app_state: TestApp = .{};
|
|
2931
|
+
const app = app_state.app();
|
|
2932
|
+
try installTooltipBindingView(harness, app);
|
|
2933
|
+
try setTooltipDismissalLayout(harness, 3);
|
|
2934
|
+
|
|
2935
|
+
// Tab reaches the trigger: focus-shown tooltip, keyboard ring.
|
|
2936
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
2937
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2938
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2939
|
+
|
|
2940
|
+
// Enter dismisses like a press — and the trigger stays visibly
|
|
2941
|
+
// focus-visible through the dismissal: the consumed register is
|
|
2942
|
+
// the reveal PROVENANCE, never the ring, which renders from
|
|
2943
|
+
// `canvas_widget_focus_visible_id`.
|
|
2944
|
+
try tooltipKey(harness, app, "enter", tooltip_t0 + 100 * tooltip_ms);
|
|
2945
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2946
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2947
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2948
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvasWidgetRenderState().focus_visible_id.?);
|
|
2949
|
+
|
|
2950
|
+
// The activation's own model rebuild rekeys the tooltip beneath
|
|
2951
|
+
// the still-focused trigger (3 -> 9): the adoption binding-
|
|
2952
|
+
// reconcile sees a changed binding under a standing ring, but the
|
|
2953
|
+
// dismissal SPENT the reveal intent — the tooltip stays down while
|
|
2954
|
+
// focus rests on the trigger, on the rebuild and on every later
|
|
2955
|
+
// frame.
|
|
2956
|
+
try setTooltipDismissalLayout(harness, 9);
|
|
2957
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2958
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
2959
|
+
try std.testing.expect(try tooltipHidden(harness, 9));
|
|
2960
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
2961
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2962
|
+
|
|
2963
|
+
// Tab away and back re-earns the immediate reveal: a fresh
|
|
2964
|
+
// keyboard ARRIVAL re-grants the contract at the one provenance
|
|
2965
|
+
// write.
|
|
2966
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1000 * tooltip_ms);
|
|
2967
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 6), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2968
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2969
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1100 * tooltip_ms);
|
|
2970
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2971
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2972
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
2973
|
+
try std.testing.expect(!try tooltipHidden(harness, 9));
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
test "escape's dismissal holds through a rebuild rekeying the tooltip, pointer dwell re-earns" {
|
|
2977
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
2978
|
+
defer harness.destroy(std.testing.allocator);
|
|
2979
|
+
const TestApp = struct {
|
|
2980
|
+
fn app(self: *@This()) App {
|
|
2981
|
+
return .{ .context = self, .name = "gpu-tooltip-escape-rekey", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
var app_state: TestApp = .{};
|
|
2985
|
+
const app = app_state.app();
|
|
2986
|
+
try installTooltipBindingView(harness, app);
|
|
2987
|
+
try setTooltipDismissalLayout(harness, 3);
|
|
2988
|
+
|
|
2989
|
+
// Tab reveals, Escape dismisses; the ring survives the dismissal.
|
|
2990
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
2991
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2992
|
+
try tooltipKey(harness, app, "escape", tooltip_t0 + 100 * tooltip_ms);
|
|
2993
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
2994
|
+
try std.testing.expect(try tooltipHidden(harness, 3));
|
|
2995
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
2996
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvasWidgetRenderState().focus_visible_id.?);
|
|
2997
|
+
|
|
2998
|
+
// A rebuild rekeys the tooltip beneath the still-focused trigger:
|
|
2999
|
+
// Escape's dismissal spent the standing reveal intent, so the
|
|
3000
|
+
// rekeyed tooltip stays down — "stays down while focus rests on
|
|
3001
|
+
// the trigger" holds against adoption, not only against
|
|
3002
|
+
// focus-visible transitions.
|
|
3003
|
+
try setTooltipDismissalLayout(harness, 9);
|
|
3004
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3005
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3006
|
+
try std.testing.expect(try tooltipHidden(harness, 9));
|
|
3007
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
3008
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3009
|
+
|
|
3010
|
+
// The pointer path is untouched by the spent keyboard intent: a
|
|
3011
|
+
// hover after the dismissal arms the normal dwell and completes on
|
|
3012
|
+
// the frame clock, exactly like any other hover.
|
|
3013
|
+
try tooltipHover(harness, app, .{ .x = 200, .y = 60 }, tooltip_t0 + 1000 * tooltip_ms);
|
|
3014
|
+
try tooltipHover(harness, app, .{ .x = 80, .y = 16 }, tooltip_t0 + 1100 * tooltip_ms);
|
|
3015
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3016
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3017
|
+
try tooltipFrame(harness, app, tooltip_t0 + 1800 * tooltip_ms);
|
|
3018
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3019
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
3020
|
+
try std.testing.expect(!try tooltipHidden(harness, 9));
|
|
3021
|
+
}
|
|
3022
|
+
|
|
3023
|
+
test "a rebuild that unmounts the tooltip beneath a hovered trigger disarms the pending dwell" {
|
|
3024
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3025
|
+
defer harness.destroy(std.testing.allocator);
|
|
3026
|
+
const TestApp = struct {
|
|
3027
|
+
fn app(self: *@This()) App {
|
|
3028
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-unmount", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3029
|
+
}
|
|
3030
|
+
};
|
|
3031
|
+
var app_state: TestApp = .{};
|
|
3032
|
+
const app = app_state.app();
|
|
3033
|
+
try installTooltipBindingView(harness, app);
|
|
3034
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
3035
|
+
|
|
3036
|
+
// Arm the dwell, then unmount the tooltip beneath the still-hovered
|
|
3037
|
+
// trigger: the transactional prune's case exactly (the armed
|
|
3038
|
+
// binding died with its tooltip node) — pinned here for the
|
|
3039
|
+
// binding matrix's completeness. Nothing fires later.
|
|
3040
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
3041
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3042
|
+
try setTooltipBindingLayout(harness, .button, 0, 0);
|
|
3043
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3044
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
3045
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
3046
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
3047
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
test "an unchanged-binding adoption leaves the armed dwell untouched" {
|
|
3051
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3052
|
+
defer harness.destroy(std.testing.allocator);
|
|
3053
|
+
const TestApp = struct {
|
|
3054
|
+
fn app(self: *@This()) App {
|
|
3055
|
+
return .{ .context = self, .name = "gpu-tooltip-binding-inert", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
var app_state: TestApp = .{};
|
|
3059
|
+
const app = app_state.app();
|
|
3060
|
+
try installTooltipBindingView(harness, app);
|
|
3061
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
3062
|
+
|
|
3063
|
+
// Arm the dwell, advance the frame clock (so any buggy RE-arm
|
|
3064
|
+
// would stamp a LATER deadline), then rebuild the identical tree:
|
|
3065
|
+
// the binding compares equal, so the adoption step stays silent —
|
|
3066
|
+
// same armed id, same deadline, same apex, nothing shown.
|
|
3067
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
3068
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3069
|
+
try tooltipFrame(harness, app, tooltip_t0 + 100 * tooltip_ms);
|
|
3070
|
+
const deadline = harness.runtime.views[0].canvas_tooltip_deadline_ns;
|
|
3071
|
+
try std.testing.expect(deadline != 0);
|
|
3072
|
+
|
|
3073
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
3074
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3075
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_tooltip_armed_owner_id);
|
|
3076
|
+
try std.testing.expectEqual(deadline, harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
3077
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3078
|
+
|
|
3079
|
+
// And the original dwell still completes on its own clock.
|
|
3080
|
+
try tooltipFrame(harness, app, tooltip_t0 + 700 * tooltip_ms);
|
|
3081
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
// ---------------------------------------- lifecycle blur (deactivate / key)
|
|
3085
|
+
//
|
|
3086
|
+
// A tooltip leaves WITH the whole window: app deactivation and window
|
|
3087
|
+
// key-loss end the tooltip conversation exactly like a view blur (the
|
|
3088
|
+
// platform convention — macOS help tags and web tooltips drop when
|
|
3089
|
+
// their window stops hearing the user), and reactivation reveals
|
|
3090
|
+
// nothing, because both reveal paths are transition-edge-triggered.
|
|
3091
|
+
|
|
3092
|
+
fn tooltipHoverInWindow(harness: anytype, app: App, window_id: platform.WindowId, point: geometry.PointF, timestamp_ns: u64) !void {
|
|
3093
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_input = .{
|
|
3094
|
+
.window_id = window_id,
|
|
3095
|
+
.label = "canvas",
|
|
3096
|
+
.kind = .pointer_move,
|
|
3097
|
+
.x = point.x,
|
|
3098
|
+
.y = point.y,
|
|
3099
|
+
.timestamp_ns = timestamp_ns,
|
|
3100
|
+
} });
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
fn tooltipHiddenInView(harness: anytype, view_index: usize, tooltip_id: canvas.ObjectId) !bool {
|
|
3104
|
+
const view = &harness.runtime.views[view_index];
|
|
3105
|
+
const node_index = view.canvasWidgetNodeIndexById(tooltip_id) orelse return error.TestUnexpectedResult;
|
|
3106
|
+
return view.widget_layout_nodes[node_index].widget.semantics.hidden;
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
test "app deactivation hides the focus-shown tooltip and reactivation reveals nothing" {
|
|
3110
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3111
|
+
defer harness.destroy(std.testing.allocator);
|
|
3112
|
+
const TestApp = struct {
|
|
3113
|
+
fn app(self: *@This()) App {
|
|
3114
|
+
return .{ .context = self, .name = "gpu-tooltip-deactivate-focus", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3115
|
+
}
|
|
3116
|
+
};
|
|
3117
|
+
var app_state: TestApp = .{};
|
|
3118
|
+
const app = app_state.app();
|
|
3119
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
3120
|
+
defer arena.deinit();
|
|
3121
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
3122
|
+
|
|
3123
|
+
// Tab earns Bold's focus-shown tooltip.
|
|
3124
|
+
try tooltipKey(harness, app, "tab", tooltip_t0);
|
|
3125
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3126
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
3127
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
3128
|
+
|
|
3129
|
+
// The app deactivates: the tooltip leaves with the window — hidden
|
|
3130
|
+
// re-stamped (no stale visible node in the a11y tree), the shown
|
|
3131
|
+
// slot and its focus ownership cleared.
|
|
3132
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_deactivated);
|
|
3133
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3134
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
3135
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
3136
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
3137
|
+
|
|
3138
|
+
// Widget focus bookkeeping survives (focus returns where it was),
|
|
3139
|
+
// but reactivation replays no focus-visible TRANSITION, so nothing
|
|
3140
|
+
// re-reveals — not on the activate, not on any later frame.
|
|
3141
|
+
try std.testing.expectEqual(toolbar.button_ids[0], harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
3142
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_activated);
|
|
3143
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
3144
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3145
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
3146
|
+
|
|
3147
|
+
// A fresh focus-visible ARRIVAL re-earns the reveal.
|
|
3148
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 1000 * tooltip_ms);
|
|
3149
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[1], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3150
|
+
try std.testing.expect(!try tooltipHidden(harness, toolbar.tooltip_ids[1]));
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
test "app deactivation ends the pointer tooltip conversation: shown hides, warm dies, armed disarms" {
|
|
3154
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3155
|
+
defer harness.destroy(std.testing.allocator);
|
|
3156
|
+
const TestApp = struct {
|
|
3157
|
+
fn app(self: *@This()) App {
|
|
3158
|
+
return .{ .context = self, .name = "gpu-tooltip-deactivate-pointer", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3159
|
+
}
|
|
3160
|
+
};
|
|
3161
|
+
var app_state: TestApp = .{};
|
|
3162
|
+
const app = app_state.app();
|
|
3163
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
3164
|
+
defer arena.deinit();
|
|
3165
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
3166
|
+
|
|
3167
|
+
// Earn Link's tooltip by hover (delay 0), then leave it: the hide
|
|
3168
|
+
// opens the warm skip window.
|
|
3169
|
+
try tooltipHoverInWindow(harness, app, 1, toolbar.button_centers[2], tooltip_t0);
|
|
3170
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3171
|
+
try tooltipHoverInWindow(harness, app, 1, .{ .x = 5, .y = 150 }, tooltip_t0 + 100 * tooltip_ms);
|
|
3172
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_warm_until_ns != 0);
|
|
3173
|
+
|
|
3174
|
+
// Deactivation kills the warmth with everything else: the user
|
|
3175
|
+
// left the app, so the next hover after reactivation must re-earn
|
|
3176
|
+
// the full delay instead of warm-showing instantly.
|
|
3177
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_deactivated);
|
|
3178
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
3179
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3180
|
+
// The stored pointer position deliberately survives (the pointer
|
|
3181
|
+
// may still be over the window): pointer truth belongs to the
|
|
3182
|
+
// pointer channel, whose own cancel clears it on hosts that scope
|
|
3183
|
+
// hover delivery to the key window.
|
|
3184
|
+
try std.testing.expect(harness.runtime.views[0].canvas_last_pointer_position != null);
|
|
3185
|
+
|
|
3186
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_activated);
|
|
3187
|
+
try tooltipHoverInWindow(harness, app, 1, toolbar.button_centers[0], tooltip_t0 + 200 * tooltip_ms);
|
|
3188
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[0], harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3189
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3190
|
+
|
|
3191
|
+
// Deactivating with an ARMED delay disarms it: the deadline never
|
|
3192
|
+
// fires, no matter how far the frame clock advances afterward.
|
|
3193
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_deactivated);
|
|
3194
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3195
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
3196
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_activated);
|
|
3197
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
3198
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3199
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[0]));
|
|
3200
|
+
}
|
|
3201
|
+
|
|
3202
|
+
test "window key-loss hides tooltips in that window's views only, re-key reveals nothing" {
|
|
3203
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3204
|
+
defer harness.destroy(std.testing.allocator);
|
|
3205
|
+
const TestApp = struct {
|
|
3206
|
+
fn app(self: *@This()) App {
|
|
3207
|
+
return .{ .context = self, .name = "gpu-tooltip-key-loss", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
var app_state: TestApp = .{};
|
|
3211
|
+
const app = app_state.app();
|
|
3212
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
3213
|
+
defer arena.deinit();
|
|
3214
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
3215
|
+
|
|
3216
|
+
// A second window with its own canvas view and a delay-0 tooltip.
|
|
3217
|
+
const second = try harness.runtime.createWindow(.{ .label = "tools", .title = "Tools" });
|
|
3218
|
+
_ = try harness.runtime.createView(.{
|
|
3219
|
+
.window_id = second.id,
|
|
3220
|
+
.label = "canvas",
|
|
3221
|
+
.kind = .gpu_surface,
|
|
3222
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
3223
|
+
});
|
|
3224
|
+
const second_children = [_]canvas.Widget{
|
|
3225
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 40, 96, 32), .text = "Run" },
|
|
3226
|
+
.{ .id = 3, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
3227
|
+
};
|
|
3228
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
3229
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &second_children }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
3230
|
+
_ = try harness.runtime.setCanvasWidgetLayout(second.id, "canvas", layout);
|
|
3231
|
+
|
|
3232
|
+
// The startup window holds key; its hover earns normally. The
|
|
3233
|
+
// NON-key second window earns NOTHING from the same hover — hosts
|
|
3234
|
+
// with always-active tracking areas deliver these for real, and a
|
|
3235
|
+
// window the user is not keyed into reveals and arms nothing. The
|
|
3236
|
+
// hover bookkeeping itself stays truthful (washes, stored pointer):
|
|
3237
|
+
// only tooltip ACTION is suppressed.
|
|
3238
|
+
try std.testing.expect(harness.runtime.windows[0].info.focused);
|
|
3239
|
+
try tooltipHoverInWindow(harness, app, 1, toolbar.button_centers[2], tooltip_t0);
|
|
3240
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3241
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 58, .y = 56 }, tooltip_t0 + 50 * tooltip_ms);
|
|
3242
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[1].canvas_widget_hovered_id);
|
|
3243
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3244
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_armed_id);
|
|
3245
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3246
|
+
|
|
3247
|
+
// The second window becomes key: the FIRST window's tooltip leaves
|
|
3248
|
+
// with its key status — and the key GAIN reveals nothing in the
|
|
3249
|
+
// second window (no transition replays), even though the pointer
|
|
3250
|
+
// still rests on its trigger.
|
|
3251
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_focused = second.id });
|
|
3252
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3253
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
3254
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3255
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3256
|
+
|
|
3257
|
+
// A FRESH hover transition in the now-key window earns per the
|
|
3258
|
+
// normal rules (delay 0: instant).
|
|
3259
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 200, .y = 10 }, tooltip_t0 + 100 * tooltip_ms);
|
|
3260
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 58, .y = 56 }, tooltip_t0 + 150 * tooltip_ms);
|
|
3261
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3262
|
+
try std.testing.expect(!try tooltipHiddenInView(harness, 1, 3));
|
|
3263
|
+
|
|
3264
|
+
// Key returns to the first window: the second window's tooltip now
|
|
3265
|
+
// drops, and the first window's does NOT spontaneously re-reveal —
|
|
3266
|
+
// a key gain replays no hover or focus-visible transition.
|
|
3267
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_focused = 1 });
|
|
3268
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3269
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3270
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3271
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3274
|
+
test "window key-loss announced loss-first (Windows/GTK ordering) hides the tooltip at the loss itself" {
|
|
3275
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3276
|
+
defer harness.destroy(std.testing.allocator);
|
|
3277
|
+
const TestApp = struct {
|
|
3278
|
+
fn app(self: *@This()) App {
|
|
3279
|
+
return .{ .context = self, .name = "gpu-tooltip-key-loss-first", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3280
|
+
}
|
|
3281
|
+
};
|
|
3282
|
+
var app_state: TestApp = .{};
|
|
3283
|
+
const app = app_state.app();
|
|
3284
|
+
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
|
3285
|
+
defer arena.deinit();
|
|
3286
|
+
const toolbar = try installTooltipToolbar(harness, app, arena.allocator());
|
|
3287
|
+
|
|
3288
|
+
// A second window with its own canvas view and a delay-0 tooltip,
|
|
3289
|
+
// exactly like the gain-only key-loss test above.
|
|
3290
|
+
const second = try harness.runtime.createWindow(.{ .label = "tools", .title = "Tools" });
|
|
3291
|
+
_ = try harness.runtime.createView(.{
|
|
3292
|
+
.window_id = second.id,
|
|
3293
|
+
.label = "canvas",
|
|
3294
|
+
.kind = .gpu_surface,
|
|
3295
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
3296
|
+
});
|
|
3297
|
+
const second_children = [_]canvas.Widget{
|
|
3298
|
+
.{ .id = 2, .kind = .button, .frame = geometry.RectF.init(10, 40, 96, 32), .text = "Run" },
|
|
3299
|
+
.{ .id = 3, .kind = .tooltip, .text = "Runs the job", .tooltip_delay_ms = 0, .layout = .{ .anchor = .{ .placement = .above } } },
|
|
3300
|
+
};
|
|
3301
|
+
var nodes: [4]canvas.WidgetLayoutNode = undefined;
|
|
3302
|
+
const layout = try canvas.layoutWidgetTree(.{ .kind = .stack, .children = &second_children }, geometry.RectF.init(0, 0, 220, 120), &nodes);
|
|
3303
|
+
_ = try harness.runtime.setCanvasWidgetLayout(second.id, "canvas", layout);
|
|
3304
|
+
|
|
3305
|
+
// The startup window holds key; hover earns Link's delay-0 tooltip.
|
|
3306
|
+
try std.testing.expect(harness.runtime.windows[0].info.focused);
|
|
3307
|
+
try tooltipHoverInWindow(harness, app, 1, toolbar.button_centers[2], tooltip_t0);
|
|
3308
|
+
try std.testing.expectEqual(toolbar.tooltip_ids[2], harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3309
|
+
|
|
3310
|
+
// Windows and GTK announce the key change LOSS-first: a state echo
|
|
3311
|
+
// carrying focused=false for the window the user left, BEFORE any
|
|
3312
|
+
// gain event for the next one. The tooltip must hide AT the loss —
|
|
3313
|
+
// the later gain's dethroning loop sees this window already
|
|
3314
|
+
// unfocused, so nothing downstream can fire it.
|
|
3315
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_frame_changed = .{
|
|
3316
|
+
.id = 1,
|
|
3317
|
+
.label = harness.runtime.windows[0].info.label,
|
|
3318
|
+
.title = harness.runtime.windows[0].info.title,
|
|
3319
|
+
.frame = harness.runtime.windows[0].info.frame,
|
|
3320
|
+
.focused = false,
|
|
3321
|
+
} });
|
|
3322
|
+
try std.testing.expect(!harness.runtime.windows[0].info.focused);
|
|
3323
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3324
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
3325
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
3326
|
+
|
|
3327
|
+
// The gain lands afterwards: it changes nothing about the first
|
|
3328
|
+
// window (already unfocused, already reset) and reveals nothing in
|
|
3329
|
+
// the second (a key gain replays no transition).
|
|
3330
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_focused = second.id });
|
|
3331
|
+
try std.testing.expect(harness.runtime.windows[1].info.focused);
|
|
3332
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3333
|
+
try std.testing.expect(try tooltipHidden(harness, toolbar.tooltip_ids[2]));
|
|
3334
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3335
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3336
|
+
|
|
3337
|
+
// A fresh hover transition in the now-key second window earns
|
|
3338
|
+
// instantly (delay 0)...
|
|
3339
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 200, .y = 10 }, tooltip_t0 + 100 * tooltip_ms);
|
|
3340
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 58, .y = 56 }, tooltip_t0 + 150 * tooltip_ms);
|
|
3341
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3342
|
+
try std.testing.expect(!try tooltipHiddenInView(harness, 1, 3));
|
|
3343
|
+
|
|
3344
|
+
// ...and a loss with NO subsequent gain — the user keyed into some
|
|
3345
|
+
// other app's window, so every tracked window is now inactive —
|
|
3346
|
+
// still resets: the seam observes the flag's own edge, not any
|
|
3347
|
+
// gain's dethroning loop.
|
|
3348
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_frame_changed = .{
|
|
3349
|
+
.id = second.id,
|
|
3350
|
+
.label = harness.runtime.windows[1].info.label,
|
|
3351
|
+
.title = harness.runtime.windows[1].info.title,
|
|
3352
|
+
.frame = harness.runtime.windows[1].info.frame,
|
|
3353
|
+
.focused = false,
|
|
3354
|
+
} });
|
|
3355
|
+
try std.testing.expect(!harness.runtime.windows[0].info.focused);
|
|
3356
|
+
try std.testing.expect(!harness.runtime.windows[1].info.focused);
|
|
3357
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3358
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
test "a rebuild from the deactivation callback reveals and arms nothing while the app is inactive" {
|
|
3362
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3363
|
+
defer harness.destroy(std.testing.allocator);
|
|
3364
|
+
const TestApp = struct {
|
|
3365
|
+
rebuilt: bool = false,
|
|
3366
|
+
|
|
3367
|
+
fn app(self: *@This()) App {
|
|
3368
|
+
return .{ .context = self, .name = "gpu-tooltip-deactivate-rebuild", .source = platform.WebViewSource.html("<h1>GPU</h1>"), .event_fn = event };
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
// The deactivate callback rebuilds the tree, swapping the
|
|
3372
|
+
// trigger's tooltip binding (3 -> 9): the adoption
|
|
3373
|
+
// binding-reconcile then sees a changed binding beneath BOTH
|
|
3374
|
+
// the retained keyboard focus ring and the stored hover — the
|
|
3375
|
+
// exact state that revealed and armed mid-deactivation before
|
|
3376
|
+
// the inactive guard, undoing the blur one dispatch later.
|
|
3377
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
3378
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
3379
|
+
switch (event_value) {
|
|
3380
|
+
.lifecycle => |lifecycle| {
|
|
3381
|
+
if (lifecycle != .deactivate) return;
|
|
3382
|
+
self.rebuilt = true;
|
|
3383
|
+
try setTooltipBindingLayoutInWindow(runtime, 1, .button, 9, -1);
|
|
3384
|
+
},
|
|
3385
|
+
else => {},
|
|
3386
|
+
}
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
var app_state: TestApp = .{};
|
|
3390
|
+
const app = app_state.app();
|
|
3391
|
+
try installTooltipBindingView(harness, app);
|
|
3392
|
+
try setTooltipBindingLayout(harness, .button, 3, -1);
|
|
3393
|
+
|
|
3394
|
+
// Standing pointer hover AND keyboard focus-visible on the trigger:
|
|
3395
|
+
// the tab reveal takes the shown slot (focus-owned) and clears the
|
|
3396
|
+
// redundant dwell.
|
|
3397
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
3398
|
+
try tooltipKey(harness, app, "tab", tooltip_t0 + 10 * tooltip_ms);
|
|
3399
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3400
|
+
try std.testing.expect(harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
3401
|
+
|
|
3402
|
+
// Deactivation: the reset hides tooltip 3, THEN the callback's
|
|
3403
|
+
// rebuild adopts the swapped binding while the app is inactive —
|
|
3404
|
+
// nothing reveals, nothing arms, and the new tooltip's semantics
|
|
3405
|
+
// stamp hidden (no stale visible node one dispatch after the blur).
|
|
3406
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_deactivated);
|
|
3407
|
+
try std.testing.expect(app_state.rebuilt);
|
|
3408
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3409
|
+
try std.testing.expect(!harness.runtime.views[0].canvas_tooltip_shown_from_focus);
|
|
3410
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3411
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_deadline_ns);
|
|
3412
|
+
try std.testing.expectEqual(@as(u64, 0), harness.runtime.views[0].canvas_tooltip_warm_until_ns);
|
|
3413
|
+
try std.testing.expect(try tooltipHidden(harness, 9));
|
|
3414
|
+
|
|
3415
|
+
// Suppression gates ACTION only: the keyboard provenance register
|
|
3416
|
+
// and the stored pointer survive, preserved for the next honest
|
|
3417
|
+
// transition — acting on them while inactive was the bug, never
|
|
3418
|
+
// their persistence.
|
|
3419
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[0].canvas_widget_focus_visible_id);
|
|
3420
|
+
try std.testing.expect(harness.runtime.views[0].canvas_widget_focus_visible_keyboard);
|
|
3421
|
+
try std.testing.expect(harness.runtime.views[0].canvas_last_pointer_position != null);
|
|
3422
|
+
|
|
3423
|
+
// Re-activation reveals nothing spontaneously — not on the
|
|
3424
|
+
// activate, not on any later frame.
|
|
3425
|
+
try harness.runtime.dispatchPlatformEvent(app, .app_activated);
|
|
3426
|
+
try tooltipFrame(harness, app, tooltip_t0 + 900 * tooltip_ms);
|
|
3427
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3428
|
+
try std.testing.expect(try tooltipHidden(harness, 9));
|
|
3429
|
+
|
|
3430
|
+
// A fresh hover TRANSITION re-earns the swapped tooltip normally:
|
|
3431
|
+
// the preserved stores act again, on a real transition.
|
|
3432
|
+
try tooltipHover(harness, app, .{ .x = 5, .y = 5 }, tooltip_t0 + 1000 * tooltip_ms);
|
|
3433
|
+
try tooltipHover(harness, app, .{ .x = 58, .y = 56 }, tooltip_t0 + 1100 * tooltip_ms);
|
|
3434
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_armed_id);
|
|
3435
|
+
try tooltipFrame(harness, app, tooltip_t0 + 2000 * tooltip_ms);
|
|
3436
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 9), harness.runtime.views[0].canvas_tooltip_shown_id);
|
|
3437
|
+
try std.testing.expect(!try tooltipHidden(harness, 9));
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
test "a tooltip mounting beneath a non-key window's hovered trigger reveals and arms nothing" {
|
|
3441
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
3442
|
+
defer harness.destroy(std.testing.allocator);
|
|
3443
|
+
const TestApp = struct {
|
|
3444
|
+
fn app(self: *@This()) App {
|
|
3445
|
+
return .{ .context = self, .name = "gpu-tooltip-nonkey-adoption", .source = platform.WebViewSource.html("<h1>GPU</h1>") };
|
|
3446
|
+
}
|
|
3447
|
+
};
|
|
3448
|
+
var app_state: TestApp = .{};
|
|
3449
|
+
const app = app_state.app();
|
|
3450
|
+
try installTooltipBindingView(harness, app);
|
|
3451
|
+
try setTooltipBindingLayout(harness, .button, 0, 0);
|
|
3452
|
+
|
|
3453
|
+
// A second window with its own canvas view and a bare trigger; the
|
|
3454
|
+
// startup window keeps key throughout the mount.
|
|
3455
|
+
const second = try harness.runtime.createWindow(.{ .label = "tools", .title = "Tools" });
|
|
3456
|
+
_ = try harness.runtime.createView(.{
|
|
3457
|
+
.window_id = second.id,
|
|
3458
|
+
.label = "canvas",
|
|
3459
|
+
.kind = .gpu_surface,
|
|
3460
|
+
.frame = geometry.RectF.init(0, 0, 220, 120),
|
|
3461
|
+
});
|
|
3462
|
+
try setTooltipBindingLayoutInWindow(&harness.runtime, second.id, .button, 0, 0);
|
|
3463
|
+
try std.testing.expect(harness.runtime.windows[0].info.focused);
|
|
3464
|
+
|
|
3465
|
+
// Hover the non-key window's trigger: the bookkeeping stays
|
|
3466
|
+
// truthful (wash, stored pointer) — only tooltip ACTION is gated.
|
|
3467
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 58, .y = 56 }, tooltip_t0);
|
|
3468
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 2), harness.runtime.views[1].canvas_widget_hovered_id);
|
|
3469
|
+
|
|
3470
|
+
// A rebuild mounts a DELAY-0 tooltip beneath that hovered trigger:
|
|
3471
|
+
// the adoption binding-reconcile sees the change, but the window
|
|
3472
|
+
// is not key — no instant show, no arm, semantics stay hidden.
|
|
3473
|
+
try setTooltipBindingLayoutInWindow(&harness.runtime, second.id, .button, 3, 0);
|
|
3474
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3475
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_armed_id);
|
|
3476
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3477
|
+
|
|
3478
|
+
// Key arriving reveals nothing spontaneously — not on the key
|
|
3479
|
+
// event, not on a later frame.
|
|
3480
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .window_focused = second.id });
|
|
3481
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
3482
|
+
.window_id = second.id,
|
|
3483
|
+
.label = "canvas",
|
|
3484
|
+
.size = geometry.SizeF.init(220, 120),
|
|
3485
|
+
.timestamp_ns = tooltip_t0 + 900 * tooltip_ms,
|
|
3486
|
+
} });
|
|
3487
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 0), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3488
|
+
try std.testing.expect(try tooltipHiddenInView(harness, 1, 3));
|
|
3489
|
+
|
|
3490
|
+
// A fresh hover transition in the now-key window earns instantly
|
|
3491
|
+
// (delay 0).
|
|
3492
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 200, .y = 10 }, tooltip_t0 + 1000 * tooltip_ms);
|
|
3493
|
+
try tooltipHoverInWindow(harness, app, second.id, .{ .x = 58, .y = 56 }, tooltip_t0 + 1050 * tooltip_ms);
|
|
3494
|
+
try std.testing.expectEqual(@as(canvas.ObjectId, 3), harness.runtime.views[1].canvas_tooltip_shown_id);
|
|
3495
|
+
try std.testing.expect(!try tooltipHiddenInView(harness, 1, 3));
|
|
3496
|
+
}
|