summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2011-09-15 21:41:54 +0200
committerQt by Nokia <qt-info@nokia.com>2011-09-19 12:06:13 +0200
commit76d0d1926466d42b1b25f0bac642c1e0f239074c (patch)
tree84397813957307cf1ac393ac29d045acc6e08846 /src/plugins
parent3647a00d47fd774daccce9f143cc2046fb59099d (diff)
Add parent and child functions to QAccessibleInterface.
Stop the mis-use of navigate to find the parent. In order to make navigation straight forward parent and child functions are now part of QAccessibleInterface. This allows navigating the hierarchy of accessible objects without the 1-based indexes in the navigate function which lead to confusion. Eventually the support for Ancestor in navigate can be completely removed and forwarded in the windows bridge if needed. In addition default parameters for virtual children. This will make the transition smooth since it allows to remove the integer already. Change-Id: I278287ce17161f9fa46797ac244676778c859576 Reviewed-on: http://codereview.qt-project.org/5024 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com> Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/accessible/widgets/complexwidgets.cpp34
-rw-r--r--src/plugins/accessible/widgets/complexwidgets.h2
-rw-r--r--src/plugins/accessible/widgets/itemviews.cpp78
-rw-r--r--src/plugins/accessible/widgets/itemviews.h20
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.cpp454
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.h6
-rw-r--r--src/plugins/accessible/widgets/qaccessiblewidgets.cpp62
-rw-r--r--src/plugins/accessible/widgets/qaccessiblewidgets.h3
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.cpp64
9 files changed, 347 insertions, 376 deletions
diff --git a/src/plugins/accessible/widgets/complexwidgets.cpp b/src/plugins/accessible/widgets/complexwidgets.cpp
index c1f70ac581..020ad06815 100644
--- a/src/plugins/accessible/widgets/complexwidgets.cpp
+++ b/src/plugins/accessible/widgets/complexwidgets.cpp
@@ -481,6 +481,17 @@ QAbstractItemView::CursorAction QAccessibleItemRow::toCursorAction(
return QAbstractItemView::MoveRight;
}
+QAccessibleInterface *QAccessibleItemRow::parent() const
+{
+ return new QAccessibleItemView(view->viewport());
+}
+
+QAccessibleInterface *QAccessibleItemRow::child(int index) const
+{
+ // FIXME? port to IA2 table2.
+ return 0;
+}
+
int QAccessibleItemRow::navigate(RelationFlag relation, int index,
QAccessibleInterface **iface) const
{
@@ -489,19 +500,9 @@ int QAccessibleItemRow::navigate(RelationFlag relation, int index,
return -1;
switch (relation) {
- case Ancestor: {
- if (!index)
- return -1;
- QAccessibleItemView *ancestor = new QAccessibleItemView(view->viewport());
- if (index == 1) {
- *iface = ancestor;
- return 0;
- } else if (index > 1) {
- int ret = ancestor->navigate(Ancestor, index - 1, iface);
- delete ancestor;
- return ret;
- }
- }
+ case Ancestor:
+ *iface = parent();
+ return *iface ? 0 : -1;
case Child: {
if (!index)
return -1;
@@ -1487,10 +1488,14 @@ public:
QString text(Text, int) const { return qt_accStripAmp(m_parent->tabText(m_index)); }
void setText(Text, int, const QString &) {}
+ QAccessibleInterface *parent() const {
+ return QAccessible::queryAccessibleInterface(m_parent);
+ }
+ QAccessibleInterface *child(int) const { return 0; }
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{
if (relation == QAccessible::Ancestor && index == 1) {
- *iface = QAccessible::queryAccessibleInterface(m_parent);
+ *iface = parent();
return 0;
}
return -1;
@@ -1842,6 +1847,7 @@ int QAccessibleComboBox::childAt(int x, int y) const
if (rect(i).contains(x, y))
return i;
}
+ Q_ASSERT(0);
return 0;
}
diff --git a/src/plugins/accessible/widgets/complexwidgets.h b/src/plugins/accessible/widgets/complexwidgets.h
index 8a5543041f..d29f4b9021 100644
--- a/src/plugins/accessible/widgets/complexwidgets.h
+++ b/src/plugins/accessible/widgets/complexwidgets.h
@@ -139,6 +139,8 @@ public:
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
int childAt(int x, int y) const;
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int index) const;
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
int userActionCount(int child) const;
diff --git a/src/plugins/accessible/widgets/itemviews.cpp b/src/plugins/accessible/widgets/itemviews.cpp
index 19ef7b59e8..90e810ab32 100644
--- a/src/plugins/accessible/widgets/itemviews.cpp
+++ b/src/plugins/accessible/widgets/itemviews.cpp
@@ -359,9 +359,7 @@ QAccessible2::TableModelChange QAccessibleTable2::modelChange() const
QAccessible::Role QAccessibleTable2::role(int child) const
{
- Q_ASSERT(child >= 0);
- if (child > 0)
- return QAccessible::Cell;
+ Q_ASSERT(child == 0);
return m_role;
}
@@ -386,6 +384,8 @@ int QAccessibleTable2::childAt(int x, int y) const
int QAccessibleTable2::childCount() const
{
+ if (!view->model())
+ return 0;
int vHeader = verticalHeader() ? 1 : 0;
int hHeader = horizontalHeader() ? 1 : 0;
return (view->model()->rowCount()+hHeader) * (view->model()->columnCount()+vHeader);
@@ -430,21 +430,31 @@ QRect QAccessibleTable2::rect(int child) const
return QRect(pos.x(), pos.y(), view->width(), view->height());
}
+QAccessibleInterface *QAccessibleTable2::parent() const
+{
+ if (view->parent()) {
+ return QAccessible::queryAccessibleInterface(view->parent());
+ }
+ return 0;
+}
+
+QAccessibleInterface *QAccessibleTable2::child(int index) const
+{
+ // Fixme: get rid of the +1 madness
+ return childFromLogical(index + 1);
+}
+
int QAccessibleTable2::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{
*iface = 0;
switch (relation) {
case Ancestor: {
- if (index == 1 && view->parent()) {
- *iface = QAccessible::queryAccessibleInterface(view->parent());
- if (*iface)
- return 0;
- }
- break;
+ *iface = parent();
+ return *iface ? 0 : -1;
}
case QAccessible::Child: {
Q_ASSERT(index > 0);
- *iface = childFromLogical(index);
+ *iface = child(index - 1);
if (*iface) {
return 0;
}
@@ -806,14 +816,23 @@ bool QAccessibleTable2Cell::isValid() const
return m_index.isValid();
}
+QAccessibleInterface *QAccessibleTable2Cell::parent() const
+{
+ if (m_role == QAccessible::TreeItem)
+ return new QAccessibleTree(view);
+
+ return new QAccessibleTable2(view);
+}
+
+QAccessibleInterface *QAccessibleTable2Cell::child(int) const
+{
+ return 0;
+}
+
int QAccessibleTable2Cell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
{
if (relation == Ancestor && index == 1) {
- if (m_role == QAccessible::TreeItem) {
- *iface = new QAccessibleTree(view);
- } else {
- *iface = new QAccessibleTable2(view);
- }
+ *iface = parent();
return 0;
}
@@ -978,19 +997,28 @@ bool QAccessibleTable2HeaderCell::isValid() const
return true;
}
-int QAccessibleTable2HeaderCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
+QAccessibleInterface *QAccessibleTable2HeaderCell::parent() const
{
- if (relation == QAccessible::Ancestor && index == 1) {
- if (false) {
+ if (false) {
#ifndef QT_NO_TREEVIEW
- } else if (qobject_cast<const QTreeView*>(view)) {
- *iface = new QAccessibleTree(view);
- return 0;
+ } else if (qobject_cast<const QTreeView*>(view)) {
+ return new QAccessibleTree(view);
#endif
- } else {
- *iface = new QAccessibleTable2(view);
- return 0;
- }
+ } else {
+ return new QAccessibleTable2(view);
+ }
+}
+
+QAccessibleInterface *QAccessibleTable2HeaderCell::child(int) const
+{
+ return 0;
+}
+
+int QAccessibleTable2HeaderCell::navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
+{
+ if (relation == QAccessible::Ancestor && index == 1) {
+ *iface = parent();
+ return *iface ? 0 : -1;
}
*iface = 0;
return -1;
diff --git a/src/plugins/accessible/widgets/itemviews.h b/src/plugins/accessible/widgets/itemviews.h
index d98180b254..c2b255b424 100644
--- a/src/plugins/accessible/widgets/itemviews.h
+++ b/src/plugins/accessible/widgets/itemviews.h
@@ -76,6 +76,8 @@ public:
int childCount() const;
int indexOfChild(const QAccessibleInterface *) const;
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int index) const;
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
@@ -193,6 +195,8 @@ public:
QString text(Text t, int child) const;
void setText(Text t, int child, const QString &text);
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int) const;
int navigate(RelationFlag relation, int m_index, QAccessibleInterface **iface) const;
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
@@ -246,6 +250,8 @@ public:
QString text(Text t, int child) const;
void setText(Text t, int child, const QString &text);
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int index) const;
int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const;
Relation relationTo(int child, const QAccessibleInterface *other, int otherChild) const;
@@ -287,11 +293,17 @@ public:
QString text(Text, int) const { return QString(); }
void setText(Text, int, const QString &) {}
- int navigate(RelationFlag relation, int index, QAccessibleInterface **iface) const
+ QAccessibleInterface *parent() const {
+ return QAccessible::queryAccessibleInterface(view);
+ }
+ QAccessibleInterface *child(int) const {
+ return 0;
+ }
+ int navigate(RelationFlag relation, int, QAccessibleInterface **iface) const
{
- if (relation == QAccessible::Ancestor && index == 1) {
- *iface = QAccessible::queryAccessibleInterface(view);
- return 0;
+ if (relation == QAccessible::Ancestor) {
+ *iface = parent();
+ return *iface ? 0 : -1;
}
return -1;
}
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.cpp b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
index eaf4ecb971..46954c4fbf 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
@@ -73,13 +73,8 @@ int QAccessibleMenu::childCount() const
QRect QAccessibleMenu::rect(int child) const
{
- if (!child || child > childCount())
- return QAccessibleWidget::rect(child);
-
- QRect r = menu()->actionGeometry(menu()->actions()[child - 1]);
- QPoint tlp = menu()->mapToGlobal(QPoint(0,0));
-
- return QRect(tlp.x() + r.x(), tlp.y() + r.y(), r.width(), r.height());
+ Q_ASSERT(child == 0);
+ return QAccessibleWidget::rect(child);
}
int QAccessibleMenu::childAt(int x, int y) const
@@ -92,79 +87,38 @@ int QAccessibleMenu::childAt(int x, int y) const
QString QAccessibleMenu::text(Text t, int child) const
{
+ Q_ASSERT(child == 0);
QString tx = QAccessibleWidget::text(t, child);
if (tx.size())
return tx;
- switch (t) {
- case Name:
- if (!child)
- return menu()->windowTitle();
- return qt_accStripAmp(menu()->actions().at(child-1)->text());
- case Help:
- return child ? menu()->actions().at(child-1)->whatsThis() : tx;
-#ifndef QT_NO_SHORTCUT
- case Accelerator:
- return child ? static_cast<QString>(menu()->actions().at(child-1)->shortcut()) : tx;
-#endif
- default:
- break;
- }
+ if (t == Name)
+ return menu()->windowTitle();
return tx;
}
QAccessible::Role QAccessibleMenu::role(int child) const
{
- if (!child)
- return PopupMenu;
-
- QAction *action = menu()->actions()[child-1];
- if (action && action->isSeparator())
- return Separator;
- return MenuItem;
+ Q_ASSERT(child == 0);
+ return PopupMenu;
}
QAccessible::State QAccessibleMenu::state(int child) const
{
+ Q_ASSERT(child == 0);
State s = QAccessibleWidget::state(child);
- if (!child)
- return s;
-
- QAction *action = menu()->actions()[child-1];
- if (!action)
- return s;
-
- if (menu()->style()->styleHint(QStyle::SH_Menu_MouseTracking))
- s |= HotTracked;
- if (action->isSeparator() || !action->isEnabled())
- s |= Unavailable;
- if (action->isChecked())
- s |= Checked;
- if (menu()->activeAction() == action)
- s |= Focused;
-
return s;
}
QString QAccessibleMenu::actionText(int action, QAccessible::Text text, int child) const
{
- if (action == QAccessible::DefaultAction && child && text == QAccessible::Name) {
- QAction *a = menu()->actions().value(child-1, 0);
- if (!a || a->isSeparator())
- return QString();
- if (a->menu()) {
- if (a->menu()->isVisible())
- return QMenu::tr("Close");
- return QMenu::tr("Open");
- }
- return QMenu::tr("Execute");
- }
-
+ Q_ASSERT(child == 0);
return QAccessibleWidget::actionText(action, text, child);
}
bool QAccessibleMenu::doAction(int act, int child, const QVariantList &)
{
+// Q_ASSERT(child == 0);
if (!child || act != QAccessible::DefaultAction)
return false;
@@ -179,52 +133,35 @@ bool QAccessibleMenu::doAction(int act, int child, const QVariantList &)
return true;
}
-int QAccessibleMenu::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+QAccessibleInterface *QAccessibleMenu::child(int index) const
{
- int ret = -1;
- if (entry < 0) {
- *target = 0;
- return ret;
- }
+ if (index < childCount())
+ return new QAccessibleMenuItem(menu(), menu()->actions().at(index));
+ return 0;
+}
- if (relation == Self || entry == 0) {
- *target = new QAccessibleMenu(menu());
- return 0;
+QAccessibleInterface *QAccessibleMenu::parent() const
+{
+ QWidget *parent = menu()->parentWidget();
+ if (qobject_cast<QMenu*>(parent) || qobject_cast<QMenuBar*>(parent)) {
+ return new QAccessibleMenuItem(parent, menu()->menuAction());
}
+ return QAccessibleWidget::parent();
+}
+int QAccessibleMenu::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+{
+ Q_ASSERT(entry >= 0);
switch (relation) {
case Child:
- if (entry <= childCount()) {
- *target = new QAccessibleMenuItem(menu(), menu()->actions().at( entry - 1 ));
- ret = 0;
- }
- break;
- case Ancestor: {
- QAccessibleInterface *iface;
- QWidget *parent = menu()->parentWidget();
- if (qobject_cast<QMenu*>(parent) || qobject_cast<QMenuBar*>(parent)) {
- iface = new QAccessibleMenuItem(parent, menu()->menuAction());
- if (entry == 1) {
- *target = iface;
- ret = 0;
- } else {
- ret = iface->navigate(Ancestor, entry - 1, target);
- delete iface;
- }
- } else {
- return QAccessibleWidget::navigate(relation, entry, target);
- }
- break;}
+ *target = child(entry - 1);
+ return *target ? 0 : -1;
+ case Ancestor:
+ *target = parent();
+ return *target ? 0 : -1;
default:
return QAccessibleWidget::navigate(relation, entry, target);
}
-
-
- if (ret == -1)
- *target = 0;
-
- return ret;
-
}
int QAccessibleMenu::indexOfChild( const QAccessibleInterface *child ) const
@@ -258,12 +195,8 @@ int QAccessibleMenuBar::childCount() const
QRect QAccessibleMenuBar::rect(int child) const
{
- if (!child)
- return QAccessibleWidget::rect(child);
-
- QRect r = menuBar()->actionGeometry(menuBar()->actions()[child - 1]);
- QPoint tlp = menuBar()->mapToGlobal(QPoint(0,0));
- return QRect(tlp.x() + r.x(), tlp.y() + r.y(), r.width(), r.height());
+ Q_ASSERT(child == 0);
+ return QAccessibleWidget::rect(child);
}
int QAccessibleMenuBar::childAt(int x, int y) const
@@ -275,38 +208,23 @@ int QAccessibleMenuBar::childAt(int x, int y) const
return -1;
}
-int QAccessibleMenuBar::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+QAccessibleInterface *QAccessibleMenuBar::child(int index) const
{
- int ret = -1;
- if (entry < 0) {
- *target = 0;
- return ret;
- }
-
- if (relation == Self || entry == 0) {
- *target = new QAccessibleMenuBar(menuBar());
- return 0;
- }
+ if (index < childCount())
+ return new QAccessibleMenuItem(menuBar(), menuBar()->actions().at(index));
+ return 0;
+}
- switch (relation) {
- case Child:
- if (entry <= childCount()) {
- *target = new QAccessibleMenuItem(menuBar(), menuBar()->actions().at( entry - 1 ));
- ret = 0;
- }
- break;
- default:
- return QAccessibleWidget::navigate(relation, entry, target);
+int QAccessibleMenuBar::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+{
+ if (relation == Child) {
+ *target = child(entry - 1);
+ return *target ? 0 : -1;
}
-
-
- if (ret == -1)
- *target = 0;
-
- return ret;
+ return QAccessibleWidget::navigate(relation, entry, target);
}
-int QAccessibleMenuBar::indexOfChild( const QAccessibleInterface *child ) const
+int QAccessibleMenuBar::indexOfChild(const QAccessibleInterface *child) const
{
int index = -1;
Role r = child->role(0);
@@ -320,87 +238,43 @@ int QAccessibleMenuBar::indexOfChild( const QAccessibleInterface *child ) const
QString QAccessibleMenuBar::text(Text t, int child) const
{
- QString str;
-
- if (child) {
- if (QAction *action = menuBar()->actions().value(child - 1, 0)) {
- switch (t) {
- case Name:
- return qt_accStripAmp(action->text());
- case Accelerator:
- str = qt_accHotKey(action->text());
- break;
- default:
- break;
- }
- }
- }
- if (str.isEmpty())
- str = QAccessibleWidget::text(t, child);
- return str;
+ Q_ASSERT(child == 0);
+ return QAccessibleWidget::text(t, child);
}
QAccessible::Role QAccessibleMenuBar::role(int child) const
{
- if (!child)
- return MenuBar;
-
- QAction *action = menuBar()->actions()[child-1];
- if (action && action->isSeparator())
- return Separator;
- return MenuItem;
+ Q_ASSERT(child == 0);
+ return MenuBar;
}
QAccessible::State QAccessibleMenuBar::state(int child) const
{
+ Q_ASSERT(child == 0);
State s = QAccessibleWidget::state(child);
- if (!child)
- return s;
-
- QAction *action = menuBar()->actions().value(child-1, 0);
- if (!action)
- return s;
-
- if (menuBar()->style()->styleHint(QStyle::SH_Menu_MouseTracking))
- s |= HotTracked;
- if (action->isSeparator() || !action->isEnabled())
- s |= Unavailable;
- if (menuBar()->activeAction() == action)
- s |= Focused;
-
return s;
}
QString QAccessibleMenuBar::actionText(int action, QAccessible::Text text, int child) const
{
- if (action == QAccessible::DefaultAction && child && text == QAccessible::Name) {
- QAction *a = menuBar()->actions().value(child-1, 0);
- if (!a || a->isSeparator())
- return QString();
- if (a->menu()) {
- if (a->menu()->isVisible())
- return QMenu::tr("Close");
- return QMenu::tr("Open");
- }
- return QMenu::tr("Execute");
- }
-
+ Q_ASSERT(child == 0);
return QAccessibleWidget::actionText(action, text, child);
}
-bool QAccessibleMenuBar::doAction(int act, int child, const QVariantList &)
+bool QAccessibleMenuBar::doAction(int, int child, const QVariantList &)
{
- if (act != !child)
- return false;
-
+// Q_ASSERT(child == 0);
QAction *action = menuBar()->actions().value(child-1, 0);
if (!action || !action->isEnabled())
return false;
if (action->menu() && action->menu()->isVisible())
action->menu()->hide();
- else
+ else {
menuBar()->setActiveAction(action);
+ }
return true;
+
+ return false;
}
#endif // QT_NO_MENUBAR
@@ -427,32 +301,69 @@ int QAccessibleMenuItem::childCount() const
return m_action->menu() ? 1 : 0;
}
-QString QAccessibleMenuItem::actionText(int action, Text text, int child ) const
+QString QAccessibleMenuItem::actionText(int action, Text text, int child) const
{
- if (text == Name && child == 0) {
- switch (action) {
- case Press:
- case DefaultAction:
- return QMenu::tr("Execute");
- break;
- default:
- break;
+ Q_ASSERT(child == 0);
+ if (!m_action || m_action->isSeparator())
+ return QString();
+
+ if (text == Name && ((action == Press) || (action == DefaultAction))) {
+ if (m_action->menu()) {
+ return QMenu::tr("Open");
}
+ return QMenu::tr("Execute");
}
return QString();
}
+
+//QAction *action = menuBar()->actions().value(child-1, 0);
+//if (!action || !action->isEnabled())
+// return false;
+//if (action->menu() && action->menu()->isVisible())
+// action->menu()->hide();
+//else
+// menuBar()->setActiveAction(action);
+//return true;
+
+
+
bool QAccessibleMenuItem::doAction(int action, int child, const QVariantList & /*params = QVariantList()*/ )
{
- if ((action == Press || action == DefaultAction) && child == 0) {
+ Q_ASSERT(child == 0);
+ if ((action != Press) && (action != DefaultAction))
+ return false;
+ if (!m_action->isEnabled())
+ return false;
+
+ if (QMenuBar *bar = qobject_cast<QMenuBar*>(owner())) {
+ if (m_action->menu() && m_action->menu()->isVisible()) {
+ m_action->menu()->hide();
+ return true;
+ } else {
+ bar->setActiveAction(m_action);
+ return true;
+ }
+ return false;
+ } else if (QMenu *menu = qobject_cast<QMenu*>(owner())){
+ if (m_action->menu() && m_action->menu()->isVisible()) {
+ m_action->menu()->hide();
+ return true;
+ } else {
+ menu->setActiveAction(m_action);
+ return true;
+ }
+ } else {
+ // no menu
m_action->trigger();
return true;
}
return false;
}
-int QAccessibleMenuItem::indexOfChild( const QAccessibleInterface * child ) const
+int QAccessibleMenuItem::indexOfChild(const QAccessibleInterface * child) const
{
+ Q_ASSERT(child == 0);
if (child->role(0) == PopupMenu && child->object() == m_action->menu())
return 1;
@@ -464,6 +375,18 @@ bool QAccessibleMenuItem::isValid() const
return m_action ? true : false;
}
+QAccessibleInterface *QAccessibleMenuItem::parent() const
+{
+ return QAccessible::queryAccessibleInterface(owner());
+}
+
+QAccessibleInterface *QAccessibleMenuItem::child(int index) const
+{
+ if (index == 0 && action()->menu())
+ return new QAccessibleMenu(action()->menu());
+ return 0;
+}
+
int QAccessibleMenuItem::navigate(RelationFlag relation, int entry, QAccessibleInterface ** target ) const
{
int ret = -1;
@@ -472,32 +395,14 @@ int QAccessibleMenuItem::navigate(RelationFlag relation, int entry, QAccessibleI
return ret;
}
- if (relation == Self || entry == 0) {
- *target = new QAccessibleMenuItem(owner(), action());
- return 0;
- }
-
switch (relation) {
case Child:
- if (entry <= childCount()) {
- *target = new QAccessibleMenu(action()->menu());
- ret = 0;
- }
+ *target = child(entry - 1);
+ ret = *target ? 0 : -1;
break;
-
- case Ancestor:{
- QWidget *parent = owner();
- QAccessibleInterface *ancestor = parent ? QAccessible::queryAccessibleInterface(parent) : 0;
- if (ancestor) {
- if (entry == 1) {
- *target = ancestor;
- ret = 0;
- } else {
- ret = ancestor->navigate(Ancestor, entry - 1, target);
- delete ancestor;
- }
- }
- break;}
+ case Ancestor:
+ *target = parent();
+ return 0;
case Up:
case Down:{
QAccessibleInterface *parent = 0;
@@ -533,36 +438,29 @@ QObject *QAccessibleMenuItem::object() const
return m_action;
}
-QRect QAccessibleMenuItem::rect (int child ) const
+QRect QAccessibleMenuItem::rect(int child) const
{
+ Q_ASSERT(child == 0);
QRect rect;
- if (child == 0) {
- QWidget *own = owner();
+ QWidget *own = owner();
#ifndef QT_NO_MENUBAR
- if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(own)) {
- rect = menuBar->actionGeometry(m_action);
- QPoint globalPos = menuBar->mapToGlobal(QPoint(0,0));
- rect = rect.translated(globalPos);
- } else
+ if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(own)) {
+ rect = menuBar->actionGeometry(m_action);
+ QPoint globalPos = menuBar->mapToGlobal(QPoint(0,0));
+ rect = rect.translated(globalPos);
+ } else
#endif // QT_NO_MENUBAR
- if (QMenu *menu = qobject_cast<QMenu*>(own)) {
- rect = menu->actionGeometry(m_action);
- QPoint globalPos = menu->mapToGlobal(QPoint(0,0));
- rect = rect.translated(globalPos);
- }
- } else if (child == 1) {
- QMenu *menu = m_action->menu();
- if (menu) {
- rect = menu->rect();
- QPoint globalPos = menu->mapToGlobal(QPoint(0,0));
- rect = rect.translated(globalPos);
- }
+ if (QMenu *menu = qobject_cast<QMenu*>(own)) {
+ rect = menu->actionGeometry(m_action);
+ QPoint globalPos = menu->mapToGlobal(QPoint(0,0));
+ rect = rect.translated(globalPos);
}
return rect;
}
QAccessible::Relation QAccessibleMenuItem::relationTo ( int child, const QAccessibleInterface * other, int otherChild ) const
{
+ Q_ASSERT(child == 0);
if (other->object() == owner()) {
return Child;
}
@@ -573,81 +471,68 @@ QAccessible::Relation QAccessibleMenuItem::relationTo ( int child, const QAccess
return Unrelated;
}
-QAccessible::Role QAccessibleMenuItem::role(int /*child*/ ) const
+QAccessible::Role QAccessibleMenuItem::role(int child) const
{
- return m_action->isSeparator() ? Separator :MenuItem;
+ Q_ASSERT(child == 0);
+// if (m_action->menu())
+// return PopupMenu;
+ return m_action->isSeparator() ? Separator : MenuItem;
}
void QAccessibleMenuItem::setText ( Text /*t*/, int /*child*/, const QString & /*text */)
{
-
}
-QAccessible::State QAccessibleMenuItem::state(int child ) const
+QAccessible::State QAccessibleMenuItem::state(int child) const
{
- QAccessible::State s = Unavailable;
-
- if (child == 0) {
- s = Normal;
- QWidget *own = owner();
+ Q_ASSERT(child == 0);
+ QAccessible::State s = Normal;
+ QWidget *own = owner();
- if (own->testAttribute(Qt::WA_WState_Visible) == false || m_action->isVisible() == false) {
- s |= Invisible;
- }
+ if (own->testAttribute(Qt::WA_WState_Visible) == false || m_action->isVisible() == false) {
+ s |= Invisible;
+ }
- if (QMenu *menu = qobject_cast<QMenu*>(own)) {
- if (menu->activeAction() == m_action)
- s |= Focused;
+ if (QMenu *menu = qobject_cast<QMenu*>(own)) {
+ if (menu->activeAction() == m_action)
+ s |= Focused;
#ifndef QT_NO_MENUBAR
- } else if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(own)) {
- if (menuBar->activeAction() == m_action)
- s |= Focused;
+ } else if (QMenuBar *menuBar = qobject_cast<QMenuBar*>(own)) {
+ if (menuBar->activeAction() == m_action)
+ s |= Focused;
#endif
- }
- if (own->style()->styleHint(QStyle::SH_Menu_MouseTracking))
- s |= HotTracked;
- if (m_action->isSeparator() || !m_action->isEnabled())
- s |= Unavailable;
- if (m_action->isChecked())
- s |= Checked;
- } else if (child == 1) {
- QMenu *menu = m_action->menu();
- if (menu) {
- QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(menu);
- s = iface->state(0);
- delete iface;
- }
}
+ if (own->style()->styleHint(QStyle::SH_Menu_MouseTracking))
+ s |= HotTracked;
+ if (m_action->isSeparator() || !m_action->isEnabled())
+ s |= Unavailable;
+ if (m_action->isChecked())
+ s |= Checked;
+
return s;
}
QString QAccessibleMenuItem::text ( Text t, int child ) const
{
+ Q_ASSERT(child == 0);
QString str;
switch (t) {
case Name:
- if (child == 0) {
- str = m_action->text();
- } else if (child == 1) {
- QMenu *m = m_action->menu();
- if (m)
- str = m->title();
- }
+ str = m_action->text();
str = qt_accStripAmp(str);
break;
- case Accelerator:
- if (child == 0) {
+ case Accelerator: {
#ifndef QT_NO_SHORTCUT
- QKeySequence key = m_action->shortcut();
- if (!key.isEmpty()) {
- str = key.toString();
- } else
+ QKeySequence key = m_action->shortcut();
+ if (!key.isEmpty()) {
+ str = key.toString();
+ } else
#endif
- {
- str = qt_accHotKey(m_action->text());
- }
+ {
+ str = qt_accHotKey(m_action->text());
}
break;
+ }
default:
break;
}
@@ -659,7 +544,6 @@ int QAccessibleMenuItem::userActionCount ( int /*child*/ ) const
return 0;
}
-
QAction *QAccessibleMenuItem::action() const
{
return m_action;
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.h b/src/plugins/accessible/widgets/qaccessiblemenu.h
index ce73629360..0144bf90b9 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.h
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.h
@@ -65,6 +65,8 @@ public:
QString text(Text t, int child) const;
Role role(int child) const;
State state(int child) const;
+ QAccessibleInterface *child(int index) const;
+ QAccessibleInterface *parent() const;
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
int indexOfChild( const QAccessibleInterface *child ) const;
@@ -81,6 +83,7 @@ class QAccessibleMenuBar : public QAccessibleWidget
public:
explicit QAccessibleMenuBar(QWidget *w);
+ QAccessibleInterface *child(int index) const;
int childCount() const;
int childAt(int x, int y) const;
@@ -113,6 +116,9 @@ public:
virtual bool doAction ( int action, int child, const QVariantList & params = QVariantList() );
virtual int indexOfChild ( const QAccessibleInterface * child ) const;
virtual bool isValid () const;
+
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int index) const;
virtual int navigate ( RelationFlag relation, int entry, QAccessibleInterface ** target ) const;
virtual QObject * object () const;
virtual QRect rect ( int child ) const;
diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
index dc16d80c5f..d811f976ab 100644
--- a/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblewidgets.cpp
@@ -414,22 +414,22 @@ int QAccessibleStackedWidget::indexOfChild(const QAccessibleInterface *child) co
return -1;
}
-int QAccessibleStackedWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+QAccessibleInterface *QAccessibleStackedWidget::child(int index) const
{
- *target = 0;
+ if (index < 0 || index >= stackedWidget()->count())
+ return 0;
+ return QAccessible::queryAccessibleInterface(stackedWidget()->widget(index));
+}
- QObject *targetObject = 0;
+int QAccessibleStackedWidget::navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const
+{
switch (relation) {
case Child:
- if (entry < 1 || entry > stackedWidget()->count())
- return -1;
- targetObject = stackedWidget()->widget(entry-1);
- break;
+ *target = child(entry - 1);
+ return *target ? 0 : -1;
default:
return QAccessibleWidget::navigate(relation, entry, target);
}
- *target = QAccessible::queryAccessibleInterface(targetObject);
- return *target ? 0 : -1;
}
QStackedWidget *QAccessibleStackedWidget::stackedWidget() const
@@ -1069,15 +1069,37 @@ QAccessibleTitleBar::QAccessibleTitleBar(QDockWidget *widget)
}
-int QAccessibleTitleBar::navigate(RelationFlag relation, int entry, QAccessibleInterface **iface) const
+QAccessibleInterface *QAccessibleTitleBar::parent() const
{
- if (entry == 0 || relation == Self) {
- *iface = new QAccessibleTitleBar(dockWidget());
- return 0;
+ return new QAccessibleDockWidget(dockWidget());
+}
+
+QAccessibleInterface *QAccessibleTitleBar::child(int index) const
+{
+ if (index >= 0) {
+ QDockWidgetLayout *layout = dockWidgetLayout();
+ int role;
+ int currentIndex = 0;
+ for (role = QDockWidgetLayout::CloseButton; role <= QDockWidgetLayout::FloatButton; ++role) {
+ QWidget *w = layout->widgetForRole((QDockWidgetLayout::Role)role);
+ if (!w || !w->isVisible())
+ continue;
+ if (currentIndex == index)
+ return QAccessible::queryAccessibleInterface(w);
+ ++currentIndex;
+ }
}
+ return 0;
+}
+
+int QAccessibleTitleBar::navigate(RelationFlag relation, int entry, QAccessibleInterface **iface) const
+{
switch (relation) {
case Child:
+ *iface = child(entry - 1);
+ return *iface ? 0 : -1;
case FocusChild:
+ // ###
if (entry >= 1) {
QDockWidgetLayout *layout = dockWidgetLayout();
int index = 1;
@@ -1095,18 +1117,8 @@ int QAccessibleTitleBar::navigate(RelationFlag relation, int entry, QAccessibleI
}
break;
case Ancestor:
- {
- QAccessibleDockWidget *target = new QAccessibleDockWidget(dockWidget());
- int index;
- if (entry == 1) {
- *iface = target;
- return 0;
- }
- index = target->navigate(Ancestor, entry - 1, iface);
- delete target;
- return index;
-
- break;}
+ *iface = parent();
+ return iface ? 0 : -1;
case Sibling:
return navigate(Child, entry, iface);
break;
diff --git a/src/plugins/accessible/widgets/qaccessiblewidgets.h b/src/plugins/accessible/widgets/qaccessiblewidgets.h
index 471dca5cab..6cb31726dd 100644
--- a/src/plugins/accessible/widgets/qaccessiblewidgets.h
+++ b/src/plugins/accessible/widgets/qaccessiblewidgets.h
@@ -132,6 +132,7 @@ public:
int childAt(int x, int y) const;
int childCount() const;
int indexOfChild(const QAccessibleInterface *child) const;
+ QAccessibleInterface *child(int index) const;
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
protected:
@@ -273,6 +274,8 @@ public:
QString actionText(int action, Text t, int child) const;
bool doAction(int action, int child, const QVariantList& params = QVariantList());
int userActionCount ( int child) const;
+ QAccessibleInterface *parent() const;
+ QAccessibleInterface *child(int index) const;
int navigate(RelationFlag relation, int entry, QAccessibleInterface **iface) const;
int indexOfChild(const QAccessibleInterface *child) const;
int childCount() const;
diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp
index f74aba2e62..eae8bd907d 100644
--- a/src/plugins/accessible/widgets/simplewidgets.cpp
+++ b/src/plugins/accessible/widgets/simplewidgets.cpp
@@ -106,8 +106,7 @@ QAbstractButton *QAccessibleButton::button() const
/*! \reimp */
QString QAccessibleButton::actionText(int action, Text text, int child) const
{
- if (child)
- return QString();
+ Q_ASSERT(child == 0);
if (text == Name) switch (action) {
case Press:
@@ -117,7 +116,7 @@ QString QAccessibleButton::actionText(int action, Text text, int child) const
return QPushButton::tr("Open");
case CheckBox:
{
- if (state(child) & Checked)
+ if (state(0) & Checked)
return QCheckBox::tr("Uncheck");
QCheckBox *cb = qobject_cast<QCheckBox*>(object());
if (!cb || !cb->isTristate() || cb->checkState() == Qt::PartiallyChecked)
@@ -138,7 +137,8 @@ QString QAccessibleButton::actionText(int action, Text text, int child) const
/*! \reimp */
bool QAccessibleButton::doAction(int action, int child, const QVariantList &params)
{
- if (child || !widget()->isEnabled())
+ Q_ASSERT(child == 0);
+ if (!widget()->isEnabled())
return false;
switch (action) {
@@ -161,6 +161,7 @@ bool QAccessibleButton::doAction(int action, int child, const QVariantList &para
/*! \reimp */
QString QAccessibleButton::text(Text t, int child) const
{
+ Q_ASSERT(child == 0);
QString str;
switch (t) {
case Accelerator:
@@ -190,7 +191,8 @@ QString QAccessibleButton::text(Text t, int child) const
/*! \reimp */
QAccessible::State QAccessibleButton::state(int child) const
{
- State state = QAccessibleWidget::state(child);
+ Q_ASSERT(child == 0);
+ State state = QAccessibleWidget::state(0);
QAbstractButton *b = button();
QCheckBox *cb = qobject_cast<QCheckBox *>(b);
@@ -336,11 +338,16 @@ bool QAccessibleToolButton::isSplitButton() const
/*! \reimp */
QAccessible::Role QAccessibleToolButton::role(int child) const
{
- if (isSplitButton()) switch(child) {
- case ButtonExecute:
- return PushButton;
- case ButtonDropMenu:
- return ButtonMenu;
+ Q_ASSERT(child == 0);
+
+ // FIXME
+ if (isSplitButton()) {
+ switch (child) {
+ case ButtonExecute:
+ return PushButton;
+ case ButtonDropMenu:
+ return ButtonMenu;
+ }
}
return QAccessibleButton::role(child);
}
@@ -348,6 +355,7 @@ QAccessible::Role QAccessibleToolButton::role(int child) const
/*! \reimp */
QAccessible::State QAccessibleToolButton::state(int child) const
{
+ Q_ASSERT(child == 0);
QAccessible::State st = QAccessibleButton::state(child);
if (toolButton()->autoRaise())
st |= HotTracked;
@@ -374,22 +382,24 @@ int QAccessibleToolButton::childCount() const
*/
QRect QAccessibleToolButton::rect(int child) const
{
+ Q_ASSERT(child == 0);
if (!toolButton()->isVisible())
return QRect();
- if (!child)
- return QAccessibleButton::rect(child);
- QStyleOptionToolButton opt;
- opt.init(widget());
- QRect subrect = widget()->style()->subControlRect(QStyle::CC_ToolButton, &opt,
- QStyle::SC_ToolButtonMenu, toolButton());
+ return QAccessibleButton::rect(child);
- if (child == ButtonExecute)
- subrect = QRect(0, 0, subrect.x(), widget()->height());
+ // FIXME: sub buttons when SplitButton
+// QStyleOptionToolButton opt;
+// opt.init(widget());
+// QRect subrect = widget()->style()->subControlRect(QStyle::CC_ToolButton, &opt,
+// QStyle::SC_ToolButtonMenu, toolButton());
- QPoint ntl = widget()->mapToGlobal(subrect.topLeft());
- subrect.moveTopLeft(ntl);
- return subrect;
+// if (child == ButtonExecute)
+// subrect = QRect(0, 0, subrect.x(), widget()->height());
+
+// QPoint ntl = widget()->mapToGlobal(subrect.topLeft());
+// subrect.moveTopLeft(ntl);
+// return subrect;
}
/*!
@@ -400,6 +410,7 @@ QRect QAccessibleToolButton::rect(int child) const
*/
QString QAccessibleToolButton::text(Text t, int child) const
{
+ Q_ASSERT(child == 0);
QString str;
switch (t) {
case Name:
@@ -423,6 +434,7 @@ QString QAccessibleToolButton::text(Text t, int child) const
*/
int QAccessibleToolButton::actionCount(int child) const
{
+ Q_ASSERT(child == 0);
// each subelement has one action
if (child)
return isSplitButton() ? 1 : 0;
@@ -445,6 +457,7 @@ int QAccessibleToolButton::actionCount(int child) const
*/
QString QAccessibleToolButton::actionText(int action, Text text, int child) const
{
+ Q_ASSERT(child == 0);
if (text == Name) switch(child) {
case ButtonExecute:
return QToolButton::tr("Press");
@@ -472,6 +485,7 @@ QString QAccessibleToolButton::actionText(int action, Text text, int child) cons
*/
bool QAccessibleToolButton::doAction(int action, int child, const QVariantList &params)
{
+ Q_ASSERT(child == 0);
if (!widget()->isEnabled())
return false;
if (action == 1 || child == ButtonDropMenu) {
@@ -507,6 +521,7 @@ QAccessibleDisplay::QAccessibleDisplay(QWidget *w, Role role)
/*! \reimp */
QAccessible::Role QAccessibleDisplay::role(int child) const
{
+ Q_ASSERT(child == 0);
QLabel *l = qobject_cast<QLabel*>(object());
if (l) {
if (l->pixmap())
@@ -530,6 +545,7 @@ QAccessible::Role QAccessibleDisplay::role(int child) const
/*! \reimp */
QString QAccessibleDisplay::text(Text t, int child) const
{
+ Q_ASSERT(child == 0);
QString str;
switch (t) {
case Name:
@@ -570,6 +586,7 @@ QString QAccessibleDisplay::text(Text t, int child) const
QAccessible::Relation QAccessibleDisplay::relationTo(int child, const QAccessibleInterface *other,
int otherChild) const
{
+ Q_ASSERT(child == 0);
Relation relation = QAccessibleWidget::relationTo(child, other, otherChild);
if (child || otherChild)
return relation;
@@ -689,6 +706,7 @@ QLineEdit *QAccessibleLineEdit::lineEdit() const
/*! \reimp */
QString QAccessibleLineEdit::text(Text t, int child) const
{
+ Q_ASSERT(child == 0);
QString str;
switch (t) {
case Value:
@@ -723,6 +741,7 @@ void QAccessibleLineEdit::setText(Text t, int control, const QString &text)
/*! \reimp */
QAccessible::State QAccessibleLineEdit::state(int child) const
{
+ Q_ASSERT(child == 0);
State state = QAccessibleWidget::state(child);
QLineEdit *l = lineEdit();
@@ -744,8 +763,7 @@ QAccessible::State QAccessibleLineEdit::state(int child) const
QVariant QAccessibleLineEdit::invokeMethod(QAccessible::Method method, int child,
const QVariantList &params)
{
- if (child)
- return QVariant();
+ Q_ASSERT(child == 0);
switch (method) {
case ListSupportedMethods: {