summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-03-18 17:20:23 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-20 12:49:33 +0100
commitb8c96f2eb9f0cb1a5ffa8bfd3ab89f53f8e8badd (patch)
tree4caef2bb8caeb8aa685635f6abfa57ca6a6a7497
parent200cc1f1e9aded9fb891e9af0699887c04a465a2 (diff)
Accessibility: Improve QTextEdit
EditableTextInterface was implemented but not reported to the accessibility bridges. Newlines in QTextEdit when using QCursor::selectedText are returned as unicode paragraphs, replace them by newlines. [ChangeLog][QtWidgets][Accessibility] Fixed QTextEdit not reporting newlines to accessibility frameworks and add editable text interface. Change-Id: Iac21e70f5468a16f8abf242ae148290dbab3f8e4 Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
-rw-r--r--src/plugins/accessible/widgets/qaccessiblewidgets.cpp6
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp47
2 files changed, 38 insertions, 15 deletions
diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
index 71d22eabc4..b502682938 100644
--- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
@@ -144,6 +144,8 @@ void *QAccessiblePlainTextEdit::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::TextInterface)
return static_cast<QAccessibleTextInterface*>(this);
+ else if (t == QAccessible::EditableTextInterface)
+ return static_cast<QAccessibleEditableTextInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
@@ -268,6 +270,8 @@ void *QAccessibleTextEdit::interface_cast(QAccessible::InterfaceType t)
{
if (t == QAccessible::TextInterface)
return static_cast<QAccessibleTextInterface*>(this);
+ else if (t == QAccessible::EditableTextInterface)
+ return static_cast<QAccessibleEditableTextInterface*>(this);
return QAccessibleWidget::interface_cast(t);
}
@@ -830,7 +834,7 @@ QString QAccessibleTextWidget::text(int startOffset, int endOffset) const
cursor.setPosition(startOffset, QTextCursor::MoveAnchor);
cursor.setPosition(endOffset, QTextCursor::KeepAnchor);
- return cursor.selectedText();
+ return cursor.selectedText().replace(QChar(QChar::ParagraphSeparator), QLatin1Char('\n'));
}
QPoint QAccessibleTextWidget::scrollBarPosition() const
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index 53f74d091b..2bf8a40451 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -1650,30 +1650,33 @@ void tst_QAccessibility::textEditTest()
QTest::qWaitForWindowShown(&edit);
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&edit);
QCOMPARE(iface->text(QAccessible::Value), edit.toPlainText());
- QCOMPARE(iface->textInterface()->textAtOffset(8, QAccessible::WordBoundary, &startOffset, &endOffset), QString("world"));
+ QAccessibleTextInterface *textIface = iface->textInterface();
+ QVERIFY(textIface);
+
+ QCOMPARE(textIface->textAtOffset(8, QAccessible::WordBoundary, &startOffset, &endOffset), QString("world"));
QCOMPARE(startOffset, 6);
QCOMPARE(endOffset, 11);
- QCOMPARE(iface->textInterface()->textAtOffset(15, QAccessible::LineBoundary, &startOffset, &endOffset), QString("How are you today?"));
+ QCOMPARE(textIface->textAtOffset(15, QAccessible::LineBoundary, &startOffset, &endOffset), QString("How are you today?"));
QCOMPARE(startOffset, 13);
QCOMPARE(endOffset, 31);
- QCOMPARE(iface->textInterface()->characterCount(), 48);
+ QCOMPARE(textIface->characterCount(), 48);
QFontMetrics fm(edit.currentFont());
- QCOMPARE(iface->textInterface()->characterRect(0).size(), QSize(fm.width("h"), fm.height()));
- QCOMPARE(iface->textInterface()->characterRect(5).size(), QSize(fm.width(" "), fm.height()));
- QCOMPARE(iface->textInterface()->characterRect(6).size(), QSize(fm.width("w"), fm.height()));
+ QCOMPARE(textIface->characterRect(0).size(), QSize(fm.width("h"), fm.height()));
+ QCOMPARE(textIface->characterRect(5).size(), QSize(fm.width(" "), fm.height()));
+ QCOMPARE(textIface->characterRect(6).size(), QSize(fm.width("w"), fm.height()));
int offset = 10;
- QCOMPARE(iface->textInterface()->text(offset, offset + 1), QStringLiteral("d"));
- QVERIFY(fuzzyRectCompare(iface->textInterface()->characterRect(offset), characterRect(edit, offset)));
+ QCOMPARE(textIface->text(offset, offset + 1), QStringLiteral("d"));
+ QVERIFY(fuzzyRectCompare(textIface->characterRect(offset), characterRect(edit, offset)));
offset = 13;
- QCOMPARE(iface->textInterface()->text(offset, offset + 1), QStringLiteral("H"));
- QVERIFY(fuzzyRectCompare(iface->textInterface()->characterRect(offset), characterRect(edit, offset)));
+ QCOMPARE(textIface->text(offset, offset + 1), QStringLiteral("H"));
+ QVERIFY(fuzzyRectCompare(textIface->characterRect(offset), characterRect(edit, offset)));
offset = 21;
- QCOMPARE(iface->textInterface()->text(offset, offset + 1), QStringLiteral("y"));
- QVERIFY(fuzzyRectCompare(iface->textInterface()->characterRect(offset), characterRect(edit, offset)));
+ QCOMPARE(textIface->text(offset, offset + 1), QStringLiteral("y"));
+ QVERIFY(fuzzyRectCompare(textIface->characterRect(offset), characterRect(edit, offset)));
offset = 32;
- QCOMPARE(iface->textInterface()->text(offset, offset + 1), QStringLiteral("I"));
- QVERIFY(fuzzyRectCompare(iface->textInterface()->characterRect(offset), characterRect(edit, offset)));
+ QCOMPARE(textIface->text(offset, offset + 1), QStringLiteral("I"));
+ QVERIFY(fuzzyRectCompare(textIface->characterRect(offset), characterRect(edit, offset)));
QTestAccessibility::clearEvents();
@@ -1692,6 +1695,22 @@ void tst_QAccessibility::textEditTest()
sel.setCursorPosition(end);
sel.setSelection(0, end);
QVERIFY_EVENT(&sel);
+
+ // check that we have newlines handled
+ QString poem = QStringLiteral("Once upon a midnight dreary,\nwhile I pondered, weak and weary,\nOver many a quaint and curious volume of forgotten lore\n");
+ QAccessibleEditableTextInterface *editableTextIface = iface->editableTextInterface();
+ QVERIFY(editableTextIface);
+ editableTextIface->replaceText(0, end, poem);
+ QCOMPARE(iface->text(QAccessible::Value), poem);
+ QCOMPARE(textIface->text(0, poem.size()), poem);
+ QCOMPARE(textIface->text(28, 29), QLatin1String("\n"));
+ int start;
+ QCOMPARE(textIface->textAtOffset(42, QAccessible::LineBoundary, &start, &end), QStringLiteral("while I pondered, weak and weary,"));
+ QCOMPARE(start, 29);
+ QCOMPARE(end, 62);
+ QCOMPARE(textIface->textAtOffset(28, QAccessible::CharBoundary, &start, &end), QLatin1String("\n"));
+ QCOMPARE(start, 28);
+ QCOMPARE(end, 29);
}
QTestAccessibility::clearEvents();
}