summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEven Oscar Andersen <[email protected]>2025-09-30 10:12:52 +0200
committerEven Oscar Andersen <[email protected]>2025-10-21 17:42:21 +0200
commita3ae69fe337f67734ac647f11e187e18e2befc14 (patch)
treefa6b25cfe894faead751dcb83e426e701d550861
parent8ee755a2c81ba8e695a2c7c3abb4a3f4748ab93f (diff)
wasm: a11y - Handle case where a child does not have a childIndex
Some interfaces will return -1 for childIndex. Work around this by adding an explicit test. Change-Id: I703f20f8d57ed4cb7e69efd87e03c68eb30aec90 Reviewed-by: Morten Johan Sørvig <[email protected]>
-rw-r--r--src/plugins/platforms/wasm/qwasmaccessibility.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/plugins/platforms/wasm/qwasmaccessibility.cpp b/src/plugins/platforms/wasm/qwasmaccessibility.cpp
index 6a3c139a060..5fa79482217 100644
--- a/src/plugins/platforms/wasm/qwasmaccessibility.cpp
+++ b/src/plugins/platforms/wasm/qwasmaccessibility.cpp
@@ -543,6 +543,7 @@ void QWasmAccessibility::linkToParent(QAccessibleInterface *iface)
{
emscripten::val element = getHtmlElement(iface);
emscripten::val container = getElementContainer(iface);
+
if (container.isUndefined() || element.isUndefined())
return;
@@ -555,21 +556,21 @@ void QWasmAccessibility::linkToParent(QAccessibleInterface *iface)
emscripten::val next = emscripten::val::undefined();
const int thisIndex = iface->parent()->indexOfChild(iface);
- Q_ASSERT(thisIndex >= 0 && thisIndex < iface->parent()->childCount());
- for (int i = thisIndex + 1; i < iface->parent()->childCount(); ++i) {
- const auto elementI = getHtmlElement(iface->parent()->child(i));
- if (!elementI.isUndefined() &&
- elementI["parentElement"] == container) {
- next = elementI;
- break;
+ if (thisIndex >= 0) {
+ Q_ASSERT(thisIndex < iface->parent()->childCount());
+ for (int i = thisIndex + 1; i < iface->parent()->childCount(); ++i) {
+ const auto elementI = getHtmlElement(iface->parent()->child(i));
+ if (!elementI.isUndefined() &&
+ elementI["parentElement"] == container) {
+ next = elementI;
+ break;
+ }
}
+ if (next.isUndefined())
+ container.call<void>("appendChild", element);
+ else
+ container.call<void>("insertBefore", element, next);
}
- if (next.isUndefined()) {
- container.call<void>("appendChild", element);
- } else {
- container.call<void>("insertBefore", element, next);
- }
-
const auto activeElementAfter = emscripten::val::take_ownership(
getActiveElement_js(emscripten::val::undefined().as_handle()));
if (activeElementBefore != activeElementAfter) {