Remove QAccessible::FocusChild, add focusChild()
authorJan-Arve Saether <jan-arve.saether@nokia.com>
Thu, 19 Jan 2012 13:20:54 +0000 (14:20 +0100)
committerQt by Nokia <qt-info@nokia.com>
Mon, 6 Feb 2012 09:15:09 +0000 (10:15 +0100)
Also cleanup (reduce) all implementations of navigate() in order
to make the final removal of navigate smoother.

Change-Id: I2c216db8f5b2e40afcce8f859fc775053adc2fe3
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
14 files changed:
src/gui/accessible/qaccessible.cpp
src/gui/accessible/qaccessible.h
src/gui/accessible/qaccessibleobject.cpp
src/gui/accessible/qaccessibleobject.h
src/plugins/accessible/widgets/complexwidgets.cpp
src/plugins/accessible/widgets/itemviews.cpp
src/plugins/accessible/widgets/itemviews.h
src/plugins/accessible/widgets/qaccessiblemenu.cpp
src/plugins/accessible/widgets/qaccessiblemenu.h
src/plugins/accessible/widgets/qaccessiblewidgets.cpp
src/plugins/accessible/widgets/qaccessiblewidgets.h
src/plugins/platforms/windows/qwindowsaccessibility.cpp
src/widgets/accessible/qaccessiblewidget.cpp
src/widgets/accessible/qaccessiblewidget.h

index 8610ef7..b45c7e8 100644 (file)
@@ -910,6 +910,16 @@ QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > QAccessibleInterfa
 }
 
 /*!
+    Returns the object that has the keyboard focus.
+
+    The object returned can be any descendant, including itself.
+*/
+QAccessibleInterface *QAccessibleInterface::focusChild() const
+{
+    return 0;
+}
+
+/*!
     \fn QAccessibleInterface *QAccessibleInterface::childAt(int x, int y) const
 
     Returns the QAccessibleInterface of a child that contains the screen coordinates (\a x, \a y).
@@ -991,6 +1001,14 @@ QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > QAccessibleInterfa
 
     \sa relationTo(), childCount(), parent(), child()
 */
+int QAccessibleInterface::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const
+{
+    Q_UNUSED(entry);
+    Q_UNUSED(relation);
+    *target = 0;
+    return -1;
+}
+
 
 /*!
     \fn QString QAccessibleInterface::text(QAccessible::Text t) const
index 202791c..214ec20 100644 (file)
@@ -307,7 +307,6 @@ public:
 
     enum RelationFlag {
         Unrelated     = 0x00000000,
-        FocusChild    = 0x00010000,
         Label         = 0x00020000,
         Labelled      = 0x00040000,
         Controller    = 0x00080000,
@@ -382,6 +381,7 @@ public:
     // relations
     virtual QAccessible::Relation relationTo(const QAccessibleInterface *other) const;
     virtual QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > relations() const;
+    virtual QAccessibleInterface *focusChild() const;
 
     virtual QAccessibleInterface *childAt(int x, int y) const = 0;
 
@@ -390,7 +390,7 @@ public:
     virtual QAccessibleInterface *child(int index) const = 0;
     virtual int childCount() const = 0;
     virtual int indexOfChild(const QAccessibleInterface *) const = 0;
-    virtual int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const = 0;
+    virtual int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const;
 
     // properties and state
     virtual QString text(QAccessible::Text t) const = 0;
index b9e0ac3..d277f39 100644 (file)
@@ -237,28 +237,13 @@ QAccessibleInterface *QAccessibleApplication::child(int index) const
     return 0;
 }
 
+
 /*! \reimp */
-int QAccessibleApplication::navigate(QAccessible::RelationFlag relation, int,
-                                     QAccessibleInterface **target) const
+QAccessibleInterface *QAccessibleApplication::focusChild() const
 {
-    if (!target)
-        return -1;
-
-    *target = 0;
-    QObject *targetObject = 0;
-
-    switch (relation) {
-    case QAccessible::FocusChild:
-        if (QWindow *window = QGuiApplication::activeWindow()) {
-            *target = window->accessibleRoot();
-            return 0;
-        }
-        break;
-    default:
-        break;
-    }
-    *target = QAccessible::queryAccessibleInterface(targetObject);
-    return *target ? 0 : -1;
+    if (QWindow *window = QGuiApplication::activeWindow())
+        return window->accessibleRoot();
+    return 0;
 }
 
 /*! \reimp */
index 2372e82..d035f17 100644 (file)
@@ -85,11 +85,11 @@ public:
     // relations
     int childCount() const;
     int indexOfChild(const QAccessibleInterface*) const;
+    QAccessibleInterface *focusChild() const;
 
     // navigation
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
-    int navigate(QAccessible::RelationFlag, int, QAccessibleInterface **) const;
 
     // properties and state
     QString text(QAccessible::Text t) const;
index 50e0cd7..e4b1067 100644 (file)
@@ -122,13 +122,6 @@ public:
         return QAccessible::queryAccessibleInterface(m_parent);
     }
     QAccessibleInterface *child(int) const { return 0; }
-    int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
-    {
-        Q_UNUSED(relation);
-        Q_UNUSED(index);
-        Q_UNUSED(iface);
-        return -1;
-    }
     // action interface
     QStringList actionNames() const
     {
index a85c799..a9f3a85 100644 (file)
@@ -442,14 +442,6 @@ QAccessibleInterface *QAccessibleTable::child(int index) const
     return childFromLogical(index + 1);
 }
 
-int QAccessibleTable::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
-{
-    Q_UNUSED(relation);
-    Q_UNUSED(index);
-    *iface = 0;
-    return -1;
-}
-
 void *QAccessibleTable::interface_cast(QAccessible::InterfaceType t)
 {
     if (t == QAccessible::TableInterface)
@@ -780,41 +772,6 @@ QAccessibleInterface *QAccessibleTableCell::child(int) const
     return 0;
 }
 
-int QAccessibleTableCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
-{
-    Q_UNUSED(index);
-    Q_UNUSED(relation);
-
-//  switch (relation) {
-// From table1 implementation:
-//    case Up:
-//    case Down:
-//    case Left:
-//    case Right: {
-//        // This is in the "not so nice" category. In order to find out which item
-//        // is geometrically around, we have to set the current index, navigate
-//        // and restore the index as well as the old selection
-//        view->setUpdatesEnabled(false);
-//        const QModelIndex oldIdx = view->currentIndex();
-//        QList<QModelIndex> kids = children();
-//        const QModelIndex currentIndex = index ? kids.at(index - 1) : QModelIndex(row);
-//        const QItemSelection oldSelection = view->selectionModel()->selection();
-//        view->setCurrentIndex(currentIndex);
-//        const QModelIndex idx = view->moveCursor(toCursorAction(relation), Qt::NoModifier);
-//        view->setCurrentIndex(oldIdx);
-//        view->selectionModel()->select(oldSelection, QItemSelectionModel::ClearAndSelect);
-//        view->setUpdatesEnabled(true);
-//        if (!idx.isValid())
-//            return -1;
-
-//        if (idx.parent() != row.parent() || idx.row() != row.row())
-//            *iface = cell(idx);
-//        return index ? kids.indexOf(idx) + 1 : 0; }
-//    }
-    *iface = 0;
-    return -1;
-}
-
 QAccessibleTableHeaderCell::QAccessibleTableHeaderCell(QAbstractItemView *view_, int index_, Qt::Orientation orientation_)
     : view(view_), index(index_), orientation(orientation_)
 {
@@ -905,15 +862,6 @@ QAccessibleInterface *QAccessibleTableHeaderCell::child(int) const
     return 0;
 }
 
-int QAccessibleTableHeaderCell::navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const
-{
-    Q_UNUSED(relation);
-    Q_UNUSED(index);
-    Q_UNUSED(iface);
-
-    return -1;
-}
-
 #endif // QT_NO_ITEMVIEWS
 
 QT_END_NAMESPACE
index 35a9f83..3d852a2 100644 (file)
@@ -77,7 +77,6 @@ public:
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
-    int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const;
 
     void *interface_cast(QAccessible::InterfaceType t);
 
@@ -190,7 +189,6 @@ public:
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int) const;
-    int navigate(QAccessible::RelationFlag relation, int m_index, QAccessibleInterface **iface) const;
 
     // cell interface
     virtual int columnExtent() const;
@@ -236,7 +234,6 @@ public:
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
-    int navigate(QAccessible::RelationFlag relation, int index, QAccessibleInterface **iface) const;
 
 private:
     QAbstractItemView *view;
@@ -276,13 +273,6 @@ public:
     QAccessibleInterface *child(int) const {
         return 0;
     }
-    int navigate(QAccessible::RelationFlag relation, int, QAccessibleInterface **iface) const
-    {
-        Q_UNUSED(relation);
-        Q_UNUSED(iface);
-        return -1;
-    }
-
 private:
     QAbstractItemView *view;
 };
index 49cf550..d3ca162 100644 (file)
@@ -204,14 +204,6 @@ QAccessibleInterface *QAccessibleMenuItem::child(int index) const
     return 0;
 }
 
-int QAccessibleMenuItem::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **target) const
-{
-    Q_UNUSED(relation);
-    Q_UNUSED(entry);
-    *target = 0;
-    return -1;
-}
-
 void *QAccessibleMenuItem::interface_cast(QAccessible::InterfaceType t)
 {
     if (t == QAccessible::ActionInterface)
index e926dc7..af934e2 100644 (file)
@@ -103,7 +103,6 @@ public:
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
-    int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface ** target) const;
     QObject * object() const;
     QRect rect() const;
     QAccessible::Role role() const;
index 12a415a..94101ef 100644 (file)
@@ -965,34 +965,6 @@ QAccessibleInterface *QAccessibleTitleBar::child(int index) const
     return 0;
 }
 
-int QAccessibleTitleBar::navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **iface) const
-{
-    switch (relation) {
-    case QAccessible::FocusChild:
-        // ###
-        if (entry >= 1) {
-            QDockWidgetLayout *layout = dockWidgetLayout();
-            int index = 1;
-            int role;
-            for (role = QDockWidgetLayout::CloseButton; role <= QDockWidgetLayout::FloatButton; ++role) {
-                QWidget *w = layout->widgetForRole((QDockWidgetLayout::Role)role);
-                if (!w->isVisible())
-                    continue;
-                if (index == entry)
-                    break;
-                ++index;
-            }
-            *iface = 0;
-            return role > QDockWidgetLayout::FloatButton ? -1 : index;
-        }
-        break;
-    default:
-        break;
-    }
-    *iface = 0;
-    return -1;
-}
-
 int QAccessibleTitleBar::indexOfChild(const QAccessibleInterface * /*child*/) const
 {
     return -1;
index c19f1f4..147ea91 100644 (file)
@@ -248,7 +248,6 @@ public:
 
     QAccessibleInterface *parent() const;
     QAccessibleInterface *child(int index) const;
-    int navigate(QAccessible::RelationFlag relation, int entry, QAccessibleInterface **iface) const;
     int indexOfChild(const QAccessibleInterface *child) const;
     int childCount() const;
     QAccessibleInterface *childAt(int x, int y) const;
index 2678fd7..8d11745 100644 (file)
@@ -1189,29 +1189,18 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accFocus(VARIANT *pvarID)
     if (!accessible->isValid())
         return E_FAIL;
 
-    QAccessibleInterface *acc = 0;
-    int control = accessible->navigate(QAccessible::FocusChild, 1, &acc);
-    if (control == -1) {
-        (*pvarID).vt = VT_EMPTY;
-        return S_FALSE;
-    }
-    if (!acc || control == 0) {
-        (*pvarID).vt = VT_I4;
-        (*pvarID).lVal = control ? control : CHILDID_SELF;
-        return S_OK;
-    }
-
-    QWindowsAccessible* wacc = new QWindowsAccessible(acc);
-    IDispatch *iface = 0;
-    wacc->QueryInterface(IID_IDispatch, (void**)&iface);
-    if (iface) {
-        (*pvarID).vt = VT_DISPATCH;
-        (*pvarID).pdispVal = iface;
-        return S_OK;
-    } else {
-        delete wacc;
+    if (QAccessibleInterface *acc = accessible->focusChild()) {
+        QWindowsAccessible* wacc = new QWindowsAccessible(acc);
+        IDispatch *iface = 0;
+        wacc->QueryInterface(IID_IDispatch, (void**)&iface);
+        if (iface) {
+            (*pvarID).vt = VT_DISPATCH;
+            (*pvarID).pdispVal = iface;
+            return S_OK;
+        } else {
+            delete wacc;
+        }
     }
-
     (*pvarID).vt = VT_EMPTY;
     return S_FALSE;
 }
index a4a86e5..be579fe 100644 (file)
@@ -339,10 +339,6 @@ QAccessible::Relation QAccessibleWidget::relationTo(const QAccessibleInterface *
     if (!o)
         return relation;
 
-    QWidget *focus = widget()->focusWidget();
-    if (object() == focus && isAncestor(o, focus))
-        relation |= QAccessible::FocusChild;
-
     QACConnectionObject *connectionObject = (QACConnectionObject*)object();
     for (int sig = 0; sig < d->primarySignals.count(); ++sig) {
         if (connectionObject->isSender(o, d->primarySignals.at(sig).toAscii())) {
@@ -383,6 +379,20 @@ QAccessibleInterface *QAccessibleWidget::child(int index) const
 }
 
 /*! \reimp */
+QAccessibleInterface *QAccessibleWidget::focusChild() const
+{
+    if (widget()->hasFocus())
+        return QAccessible::queryAccessibleInterface(object());
+
+    QWidget *fw = widget()->focusWidget();
+    if (!fw)
+        return 0;
+
+    if (isAncestor(widget(), fw) || fw == widget())
+        return QAccessible::queryAccessibleInterface(fw);
+}
+
+/*! \reimp */
 int QAccessibleWidget::navigate(QAccessible::RelationFlag relation, int entry,
                                 QAccessibleInterface **target) const
 {
@@ -394,29 +404,6 @@ int QAccessibleWidget::navigate(QAccessible::RelationFlag relation, int entry,
 
     switch (relation) {
     // Logical
-    case QAccessible::FocusChild:
-        {
-            if (widget()->hasFocus()) {
-                targetObject = object();
-                break;
-            }
-
-            QWidget *fw = widget()->focusWidget();
-            if (!fw)
-                return -1;
-
-            if (isAncestor(widget(), fw) || fw == widget())
-                targetObject = fw;
-            /* ###
-            QWidget *parent = fw;
-            while (parent && !targetObject) {
-                parent = parent->parentWidget();
-                if (parent == widget())
-                    targetObject = fw;
-            }
-            */
-        }
-        break;
     case QAccessible::Label:
         if (entry > 0) {
             QAccessibleInterface *pIface = QAccessible::queryAccessibleInterface(parentObject());
index f96d298..d34d852 100644 (file)
@@ -62,6 +62,7 @@ public:
     int childCount() const;
     int indexOfChild(const QAccessibleInterface *child) const;
     QAccessible::Relation relationTo(const QAccessibleInterface *other) const;
+    QAccessibleInterface *focusChild() const;
 
     QRect rect() const;