mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 12:54:45 +00:00

Implement basic accessibility (a11y) support, using the Qt backend. _This should get us started, but accessibility support is an additional way to interact with UIs that is very different from the "graphical way" most users will interact with the UI. No single PR will "make a toolkit accessibility", this needs to be an ongoing effort!_ Parts of this PR: * Add functions to access a11y-related properties to Component * Add helper functions to Item struct * Handle accessible- properties in the compiler * Add documentation, add description, enforce some basic rules * Make the Text element accessible by default * Don't optimize away accessibility property in the LLR * Ensure that accessibility property are marked as used * Add some accessibility properties to the native style widgets * Support for bool and integer `accessible` properties * Implement basic support for accessibility * Make basic widgets accessible by default * Make slider focus-able and interactable with keyboard * Tell a11y layer about value changes * Generate QAccessible constants using bindgen * Don't expose the `accessible` properties when using the MCU backend: There is no backend to make use of them * Handle focus change based on keyboard focus of the window * Report accessible widgets at correct positions * Allow for (virtual) focus delegation at the a11y level * Calculate value step size dynamically * Make sure to not send notifications to a11y backend about dead objects
117 lines
4.7 KiB
Rust
117 lines
4.7 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
|
|
/*!
|
|
Make sure that the Repeated expression are just components without any children
|
|
*/
|
|
|
|
use crate::expression_tree::{Expression, NamedReference};
|
|
use crate::langtype::Type;
|
|
use crate::object_tree::*;
|
|
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
|
|
pub fn process_repeater_components(component: &Rc<Component>) {
|
|
create_repeater_components(component);
|
|
adjust_references(component);
|
|
}
|
|
|
|
fn create_repeater_components(component: &Rc<Component>) {
|
|
recurse_elem(&component.root_element, &(), &mut |elem, _| {
|
|
let is_listview = match &elem.borrow().repeated {
|
|
Some(r) => r.is_listview.clone(),
|
|
None => return,
|
|
};
|
|
let parent_element = Rc::downgrade(elem);
|
|
let mut elem = elem.borrow_mut();
|
|
|
|
let comp = Rc::new(Component {
|
|
root_element: Rc::new(RefCell::new(Element {
|
|
id: elem.id.clone(),
|
|
base_type: std::mem::take(&mut elem.base_type),
|
|
bindings: std::mem::take(&mut elem.bindings),
|
|
property_analysis: std::mem::take(&mut elem.property_analysis),
|
|
children: std::mem::take(&mut elem.children),
|
|
property_declarations: std::mem::take(&mut elem.property_declarations),
|
|
named_references: Default::default(),
|
|
repeated: None,
|
|
node: elem.node.clone(),
|
|
enclosing_component: Default::default(),
|
|
states: std::mem::take(&mut elem.states),
|
|
transitions: std::mem::take(&mut elem.transitions),
|
|
child_of_layout: elem.child_of_layout || is_listview.is_some(),
|
|
layout_info_prop: elem.layout_info_prop.take(),
|
|
accessibility_props: std::mem::take(&mut elem.accessibility_props),
|
|
is_flickable_viewport: elem.is_flickable_viewport,
|
|
has_popup_child: elem.has_popup_child,
|
|
item_index: Default::default(), // Not determined yet
|
|
item_index_of_first_children: Default::default(),
|
|
inline_depth: 0,
|
|
})),
|
|
parent_element,
|
|
..Component::default()
|
|
});
|
|
|
|
if let Some(listview) = is_listview {
|
|
if !comp.root_element.borrow().is_binding_set("height", false) {
|
|
let preferred = Expression::PropertyReference(NamedReference::new(
|
|
&comp.root_element,
|
|
"preferred-height",
|
|
));
|
|
comp.root_element
|
|
.borrow_mut()
|
|
.bindings
|
|
.insert("height".into(), RefCell::new(preferred.into()));
|
|
}
|
|
if !comp.root_element.borrow().is_binding_set("width", false) {
|
|
comp.root_element.borrow_mut().bindings.insert(
|
|
"width".into(),
|
|
RefCell::new(Expression::PropertyReference(listview.listview_width).into()),
|
|
);
|
|
}
|
|
|
|
NamedReference::new(&comp.root_element, "y").mark_as_set();
|
|
}
|
|
|
|
let weak = Rc::downgrade(&comp);
|
|
recurse_elem(&comp.root_element, &(), &mut |e, _| {
|
|
e.borrow_mut().enclosing_component = weak.clone()
|
|
});
|
|
create_repeater_components(&comp);
|
|
elem.base_type = Type::Component(comp);
|
|
});
|
|
|
|
for p in component.popup_windows.borrow().iter() {
|
|
create_repeater_components(&p.component);
|
|
}
|
|
}
|
|
|
|
/// Make sure that references to property within the repeated element actually point to the reference
|
|
/// to the root of the newly created component
|
|
fn adjust_references(comp: &Rc<Component>) {
|
|
visit_all_named_references(comp, &mut |nr| {
|
|
if nr.name() == "$model" {
|
|
return;
|
|
}
|
|
let e = nr.element();
|
|
if e.borrow().repeated.is_some() {
|
|
if let Type::Component(c) = e.borrow().base_type.clone() {
|
|
*nr = NamedReference::new(&c.root_element, nr.name())
|
|
};
|
|
}
|
|
});
|
|
// Transform any references to the repeated element to refer to the root of each instance.
|
|
visit_all_expressions(comp, |expr, _| {
|
|
expr.visit_recursive_mut(&mut |expr| {
|
|
if let Expression::ElementReference(ref mut element_ref) = expr {
|
|
if let Some(repeater_element) =
|
|
element_ref.upgrade().filter(|e| e.borrow().repeated.is_some())
|
|
{
|
|
let inner_element =
|
|
repeater_element.borrow().base_type.as_component().root_element.clone();
|
|
*element_ref = Rc::downgrade(&inner_element);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
}
|