Change default implementation of window() to just return 0
authorJan-Arve Saether <jan-arve.saether@nokia.com>
Thu, 24 Nov 2011 14:33:29 +0000 (15:33 +0100)
committerQt by Nokia <qt-info@nokia.com>
Fri, 25 Nov 2011 10:29:11 +0000 (11:29 +0100)
Instead move the traversal up to the ancestors to the bridge.
This simplifies the default implementation to just return 0

Change-Id: Ic3ec60851f378587f4a23363aec2039d0e8a08a1
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
src/gui/accessible/qaccessible.cpp
src/plugins/platforms/windows/qwindowsaccessibility.cpp

index 5faadc8..057d97a 100644 (file)
@@ -1167,18 +1167,18 @@ QColor QAccessibleInterface::backgroundColor() const
     For instance, QAccessibleWidget reimplements this and returns
     the windowHandle() of the QWidget.
 
-    The default implementation returns the window() of the parent interface.
-
     It is used on some platforms to be able to notify the AT client about
     state changes.
+    The backend will traverse up all ancestors until it finds a window.
+    (This means that at least one interface among the ancestors should
+    return a valid QWindow pointer).
+
+    The default implementation of this returns 0.
     \preliminary
   */
 QWindow *QAccessibleInterface::window() const
 {
-    QAccessibleInterface *par = parent();
-    QWindow *w = par ? par->window() : 0;
-    delete par;
-    return w;
+    return 0;
 }
 
 /*!
index ee8ecc1..8833981 100644 (file)
@@ -1285,13 +1285,28 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accSelection(VARIANT *pvarChil
     return S_OK;
 }
 
+static QWindow *window_helper(const QAccessibleInterface *iface)
+{
+    QWindow *window = iface->window();
+    if (!window) {
+        QAccessibleInterface *acc = iface->parent();
+        while (acc && !window) {
+            window = acc->window();
+            QAccessibleInterface *par = acc->parent();
+            delete acc;
+            acc = par;
+        }
+    }
+    return window;
+}
+
 HRESULT STDMETHODCALLTYPE QWindowsAccessible::GetWindow(HWND *phwnd)
 {
     *phwnd = 0;
     if (!accessible->isValid())
         return E_UNEXPECTED;
 
-    QWindow *window = accessible->window();
+    QWindow *window = window_helper(accessible);
     if (!window)
         return E_FAIL;
 
@@ -1387,7 +1402,7 @@ void QWindowsAccessibility::notifyAccessibilityUpdate(QObject *o, int who, QAcce
     // An event has to be associated with a window,
     // so find the first parent that is a widget and that has a WId
     QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(o);
-    QWindow *window = iface->window();
+    QWindow *window = window_helper(iface);
 
     if (!window) {
         window = QGuiApplication::activeWindow();