Accessibility: Make sure StaticText is marked read-only
Test more of the text properties. This is still very incomplete, but a small step forward. Also make sure that editable text reports the editable state. Fixes: QTBUG-75002 Change-Id: I9e43c980d8fa91671acb4e40e5d9162854884ee7 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
parent
3df8500859
commit
4a4842118d
|
@ -382,6 +382,22 @@ QString QAccessibleQuickItem::text(QAccessible::Text textType) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
void QAccessibleQuickItem::setText(QAccessible::Text textType, const QString &text)
|
||||
{
|
||||
if (role() != QAccessible::EditableText)
|
||||
return;
|
||||
if (textType != QAccessible::Value)
|
||||
return;
|
||||
|
||||
if (QTextDocument *doc = textDocument()) {
|
||||
doc->setPlainText(text);
|
||||
return;
|
||||
}
|
||||
auto textPropertyName = "text";
|
||||
if (object()->metaObject()->indexOfProperty(textPropertyName) >= 0)
|
||||
object()->setProperty(textPropertyName, text);
|
||||
}
|
||||
|
||||
void *QAccessibleQuickItem::interface_cast(QAccessible::InterfaceType t)
|
||||
{
|
||||
QAccessible::Role r = role();
|
||||
|
|
|
@ -83,6 +83,7 @@ public:
|
|||
QAccessible::State state() const override;
|
||||
QAccessible::Role role() const override;
|
||||
QString text(QAccessible::Text) const override;
|
||||
void setText(QAccessible::Text, const QString &text) override;
|
||||
|
||||
bool isAccessible() const;
|
||||
|
||||
|
|
|
@ -128,13 +128,19 @@ public:
|
|||
case QAccessible::Button:
|
||||
case QAccessible::MenuItem:
|
||||
case QAccessible::PageTab:
|
||||
case QAccessible::EditableText:
|
||||
case QAccessible::SpinBox:
|
||||
case QAccessible::ComboBox:
|
||||
case QAccessible::Terminal:
|
||||
case QAccessible::ScrollBar:
|
||||
m_state.focusable = true;
|
||||
break;
|
||||
case QAccessible::EditableText:
|
||||
m_state.editable = true;
|
||||
m_state.focusable = true;
|
||||
break;
|
||||
case QAccessible::StaticText:
|
||||
m_state.readOnly = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -28,4 +28,22 @@ Item {
|
|||
Accessible.name: "The Hello 2 accessible text"
|
||||
Accessible.description: "A text description"
|
||||
}
|
||||
|
||||
TextInput {
|
||||
x: 100
|
||||
y: 80
|
||||
width: 200
|
||||
height: 40
|
||||
text: "A text input"
|
||||
Accessible.role: Accessible.EditableText
|
||||
}
|
||||
|
||||
TextEdit {
|
||||
x: 100
|
||||
y: 120
|
||||
width: 200
|
||||
height: 100
|
||||
text: "A multi-line text edit\nTesting Accessibility."
|
||||
Accessible.role: Accessible.EditableText
|
||||
}
|
||||
}
|
|
@ -130,7 +130,7 @@ void tst_QQuickAccessible::commonTests_data()
|
|||
{
|
||||
QTest::addColumn<QString>("accessibleRoleFileName");
|
||||
|
||||
QTest::newRow("StaticText") << "statictext.qml";
|
||||
QTest::newRow("Text") << "text.qml";
|
||||
QTest::newRow("PushButton") << "pushbutton.qml";
|
||||
}
|
||||
|
||||
|
@ -302,7 +302,7 @@ void tst_QQuickAccessible::basicPropertiesTest()
|
|||
QCOMPARE(app->childCount(), 0);
|
||||
|
||||
QQuickView *window = new QQuickView();
|
||||
window->setSource(testFileUrl("statictext.qml"));
|
||||
window->setSource(testFileUrl("text.qml"));
|
||||
window->show();
|
||||
QCOMPARE(app->childCount(), 1);
|
||||
|
||||
|
@ -312,7 +312,7 @@ void tst_QQuickAccessible::basicPropertiesTest()
|
|||
|
||||
QAccessibleInterface *item = iface->child(0);
|
||||
QVERIFY(item);
|
||||
QCOMPARE(item->childCount(), 2);
|
||||
QCOMPARE(item->childCount(), 4);
|
||||
QCOMPARE(item->rect().size(), QSize(400, 400));
|
||||
QCOMPARE(item->role(), QAccessible::Client);
|
||||
QCOMPARE(iface->indexOfChild(item), 0);
|
||||
|
@ -338,10 +338,50 @@ void tst_QQuickAccessible::basicPropertiesTest()
|
|||
QCOMPARE(text2->rect().y(), item->rect().y() + 40);
|
||||
QCOMPARE(text2->role(), QAccessible::StaticText);
|
||||
QCOMPARE(item->indexOfChild(text2), 1);
|
||||
QCOMPARE(text2->state().editable, 0);
|
||||
QCOMPARE(text2->state().readOnly, 1);
|
||||
|
||||
QCOMPARE(iface->indexOfChild(text2), -1);
|
||||
QCOMPARE(text2->indexOfChild(item), -1);
|
||||
|
||||
// TextInput
|
||||
QAccessibleInterface *textInput = item->child(2);
|
||||
QVERIFY(textInput);
|
||||
QCOMPARE(textInput->childCount(), 0);
|
||||
QCOMPARE(textInput->role(), QAccessible::EditableText);
|
||||
QCOMPARE(textInput->state().editable, 1);
|
||||
QCOMPARE(textInput->state().readOnly, 0);
|
||||
QCOMPARE(textInput->state().multiLine, 0);
|
||||
QCOMPARE(textInput->state().focusable, 1);
|
||||
QCOMPARE(textInput->text(QAccessible::Value), "A text input");
|
||||
auto textInterface = textInput->textInterface();
|
||||
QVERIFY(textInterface);
|
||||
auto editableTextInterface = textInput->editableTextInterface();
|
||||
QEXPECT_FAIL("", "EditableTextInterface is not implemented", Continue);
|
||||
QVERIFY(editableTextInterface);
|
||||
auto newText = QString("a new text");
|
||||
textInput->setText(QAccessible::Value, newText);
|
||||
QCOMPARE(textInput->text(QAccessible::Value), newText);
|
||||
|
||||
// TextEdit
|
||||
QAccessibleInterface *textEdit = item->child(3);
|
||||
QVERIFY(textEdit);
|
||||
QCOMPARE(textEdit->childCount(), 0);
|
||||
QCOMPARE(textEdit->role(), QAccessible::EditableText);
|
||||
QCOMPARE(textEdit->state().editable, 1);
|
||||
QCOMPARE(textEdit->state().readOnly, 0);
|
||||
QCOMPARE(textEdit->state().focusable, 1);
|
||||
QCOMPARE(textEdit->text(QAccessible::Value), "A multi-line text edit\nTesting Accessibility.");
|
||||
auto textEditTextInterface = textEdit->textInterface();
|
||||
QVERIFY(textEditTextInterface);
|
||||
auto textEditEditableTextInterface = textEdit->editableTextInterface();
|
||||
QEXPECT_FAIL("", "EditableTextInterface is not implemented", Continue);
|
||||
QVERIFY(textEditEditableTextInterface);
|
||||
textEdit->setText(QAccessible::Value, newText);
|
||||
QCOMPARE(textEdit->text(QAccessible::Value), newText);
|
||||
QEXPECT_FAIL("", "multi line is not implemented", Continue);
|
||||
QCOMPARE(textInput->state().multiLine, 1);
|
||||
|
||||
delete window;
|
||||
QTestAccessibility::clearEvents();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue