From 7dca461620ee6d8cce3a74acf2e1530d4497bff9 Mon Sep 17 00:00:00 2001 From: Jan-Arve Saether Date: Thu, 5 Jan 2012 09:51:20 +0100 Subject: [PATCH] Remove all references to QAccessible:: {Child|Ancestor|Sibling} These are deprecated in favor of QAccessibleInterface::child() and QAccessibleInterface::parent() QAccessible::Sibling can be done with a combination of those two. This is handled by the bridges, if required. Change-Id: I2e2a6eb2a982e7c9001a393d69f0c5f1ae9c0970 Reviewed-by: Frederik Gladhorn --- src/gui/accessible/qaccessible.h | 5 - src/gui/accessible/qaccessibleobject.cpp | 3 - src/plugins/accessible/widgets/complexwidgets.cpp | 32 +--- src/plugins/accessible/widgets/complexwidgets.h | 1 - src/plugins/accessible/widgets/itemviews.cpp | 128 ++++--------- src/plugins/accessible/widgets/itemviews.h | 11 +- src/plugins/accessible/widgets/qaccessiblemenu.cpp | 47 ----- src/plugins/accessible/widgets/qaccessiblemenu.h | 3 - .../accessible/widgets/qaccessiblewidgets.cpp | 66 +++---- .../accessible/widgets/qaccessiblewidgets.h | 4 +- src/plugins/accessible/widgets/simplewidgets.cpp | 5 +- .../platforms/windows/qwindowsaccessibility.cpp | 116 +++++++++--- src/widgets/accessible/qaccessiblewidget.cpp | 134 -------------- .../other/qaccessibility/tst_qaccessibility.cpp | 198 ++++----------------- 14 files changed, 208 insertions(+), 545 deletions(-) diff --git a/src/gui/accessible/qaccessible.h b/src/gui/accessible/qaccessible.h index 37071bc..949c67c 100644 --- a/src/gui/accessible/qaccessible.h +++ b/src/gui/accessible/qaccessible.h @@ -274,11 +274,6 @@ public: enum RelationFlag { Unrelated = 0x00000000, Self = 0x00000001, - Ancestor = 0x00000002, - Child = 0x00000004, - Descendent = 0x00000008, - Sibling = 0x00000010, - HierarchyMask = 0x000000ff, Up = 0x00000100, Down = 0x00000200, diff --git a/src/gui/accessible/qaccessibleobject.cpp b/src/gui/accessible/qaccessibleobject.cpp index af86ad4..5ba3cd1 100644 --- a/src/gui/accessible/qaccessibleobject.cpp +++ b/src/gui/accessible/qaccessibleobject.cpp @@ -272,9 +272,6 @@ int QAccessibleApplication::navigate(QAccessible::RelationFlag relation, int, return 0; } break; - case QAccessible::Ancestor: - *target = parent(); - return 0; default: break; } diff --git a/src/plugins/accessible/widgets/complexwidgets.cpp b/src/plugins/accessible/widgets/complexwidgets.cpp index b1ff871..f09c942 100644 --- a/src/plugins/accessible/widgets/complexwidgets.cpp +++ b/src/plugins/accessible/widgets/complexwidgets.cpp @@ -124,17 +124,11 @@ public: QAccessibleInterface *child(int) const { return 0; } int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const { - if (relation == QAccessible::Ancestor && index == 1) { - *iface = parent(); - return 0; - } + Q_UNUSED(relation); + Q_UNUSED(index); + Q_UNUSED(iface); return -1; } - QAccessible::Relation relationTo(const QAccessibleInterface *) const - { - return QAccessible::Unrelated; - } - // action interface QStringList actionNames() const { @@ -172,18 +166,6 @@ QTabBar *QAccessibleTabBar::tabBar() const return qobject_cast(object()); } -int QAccessibleTabBar::navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const -{ - if (rel == QAccessible::Child) { - *target = child(entry - 1); - if (*target) { - return 0; - } - return -1; - } - return QAccessibleWidget::navigate(rel, entry, target); -} - QAccessibleInterface* QAccessibleTabBar::child(int index) const { // first the tabs, then 2 buttons @@ -443,8 +425,7 @@ int QAccessibleAbstractScrollArea::navigate(QAccessible::RelationFlag relation, QWidget *targetWidget = 0; QWidget *entryWidget = 0; - if (relation == QAccessible::Child || - relation == QAccessible::Left || relation == QAccessible::Up || relation == QAccessible::Right || relation == QAccessible::Down) { + if (relation == QAccessible::Left || relation == QAccessible::Up || relation == QAccessible::Right || relation == QAccessible::Down) { QWidgetList children = accessibleChildren(); if (entry < 0 || entry > children.count()) return -1; @@ -460,11 +441,6 @@ int QAccessibleAbstractScrollArea::navigate(QAccessible::RelationFlag relation, // It might be possible to make it more general, but I'll leave that as an exercise // to the reader. :-) switch (relation) { - case QAccessible::Child: - if (entry > 0) { - *target = child(entry - 1); - return *target ? 0 : -1; - } case QAccessible::Left: if (entry < 1) break; diff --git a/src/plugins/accessible/widgets/complexwidgets.h b/src/plugins/accessible/widgets/complexwidgets.h index 66dbdcf..24c033b 100644 --- a/src/plugins/accessible/widgets/complexwidgets.h +++ b/src/plugins/accessible/widgets/complexwidgets.h @@ -112,7 +112,6 @@ public: QAccessibleInterface* child(int index) const; int indexOfChild(const QAccessibleInterface *child) const; - int navigate(QAccessible::RelationFlag rel, int entry, QAccessibleInterface **target) const; protected: QTabBar *tabBar() const; diff --git a/src/plugins/accessible/widgets/itemviews.cpp b/src/plugins/accessible/widgets/itemviews.cpp index f6d719a..a12036b 100644 --- a/src/plugins/accessible/widgets/itemviews.cpp +++ b/src/plugins/accessible/widgets/itemviews.cpp @@ -444,23 +444,9 @@ QAccessibleInterface *QAccessibleTable::child(int index) const int QAccessibleTable::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const { + Q_UNUSED(relation); + Q_UNUSED(index); *iface = 0; - switch (relation) { - case QAccessible::Ancestor: { - *iface = parent(); - return *iface ? 0 : -1; - } - case QAccessible::Child: { - Q_ASSERT(index > 0); - *iface = child(index - 1); - if (*iface) { - return 0; - } - break; - } - default: - break; - } return -1; } @@ -518,6 +504,29 @@ int QAccessibleTree::childCount() const return (treeView->d_func()->viewItems.count() + hHeader)* view->model()->columnCount(); } + +QAccessibleInterface *QAccessibleTree::child(int index) const +{ + Q_ASSERT(index >= 0); + int hHeader = horizontalHeader() ? 1 : 0; + + if (hHeader) { + if (index < view->model()->columnCount()) { + return new QAccessibleTableHeaderCell(view, index, Qt::Horizontal); + } else { + index -= view->model()->columnCount(); + } + } + + int row = index / view->model()->columnCount(); + int column = index % view->model()->columnCount(); + QModelIndex modelIndex = indexFromLogical(row, column); + if (modelIndex.isValid()) { + return cell(modelIndex); + } + return 0; +} + int QAccessibleTree::rowCount() const { const QTreeView *treeView = qobject_cast(view); @@ -550,38 +559,6 @@ int QAccessibleTree::indexOfChild(const QAccessibleInterface *iface) const return -1; } -int QAccessibleTree::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const -{ - switch (relation) { - case QAccessible::Child: { - Q_ASSERT(index > 0); - --index; - int hHeader = horizontalHeader() ? 1 : 0; - - if (hHeader) { - if (index < view->model()->columnCount()) { - *iface = new QAccessibleTableHeaderCell(view, index, Qt::Horizontal); - return 0; - } else { - index -= view->model()->columnCount(); - } - } - - int row = index / view->model()->columnCount(); - int column = index % view->model()->columnCount(); - QModelIndex modelIndex = indexFromLogical(row, column); - if (modelIndex.isValid()) { - *iface = cell(modelIndex); - return 0; - } - return -1; - } - default: - break; - } - return QAccessibleTable::navigate(relation, index, iface); -} - QAccessible::Relation QAccessibleTree::relationTo(const QAccessibleInterface *) const { return QAccessible::Unrelated; @@ -815,29 +792,10 @@ QAccessibleInterface *QAccessibleTableCell::child(int) const int QAccessibleTableCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const { - if (relation == QAccessible::Ancestor && index == 1) { - *iface = parent(); - return 0; - } - - *iface = 0; - if (!view) - return -1; - - switch (relation) { - - case QAccessible::Child: { - return -1; - } - case QAccessible::Sibling: - if (index > 0) { - QAccessibleInterface *parent = QAccessible::queryAccessibleInterface(view); - *iface = parent->child(index - 1); - delete parent; - return *iface ? 0 : -1; - } - return -1; + Q_UNUSED(index); + Q_UNUSED(relation); +// switch (relation) { // From table1 implementation: // case Up: // case Down: @@ -862,28 +820,11 @@ int QAccessibleTableCell::navigate(QAccessible::RelationFlag relation, int index // if (idx.parent() != row.parent() || idx.row() != row.row()) // *iface = cell(idx); // return index ? kids.indexOf(idx) + 1 : 0; } - default: - break; - } - +// } + *iface = 0; return -1; } -QAccessible::Relation QAccessibleTableCell::relationTo(const QAccessibleInterface *other) const -{ - // we only check for parent-child relationships in trees - if (m_role == QAccessible::TreeItem && other->role() == QAccessible::TreeItem) { - QModelIndex otherIndex = static_cast(other)->m_index; - // is the other our parent? - if (otherIndex.parent() == m_index) - return QAccessible::Ancestor; - // are we the other's child? - if (m_index.parent() == otherIndex) - return QAccessible::Child; - } - return QAccessible::Unrelated; -} - QAccessibleTableHeaderCell::QAccessibleTableHeaderCell(QAbstractItemView *view_, int index_, Qt::Orientation orientation_) : view(view_), index(index_), orientation(orientation_) { @@ -976,11 +917,10 @@ QAccessibleInterface *QAccessibleTableHeaderCell::child(int) const int QAccessibleTableHeaderCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const { - if (relation == QAccessible::Ancestor && index == 1) { - *iface = parent(); - return *iface ? 0 : -1; - } - *iface = 0; + Q_UNUSED(relation); + Q_UNUSED(index); + Q_UNUSED(iface); + return -1; } diff --git a/src/plugins/accessible/widgets/itemviews.h b/src/plugins/accessible/widgets/itemviews.h index 6fe6138..3a2f5a8 100644 --- a/src/plugins/accessible/widgets/itemviews.h +++ b/src/plugins/accessible/widgets/itemviews.h @@ -155,11 +155,12 @@ public: QAccessibleInterface *childAt(int x, int y) const; int childCount() const; + QAccessibleInterface *child(int index) const; + int indexOfChild(const QAccessibleInterface *) const; int rowCount() const; - int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const; QAccessible::Relation relationTo(const QAccessibleInterface *other) const; // table interface @@ -194,7 +195,6 @@ public: QAccessibleInterface *parent() const; QAccessibleInterface *child(int) const; int navigate(QAccessible::RelationFlag relation, int m_index, QAccessibleInterface **iface) const; - QAccessible::Relation relationTo(const QAccessibleInterface *other) const; // cell interface virtual int columnExtent() const; @@ -283,12 +283,11 @@ public: } int navigate(QAccessible::RelationFlag relation, int, QAccessibleInterface **iface) const { - if (relation == QAccessible::Ancestor) { - *iface = parent(); - return *iface ? 0 : -1; - } + Q_UNUSED(relation); + Q_UNUSED(iface); return -1; } + QAccessible::Relation relationTo(const QAccessibleInterface *) const { return QAccessible::Unrelated; diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.cpp b/src/plugins/accessible/widgets/qaccessiblemenu.cpp index 8204621..d3a7fe0 100644 --- a/src/plugins/accessible/widgets/qaccessiblemenu.cpp +++ b/src/plugins/accessible/widgets/qaccessiblemenu.cpp @@ -111,21 +111,6 @@ QAccessibleInterface *QAccessibleMenu::parent() const return QAccessibleWidget::parent(); } -int QAccessibleMenu::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const -{ - Q_ASSERT(entry >= 0); - switch (relation) { - case QAccessible::Child: - *target = child(entry - 1); - return *target ? 0 : -1; - case QAccessible::Ancestor: - *target = parent(); - return *target ? 0 : -1; - default: - return QAccessibleWidget::navigate(relation, entry, target); - } -} - int QAccessibleMenu::indexOfChild( const QAccessibleInterface *child) const { int index = -1; @@ -162,15 +147,6 @@ QAccessibleInterface *QAccessibleMenuBar::child(int index) const return 0; } -int QAccessibleMenuBar::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const -{ - if (relation == QAccessible::Child) { - *target = child(entry - 1); - return *target ? 0 : -1; - } - return QAccessibleWidget::navigate(relation, entry, target); -} - int QAccessibleMenuBar::indexOfChild(const QAccessibleInterface *child) const { int index = -1; @@ -244,12 +220,6 @@ int QAccessibleMenuItem::navigate(QAccessible::RelationFlag relation, int entry, } switch (relation) { - case QAccessible::Child: - *target = child(entry - 1); - break; - case QAccessible::Ancestor: - *target = parent(); - break; case QAccessible::Up: case QAccessible::Down:{ QAccessibleInterface *parentIface = parent(); @@ -263,13 +233,6 @@ int QAccessibleMenuItem::navigate(QAccessible::RelationFlag relation, int entry, delete parentIface; break; } - case QAccessible::Sibling: { - QAccessibleInterface *parentIface = parent(); - if (parentIface) - *target = parentIface->child(entry - 1); - delete parentIface; - break; - } default: break; @@ -308,16 +271,6 @@ QRect QAccessibleMenuItem::rect() const return rect; } -QAccessible::Relation QAccessibleMenuItem::relationTo(const QAccessibleInterface *other) const -{ - if (other->object() == owner()) { - return QAccessible::Child; - } - Q_UNUSED(other) - // ### - return QAccessible::Unrelated; -} - QAccessible::Role QAccessibleMenuItem::role() const { return m_action->isSeparator() ? QAccessible::Separator : QAccessible::MenuItem; diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.h b/src/plugins/accessible/widgets/qaccessiblemenu.h index d44c02b..873aacd 100644 --- a/src/plugins/accessible/widgets/qaccessiblemenu.h +++ b/src/plugins/accessible/widgets/qaccessiblemenu.h @@ -65,7 +65,6 @@ public: QAccessible::Role role() const; QAccessibleInterface *child(int index) const; QAccessibleInterface *parent() const; - int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; int indexOfChild( const QAccessibleInterface *child ) const; protected: @@ -81,7 +80,6 @@ public: QAccessibleInterface *child(int index) const; int childCount() const; - int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; int indexOfChild(const QAccessibleInterface *child) const; protected: @@ -108,7 +106,6 @@ public: int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface ** target) const; QObject * object() const; QRect rect() const; - QAccessible::Relation relationTo(const QAccessibleInterface *other) const; QAccessible::Role role() const; void setText(QAccessible::Text t, const QString & text); QAccessible::State state() const; diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp index 17031fe..182a85d 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp @@ -698,6 +698,7 @@ QAccessibleStackedWidget::QAccessibleStackedWidget(QWidget *widget) QVariant QAccessibleStackedWidget::invokeMethod(QAccessible::Method, const QVariantList ¶ms) { + Q_UNUSED(params); return QVariant(); } @@ -739,17 +740,6 @@ QAccessibleInterface *QAccessibleStackedWidget::child(int index) const return QAccessible::queryAccessibleInterface(stackedWidget()->widget(index)); } -int QAccessibleStackedWidget::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const -{ - switch (relation) { - case QAccessible::Child: - *target = child(entry - 1); - return *target ? 0 : -1; - default: - return QAccessibleWidget::navigate(relation, entry, target); - } -} - QStackedWidget *QAccessibleStackedWidget::stackedWidget() const { return static_cast(object()); @@ -783,6 +773,16 @@ int QAccessibleMdiArea::childCount() const return mdiArea()->subWindowList().count(); } +QAccessibleInterface *QAccessibleMdiArea::child(int index) const +{ + QList subWindows = mdiArea()->subWindowList(); + QWidget *targetObject = subWindows.value(index); + if (!targetObject) + return 0; + return QAccessible::queryAccessibleInterface(targetObject); +} + + int QAccessibleMdiArea::indexOfChild(const QAccessibleInterface *child) const { if (!child || !child->object() || mdiArea()->subWindowList().isEmpty()) @@ -799,13 +799,7 @@ int QAccessibleMdiArea::navigate(QAccessible::RelationFlag relation, int entry, { *target = 0; QWidget *targetObject = 0; - QList subWindows = mdiArea()->subWindowList(); switch (relation) { - case QAccessible::Child: - if (entry < 1 || subWindows.isEmpty() || entry > subWindows.count()) - return -1; - targetObject = subWindows.at(entry - 1); - break; case QAccessible::Up: case QAccessible::Down: case QAccessible::Left: @@ -873,6 +867,15 @@ int QAccessibleMdiSubWindow::childCount() const return 0; } +QAccessibleInterface *QAccessibleMdiSubWindow::child(int index) const +{ + QMdiSubWindow *source = mdiSubWindow(); + if (index != 0 || !source->widget()) + return 0; + + return QAccessible::queryAccessibleInterface(source->widget()); +} + int QAccessibleMdiSubWindow::indexOfChild(const QAccessibleInterface *child) const { if (child && child->object() && child->object() == mdiSubWindow()->widget()) @@ -890,11 +893,6 @@ int QAccessibleMdiSubWindow::navigate(QAccessible::RelationFlag relation, int en QWidget *targetObject = 0; QMdiSubWindow *source = mdiSubWindow(); switch (relation) { - case QAccessible::Child: - if (entry != 1 || !source->widget()) - return -1; - targetObject = source->widget(); - break; case QAccessible::Up: case QAccessible::Down: case QAccessible::Left: @@ -952,6 +950,15 @@ int QAccessibleWorkspace::childCount() const return workspace()->windowList().count(); } +QAccessibleInterface *QAccessibleWorkspace::child(int index) const +{ + QWidgetList subWindows = workspace()->windowList(); + if (index < 0 || subWindows.isEmpty() || index >= subWindows.count()) + return 0; + QObject *targetObject = subWindows.at(index); + return QAccessible::queryAccessibleInterface(targetObject); +} + int QAccessibleWorkspace::indexOfChild(const QAccessibleInterface *child) const { if (!child || !child->object() || workspace()->windowList().isEmpty()) @@ -968,13 +975,7 @@ int QAccessibleWorkspace::navigate(QAccessible::RelationFlag relation, int entry { *target = 0; QWidget *targetObject = 0; - QWidgetList subWindows = workspace()->windowList(); switch (relation) { - case QAccessible::Child: - if (entry < 1 || subWindows.isEmpty() || entry > subWindows.count()) - return -1; - targetObject = subWindows.at(entry - 1); - break; case QAccessible::Up: case QAccessible::Down: case QAccessible::Left: @@ -1066,9 +1067,6 @@ int QAccessibleCalendarWidget::navigate(QAccessible::RelationFlag relation, int return QAccessibleWidget::navigate(relation, entry, target); QWidget *targetWidget = 0; switch (relation) { - case QAccessible::Child: - *target = child(entry - 1); - return *target ? 0 : -1; case QAccessible::Up: if (entry == 2) targetWidget = navigationBar(); @@ -1201,9 +1199,6 @@ QAccessibleInterface *QAccessibleTitleBar::child(int index) const int QAccessibleTitleBar::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **iface) const { switch (relation) { - case QAccessible::Child: - *iface = child(entry - 1); - return *iface ? 0 : -1; case QAccessible::FocusChild: // ### if (entry >= 1) { @@ -1222,9 +1217,6 @@ int QAccessibleTitleBar::navigate(QAccessible::RelationFlag relation, int entry, return role > QDockWidgetLayout::FloatButton ? -1 : index; } break; - case QAccessible::Ancestor: - *iface = parent(); - return iface ? 0 : -1; default: break; } diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.h b/src/plugins/accessible/widgets/qaccessiblewidgets.h index 44fdcc7..e60ed06 100644 --- a/src/plugins/accessible/widgets/qaccessiblewidgets.h +++ b/src/plugins/accessible/widgets/qaccessiblewidgets.h @@ -125,7 +125,6 @@ public: int childCount() const; int indexOfChild(const QAccessibleInterface *child) const; QAccessibleInterface *child(int index) const; - int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; protected: QStackedWidget *stackedWidget() const; @@ -153,6 +152,7 @@ public: explicit QAccessibleMdiArea(QWidget *widget); int childCount() const; + QAccessibleInterface *child(int index) const; int indexOfChild(const QAccessibleInterface *child) const; int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; @@ -169,6 +169,7 @@ public: void setText(QAccessible::Text textType, const QString &text); QAccessible::State state() const; int childCount() const; + QAccessibleInterface *child(int index) const; int indexOfChild(const QAccessibleInterface *child) const; int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; QRect rect() const; @@ -185,6 +186,7 @@ public: explicit QAccessibleWorkspace(QWidget *widget); int childCount() const; + QAccessibleInterface *child(int index) const; int indexOfChild(const QAccessibleInterface *child) const; int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const; diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 385ca09..b05b917 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -464,10 +464,11 @@ int QAccessibleDisplay::navigate(QAccessible::RelationFlag rel, int entry, QAcce } else { QGroupBox *groupbox = qobject_cast(object()); if (groupbox && !groupbox->title().isEmpty()) - rel = QAccessible::Child; + *target = child(entry - 1); #endif } - *target = QAccessible::queryAccessibleInterface(targetObject); + if (targetObject) + *target = QAccessible::queryAccessibleInterface(targetObject); if (*target) return 0; } diff --git a/src/plugins/platforms/windows/qwindowsaccessibility.cpp b/src/plugins/platforms/windows/qwindowsaccessibility.cpp index 73006a5..f181f30 100644 --- a/src/plugins/platforms/windows/qwindowsaccessibility.cpp +++ b/src/plugins/platforms/windows/qwindowsaccessibility.cpp @@ -762,13 +762,12 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::accNavigate(long navDir, VARIANT v return E_FAIL; QAccessibleInterface *acc = 0; - int control = -1; switch (navDir) { case NAVDIR_FIRSTCHILD: - control = accessible->navigate(QAccessible::Child, 1, &acc); + acc = accessible->child(0); break; case NAVDIR_LASTCHILD: - control = accessible->navigate(QAccessible::Child, accessible->childCount(), &acc); + acc = accessible->child(accessible->childCount() - 1); break; case NAVDIR_NEXT: case NAVDIR_PREVIOUS: @@ -778,41 +777,107 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::accNavigate(long navDir, VARIANT v int index = parent->indexOfChild(accessible); index += (navDir == NAVDIR_NEXT) ? 1 : -1; if (index > 0 && index <= parent->childCount()) - control = parent->navigate(QAccessible::Child, index, &acc); + acc = parent->child(index - 1); delete parent; } } else { int index = varStart.lVal; index += (navDir == NAVDIR_NEXT) ? 1 : -1; if (index > 0 && index <= accessible->childCount()) - control = accessible->navigate(QAccessible::Child, index, &acc); + acc = accessible->child(index - 1); } break; + + // Geometrical case NAVDIR_UP: - control = accessible->navigate(QAccessible::Up, varStart.lVal, &acc); - break; case NAVDIR_DOWN: - control = accessible->navigate(QAccessible::Down, varStart.lVal, &acc); - break; case NAVDIR_LEFT: - control = accessible->navigate(QAccessible::Left, varStart.lVal, &acc); - break; case NAVDIR_RIGHT: - control = accessible->navigate(QAccessible::Right, varStart.lVal, &acc); + if (QAccessibleInterface *pIface = accessible->parent()) { + + QRect startg = accessible->rect(); + QPoint startc = startg.center(); + QAccessibleInterface *candidate = 0; + unsigned mindist = UINT_MAX; // will work on screen sizes at least up to 46340x46340 + const int sibCount = pIface->childCount(); + for (int i = 0; i < sibCount; ++i) { + QAccessibleInterface *sibling = 0; + sibling = pIface->child(i); + Q_ASSERT(sibling); + if ((accessible->relationTo(sibling) & QAccessible::Self) || (sibling->state() & QAccessible::Invisible)) { + //ignore ourself and invisible siblings + delete sibling; + continue; + } + + QRect sibg = sibling->rect(); + QPoint sibc = sibg.center(); + QPoint sibp; + QPoint startp; + QPoint distp; + switch (navDir) { + case NAVDIR_LEFT: + startp = QPoint(startg.left(), startg.top() + startg.height() / 2); + sibp = QPoint(sibg.right(), sibg.top() + sibg.height() / 2); + if (QPoint(sibc - startc).x() >= 0) { + delete sibling; + continue; + } + distp = sibp - startp; + break; + case NAVDIR_RIGHT: + startp = QPoint(startg.right(), startg.top() + startg.height() / 2); + sibp = QPoint(sibg.left(), sibg.top() + sibg.height() / 2); + if (QPoint(sibc - startc).x() <= 0) { + delete sibling; + continue; + } + distp = sibp - startp; + break; + case NAVDIR_UP: + startp = QPoint(startg.left() + startg.width() / 2, startg.top()); + sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.bottom()); + if (QPoint(sibc - startc).y() >= 0) { + delete sibling; + continue; + } + distp = sibp - startp; + break; + case NAVDIR_DOWN: + startp = QPoint(startg.left() + startg.width() / 2, startg.bottom()); + sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.top()); + if (QPoint(sibc - startc).y() <= 0) { + delete sibling; + continue; + } + distp = sibp - startp; + break; + default: + break; + } + + // Since we're *comparing* (and not measuring) distances, we can compare the + // squared distance, (thus, no need to take the sqrt()). + unsigned dist = distp.x() * distp.x() + distp.y() * distp.y(); + if (dist < mindist) { + delete candidate; + candidate = sibling; + mindist = dist; + } else { + delete sibling; + } + } + delete pIface; + acc = candidate; + } break; default: break; } - if (control == -1) { + if (!acc) { (*pvarEnd).vt = VT_EMPTY; return S_FALSE; } - if (!acc) { - (*pvarEnd).vt = VT_I4; - (*pvarEnd).lVal = control; - return S_OK; - } - QWindowsAccessible* wacc = new QWindowsAccessible(acc); IDispatch *iface = 0; @@ -850,18 +915,21 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accChild(VARIANT varChildID, I acc = QAccessible::queryAccessibleInterface(ref.first); if (acc && ref.second) { if (ref.second) { - QAccessibleInterface *res; - int index = acc->navigate(QAccessible::Child, ref.second, &res); + QAccessibleInterface *res = acc->child(ref.second - 1); delete acc; - if (index == -1) + if (!res) return E_INVALIDARG; acc = res; } } } } else { - QAccessible::RelationFlag rel = childIndex ? QAccessible::Child : QAccessible::Self; - accessible->navigate(rel, childIndex, &acc); + if (childIndex) { + acc = accessible->child(childIndex - 1); + } else { + // FIXME + Q_ASSERT(0); + } } if (acc) { diff --git a/src/widgets/accessible/qaccessiblewidget.cpp b/src/widgets/accessible/qaccessiblewidget.cpp index 5953333..43a72a3 100644 --- a/src/widgets/accessible/qaccessiblewidget.cpp +++ b/src/widgets/accessible/qaccessiblewidget.cpp @@ -363,11 +363,7 @@ QAccessible::Relation QAccessibleWidget::relationTo(const QAccessibleInterface * } QObject *parent = object()->parent(); - if (o == parent) - return relation | QAccessible::Child; - if (o->parent() == parent) { - relation |= QAccessible::Sibling; QAccessibleInterface *sibIface = QAccessible::queryAccessibleInterface(o); Q_ASSERT(sibIface); QRect wg = rect(); @@ -385,28 +381,12 @@ QAccessible::Relation QAccessibleWidget::relationTo(const QAccessibleInterface * relation |= QAccessible::Covered; } delete pIface; - } else { - QPoint wc = wg.center(); - QPoint sc = sg.center(); - if (wc.x() < sc.x()) - relation |= QAccessible::Left; - else if(wc.x() > sc.x()) - relation |= QAccessible::Right; - if (wc.y() < sc.y()) - relation |= QAccessible::Up; - else if (wc.y() > sc.y()) - relation |= QAccessible::Down; } delete sibIface; return relation; } - if (isAncestor(o, object())) - return relation | QAccessible::Descendent; - if (isAncestor(object(), o)) - return relation | QAccessible::Ancestor; - return relation; } @@ -437,120 +417,6 @@ int QAccessibleWidget::navigate(QAccessible::RelationFlag relation, int entry, QObject *targetObject = 0; switch (relation) { - // Hierarchical - case QAccessible::Self: - targetObject = object(); - break; - case QAccessible::Child: - qWarning() << "QAccessibleWidget::navigate is deprecated for QAccessible::Child in:" << object()->metaObject()->className(); - *target = child(entry - 1); - return *target ? 0 : -1; - case QAccessible::Ancestor: - qWarning() << "QAccessibleWidget::navigate is deprecated for QAccessible::Ancestor in:" << object()->metaObject()->className(); - *target = parent(); - return *target ? 0 : -1; - case QAccessible::Sibling: - { - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(parentObject()); - if (!iface) - return -1; - - *target = iface->child(entry - 1); - delete iface; - if (*target) - return 0; - } - break; - - // Geometrical - case QAccessible::Left: - // fall through - case QAccessible::Right: - // fall through - case QAccessible::Up: - // fall through - case QAccessible::Down: - { - QAccessibleInterface *pIface = parent(); - if (!pIface) - return -1; - - QRect startg = rect(); - QPoint startc = startg.center(); - QAccessibleInterface *candidate = 0; - int mindist = 100000; - int sibCount = pIface->childCount(); - for (int i = 0; i < sibCount; ++i) { - QAccessibleInterface *sibling = 0; - sibling = pIface->child(i); - Q_ASSERT(sibling); - if ((relationTo(sibling) & QAccessible::Self) || (sibling->state() & QAccessible::Invisible)) { - //ignore ourself and invisible siblings - delete sibling; - continue; - } - - QRect sibg = sibling->rect(); - QPoint sibc = sibg.center(); - QPoint sibp; - QPoint startp; - QPoint distp; - switch (relation) { - case QAccessible::Left: - startp = QPoint(startg.left(), startg.top() + startg.height() / 2); - sibp = QPoint(sibg.right(), sibg.top() + sibg.height() / 2); - if (QPoint(sibc - startc).x() >= 0) { - delete sibling; - continue; - } - distp = sibp - startp; - break; - case QAccessible::Right: - startp = QPoint(startg.right(), startg.top() + startg.height() / 2); - sibp = QPoint(sibg.left(), sibg.top() + sibg.height() / 2); - if (QPoint(sibc - startc).x() <= 0) { - delete sibling; - continue; - } - distp = sibp - startp; - break; - case QAccessible::Up: - startp = QPoint(startg.left() + startg.width() / 2, startg.top()); - sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.bottom()); - if (QPoint(sibc - startc).y() >= 0) { - delete sibling; - continue; - } - distp = sibp - startp; - break; - case QAccessible::Down: - startp = QPoint(startg.left() + startg.width() / 2, startg.bottom()); - sibp = QPoint(sibg.left() + sibg.width() / 2, sibg.top()); - if (QPoint(sibc - startc).y() <= 0) { - delete sibling; - continue; - } - distp = sibp - startp; - break; - default: - break; - } - - int dist = (int)qSqrt((qreal)distp.x() * distp.x() + distp.y() * distp.y()); - if (dist < mindist) { - delete candidate; - candidate = sibling; - mindist = dist; - } else { - delete sibling; - } - } - delete pIface; - *target = candidate; - if (*target) - return 0; - } - break; case QAccessible::Covers: if (entry > 0) { QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject()); diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 858d439..111633c 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -230,7 +230,6 @@ private slots: void customWidget(); void deletedWidget(); - void navigateGeometric(); void navigateHierarchy(); void sliderTest(); void navigateCovered(); @@ -463,102 +462,6 @@ void tst_QAccessibility::deletedWidget() delete iface; } -void tst_QAccessibility::navigateGeometric() -{ - { - static const int skip = 20; //speed the test up significantly - static const double step = Q_PI / 180; - QWidget *w = new QWidget(0); - w->setObjectName(QString("Josef")); - w->setFixedSize(400, 400); - - // center widget - QtTestAccessibleWidget *center = new QtTestAccessibleWidget(w, "Sol"); - center->move(200, 200); - - // arrange 360 widgets around it in a circle - QtTestAccessibleWidget *aw = 0; - for (int i = 0; i < 360; i += skip) { - aw = new QtTestAccessibleWidget(w, QString::number(i).toLatin1()); - aw->move( int(200.0 + 100.0 * sin(step * (double)i)), int(200.0 + 100.0 * cos(step * (double)i)) ); - } - - aw = new QtTestAccessibleWidget(w, "Earth"); - QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(center); - QAccessibleInterface *target = 0; - QVERIFY(iface != 0); - QVERIFY(iface->isValid()); - - w->show(); - QCoreApplication::processEvents(); - QTest::qWait(100); - - // let one widget rotate around center - for (int i = 0; i < 360; i+=skip) { - aw->move( int(200.0 + 75.0 * sin(step * (double)i)), int(200.0 + 75.0 * cos(step * (double)i)) ); - - if (i < 45 || i > 315) { - QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0); - } else if ( i < 135 ) { - QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0); - } else if ( i < 225 ) { - QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0); - } else { - QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0); - } - - QVERIFY(target); - QVERIFY(target->isValid()); - QVERIFY(target->object()); - QCOMPARE(target->object()->objectName(), aw->objectName()); - delete target; target = 0; - } - - // test invisible widget - target = QAccessible::queryAccessibleInterface(aw); - QVERIFY(!(target->state() & QAccessible::Invisible)); - aw->hide(); - QVERIFY(target->state() & QAccessible::Invisible); - delete target; target = 0; - - aw->move(center->x() + 10, center->y()); - QCOMPARE(iface->navigate(QAccessible::Right, 0, &target), 0); - QVERIFY(target); - QVERIFY(target->isValid()); - QVERIFY(target->object()); - QVERIFY(QString(target->object()->objectName()) != "Earth"); - delete target; target = 0; - - aw->move(center->x() - 10, center->y()); - QCOMPARE(iface->navigate(QAccessible::Left, 0, &target), 0); - QVERIFY(target); - QVERIFY(target->isValid()); - QVERIFY(target->object()); - QVERIFY(QString(target->object()->objectName()) != "Earth"); - delete target; target = 0; - - aw->move(center->x(), center->y() + 10); - QCOMPARE(iface->navigate(QAccessible::Down, 0, &target), 0); - QVERIFY(target); - QVERIFY(target->isValid()); - QVERIFY(target->object()); - QVERIFY(QString(target->object()->objectName()) != "Earth"); - delete target; target = 0; - - aw->move(center->x(), center->y() - 10); - QCOMPARE(iface->navigate(QAccessible::Up, 0, &target), 0); - QVERIFY(target); - QVERIFY(target->isValid()); - QVERIFY(target->object()); - QVERIFY(QString(target->object()->objectName()) != "Earth"); - delete target; target = 0; - - delete iface; - delete w; - } - QTestAccessibility::clearEvents(); -} - void tst_QAccessibility::sliderTest() { { @@ -721,11 +624,6 @@ void tst_QAccessibility::navigateHierarchy() QVERIFY(iface != 0); QVERIFY(iface->isValid()); - QCOMPARE(iface->navigate(QAccessible::Sibling, -42, &target), -1); - QVERIFY(target == 0); - QCOMPARE(iface->navigate(QAccessible::Sibling, 42, &target), -1); - QVERIFY(target == 0); - target = iface->child(14); QVERIFY(target == 0); target = iface->child(-1); @@ -741,38 +639,27 @@ void tst_QAccessibility::navigateHierarchy() delete interfaceW1; delete iface; iface = 0; - QCOMPARE(target->navigate(QAccessible::Sibling, 0, &iface), -1); - QVERIFY(iface == 0); - QCOMPARE(target->navigate(QAccessible::Sibling, 42, &iface), -1); - QVERIFY(iface == 0); - QCOMPARE(target->navigate(QAccessible::Sibling, -42, &iface), -1); - QVERIFY(iface == 0); - QCOMPARE(target->navigate(QAccessible::Sibling, 2, &iface), 0); - QVERIFY(iface != 0); - QVERIFY(iface->isValid()); - QCOMPARE(iface->object(), (QObject*)w2); - delete target; target = 0; - QCOMPARE(iface->navigate(QAccessible::Sibling, 3, &target), 0); + iface = QAccessible::queryAccessibleInterface(w); + target = iface->child(2); QVERIFY(target != 0); QVERIFY(target->isValid()); QCOMPARE(target->object(), (QObject*)w3); delete iface; iface = 0; + + iface = target->child(1); + QCOMPARE(iface, (QAccessibleInterface*)0); iface = target->child(0); QVERIFY(iface != 0); QVERIFY(iface->isValid()); QCOMPARE(iface->object(), (QObject*)w31); - delete target; target = 0; - QCOMPARE(iface->navigate(QAccessible::Sibling, -1, &target), -1); - QVERIFY(target == 0); - QCOMPARE(iface->navigate(QAccessible::Sibling, 0, &target), -1); - QVERIFY(target == 0); - QCOMPARE(iface->navigate(QAccessible::Sibling, 1, &target), 0); - QVERIFY(target != 0); - QVERIFY(target->isValid()); + iface = QAccessible::queryAccessibleInterface(w); + QAccessibleInterface *acc3 = iface->child(2); + target = acc3->child(0); + delete acc3; + delete iface; QCOMPARE(target->object(), (QObject*)w31); - delete iface; iface = 0; iface = target->parent(); QVERIFY(iface != 0); @@ -1555,8 +1442,7 @@ void tst_QAccessibility::menuTest() QAccessible::MenuItem }; for (int child = 0; child < 5; ++child) { - entry = iface->navigate(QAccessible::Sibling, child + 1, &iface2); - QCOMPARE(entry, 0); + iface2 = interface->child(child); QVERIFY(iface2); QCOMPARE(iface2->role(), fileRoles[child]); delete iface2; @@ -2133,6 +2019,16 @@ void tst_QAccessibility::workspaceTest() QTestAccessibility::clearEvents(); } +bool accessibleInterfaceLeftOf(const QAccessibleInterface *a1, const QAccessibleInterface *a2) +{ + return a1->rect().x() < a2->rect().x(); +} + +bool accessibleInterfaceAbove(const QAccessibleInterface *a1, const QAccessibleInterface *a2) +{ + return a1->rect().y() < a2->rect().y(); +} + void tst_QAccessibility::dialogButtonBoxTest() { { @@ -2154,25 +2050,17 @@ void tst_QAccessibility::dialogButtonBoxTest() QCOMPARE(iface->role(), QAccessible::Grouping); QStringList actualOrder; QAccessibleInterface *child; - QAccessibleInterface *leftmost; child = iface->child(0); QCOMPARE(child->role(), QAccessible::PushButton); - // first find the leftmost button - while (child->navigate(QAccessible::Left, 1, &leftmost) != -1) { - delete child; - child = leftmost; - } - leftmost = child; - - // then traverse from left to right to find the correct order of the buttons - int right = 0; - while (right != -1) { - actualOrder << leftmost->text(QAccessible::Name); - right = leftmost->navigate(QAccessible::Right, 1, &child); - delete leftmost; - leftmost = child; - } + QVector buttons; + for (int i = 0; i < iface->childCount(); ++i) + buttons << iface->child(i); + + qSort(buttons.begin(), buttons.end(), accessibleInterfaceLeftOf); + + for (int i = 0; i < buttons.count(); ++i) + actualOrder << buttons.at(i)->text(QAccessible::Name); QStringList expectedOrder; QDialogButtonBox::ButtonLayout btnlout = @@ -2214,26 +2102,16 @@ void tst_QAccessibility::dialogButtonBoxTest() #endif QApplication::processEvents(); - QAccessibleInterface *child; QStringList actualOrder; - child = iface->child(0); - // first find the topmost button - QAccessibleInterface *other; - while (child->navigate(QAccessible::Up, 1, &other) != -1) { - delete child; - child = other; - } - other = child; - - // then traverse from top to bottom to find the correct order of the buttons - actualOrder.clear(); - int right = 0; - while (right != -1) { - actualOrder << other->text(QAccessible::Name); - right = other->navigate(QAccessible::Down, 1, &child); - delete other; - other = child; - } + + QVector buttons; + for (int i = 0; i < iface->childCount(); ++i) + buttons << iface->child(i); + + qSort(buttons.begin(), buttons.end(), accessibleInterfaceAbove); + + for (int i = 0; i < buttons.count(); ++i) + actualOrder << buttons.at(i)->text(QAccessible::Name); QStringList expectedOrder; expectedOrder << QDialogButtonBox::tr("OK") -- 2.7.4