Port a11y integration to Qt5

REVIEW: 128350
parent cdc43d37
...@@ -68,8 +68,6 @@ add_definitions( ...@@ -68,8 +68,6 @@ add_definitions(
-Wno-deprecated-declarations -Wno-deprecated-declarations
) )
#TODO: this is temporarily disabled until it has been ported to Qt5
add_definitions(-DQT_NO_ACCESSIBILITY)
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ) include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} )
add_subdirectory( src ) add_subdirectory( src )
......
...@@ -295,7 +295,6 @@ void TerminalDisplay::setLineSpacing(uint i) ...@@ -295,7 +295,6 @@ void TerminalDisplay::setLineSpacing(uint i)
namespace Konsole namespace Konsole
{ {
#pragma message("The accessibility code needs proper porting to Qt5")
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
/** /**
* This function installs the factory function which lets Qt instantiate the QAccessibleInterface * This function installs the factory function which lets Qt instantiate the QAccessibleInterface
...@@ -1242,8 +1241,8 @@ void TerminalDisplay::updateImage() ...@@ -1242,8 +1241,8 @@ void TerminalDisplay::updateImage()
delete[] dirtyMask; delete[] dirtyMask;
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
QAccessible::updateAccessibility(this, 0, QAccessible::TextUpdated); QAccessible::updateAccessibility(new QAccessibleEvent(this, QAccessible::VisibleDataChanged));
QAccessible::updateAccessibility(this, 0, QAccessible::TextCaretMoved); QAccessible::updateAccessibility(new QAccessibleTextCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()));
#endif #endif
} }
...@@ -3080,7 +3079,7 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event) ...@@ -3080,7 +3079,7 @@ void TerminalDisplay::keyPressEvent(QKeyEvent* event)
emit keyPressedSignal(event); emit keyPressedSignal(event);
#ifndef QT_NO_ACCESSIBILITY #ifndef QT_NO_ACCESSIBILITY
QAccessible::updateAccessibility(this, 0, QAccessible::TextCaretMoved); QAccessible::updateAccessibility(new QAccessibleTextCursorEvent(this, _usedColumns * screenWindow()->screen()->getCursorY() + screenWindow()->screen()->getCursorX()));
#endif #endif
event->accept(); event->accept();
......
...@@ -20,32 +20,30 @@ ...@@ -20,32 +20,30 @@
*/ */
#include "TerminalDisplayAccessible.h" #include "TerminalDisplayAccessible.h"
#include "SessionController.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) #include <klocalizedstring.h>
QString Q_GUI_EXPORT qTextBeforeOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset, int* endOffset, const QString& text);
QString Q_GUI_EXPORT qTextAtOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset, int* endOffset, const QString& text);
QString Q_GUI_EXPORT qTextAfterOffsetFromString(int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset, int* endOffset, const QString& text);
using namespace Konsole; using namespace Konsole;
TerminalDisplayAccessible::TerminalDisplayAccessible(TerminalDisplay* display) TerminalDisplayAccessible::TerminalDisplayAccessible(TerminalDisplay* display)
: QAccessibleWidgetEx(display, : QAccessibleWidget(display, QAccessible::Terminal, display->sessionController()->userTitle())
QAccessible::Terminal {
) }
, QAccessibleSimpleEditableTextInterface(this)
{} QString TerminalDisplayAccessible::text(QAccessible::Text t) const
{
if (t == QAccessible::Value) {
return visibleText();
}
return QAccessibleWidget::text(t);
}
int TerminalDisplayAccessible::characterCount() int TerminalDisplayAccessible::characterCount() const
{ {
return display()->_usedLines * display()->_usedColumns; return display()->_usedLines * display()->_usedColumns;
} }
int TerminalDisplayAccessible::cursorPosition() int TerminalDisplayAccessible::cursorPosition() const
{ {
if (!display()->screenWindow()) if (!display()->screenWindow())
return 0; return 0;
...@@ -54,7 +52,7 @@ int TerminalDisplayAccessible::cursorPosition() ...@@ -54,7 +52,7 @@ int TerminalDisplayAccessible::cursorPosition()
return offset + display()->screenWindow()->screen()->getCursorX(); return offset + display()->screenWindow()->screen()->getCursorX();
} }
void TerminalDisplayAccessible::selection(int selectionIndex, int* startOffset, int* endOffset) void TerminalDisplayAccessible::selection(int selectionIndex, int* startOffset, int* endOffset) const
{ {
*startOffset = 0; *startOffset = 0;
*endOffset = 0; *endOffset = 0;
...@@ -73,7 +71,7 @@ void TerminalDisplayAccessible::selection(int selectionIndex, int* startOffset, ...@@ -73,7 +71,7 @@ void TerminalDisplayAccessible::selection(int selectionIndex, int* startOffset,
*endOffset = positionToOffset(endColumn, endLine); *endOffset = positionToOffset(endColumn, endLine);
} }
int TerminalDisplayAccessible::selectionCount() int TerminalDisplayAccessible::selectionCount() const
{ {
if (!display()->screenWindow()) if (!display()->screenWindow())
return 0; return 0;
...@@ -105,7 +103,7 @@ void TerminalDisplayAccessible::addSelection(int startOffset, int endOffset) ...@@ -105,7 +103,7 @@ void TerminalDisplayAccessible::addSelection(int startOffset, int endOffset)
display()->screenWindow()->setSelectionEnd(columnForOffset(endOffset), lineForOffset(endOffset)); display()->screenWindow()->setSelectionEnd(columnForOffset(endOffset), lineForOffset(endOffset));
} }
QString TerminalDisplayAccessible::attributes(int offset, int* startOffset, int* endOffset) QString TerminalDisplayAccessible::attributes(int offset, int* startOffset, int* endOffset) const
{ {
// FIXME: this function should return css like attributes // FIXME: this function should return css like attributes
// as defined in the web ARIA standard // as defined in the web ARIA standard
...@@ -115,21 +113,18 @@ QString TerminalDisplayAccessible::attributes(int offset, int* startOffset, int* ...@@ -115,21 +113,18 @@ QString TerminalDisplayAccessible::attributes(int offset, int* startOffset, int*
return QString(); return QString();
} }
QRect TerminalDisplayAccessible::characterRect(int offset, QAccessible2::CoordinateType coordType) QRect TerminalDisplayAccessible::characterRect(int offset) const
{ {
int row = offset / display()->_usedColumns; int row = offset / display()->_usedColumns;
int col = offset - row * display()->_usedColumns; int col = offset - row * display()->_usedColumns;
QPoint position = QPoint(col * display()->fontWidth() , row * display()->fontHeight()); QPoint position = QPoint(col * display()->fontWidth() , row * display()->fontHeight());
if(coordType == QAccessible2::RelativeToScreen)
position = display()->mapToGlobal(position);
return QRect(position, QSize(display()->fontWidth(), display()->fontHeight())); return QRect(position, QSize(display()->fontWidth(), display()->fontHeight()));
} }
int TerminalDisplayAccessible::offsetAtPoint(const QPoint& point, QAccessible2::CoordinateType coordType) int TerminalDisplayAccessible::offsetAtPoint(const QPoint& point) const
{ {
// FIXME return the offset into the text from the given point // FIXME return the offset into the text from the given point
Q_UNUSED(point) Q_UNUSED(point)
Q_UNUSED(coordType)
return 0; return 0;
} }
...@@ -155,6 +150,15 @@ void TerminalDisplayAccessible::setCursorPosition(int position) ...@@ -155,6 +150,15 @@ void TerminalDisplayAccessible::setCursorPosition(int position)
display()->screenWindow()->screen()->setCursorYX(lineForOffset(position), columnForOffset(position)); display()->screenWindow()->screen()->setCursorYX(lineForOffset(position), columnForOffset(position));
} }
void *TerminalDisplayAccessible::interface_cast(QAccessible::InterfaceType type)
{
if (type == QAccessible::TextInterface) {
return static_cast<QAccessibleTextInterface*>(this);
}
return QAccessibleWidget::interface_cast(type);
}
void TerminalDisplayAccessible::setSelection(int selectionIndex, int startOffset, int endOffset) void TerminalDisplayAccessible::setSelection(int selectionIndex, int startOffset, int endOffset)
{ {
if (selectionIndex) if (selectionIndex)
...@@ -162,44 +166,16 @@ void TerminalDisplayAccessible::setSelection(int selectionIndex, int startOffset ...@@ -162,44 +166,16 @@ void TerminalDisplayAccessible::setSelection(int selectionIndex, int startOffset
addSelection(startOffset, endOffset); addSelection(startOffset, endOffset);
} }
QString TerminalDisplayAccessible::text(QAccessible::Text t, int child) const QString TerminalDisplayAccessible::text(int startOffset, int endOffset) const
{
if (t == QAccessible::Value && child == 0)
return visibleText();
return QAccessibleWidgetEx::text(t, child);
}
QString TerminalDisplayAccessible::text(int startOffset, int endOffset)
{ {
if (!display()->screenWindow()) if (!display()->screenWindow()) {
return QString(); return QString();
}
return display()->screenWindow()->screen()->text(startOffset, endOffset, true); return display()->screenWindow()->screen()->text(startOffset, endOffset, true);
} }
QString TerminalDisplayAccessible::textAfterOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset) TerminalDisplay* TerminalDisplayAccessible::display() const
{
const QString text = visibleText();
return qTextAfterOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
}
QString TerminalDisplayAccessible::textAtOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset)
{ {
const QString text = visibleText(); return static_cast<TerminalDisplay*>(widget());
return qTextAtOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
} }
QString TerminalDisplayAccessible::textBeforeOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset)
{
const QString text = visibleText();
return qTextBeforeOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
}
TerminalDisplay* TerminalDisplayAccessible::display()
{
return static_cast<TerminalDisplay*>(object());
}
#else
#pragma message("This code needs proper porting to Qt5")
#endif
...@@ -22,13 +22,11 @@ ...@@ -22,13 +22,11 @@
#ifndef TERMINALDISPLAYACCESSIBLE_H #ifndef TERMINALDISPLAYACCESSIBLE_H
#define TERMINALDISPLAYACCESSIBLE_H #define TERMINALDISPLAYACCESSIBLE_H
#include <QtGlobal> //#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/qaccessible.h> #include <QtGui/QAccessibleTextInterface>
#include <QtGui/qaccessible2.h> #include <QtWidgets/QAccessibleWidget>
#include <qaccessiblewidget.h>
#include "TerminalDisplay.h" #include "TerminalDisplay.h"
#include "ScreenWindow.h" #include "ScreenWindow.h"
...@@ -42,49 +40,44 @@ namespace Konsole ...@@ -42,49 +40,44 @@ namespace Konsole
* *
* Most functions are re-implemented from QAccessibleTextInterface. * Most functions are re-implemented from QAccessibleTextInterface.
*/ */
class TerminalDisplayAccessible class TerminalDisplayAccessible : public QAccessibleWidget, public QAccessibleTextInterface
: public QAccessibleWidgetEx, public QAccessibleTextInterface, public QAccessibleSimpleEditableTextInterface
{ {
Q_ACCESSIBLE_OBJECT
public: public:
explicit TerminalDisplayAccessible(TerminalDisplay *display); explicit TerminalDisplayAccessible(TerminalDisplay *display);
QString text(QAccessible::Text t, int child) const; QString text(QAccessible::Text t) const override;
QString text(int startOffset, int endOffset) const override;
int characterCount() const override;
QString text(int startOffset, int endOffset); int selectionCount() const override;
QString textAfterOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset); void selection(int selectionIndex, int *startOffset, int *endOffset) const override;
QString textAtOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset); void addSelection(int startOffset, int endOffset) override;
QString textBeforeOffset(int offset, QAccessible2::BoundaryType boundaryType, int* startOffset, int* endOffset); void setSelection(int selectionIndex, int startOffset, int endOffset) override;
int characterCount(); void removeSelection(int selectionIndex) override;
int selectionCount(); QRect characterRect(int offset) const override;
void selection(int selectionIndex, int *startOffset, int *endOffset); int offsetAtPoint(const QPoint& point) const override;
void addSelection(int startOffset, int endOffset); void scrollToSubstring(int startIndex, int endIndex) override;
void setSelection(int selectionIndex, int startOffset, int endOffset);
void removeSelection(int selectionIndex);
QRect characterRect(int offset, QAccessible2::CoordinateType coordType); QString attributes(int offset, int* startOffset, int* endOffset) const override;
int offsetAtPoint(const QPoint& point, QAccessible2::CoordinateType coordType);
void scrollToSubstring(int startIndex, int endIndex);
QString attributes(int offset, int* startOffset, int* endOffset); int cursorPosition() const override;
void setCursorPosition(int position) override;
int cursorPosition(); void *interface_cast(QAccessible::InterfaceType type) override;
void setCursorPosition(int position);
private: private:
Konsole::TerminalDisplay *display(); Konsole::TerminalDisplay *display() const;
inline int positionToOffset(int column, int line) { inline int positionToOffset(int column, int line) const {
return line * display()->_usedColumns + column; return line * display()->_usedColumns + column;
} }
inline int lineForOffset(int offset) { inline int lineForOffset(int offset) const {
return offset / display()->_usedColumns; return offset / display()->_usedColumns;
} }
inline int columnForOffset(int offset) { inline int columnForOffset(int offset) const {
return offset % display()->_usedColumns; return offset % display()->_usedColumns;
} }
...@@ -93,8 +86,5 @@ private: ...@@ -93,8 +86,5 @@ private:
} // namespace } // namespace
#else
#pragma message("The accessibility code needs proper porting to Qt5")
#endif
#endif // TERMINALDISPLAYACCESSIBLE_H #endif // TERMINALDISPLAYACCESSIBLE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment