Skip to main content

slint_interpreter/
item_tree_vtable.rs

1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4//! `ItemTreeVTable` implementation for [`Instance`].
5//!
6//! A single static vtable serves every runtime `Instance`; vtable calls
7//! walk the instance's sub-component tree on demand rather than through
8//! a precomputed offset table.
9
10use crate::prelude::*;
11use i_slint_core::SharedString;
12use i_slint_core::accessibility::{
13    AccessibilityAction, AccessibleStringProperty, SupportedAccessibilityAction,
14};
15use i_slint_core::item_tree::{
16    IndexRange, ItemTree, ItemTreeNode, ItemVisitorVTable, ItemWeak, TraversalOrder,
17    VisitChildrenResult,
18};
19use i_slint_core::items::{AccessibleRole, ItemVTable};
20use i_slint_core::layout::{LayoutInfo, Orientation};
21use i_slint_core::lengths::LogicalRect;
22use i_slint_core::slice::Slice;
23use i_slint_core::window::WindowAdapterRc;
24use vtable::{VRef, VRefMut, VWeak};
25
26i_slint_core::ItemTreeVTable_static!(static INTERPRETER_INSTANCE_VT for Instance);
27
28/// Find the `sub_component_path` (sequence of `SubComponentInstanceIdx`)
29/// from the parent instance's root to the given sub-component. Used by
30/// `parent_node` to match entries in the parent's `dynamic_table`.
31pub(crate) fn sub_component_path_of(
32    target: &crate::instance::SubComponentInstance,
33    parent_root: &Instance,
34) -> Vec<i_slint_compiler::llr::SubComponentInstanceIdx> {
35    fn walk(
36        current: &crate::instance::SubComponentInstance,
37        target_ptr: *const crate::instance::SubComponentInstance,
38        path: &mut Vec<i_slint_compiler::llr::SubComponentInstanceIdx>,
39    ) -> bool {
40        if core::ptr::eq(current as *const _, target_ptr) {
41            return true;
42        }
43        for (idx, nested) in current.sub_components.iter().enumerate() {
44            path.push(idx.into());
45            if walk(nested, target_ptr, path) {
46                return true;
47            }
48            path.pop();
49        }
50        false
51    }
52    let mut path = Vec::new();
53    walk(&parent_root.root_sub_component, target as *const _, &mut path);
54    path
55}
56
57impl i_slint_core::item_tree::ItemTree for Instance {
58    fn visit_children_item(
59        self: Pin<&Self>,
60        index: isize,
61        order: TraversalOrder,
62        visitor: VRefMut<'_, ItemVisitorVTable>,
63    ) -> VisitChildrenResult {
64        let this = self.get_ref();
65        let weak = this.self_weak.get().unwrap().clone();
66        if index >= 0 && this.z_sort_table.get(index as usize).is_some_and(|e| e.is_some()) {
67            i_slint_core::item_tree::visit_item_tree_z_sorted(
68                &VRc::into_dyn(weak.upgrade().unwrap()),
69                &this.tree_nodes[..],
70                index,
71                order,
72                visitor,
73                &mut |order, visitor, dyn_index| {
74                    self.visit_dynamic_children(dyn_index, order, visitor)
75                },
76                &mut |push| self.collect_z_sorted_children(index, push),
77            )
78        } else {
79            i_slint_core::item_tree::visit_item_tree(
80                &VRc::into_dyn(weak.upgrade().unwrap()),
81                &this.tree_nodes[..],
82                index,
83                order,
84                visitor,
85                &mut |order, visitor, dyn_index| {
86                    self.visit_dynamic_children(dyn_index, order, visitor)
87                },
88            )
89        }
90    }
91
92    fn get_item_ref(self: Pin<&Self>, index: u32) -> Pin<VRef<'_, ItemVTable>> {
93        // The item_table is indexed by flat tree index (same ordering as
94        // `tree_nodes`), pointing at the sub-component path + item slot
95        // that backs each static item node.
96        let this = self.get_ref();
97        let entry = this
98            .item_table
99            .get(index as usize)
100            .and_then(Option::as_ref)
101            .expect("get_item_ref: tree index is not a static item");
102        // Walk the path by borrowing — every intermediate sub-component
103        // is owned by its parent via `sub_components`, so a reference
104        // to the leaf is valid for the lifetime of `self`.
105        let mut current: &crate::instance::SubComponentInstance = &this.root_sub_component;
106        for &sub_idx in entry.0.iter() {
107            current = &current.sub_components[sub_idx];
108        }
109        Pin::as_ref(&current.items[entry.1]).as_item_ref()
110    }
111
112    fn ensure_instantiated(self: Pin<&Self>) -> bool {
113        self.get_ref().ensure_instantiated()
114    }
115
116    fn get_subtree_range(self: Pin<&Self>, index: u32) -> IndexRange {
117        let Some((sub, rep_idx)) = self.get_ref().dynamic_at(index) else {
118            return IndexRange { start: 0, end: 0 };
119        };
120        if let Some(cc) = crate::instance::component_container_item(&sub, rep_idx) {
121            return cc.subtree_range();
122        }
123        let repeater = &sub.repeaters[rep_idx];
124        repeater.track_instance_changes();
125        let range = repeater.range();
126        IndexRange { start: range.start, end: range.end }
127    }
128
129    fn get_subtree(
130        self: Pin<&Self>,
131        index: u32,
132        subindex: usize,
133        result: &mut VWeak<ItemTreeVTable, vtable::Dyn>,
134    ) {
135        let Some((sub, rep_idx)) = self.get_ref().dynamic_at(index) else {
136            return;
137        };
138        if let Some(cc) = crate::instance::component_container_item(&sub, rep_idx) {
139            if subindex == 0 {
140                *result = cc.subtree_component();
141            }
142            return;
143        }
144        let repeater = &sub.repeaters[rep_idx];
145        if let Some(instance) = repeater.instance_at(subindex) {
146            *result = VRc::downgrade(&VRc::into_dyn(instance));
147        }
148    }
149
150    fn get_item_tree(self: Pin<&Self>) -> Slice<'_, ItemTreeNode> {
151        Slice::from(&*self.get_ref().tree_nodes)
152    }
153
154    fn parent_node(self: Pin<&Self>, result: &mut ItemWeak) {
155        // If this is a repeated sub-tree, point at the repeater's placeholder
156        // in the parent instance. For a popup (parented but not repeated),
157        // point at the parent instance's root item.
158        let this = self.get_ref();
159        // `embedded_in` records where in the outer item tree this instance
160        // lives. Return that as the parent; the core walks back through it
161        // the same way as a repeated DynamicTree node.
162        if let Some((outer_weak, outer_index)) = this.embedded_in.get()
163            && let Some(outer) = outer_weak.upgrade()
164        {
165            *result = i_slint_core::items::ItemRc::new(outer, *outer_index).downgrade();
166            return;
167        }
168        let Some(parent_sub) = this.parent_instance.upgrade() else { return };
169        let Some(parent_root_vrc) = parent_sub.root.get().and_then(|w| w.upgrade()) else {
170            return;
171        };
172        let parent_dyn = VRc::into_dyn(parent_root_vrc.clone());
173        if let Some((_, repeater_idx)) = this.root_sub_component.repeated_in.get() {
174            // Return the DynamicTree node itself in the parent's flat tree.
175            // `parent_item` in i_slint_core detects that the returned parent
176            // is a DynamicTree and walks one more level up to its parent
177            // item. Returning the DynamicTree's own parent here skips that
178            // adjustment and gives the caller the wrong node.
179            let rep_idx = *repeater_idx;
180            let parent_path = sub_component_path_of(&parent_sub, &parent_root_vrc);
181            for (flat, entry) in parent_root_vrc.dynamic_table.iter().enumerate() {
182                if let Some((path, idx)) = entry.as_ref()
183                    && path.as_ref() == parent_path.as_slice()
184                    && *idx == rep_idx
185                {
186                    *result = i_slint_core::items::ItemRc::new(parent_dyn, flat as u32).downgrade();
187                    return;
188                }
189            }
190        } else {
191            // Popup case: ItemRc::new_root on the parent instance, which the
192            // caller uses to traverse up to the window.
193            *result = i_slint_core::items::ItemRc::new(parent_dyn, 0).downgrade();
194        }
195    }
196
197    fn embed_component(
198        self: Pin<&Self>,
199        parent: &VWeak<ItemTreeVTable>,
200        parent_item_tree_index: u32,
201    ) -> bool {
202        // Stash the outer item tree handle so `parent_node` can point at
203        // the ComponentContainer slot that substitutes this instance in.
204        let this = self.get_ref();
205        this.embedded_in.set((parent.clone(), parent_item_tree_index)).is_ok()
206    }
207
208    fn subtree_index(self: Pin<&Self>) -> usize {
209        // For repeated instances, return the model index so tab-focus
210        // traversal can step to the next sibling via get_subtree(idx+1).
211        let this = self.get_ref();
212        let sc = &this.root_sub_component.compilation_unit.sub_components
213            [this.root_sub_component.sub_component_idx];
214        for (idx, prop) in sc.properties.iter_enumerated() {
215            if prop.name == "model_index"
216                && let Value::Number(n) =
217                    Pin::as_ref(&this.root_sub_component.properties[idx]).get()
218            {
219                return n as usize;
220            }
221        }
222        // Conditional: only one instance, index 0.
223        0
224    }
225
226    fn layout_info(self: Pin<&Self>, orientation: Orientation) -> LayoutInfo {
227        let this = self.get_ref();
228        let sc_idx = this.root_sub_component.sub_component_idx;
229        let cu = &this.root_sub_component.compilation_unit;
230        let sc = &cu.sub_components[sc_idx];
231        let expr = match orientation {
232            Orientation::Horizontal => sc.layout_info_h.borrow(),
233            Orientation::Vertical => sc.layout_info_v.borrow(),
234        };
235        let mut ctx = crate::eval::EvalContext::new(this.root_sub_component.clone());
236        crate::eval::eval_expression(&mut ctx, &expr).try_into().unwrap_or_default()
237    }
238
239    fn item_geometry(self: Pin<&Self>, item_index: u32) -> LogicalRect {
240        // `item_index` is the flat tree index. Resolve it via `item_table`
241        // into the owning sub-component, then look up the geometry by
242        // the item's `index_in_tree`. `sc.geometries` is keyed by the
243        // sub-component-local tree index (set by `generate_item_indices`),
244        // not by the raw `ItemInstanceIdx` slot.
245        let this = self.get_ref();
246        let Some(entry) = this.item_table.get(item_index as usize).and_then(Option::as_ref) else {
247            return LogicalRect::default();
248        };
249        let mut owner_rc = this.root_sub_component.clone();
250        for &sub_idx in entry.0.iter() {
251            owner_rc = owner_rc.sub_components[sub_idx].clone();
252        }
253        let cu = owner_rc.compilation_unit.clone();
254        let sc = &cu.sub_components[owner_rc.sub_component_idx];
255        let item = &sc.items[entry.1];
256        // When the flat tree crosses into a sub-component (non-empty path)
257        // and lands on its root element (local tree index 0), the inner
258        // root's geometry can duplicate the parent's placement: the
259        // compiler's `adjust_geometry_for_injected_parent` pass hoists the
260        // original position into an injected wrapper item, and the inner
261        // root applies the same offset again via its `y: root-1_y`
262        // binding. So read the wrapper's geometry from the *parent*
263        // sub-component at the placement slot and never query the inner
264        // root. Fall through when the parent
265        // has no entry (the sub-component was placed directly with no
266        // wrapper, e.g. `box := SpinBox {}` inside a Window — then the
267        // inner root's own geometry is the correct placement).
268        let parent_placement = if !entry.0.is_empty() && item.index_in_tree == 0 {
269            let mut parent_rc = this.root_sub_component.clone();
270            for &sub_idx in &entry.0[..entry.0.len() - 1] {
271                parent_rc = parent_rc.sub_components[sub_idx].clone();
272            }
273            let placement = entry.0[entry.0.len() - 1];
274            let parent_sc = &cu.sub_components[parent_rc.sub_component_idx];
275            let placement_idx = parent_sc.sub_components[placement].index_in_tree as usize;
276            parent_sc
277                .geometries
278                .get(placement_idx)
279                .and_then(|g| g.clone())
280                .map(|expr| (expr, parent_rc))
281        } else {
282            None
283        };
284        let (expr_cell, ctx_owner) = if let Some(pair) = parent_placement {
285            pair
286        } else {
287            let tree_local_idx = item.index_in_tree as usize;
288            match sc.geometries.get(tree_local_idx) {
289                Some(Some(expr)) => (expr.clone(), owner_rc),
290                _ => return LogicalRect::default(),
291            }
292        };
293        let expr = expr_cell.borrow();
294        let mut ctx = crate::eval::EvalContext::new(ctx_owner);
295        let Value::Struct(s) = crate::eval::eval_expression(&mut ctx, &expr) else {
296            return LogicalRect::default();
297        };
298        let as_f32 = |name: &str| -> f32 {
299            match s.get_field(name) {
300                Some(Value::Number(n)) => *n as f32,
301                _ => 0.0,
302            }
303        };
304        LogicalRect::new(
305            i_slint_core::lengths::LogicalPoint::new(as_f32("x"), as_f32("y")),
306            i_slint_core::lengths::LogicalSize::new(as_f32("width"), as_f32("height")),
307        )
308    }
309
310    fn accessible_role(self: Pin<&Self>, item_index: u32) -> AccessibleRole {
311        eval_accessible_prop(self.get_ref(), item_index, "Role", Vec::new())
312            .and_then(|role| role.try_into().ok())
313            .unwrap_or_default()
314    }
315
316    fn accessible_string_property(
317        self: Pin<&Self>,
318        item_index: u32,
319        what: AccessibleStringProperty,
320        result: &mut SharedString,
321    ) -> bool {
322        let what = accessible_string_property_name(what);
323        let Some(Value::String(s)) =
324            eval_accessible_prop(self.get_ref(), item_index, &what, Vec::new())
325        else {
326            return false;
327        };
328        *result = s;
329        true
330    }
331
332    fn accessibility_action(self: Pin<&Self>, item_index: u32, action: &AccessibilityAction) {
333        let what = format!("Action{}", accessibility_action_name(action));
334        eval_accessible_prop(self.get_ref(), item_index, &what, accessibility_action_args(action));
335    }
336
337    fn supported_accessibility_actions(
338        self: Pin<&Self>,
339        item_index: u32,
340    ) -> SupportedAccessibilityAction {
341        let mut actions = SupportedAccessibilityAction::default();
342        for (owner, local_idx) in sub_component_levels(self.get_ref(), item_index) {
343            let sc = &owner.compilation_unit.sub_components[owner.sub_component_idx];
344            let item_props = sc
345                .accessible_prop
346                .range((local_idx, String::new())..)
347                .take_while(|((idx, _), _)| *idx == local_idx);
348            for ((_, key), _) in item_props {
349                if let Some(action_name) = key.strip_prefix("Action") {
350                    actions |= SupportedAccessibilityAction::from_name(action_name)
351                        .unwrap_or_else(|| panic!("Not an accessible action: {action_name:?}"));
352                }
353            }
354        }
355        actions
356    }
357
358    fn item_element_infos(self: Pin<&Self>, item_index: u32, result: &mut SharedString) -> bool {
359        let this = self.get_ref();
360        let cu = &this.root_sub_component.compilation_unit;
361        // Like the code generators, answer for every item when compiled with debug
362        // info, leaving `result` empty for items the compiler synthesized (such as
363        // the wrapper of a `visible` binding). `false` means that the whole tree
364        // lacks debug info.
365        if !cu.has_debug_info {
366            return false;
367        }
368        // A native item's info lives on the leaf sub-component; a
369        // component-instance declaration's (`Switch { }`) lives on the
370        // *parent* of the leaf, keyed by the instance's `index_in_tree`.
371        // The first match wins.
372        for (owner, local_idx) in sub_component_levels(this, item_index) {
373            if let Some(info) =
374                cu.sub_components[owner.sub_component_idx].element_infos.get(&local_idx)
375            {
376                *result = info.as_str().into();
377                break;
378            }
379        }
380        true
381    }
382
383    fn slint_context(self: Pin<&Self>, result: &mut Option<SlintContext>) {
384        *result = Some(self.get_ref().globals.context.clone());
385    }
386
387    fn element_testable_properties(
388        self: Pin<&Self>,
389        item_index: u32,
390        result: &mut SharedString,
391    ) -> bool {
392        let this = self.get_ref();
393        let cu = this.root_sub_component.compilation_unit.clone();
394        if !cu.has_debug_info {
395            return false;
396        }
397        if let Some((owner, local_idx)) = resolve_element_properties_owner(this, item_index) {
398            let sc = &cu.sub_components[owner.sub_component_idx];
399            if let Some(props) = sc.testable_properties.get(&local_idx) {
400                let mut encoded = String::new();
401                for p in props {
402                    use core::fmt::Write;
403                    writeln!(encoded, "{}:{}", p.name, p.ty).unwrap();
404                }
405                *result = encoded.as_str().into();
406            }
407        }
408        true
409    }
410
411    fn element_testable_property_value(
412        self: Pin<&Self>,
413        item_index: u32,
414        property_name: Slice<u8>,
415        result: &mut SharedString,
416    ) -> bool {
417        let this = self.get_ref();
418        let cu = this.root_sub_component.compilation_unit.clone();
419        if !cu.has_debug_info {
420            return false;
421        }
422        let Ok(name) = core::str::from_utf8(property_name.as_slice()) else {
423            return false;
424        };
425        let Some((owner, local_idx)) = resolve_element_properties_owner(this, item_index) else {
426            return false;
427        };
428        let sc = &cu.sub_components[owner.sub_component_idx];
429        let Some(prop) = sc
430            .testable_properties
431            .get(&local_idx)
432            .and_then(|props| props.iter().find(|p| p.name == name))
433        else {
434            return false;
435        };
436        let ctx = crate::eval::EvalContext::new(owner);
437        let value = crate::eval::load_property(&ctx, &prop.prop);
438        format_element_testable_property_value(&value, &prop.ty, result)
439    }
440
441    fn window_adapter(self: Pin<&Self>, do_create: bool, result: &mut Option<WindowAdapterRc>) {
442        // A repeated instance's own `window_adapter` is unset; walk up via
443        // `parent_instance` to the root `Instance` and read its adapter.
444        let this = self.get_ref();
445        if let Some(adapter) = this.window_adapter.get() {
446            *result = Some(adapter.clone());
447            return;
448        }
449        let mut parent_sub = this.parent_instance.upgrade();
450        while let Some(sub) = parent_sub {
451            let Some(root_vrc) = sub.root.get().and_then(|w| w.upgrade()) else { break };
452            if let Some(adapter) = root_vrc.window_adapter.get() {
453                *result = Some(adapter.clone());
454                return;
455            }
456            parent_sub = root_vrc.parent_instance.upgrade();
457        }
458        if do_create {
459            *result = this.window_adapter_or_default();
460        }
461    }
462}
463
464/// Resolve a flat tree index to the sub-component instance whose `testable_properties`
465/// table has an entry for it, plus the local key.
466/// Walks like `item_element_infos`; first match wins.
467fn resolve_element_properties_owner(
468    instance: &Instance,
469    item_index: u32,
470) -> Option<(Pin<Rc<crate::instance::SubComponentInstance>>, u32)> {
471    sub_component_levels(instance, item_index).find(|(owner, local_idx)| {
472        owner.compilation_unit.sub_components[owner.sub_component_idx]
473            .testable_properties
474            .contains_key(local_idx)
475    })
476}
477
478/// Encode `value` per [`i_slint_core::debug_info`],
479/// dispatching on the declared type exactly like the generated code does,
480/// so both runtimes produce the same string.
481fn format_element_testable_property_value(
482    value: &crate::Value,
483    ty: &i_slint_compiler::langtype::Type,
484    result: &mut SharedString,
485) -> bool {
486    use i_slint_compiler::langtype::Type;
487    use i_slint_core::debug_info;
488    match ty {
489        Type::Bool => {
490            let crate::Value::Bool(b) = value else { return false };
491            *result = debug_info::format_bool(*b);
492        }
493        Type::Int32 => {
494            let crate::Value::Number(n) = value else { return false };
495            *result = debug_info::format_integer(*n as i32 as i64);
496        }
497        Type::Duration => {
498            let crate::Value::Number(n) = value else { return false };
499            *result = debug_info::format_integer(*n as i64);
500        }
501        Type::Float32
502        | Type::Angle
503        | Type::Percent
504        | Type::PhysicalLength
505        | Type::LogicalLength
506        | Type::Rem => {
507            let crate::Value::Number(n) = value else { return false };
508            *result = debug_info::format_float(*n as f32);
509        }
510        Type::String => {
511            let crate::Value::String(s) = value else { return false };
512            *result = s.clone();
513        }
514        Type::Color | Type::Brush => {
515            let crate::Value::Brush(b) = value else { return false };
516            let Some(formatted) = debug_info::format_brush(b) else { return false };
517            *result = formatted;
518        }
519        Type::Enumeration(_) => {
520            let crate::Value::EnumerationValue(_, v) = value else { return false };
521            *result = v.replace('_', "-").as_str().into();
522        }
523        _ => return false,
524    }
525    true
526}
527
528/// The sub-components from the root down to the item at the flat tree index `item_index`,
529/// each with the index of the item in that sub-component's tree,
530/// which is what the compiler keys its per-item tables with.
531fn sub_component_levels(
532    instance: &Instance,
533    item_index: u32,
534) -> impl Iterator<Item = (Pin<Rc<crate::instance::SubComponentInstance>>, u32)> + '_ {
535    let entry = instance.item_table.get(item_index as usize).and_then(Option::as_ref);
536    let mut path = entry.map_or(&[][..], |(path, _)| &path[..]).iter();
537    let mut next = entry.map(|_| (instance.root_sub_component.clone(), item_index));
538    core::iter::from_fn(move || {
539        let (owner, local_idx) = next.take()?;
540        let sc = &owner.compilation_unit.sub_components[owner.sub_component_idx];
541        let Some(&sub_idx) = path.next() else {
542            let leaf_idx = sc.items[entry?.1].index_in_tree;
543            return Some((owner, leaf_idx));
544        };
545        let nested = &sc.sub_components[sub_idx];
546        let nested_idx = if local_idx == nested.index_in_tree {
547            0
548        } else if nested.index_of_first_child_in_tree > 0 {
549            local_idx + 1 - nested.index_of_first_child_in_tree
550        } else {
551            local_idx
552        };
553        next = Some((owner.sub_components[sub_idx].clone(), nested_idx));
554        Some((owner, local_idx))
555    })
556}
557
558/// Evaluates the accessible property `key` of the item at `item_index`.
559/// The outermost sub-component that sets it wins, as the generated code forwards
560/// to a sub-component only for the properties not set where it's used.
561fn eval_accessible_prop(
562    instance: &Instance,
563    item_index: u32,
564    key: &str,
565    args: Vec<Value>,
566) -> Option<Value> {
567    let mut key = (0, key.to_string());
568    let (owner, local_idx) =
569        sub_component_levels(instance, item_index).find(|(owner, local_idx)| {
570            key.0 = *local_idx;
571            owner.compilation_unit.sub_components[owner.sub_component_idx]
572                .accessible_prop
573                .contains_key(&key)
574        })?;
575    key.0 = local_idx;
576    let cu = owner.compilation_unit.clone();
577    let expr = &cu.sub_components[owner.sub_component_idx].accessible_prop[&key];
578    let mut ctx = crate::eval::EvalContext::with_arguments(owner, args);
579    Some(crate::eval::eval_expression(&mut ctx, &expr.borrow()))
580}
581
582/// The `accessible_prop` map key for a string property — the same
583/// PascalCase form the lowering derives from the enum's kebab-case
584/// `Display` (see `lower_to_item_tree`).
585fn accessible_string_property_name(what: AccessibleStringProperty) -> String {
586    i_slint_compiler::names::to_pascal_case(&what.to_string())
587}
588
589fn accessibility_action_name(action: &AccessibilityAction) -> &'static str {
590    match action {
591        AccessibilityAction::Default => "Default",
592        AccessibilityAction::Decrement => "Decrement",
593        AccessibilityAction::Increment => "Increment",
594        AccessibilityAction::Expand => "Expand",
595        AccessibilityAction::ReplaceSelectedText(_) => "ReplaceSelectedText",
596        AccessibilityAction::SetValue(_) => "SetValue",
597        AccessibilityAction::SetSelectionOffsets(..) => "SetSelectionOffsets",
598    }
599}
600
601fn accessibility_action_args(action: &AccessibilityAction) -> Vec<Value> {
602    match action {
603        AccessibilityAction::ReplaceSelectedText(s) | AccessibilityAction::SetValue(s) => {
604            vec![Value::String(s.clone())]
605        }
606        AccessibilityAction::SetSelectionOffsets(anchor, focus) => {
607            vec![Value::Number(*anchor as f64), Value::Number(*focus as f64)]
608        }
609        _ => Vec::new(),
610    }
611}