summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@nokia.com>2011-10-06 14:54:49 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-19 19:25:42 +0200
commit4dc25c1f2995a5e02da47f0f6f3522af9eb6f78c (patch)
tree86391ff6c57ed46295df684a4c87ba9db0b73263 /src/plugins
parent663cd1771883e1e7ac9c1a0dc8b797601b59ba17 (diff)
Refactor QAccessibleActionInterface.
Some refinements done by Jan-Arve Sæther. Change-Id: I99195b3c7273316cfa9c46e451924bbcfddd11a9 Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/accessible/widgets/complexwidgets.cpp94
-rw-r--r--src/plugins/accessible/widgets/complexwidgets.h13
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.cpp170
-rw-r--r--src/plugins/accessible/widgets/qaccessiblemenu.h19
-rw-r--r--src/plugins/accessible/widgets/rangecontrols.cpp33
-rw-r--r--src/plugins/accessible/widgets/rangecontrols.h6
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.cpp289
-rw-r--r--src/plugins/accessible/widgets/simplewidgets.h21
-rw-r--r--src/plugins/platforms/windows/qwindowsaccessibility.cpp49
9 files changed, 206 insertions, 488 deletions
diff --git a/src/plugins/accessible/widgets/complexwidgets.cpp b/src/plugins/accessible/widgets/complexwidgets.cpp
index b0014e3e75..a94163c117 100644
--- a/src/plugins/accessible/widgets/complexwidgets.cpp
+++ b/src/plugins/accessible/widgets/complexwidgets.cpp
@@ -486,7 +486,7 @@ QAccessibleInterface *QAccessibleItemRow::parent() const
return new QAccessibleItemView(view->viewport());
}
-QAccessibleInterface *QAccessibleItemRow::child(int index) const
+QAccessibleInterface *QAccessibleItemRow::child(int) const
{
// FIXME? port to IA2 table2.
return 0;
@@ -1500,47 +1500,25 @@ public:
return QAccessible::Unrelated;
}
-#ifndef QT_NO_ACTION
- int userActionCount(int) const { return 0; }
- QString actionText(int, Text, int) const { return QString(); }
- bool doAction(int actionIndex, int, const QVariantList &) {
- doAction(actionIndex);
- return true;
- }
-#endif
-
// action interface
int actionCount() {
return 1;
}
- void doAction(int actionIndex)
- {
- if (actionIndex == Press || actionIndex == DefaultAction)
- m_parent->setCurrentIndex(m_index);
- }
- QString localizedDescription(int actionIndex)
+ QStringList actionNames() const
{
- if (actionIndex == 0)
- return QTabWidget::tr("Select this tab");
- return QString();
+ return QStringList() << PressAction;
}
- QString name(int actionIndex)
+ void doAction(const QString &actionName)
{
- if (actionIndex == 0)
- return QStringLiteral("Select tab");
- return QString();
+ if (actionName == PressAction)
+ m_parent->setCurrentIndex(m_index);
}
- QString localizedName(int actionIndex)
+ QStringList keyBindingsForAction(const QString &) const
{
- if (actionIndex == 0)
- return QTabWidget::tr("Select tab");
- return QString();
- }
- QStringList keyBindings(int actionIndex) {
return QStringList();
}
@@ -1684,7 +1662,6 @@ QComboBox *QAccessibleComboBox::comboBox() const
QAccessibleInterface* QAccessibleComboBox::child(int index) const
{
- QAccessibleInterface* target = 0;
if (index == 0) {
QAbstractItemView *view = comboBox()->view();
//QWidget *parent = view ? view->parentWidget() : 0;
@@ -1717,7 +1694,8 @@ int QAccessibleComboBox::indexOfChild(const QAccessibleInterface *child) const
return -1;
}
-QString QAccessibleComboBox::text(Text t, int child) const
+/*! \reimp */
+QString QAccessibleComboBox::text(Text t, int) const
{
QString str;
@@ -1746,54 +1724,30 @@ QString QAccessibleComboBox::text(Text t, int child) const
return str;
}
-bool QAccessibleComboBox::doAction(int action, int, const QVariantList &)
-{
- if (action == DefaultAction || action == Press) {
- if (comboBox()->view()->isVisible()) {
- comboBox()->hidePopup();
- } else {
- comboBox()->showPopup();
- }
- return true;
- }
- return false;
-}
-
-QString QAccessibleComboBox::actionText(int action, Text t, int child) const
-{
- QString text;
- if (t == Name && (action == DefaultAction || action == Press))
- text = comboBox()->view()->isVisible() ? QComboBox::tr("Close") : QComboBox::tr("Open");
- return text;
-}
-
-int QAccessibleComboBox::actionCount()
-{
- return 1;
-}
-
-void QAccessibleComboBox::doAction(int actionIndex)
-{
- doAction(0, 0, QVariantList());
-}
-
-QString QAccessibleComboBox::localizedDescription
-(int actionIndex)
+QStringList QAccessibleComboBox::actionNames() const
{
- return QComboBox::tr("Opens the selection list of this combo box.");
+ return QStringList() << ShowMenuAction;
}
-QString QAccessibleComboBox::name(int actionIndex)
+QString QAccessibleComboBox::localizedActionDescription(const QString &actionName) const
{
- return QStringLiteral("Popup Combobox Menu");
+ if (actionName == ShowMenuAction)
+ return QComboBox::tr("Open the combo box selection popup");
+ return QString();
}
-QString QAccessibleComboBox::localizedName(int actionIndex)
+void QAccessibleComboBox::doAction(const QString &actionName)
{
- return QComboBox::tr("Popup Combobox Menu");
+ if (actionName == ShowMenuAction) {
+ if (comboBox()->view()->isVisible()) {
+ comboBox()->hidePopup();
+ } else {
+ comboBox()->showPopup();
+ }
+ }
}
-QStringList QAccessibleComboBox::keyBindings(int)
+QStringList QAccessibleComboBox::keyBindingsForAction(const QString &/*actionName*/) const
{
return QStringList();
}
diff --git a/src/plugins/accessible/widgets/complexwidgets.h b/src/plugins/accessible/widgets/complexwidgets.h
index a8c63a026a..980eee2502 100644
--- a/src/plugins/accessible/widgets/complexwidgets.h
+++ b/src/plugins/accessible/widgets/complexwidgets.h
@@ -263,16 +263,11 @@ public:
QString text(Text t, int child) const;
- bool doAction(int action, int child, const QVariantList &params);
- QString actionText(int action, Text t, int child) const;
-
// QAccessibleActionInterface
- int actionCount();
- void doAction(int actionIndex);
- QString localizedDescription(int actionIndex);
- QString name(int actionIndex);
- QString localizedName(int actionIndex);
- QStringList keyBindings(int actionIndex);
+ QStringList actionNames() const;
+ QString localizedActionDescription(const QString &actionName) const;
+ void doAction(const QString &actionName);
+ QStringList keyBindingsForAction(const QString &actionName) const;
protected:
QComboBox *comboBox() const;
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.cpp b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
index 48fb471ace..5eaf5bc2c9 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.cpp
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.cpp
@@ -110,29 +110,6 @@ QAccessible::State QAccessibleMenu::state(int child) const
return s;
}
-QString QAccessibleMenu::actionText(int action, QAccessible::Text text, int child) const
-{
- 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;
-
- QAction *action = menu()->actions().value(child-1, 0);
- if (!action || !action->isEnabled())
- return false;
-
- if (action->menu() && action->menu()->isVisible())
- action->menu()->hide();
- else
- menu()->setActiveAction(action);
- return true;
-}
-
QAccessibleInterface *QAccessibleMenu::child(int index) const
{
if (index < childCount())
@@ -246,35 +223,12 @@ QAccessible::State QAccessibleMenuBar::state(int child) const
return s;
}
-QString QAccessibleMenuBar::actionText(int action, QAccessible::Text text, int child) const
-{
- Q_ASSERT(child == 0);
- return QAccessibleWidget::actionText(action, text, child);
-}
-
-bool QAccessibleMenuBar::doAction(int, int child, const QVariantList &)
-{
-// 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 {
- menuBar()->setActiveAction(action);
- }
- return true;
-
- return false;
-}
-
#endif // QT_NO_MENUBAR
QAccessibleMenuItem::QAccessibleMenuItem(QWidget *owner, QAction *action) : m_action(action), m_owner(owner)
{
}
-
QAccessibleMenuItem::~QAccessibleMenuItem()
{}
@@ -292,66 +246,6 @@ int QAccessibleMenuItem::childCount() const
return m_action->menu() ? 1 : 0;
}
-QString QAccessibleMenuItem::actionText(int action, Text text, int child) const
-{
- 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()*/ )
-{
- 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
{
Q_ASSERT(child == 0);
@@ -462,11 +356,8 @@ QAccessible::Relation QAccessibleMenuItem::relationTo ( int child, const QAccess
return Unrelated;
}
-QAccessible::Role QAccessibleMenuItem::role(int child) const
+QAccessible::Role QAccessibleMenuItem::role(int) const
{
- Q_ASSERT(child == 0);
-// if (m_action->menu())
-// return PopupMenu;
return m_action->isSeparator() ? Separator : MenuItem;
}
@@ -530,11 +421,66 @@ QString QAccessibleMenuItem::text ( Text t, int child ) const
return str;
}
-int QAccessibleMenuItem::userActionCount ( int /*child*/ ) const
+
+QString QAccessibleMenuItem::actionText(int action, Text text, int child) const
{
- return 0;
+ 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();
}
+QStringList QAccessibleMenuItem::actionNames() const
+{
+ QStringList actions;
+ if (!m_action || m_action->isSeparator())
+ return actions;
+
+ if (m_action->menu()) {
+ actions << ShowMenuAction;
+ } else {
+ actions << PressAction;
+ }
+ return actions;
+}
+
+void QAccessibleMenuItem::doAction(const QString &actionName)
+{
+ if (!m_action->isEnabled())
+ return;
+
+ if (actionName == PressAction) {
+ m_action->trigger();
+ } else if (actionName == ShowMenuAction) {
+ if (QMenuBar *bar = qobject_cast<QMenuBar*>(owner())) {
+ if (m_action->menu() && m_action->menu()->isVisible()) {
+ m_action->menu()->hide();
+ } else {
+ bar->setActiveAction(m_action);
+ }
+ } else if (QMenu *menu = qobject_cast<QMenu*>(owner())){
+ if (m_action->menu() && m_action->menu()->isVisible()) {
+ m_action->menu()->hide();
+ } else {
+ menu->setActiveAction(m_action);
+ }
+ }
+ }
+}
+
+QStringList QAccessibleMenuItem::keyBindingsForAction(const QString &) const
+{
+ return QStringList();
+}
+
+
QAction *QAccessibleMenuItem::action() const
{
return m_action;
diff --git a/src/plugins/accessible/widgets/qaccessiblemenu.h b/src/plugins/accessible/widgets/qaccessiblemenu.h
index 82bb93b3c4..2ac8b37b6e 100644
--- a/src/plugins/accessible/widgets/qaccessiblemenu.h
+++ b/src/plugins/accessible/widgets/qaccessiblemenu.h
@@ -70,9 +70,6 @@ public:
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
int indexOfChild( const QAccessibleInterface *child ) const;
- QString actionText(int action, QAccessible::Text text, int child) const;
- bool doAction(int action, int child, const QVariantList &params);
-
protected:
QMenu *menu() const;
};
@@ -93,18 +90,15 @@ public:
int navigate(RelationFlag relation, int entry, QAccessibleInterface **target) const;
int indexOfChild( const QAccessibleInterface *child ) const;
- QString actionText(int action, QAccessible::Text text, int child) const;
- bool doAction(int action, int child, const QVariantList &params);
-
protected:
QMenuBar *menuBar() const;
};
#endif // QT_NO_MENUBAR
-
-class QAccessibleMenuItem : public QAccessibleInterface
+class QAccessibleMenuItem : public QAccessibleInterface, public QAccessibleActionInterface
{
+ Q_ACCESSIBLE_OBJECT
public:
explicit QAccessibleMenuItem(QWidget *owner, QAction *w);
@@ -112,7 +106,6 @@ public:
virtual QString actionText ( int action, Text t, int child ) const;
virtual int childAt ( int x, int y ) const;
virtual int childCount () const;
- virtual bool doAction ( int action, int child, const QVariantList & params = QVariantList() );
virtual int indexOfChild ( const QAccessibleInterface * child ) const;
virtual bool isValid () const;
@@ -126,11 +119,13 @@ public:
virtual void setText ( Text t, int child, const QString & text );
virtual State state ( int child ) const;
virtual QString text ( Text t, int child ) const;
- virtual int userActionCount ( int child ) const;
-
- QWidget *owner() const;
+ // QAccessibleActionInterface
+ QStringList actionNames() const;
+ void doAction(const QString &actionName);
+ QStringList keyBindingsForAction(const QString &actionName) const;
+ QWidget *owner() const;
protected:
QAction *action() const;
private:
diff --git a/src/plugins/accessible/widgets/rangecontrols.cpp b/src/plugins/accessible/widgets/rangecontrols.cpp
index fdbb02e3e5..9eac2730b2 100644
--- a/src/plugins/accessible/widgets/rangecontrols.cpp
+++ b/src/plugins/accessible/widgets/rangecontrols.cpp
@@ -88,14 +88,6 @@ QString QAccessibleAbstractSpinBox::text(Text t, int child) const
return QAccessibleWidget::text(t, 0);
}
-bool QAccessibleAbstractSpinBox::doAction(int action, int child, const QVariantList &params)
-{
- Q_UNUSED(child)
- if (!widget()->isEnabled())
- return false;
- return QAccessibleWidget::doAction(action, 0, params);
-}
-
QVariant QAccessibleAbstractSpinBox::currentValue()
{
QVariant result = abstractSpinBox()->property("value");
@@ -166,14 +158,6 @@ QSpinBox *QAccessibleSpinBox::spinBox() const
return qobject_cast<QSpinBox*>(object());
}
-bool QAccessibleSpinBox::doAction(int action, int child, const QVariantList &params)
-{
- Q_UNUSED(child)
- if (!widget()->isEnabled())
- return false;
-
- return QAccessibleAbstractSpinBox::doAction(action, 0, params);
-}
// ================================== QAccessibleDoubleSpinBox ==================================
QAccessibleDoubleSpinBox::QAccessibleDoubleSpinBox(QWidget *widget)
@@ -276,23 +260,6 @@ QString QAccessibleSlider::text(Text t, int child) const
return QAccessibleAbstractSlider::text(t, child);
}
-/*!
- \fn int QAccessibleSlider::defaultAction(int child) const
-
- Returns the default action for the given \a child. The base class
- implementation returns 0.
-*/
-int QAccessibleSlider::defaultAction(int /*child*/) const
-{
- return 0;
-}
-
-/*! \internal */
-QString QAccessibleSlider::actionText(int /*action*/, Text /*t*/, int /*child*/) const
-{
- return QLatin1String("");
-}
-
QAccessibleAbstractSlider::QAccessibleAbstractSlider(QWidget *w, Role r)
: QAccessibleWidget(w, r)
{
diff --git a/src/plugins/accessible/widgets/rangecontrols.h b/src/plugins/accessible/widgets/rangecontrols.h
index 39916a789a..827c305c49 100644
--- a/src/plugins/accessible/widgets/rangecontrols.h
+++ b/src/plugins/accessible/widgets/rangecontrols.h
@@ -58,7 +58,7 @@ class QDoubleSpinBox;
class QDial;
#ifndef QT_NO_SPINBOX
-class QAccessibleAbstractSpinBox: public QAccessibleWidget, public QAccessibleValueInterface
+class QAccessibleAbstractSpinBox: public QAccessibleWidget, public QAccessibleValueInterface // TODO, public QAccessibleActionInterface
{
Q_ACCESSIBLE_OBJECT
public:
@@ -86,7 +86,6 @@ class QAccessibleSpinBox : public QAccessibleAbstractSpinBox
{
public:
explicit QAccessibleSpinBox(QWidget *w);
- bool doAction(int action, int child, const QVariantList &params);
protected:
QSpinBox *spinBox() const;
@@ -142,9 +141,6 @@ public:
explicit QAccessibleSlider(QWidget *w);
QString text(Text t, int child) const;
- int defaultAction(int child) const;
- QString actionText(int action, Text t, int child) const;
-
protected:
QSlider *slider() const;
};
diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp
index 15f2355407..4771d93980 100644
--- a/src/plugins/accessible/widgets/simplewidgets.cpp
+++ b/src/plugins/accessible/widgets/simplewidgets.cpp
@@ -104,75 +104,23 @@ QAbstractButton *QAccessibleButton::button() const
return qobject_cast<QAbstractButton*>(object());
}
-QString QAccessibleButton::actionText(int action, Text text, int child) const
-{
- Q_ASSERT(child == 0);
-
- if (text == Name) switch (action) {
- case Press:
- case DefaultAction: // press, checking or open
- switch (role(0)) {
- case ButtonMenu:
- return QPushButton::tr("Open");
- case CheckBox:
- {
- if (state(0) & Checked)
- return QCheckBox::tr("Uncheck");
- QCheckBox *cb = qobject_cast<QCheckBox*>(object());
- if (!cb || !cb->isTristate() || cb->checkState() == Qt::PartiallyChecked)
- return QCheckBox::tr("Check");
- return QCheckBox::tr("Toggle");
- }
- break;
- case RadioButton:
- return QRadioButton::tr("Check");
- default:
- break;
- }
- break;
- }
- return QAccessibleWidget::actionText(action, text, child);
-}
-
-bool QAccessibleButton::doAction(int action, int child, const QVariantList &params)
-{
- Q_ASSERT(child == 0);
- if (!widget()->isEnabled())
- return false;
-
- switch (action) {
- case DefaultAction:
- case Press:
- {
-#ifndef QT_NO_MENU
- QPushButton *pb = qobject_cast<QPushButton*>(object());
- if (pb && pb->menu())
- pb->showMenu();
- else
-#endif
- button()->animateClick();
- }
- return true;
- }
- return QAccessibleWidget::doAction(action, child, params);
-}
-
+/*! \reimp */
QString QAccessibleButton::text(Text t, int child) const
{
Q_ASSERT(child == 0);
QString str;
switch (t) {
case Accelerator:
- {
+ {
#ifndef QT_NO_SHORTCUT
- QPushButton *pb = qobject_cast<QPushButton*>(object());
- if (pb && pb->isDefault())
- str = (QString)QKeySequence(Qt::Key_Enter);
+ QPushButton *pb = qobject_cast<QPushButton*>(object());
+ if (pb && pb->isDefault())
+ str = (QString)QKeySequence(Qt::Key_Enter);
#endif
- if (str.isEmpty())
- str = qt_accHotKey(button()->text());
- }
- break;
+ if (str.isEmpty())
+ str = qt_accHotKey(button()->text());
+ }
+ break;
case Name:
str = widget()->accessibleName();
if (str.isEmpty())
@@ -189,7 +137,7 @@ QString QAccessibleButton::text(Text t, int child) const
QAccessible::State QAccessibleButton::state(int child) const
{
Q_ASSERT(child == 0);
- State state = QAccessibleWidget::state(0);
+ State state = QAccessibleWidget::state();
QAbstractButton *b = button();
QCheckBox *cb = qobject_cast<QCheckBox *>(b);
@@ -212,79 +160,68 @@ QAccessible::State QAccessibleButton::state(int child) const
return state;
}
-int QAccessibleButton::actionCount()
+QStringList QAccessibleButton::actionNames() const
{
- return 1;
-}
-
-void QAccessibleButton::doAction(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- button()->click();
- break;
- }
-}
-
-QString QAccessibleButton::localizedDescription(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- return QLatin1String("Toggles the button.");
- }
- return QLatin1String("Clicks the button.");
- default:
- return QString();
- }
-}
-
-QString QAccessibleButton::name(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- if (button()->isChecked()) {
- return QLatin1String("Uncheck");
+ QStringList names;
+ if (widget()->isEnabled()) {
+ switch (role()) {
+ case ButtonMenu:
+ names << ShowMenuAction;
+ break;
+ case RadioButton:
+ names << CheckAction;
+ break;
+ default:
+ if (button()->isCheckable()) {
+ if (state() & Checked) {
+ names << UncheckAction;
+ } else {
+ // FIXME
+ // QCheckBox *cb = qobject_cast<QCheckBox*>(object());
+ // if (!cb || !cb->isTristate() || cb->checkState() == Qt::PartiallyChecked)
+ names << CheckAction;
+ }
} else {
- return QLatin1String("Check");
+ names << PressAction;
}
+ break;
}
- return QLatin1String("Press");
- default:
- return QString();
}
+ return names;
}
-QString QAccessibleButton::localizedName(int actionIndex)
+void QAccessibleButton::doAction(const QString &actionName)
{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- if (button()->isChecked()) {
- return tr("Uncheck");
- } else {
- return tr("Check");
- }
- }
- return tr("Press");
- default:
- return QString();
+ if (!widget()->isEnabled())
+ return;
+ if (actionName == PressAction ||
+ actionName == ShowMenuAction) {
+#ifndef QT_NO_MENU
+ QPushButton *pb = qobject_cast<QPushButton*>(object());
+ if (pb && pb->menu())
+ pb->showMenu();
+ else
+#endif
+ button()->animateClick();
}
+
+ if (actionName == CheckAction)
+ button()->setChecked(true);
+ if (actionName == UncheckAction)
+ button()->setChecked(false);
}
-QStringList QAccessibleButton::keyBindings(int actionIndex)
+QStringList QAccessibleButton::keyBindingsForAction(const QString &actionName) const
{
- switch (actionIndex) {
+ if (actionName == PressAction) {
#ifndef QT_NO_SHORTCUT
- case 0:
return QStringList() << button()->shortcut().toString();
#endif
- default:
- return QStringList();
}
+ return QStringList();
}
+
#ifndef QT_NO_TOOLBUTTON
/*!
\class QAccessibleToolButton
@@ -383,120 +320,44 @@ int QAccessibleToolButton::actionCount(int) const
return 1;
}
-/*!
- \internal
-
- If \a text is \c Name, then depending on the \a child or the \a
- action, an action text is returned. This is a translated string
- which in English is one of "Press", "Open", or "Set Focus". If \a
- text is not \c Name, an empty string is returned.
-*/
-QString QAccessibleToolButton::actionText(int action, Text text, int) const
-{
- return QString();
-}
-
-/*!
- \internal
+/*
+ The three different tool button types can have the following actions:
+| DelayedPopup | ShowMenuAction + (PressedAction || CheckedAction) |
+| MenuButtonPopup | ShowMenuAction + (PressedAction || CheckedAction) |
+| InstantPopup | ShowMenuAction |
*/
-bool QAccessibleToolButton::doAction(int, int, const QVariantList &)
-{
- return false;
-}
-
-
-int QAccessibleToolButton::actionCount()
-{
- return isSplitButton() ? 2 : 1;
+QStringList QAccessibleToolButton::actionNames() const
+{
+ QStringList names;
+ if (widget()->isEnabled()) {
+ if (toolButton()->menu())
+ names << ShowMenuAction;
+ if (toolButton()->popupMode() != QToolButton::InstantPopup)
+ names << QAccessibleButton::actionNames();
+ }
+ return names;
}
-void QAccessibleToolButton::doAction(int actionIndex)
+void QAccessibleToolButton::doAction(const QString &actionName)
{
if (!widget()->isEnabled())
return;
- switch (actionIndex) {
- case 0:
+ if (actionName == PressAction) {
button()->click();
- break;
- case 1:
- if (isSplitButton()) {
+ } else if (actionName == ShowMenuAction) {
+ if (toolButton()->popupMode() != QToolButton::InstantPopup) {
toolButton()->setDown(true);
#ifndef QT_NO_MENU
toolButton()->showMenu();
#endif
}
- break;
- }
-}
-
-QString QAccessibleToolButton::name(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- if (button()->isChecked()) {
- return QLatin1String("Uncheck");
- } else {
- return QLatin1String("Check");
- }
- }
- return QLatin1String("Press");
- case 1:
- if (isSplitButton())
- return QLatin1String("Show popup menu");
- default:
- return QString();
- }
-}
-
-QString QAccessibleToolButton::localizedName(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- if (button()->isChecked()) {
- return tr("Uncheck");
- } else {
- return tr("Check");
- }
- }
- return tr("Press");
- case 1:
- return tr("Show popup menu");
- default:
- return QString();
- }
-}
-
-QString QAccessibleToolButton::localizedDescription(int actionIndex)
-{
- switch (actionIndex) {
- case 0:
- if (button()->isCheckable()) {
- return tr("Toggles the button.");
- }
- return tr("Clicks the button.");
- case 1:
- return tr("Shows the menu.");
- default:
- return QString();
+ } else {
+ QAccessibleButton::doAction(actionName);
}
-}
-QStringList QAccessibleToolButton::keyBindings(int actionIndex)
-{
- switch (actionIndex) {
-#ifndef QT_NO_SHORTCUT
- case 0:
- return QStringList() << button()->shortcut().toString();
-#endif
- default:
- return QStringList();
- }
}
-
#endif // QT_NO_TOOLBUTTON
/*!
diff --git a/src/plugins/accessible/widgets/simplewidgets.h b/src/plugins/accessible/widgets/simplewidgets.h
index 9ba5d9127e..252d994d1b 100644
--- a/src/plugins/accessible/widgets/simplewidgets.h
+++ b/src/plugins/accessible/widgets/simplewidgets.h
@@ -65,16 +65,9 @@ public:
QString text(Text t, int child = 0) const;
State state(int child = 0) const;
- QString actionText(int action, Text text, int child) const;
- bool doAction(int action, int child, const QVariantList &params);
-
- // QAccessibleActionInterface
- int actionCount();
- void doAction(int actionIndex);
- QString localizedDescription(int actionIndex);
- QString name(int actionIndex);
- QString localizedName(int actionIndex);
- QStringList keyBindings(int actionIndex);
+ QStringList actionNames() const;
+ void doAction(const QString &actionName);
+ QStringList keyBindingsForAction(const QString &actionName) const;
protected:
QAbstractButton *button() const;
@@ -98,12 +91,8 @@ public:
bool doAction(int action, int child, const QVariantList &params);
// QAccessibleActionInterface
- int actionCount();
- void doAction(int actionIndex);
- QString localizedDescription(int actionIndex);
- QString name(int actionIndex);
- QString localizedName(int actionIndex);
- QStringList keyBindings(int actionIndex);
+ QStringList actionNames() const;
+ void doAction(const QString &actionName);
protected:
QToolButton *toolButton() const;
diff --git a/src/plugins/platforms/windows/qwindowsaccessibility.cpp b/src/plugins/platforms/windows/qwindowsaccessibility.cpp
index 7434071bf3..a344b422a5 100644
--- a/src/plugins/platforms/windows/qwindowsaccessibility.cpp
+++ b/src/plugins/platforms/windows/qwindowsaccessibility.cpp
@@ -58,7 +58,7 @@
#include <QtGui/qaccessible.h>
#include <QtGui/qplatformnativeinterface_qpa.h>
#include <QtGui/qwindow.h>
-
+#include <QtGui/qaccessible2.h>
#include <OleAcc.h>
//#include <uiautomationcoreapi.h>
@@ -949,27 +949,35 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accParent(IDispatch** ppdispPa
*/
HRESULT STDMETHODCALLTYPE QWindowsAccessible::accDoDefaultAction(VARIANT varID)
{
+ Q_UNUSED(varID);
showDebug(__FUNCTION__, accessible);
if (!accessible->isValid())
return E_FAIL;
- return accessible->doAction(DefaultAction, varID.lVal, QVariantList()) ? S_OK : S_FALSE;
+ if (QAccessibleActionInterface *actionIface = accessible->actionInterface()) {
+ const QString def = actionIface->actionNames().value(0);
+ if (!def.isEmpty()) {
+ actionIface->doAction(def);
+ return S_OK;
+ }
+ }
+ return S_FALSE;
}
HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accDefaultAction(VARIANT varID, BSTR* pszDefaultAction)
{
+ Q_UNUSED(varID);
showDebug(__FUNCTION__, accessible);
if (!accessible->isValid())
return E_FAIL;
- QString def = accessible->actionText(DefaultAction, Name, varID.lVal);
- if (def.isEmpty()) {
- *pszDefaultAction = 0;
- return S_FALSE;
+ *pszDefaultAction = 0;
+ if (QAccessibleActionInterface *actionIface = accessible->actionInterface()) {
+ const QString def = actionIface->actionNames().value(0);
+ if (!def.isEmpty())
+ *pszDefaultAction = QStringToBSTR(def);
}
-
- *pszDefaultAction = QStringToBSTR(def);
- return S_OK;
+ return *pszDefaultAction ? S_OK : S_FALSE;
}
HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accDescription(VARIANT varID, BSTR* pszDescription)
@@ -1011,18 +1019,21 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accHelpTopic(BSTR *, VARIANT,
HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accKeyboardShortcut(VARIANT varID, BSTR *pszKeyboardShortcut)
{
+ Q_UNUSED(varID);
showDebug(__FUNCTION__, accessible);
if (!accessible->isValid())
return E_FAIL;
- QString sc = accessible->text(Accelerator, varID.lVal);
- if (sc.size()) {
- *pszKeyboardShortcut = QStringToBSTR(sc);
- return S_OK;
- }
-
*pszKeyboardShortcut = 0;
- return S_FALSE;
+ if (QAccessibleActionInterface *actionIface = accessible->actionInterface()) {
+ const QString def = actionIface->actionNames().value(0);
+ if (!def.isEmpty()) {
+ const QString keyBoardShortCut = actionIface->keyBindingsForAction(def).value(0);
+ if (!keyBoardShortCut.isEmpty())
+ *pszKeyboardShortcut = QStringToBSTR(keyBoardShortCut);
+ }
+ }
+ return *pszKeyboardShortcut ? S_OK : S_FALSE;
}
HRESULT STDMETHODCALLTYPE QWindowsAccessible::get_accName(VARIANT varID, BSTR* pszName)
@@ -1106,6 +1117,10 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::accSelect(long flagsSelect, VARIAN
bool res = false;
+/*
+ ### Check for accessibleTableInterface() or accessibleTextInterface()
+
+ ### and if there are no ia2 interfaces we should do nothing??
if (flagsSelect & SELFLAG_TAKEFOCUS)
res = accessible->doAction(SetFocus, varID.lVal, QVariantList());
if (flagsSelect & SELFLAG_TAKESELECTION) {
@@ -1118,7 +1133,7 @@ HRESULT STDMETHODCALLTYPE QWindowsAccessible::accSelect(long flagsSelect, VARIAN
res = accessible->doAction(AddToSelection, varID.lVal, QVariantList());
if (flagsSelect & SELFLAG_REMOVESELECTION)
res = accessible->doAction(RemoveSelection, varID.lVal, QVariantList());
-
+*/
return res ? S_OK : S_FALSE;
}