1
0
Fork 0

Another rewrite

This commit is contained in:
Duncan Ogilvie 2026-07-21 12:39:24 +02:00
parent 8ab705c574
commit 8b918baf24
18 changed files with 612 additions and 73 deletions

View File

@ -23,9 +23,10 @@ The script activates every minidump tab and covers every interface supplied by
| Disassembly | `AccessibleDisassembly` | | Disassembly | `AccessibleDisassembly` |
| Registers | `AccessibleRegistersView` | | Registers | `AccessibleRegistersView` |
This also exercises `AccessibleAbstractTableView`, its virtual data cells and This also exercises `AccessibleAbstractTableView`, its virtual data cells,
column headers, native parent/child navigation, names, bounds, focus, selection, column headers, dedicated hidden row headers, native parent/child navigation,
and model resets caused by scrolling. The Threads `QTableWidget` is captured as names, bounds, focus, selection, register visual order, and model resets caused
by scrolling. The Threads `QTableWidget` is captured as
a native Qt-table comparison. a native Qt-table comparison.
The first runs intentionally produce rich platform-specific captures. Use The first runs intentionally produce rich platform-specific captures. Use
@ -132,7 +133,9 @@ The output directory contains:
- `minidump.stdout.log` and `minidump.stderr.log`. - `minidump.stdout.log` and `minidump.stderr.log`.
xa11y currently normalizes Qt/UIA DataItem cells as `table_row` on Windows. xa11y currently normalizes Qt/UIA DataItem cells as `table_row` on Windows.
Linux exposes the corresponding objects directly as `table_cell`; macOS exposes The action check recognizes those native DataItems so this known normalization
bug does not prevent testing real cell selection. Linux exposes the
corresponding objects directly as `table_cell`; macOS exposes
`AXRow` containers with nested `AXCell`/`table_cell` objects. The underlying `AXRow` containers with nested `AXCell`/`table_cell` objects. The underlying
x64dbg child layout deliberately follows Qt's native accessible table contract; x64dbg child layout deliberately follows Qt's native accessible table contract;
the capture records both normalized roles and native `raw` fields so these the capture records both normalized roles and native `raw` fields so these

View File

@ -32,6 +32,7 @@ class ControlSpec:
expected_names: tuple[str, ...] expected_names: tuple[str, ...]
minimum_children: int minimum_children: int
minimum_named_children: int = 1 minimum_named_children: int = 1
expected_order: tuple[str, ...] = ()
exercise_scroll: bool = False exercise_scroll: bool = False
exercise_selection: bool = False exercise_selection: bool = False
@ -99,6 +100,16 @@ TAB_SPECS = (
"list[name='Registers']", "list[name='Registers']",
("RAX", "RSP", "RIP"), ("RAX", "RSP", "RIP"),
10, 10,
expected_order=(
"RAX",
"RBX",
"RCX",
"RDX",
"RBP",
"RSP",
"RSI",
"RDI",
),
exercise_selection=True, exercise_selection=True,
), ),
), ),
@ -426,8 +437,16 @@ def selectable_descendants(element: Any, depth: int = 2) -> list[Any]:
following = [] following = []
for parent in current: for parent in current:
for child in parent.children(): for child in parent.children():
# xa11y 0.11.0 normalizes Windows UIA DataItem controls as
# table_row even when GridItem/TableItem identify them as cells.
# Accept that known backend role here so selection remains an
# end-to-end action test instead of duplicating the role bug.
is_selectable_item = child.role in ("table_cell", "list_item") or (
child.role == "table_row"
and child.raw.get("control_type_id") == 50029
)
if ( if (
child.role in ("table_cell", "list_item") is_selectable_item
and child.visible and child.visible
and child.bounds is not None and child.bounds is not None
and child.bounds.width > 0 and child.bounds.width > 0
@ -700,6 +719,33 @@ def main() -> int:
else: else:
add_check(checks, found, message, args.strict) add_check(checks, found, message, args.strict)
if control_spec.expected_order:
try:
direct_names = [
child.name or "" for child in element.children()
]
except Exception:
direct_names = []
expected_positions = [
next(
(
index
for index, name in enumerate(direct_names)
if name == expected
or name.startswith(expected + " =")
),
-1,
)
for expected in control_spec.expected_order
]
add_check(
checks,
all(position >= 0 for position in expected_positions)
and expected_positions == sorted(expected_positions),
f"{control_spec.selector} exposes registers in visual order",
args.strict,
)
bounds = snapshot.get("bounds") bounds = snapshot.get("bounds")
add_check( add_check(
checks, checks,

View File

@ -4,6 +4,7 @@
#include "AccessibleAbstractTableViewCell.h" #include "AccessibleAbstractTableViewCell.h"
#include "AccessibleAbstractTableViewCellTitle.h" #include "AccessibleAbstractTableViewCellTitle.h"
#include <algorithm> #include <algorithm>
#include <exception>
AccessibleAbstractTableView::AccessibleAbstractTableView(QWidget* w) AccessibleAbstractTableView::AccessibleAbstractTableView(QWidget* w)
: QAccessibleWidget(w, QAccessible::Table, dynamic_cast<AbstractTableView*>(w)->accessibleName()) : QAccessibleWidget(w, QAccessible::Table, dynamic_cast<AbstractTableView*>(w)->accessibleName())
@ -29,20 +30,40 @@ AbstractTableView* AccessibleAbstractTableView::getTable() const
return m_tableView; return m_tableView;
} }
std::vector<QAccessible::Id> AccessibleAbstractTableView::takeChildInterfaces()
{
std::vector<QAccessible::Id> result;
result.reserve(1
+ columnTitleInterfaces.size()
+ rowTitleInterfaces.size()
+ cellInterfaces.size());
result.push_back(cornerInterface);
result.insert(result.end(), columnTitleInterfaces.begin(), columnTitleInterfaces.end());
result.insert(result.end(), rowTitleInterfaces.begin(), rowTitleInterfaces.end());
result.insert(result.end(), cellInterfaces.begin(), cellInterfaces.end());
// Detach every old ID before deletion. Qt 6.11+ emits synchronous
// ObjectDestroyed notifications for objectless interfaces, so callbacks
// must observe an empty/current cache rather than IDs being torn down.
cornerInterface = 0;
columnTitleInterfaces.clear();
rowTitleInterfaces.clear();
cellInterfaces.clear();
return result;
}
void AccessibleAbstractTableView::deleteChildInterfaces(const std::vector<QAccessible::Id>& ids)
{
for(const auto id : ids)
{
if(id != 0)
QAccessible::deleteAccessibleInterface(id);
}
}
void AccessibleAbstractTableView::clearChildInterfaces() void AccessibleAbstractTableView::clearChildInterfaces()
{ {
for(const auto id : columnTitleInterfaces) deleteChildInterfaces(takeChildInterfaces());
{
if(id != 0)
QAccessible::deleteAccessibleInterface(id);
}
for(const auto id : cellInterfaces)
{
if(id != 0)
QAccessible::deleteAccessibleInterface(id);
}
columnTitleInterfaces.clear();
cellInterfaces.clear();
} }
std::vector<duint> AccessibleAbstractTableView::visibleColumns() const std::vector<duint> AccessibleAbstractTableView::visibleColumns() const
@ -122,7 +143,44 @@ QAccessibleInterface* AccessibleAbstractTableView::columnHeaderInterface(int col
if(id == 0) if(id == 0)
{ {
id = QAccessible::registerAccessibleInterface( id = QAccessible::registerAccessibleInterface(
new AccessibleAbstractTableViewCellTitle(m_tableView, column, modelRevision)); new AccessibleAbstractTableViewCellTitle(
m_tableView,
AccessibleAbstractTableViewCellTitle::HeaderType::Column,
column,
modelRevision));
}
return QAccessible::accessibleInterface(id);
}
QAccessibleInterface* AccessibleAbstractTableView::rowHeaderInterface(int row) const
{
if(row < 0 || row >= rows)
return nullptr;
auto & id = const_cast<std::vector<QAccessible::Id>&>(rowTitleInterfaces).at(row);
if(id == 0)
{
id = QAccessible::registerAccessibleInterface(
new AccessibleAbstractTableViewCellTitle(
m_tableView,
AccessibleAbstractTableViewCellTitle::HeaderType::Row,
row,
modelRevision));
}
return QAccessible::accessibleInterface(id);
}
QAccessibleInterface* AccessibleAbstractTableView::cornerHeaderInterface() const
{
auto & id = const_cast<QAccessible::Id &>(cornerInterface);
if(id == 0)
{
id = QAccessible::registerAccessibleInterface(
new AccessibleAbstractTableViewCellTitle(
m_tableView,
AccessibleAbstractTableViewCellTitle::HeaderType::Corner,
-1,
modelRevision));
} }
return QAccessible::accessibleInterface(id); return QAccessible::accessibleInterface(id);
} }
@ -130,21 +188,27 @@ QAccessibleInterface* AccessibleAbstractTableView::columnHeaderInterface(int col
int AccessibleAbstractTableView::childCount() const int AccessibleAbstractTableView::childCount() const
{ {
ensureModelUpToDate(); ensureModelUpToDate();
return cols + static_cast<int>(cellInterfaces.size()); return (rows + 1) * (cols + 1);
} }
QAccessibleInterface* AccessibleAbstractTableView::child(int index) const QAccessibleInterface* AccessibleAbstractTableView::child(int index) const
{ {
ensureModelUpToDate(); ensureModelUpToDate();
if(index < 0) if(index < 0 || index >= (rows + 1) * (cols + 1))
return nullptr; return nullptr;
if(index < cols)
return columnHeaderInterface(index);
const int cellIndex = index - cols; const int stride = cols + 1;
if(cellIndex < 0 || cellIndex >= static_cast<int>(cellInterfaces.size()) || cols == 0) const int structuralRow = index / stride;
return nullptr; const int structuralColumn = index % stride;
return cellInterface(cellIndex / cols, cellIndex % cols); if(structuralRow == 0)
{
if(structuralColumn == 0)
return cornerHeaderInterface();
return columnHeaderInterface(structuralColumn - 1);
}
if(structuralColumn == 0)
return rowHeaderInterface(structuralRow - 1);
return cellInterface(structuralRow - 1, structuralColumn - 1);
} }
QAccessibleInterface* AccessibleAbstractTableView::childAt(int x, int y) const QAccessibleInterface* AccessibleAbstractTableView::childAt(int x, int y) const
@ -243,6 +307,11 @@ QAccessibleInterface* AccessibleAbstractTableView::caption() const
QAccessibleInterface* AccessibleAbstractTableView::cellAt(int row, int column) const QAccessibleInterface* AccessibleAbstractTableView::cellAt(int row, int column) const
{ {
ensureModelUpToDate(); ensureModelUpToDate();
// Match QAccessibleTable's header extension to the public data-cell API.
if(row == -1)
return column == -1 ? cornerHeaderInterface() : columnHeaderInterface(column);
if(column == -1)
return rowHeaderInterface(row);
return cellInterface(row, column); return cellInterface(row, column);
} }
@ -278,10 +347,12 @@ void AccessibleAbstractTableView::modelChange(QAccessibleTableModelChangeEvent*
{ {
Q_UNUSED(event); Q_UNUSED(event);
// Every event emitted by AbstractTableView is a model reset. Clear virtual // Every event emitted by AbstractTableView is a model reset. Visible
// interfaces even when the dimensions did not change: after scrolling the // coordinates have new identity after scrolling even if dimensions match.
// same viewport coordinate represents a different logical row. // Publish the new generation and empty cache before deleting old IDs: Qt
clearChildInterfaces(); // 6.11+ synchronously dispatches ObjectDestroyed for virtual interfaces,
// and Cocoa may re-query this adapter from that callback.
const auto oldInterfaces = takeChildInterfaces();
modelRevision = m_tableView ? m_tableView->accessibilityModelRevision : 0; modelRevision = m_tableView ? m_tableView->accessibilityModelRevision : 0;
tableOffset = m_tableView ? m_tableView->getTableOffset() : 0; tableOffset = m_tableView ? m_tableView->getTableOffset() : 0;
rows = visibleRowCount(); rows = visibleRowCount();
@ -289,6 +360,9 @@ void AccessibleAbstractTableView::modelChange(QAccessibleTableModelChangeEvent*
cols = static_cast<int>(m_visibleColumns.size()); cols = static_cast<int>(m_visibleColumns.size());
cellInterfaces.assign(static_cast<size_t>(rows) * cols, 0); cellInterfaces.assign(static_cast<size_t>(rows) * cols, 0);
columnTitleInterfaces.assign(cols, 0); columnTitleInterfaces.assign(cols, 0);
rowTitleInterfaces.assign(rows, 0);
cornerInterface = 0;
deleteChildInterfaces(oldInterfaces);
} }
int AccessibleAbstractTableView::rowCount() const int AccessibleAbstractTableView::rowCount() const
@ -299,9 +373,17 @@ int AccessibleAbstractTableView::rowCount() const
QString AccessibleAbstractTableView::rowDescription(int row) const QString AccessibleAbstractTableView::rowDescription(int row) const
{ {
Q_UNUSED(row); ensureModelUpToDate();
// AbstractTableView has no visual row headers. if(row < 0 || row >= rows || !m_tableView || m_tableView->getColumnCount() == 0)
return QString(); return QString();
try
{
return getCellContent(row, 0);
}
catch(const std::exception &)
{
return QString();
}
} }
bool AccessibleAbstractTableView::selectColumn(int column) bool AccessibleAbstractTableView::selectColumn(int column)
@ -388,6 +470,16 @@ bool AccessibleAbstractTableView::headerIsValid(int column) const
return isValid() && modelIsCurrent() && column >= 0 && column < cols; return isValid() && modelIsCurrent() && column >= 0 && column < cols;
} }
bool AccessibleAbstractTableView::rowHeaderIsValid(int row) const
{
return isValid() && modelIsCurrent() && row >= 0 && row < rows;
}
bool AccessibleAbstractTableView::cornerIsValid() const
{
return isValid() && modelIsCurrent();
}
QRect AccessibleAbstractTableView::elementRect(int row, int column, bool header) const QRect AccessibleAbstractTableView::elementRect(int row, int column, bool header) const
{ {
if((header && !headerIsValid(column)) || (!header && !cellIsValid(row, column))) if((header && !headerIsValid(column)) || (!header && !cellIsValid(row, column)))

View File

@ -6,15 +6,19 @@
/** /**
* Accessible interface for AbstractTableView. * Accessible interface for AbstractTableView.
* This accessibility interface only exposes what is visible on the screen because the data scale of underlying AbstractTableView is uncontrollable. * This accessibility interface only exposes what is visible on the screen because the data scale of underlying AbstractTableView is uncontrollable.
* Its direct-child layout matches Qt's QAccessibleTable without a vertical * Its direct-child layout matches QAccessibleTable with horizontal and vertical
* header: column headers first, followed by row-major data cells. Like Qt's * headers: a hidden corner, column headers, then a hidden row header followed by
* item-view adapter, virtual children retain the widget and model identity and * each row's data cells. Row-header names use the first raw data column, like a
* re-query this adapter instead of retaining its address. * QTableView model whose vertical headerData contains debugger addresses.
* Like Qt's item-view adapter, virtual children retain the widget and model
* identity and re-query this adapter instead of retaining its address.
*/ */
class AccessibleAbstractTableView : public QAccessibleWidget, public QAccessibleTableInterface class AccessibleAbstractTableView : public QAccessibleWidget, public QAccessibleTableInterface
{ {
std::vector<QAccessible::Id> cellInterfaces; std::vector<QAccessible::Id> cellInterfaces;
std::vector<QAccessible::Id> columnTitleInterfaces; std::vector<QAccessible::Id> columnTitleInterfaces;
std::vector<QAccessible::Id> rowTitleInterfaces;
QAccessible::Id cornerInterface = 0;
int rows = 0; int rows = 0;
int cols = 0; int cols = 0;
duint tableOffset = 0; duint tableOffset = 0;
@ -39,7 +43,7 @@ public:
QAccessible::State state() const override; QAccessible::State state() const override;
void* interface_cast(QAccessible::InterfaceType type) override; void* interface_cast(QAccessible::InterfaceType type) override;
// QAccessibleTableInterface. Rows and columns are zero-based data coordinates; // QAccessibleTableInterface. Rows and columns are zero-based data coordinates;
// column headers are separate children and are not part of rowCount(). // structural headers are separate children and are not part of rowCount().
QAccessibleInterface* caption() const override; QAccessibleInterface* caption() const override;
QAccessibleInterface* cellAt(int row, int column) const override; QAccessibleInterface* cellAt(int row, int column) const override;
int columnCount() const override; int columnCount() const override;
@ -64,6 +68,8 @@ protected:
virtual QString getCellContent(int row, int col) const; // Get plain text of a cell virtual QString getCellContent(int row, int col) const; // Get plain text of a cell
AbstractTableView* m_tableView; AbstractTableView* m_tableView;
private: private:
std::vector<QAccessible::Id> takeChildInterfaces();
static void deleteChildInterfaces(const std::vector<QAccessible::Id>& ids);
void clearChildInterfaces(); void clearChildInterfaces();
std::vector<duint> visibleColumns() const; std::vector<duint> visibleColumns() const;
int visibleRowCount() const; int visibleRowCount() const;
@ -71,9 +77,13 @@ private:
void ensureModelUpToDate() const; void ensureModelUpToDate() const;
QAccessibleInterface* cellInterface(int row, int column) const; QAccessibleInterface* cellInterface(int row, int column) const;
QAccessibleInterface* columnHeaderInterface(int column) const; QAccessibleInterface* columnHeaderInterface(int column) const;
QAccessibleInterface* rowHeaderInterface(int row) const;
QAccessibleInterface* cornerHeaderInterface() const;
QRect elementRect(int row, int column, bool header) const; QRect elementRect(int row, int column, bool header) const;
bool cellIsValid(int row, int column) const; bool cellIsValid(int row, int column) const;
bool headerIsValid(int column) const; bool headerIsValid(int column) const;
bool rowHeaderIsValid(int row) const;
bool cornerIsValid() const;
}; };
#endif #endif

View File

@ -177,7 +177,11 @@ QList<QAccessibleInterface*> AccessibleAbstractTableViewCell::columnHeaderCells(
QList<QAccessibleInterface*> AccessibleAbstractTableViewCell::rowHeaderCells() const QList<QAccessibleInterface*> AccessibleAbstractTableViewCell::rowHeaderCells() const
{ {
// AbstractTableView does not paint or expose row headers. AccessibleAbstractTableView* accessible = accessibleTable();
if(!belongsTo(accessible) || !accessible->cellIsValid(row, column))
return QList<QAccessibleInterface*>();
if(auto header = accessible->rowHeaderInterface(row))
return QList<QAccessibleInterface*>({header});
return QList<QAccessibleInterface*>(); return QList<QAccessibleInterface*>();
} }

View File

@ -1,27 +1,52 @@
// This file implements accessibility interface for the column headers of AbstractTableView // This file implements the structural headers of AbstractTableView.
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
#include "AccessibleAbstractTableViewCellTitle.h" #include "AccessibleAbstractTableViewCellTitle.h"
#include "AccessibleAbstractTableView.h" #include "AccessibleAbstractTableView.h"
#include <exception>
AccessibleAbstractTableViewCellTitle::AccessibleAbstractTableViewCellTitle(AbstractTableView* tableView, int column, quint64 modelRevision) AccessibleAbstractTableViewCellTitle::AccessibleAbstractTableViewCellTitle(
: AccessibleAbstractTableViewCell(tableView, -1, column, modelRevision) AbstractTableView* tableView, HeaderType type, int index, quint64 modelRevision)
: AccessibleAbstractTableViewCell(
tableView,
type == HeaderType::Row ? index : -1,
type == HeaderType::Column ? index : -1,
modelRevision)
, mType(type)
{ {
} }
QString AccessibleAbstractTableViewCellTitle::text(QAccessible::Text t) const QString AccessibleAbstractTableViewCellTitle::text(QAccessible::Text t) const
{ {
AccessibleAbstractTableView* accessible = accessibleTable(); if(t != QAccessible::Name)
if(!belongsTo(accessible) || !accessible->headerIsValid(column))
return QString(); return QString();
if(t == QAccessible::Name)
AccessibleAbstractTableView* accessible = accessibleTable();
if(!isValidFor(accessible))
return QString();
if(mType == HeaderType::Column)
return mTableView->getColTitle(accessible->logicalColumn(column)); return mTableView->getColTitle(accessible->logicalColumn(column));
if(mType == HeaderType::Row && mTableView->getColumnCount() > 0)
{
try
{
// Match a QTableView with custom vertical headerData: the dedicated
// row-header object carries the debugger row's stable identifier,
// while the first data cell remains an ordinary table cell.
return accessible->getCellContent(row, 0);
}
catch(const std::exception &)
{
return QString();
}
}
return QString(); return QString();
} }
QColor AccessibleAbstractTableViewCellTitle::foregroundColor() const QColor AccessibleAbstractTableViewCellTitle::foregroundColor() const
{ {
AccessibleAbstractTableView* accessible = accessibleTable(); AccessibleAbstractTableView* accessible = accessibleTable();
return belongsTo(accessible) && accessible->headerIsValid(column) && mTableView return isValidFor(accessible) && mTableView
? mTableView->mHeaderTextColor ? mTableView->mHeaderTextColor
: QColor(); : QColor();
} }
@ -29,7 +54,7 @@ QColor AccessibleAbstractTableViewCellTitle::foregroundColor() const
QColor AccessibleAbstractTableViewCellTitle::backgroundColor() const QColor AccessibleAbstractTableViewCellTitle::backgroundColor() const
{ {
AccessibleAbstractTableView* accessible = accessibleTable(); AccessibleAbstractTableView* accessible = accessibleTable();
return belongsTo(accessible) && accessible->headerIsValid(column) && mTableView return isValidFor(accessible) && mTableView
? mTableView->mHeaderBackgroundColor ? mTableView->mHeaderBackgroundColor
: QColor(); : QColor();
} }
@ -39,7 +64,7 @@ QAccessible::State AccessibleAbstractTableViewCellTitle::state() const
QAccessible::State result; QAccessible::State result;
AccessibleAbstractTableView* accessible = accessibleTable(); AccessibleAbstractTableView* accessible = accessibleTable();
const AbstractTableView* table = mTableView.data(); const AbstractTableView* table = mTableView.data();
if(!belongsTo(accessible) || !accessible->headerIsValid(column) || !table) if(!isValidFor(accessible) || !table)
{ {
result.invalid = true; result.invalid = true;
return result; return result;
@ -48,48 +73,89 @@ QAccessible::State AccessibleAbstractTableViewCellTitle::state() const
const bool visible = !rect().isEmpty(); const bool visible = !rect().isEmpty();
result.disabled = !table->isEnabled(); result.disabled = !table->isEnabled();
result.readOnly = true; result.readOnly = true;
result.invisible = table->getHeaderHeight() == 0 || !table->isVisible() || !visible; // AbstractTableView paints its horizontal header, but has no visible
// vertical-header gutter or corner. Keep those canonical structural
// objects available to table APIs while native trees mark them hidden.
result.invisible = mType != HeaderType::Column
|| table->getHeaderHeight() == 0
|| !table->isVisible()
|| !visible;
result.offscreen = !visible; result.offscreen = !visible;
return result; return result;
} }
QRect AccessibleAbstractTableViewCellTitle::rect() const QRect AccessibleAbstractTableViewCellTitle::rect() const
{ {
if(mType != HeaderType::Column)
return QRect();
AccessibleAbstractTableView* accessible = accessibleTable(); AccessibleAbstractTableView* accessible = accessibleTable();
return belongsTo(accessible) ? accessible->elementRect(-1, column, true) : QRect(); return isValidFor(accessible) ? accessible->elementRect(-1, column, true) : QRect();
} }
QAccessible::Role AccessibleAbstractTableViewCellTitle::role() const QAccessible::Role AccessibleAbstractTableViewCellTitle::role() const
{ {
return QAccessible::ColumnHeader; switch(mType)
{
case HeaderType::Column:
return QAccessible::ColumnHeader;
case HeaderType::Row:
return QAccessible::RowHeader;
case HeaderType::Corner:
return QAccessible::Pane;
}
return QAccessible::NoRole;
}
int AccessibleAbstractTableViewCellTitle::columnIndex() const
{
return mType == HeaderType::Column ? column : -1;
} }
int AccessibleAbstractTableViewCellTitle::rowIndex() const int AccessibleAbstractTableViewCellTitle::rowIndex() const
{ {
return -1; return mType == HeaderType::Row ? row : -1;
}
bool AccessibleAbstractTableViewCellTitle::isValidFor(AccessibleAbstractTableView* accessible) const
{
if(!belongsTo(accessible))
return false;
switch(mType)
{
case HeaderType::Column:
return accessible->headerIsValid(column);
case HeaderType::Row:
return accessible->rowHeaderIsValid(row);
case HeaderType::Corner:
return accessible->cornerIsValid();
}
return false;
} }
bool AccessibleAbstractTableViewCellTitle::isValid() const bool AccessibleAbstractTableViewCellTitle::isValid() const
{ {
AccessibleAbstractTableView* accessible = accessibleTable(); return isValidFor(accessibleTable());
return belongsTo(accessible) && accessible->headerIsValid(column);
} }
void* AccessibleAbstractTableViewCellTitle::interface_cast(QAccessible::InterfaceType type) void* AccessibleAbstractTableViewCellTitle::interface_cast(QAccessible::InterfaceType type)
{ {
Q_UNUSED(type); Q_UNUSED(type);
// Headers are separate structural children, not cells in the data grid. // Headers are structural children, not cells in the data grid.
return nullptr; return nullptr;
} }
QList<QAccessibleInterface*> AccessibleAbstractTableViewCellTitle::rowHeaderCells() const QList<QAccessibleInterface*> AccessibleAbstractTableViewCellTitle::rowHeaderCells() const
{ {
return QList<QAccessibleInterface*>(); return mType == HeaderType::Row
? QList<QAccessibleInterface*>({const_cast<AccessibleAbstractTableViewCellTitle*>(this)})
: QList<QAccessibleInterface*>();
} }
QList<QAccessibleInterface*> AccessibleAbstractTableViewCellTitle::columnHeaderCells() const QList<QAccessibleInterface*> AccessibleAbstractTableViewCellTitle::columnHeaderCells() const
{ {
return QList<QAccessibleInterface*>({const_cast<AccessibleAbstractTableViewCellTitle*>(this)}); return mType == HeaderType::Column
? QList<QAccessibleInterface*>({const_cast<AccessibleAbstractTableViewCellTitle*>(this)})
: QList<QAccessibleInterface*>();
} }
#endif #endif

View File

@ -6,7 +6,14 @@
class AccessibleAbstractTableViewCellTitle : public AccessibleAbstractTableViewCell class AccessibleAbstractTableViewCellTitle : public AccessibleAbstractTableViewCell
{ {
public: public:
AccessibleAbstractTableViewCellTitle(AbstractTableView* tableView, int column, quint64 modelRevision); enum class HeaderType
{
Column,
Row,
Corner
};
AccessibleAbstractTableViewCellTitle(AbstractTableView* tableView, HeaderType type, int index, quint64 modelRevision);
// QAccessibleInterface // QAccessibleInterface
QString text(QAccessible::Text t) const override; QString text(QAccessible::Text t) const override;
QColor foregroundColor() const override; QColor foregroundColor() const override;
@ -16,9 +23,14 @@ public:
QList<QAccessibleInterface*> columnHeaderCells() const override; QList<QAccessibleInterface*> columnHeaderCells() const override;
QRect rect() const override; QRect rect() const override;
QAccessible::Role role() const override; QAccessible::Role role() const override;
int columnIndex() const override;
int rowIndex() const override; int rowIndex() const override;
bool isValid() const override; bool isValid() const override;
void* interface_cast(QAccessible::InterfaceType type) override; void* interface_cast(QAccessible::InterfaceType type) override;
private:
bool isValidFor(AccessibleAbstractTableView* accessible) const;
HeaderType mType;
}; };
#endif #endif

View File

@ -40,6 +40,7 @@ QString AccessibleRegistersViewItem::text(QAccessible::Text t) const
switch(t) switch(t)
{ {
case QAccessible::Name: case QAccessible::Name:
case QAccessible::Value:
{ {
const auto it = view->mRegisterMapping.constFind(id); const auto it = view->mRegisterMapping.constFind(id);
if(it == view->mRegisterMapping.cend()) if(it == view->mRegisterMapping.cend())
@ -204,6 +205,9 @@ AccessibleRegistersView::~AccessibleRegistersView()
std::vector<RegistersView::REGISTER_NAME> AccessibleRegistersView::registerOrder() const std::vector<RegistersView::REGISTER_NAME> AccessibleRegistersView::registerOrder() const
{ {
// REGISTER_NAME groups storage identities, not presentation order. The
// visible layout also changes with x87/MMX and AVX-512 display modes, so
// derive child order from the same geometry used for painting and hit tests.
std::vector<RegistersView::REGISTER_NAME> result; std::vector<RegistersView::REGISTER_NAME> result;
if(!m_registersView) if(!m_registersView)
return result; return result;

View File

@ -1479,7 +1479,9 @@ void AbstractTableView::accessibilitySelectionChanged()
return false; return false;
QAccessibleEvent event(this, type); QAccessibleEvent event(this, type);
event.setChild(columns + row * columns + column); // Match QAccessibleTable's structural grid: hidden corner and column
// headers in row zero, then a hidden row header before each data row.
event.setChild((row + 1) * (columns + 1) + column + 1);
QAccessible::updateAccessibility(&event); QAccessible::updateAccessibility(&event);
return true; return true;
}; };

View File

@ -1,4 +1,5 @@
#include "DebugStatusLabel.h" #include "DebugStatusLabel.h"
#include <QAccessible>
#include <QStyle> #include <QStyle>
#include <QMetaEnum> #include <QMetaEnum>
@ -45,5 +46,12 @@ void DebugStatusLabel::debugStateChangedSlot(DBGSTATE state)
this->style()->polish(this); this->style()->polish(this);
this->update(); this->update();
// QLabel::setText() emits QAccessible::NameChanged when needed. // Passive status labels are not focused, so screen readers such as
// Narrator do not announce QLabel's automatic NameChanged notification.
// Preserve the explicit ValueChanged event used for live status updates.
if(QAccessible::isActive())
{
QAccessibleValueChangeEvent updateEvent(this, mStatusTexts[state]);
QAccessible::updateAccessibility(&updateEvent);
}
} }

View File

@ -1,6 +1,8 @@
#include "LogStatusLabel.h" #include "LogStatusLabel.h"
#include "LogView.h" #include "LogView.h"
#include <QAccessible>
#include <QApplication> #include <QApplication>
#include <QTextDocumentFragment>
#include <QStatusBar> #include <QStatusBar>
LogStatusLabel::LogStatusLabel(QStatusBar* parent) : QLabel(parent) LogStatusLabel::LogStatusLabel(QStatusBar* parent) : QLabel(parent)
@ -42,7 +44,15 @@ void LogStatusLabel::logUpdate(QString message, bool encodeHTML)
} }
} }
setText(finalLabel); setText(finalLabel);
// QLabel::setText() emits QAccessible::NameChanged when needed. // A status-bar label is passive and its automatic NameChanged event is not
// announced by Narrator. Send the explicit live ValueChanged notification
// and strip any rich-text markup from its payload.
if(QAccessible::isActive())
{
QAccessibleValueChangeEvent updateEvent(
this, QTextDocumentFragment::fromHtml(finalLabel).toPlainText());
QAccessible::updateAccessibility(&updateEvent);
}
} }
void LogStatusLabel::logUpdateUtf8(QByteArray message) void LogStatusLabel::logUpdateUtf8(QByteArray message)

View File

@ -3548,10 +3548,13 @@ void RegistersView::accessibilityValueChanged()
{ {
if(auto item = accessible->interfaceForRegister(reg)) if(auto item = accessible->interfaceForRegister(reg))
{ {
// Register items expose their displayed "RAX = value" string as // Narrator listens for ValueChanged on register list items. The
// Name and do not implement a numeric QAccessibleValueInterface. // displayed value is textual (and may include a symbol), so expose
QAccessibleEvent nameChangeEvent(item, QAccessible::NameChanged); // the same string through QAccessible::Value without claiming a
QAccessible::updateAccessibility(&nameChangeEvent); // numeric QAccessibleValueInterface.
QAccessibleValueChangeEvent valueChangeEvent(
item, QVariant(item->text(QAccessible::Value)));
QAccessible::updateAccessibility(&valueChangeEvent);
} }
} }
} }

View File

@ -41,8 +41,10 @@ The checker validates:
GridItem row/column and containing Grid round-trip correctly. GridItem row/column and containing Grid round-trip correctly.
- A populated table exposes one column-header relation per column, and every - A populated table exposes one column-header relation per column, and every
first-row cell points to the corresponding header. first-row cell points to the corresponding header.
- Visible cells/headers participate in direct child navigation and point back to - Every row has a distinct, hidden row-header object and all cells in that row
the table. reference it. The first data cell is never repurposed as the header.
- Visible cells/column headers participate in direct child navigation and point
back to the table; hidden row headers remain available through TablePattern.
- Hit-testing the center of visible headers and first-row cells returns that - Hit-testing the center of visible headers and first-row cells returns that
exact UIA element. exact UIA element.
- UIA Name properties can be queried for all cells and headers. - UIA Name properties can be queried for all cells and headers.
@ -50,6 +52,21 @@ The checker validates:
The script exits non-zero on a contract failure. `--max-cells` limits work for The script exits non-zero on a contract failure. `--max-cells` limits work for
unexpectedly large grids. unexpectedly large grids.
## Live event checks
With a live debug target paused, the event checker logs a unique marker and
single-steps once through the debugger Command Bar:
```powershell
uv run x64dbg-screenreader-event-checks
```
It listens through native UIA and requires `ValueChanged` payloads for the log
message, `Running` and `Paused` debug states, and the updated `EIP`/`RIP` list
item. These are the passive live-region events consumed by Microsoft Narrator;
a QLabel `NameChanged` event alone is not announced. The command intentionally
advances the debug target by one instruction.
## Capture visible contents ## Capture visible contents
The dump command writes the currently visible tables, register lists, text The dump command writes the currently visible tables, register lists, text
@ -80,7 +97,7 @@ output file includes the corresponding `ERROR:` section.
`--window-index`. `--window-index`.
- Empty tables can validate Grid structure but cannot expose header relations - Empty tables can validate Grid structure but cannot expose header relations
through Qt's UIA Table provider until at least one data row exists. through Qt's UIA Table provider until at least one data row exists.
- These scripts do not yet capture UIA events or automate scrolling/model-reset - Table scrolling/model-reset transitions still require a deliberate manual
transitions. Those still require a deliberate manual scenario. scenario. The event checker automates only one instruction step.
- macOS VoiceOver/Accessibility Inspector and Linux AT-SPI require separate - macOS VoiceOver/Accessibility Inspector and Linux AT-SPI require separate
platform-specific testing. platform-specific testing.

View File

@ -4,14 +4,16 @@ version = "0.1.0"
description = "UIA-based accessibility checks for x64dbg table views." description = "UIA-based accessibility checks for x64dbg table views."
requires-python = ">=3.11" requires-python = ">=3.11"
dependencies = [ dependencies = [
"comtypes>=1.4.10; sys_platform == 'win32'",
"pywinauto>=0.6.9", "pywinauto>=0.6.9",
] ]
[tool.setuptools] [tool.setuptools]
py-modules = ["screenreader_check", "ui_dump", "ui_common"] py-modules = ["screenreader_check", "uia_event_check", "ui_dump", "ui_common"]
[project.scripts] [project.scripts]
x64dbg-screenreader-checks = "screenreader_check:main" x64dbg-screenreader-checks = "screenreader_check:main"
x64dbg-screenreader-event-checks = "uia_event_check:main"
x64dbg-ui-dump = "ui_dump:main" x64dbg-ui-dump = "ui_dump:main"
[tool.uv] [tool.uv]

View File

@ -198,13 +198,65 @@ def _check_headers(
except Exception as exc: except Exception as exc:
failures.append(f"Cell (0,{col}) header relation failed: {exc}") failures.append(f"Cell (0,{col}) header relation failed: {exc}")
row_headers: list[UIAWrapper] = []
if rows > 0 and cols > 0:
try:
row_header_array = table.iface_table.GetCurrentRowHeaders()
row_headers = [
wrap_uia_element(row_header_array.GetElement(index))
for index in range(int(row_header_array.Length))
]
except Exception as exc:
failures.append(f"Table row-header query failed: {exc}")
if len(row_headers) != rows:
failures.append(
f"TablePattern returned {len(row_headers)} row headers for {rows} rows"
)
row_header_ids: set[tuple[int, ...]] = set()
for row, row_header in enumerate(row_headers):
row_header_id = _runtime_id(row_header)
if not row_header_id:
failures.append(f"Row header {row} has no runtime ID")
elif row_header_id in row_header_ids:
failures.append(f"Row header {row} reuses runtime ID {row_header_id}")
else:
row_header_ids.add(row_header_id)
if row_header.element_info.control_type not in {"Header", "HeaderItem"}:
failures.append(
f"Row header {row} has type "
f"{row_header.element_info.control_type!r}"
)
if row < len(grid_items) and grid_items[row]:
if _same_element(row_header, grid_items[row][0]):
failures.append(f"Row header {row} reuses its first data cell")
for col, item in enumerate(grid_items[row]):
try:
header_array = item.iface_table_item.GetCurrentRowHeaderItems()
cell_headers = [
wrap_uia_element(header_array.GetElement(index))
for index in range(int(header_array.Length))
]
if len(cell_headers) != 1 or not _same_element(
cell_headers[0], row_header
):
failures.append(
f"Cell ({row},{col}) does not reference row header {row}"
)
except Exception as exc:
failures.append(
f"Cell ({row},{col}) row-header relation failed: {exc}"
)
if failures: if failures:
return headers, CheckResult(False, "; ".join(failures[:8])) return headers, CheckResult(False, "; ".join(failures[:8]))
if rows == 0: if rows == 0:
return headers, CheckResult( return headers, CheckResult(
True, "Header relation check skipped because the Grid has no data rows." True, "Header relation check skipped because the Grid has no data rows."
) )
return headers, CheckResult(True, f"Header relations OK ({len(headers)} headers).") return headers, CheckResult(
True,
f"Header relations OK ({len(headers)} column, {len(row_headers)} row).",
)
def _check_child_navigation( def _check_child_navigation(

View File

@ -88,6 +88,15 @@ def list_matching_windows(title_hint: Optional[str]) -> list[WindowMatch]:
continue continue
windows.append(window) windows.append(window)
# UIA desktop enumeration order is not stable between calls. Both the CLI
# validation and select_window() enumerate, so sort before assigning indexes
# or --window-index can select a different process than --list-windows showed.
windows.sort(
key=lambda window: (
int(window.element_info.process_id),
window.window_text() or "",
)
)
return [ return [
WindowMatch(index=index, title=window.window_text(), window=window) WindowMatch(index=index, title=window.window_text(), window=window)
for index, window in enumerate(windows) for index, window in enumerate(windows)

View File

@ -0,0 +1,195 @@
from __future__ import annotations
import argparse
import ctypes
import re
import sys
from dataclasses import dataclass
from typing import Any, Optional
# Let pywinauto establish the process COM apartment before importing comtypes;
# reversing this order makes pywinauto warn and switch apartment assumptions.
from pywinauto.controls.uiawrapper import UIAWrapper
from pywinauto.uia_defines import IUIA
from ui_common import list_matching_windows, select_window
import comtypes
import comtypes.client
import comtypes.gen.UIAutomationClient as UIA
LOG_MARKER = "X64DBG_ACCESSIBILITY_EVENT_PROBE"
INSTRUCTION_POINTER = re.compile(r"^(?:EIP|RIP) = ", re.IGNORECASE)
@dataclass(frozen=True)
class PropertyEvent:
property_id: int
name: str
value: str
control_type: int
def _variant_text(value: Any) -> str:
try:
unwrapped = value.value
except Exception:
unwrapped = value
return "" if unwrapped is None else str(unwrapped)
class PropertyChangedHandler(comtypes.COMObject):
_com_interfaces_ = [UIA.IUIAutomationPropertyChangedEventHandler]
def __init__(self) -> None:
super().__init__()
self.events: list[PropertyEvent] = []
def HandlePropertyChangedEvent(
self, sender: Any, property_id: int, new_value: Any
) -> int:
try:
name = str(sender.CurrentName or "")
except Exception:
name = ""
try:
control_type = int(sender.CurrentControlType)
except Exception:
control_type = 0
self.events.append(
PropertyEvent(
property_id=int(property_id),
name=name,
value=_variant_text(new_value),
control_type=control_type,
)
)
return 0
def _command_line(window: UIAWrapper) -> Optional[UIAWrapper]:
for edit in window.descendants(control_type="Edit"):
try:
parent = edit.parent()
if parent and parent.element_info.name == "CommandBar":
return edit
except Exception:
continue
return None
def _execute(command_line: UIAWrapper, command: str) -> None:
command_line.set_focus()
command_line.set_edit_text(command)
command_line.type_keys("{ENTER}")
def _has_value(events: list[PropertyEvent], predicate) -> bool:
return any(
event.property_id == UIA.UIA_ValueValuePropertyId and predicate(event.value)
for event in events
)
def main() -> int:
parser = argparse.ArgumentParser(
description=(
"Verify the live UIA events consumed by screen readers. The selected "
"debugger must be paused with a live debug target."
)
)
parser.add_argument(
"--window-title",
default=None,
help="Substring to match an x64dbg/x32dbg window title (optional).",
)
parser.add_argument(
"--window-index",
type=int,
default=None,
help="Select a specific matching debugger window by index (0-based).",
)
parser.add_argument(
"--timeout",
type=float,
default=6.0,
help="Seconds to collect events after issuing a single-step command.",
)
args = parser.parse_args()
matches = list_matching_windows(args.window_title)
if not matches:
print("ERROR: Could not find a running x64dbg/x32dbg window.", file=sys.stderr)
return 2
if args.window_index is not None and not (0 <= args.window_index < len(matches)):
print("ERROR: --window-index is out of range.", file=sys.stderr)
return 2
window = select_window(args.window_title, args.window_index)
if window is None:
print("ERROR: Could not select a debugger window.", file=sys.stderr)
return 2
print(f"Window: {window.window_text()}")
command_line = _command_line(window)
if command_line is None:
print("ERROR: Could not find the debugger CommandBar edit.", file=sys.stderr)
return 3
automation = IUIA().iuia
handler = PropertyChangedHandler()
properties = (ctypes.c_long * 1)(UIA.UIA_ValueValuePropertyId)
root = window.element_info.element
automation.AddPropertyChangedEventHandlerNativeArray(
root,
UIA.TreeScope_Subtree,
None,
handler,
properties,
len(properties),
)
try:
_execute(command_line, f'log "{LOG_MARKER}"')
comtypes.client.PumpEvents(1.0)
_execute(command_line, "sti")
comtypes.client.PumpEvents(max(args.timeout, 0.1))
finally:
automation.RemovePropertyChangedEventHandler(root, handler)
checks = [
(
"log message",
_has_value(handler.events, lambda value: LOG_MARKER in value),
),
(
"running debug state",
_has_value(handler.events, lambda value: value == "Running"),
),
(
"paused debug state",
_has_value(handler.events, lambda value: value == "Paused"),
),
(
"instruction pointer",
_has_value(
handler.events, lambda value: bool(INSTRUCTION_POINTER.match(value))
),
),
]
failed = False
for name, passed in checks:
print(f"[{'OK' if passed else 'FAIL'}] {name} ValueChanged event")
failed = failed or not passed
print(f"Captured {len(handler.events)} UIA property-change events.")
if failed:
print("Observed ValueChanged payloads:")
for event in handler.events:
if event.property_id == UIA.UIA_ValueValuePropertyId:
print(f" {event.control_type} {event.name!r}: {event.value!r}")
return 1 if failed else 0
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -1,5 +1,5 @@
version = 1 version = 1
revision = 2 revision = 3
requires-python = ">=3.11" requires-python = ">=3.11"
[[package]] [[package]]
@ -71,8 +71,12 @@ name = "x64dbg-screenreader-checks"
version = "0.1.0" version = "0.1.0"
source = { editable = "." } source = { editable = "." }
dependencies = [ dependencies = [
{ name = "comtypes", marker = "sys_platform == 'win32'" },
{ name = "pywinauto" }, { name = "pywinauto" },
] ]
[package.metadata] [package.metadata]
requires-dist = [{ name = "pywinauto", specifier = ">=0.6.9" }] requires-dist = [
{ name = "comtypes", marker = "sys_platform == 'win32'", specifier = ">=1.4.10" },
{ name = "pywinauto", specifier = ">=0.6.9" },
]