summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-08-29 11:47:05 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-01 18:03:29 +0200
commitc59b34b8cf1c2a087e361d4235990803d89d34ec (patch)
tree9bd0e09474bc0d0179a7ad0b3363c6997eea1608 /src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm
parentb770b0f8b98a280034b70bfd7e51e29f94ca93b6 (diff)
QAccessible: consistently respect rootIndex of item views
Accessibility implementations rely on correct information about the model dimensions when operating on item views. An item view that has a root index set needs to report it's size based on the root index, rather than for the view's model directly. Pass the rootIndex to all calls to QAbstractItemModel::column/rowCount. Refactor the code to avoid excessive dereferencing of a QPointer, apply const and fix/improve coding style in touched lines. Emit a ModelReset notification when the root index changes, or (in the case of QListView) when the model column changes. Split long Q_ASSERTs into multiple lines to be able to better trace the exact reason for an assertion, and replace the assert with an early return of nil when it's plausible that a cached cell is no longer part of the view (i.e. because the root index changed). Add a test case that verifies that changing the root index changes the dimension of the view as reported through the accessibility interface. Pick-to: 6.6 6.5 Fixes: QTBUG-114423 Change-Id: I7897b79b2e1d10c789cc866b7f5c5dabdabe6770 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm
index 7a1bab7351..85c395e2bf 100644
--- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm
+++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm
@@ -130,7 +130,8 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
if (tableInterface) {
auto *tableElement = [QMacAccessibilityElement elementWithInterface:table];
Q_ASSERT(tableElement);
- Q_ASSERT(tableElement->rows && int(tableElement->rows.count) > m_rowIndex);
+ Q_ASSERT(tableElement->rows);
+ Q_ASSERT(int(tableElement->rows.count) > m_rowIndex);
auto *rowElement = tableElement->rows[m_rowIndex];
if (!rowElement->columns) {
rowElement->columns = [rowElement populateTableRow:rowElement->columns
@@ -490,7 +491,8 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
// a synthetic cell without interface - shortcut to the row
QMacAccessibilityElement *tableElement =
[QMacAccessibilityElement elementWithId:axid];
- Q_ASSERT(tableElement && tableElement->rows && int(tableElement->rows.count) > m_rowIndex);
+ Q_ASSERT(tableElement && tableElement->rows);
+ Q_ASSERT(int(tableElement->rows.count) > m_rowIndex);
QMacAccessibilityElement *rowElement = tableElement->rows[m_rowIndex];
return rowElement;
}
@@ -520,7 +522,9 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of
rowIndex = m_rowIndex;
else if (QAccessibleTableCellInterface *cell = iface->tableCellInterface())
rowIndex = cell->rowIndex();
- Q_ASSERT(tableElement->rows && int([tableElement->rows count]) > rowIndex);
+ Q_ASSERT(tableElement->rows);
+ if (rowIndex > int([tableElement->rows count]))
+ return nil;
QMacAccessibilityElement *rowElement = tableElement->rows[rowIndex];
return NSAccessibilityUnignoredAncestor(rowElement);
}