AcceleratorChanged = 0x80C0
};
-
- enum StateFlag {
- Normal = 0x00000000,
- Unavailable = 0x00000001,
- Selected = 0x00000002,
- Focused = 0x00000004,
- Pressed = 0x00000008,
- Checked = 0x00000010,
- Mixed = 0x00000020,
- ReadOnly = 0x00000040,
- HotTracked = 0x00000080,
- DefaultButton = 0x00000100,
- Expanded = 0x00000200,
- Collapsed = 0x00000400,
- Busy = 0x00000800,
- // Floating = 0x00001000,
- Expandable = 0x00001000,
- Marqueed = 0x00002000,
- Animated = 0x00004000,
- Invisible = 0x00008000,
- Offscreen = 0x00010000,
- Sizeable = 0x00020000,
- Movable = 0x00040000,
- SelfVoicing = 0x00080000,
- Focusable = 0x00100000,
- Selectable = 0x00200000,
- Linked = 0x00400000,
- Traversed = 0x00800000,
- MultiSelectable = 0x01000000,
- ExtSelectable = 0x02000000,
- //AlertLow = 0x04000000,
- //AlertMedium = 0x08000000,
- //AlertHigh = 0x10000000, /* reused for HasInvokeExtension */
- Protected = 0x20000000,
- HasPopup = 0x40000000,
- Modal = 0x80000000
-
+ // 64 bit enums seem hard on some platforms (windows...)
+ // which makes using a bit field a sensible alternative
+ struct State {
+ quint64 unavailable : 1;
+ quint64 selected : 1;
+ quint64 focused : 1;
+ quint64 pressed : 1;
+ quint64 checked : 1;
+ quint64 mixed : 1;
+ quint64 readOnly : 1;
+ quint64 hotTracked : 1;
+ quint64 defaultButton : 1;
+ quint64 expanded : 1;
+ quint64 collapsed : 1;
+ quint64 busy : 1;
+ // quint64 Floating : 1;
+ quint64 expandable : 1;
+ quint64 marqueed : 1;
+ quint64 animated : 1;
+ quint64 invisible : 1;
+ quint64 offscreen : 1;
+ quint64 sizeable : 1;
+ quint64 movable : 1;
+ quint64 selfVoicing : 1;
+ quint64 focusable : 1;
+ quint64 selectable : 1;
+ quint64 linked : 1;
+ quint64 traversed : 1;
+ quint64 multiSelectable : 1;
+ quint64 extSelectable : 1;
+ // quint64 alertLow : 1;
+ // quint64 alertMedium : 1;
+ // quint64 alertHigh : 1;
+ quint64 passwordEdit : 1;
+ quint64 hasPopup : 1;
+ quint64 modal : 1;
+
+ State() {
+ qMemSet(this, 0, sizeof(State));
+ }
};
- Q_DECLARE_FLAGS(State, StateFlag)
-
enum Role {
NoRole = 0x00000000,
QAccessible() {}
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::State)
+Q_GUI_EXPORT bool operator==(const QAccessible::State &first, const QAccessible::State &second);
+
Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
QT_END_NAMESPACE
Q_DECLARE_METATYPE(QSet<QAccessible::Method>)
virtual QRect rect() const = 0;
virtual QAccessible::Role role() const = 0;
virtual QAccessible::State state() const = 0;
- // FIXME virtual QSet<QAccessible::State> states() const = 0;
virtual QColor foregroundColor() const;
virtual QColor backgroundColor() const;
void customWidget();
void deletedWidget();
+ void statesStructTest();
void navigateHierarchy();
void sliderTest();
void navigateCovered();
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget);
if (!iface)
qWarning() << "Cannot get QAccessibleInterface for widget";
- QAccessible::State state = (iface ? iface->state() : static_cast<QAccessible::State>(0));
+ QAccessible::State state = (iface ? iface->state() : QAccessible::State());
delete iface;
return state;
}
delete iface;
}
+void tst_QAccessibility::statesStructTest()
+{
+ QAccessible::State s1;
+ QVERIFY(s1.unavailable == 0);
+ QVERIFY(s1.focusable == 0);
+ QVERIFY(s1.modal == 0);
+
+ QAccessible::State s2;
+ QVERIFY(s2 == s1);
+ s2.busy = true;
+ QVERIFY(!(s2 == s1));
+ s1.busy = true;
+ QVERIFY(s2 == s1);
+ s1 = QAccessible::State();
+ QVERIFY(!(s2 == s1));
+ s1 = s2;
+ QVERIFY(s2 == s1);
+ QVERIFY(s1.busy == 1);
+}
+
void tst_QAccessibility::sliderTest()
{
{
w1->raise();
QVERIFY(iface1->relationTo(iface2) & QAccessible::Covers);
QVERIFY(iface2->relationTo(iface1) & QAccessible::Covered);
- QVERIFY(!(iface1->state() & QAccessible::Invisible));
+ QVERIFY(!iface1->state().invisible);
w1->hide();
- QVERIFY(iface1->state() & QAccessible::Invisible);
+ QVERIFY(iface1->state().invisible);
QVERIFY(!(iface1->relationTo(iface2) & QAccessible::Covers));
QVERIFY(!(iface2->relationTo(iface1) & QAccessible::Covered));
QCOMPARE(iface2->navigate(QAccessible::Covered, 1, &iface3), -1);
QWidget * const window = new QWidget();
QWidget * const child = new QWidget(window);
- QVERIFY(state(window) & QAccessible::Invisible);
- QVERIFY(state(child) & QAccessible::Invisible);
+ QVERIFY(state(window).invisible);
+ QVERIFY(state(child).invisible);
QTestAccessibility::clearEvents();
// show() and veryfy that both window and child are not invisible and get ObjectShow events.
window->show();
- QVERIFY(state(window) ^ QAccessible::Invisible);
- QVERIFY(state(child) ^ QAccessible::Invisible);
+ QVERIFY(!state(window).invisible);
+ QVERIFY(!state(child).invisible);
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, 0, QAccessible::ObjectShow)));
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, 0, QAccessible::ObjectShow)));
QTestAccessibility::clearEvents();
// hide() and veryfy that both window and child are invisible and get ObjectHide events.
window->hide();
- QVERIFY(state(window) & QAccessible::Invisible);
- QVERIFY(state(child) & QAccessible::Invisible);
+ QVERIFY(state(window).invisible);
+ QVERIFY(state(child).invisible);
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(window, 0, QAccessible::ObjectHide)));
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(child, 0, QAccessible::ObjectHide)));
QTestAccessibility::clearEvents();
QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction());
QCOMPARE(actionInterface->localizedActionDescription(QAccessibleActionInterface::checkAction()), QString("Checks the checkbox"));
QVERIFY(!toggleButton.isChecked());
- QVERIFY((interface->state() & QAccessible::Checked) == 0);
+ QVERIFY(!interface->state().checked);
actionInterface->doAction(QAccessibleActionInterface::checkAction());
QTest::qWait(500);
QVERIFY(toggleButton.isChecked());
QCOMPARE(actionInterface->actionNames().at(0), QAccessibleActionInterface::uncheckAction());
- QVERIFY(interface->state() & QAccessible::Checked);
+ QVERIFY(interface->state().checked);
delete interface;
{
menuButton.show();
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&menuButton);
QCOMPARE(interface->role(), QAccessible::ButtonMenu);
- QVERIFY(interface->state() & QAccessible::HasPopup);
+ QVERIFY(interface->state().hasPopup);
QCOMPARE(interface->actionInterface()->actionNames(), QStringList() << QAccessibleActionInterface::showMenuAction() << QAccessibleActionInterface::setFocusAction());
// showing the menu enters a new event loop...
// interface->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction());
actionInterface = interface->actionInterface();
QCOMPARE(interface->role(), QAccessible::CheckBox);
QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction());
- QVERIFY((interface->state() & QAccessible::Checked) == 0);
+ QVERIFY(!interface->state().checked);
actionInterface->doAction(QAccessibleActionInterface::checkAction());
QTest::qWait(500);
QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::uncheckAction() << QAccessibleActionInterface::setFocusAction());
- QVERIFY(interface->state() & QAccessible::Checked);
+ QVERIFY(interface->state().checked);
QVERIFY(checkBox.isChecked());
delete interface;
actionInterface = interface->actionInterface();
QCOMPARE(interface->role(), QAccessible::RadioButton);
QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction());
- QVERIFY((interface->state() & QAccessible::Checked) == 0);
+ QVERIFY(!interface->state().checked);
actionInterface->doAction(QAccessibleActionInterface::checkAction());
QTest::qWait(500);
QCOMPARE(actionInterface->actionNames(), QStringList() << QAccessibleActionInterface::checkAction() << QAccessibleActionInterface::setFocusAction());
- QVERIFY(interface->state() & QAccessible::Checked);
+ QVERIFY(interface->state().checked);
QVERIFY(checkBox.isChecked());
delete interface;
QScrollBar *scrollBar = new QScrollBar(Qt::Horizontal);
QAccessibleInterface * const scrollBarInterface = QAccessible::queryAccessibleInterface(scrollBar);
QVERIFY(scrollBarInterface);
- QVERIFY(scrollBarInterface->state() & QAccessible::Invisible);
+ QVERIFY(scrollBarInterface->state().invisible);
scrollBar->resize(200, 50);
scrollBar->show();
- QVERIFY(scrollBarInterface->state() ^ QAccessible::Invisible);
+ QVERIFY(!scrollBarInterface->state().invisible);
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectShow)));
QTestAccessibility::clearEvents();
scrollBar->hide();
- QVERIFY(scrollBarInterface->state() & QAccessible::Invisible);
+ QVERIFY(scrollBarInterface->state().invisible);
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectHide)));
QTestAccessibility::clearEvents();
// and cleared correctly.
QAccessibleInterface *leftButton = interface->child(0);
QCOMPARE(leftButton->role(), QAccessible::PushButton);
- QVERIFY(leftButton->state() & QAccessible::Invisible);
+ QVERIFY(leftButton->state().invisible);
delete leftButton;
const int lots = 5;
QVERIFY(child2);
QCOMPARE(child2->role(), QAccessible::PageTab);
- QVERIFY((child1->state() & QAccessible::Invisible) == false);
+ QVERIFY((child1->state().invisible) == false);
tabBar->hide();
QCoreApplication::processEvents();
QTest::qWait(100);
- QVERIFY(child1->state() & QAccessible::Invisible);
+ QVERIFY(child1->state().invisible);
tabBar->show();
tabBar->setCurrentIndex(0);
mdiArea.setActiveSubWindow(testWindow);
// state
- QAccessible::State state = QAccessible::Normal | QAccessible::Focusable | QAccessible::Focused
- | QAccessible::Movable | QAccessible::Sizeable;
+ QAccessible::State state;
+ state.focusable = true;
+ state.focused = true;
+ state.movable = true;
+ state.sizeable = true;
+
QCOMPARE(interface->state(), state);
const QRect originalGeometry = testWindow->geometry();
testWindow->showMaximized();
- state &= (uint)~QAccessible::Sizeable;
- state &= (uint)~QAccessible::Movable;
+ state.sizeable = false;
+ state.movable = false;
QCOMPARE(interface->state(), state);
testWindow->showNormal();
testWindow->move(-10, 0);
- QVERIFY(interface->state() & QAccessible::Offscreen);
+ QVERIFY(interface->state().offscreen);
testWindow->setVisible(false);
- QVERIFY(interface->state() & QAccessible::Invisible);
+ QVERIFY(interface->state().invisible);
testWindow->setVisible(true);
testWindow->setEnabled(false);
- QVERIFY(interface->state() & QAccessible::Unavailable);
+ QVERIFY(interface->state().unavailable);
testWindow->setEnabled(true);
qApp->setActiveWindow(&mdiArea);
mdiArea.setActiveSubWindow(testWindow);
testWindow->setFocus();
QVERIFY(testWindow->isAncestorOf(qApp->focusWidget()));
- QVERIFY(interface->state() & QAccessible::Focused);
+ QVERIFY(interface->state().focused);
testWindow->setGeometry(originalGeometry);
if (isSubWindowsPlacedNextToEachOther) {
QApplication::processEvents();
QCOMPARE(iface->childCount(), 0);
- QVERIFY(iface->state() & QAccessible::Sizeable);
- QVERIFY(iface->state() & QAccessible::Movable);
- QCOMPARE(bool(iface->state() & QAccessible::Focusable), le->isActiveWindow());
- QVERIFY(iface->state() & QAccessible::Selectable);
- QVERIFY(iface->state() & QAccessible::HasPopup);
- QCOMPARE(bool(iface->state() & QAccessible::Focused), le->hasFocus());
+ QVERIFY(iface->state().sizeable);
+ QVERIFY(iface->state().movable);
+ QCOMPARE(bool(iface->state().focusable), le->isActiveWindow());
+ QVERIFY(iface->state().selectable);
+ QVERIFY(iface->state().hasPopup);
+ QCOMPARE(bool(iface->state().focused), le->hasFocus());
QString secret(QLatin1String("secret"));
le->setText(secret);
le->setEchoMode(QLineEdit::Normal);
- QVERIFY(!(iface->state() & QAccessible::Protected));
+ QVERIFY(!(iface->state().passwordEdit));
QCOMPARE(iface->text(QAccessible::Value), secret);
le->setEchoMode(QLineEdit::NoEcho);
- QVERIFY(iface->state() & QAccessible::Protected);
+ QVERIFY(iface->state().passwordEdit);
QVERIFY(iface->text(QAccessible::Value).isEmpty());
le->setEchoMode(QLineEdit::Password);
- QVERIFY(iface->state() & QAccessible::Protected);
+ QVERIFY(iface->state().passwordEdit);
QVERIFY(iface->text(QAccessible::Value).isEmpty());
le->setEchoMode(QLineEdit::PasswordEchoOnEdit);
- QVERIFY(iface->state() & QAccessible::Protected);
+ QVERIFY(iface->state().passwordEdit);
QVERIFY(iface->text(QAccessible::Value).isEmpty());
le->setEchoMode(QLineEdit::Normal);
- QVERIFY(!(iface->state() & QAccessible::Protected));
+ QVERIFY(!(iface->state().passwordEdit));
QCOMPARE(iface->text(QAccessible::Value), secret);
QWidget *toplevel = new QWidget;
le->setParent(toplevel);
toplevel->show();
QApplication::processEvents();
- QVERIFY(!(iface->state() & QAccessible::Sizeable));
- QVERIFY(!(iface->state() & QAccessible::Movable));
- QCOMPARE(bool(iface->state() & QAccessible::Focusable), le->isActiveWindow());
- QVERIFY(iface->state() & QAccessible::Selectable);
- QVERIFY(iface->state() & QAccessible::HasPopup);
- QCOMPARE(bool(iface->state() & QAccessible::Focused), le->hasFocus());
+ QVERIFY(!(iface->state().sizeable));
+ QVERIFY(!(iface->state().movable));
+ QCOMPARE(bool(iface->state().focusable), le->isActiveWindow());
+ QVERIFY(iface->state().selectable);
+ QVERIFY(iface->state().hasPopup);
+ QCOMPARE(bool(iface->state().focused), le->hasFocus());
QLineEdit *le2 = new QLineEdit(toplevel);
le2->show();
QCOMPARE(QAIPtr(cellInterface->table())->object(), listView);
listView->clearSelection();
- QVERIFY(!(cell4->state() & QAccessible::Expandable));
- QVERIFY( (cell4->state() & QAccessible::Selectable));
- QVERIFY(!(cell4->state() & QAccessible::Selected));
+ QVERIFY(!(cell4->state().expandable));
+ QVERIFY( (cell4->state().selectable));
+ QVERIFY(!(cell4->state().selected));
table2->selectRow(3);
QCOMPARE(listView->selectedItems().size(), 1);
QCOMPARE(listView->selectedItems().at(0)->text(), QLatin1String("Munich"));
- QVERIFY(cell4->state() & QAccessible::Selected);
+ QVERIFY(cell4->state().selected);
QVERIFY(cellInterface->isSelected());
QVERIFY(table2->cellAt(-1, 0) == 0);
QCOMPARE(iface->indexOfChild(child1), 3);
QCOMPARE(child1->text(QAccessible::Name), QString("Spain"));
QCOMPARE(child1->role(), QAccessible::TreeItem);
- QVERIFY(!(child1->state() & QAccessible::Expanded));
+ QVERIFY(!(child1->state().expanded));
delete child1;
QAccessibleInterface *child2 = 0;
QCOMPARE(cell2->role(), QAccessible::TreeItem);
QCOMPARE(cell2->tableCellInterface()->rowIndex(), 1);
QCOMPARE(cell2->tableCellInterface()->columnIndex(), 0);
- QVERIFY(cell2->state() & QAccessible::Expandable);
+ QVERIFY(cell2->state().expandable);
QCOMPARE(iface->indexOfChild(cell2), 5);
- QVERIFY(!(cell2->state() & QAccessible::Expanded));
+ QVERIFY(!(cell2->state().expanded));
QCOMPARE(table2->columnDescription(1), QString("Work"));
delete cell2;
delete cell1;
QCOMPARE(cell2->role(), QAccessible::TreeItem);
QCOMPARE(cell2->tableCellInterface()->rowIndex(), 4);
QCOMPARE(cell2->tableCellInterface()->columnIndex(), 0);
- QVERIFY(!(cell2->state() & QAccessible::Expandable));
+ QVERIFY(!(cell2->state().expandable));
QCOMPARE(iface->indexOfChild(cell2), 11);
QCOMPARE(table2->columnDescription(0), QString("Artist"));
QCOMPARE(iface->indexOfChild(child1), 3);
QCOMPARE(child1->text(QAccessible::Name), QString("h2"));
QCOMPARE(child1->role(), QAccessible::ColumnHeader);
- QVERIFY(!(child1->state() & QAccessible::Expanded));
+ QVERIFY(!(child1->state().expanded));
delete child1;
QAccessibleInterface *child2 = iface->child(10);