diff --git a/docs/api-migrations.md b/docs/api-migrations.md index 422c7504c..1c358793c 100644 --- a/docs/api-migrations.md +++ b/docs/api-migrations.md @@ -3813,6 +3813,24 @@ boolean property. Removing it restores editable behavior. Applications that used `disabled` solely to prevent edits may switch to `read_only` when users should retain selection and copying. +The experimental self-drawn native backend now enforces the same contract: +`Lui_text_input.accepts_edits` gates insert, delete, paste, cut-deletion, undo +and IME commit/composition, while focus, selection, copy and caret navigation +remain available. Typed virtual-list `overscan` and `item-extent` are read by +`Lui_layout` with precedence over legacy `data-overscan` / `data-item-extent`. + +### Native bridge registrar is a polymorphic record + +`Lui_native_bridge.register` takes `~register_named` as +`{ register_named : 'a. string -> 'a -> unit }` instead of a bare function. +Wrap `Callback.register` (or a test stub) in that record: + +```ocaml +Lui_native_bridge.register + ~register_named:{ register_named = Callback.register } + "lui_ocaml" bridge +``` + ### Tabs, lifecycle and scroll results Ordinary `tabs` keep their application-owned content. Arrow keys activate the diff --git a/examples/components/native/components_bridge.ml b/examples/components/native/components_bridge.ml index 44ca249c5..a9c15b341 100644 --- a/examples/components/native/components_bridge.ml +++ b/examples/components/native/components_bridge.ml @@ -25,5 +25,5 @@ let () = Printexc.record_backtrace true; Callback.register "lui_ocaml_init" initialize; Callback.register "lui_kotlin_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge; - Lui_native_bridge.register ~register_named:Callback.register "lui_kotlin" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge; + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_kotlin" bridge diff --git a/examples/markdown/native/markdown_bridge.ml b/examples/markdown/native/markdown_bridge.ml index bb36b9c02..0f07957d0 100644 --- a/examples/markdown/native/markdown_bridge.ml +++ b/examples/markdown/native/markdown_bridge.ml @@ -15,4 +15,4 @@ let initialize platform_code host_code = let () = Callback.register "lui_ocaml_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge diff --git a/examples/navigation/native/navigation_bridge.ml b/examples/navigation/native/navigation_bridge.ml index d1296ff6e..9b84438e3 100644 --- a/examples/navigation/native/navigation_bridge.ml +++ b/examples/navigation/native/navigation_bridge.ml @@ -135,4 +135,4 @@ let initialize _platform host_code = let () = Printexc.record_backtrace true; Callback.register "lui_ocaml_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge diff --git a/examples/split/native/split_bridge.ml b/examples/split/native/split_bridge.ml index 65e7e72ff..aeebda340 100644 --- a/examples/split/native/split_bridge.ml +++ b/examples/split/native/split_bridge.ml @@ -15,4 +15,4 @@ let initialize platform_code host_code = let () = Callback.register "lui_ocaml_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge diff --git a/examples/todos/native/todos_bridge.ml b/examples/todos/native/todos_bridge.ml index 51423d096..5c6083660 100644 --- a/examples/todos/native/todos_bridge.ml +++ b/examples/todos/native/todos_bridge.ml @@ -14,4 +14,4 @@ let initialize platform_code host_code = let () = Callback.register "lui_ocaml_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge diff --git a/platform/native/lui_input/lui_text_input.ml b/platform/native/lui_input/lui_text_input.ml index 9e105bb53..734b9b851 100644 --- a/platform/native/lui_input/lui_text_input.ml +++ b/platform/native/lui_input/lui_text_input.ml @@ -62,11 +62,16 @@ let composing st = Lui_ime.composing st.ime let sel_lo st = min st.anchor st.caret let sel_hi st = max st.anchor st.caret -(* Whether the node's focused field accepts edits — admits - TextChanged. *) +(* Whether the node is a text field that admits TextChanged — focus, + selection and copy still apply when [read-only] is set. *) let editable store node = node <> 0 && Lui_query.event_supported store node (TextChanged (node, "")) +(* User edits (insert, delete, paste, IME commit, undo) require an + editable field that is not marked read-only. *) +let accepts_edits store node = + editable store node && not (Lui_store.bool_prop store node "read-only") + (* Session ids — every attach starts a new session so model responses to one session cannot leak into the next. *) let session_seq = ref 0 @@ -242,11 +247,13 @@ let edit_key hooks store rects st ~(k : Lui_input.key) then Lui_query.submit store n else [] | _ -> Lui_query.submit store n) ) | Lui_input.Backspace -> - if sel_hi st > sel_lo st then splice st "" + if not (accepts_edits store n) then (st, []) + else if sel_hi st > sel_lo st then splice st "" else if caret > 0 then delete_between st (prev caret) caret else (st, []) | Lui_input.Delete -> - if sel_hi st > sel_lo st then splice st "" + if not (accepts_edits store n) then (st, []) + else if sel_hi st > sel_lo st then splice st "" else if caret < String.length cur then delete_between st caret (next caret) else (st, []) @@ -309,7 +316,7 @@ let apply_ime store st actions = nothing or finds no editable target *) (match !st.node with | 0 -> [ `Repaint ] - | n when Lui_query.node_enabled store n && editable store n -> + | n when Lui_query.node_enabled store n && accepts_edits store n -> let st', acts = splice !st s in st := st'; `Repaint :: acts @@ -321,11 +328,20 @@ let apply_ime store st actions = (!st, out) (* Feed one IME event into the embedded state machine and apply what - it asks for. *) + it asks for. Read-only fields keep caret tracking but reject + composition and commit so the shadow never changes. *) let feed_ime store st ev = - let ime, actions = Lui_ime.feed_event st.ime ev in - let st, acts = apply_ime store { st with ime } actions in - (st, acts) + let reject_edit = + match ev with + | `Editing _ | `Commit _ -> + st.node <> 0 && not (accepts_edits store st.node) + | `Focus _ | `Caret _ -> false + in + if reject_edit then (st, []) + else + let ime, actions = Lui_ime.feed_event st.ime ev in + let st, acts = apply_ime store { st with ime } actions in + (st, acts) (* Model-side text sync — the revision protocol. The host's own edits mirror into the store prop immediately, so a prop equal to diff --git a/platform/native/lui_input/test/lui_input_test.ml b/platform/native/lui_input/test/lui_input_test.ml index e4c371e39..7750a6acf 100644 --- a/platform/native/lui_input/test/lui_input_test.ml +++ b/platform/native/lui_input/test/lui_input_test.ml @@ -309,6 +309,37 @@ let test_text_session () = acts); ignore store +let test_read_only_accepts_edits () = + let store = + store_of + [ CreateNode (1, TextField); + SetProp (1, TextValue, StringValue "ref"); + SetProp (1, ReadOnly, BoolValue true) ] + in + Alcotest.(check bool) "editable for focus" true + (Lui_text_input.editable store 1); + Alcotest.(check bool) "rejects edits" false + (Lui_text_input.accepts_edits store 1); + let st = Lui_text_input.attach Lui_text_input.initial ~node:1 ~text:"ref" in + let st, acts = Lui_text_input.feed_ime store st (`Commit "x") in + Alcotest.(check string) "commit ignored" "ref" (Lui_text_input.text st); + Alcotest.(check bool) "no TextChanged" true + (not + (List.exists + (function `Dispatch (TextChanged _) -> true | _ -> false) + acts)); + let rects = rects_of [ 1, rect 0. 0. 100. 20. ] in + let st, _ = + Lui_text_input.key hooks store rects st ~k:Lui_input.Backspace + ~mods:none ~prim:false + in + Alcotest.(check string) "backspace ignored" "ref" (Lui_text_input.text st); + let st, _ = + Lui_text_input.key hooks store rects st ~k:Lui_input.Arrow_left + ~mods:none ~prim:false + in + Alcotest.(check int) "navigation kept" 2 (Lui_text_input.caret st) + let test_unchanged_committed_replacement () = let initial = Lui_text_input.attach Lui_text_input.initial ~node:4 ~text:"hello" in let selected, _ = Lui_text_input.select_all initial in @@ -1332,6 +1363,7 @@ let () = ( "text input", [ Alcotest.test_case "navigation" `Quick test_text_navigation; Alcotest.test_case "splice" `Quick test_text_session; + Alcotest.test_case "read-only" `Quick test_read_only_accepts_edits; Alcotest.test_case "unchanged committed replacement" `Quick test_unchanged_committed_replacement; Alcotest.test_case "undo" `Quick test_text_undo; Alcotest.test_case "caret ops" `Quick test_text_caret_ops; diff --git a/platform/native/lui_layout/lui_layout.ml b/platform/native/lui_layout/lui_layout.ml index a93ca1c78..fcb59d165 100644 --- a/platform/native/lui_layout/lui_layout.ml +++ b/platform/native/lui_layout/lui_layout.ml @@ -958,12 +958,10 @@ let vlist_state ctx id = Hashtbl.replace ctx.vlists id v; v -(* data-attrs is the wire-clean channel for virtual-list config that - the schema does not model: [data-item-extent] is the estimated row - main extent in logical px, [data-overscan] the extra rows mounted - past each viewport edge, [data-scroll-target]/[data-scroll-token]/ - [data-scroll-anchor] the scroll-request triple and - [data-track-visible-range] the visible-range opt-in. *) +(* Legacy virtual-list config still rides [data-attrs]: typed + [item-extent]/[overscan] take precedence when present, then these + semantic attributes, then host defaults. Scroll-request and + visible-range opt-ins remain data-attrs-only for now. *) let vlist_data_attr store id name = match Lui_store.prop store id "data-attrs" with | Some (StringValue s) -> ( @@ -976,9 +974,9 @@ let vlist_data_attr store id name = let vlist_vertical store id = pstr store id "orientation" <> Some "horizontal" -(* Pull the model inputs off the resolved style and the data-attrs. - [style] is the vlist's own flex style — padding, border and the - row gap come straight from it. *) +(* Pull the model inputs off the resolved style, typed props and the + data-attrs. [style] is the vlist's own flex style — padding, border + and the row gap come straight from it. *) let vlist_configure ctx store (v : vlist) (style : Lui_flex.style) = (* The logical child ids snapshot: [count] stays O(1) on the store, but a per-row indexed probe on the intrusive child list is O(i), @@ -989,28 +987,34 @@ let vlist_configure ctx store (v : vlist) (style : Lui_flex.style) = let count = Lui_store.child_count store v.vid in let gap = len_px ~owner:ctx.vh style.row_gap in let estimate = - match - Option.bind - (vlist_data_attr store v.vid "data-item-extent") - (fun s -> float_of_string_opt (String.trim s)) - with + match pnum store v.vid "item-extent" with | Some f when f > 0. -> f *. ctx.scale | _ -> ( - match if count > 0 then v.kids.(0) else -1 with - | cid when cid >= 0 -> ( - match pnum store cid "height" with - | Some h -> h *. ctx.scale - | None -> 28. *. ctx.scale) - | _ -> 28. *. ctx.scale) + match + Option.bind + (vlist_data_attr store v.vid "data-item-extent") + (fun s -> float_of_string_opt (String.trim s)) + with + | Some f when f > 0. -> f *. ctx.scale + | _ -> ( + match if count > 0 then v.kids.(0) else -1 with + | cid when cid >= 0 -> ( + match pnum store cid "height" with + | Some h -> h *. ctx.scale + | None -> 28. *. ctx.scale) + | _ -> 28. *. ctx.scale)) in let overscan = - match - Option.bind - (vlist_data_attr store v.vid "data-overscan") - (fun s -> int_of_string_opt (String.trim s)) - with - | Some n -> max 0 n - | None -> 4 + match Lui_store.int_prop store v.vid "overscan" with + | Some n when n >= 0 -> n + | _ -> ( + match + Option.bind + (vlist_data_attr store v.vid "data-overscan") + (fun s -> int_of_string_opt (String.trim s)) + with + | Some n -> max 0 n + | None -> 4) in (* Configure runs once per structural sync; child props may have changed under a stable shape, so the lazy lookup indexes rebuild diff --git a/platform/native/lui_layout/lui_layout.mli b/platform/native/lui_layout/lui_layout.mli index a3ba5e5d7..70629802b 100644 --- a/platform/native/lui_layout/lui_layout.mli +++ b/platform/native/lui_layout/lui_layout.mli @@ -132,12 +132,13 @@ val sync : content extent, so frame extent, scroll caps and hit clips behave exactly as if all rows were laid out. - Config rides [data-attrs] on the node (no schema change): - [data-item-extent] — estimated row main extent in logical px (per- - child [height] or a 28px default otherwise); [data-overscan] — - extra rows mounted past each view edge (4 default). Rows are - measured once mounted, so a mixed-height list converges to real - positions; [data-scroll-target]/[data-scroll-token]/ + Typed wire props [item-extent] (positive finite logical px) and + [overscan] (nonnegative row count) configure the estimate and mount + window. Legacy [data-item-extent]/[data-overscan] remain readable + when the typed props are absent; typed values take precedence. + Defaults are the first child's [height] or 28px, and overscan 4. + Rows are measured once mounted, so a mixed-height list converges + to real positions. [data-scroll-target]/[data-scroll-token]/ [data-scroll-anchor] name a scroll request the host resolves through {!virtual_index_of_key}, and [data-track-visible-range] opts the list into visible-range reports through {!virtual_view}. *) diff --git a/platform/native/lui_layout/test/lui_layout_test.ml b/platform/native/lui_layout/test/lui_layout_test.ml index b7f66a9d5..a82c25c4b 100644 --- a/platform/native/lui_layout/test/lui_layout_test.ml +++ b/platform/native/lui_layout/test/lui_layout_test.ml @@ -1259,6 +1259,56 @@ let test_vlist_mounted_children () = check int "first id" (10 + f) (List.hd ids); check int "last id" (10 + l - 1) (List.nth ids (l - f - 1)) +(* Typed [overscan]/[item-extent] drive the mount window; legacy + data-attrs remain a fallback and lose to typed values. Row heights + match the configured estimate so measurement does not expand the + window mid-sync. *) +let test_vlist_typed_props () = + let store = vlist_store ~item_h:40. ~n:1000 () in + apply store + [ SetProp (2, VirtualOverscan, IntValue 0); + SetProp (2, VirtualItemExtent, FloatValue 40.) ]; + let t = Lui_layout.create () in + Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800. + ~vport:(vport 0. 200.) t store; + let f, l = Option.get (Lui_layout.mounted_range t 2) in + check int "typed overscan 0 first" 0 f; + (* 200px / 40px = 5 rows (+1 touching), no overscan past the end *) + check int "typed overscan 0 last" 6 l; + (* Legacy attributes alone still configure the estimate/window. *) + let legacy = vlist_store ~item_h:50. ~n:1000 () in + apply legacy + [ SetProp + (2, DataAttrs, + StringValue + (Lui_protocol.data_attrs_encode + [ ("data-item-extent", "50"); ("data-overscan", "1") ])) ]; + let t = Lui_layout.create () in + Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800. + ~vport:(vport 0. 200.) t legacy; + let f, l = Option.get (Lui_layout.mounted_range t 2) in + check int "legacy overscan first" 0 f; + (* 200/50 = 4 (+1) + 1 overscan → last 6 *) + check int "legacy overscan last" 6 l; + (* Typed props win over conflicting legacy attributes. Rebuild with + matching row heights so measurement does not widen the window. *) + let prefer = vlist_store ~item_h:100. ~n:1000 () in + apply prefer + [ SetProp + (2, DataAttrs, + StringValue + (Lui_protocol.data_attrs_encode + [ ("data-item-extent", "50"); ("data-overscan", "8") ])); + SetProp (2, VirtualOverscan, IntValue 0); + SetProp (2, VirtualItemExtent, FloatValue 100.) ]; + let t = Lui_layout.create () in + Lui_layout.sync ~measure:no_measure4 ~width:100. ~height:800. + ~vport:(vport 0. 200.) t prefer; + let f, l = Option.get (Lui_layout.mounted_range t 2) in + check int "typed wins first" 0 f; + (* 200/100 = 2 (+1), overscan 0 → last 3 (legacy overscan 8 ignored) *) + check int "typed wins last" 3 l + (* Variable heights settle through measured extents: overscan rows above the anchor that differ from the estimate shift the prefix sums — the drift the scroller folds back into the offset so the @@ -2601,6 +2651,7 @@ let () = test_case "vlist unwindowed" `Quick test_vlist_unwindowed; test_case "vlist mounted children" `Quick test_vlist_mounted_children; + test_case "vlist typed props" `Quick test_vlist_typed_props; test_case "vlist anchor drift" `Quick test_vlist_anchor_drift; test_case "vlist incremental child" `Quick test_vlist_incremental_child; diff --git a/platform/native/lui_paint/lui_paint.ml b/platform/native/lui_paint/lui_paint.ml index 8f2cf3c94..fbb5aef3f 100644 --- a/platform/native/lui_paint/lui_paint.ml +++ b/platform/native/lui_paint/lui_paint.ml @@ -136,6 +136,24 @@ let prop_coverage = ("scroll-token", Host); ("scroll-animated", Host); ("track-visible-range", Host); + ("overscan", Layout); (* virtual-list mount window *) + ("item-extent", Layout); (* virtual-list row estimate *) + ("virtual-total-count", Host); (* sparse virtual-list wire *) + ("virtual-generation", Host); + ("virtual-indices", Host); + ("virtual-scroll-index", Host); + ("virtual-viewport-epoch", Host); + ("virtual-owner-node", Host); + ("virtual-owner-epoch", Host); + ("virtual-row-keys", Host); + ("virtual-retentions", Host); + ("virtual-retention-releases", Host); + ("read-only", Host); (* text controls: focus/copy, reject edits *) + ("pointer-capture", Host); + ("indeterminate", Painted); (* checkbox mixed state *) + ("toggle-detail-enabled", Host); + ("focus-within-enabled", Host); + ("shrink", Layout); (* flex shrink factor *) ("edge", Layout); (* edge-inset side *) ("request", Host); (* file picker *) ("types", Host); diff --git a/platform/native/lui_paint/test/lui_paint_test.ml b/platform/native/lui_paint/test/lui_paint_test.ml index 908f02794..57262ab29 100644 --- a/platform/native/lui_paint/test/lui_paint_test.ml +++ b/platform/native/lui_paint/test/lui_paint_test.ml @@ -1406,8 +1406,6 @@ let test_secure_byte_of_masked () = (* ---------- coverage ---------- *) -(* TODO: Restore this guard and its registration once the Native property - inventory accounts for read-only, overscan and item-extent. let test_coverage_table () = let names = List.map Lui_wire_schema.property_name Lui_wire_schema.all_properties @@ -1418,7 +1416,6 @@ let test_coverage_table () = names in check bool "all props classified" true (missing = []) -*) (* ---------- spatial index ---------- *) @@ -2167,7 +2164,6 @@ let () = test_case "build allocation" `Quick test_spatial_build_allocation; test_case "paint equivalence" `Quick test_spatial_paint_equiv; test_case "visit bound" `Quick test_spatial_visit_bound; - test_case "degenerate kept" `Quick test_spatial_degenerate_kept ]) - (* TODO: Restore alongside test_coverage_table after the Native inventory update. - ; ("coverage", - [ test_case "all props" `Quick test_coverage_table ]) *) ] + test_case "degenerate kept" `Quick test_spatial_degenerate_kept ]); + ("coverage", + [ test_case "all props" `Quick test_coverage_table ]) ] diff --git a/platform/native/lui_store/lui_store.ml b/platform/native/lui_store/lui_store.ml index 85d25b262..8289e1f4b 100644 --- a/platform/native/lui_store/lui_store.ml +++ b/platform/native/lui_store/lui_store.ml @@ -51,9 +51,10 @@ let layout_prop_names = "icon"; "inset"; "inset-top"; "inset-right"; "inset-bottom"; "inset-left"; "label"; "margin"; "margin-top"; "margin-right"; "margin-bottom"; "margin-left"; "margin-horizontal"; "margin-vertical"; - "orientation"; "overflow"; "padding"; "padding-horizontal"; + "orientation"; "overflow"; "overscan"; "padding"; "padding-horizontal"; "padding-vertical"; "padding-top"; "padding-right"; "padding-bottom"; "padding-left"; "placeholder"; "position"; "selected"; "size"; - "text"; "title"; "value"; "first-pane-width"; "style-class" ] + "text"; "title"; "value"; "first-pane-width"; "item-extent"; "style-class"; + "shrink" ] let layout_props = let t = Hashtbl.create 64 in @@ -120,7 +121,8 @@ let semantics_props = (* Focus/selection/input-channel props. *) let input_prop_names = [ "enabled"; "disabled"; "focus"; "focused"; "selection"; - "selection-start"; "selection-end"; "input-mode"; "readonly" ] + "selection-start"; "selection-end"; "input-mode"; "read-only"; + "pointer-capture"; "toggle-detail-enabled"; "focus-within-enabled" ] let input_props = let t = Hashtbl.create 16 in diff --git a/platform/native/lui_window/lui_window.ml b/platform/native/lui_window/lui_window.ml index ceba7d16b..446435dd2 100644 --- a/platform/native/lui_window/lui_window.ml +++ b/platform/native/lui_window/lui_window.ml @@ -904,9 +904,8 @@ module Ui = struct let ime_surrounding t store = let id = focused t in - if not (Lui_text_input.editable store id && node_enabled store id) - || kind_name store id = "secure-field" - || bool_prop store id "read-only" then None + if not (Lui_text_input.accepts_edits store id && node_enabled store id) + || kind_name store id = "secure-field" then None else let text = shadow t and caret = caret t and anchor = sel_anchor t in Some { Lui_ime.text; caret; @@ -1455,7 +1454,7 @@ module Ui = struct run m | Input.Paste s -> (* clipboard text the driver pulled after Paste_request *) - if s <> "" && Lui_text_input.editable store (focused t) + if s <> "" && Lui_text_input.accepts_edits store (focused t) then begin let s', m = Lui_text_input.insert t.session s in t.session <- s'; @@ -1588,19 +1587,23 @@ module Ui = struct | Some s -> acts := Clipboard_write s :: !acts | None -> ()) | Input.Other 27 when prim -> + (* Cut: copy always when editable; delete only when edits + are admitted (read-only keeps the selection intact). *) if Lui_text_input.editable store (focused t) then (match active_sel_text t store with | Some s -> acts := Clipboard_write s :: !acts; - let s', m = Lui_text_input.splice t.session "" in - t.session <- s'; - run m + if Lui_text_input.accepts_edits store (focused t) then begin + let s', m = Lui_text_input.splice t.session "" in + t.session <- s'; + run m + end | None -> ()) | Input.Other 25 when prim -> - if Lui_text_input.editable store (focused t) + if Lui_text_input.accepts_edits store (focused t) then acts := Paste_request :: !acts | Input.Other 29 when prim -> - if Lui_text_input.editable store (focused t) then begin + if Lui_text_input.accepts_edits store (focused t) then begin let s', m = Lui_text_input.undo t.session ~shift:mods.Input.shift in diff --git a/platform/native/lui_window/test/lui_window_test.ml b/platform/native/lui_window/test/lui_window_test.ml index d38dc49a6..7ed6d5758 100644 --- a/platform/native/lui_window/test/lui_window_test.ml +++ b/platform/native/lui_window/test/lui_window_test.ml @@ -2043,6 +2043,49 @@ let test_sel_shift_and_all () = Alcotest.(check int) "sel all a" 0 (Ui.sel_anchor ui); Alcotest.(check int) "sel all c" 5 (Ui.caret ui) +(* Read-only keeps focus, selection and copy; typing, paste, cut + deletion, backspace and IME commits are rejected. *) +let test_read_only_text_field () = + let s, rects = ui_store_fresh () in + Lui_store.apply_batch s + { generation = 2; + ops = + [ SetProp (4, TextValue, StringValue "locked"); + SetProp (4, ReadOnly, BoolValue true) ] }; + let ui = Ui.create () in + press_field s rects ui 5. 40.; + Alcotest.(check int) "focuses" 4 (Ui.focused ui); + Alcotest.(check string) "shadow" "locked" (Ui.shadow ui); + Alcotest.(check bool) "typing rejected" true + (press_actions (Ui.handle ui s rects (Input.Text_input "x")) = []); + Alcotest.(check string) "text unchanged after type" "locked" (Ui.shadow ui); + Alcotest.(check bool) "IME editing rejected" true + (Ui.handle ui s rects (Input.Text_editing ("候補", 0, 2)) = []); + Alcotest.(check string) "no marked text" "" (Ui.marked ui); + ignore (Ui.handle ui s rects (key ~mods:meta (Input.Other 4))); + Alcotest.(check int) "select-all anchor" 0 (Ui.sel_anchor ui); + Alcotest.(check int) "select-all caret" 6 (Ui.caret ui); + (match Ui.handle ui s rects (key ~mods:meta (Input.Other 6)) with + | [ Clipboard_write "locked" ] -> () + | _ -> Alcotest.fail "copy must still work"); + (match Ui.handle ui s rects (key ~mods:meta (Input.Other 27)) with + | [ Clipboard_write "locked" ] -> () + | a -> Alcotest.failf "cut must copy without deleting (%d acts)" (List.length a)); + Alcotest.(check string) "cut leaves text" "locked" (Ui.shadow ui); + Alcotest.(check bool) "paste request denied" true + (Ui.handle ui s rects (key ~mods:meta (Input.Other 25)) = []); + ignore (Ui.handle ui s rects (Input.Paste "nope")); + Alcotest.(check string) "paste rejected" "locked" (Ui.shadow ui); + ignore + (Ui.handle ui s rects + (Input.Key_down (Input.Backspace, Input.mods_none, false))); + Alcotest.(check string) "backspace rejected" "locked" (Ui.shadow ui); + (* Collapse the selection, then arrow navigation still moves the caret. *) + ignore (Ui.handle ui s rects (key Input.End)); + Alcotest.(check int) "collapsed at end" 6 (Ui.caret ui); + ignore (Ui.handle ui s rects (key Input.Arrow_left)); + Alcotest.(check int) "arrow left" 5 (Ui.caret ui) + let test_clipboard_cycle () = let s, rects = ui_store_fresh () in let ui = Ui.create () in @@ -5022,7 +5065,8 @@ let () = Alcotest.test_case "siblings" `Quick test_sel_siblings ] ); ( "clipboard", [ Alcotest.test_case "cut/copy/paste" `Quick test_clipboard_cycle; - Alcotest.test_case "undo/redo" `Quick test_undo_redo ] ); + Alcotest.test_case "undo/redo" `Quick test_undo_redo; + Alcotest.test_case "read-only" `Quick test_read_only_text_field ] ); ( "split resize", [ Alcotest.test_case "pointer feedback" `Quick test_split_pointer_resize; Alcotest.test_case "pixel pane resize" `Quick test_split_pointer_pixels; diff --git a/src/lui_native_bridge.ml b/src/lui_native_bridge.ml index d5c211d44..b4048648e 100644 --- a/src/lui_native_bridge.ml +++ b/src/lui_native_bridge.ml @@ -235,8 +235,15 @@ let agent bridge request = let pointer_detail x y modifiers button target_class = {x; y; modifiers; button; target_class} -let register ~(register_named : 'a. string -> 'a -> unit) prefix bridge = - let register suffix value = register_named (prefix ^ "_" ^ suffix) value in +(* Rank-2 registrar: each callback may close over a different payload + type. OCaml only accepts that polymorphism through a record field, + so callers wrap [Callback.register] (or a test stub) in {!registrar}. *) +type registrar = { register_named : 'a. string -> 'a -> unit } + +let register ~(register_named : registrar) prefix bridge = + let register suffix value = + register_named.register_named (prefix ^ "_" ^ suffix) value + in let node make node_id = dispatch_event bridge (make node_id) in register "appear" (node (fun id -> Appear id)); register "press" (node (fun id -> Press id)); diff --git a/test/test_lui.ml b/test/test_lui.ml index 2188f4138..38478f209 100644 --- a/test/test_lui.ml +++ b/test/test_lui.ml @@ -5911,7 +5911,9 @@ let test_native_bridge_negotiation_drives_real_source_windows () = List.iter (fun (os, _plain, flagged, host) -> let bridge = Lui_native_bridge.create "startup-window" in let registered = ref [] in - Lui_native_bridge.register ~register_named:(fun name _ -> registered := name :: !registered) + Lui_native_bridge.register + ~register_named: + { register_named = (fun name _ -> registered := name :: !registered) } "startup-window" bridge; List.iter (fun callback -> Alcotest.(check bool) "callback registration remains complete" true (List.mem ("startup-window_" ^ callback) !registered)) @@ -6026,7 +6028,9 @@ let test_runtime_constructor_capability_is_immutable_and_owned () = let test_native_bridge_reports_refused_calls () = let bridge = Lui_native_bridge.create "refusal" in let registered = ref [] in - Lui_native_bridge.register ~register_named:(fun name _ -> registered := name :: !registered) + Lui_native_bridge.register + ~register_named: + { register_named = (fun name _ -> registered := name :: !registered) } "refusal" bridge; Alcotest.(check bool) "last_error is a registered bridge callback" true (List.mem "refusal_last_error" !registered); diff --git a/tooling/test/fixtures/bounded_virtual_bridge.ml b/tooling/test/fixtures/bounded_virtual_bridge.ml index ba16a06fa..d46e6c09f 100644 --- a/tooling/test/fixtures/bounded_virtual_bridge.ml +++ b/tooling/test/fixtures/bounded_virtual_bridge.ml @@ -91,5 +91,5 @@ let initialize platform_code host_code = let () = Callback.register "lui_ocaml_init" initialize; Callback.register "lui_kotlin_init" initialize; - Lui_native_bridge.register ~register_named:Callback.register "lui_ocaml" bridge; - Lui_native_bridge.register ~register_named:Callback.register "lui_kotlin" bridge + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_ocaml" bridge; + Lui_native_bridge.register ~register_named:{ register_named = Callback.register } "lui_kotlin" bridge