a11y uia: Report locale via UIA_CulturePropertyId

Map QAccessible::Attribute::Locale to
UIA_CulturePropertyId [1] in the Windows UIA
accessibility bridge:

> Identifies the Culture property, which contains a
> locale identifier for the automation element (for
> example, 0x0409 for "en-US" or English (United States)).

In a test with 2 spinboxes whose locales were explicitly
set to

* QLocale(QLocale::English, QLocale::UnitedStates))
* QLocale(QLocale::Chinese, QLocale::China))

, retrieving the current value of UIA_CulturePropertyId (30015)
using NVDA's Python console gives the expected result:

With the spinbox whose locale is set to English/United States:

	>>> hex(focus.UIAElement.GetCurrentPropertyValue(30015))
	'0x409'

With the spinbox whose locale is set to Chinese/China:

	>>> hex(focus.UIAElement.GetCurrentPropertyValue(30015))
	'0x804'

as "[MS-LCID]: Windows Language Code Identifier (LCID) Reference" [2]
lists these identifiers as follows:

* 0x0409 en-US
* 0x0804 zh-CN

[1] https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids
[2] https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f

Task-number: QTBUG-137144
Change-Id: I2b0cad9ab7ede9f01dee3d7f3efddb8c5335caaf
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Michael Weghorn 2025-05-27 17:04:00 +02:00
parent bb2121551c
commit 854d7021b8

View File

@ -535,6 +535,20 @@ HRESULT QWindowsUiaMainProvider::GetPropertyValue(PROPERTYID idProp, VARIANT *pR
*pRetVal = QComVariant{ className }.release();
}
break;
case UIA_CulturePropertyId:
{
QLocale locale;
if (QAccessibleAttributesInterface *attributesIface = accessible->attributesInterface()) {
const QVariant localeVariant = attributesIface->attributeValue(QAccessible::Attribute::Locale);
if (localeVariant.isValid()) {
Q_ASSERT(localeVariant.canConvert<QLocale>());
locale = localeVariant.toLocale();
}
}
LCID lcid = LocaleNameToLCID(qUtf16Printable(locale.bcp47Name()), 0);
*pRetVal = QComVariant{ long(lcid) }.release();
break;
}
case UIA_DescribedByPropertyId:
fillVariantArrayForRelation(accessible, QAccessible::DescriptionFor, pRetVal);
break;