Add description to the HTML tags using aria-description

Description added to the html tags for accessibility in wasm through the
aria-description property

Change-Id: Ic1976d5c4c64ea45298f24b660807adeda6fdb64
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Shreya Pattani 2023-08-10 13:41:54 +05:30
parent 4cf51f4616
commit e3925996f1
2 changed files with 45 additions and 6 deletions

View File

@ -5,7 +5,6 @@
#include "qwasmscreen.h"
#include "qwasmwindow.h"
#include "qwasmintegration.h"
#include <QtGui/qwindow.h>
#if QT_CONFIG(accessibility)
@ -364,12 +363,21 @@ void QWasmAccessibility::setHtmlElementTextNameLE(QAccessibleInterface *iface) {
element.set("innerHTML", value.toStdString());
}
void QWasmAccessibility::setHtmlElementDescription(QAccessibleInterface *iface) {
emscripten::val element = ensureHtmlElement(iface);
QString desc = iface->text(QAccessible::Description);
element.call<void>("setAttribute", std::string("aria-description"), desc.toStdString());
}
void QWasmAccessibility::handleStaticTextUpdate(QAccessibleEvent *event)
{
switch (event->type()) {
case QAccessible::NameChanged: {
setHtmlElementTextName(event->accessibleInterface());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleStaticTextUpdate for event" << event->type();
break;
@ -388,7 +396,9 @@ void QWasmAccessibility::handleLineEditUpdate(QAccessibleEvent *event) {
case QAccessible::TextCaretMoved: {
setHtmlElementTextNameLE(event->accessibleInterface());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleLineEditUpdate for event" << event->type();
break;
@ -399,13 +409,11 @@ void QWasmAccessibility::handleEventFromHtmlElement(const emscripten::val event)
{
QAccessibleInterface *iface = m_elements.key(event["target"]);
if (iface == nullptr) {
return;
} else {
QString eventType = QString::fromStdString(event["type"].as<std::string>());
const auto& actionNames = QAccessibleBridgeUtils::effectiveActionNames(iface);
if (actionNames.contains(QAccessibleActionInterface::pressAction())) {
iface->actionInterface()->doAction(QAccessibleActionInterface::pressAction());
@ -452,6 +460,9 @@ void QWasmAccessibility::handleCheckBoxUpdate(QAccessibleEvent *event)
bool checkedString = accessible->state().checked ? true : false;
element.call<void>("setAttribute", std::string("checked"), checkedString);
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleCheckBoxUpdate for event" << event->type();
break;
@ -468,6 +479,9 @@ void QWasmAccessibility::handleToolUpdate(QAccessibleEvent *event)
emscripten::val element = ensureHtmlElement(iface);
element.call<void>("setAttribute", std::string("title"), text.toStdString());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleToolUpdate for event" << event->type();
break;
@ -486,6 +500,9 @@ void QWasmAccessibility::handleMenuUpdate(QAccessibleEvent *event)
emscripten::val element = ensureHtmlElement(iface);
element.call<void>("setAttribute", std::string("title"), text.toStdString());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleMenuUpdate for event" << event->type();
break;
@ -500,7 +517,9 @@ void QWasmAccessibility::handleDialogUpdate(QAccessibleEvent *event) {
case QAccessible::StateChanged: {
setHtmlElementTextName(event->accessibleInterface());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qCDebug(lcQpaAccessibility) << "TODO: implement handleLineEditUpdate for event" << event->type();
break;
@ -518,6 +537,7 @@ void QWasmAccessibility::populateAccessibilityTree(QAccessibleInterface *iface)
setHtmlElementVisibility(iface, visible);
setHtmlElementGeometry(iface);
setHtmlElementTextName(iface);
setHtmlElementDescription(iface);
for (int i = 0; i < iface->childCount(); ++i)
populateAccessibilityTree(iface->child(i));
@ -536,6 +556,9 @@ void QWasmAccessibility::handleRadioButtonUpdate(QAccessibleEvent *event)
std::string checkedString = accessible->state().checked ? "true" : "false";
element.call<void>("setAttribute", std::string("checked"), checkedString);
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handleRadioButtonUpdate for event" << event->type();
break;
@ -555,6 +578,9 @@ void QWasmAccessibility::handleSpinBoxUpdate(QAccessibleEvent *event)
std::string valueString = accessible->valueInterface()->currentValue().toString().toStdString();
element.call<void>("setAttribute", std::string("value"), valueString);
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handleSpinBoxUpdate for event" << event->type();
break;
@ -574,6 +600,9 @@ void QWasmAccessibility::handleSliderUpdate(QAccessibleEvent *event)
std::string valueString = accessible->valueInterface()->currentValue().toString().toStdString();
element.call<void>("setAttribute", std::string("value"), valueString);
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handleSliderUpdate for event" << event->type();
break;
@ -593,6 +622,9 @@ void QWasmAccessibility::handleScrollBarUpdate(QAccessibleEvent *event)
std::string valueString = accessible->valueInterface()->currentValue().toString().toStdString();
element.call<void>("setAttribute", std::string("aria-valuenow"), valueString);
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handleSliderUpdate for event" << event->type();
break;
@ -609,6 +641,9 @@ void QWasmAccessibility::handlePageTabUpdate(QAccessibleEvent *event)
case QAccessible::Focus: {
setHtmlElementTextName(event->accessibleInterface());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handlePageTabUpdate for event" << event->type();
break;
@ -624,6 +659,9 @@ void QWasmAccessibility::handlePageTabListUpdate(QAccessibleEvent *event)
case QAccessible::Focus: {
setHtmlElementTextName(event->accessibleInterface());
} break;
case QAccessible::DescriptionChanged: {
setHtmlElementDescription(event->accessibleInterface());
} break;
default:
qDebug() << "TODO: implement handlePageTabUpdate for event" << event->type();
break;
@ -645,12 +683,12 @@ void QWasmAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
// https://doc.qt.io/qt-5/qaccessible.html#Event-enum
switch (event->type()) {
case QAccessible::ObjectShow:
setHtmlElementVisibility(iface, true);
// Sync up properties on show;
setHtmlElementGeometry(iface);
setHtmlElementTextName(iface);
setHtmlElementDescription(iface);
return;
break;

View File

@ -48,6 +48,7 @@ private:
void setHtmlElementGeometry(emscripten::val element, QRect geometry);
void setHtmlElementTextName(QAccessibleInterface *iface);
void setHtmlElementTextNameLE(QAccessibleInterface *iface);
void setHtmlElementDescription(QAccessibleInterface *iface);
void handleStaticTextUpdate(QAccessibleEvent *event);
void handleButtonUpdate(QAccessibleEvent *event);