Simplify QAccessibleAbstractScrollArea and Calendar.
Change-Id: Iea1df37fd9fd486295458ec7627f5b6908053cdf Reviewed-on: http://codereview.qt-project.org/5727 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
This commit is contained in:
parent
9ac51af083
commit
5ea2eab00d
@ -1847,59 +1847,16 @@ QAccessibleAbstractScrollArea::QAccessibleAbstractScrollArea(QWidget *widget)
|
||||
Q_ASSERT(qobject_cast<QAbstractScrollArea *>(widget));
|
||||
}
|
||||
|
||||
QString QAccessibleAbstractScrollArea::text(Text textType, int child) const
|
||||
{
|
||||
if (child == Self)
|
||||
return QAccessibleWidget::text(textType, 0);
|
||||
QWidgetList children = accessibleChildren();
|
||||
if (child < 1 || child > children.count())
|
||||
return QString();
|
||||
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1));
|
||||
if (!childInterface)
|
||||
return QString();
|
||||
QString string = childInterface->text(textType, 0);
|
||||
delete childInterface;
|
||||
return string;
|
||||
}
|
||||
|
||||
void QAccessibleAbstractScrollArea::setText(Text textType, int child, const QString &text)
|
||||
{
|
||||
if (text.isEmpty())
|
||||
return;
|
||||
if (child == 0) {
|
||||
QAccessibleWidget::setText(textType, 0, text);
|
||||
return;
|
||||
}
|
||||
QWidgetList children = accessibleChildren();
|
||||
if (child < 1 || child > children.count())
|
||||
return;
|
||||
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1));
|
||||
if (!childInterface)
|
||||
return;
|
||||
childInterface->setText(textType, 0, text);
|
||||
delete childInterface;
|
||||
}
|
||||
|
||||
QAccessible::State QAccessibleAbstractScrollArea::state(int child) const
|
||||
{
|
||||
if (child == Self)
|
||||
return QAccessibleWidget::state(child);
|
||||
QWidgetList children = accessibleChildren();
|
||||
if (child < 1 || child > children.count())
|
||||
return QAccessibleWidget::state(Self);
|
||||
QAccessibleInterface *childInterface = queryAccessibleInterface(children.at(child - 1));
|
||||
if (!childInterface)
|
||||
return QAccessibleWidget::state(Self);
|
||||
QAccessible::State returnState = childInterface->state(0);
|
||||
delete childInterface;
|
||||
return returnState;
|
||||
}
|
||||
|
||||
QVariant QAccessibleAbstractScrollArea::invokeMethod(QAccessible::Method, int, const QVariantList &)
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QAccessibleInterface *QAccessibleAbstractScrollArea::child(int index) const
|
||||
{
|
||||
return QAccessible::queryAccessibleInterface(accessibleChildren().at(index));
|
||||
}
|
||||
|
||||
int QAccessibleAbstractScrollArea::childCount() const
|
||||
{
|
||||
return accessibleChildren().count();
|
||||
@ -1948,9 +1905,10 @@ int QAccessibleAbstractScrollArea::navigate(RelationFlag relation, int entry, QA
|
||||
// to the reader. :-)
|
||||
switch (relation) {
|
||||
case Child:
|
||||
if (entry > 0)
|
||||
targetWidget = children.at(entry - 1);
|
||||
break;
|
||||
if (entry > 0) {
|
||||
*target = child(entry - 1);
|
||||
return *target ? 0 : -1;
|
||||
}
|
||||
case Left:
|
||||
if (entry < 1)
|
||||
break;
|
||||
@ -2039,46 +1997,31 @@ int QAccessibleAbstractScrollArea::navigate(RelationFlag relation, int entry, QA
|
||||
return *target ? 0: -1;
|
||||
}
|
||||
|
||||
QRect QAccessibleAbstractScrollArea::rect(int child) const
|
||||
{
|
||||
if (!abstractScrollArea()->isVisible())
|
||||
return QRect();
|
||||
if (child == Self)
|
||||
return QAccessibleWidget::rect(child);
|
||||
QWidgetList children = accessibleChildren();
|
||||
if (child < 1 || child > children.count())
|
||||
return QRect();
|
||||
const QWidget *childWidget = children.at(child - 1);
|
||||
if (!childWidget->isVisible())
|
||||
return QRect();
|
||||
return QRect(childWidget->mapToGlobal(QPoint(0, 0)), childWidget->size());
|
||||
}
|
||||
|
||||
int QAccessibleAbstractScrollArea::childAt(int x, int y) const
|
||||
{
|
||||
if (!abstractScrollArea()->isVisible())
|
||||
return -1;
|
||||
#if 0
|
||||
const QRect globalSelfGeometry = rect(Self);
|
||||
if (!globalSelfGeometry.isValid() || !globalSelfGeometry.contains(QPoint(x, y)))
|
||||
return -1;
|
||||
const QWidgetList children = accessibleChildren();
|
||||
for (int i = 0; i < children.count(); ++i) {
|
||||
const QWidget *child = children.at(i);
|
||||
const QRect globalChildGeometry = QRect(child->mapToGlobal(QPoint(0, 0)), child->size());
|
||||
if (globalChildGeometry.contains(QPoint(x, y))) {
|
||||
return ++i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
for (int i = childCount(); i >= 0; --i) {
|
||||
if (rect(i).contains(x, y))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
//int QAccessibleAbstractScrollArea::childAt(int x, int y) const
|
||||
//{
|
||||
// if (!abstractScrollArea()->isVisible())
|
||||
// return -1;
|
||||
//#if 0
|
||||
// const QRect globalSelfGeometry = rect(Self);
|
||||
// if (!globalSelfGeometry.isValid() || !globalSelfGeometry.contains(QPoint(x, y)))
|
||||
// return -1;
|
||||
// const QWidgetList children = accessibleChildren();
|
||||
// for (int i = 0; i < children.count(); ++i) {
|
||||
// const QWidget *child = children.at(i);
|
||||
// const QRect globalChildGeometry = QRect(child->mapToGlobal(QPoint(0, 0)), child->size());
|
||||
// if (globalChildGeometry.contains(QPoint(x, y))) {
|
||||
// return ++i;
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
//#else
|
||||
// for (int i = childCount(); i >= 0; --i) {
|
||||
// if (rect().contains(x, y))
|
||||
// return i;
|
||||
// }
|
||||
// return -1;
|
||||
//#endif
|
||||
//}
|
||||
|
||||
QAbstractScrollArea *QAccessibleAbstractScrollArea::abstractScrollArea() const
|
||||
{
|
||||
|
@ -74,16 +74,13 @@ public:
|
||||
Undefined
|
||||
};
|
||||
|
||||
QString text(Text textType, int child) const;
|
||||
void setText(Text textType, int child, const QString &text);
|
||||
State state(int child) const;
|
||||
QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms);
|
||||
QAccessibleInterface *child(int index) const;
|
||||
QVariant invokeMethod(QAccessible::Method method, int, const QVariantList ¶ms);
|
||||
int childCount() const;
|
||||
int indexOfChild(const QAccessibleInterface *child) const;
|
||||
bool isValid() const;
|
||||
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
|
||||
QRect rect(int child) const;
|
||||
int childAt(int x, int y) const;
|
||||
// int childAt(int x, int y) const;
|
||||
|
||||
//protected:
|
||||
QAbstractScrollArea *abstractScrollArea() const;
|
||||
|
@ -1200,6 +1200,17 @@ int QAccessibleCalendarWidget::indexOfChild(const QAccessibleInterface *child) c
|
||||
return 1;
|
||||
}
|
||||
|
||||
QAccessibleInterface *QAccessibleCalendarWidget::child(int index) const
|
||||
{
|
||||
if (index < 0 || index >= childCount())
|
||||
return 0;
|
||||
|
||||
if (childCount() > 1 && index == 0)
|
||||
return queryAccessibleInterface(navigationBar());
|
||||
|
||||
return queryAccessibleInterface(calendarView());
|
||||
}
|
||||
|
||||
int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
|
||||
{
|
||||
*target = 0;
|
||||
@ -1208,15 +1219,8 @@ int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAcces
|
||||
QWidget *targetWidget = 0;
|
||||
switch (relation) {
|
||||
case Child:
|
||||
if (childCount() == 1) {
|
||||
targetWidget = calendarView();
|
||||
} else {
|
||||
if (entry == 1)
|
||||
targetWidget = navigationBar();
|
||||
else
|
||||
targetWidget = calendarView();
|
||||
}
|
||||
break;
|
||||
*target = child(entry - 1);
|
||||
return *target ? 0 : -1;
|
||||
case Up:
|
||||
if (entry == 2)
|
||||
targetWidget = navigationBar();
|
||||
@ -1229,33 +1233,7 @@ int QAccessibleCalendarWidget::navigate(RelationFlag relation, int entry, QAcces
|
||||
return QAccessibleWidget::navigate(relation, entry, target);
|
||||
}
|
||||
*target = queryAccessibleInterface(targetWidget);
|
||||
return *target ? 0: -1;
|
||||
}
|
||||
|
||||
QRect QAccessibleCalendarWidget::rect(int child) const
|
||||
{
|
||||
if (!calendarWidget()->isVisible() || child > childCount())
|
||||
return QRect();
|
||||
if (child == 0)
|
||||
return QAccessibleWidget::rect(child);
|
||||
QWidget *childWidget = 0;
|
||||
if (childCount() == 2)
|
||||
childWidget = child == 1 ? navigationBar() : calendarView();
|
||||
else
|
||||
childWidget = calendarView();
|
||||
return QRect(childWidget->mapToGlobal(QPoint(0, 0)), childWidget->size());
|
||||
}
|
||||
|
||||
int QAccessibleCalendarWidget::childAt(int x, int y) const
|
||||
{
|
||||
const QPoint globalTargetPos = QPoint(x, y);
|
||||
if (!rect(0).contains(globalTargetPos))
|
||||
return -1;
|
||||
if (rect(1).contains(globalTargetPos))
|
||||
return 1;
|
||||
if (rect(2).contains(globalTargetPos))
|
||||
return 2;
|
||||
return 0;
|
||||
return *target ? 0 : -1;
|
||||
}
|
||||
|
||||
QCalendarWidget *QAccessibleCalendarWidget::calendarWidget() const
|
||||
|
@ -228,13 +228,14 @@ class QAccessibleCalendarWidget : public QAccessibleWidget
|
||||
public:
|
||||
explicit QAccessibleCalendarWidget(QWidget *widget);
|
||||
|
||||
QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms);
|
||||
int childCount() const;
|
||||
int indexOfChild(const QAccessibleInterface *child) const;
|
||||
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
|
||||
QRect rect(int child) const;
|
||||
int childAt(int x, int y) const;
|
||||
|
||||
QAccessibleInterface *child(int index) const;
|
||||
|
||||
|
||||
QVariant invokeMethod(QAccessible::Method method, int child, const QVariantList ¶ms);
|
||||
protected:
|
||||
QCalendarWidget *calendarWidget() const;
|
||||
|
||||
|
@ -81,6 +81,32 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that we get a valid QAccessibleInterface for the child.
|
||||
QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child);
|
||||
if (!childInterface) {
|
||||
qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// QAccessibleInterface::indexOfChild():
|
||||
// Verify that indexOfChild() returns an index equal to the index passed in
|
||||
int indexFromIndexOfChild = interface->indexOfChild(childInterface);
|
||||
delete childInterface;
|
||||
if (indexFromIndexOfChild != index) {
|
||||
qWarning("tst_QAccessibility::verifyChild (indexOfChild()):");
|
||||
qWarning() << "Expected:" << index;
|
||||
qWarning() << "Actual: " << indexFromIndexOfChild;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child).
|
||||
QAccessibleInterface *navigatedChildInterface = interface->child(index - 1);
|
||||
if (navigatedChildInterface == 0)
|
||||
return false;
|
||||
|
||||
const QRect rectFromInterface = navigatedChildInterface->rect();
|
||||
delete navigatedChildInterface;
|
||||
|
||||
// QAccessibleInterface::childAt():
|
||||
// Calculate global child position and check that the interface
|
||||
// returns the correct index for that position.
|
||||
@ -97,7 +123,6 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
|
||||
// Calculate global child geometry and check that the interface
|
||||
// returns a QRect which is equal to the calculated QRect.
|
||||
const QRect expectedGlobalRect = QRect(globalChildPos, child->size());
|
||||
const QRect rectFromInterface = interface->rect(index);
|
||||
if (expectedGlobalRect != rectFromInterface) {
|
||||
qWarning("tst_QAccessibility::verifyChild (rect()):");
|
||||
qWarning() << "Expected:" << expectedGlobalRect;
|
||||
@ -111,39 +136,6 @@ static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that we get a valid QAccessibleInterface for the child.
|
||||
QAccessibleInterface *childInterface = QAccessible::queryAccessibleInterface(child);
|
||||
if (!childInterface) {
|
||||
qWarning("tst_QAccessibility::verifyChild: Failed to retrieve interface for child.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// QAccessibleInterface::indexOfChild():
|
||||
// Verify that indexOfChild() returns an index equal to the index passed by,
|
||||
// or -1 if child is "Self" (index == 0).
|
||||
int indexFromIndexOfChild = interface->indexOfChild(childInterface);
|
||||
delete childInterface;
|
||||
int expectedIndex = index == 0 ? -1 : index;
|
||||
if (indexFromIndexOfChild != expectedIndex) {
|
||||
qWarning("tst_QAccessibility::verifyChild (indexOfChild()):");
|
||||
qWarning() << "Expected:" << expectedIndex;
|
||||
qWarning() << "Actual: " << indexFromIndexOfChild;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Navigate to child, compare its object and role with the interface from queryAccessibleInterface(child).
|
||||
{
|
||||
QAccessibleInterface *navigatedChildInterface = 0;
|
||||
const int status = interface->navigate(QAccessible::Child, index, &navigatedChildInterface);
|
||||
// We are navigating to a separate widget/interface, so status should be 0.
|
||||
if (status != 0)
|
||||
return false;
|
||||
|
||||
if (navigatedChildInterface == 0)
|
||||
return false;
|
||||
delete navigatedChildInterface;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -2413,7 +2405,6 @@ void tst_QAccessibility::abstractScrollAreaTest()
|
||||
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&abstractScrollArea);
|
||||
QVERIFY(interface);
|
||||
QVERIFY(!interface->rect(0).isValid());
|
||||
QVERIFY(!interface->rect(1).isValid());
|
||||
QCOMPARE(interface->childAt(200, 200), -1);
|
||||
|
||||
abstractScrollArea.resize(400, 400);
|
||||
@ -3138,7 +3129,7 @@ void tst_QAccessibility::calendarWidgetTest()
|
||||
|
||||
const QRect globalGeometry = QRect(calendarWidget.mapToGlobal(QPoint(0, 0)),
|
||||
calendarWidget.size());
|
||||
QCOMPARE(interface->rect(0), globalGeometry);
|
||||
QCOMPARE(interface->rect(), globalGeometry);
|
||||
|
||||
QWidget *navigationBar = 0;
|
||||
foreach (QObject *child, calendarWidget.children()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user