From 30c254591d30300221fe4d98dbe885474a2889d9 Mon Sep 17 00:00:00 2001 From: Even Oscar Andersen Date: Fri, 6 Jun 2025 09:52:23 +0200 Subject: [PATCH] wasm: a11y - Implement support for disabled attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: QTBUG-137449 Change-Id: I6aa07c7108b5ad14c12e6f24e71b8dda12fec483 Reviewed-by: Morten Johan Sørvig --- .../platforms/wasm/qwasmaccessibility.cpp | 15 ++++++++++++++- src/plugins/platforms/wasm/qwasmaccessibility.h | 1 + src/widgets/kernel/qwidget.cpp | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/wasm/qwasmaccessibility.cpp b/src/plugins/platforms/wasm/qwasmaccessibility.cpp index 842d70145a1..fdbd301753e 100644 --- a/src/plugins/platforms/wasm/qwasmaccessibility.cpp +++ b/src/plugins/platforms/wasm/qwasmaccessibility.cpp @@ -454,7 +454,7 @@ void QWasmAccessibility::setHtmlElementVisibility(QAccessibleInterface *iface, b container.call("appendChild", element); - visible = visible && !iface->state().invisible && !iface->state().disabled; + visible = visible && !iface->state().invisible; setProperty(element, "ariaHidden", !visible); // ariaHidden mean completely hidden; maybe some sort of soft-hidden should be used. } @@ -513,6 +513,12 @@ void QWasmAccessibility::setHtmlElementFocus(QAccessibleInterface *iface) element.call("focus"); } +void QWasmAccessibility::setHtmlElementDisabled(QAccessibleInterface *iface) +{ + auto element = ensureHtmlElement(iface); + setAttribute(element, "aria-disabled", iface->state().disabled); +} + void QWasmAccessibility::handleStaticTextUpdate(QAccessibleEvent *event) { switch (event->type()) { @@ -677,6 +683,7 @@ void QWasmAccessibility::populateAccessibilityTree(QAccessibleInterface *iface) setHtmlElementVisibility(iface, true); setHtmlElementGeometry(iface); setHtmlElementTextName(iface); + setHtmlElementDisabled(iface); handleIdentifierUpdate(iface); handleDescriptionChanged(iface); } @@ -853,6 +860,12 @@ void QWasmAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) // Handle some common event types. See // https://doc.qt.io/qt-5/qaccessible.html#Event-enum switch (event->type()) { + case QAccessible::StateChanged: { + QAccessibleStateChangeEvent *stateChangeEvent = (QAccessibleStateChangeEvent *)event; + if (stateChangeEvent->changedStates().disabled) + setHtmlElementDisabled(iface); + } break; + case QAccessible::DescriptionChanged: handleDescriptionChanged(iface); return; diff --git a/src/plugins/platforms/wasm/qwasmaccessibility.h b/src/plugins/platforms/wasm/qwasmaccessibility.h index c5dc9d9cb73..64e7f603833 100644 --- a/src/plugins/platforms/wasm/qwasmaccessibility.h +++ b/src/plugins/platforms/wasm/qwasmaccessibility.h @@ -58,6 +58,7 @@ private: void setHtmlElementTextName(QAccessibleInterface *iface); void setHtmlElementTextNameLE(QAccessibleInterface *iface); void setHtmlElementFocus(QAccessibleInterface *iface); + void setHtmlElementDisabled(QAccessibleInterface *iface); void handleStaticTextUpdate(QAccessibleEvent *event); void handleButtonUpdate(QAccessibleEvent *event); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e2a505f6e2a..1155172a0a8 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -3377,8 +3377,25 @@ QAction *QWidget::addAction(const QIcon &icon, const QString &text, const QKeySe void QWidget::setEnabled(bool enable) { Q_D(QWidget); + +#if QT_CONFIG(accessibility) + const bool wasEnabled = !testAttribute(Qt::WA_ForceDisabled); +#endif + setAttribute(Qt::WA_ForceDisabled, !enable); d->setEnabled_helper(enable); + +#if QT_CONFIG(accessibility) + // A widget is enabled if it's parent and itself is enabled. + // We do not send state changed events recursively. It is up + // to the receiver of the events to check children if required. + if (QAccessible::isActive() && wasEnabled != enable) { + QAccessible::State states; + states.disabled = 1; + QAccessibleStateChangeEvent scEvent(this, states); + QAccessible::updateAccessibility(&scEvent); + } +#endif } void QWidgetPrivate::setEnabled_helper(bool enable)