vcl/CustomTarget_qt5_moc.mk         |    2 
 vcl/Library_vclplug_qt5.mk          |    2 
 vcl/inc/qt5/Qt5AccessibleWidget.hxx |    8 -
 vcl/inc/qt5/Qt5XAccessible.hxx      |   11 +-
 vcl/qt5/Qt5AccessibleWidget.cxx     |  162 ++++++++++--------------------------
 vcl/qt5/Qt5XAccessible.cxx          |   11 +-
 6 files changed, 65 insertions(+), 131 deletions(-)

New commits:
commit 7384e53bbc5163534ae898b7295b4efe51c8acde
Author:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
AuthorDate: Fri Sep 28 17:00:12 2018 +0200
Commit:     Samuel Mehrbrodt <samuel.mehrbr...@cib.de>
CommitDate: Mon Oct 1 08:49:24 2018 +0200

    qt5 a11y: Use UNO Api instead of vcl::Window methods
    
    This gets us into the document itself, not only the widgets.
    
    Change-Id: Id0cf1294817309c889729d01242cae69d2391130
    Reviewed-on: https://gerrit.libreoffice.org/61094
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index ab8deea2e950..55e9dcee9cd3 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -17,8 +17,8 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5MainWindow.moc \
        $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5Menu.moc \
        $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5Timer.moc \
-       $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5VclWindow.moc \
        $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5Widget.moc \
+       $(call gb_CustomTarget_get_workdir,vcl/qt5)/Qt5XAccessible.moc \
 
 $(call gb_CustomTarget_get_workdir,vcl/qt5)/%.moc : \
                $(SRCDIR)/vcl/inc/qt5/%.hxx \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index 3d350afe6a36..eda2e104d941 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -102,8 +102,8 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/Qt5Timer \
     vcl/qt5/Qt5Tools \
     vcl/qt5/Qt5VirtualDevice \
-    vcl/qt5/Qt5VclWindow \
     vcl/qt5/Qt5Widget \
+    vcl/qt5/Qt5XAccessible \
 ))
 
 ifeq ($(OS),LINUX)
diff --git a/vcl/inc/qt5/Qt5AccessibleWidget.hxx 
b/vcl/inc/qt5/Qt5AccessibleWidget.hxx
index df6862567dd0..c77104931eb6 100644
--- a/vcl/inc/qt5/Qt5AccessibleWidget.hxx
+++ b/vcl/inc/qt5/Qt5AccessibleWidget.hxx
@@ -22,7 +22,7 @@
 #include <QtGui/QColor>
 #include <QtGui/QWindow>
 
-#include <vcl/window.hxx>
+#include <com/sun/star/accessibility/XAccessible.hpp>
 
 class Qt5Frame;
 class Qt5Widget;
@@ -33,8 +33,7 @@ class VCLPLUG_QT5_PUBLIC Qt5AccessibleWidget : public 
QObject, public QAccessibl
     Q_OBJECT
 
 public:
-    Qt5AccessibleWidget(Qt5Widget* pFrame, vcl::Window* pWindow);
-    Qt5AccessibleWidget(vcl::Window* pWindow);
+    Qt5AccessibleWidget(const 
css::uno::Reference<css::accessibility::XAccessible> xAccessible);
     QWindow* window() const override;
     int childCount() const override;
     int indexOfChild(const QAccessibleInterface* child) const override;
@@ -70,8 +69,7 @@ public:
     static QAccessibleInterface* customFactory(const QString& classname, 
QObject* object);
 
 private:
-    Qt5Widget* m_pFrame;
-    VclPtr<vcl::Window> m_pWindow;
+    css::uno::Reference<css::accessibility::XAccessible> m_xAccessible;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5VclWindow.hxx b/vcl/inc/qt5/Qt5XAccessible.hxx
similarity index 59%
rename from vcl/inc/qt5/Qt5VclWindow.hxx
rename to vcl/inc/qt5/Qt5XAccessible.hxx
index f7883aa67c4d..66b3901f0b85 100644
--- a/vcl/inc/qt5/Qt5VclWindow.hxx
+++ b/vcl/inc/qt5/Qt5XAccessible.hxx
@@ -13,19 +13,22 @@
 
 #include <QtCore/QObject>
 
+#include <com/sun/star/accessibility/XAccessible.hpp>
+
 #include <vcl/window.hxx>
 
 class Qt5Frame;
 class Qt5Widget;
 
-// Wrapper class to hold a vcl::Window while being able to pass it as a QObject
-class VCLPLUG_QT5_PUBLIC Qt5VclWindow : public QObject
+// Wrapper class to hold a css::accessibility::XAccessible object
+// while being able to pass it as a QObject
+class VCLPLUG_QT5_PUBLIC Qt5XAccessible : public QObject
 {
     Q_OBJECT
 
 public:
-    Qt5VclWindow(vcl::Window* pWindow);
-    VclPtr<vcl::Window> m_pWindow;
+    Qt5XAccessible(css::uno::Reference<css::accessibility::XAccessible> 
xAccessible);
+    css::uno::Reference<css::accessibility::XAccessible> m_xAccessible;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5AccessibleWidget.cxx b/vcl/qt5/Qt5AccessibleWidget.cxx
index b07182fbee8f..3fecb9a28155 100644
--- a/vcl/qt5/Qt5AccessibleWidget.cxx
+++ b/vcl/qt5/Qt5AccessibleWidget.cxx
@@ -24,28 +24,24 @@
 
 #include <Qt5Frame.hxx>
 #include <Qt5Tools.hxx>
-#include <Qt5VclWindow.hxx>
+#include <Qt5XAccessible.hxx>
 #include <Qt5Widget.hxx>
 
 #include <com/sun/star/accessibility/AccessibleRole.hpp>
 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
 #include <com/sun/star/accessibility/XAccessible.hpp>
+#include <com/sun/star/accessibility/XAccessibleComponent.hpp>
 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
 
 #include <sal/log.hxx>
 #include <vcl/popupmenuwindow.hxx>
 
+using namespace css;
 using namespace css::accessibility;
 using namespace css::uno;
 
-Qt5AccessibleWidget::Qt5AccessibleWidget(Qt5Widget* pFrame, vcl::Window* 
pWindow)
-    : m_pFrame(pFrame)
-    , m_pWindow(pWindow)
-{
-}
-
-Qt5AccessibleWidget::Qt5AccessibleWidget(vcl::Window* pWindow)
-    : m_pWindow(pWindow)
+Qt5AccessibleWidget::Qt5AccessibleWidget(const Reference<XAccessible> 
xAccessible)
+    : m_xAccessible(xAccessible)
 {
 }
 
@@ -53,10 +49,7 @@ QWindow* Qt5AccessibleWidget::window() const { return 
nullptr; }
 
 int Qt5AccessibleWidget::childCount() const
 {
-    if (!m_pWindow.get())
-        return 0;
-
-    return m_pWindow->GetAccessibleChildWindowCount();
+    return m_xAccessible->getAccessibleContext()->getAccessibleChildCount();
 }
 
 int Qt5AccessibleWidget::indexOfChild(const QAccessibleInterface* /* child */) 
const { return 0; }
@@ -68,58 +61,42 @@ QVector<QPair<QAccessibleInterface*, QAccessible::Relation>>
 
 QAccessibleInterface* Qt5AccessibleWidget::focusChild() const
 {
-    if (m_pWindow->HasChildPathFocus())
+    /* if (m_pWindow->HasChildPathFocus())
         return QAccessible::queryAccessibleInterface(
-            new Qt5VclWindow(Application::GetFocusWindow()));
+            new 
Qt5XAccessible(m_xAccessible->getAccessibleContext()->getAccessibleChild(index)));
 */
     return QAccessible::queryAccessibleInterface(object());
 }
 
 QRect Qt5AccessibleWidget::rect() const
 {
-    if (!m_pWindow.get())
-        return QRect();
-
-    SolarMutexGuard aSolarGuard;
+    Reference<XAccessibleComponent> 
xAccessibleComponent(m_xAccessible->getAccessibleContext(),
+                                                         UNO_QUERY);
+    awt::Point aPoint = xAccessibleComponent->getLocation();
+    awt::Size aSize = xAccessibleComponent->getSize();
 
-    // TODO: This seems to return a relative position (to the parent window).
-    // Needs to be absolute instead.
-    Point aPoint(m_pWindow->GetPosPixel());
-    Size aSize(m_pWindow->GetSizePixel());
-
-    return QRect(aPoint.X(), aPoint.Y(), aSize.Width(), aSize.Height());
+    return QRect(aPoint.X, aPoint.Y, aSize.Width, aSize.Height);
 }
 
 QAccessibleInterface* Qt5AccessibleWidget::parent() const
 {
-    if (!m_pWindow)
-        return QAccessible::queryAccessibleInterface(nullptr);
-
     return QAccessible::queryAccessibleInterface(
-        new Qt5VclWindow(m_pWindow->GetAccessibleParentWindow()));
+        new 
Qt5XAccessible(m_xAccessible->getAccessibleContext()->getAccessibleParent()));
 }
 QAccessibleInterface* Qt5AccessibleWidget::child(int index) const
 {
-    if (!m_pWindow)
-        return QAccessible::queryAccessibleInterface(nullptr);
-
     return QAccessible::queryAccessibleInterface(
-        new Qt5VclWindow(m_pWindow->GetAccessibleChildWindow(index)));
+        new 
Qt5XAccessible(m_xAccessible->getAccessibleContext()->getAccessibleChild(index)));
 }
 
 QString Qt5AccessibleWidget::text(QAccessible::Text text) const
 {
-    if (!m_pWindow.get())
-        return QString();
-
-    SolarMutexGuard aSolarGuard;
-
     switch (text)
     {
         case QAccessible::Name:
-            return toQString(m_pWindow->GetAccessibleName());
+            return 
toQString(m_xAccessible->getAccessibleContext()->getAccessibleName());
         case QAccessible::Description:
         case QAccessible::DebugDescription:
-            return toQString(m_pWindow->GetAccessibleDescription());
+            return 
toQString(m_xAccessible->getAccessibleContext()->getAccessibleDescription());
         case QAccessible::Value:
         case QAccessible::Help:
         case QAccessible::Accelerator:
@@ -130,10 +107,10 @@ QString Qt5AccessibleWidget::text(QAccessible::Text text) 
const
 }
 QAccessible::Role Qt5AccessibleWidget::role() const
 {
-    if (!m_pWindow.get())
+    if (!m_xAccessible.is())
         return QAccessible::NoRole;
 
-    switch (m_pWindow->GetAccessibleRole())
+    switch (m_xAccessible->getAccessibleContext()->getAccessibleRole())
     {
         case AccessibleRole::UNKNOWN:
             return QAccessible::NoRole;
@@ -388,48 +365,12 @@ QAccessible::Role Qt5AccessibleWidget::role() const
          */
         case AccessibleRole::WINDOW: // top-level window without title bar
         {
-            SolarMutexGuard aSolarGuard;
-            WindowType type = WindowType::WINDOW;
-            bool parentIsMenuFloatingWindow = false;
-
-            vcl::Window* pParent = m_pWindow->GetParent();
-            if (pParent)
-            {
-                type = pParent->GetType();
-                parentIsMenuFloatingWindow = pParent->IsMenuFloatingWindow();
-            }
-
-            if ((WindowType::LISTBOX != type) && (WindowType::COMBOBOX != type)
-                && (WindowType::MENUBARWINDOW != type) && 
!parentIsMenuFloatingWindow)
-            {
-                return QAccessible::Window;
-            }
-        }
-            SAL_FALLTHROUGH;
-
-        default:
-        {
-            SolarMutexGuard aSolarGuard;
-            vcl::Window* pChild = 
m_pWindow->GetWindow(GetWindowType::FirstChild);
-            if (pChild)
-            {
-                if (WindowType::HELPTEXTWINDOW == pChild->GetType())
-                {
-                    return QAccessible::HelpBalloon;
-                }
-                else if (m_pWindow->GetType() == WindowType::BORDERWINDOW
-                         && pChild->GetType() == WindowType::FLOATINGWINDOW)
-                {
-                    PopupMenuFloatingWindow* p = 
dynamic_cast<PopupMenuFloatingWindow*>(pChild);
-                    if (p && p->IsPopupMenu() && p->GetMenuStackLevel() == 0)
-                    {
-                        return QAccessible::PopupMenu;
-                    }
-                }
-            }
-            break;
+            return QAccessible::Window;
         }
     }
+
+    SAL_WARN("vcl.qt5",
+             "Unmapped role: " << 
m_xAccessible->getAccessibleContext()->getAccessibleRole());
     return QAccessible::NoRole;
 }
 
@@ -470,10 +411,10 @@ void lcl_addState(QAccessible::State* state, sal_Int16 
nState)
             state->focused = true;
             break;
         case AccessibleStateType::HORIZONTAL:
-            //state->horizontal = true;
+            // No match
             break;
         case AccessibleStateType::ICONIFIED:
-            //state->iconified = true;
+            // No match
             break;
         case AccessibleStateType::INDETERMINATE:
             // No match
@@ -540,11 +481,10 @@ QAccessible::State Qt5AccessibleWidget::state() const
 {
     QAccessible::State state;
 
-    Reference<XAccessible> xAccessible(m_pWindow->GetAccessible());
-    if (!xAccessible.is())
+    if (!m_xAccessible.is())
         return state;
     Reference<XAccessibleStateSet> xStateSet(
-        xAccessible->getAccessibleContext()->getAccessibleStateSet());
+        m_xAccessible->getAccessibleContext()->getAccessibleStateSet());
 
     if (!xStateSet.is())
         return state;
@@ -561,11 +501,15 @@ QAccessible::State Qt5AccessibleWidget::state() const
 
 QColor Qt5AccessibleWidget::foregroundColor() const
 {
-    return toQColor(m_pWindow->GetControlForeground());
+    Reference<XAccessibleComponent> 
xAccessibleComponent(m_xAccessible->getAccessibleContext(),
+                                                         UNO_QUERY);
+    return toQColor(xAccessibleComponent->getForeground());
 }
 QColor Qt5AccessibleWidget::backgroundColor() const
 {
-    return toQColor(m_pWindow->GetControlBackground());
+    Reference<XAccessibleComponent> 
xAccessibleComponent(m_xAccessible->getAccessibleContext(),
+                                                         UNO_QUERY);
+    return toQColor(xAccessibleComponent->getBackground());
 }
 
 void* Qt5AccessibleWidget::interface_cast(QAccessible::InterfaceType /* t */)
@@ -592,31 +536,14 @@ QStringList 
Qt5AccessibleWidget::keyBindingsForAction(const QString& actionName)
     return QStringList();
 } */
 
-bool Qt5AccessibleWidget::isValid() const { return m_pWindow.get() != nullptr; 
}
+bool Qt5AccessibleWidget::isValid() const
+{
+    return m_xAccessible.is() && m_xAccessible->getAccessibleContext().is();
+}
 
 QObject* Qt5AccessibleWidget::object() const { return nullptr; }
 
-void Qt5AccessibleWidget::setText(QAccessible::Text t, const QString& text)
-{
-    if (!m_pWindow)
-        return;
-
-    switch (t)
-    {
-        case QAccessible::Name:
-            m_pWindow->SetAccessibleName(toOUString(text));
-            break;
-        case QAccessible::Description:
-        case QAccessible::DebugDescription:
-            m_pWindow->SetAccessibleDescription(toOUString(text));
-            break;
-        case QAccessible::Value:
-        case QAccessible::Help:
-        case QAccessible::Accelerator:
-        case QAccessible::UserText:
-            break;
-    }
-}
+void Qt5AccessibleWidget::setText(QAccessible::Text /* t */, const QString& /* 
text */) {}
 
 QAccessibleInterface* Qt5AccessibleWidget::childAt(int /* x */, int /* y */) 
const
 {
@@ -627,13 +554,16 @@ QAccessibleInterface* 
Qt5AccessibleWidget::customFactory(const QString& classnam
 {
     if (classname == QLatin1String("Qt5Widget") && object && 
object->isWidgetType())
     {
-        return new Qt5AccessibleWidget(static_cast<Qt5Widget*>(object),
-                                       
(static_cast<Qt5Widget*>(object))->m_pFrame->GetWindow());
+        Qt5Widget* pWidget = static_cast<Qt5Widget*>(object);
+        return new 
Qt5AccessibleWidget(pWidget->m_pFrame->GetWindow()->GetAccessible());
     }
-    if (classname == QLatin1String("Qt5VclWindow") && object)
+    if (classname == QLatin1String("Qt5XAccessible") && object)
     {
-        if (dynamic_cast<Qt5VclWindow*>(object) != nullptr)
-            return new 
Qt5AccessibleWidget((static_cast<Qt5VclWindow*>(object))->m_pWindow);
+        if (dynamic_cast<Qt5XAccessible*>(object) != nullptr)
+        {
+            Qt5XAccessible* pVclWindow = static_cast<Qt5XAccessible*>(object);
+            return new Qt5AccessibleWidget(pVclWindow->m_xAccessible);
+        }
     }
 
     return nullptr;
diff --git a/vcl/qt5/Qt5VclWindow.cxx b/vcl/qt5/Qt5XAccessible.cxx
similarity index 68%
rename from vcl/qt5/Qt5VclWindow.cxx
rename to vcl/qt5/Qt5XAccessible.cxx
index 0b89aba9d834..e9f0804d5061 100644
--- a/vcl/qt5/Qt5VclWindow.cxx
+++ b/vcl/qt5/Qt5XAccessible.cxx
@@ -7,19 +7,22 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <Qt5VclWindow.hxx>
-#include <Qt5VclWindow.moc>
+#include <Qt5XAccessible.hxx>
+#include <Qt5XAccessible.moc>
 
 #include <Qt5Frame.hxx>
 #include <Qt5Tools.hxx>
 #include <Qt5Widget.hxx>
 
+#include <com/sun/star/accessibility/XAccessible.hpp>
+
 #include <sal/log.hxx>
 
 using namespace css::accessibility;
+using namespace css::uno;
 
-Qt5VclWindow::Qt5VclWindow(vcl::Window* pWindow)
-    : m_pWindow(pWindow)
+Qt5XAccessible::Qt5XAccessible(Reference<XAccessible> xAccessible)
+    : m_xAccessible(xAccessible)
 {
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to