[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ktexteditor] src/view: Port Accessibility for KateView to Qt5
From:       Frederik Gladhorn <gladhorn () kde ! org>
Date:       2014-01-11 21:49:14
Message-ID: E1W26Qc-0002sE-8G () scm ! kde ! org
[Download RAW message or body]

Git commit 41418f2212af458b7e76fae25a299c8088675b99 by Frederik Gladhorn.
Committed on 11/01/2014 at 21:15.
Pushed by gladhorn into branch 'master'.

Port Accessibility for KateView to Qt5

Remove the cursor accessible as that is superceeded by the text
interface.

This brings the static text interface back, with accerciser the text is
visible, but changes are not yet reflected.

To test this is a bit tricky as a kde 5 session is required but that
means that the accessibility dbus is not available. I patched qtbase to
directly connect to the normal accessibility bus instead of trying to
use the session bus to find the other bus' address.

M  +26   -290  src/view/kateviewaccessible.h
M  +15   -17   src/view/kateviewinternal.cpp

http://commits.kde.org/ktexteditor/41418f2212af458b7e76fae25a299c8088675b99

diff --git a/src/view/kateviewaccessible.h b/src/view/kateviewaccessible.h
index bd3732c..98c7fd5 100644
--- a/src/view/kateviewaccessible.h
+++ b/src/view/kateviewaccessible.h
@@ -21,7 +21,6 @@
 #ifndef _KATE_VIEW_ACCESSIBLE_
 #define _KATE_VIEW_ACCESSIBLE_
 
-#if 0 // FIXME KF5
 #ifndef QT_NO_ACCESSIBILITY
 
 #include "kateviewinternal.h"
@@ -32,207 +31,29 @@
 #include <KLocalizedString>
 #include <QAccessibleWidget>
 
-QString Q_GUI_EXPORT qTextBeforeOffsetFromString(int offset, \
                QAccessible::TextBoundaryType boundaryType,
-        int *startOffset, int *endOffset, const QString &text);
-QString Q_GUI_EXPORT qTextAtOffsetFromString(int offset, \
                QAccessible::TextBoundaryType boundaryType,
-        int *startOffset, int *endOffset, const QString &text);
-QString Q_GUI_EXPORT qTextAfterOffsetFromString(int offset, \
                QAccessible::TextBoundaryType boundaryType,
-        int *startOffset, int *endOffset, const QString &text);
-
-/**
- * This class implements a QAccessible-interface for a Kate::TextCursor. An
- * instance of \a KateViewAccessible will hold an instance of this class to
- * provide access to the cursor within a kateview.
- *
- * To test the cursor positioning using kmagnifier from kdeaccessibility you
- * can do for example;
- * @code
- * export QT_ACCESSIBILITY=1
- * kmag &
- * kwrite &
- * @endcode
- * then press F2 in kmag to switch to the "Follow Focus Mode" and see that
- * the view follows the cursor in kwrite.
- */
-class KateCursorAccessible : public QAccessibleInterface
-{
-public:
-
-    enum { ChildId = 1 };
-
-    explicit KateCursorAccessible(KateViewInternal *view)
-        : QAccessibleInterface()
-        , m_view(view)
-    {
-    }
-
-    virtual ~KateCursorAccessible()
-    {
-    }
-
-    virtual QString actionText(int action, QAccessible::Text t, int) const
-    {
-        if (t == QAccessible::Name) {
-            switch (action) {
-            case 0: return i18n("Move To...");
-            case 1: return i18n("Move Left");
-            case 2: return i18n("Move Right");
-            case 3: return i18n("Move Up");
-            case 4: return i18n("Move Down");
-            default: break;
-            }
-        }
-        return QString();
-    }
-
-    virtual bool doAction(int action, int, const QVariantList &params = \
                QVariantList())
-    {
-        bool ok = true;
-        KTextEditor::Cursor c = m_view->getCursor();
-        switch (action) {
-        case 0: {
-            if (params.count() < 2) {
-                ok = false;
-            }
-            const int line = ok ? params[0].toInt(&ok) : 0;
-            const int column = ok ? params[1].toInt(&ok) : 0;
-            if (ok) {
-                c.setPosition(line, column);
-            }
-        } break;
-        case 1: c.setPosition(c.line(), c.column() - 1); break;
-        case 2: c.setPosition(c.line(), c.column() + 1); break;
-        case 3: c.setPosition(c.line() - 1, c.column()); break;
-        case 4: c.setPosition(c.line() + 1, c.column()); break;
-        default: ok = false; break;
-        }
-
-        return ok;
-    }
-
-    virtual int userActionCount(int) const
-    {
-        return 5;
-    }
-
-    virtual QAccessibleInterface *childAt(int, int) const
-    {
-        return 0;
-    }
-
-    virtual int childCount() const
-    {
-        return 0;
-    }
-
-    virtual int indexOfChild(const QAccessibleInterface *) const
-    {
-        return 0;
-    }
-
-    virtual bool isValid() const
-    {
-        KTextEditor::Cursor c = m_view->getCursor();
-        return c.isValid();
-    }
-
-    virtual int navigate(QAccessible::RelationFlag relation, int entry, \
                QAccessibleInterface **target) const
-    {
-        Q_UNUSED(relation);
-        Q_UNUSED(entry);
-        *target = 0;
-        return -1;
-    }
-
-    virtual QObject *object() const
-    {
-        return m_view;
-    }
-
-    virtual QRect rect() const
-    {
-        // return the exact position of the cursor with no width and height defined,
-        QPoint p = m_view->view()->cursorPositionCoordinates();
-        return QRect(m_view->mapToGlobal(p), QSize(0, 0));
-    }
-
-    virtual QAccessible::Relation relationTo(int child, const QAccessibleInterface \
                *other, int otherChild) const
-    {
-        Q_UNUSED(child);
-        Q_UNUSED(other);
-        Q_UNUSED(otherChild);
-        return QAccessible::AllRelations; // FIXME KF5: was ::Unrelated
-    }
-
-    virtual QAccessible::Role role() const Q_DECL_OVERRIDE
-    {
-        return QAccessible::Cursor;
-    }
-
-    virtual void setText(QAccessible::Text, const QString &)
-    {
-    }
-
-    virtual QAccessible::State state() const
-    {
-        QAccessible::State s;
-        s.focusable = 1;
-        s.focused = 1;
-        return s;
-    }
-
-    virtual QString text(QAccessible::Text) const
-    {
-        return QString();
-    }
-
-private:
-    KateViewInternal *m_view;
-};
-
 /**
  * This class implements a QAccessible-interface for a KateViewInternal.
  *
  * This is the root class for the kateview. The \a KateCursorAccessible class
  * represents the cursor in the kateview and is a child of this class.
  */
-class KateViewAccessible : public QAccessibleWidget, public \
QAccessibleTextInterface, public QAccessibleEditableTextInterface +class \
KateViewAccessible : public QAccessibleWidget, public QAccessibleTextInterface // \
FIXME maybe:, public QAccessibleEditableTextInterface  {
-    Q_ACCESSIBLE_OBJECT
-
 public:
     explicit KateViewAccessible(KateViewInternal *view)
-        : QAccessibleWidgetEx(view), QAccessibleEditableTextInterface(this)
-        , m_cursor(new KateCursorAccessible(view))
+        : QAccessibleWidget(view, QAccessible::EditableText)
     {
     }
 
-    virtual ~KateViewAccessible()
-    {
-    }
-
-    virtual QString actionText(int action, QAccessible::Text t, int child) const
+    void *interface_cast(QAccessible::InterfaceType t)
     {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->actionText(action, t, 0);
-        }
-        return QString();
-    }
-
-    virtual bool doAction(int action, int child, const QVariantList &params = \
                QVariantList())
-    {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->doAction(action, 0, params);
-        }
-        return false;
+        if (t == QAccessible::TextInterface)
+            return static_cast<QAccessibleTextInterface*>(this);
+        return 0;
     }
 
-    virtual int userActionCount(int child) const
+    virtual ~KateViewAccessible()
     {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->userActionCount(0);
-        }
-        return 0;
     }
 
     virtual QAccessibleInterface *childAt(int x, int y) const
@@ -242,79 +63,26 @@ public:
         return 0;
     }
 
-    virtual int childCount() const
-    {
-        return 1;
-    }
-
-    virtual int indexOfChild(const QAccessibleInterface *child) const
-    {
-        return dynamic_cast<const KateCursorAccessible *>(child) ? \
                KateCursorAccessible::ChildId : 0;
-    }
-
-    virtual int navigate(QAccessible::RelationFlag relation, int entry, \
                QAccessibleInterface **target) const
-    {
-        if ((relation == QAccessible::Child || QAccessible::FocusChild) && entry == \
                KateCursorAccessible::ChildId) {
-            *target = new KateCursorAccessible(view());
-            return KateCursorAccessible::ChildId;
-        }
-        *target = 0;
-        return -1;
-    }
-
-    virtual QRect rect(int child) const
+    virtual void setText(QAccessible::Text t, const QString &text)
     {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->rect(0);
-        }
-        return QRect(view()->mapToGlobal(QPoint(0, 0)), view()->size());
-    }
-
-    virtual QAccessible::Relation relationTo(int child, const QAccessibleInterface \
                *other, int otherChild) const
-    {
-        Q_UNUSED(child);
-        Q_UNUSED(other);
-        Q_UNUSED(otherChild);
-        return QAccessible::Unrelated;
-    }
-
-    virtual QAccessible::Role role() const
-    {
-        if (child == KateCursorAccessible::ChildId) {
-            return QAccessible::Cursor;
-        }
-        return QAccessible::EditableText;
-    }
-
-    virtual void setText(QAccessible::Text t, int child, const QString &text)
-    {
-        if (t == QAccessible::Value && child == 0 && view()->view()->document()) {
+        if (t == QAccessible::Value && view()->view()->document()) {
             view()->view()->document()->setText(text);
         }
     }
 
-    virtual QAccessible::State state(int child) const
+    virtual QAccessible::State state() const
     {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->state(0);
-        }
-
-        QAccessible::State s = QAccessibleWidgetEx::state(0);
-        s |= QAccessible::Focusable;
-
-        if (view()->hasFocus()) {
-            s |= QAccessible::Focused;
-        }
-
-        s |= QAccessible::HasInvokeExtension;
+        QAccessible::State s = QAccessibleWidget::state();
+        s.focusable = view()->focusPolicy() != Qt::NoFocus;
+        s.focused = view()->hasFocus();
+        s.editable = true;
+        s.multiLine = true;
+        s.selectableText = true;
         return s;
     }
 
-    virtual QString text(QAccessible::Text t, int child) const
+    virtual QString text(QAccessible::Text t) const
     {
-        if (child == KateCursorAccessible::ChildId) {
-            return m_cursor->text(t, 0);
-        }
         QString s;
         if (view()->view()->document()) {
             if (t == QAccessible::Name) {
@@ -327,7 +95,7 @@ public:
         return s;
     }
 
-    virtual int characterCount()
+    virtual int characterCount() const
     {
         return view()->view()->document()->text().size();
     }
@@ -340,14 +108,14 @@ public:
         view()->view()->setCursorPosition(cursorFromInt(endOffset));
     }
 
-    virtual QString attributes(int offset, int *startOffset, int *endOffset)
+    virtual QString attributes(int offset, int *startOffset, int *endOffset) const
     {
         Q_UNUSED(offset);
         *startOffset = 0;
         *endOffset = characterCount();
         return QString();
     }
-    virtual QRect characterRect(int offset)
+    virtual QRect characterRect(int offset) const
     {
         KTextEditor::Cursor c = cursorFromInt(offset);
         if (!c.isValid()) {
@@ -358,12 +126,12 @@ public:
         QPoint size = view()->view()->cursorToCoordinate(endCursor) - p;
         return QRect(view()->mapToGlobal(p), QSize(size.x(), size.y()));
     }
-    virtual int cursorPosition()
+    virtual int cursorPosition() const
     {
         KTextEditor::Cursor c = view()->getCursor();
         return positionFromCursor(c);
     }
-    virtual int offsetAtPoint(const QPoint & /*point*/)
+    virtual int offsetAtPoint(const QPoint & /*point*/) const
     {
         return 0;
     }
@@ -378,7 +146,7 @@ public:
     {
         // FIXME
     }
-    virtual void selection(int selectionIndex, int *startOffset, int *endOffset)
+    virtual void selection(int selectionIndex, int *startOffset, int *endOffset) \
const  {
         if (selectionIndex != 0 || !view()->view()->selection()) {
             *startOffset = 0;
@@ -390,7 +158,7 @@ public:
         *endOffset = positionFromCursor(range.end());
     }
 
-    virtual int selectionCount()
+    virtual int selectionCount() const
     {
         return view()->view()->selection() ? 1 : 0;
     }
@@ -406,7 +174,7 @@ public:
         KTextEditor::Range range = KTextEditor::Range(cursorFromInt(startOffset), \
cursorFromInt(endOffset));  view()->view()->setSelection(range);
     }
-    virtual QString text(int startOffset, int endOffset)
+    virtual QString text(int startOffset, int endOffset) const
     {
         if (startOffset > endOffset) {
             return QString();
@@ -414,34 +182,6 @@ public:
         return view()->view()->document()->text().mid(startOffset, endOffset - \
startOffset);  }
 
-    virtual QString textAfterOffset(int offset, QAccessible::TextBoundaryType \
                boundaryType, int *startOffset, int *endOffset)
-    {
-        if (boundaryType == QAccessible::LineBoundary) {
-            return textLine(1, offset + 1, startOffset, endOffset);
-        }
-
-        const QString text = view()->view()->document()->text();
-        return qTextAfterOffsetFromString(offset, boundaryType, startOffset, \
                endOffset, text);
-    }
-    virtual QString textAtOffset(int offset, QAccessible::TextBoundaryType \
                boundaryType, int *startOffset, int *endOffset)
-    {
-        if (boundaryType == QAccessible::LineBoundary) {
-            return textLine(0, offset, startOffset, endOffset);
-        }
-
-        const QString text = view()->view()->document()->text();
-        return qTextAtOffsetFromString(offset, boundaryType, startOffset, endOffset, \
                text);
-    }
-    virtual QString textBeforeOffset(int offset, QAccessible::TextBoundaryType \
                boundaryType, int *startOffset, int *endOffset)
-    {
-        if (boundaryType == QAccessible::LineBoundary) {
-            return textLine(-1, offset - 1, startOffset, endOffset);
-        }
-
-        const QString text = view()->view()->document()->text();
-        return qTextBeforeOffsetFromString(offset, boundaryType, startOffset, \
                endOffset, text);
-    }
-
 private:
     KateViewInternal *view() const
     {
@@ -484,12 +224,10 @@ private:
             pos.setLine(pos.line() + shiftLines);
         }
         *startOffset = positionFromCursor(pos);
-        QString line = view()->view()->document()->line(pos.line()) + '\n';
+        QString line = view()->view()->document()->line(pos.line()) + \
                QLatin1Char('\n');
         *endOffset = *startOffset + line.length();
         return line;
     }
-
-    KateCursorAccessible *m_cursor;
 };
 
 /**
@@ -508,5 +246,3 @@ QAccessibleInterface *accessibleInterfaceFactory(const QString \
&key, QObject *ob  
 #endif
 #endif
-
-#endif // FIXME KF5
diff --git a/src/view/kateviewinternal.cpp b/src/view/kateviewinternal.cpp
index f0b021f..abbb9a3 100644
--- a/src/view/kateviewinternal.cpp
+++ b/src/view/kateviewinternal.cpp
@@ -211,11 +211,9 @@ KateViewInternal::KateViewInternal(KateView *view)
     connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)),
             this, SLOT(viewSelectionChanged()));
 
-#if 0 //FIXME KF5
 #ifndef QT_NO_ACCESSIBILITY
     QAccessible::installFactory(accessibleInterfaceFactory);
 #endif
-#endif
 
     // update is called in KateView, after construction and layout is over
     // but before any other kateviewinternal call
@@ -228,12 +226,9 @@ KateViewInternal::~KateViewInternal()
         delete m_textAnimation;
     }
 
-#if 0 //FIXME KF5
-
 #ifndef QT_NO_ACCESSIBILITY
     QAccessible::removeFactory(accessibleInterfaceFactory);
 #endif
-#endif
 
     // kill preedit ranges
     delete m_imPreeditRange;
@@ -675,12 +670,9 @@ void KateViewInternal::makeVisible(const KTextEditor::Cursor &c, \
int endCol, boo  
     m_madeVisible = !force;
 
-#if 0 //FIXME KF5
-
 #ifndef QT_NO_ACCESSIBILITY
-    QAccessible::updateAccessibility(this, KateCursorAccessible::ChildId, \
                QAccessible::Focus);
-#endif
-
+    // FIXME -- is this needed?
+//    QAccessible::updateAccessibility(this, KateCursorAccessible::ChildId, \
QAccessible::Focus);  #endif
 
 }
@@ -1889,11 +1881,10 @@ void KateViewInternal::updateSelection(const \
KTextEditor::Cursor &_newCursor, bo  m_selectAnchor = KTextEditor::Cursor::invalid();
     }
 
-#if 0 //FIXME KF5
-
 #ifndef QT_NO_ACCESSIBILITY
-    QAccessible::updateAccessibility(this, 0, QAccessible::TextSelectionChanged);
-#endif
+//    FIXME KF5
+//    QAccessibleTextSelectionEvent ev(this, /* selection start, selection end*/);
+//    QAccessible::updateAccessibility(&ev);
 #endif
 }
 
@@ -3531,10 +3522,17 @@ void KateViewInternal::cursorMoved()
 {
     m_view->updateRangesIn(KTextEditor::Attribute::ActivateCaretIn);
 
-#if 0 //FIXME KF5
 #ifndef QT_NO_ACCESSIBILITY
-    QAccessible::updateAccessibility(this, 0, QAccessible::TextCaretMoved);
-#endif
+    if (QAccessible::isActive()) {
+        QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(this);
+        if (iface) {
+            QAccessibleTextInterface *textInterface = iface->textInterface();
+            if (textInterface) {
+                QAccessibleTextCursorEvent ev(this, \
textInterface->cursorPosition()); +                \
QAccessible::updateAccessibility(&ev); +            }
+        }
+    }
 #endif
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic