diff --git a/examples/accessibleapps/accessibleproperties.cpp b/examples/accessibleapps/accessibleproperties.cpp index fb91202..fc4b499 100644 --- a/examples/accessibleapps/accessibleproperties.cpp +++ b/examples/accessibleapps/accessibleproperties.cpp @@ -1,376 +1,357 @@ /* Copyright 2012 Sebastian Sauer This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "accessibleproperties.h" #include "qaccessibilityclient/registry.h" using namespace QAccessibleClient; ObjectProperties::ObjectProperties(QObject *parent) : QStandardItemModel(parent) { setColumnCount(2); setHorizontalHeaderLabels( QStringList() << QString("Property") << QString("Value") ); connect(this, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(slotDataChanged(QStandardItem *))); } ObjectProperties::~ObjectProperties() { } void ObjectProperties::slotDataChanged(QStandardItem *item) { if (item == m_textItem) { QString newText = item->data(Qt::EditRole).toString(); m_acc.setText(newText); } else if (item == m_valueItem) { bool couldConvert; double value = item->data(Qt::EditRole).toDouble(&couldConvert); if (couldConvert) { m_acc.setCurrentValue(value); } m_valueItem = 0; //Prevent recursion item->setData(m_acc.currentValue(), Qt::DisplayRole); m_valueItem = item; } } QVariant ObjectProperties::headerData(int section, Qt::Orientation orientation, int role) const { if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { if (section == 0) { return QStringLiteral("Property"); } if (section == 1) { return QStringLiteral("Value"); } } return QVariant(); } QHash ObjectProperties::roleNames() const { QHash roles; roles[NameRole] = "name"; roles[ValueRole] = "value"; return roles; } void ObjectProperties::setAccessibleObject(const QAccessibleClient::AccessibleObject &acc) { beginResetModel(); m_acc = acc; m_textItem = 0; m_valueItem = 0; clear(); if (!acc.isValid()) { endResetModel(); return; } QAccessibleClient::AccessibleObject::Interfaces interfaces = acc.supportedInterfaces(); if (interfaces.testFlag(QAccessibleClient::AccessibleObject::AccessibleInterface)) { QStandardItem *item = append(QString("Accessible")); append(QString("Name"), acc.name(), item); append(QString("Description"), acc.description(), item); append(QString("Role"), acc.roleName(), item); append(QString("LocalizedRole"), acc.localizedRoleName(), item); append(QString("Visible"), acc.isVisible(), item); append(QString("Default"), acc.isDefault(), item); - append(QString("State"), stateString(acc), item); + append(QString("State"), acc.stateString(), item); append(tr("Url"), acc.url(), item); AccessibleObject parent = acc.parent(); if (parent.isValid()) append(tr("Parent"), parent.url(), item); int childCount = acc.childCount(); QStandardItem *children = append(QString("Children"), acc.childCount(), item); for (int i = 0; i < childCount; ++i) { AccessibleObject child = acc.child(i); if (!child.isValid()) { append(QLatin1String("Broken child"), QString::number(i), children); } else { append(child.name().isEmpty() ? tr("[%1]").arg(child.roleName()) : child.name(), child.url(), children); } } //GetAttributes } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ComponentInterface)) { QStandardItem *item = append(QString("Component")); append(QString("BoundingRect"), acc.boundingRect(), item); append(QString("Layer"), acc.layer(), item); append(QString("MDIZOrder"), acc.mdiZOrder(), item); append(QString("Alpha"), acc.alpha(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::CollectionInterface)) { QStandardItem *item = append(QString("Collection")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ApplicationInterface)) { QStandardItem *item = append(QString("Application")); append(QString("ToolkitName"), acc.appToolkitName(), item); append(QString("Version"), acc.appVersion(), item); append(QString("Id"), acc.appId(), item); append(QString("Locale"), acc.appLocale(), item); append(QString("BusAddress"), acc.appBusAddress(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::DocumentInterface)) { QStandardItem *item = append(QString("Document")); Q_UNUSED(item); //GetLocale //GetAttributeValue //GetAttributes } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EditableTextInterface)) { QStandardItem *item = append(QString("EditableText")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::HyperlinkInterface)) { QStandardItem *item = append(QString("Hyperlink")); Q_UNUSED(item); /* 0 */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::HypertextInterface)) { QStandardItem *item = append(QString("Hypertext")); Q_UNUSED(item); /* */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ImageInterface)) { QStandardItem *item = append(QString("Image")); append(QString("Description"), acc.imageDescription(), item); append(QString("Locale"), acc.imageLocale(), item); append(QString("Rect"), acc.imageRect(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::SelectionInterface)) { QStandardItem *item = append(QString("Selection")); Q_FOREACH(const QAccessibleClient::AccessibleObject &s, acc.selection()) { append(s.name(), s.role(), item); } } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::TableInterface)) { QStandardItem *item = append(QString("Table")); Q_UNUSED(item); /* */ } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::TextInterface)) { QStandardItem *item = append(QString("Text")); int offset = acc.caretOffset(); append(QString("CaretOffset"), offset, item); append(QString("CharacterCount"), acc.characterCount(), item); append(QString("CharacterRect"), acc.characterRect(offset), item); QString text = acc.text(); if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EditableTextInterface)) { append(QString("Text"), text, item, &m_textItem); } else { append(QString("Text"), text, item); } QList< QPair > selections = acc.textSelections(); QStandardItem *selectionsItem = append(QString("Selections"), selections.count(), item); for (int i = 0; i < selections.count(); ++i) { QPair sel = selections[i]; int startOffset = sel.first; int endOffset = sel.second; Q_ASSERT(startOffset <= endOffset); append( QString("%1:%2").arg(startOffset).arg(endOffset), text.mid(startOffset, endOffset - startOffset), selectionsItem ); } } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ValueInterface)) { QStandardItem *item = append(QString("Value")); append(QString("Current"), acc.currentValue(), item, &m_valueItem); append(QString("Minimum"), acc.minimumValue(), item); append(QString("Maximum"), acc.maximumValue(), item); append(QString("Increment"), acc.minimumValueIncrement(), item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::SocketInterface)) { QStandardItem *item = append(QString("Socket")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventKeyboardInterface)) { QStandardItem *item = append(QString("EventKeyboard")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventMouseInterface)) { QStandardItem *item = append(QString("EventMouse")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventObjectInterface)) { QStandardItem *item = append(QString("EventObject")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventWindowInterface)) { QStandardItem *item = append(QString("EventWindow")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::EventFocusInterface)) { QStandardItem *item = append(QString("EventFocus")); Q_UNUSED(item); } if (interfaces.testFlag(QAccessibleClient::AccessibleObject::ActionInterface)) { QStandardItem *item = append(QString("Action")); Q_FOREACH(const QSharedPointer &a, acc.actions()) { QStandardItem *nameItem = new QStandardItem(a->text()); QStandardItem *valueItem = new QStandardItem(a->whatsThis()); nameItem->setEditable(false); valueItem->setEditable(false); item->appendRow(QList() << nameItem << valueItem); } } endResetModel(); } void ObjectProperties::doubleClicked(const QModelIndex &index) { if (!index.isValid() || !index.parent().isValid() || index.parent().data().toString() != QLatin1String("Action")) return; foreach (const QSharedPointer &action, m_acc.actions()) { if (action->text() == data(index).toString()) { action->trigger(); return; } } } QStandardItem* ObjectProperties::append(const QString &name, const QVariant &value, QStandardItem *parentItem, QStandardItem **changeHandler) { if (!parentItem) parentItem = invisibleRootItem(); QStandardItem *nameItem = new QStandardItem(name); QString text; switch (value.type()) { case QVariant::Point: { QPoint p = value.toPoint(); text = QString("%1:%2").arg(p.x()).arg(p.y()); } break; case QVariant::PointF: { QPointF p = value.toPointF(); text = QString("%1:%2").arg(p.x()).arg(p.y()); } break; case QVariant::Rect: { QRect r = value.toRect(); text = QString("%1:%2 %3x%4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height()); } break; case QVariant::RectF: { QRectF r = value.toRectF(); text = QString("%1:%2 %3x%4").arg(r.left()).arg(r.top()).arg(r.width()).arg(r.height()); } break; default: text = value.toString(); break; } QStandardItem *valueItem = new QStandardItem(text); parentItem->appendRow(QList() << nameItem << valueItem); nameItem->setEditable(false); if (changeHandler) { *changeHandler = valueItem; valueItem->setEditable(true); } else { valueItem->setEditable(false); } return nameItem; } - -QString ObjectProperties::stateString(const QAccessibleClient::AccessibleObject &acc) -{ - QStringList s; - if (acc.isActive()) s << "Active"; - if (acc.isCheckable()) s << "Checkable"; - if (acc.isChecked()) s << "Checked"; - if (acc.isEditable()) s << "Editable"; - if (acc.isExpandable()) s << "Expandable"; - if (acc.isExpanded()) s << "Expanded"; - if (acc.isFocusable()) s << "Focusable"; - if (acc.isFocused()) s << "Focused"; - if (acc.isMultiLine()) s << "MultiLine"; - if (acc.isSelectable()) s << "Selectable"; - if (acc.isSelected()) s << "Selected"; - if (acc.isSensitive()) s << "Sensitive"; - if (acc.isSingleLine()) s << "SingleLine"; - return s.join(","); -} diff --git a/src/qaccessibilityclient/accessibleobject.cpp b/src/qaccessibilityclient/accessibleobject.cpp index f94df31..6297884 100644 --- a/src/qaccessibilityclient/accessibleobject.cpp +++ b/src/qaccessibilityclient/accessibleobject.cpp @@ -1,541 +1,560 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "accessibleobject.h" #include #include #include "accessibleobject_p.h" #include "registry_p.h" #include using namespace QAccessibleClient; AccessibleObject::AccessibleObject() :d(0) { } AccessibleObject::AccessibleObject(RegistryPrivate *registryPrivate, const QString &service, const QString &path) :d(0) { Q_ASSERT(registryPrivate); Q_ASSERT(!service.isEmpty()); Q_ASSERT(!path.isEmpty()); if (registryPrivate->m_cache) { const QString id = path + service; d = registryPrivate->m_cache->get(id); if (!d) { d = QSharedPointer(new AccessibleObjectPrivate(registryPrivate, service, path)); registryPrivate->m_cache->add(id, d); } } else { d = QSharedPointer(new AccessibleObjectPrivate(registryPrivate, service, path)); } } AccessibleObject::AccessibleObject(const QSharedPointer &dd) :d(dd) { } AccessibleObject::AccessibleObject(const AccessibleObject &other) : d(other.d) { } AccessibleObject::~AccessibleObject() { } QString AccessibleObject::id() const { if (!d || !d->registryPrivate) return QString(); return d->path + d->service; } QUrl AccessibleObject::url() const { if (!d || !d->registryPrivate) return QUrl(); QUrl u; u.setScheme(d->registryPrivate->ACCESSIBLE_OBJECT_SCHEME_STRING); u.setPath(d->path); u.setFragment(d->service); return u; } bool AccessibleObject::isValid() const { return d && d->registryPrivate && (!d->service.isEmpty()) && (!d->path.isEmpty()) && (d->path != QLatin1String("/org/a11y/atspi/null")); } AccessibleObject &AccessibleObject::operator=(const AccessibleObject &other) { d = other.d; return *this; } bool AccessibleObject::operator==(const AccessibleObject &other) const { return (d == other.d) || (d && other.d && *d == *other.d); } AccessibleObject AccessibleObject::parent() const { return d->registryPrivate->parentAccessible(*this); } QList AccessibleObject::children() const { return d->registryPrivate->children(*this); } QVector< QList > AccessibleObject::children(const QList &roles) const { QVector< QList > result(roles.count()); QList all = children(); for(int i = 0; i < all.count(); ++i) { const AccessibleObject &child = all[i]; int index = roles.indexOf(child.role()); if (index < 0) continue; result[index].append(child); } return result; } int AccessibleObject::childCount() const { return d->registryPrivate->childCount(*this); } AccessibleObject AccessibleObject::child(int index) const { return d->registryPrivate->child(*this, index); } int AccessibleObject::indexInParent() const { return d->registryPrivate->indexInParent(*this); } QString AccessibleObject::name() const { return d->registryPrivate->name(*this); } QString AccessibleObject::description() const { return d->registryPrivate->description(*this); } AccessibleObject::Role AccessibleObject::role() const { return d->registryPrivate->role(*this); } QString AccessibleObject::roleName() const { return d->registryPrivate->roleName(*this); } QString AccessibleObject::localizedRoleName() const { return d->registryPrivate->localizedRoleName(*this); } int AccessibleObject::layer() const { return d->registryPrivate->layer(*this); } int AccessibleObject::mdiZOrder() const { return d->registryPrivate->mdiZOrder(*this); } double AccessibleObject::alpha() const { return d->registryPrivate->alpha(*this); } QRect AccessibleObject::boundingRect() const { if( supportedInterfaces() & AccessibleObject::ComponentInterface ){ return d->registryPrivate->boundingRect(*this); } else { qWarning() << "boundingRect called on accessible that does not implement component"; return QRect(); } } QRect AccessibleObject::characterRect(int offset) const { if( supportedInterfaces() & AccessibleObject::TextInterface ){ return d->registryPrivate->characterRect(*this, offset); } else { qWarning() << "characterRect called on accessible that does not implement text"; return QRect(); } } AccessibleObject::Interfaces AccessibleObject::supportedInterfaces() const { return d->registryPrivate->supportedInterfaces(*this); } int AccessibleObject::caretOffset() const { if( supportedInterfaces() & AccessibleObject::TextInterface ){ return d->registryPrivate->caretOffset(*this); } else { qWarning() << "caretOffset called on accessible that does not implement text"; return 0; } } int AccessibleObject::characterCount() const { if( supportedInterfaces() & AccessibleObject::TextInterface ){ return d->registryPrivate->characterCount(*this); } else { qWarning() << "characterCount called on accessible that does not implement text"; return 0; } } QString AccessibleObject::text(int startOffset, int endOffset) const { if( supportedInterfaces() & AccessibleObject::TextInterface ) return d->registryPrivate->text(*this, startOffset, endOffset); qWarning() << "text called on accessible that does not implement text"; return QString(); } QString AccessibleObject::textWithBoundary(int offset, TextBoundary boundary, int *startOffset, int *endOffset) const { if (supportedInterfaces() & AccessibleObject::TextInterface) return d->registryPrivate->textWithBoundary(*this, offset, boundary, startOffset, endOffset); qWarning() << "text called on accessible that does not implement text"; return QString(); } bool AccessibleObject::setText(const QString &text) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->setText(*this, text); qWarning() << "setText called on accessible that does not implement editableText"; return false; } bool AccessibleObject::insertText(const QString &text, int position, int length) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->insertText(*this, text, position, length); qWarning() << "insertText called on accessible that does not implement editableText"; return false; } bool AccessibleObject::copyText(int startPos, int endPos) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->copyText(*this, startPos, endPos); qWarning() << "copyText called on accessible that does not implement editableText"; return false; } bool AccessibleObject::cutText(int startPos, int endPos) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->cutText(*this, startPos, endPos); qWarning() << "cutText called on accessible that does not implement editableText"; return false; } bool AccessibleObject::deleteText(int startPos, int endPos) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->deleteText(*this, startPos, endPos); qWarning() << "deleteText called on accessible that does not implement editableText"; return false; } bool AccessibleObject::pasteText(int position) { if( supportedInterfaces() & AccessibleObject::EditableTextInterface ) return d->registryPrivate->pasteText(*this, position); qWarning() << "pasteText called on accessible that does not implement editableText"; return false; } QList< QPair > AccessibleObject::textSelections() const { if(supportedInterfaces() & AccessibleObject::Text) return d->registryPrivate->textSelections(*this); qWarning() << "textSelections called on accessible that does not implement text"; return QList< QPair >(); } void AccessibleObject::setTextSelections(const QList< QPair > &selections) { if(supportedInterfaces() & AccessibleObject::Text) return d->registryPrivate->setTextSelections(*this, selections); qWarning() << "setTextSelections called on accessible that does not implement text"; } QPoint AccessibleObject::focusPoint() const { Interfaces ifaces = supportedInterfaces(); if (ifaces & TextInterface) { int offset = caretOffset(); QRect r = characterRect(offset); if (r.x() != 0 || r.y() != 0) return r.center(); } if (ifaces & ComponentInterface) { QRect r = boundingRect(); if (!r.isNull()) return r.center(); } AccessibleObject p = parent(); if (p.isValid()) return p.focusPoint(); // recursive return QPoint(); } AccessibleObject AccessibleObject::application() const { return d->registryPrivate->application(*this); } QString AccessibleObject::appToolkitName() const { return d->registryPrivate->appToolkitName(*this); } QString AccessibleObject::appVersion() const { return d->registryPrivate->appVersion(*this); } int AccessibleObject::appId() const { return d->registryPrivate->appId(*this); } QString AccessibleObject::appLocale(LocaleType lctype) const { return d->registryPrivate->appLocale(*this, lctype); } QString AccessibleObject::appBusAddress() const { return d->registryPrivate->appBusAddress(*this); } double AccessibleObject::minimumValue() const { return d->registryPrivate->minimumValue(*this); } double AccessibleObject::maximumValue() const { return d->registryPrivate->maximumValue(*this); } double AccessibleObject::minimumValueIncrement() const { return d->registryPrivate->minimumValueIncrement(*this); } double AccessibleObject::currentValue() const { return d->registryPrivate->currentValue(*this); } bool AccessibleObject::setCurrentValue(double value) { return d->registryPrivate->setCurrentValue(*this, value); } QList AccessibleObject::selection() const { return d->registryPrivate->selection(*this); } QString AccessibleObject::imageDescription() const { return d->registryPrivate->imageDescription(*this); } QString AccessibleObject::imageLocale() const { return d->registryPrivate->imageLocale(*this); } QRect AccessibleObject::imageRect() const { return d->registryPrivate->imageRect(*this); } QVector< QSharedPointer > AccessibleObject::actions() const { // Actions in atspi are supposed to be static what means they cannot change in // between (e.g. actions removed or added or edited) so we can safely just // fetch them only once and store the result for the life-time of the object, if (!d->actionsFetched) { d->actionsFetched = true; d->actions = d->registryPrivate->actions(*this); } return d->actions; } bool AccessibleObject::hasSelectableText() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SELECTABLE_TEXT); } bool AccessibleObject::hasToolTip() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_HAS_TOOLTIP); } bool AccessibleObject::isActive() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_ACTIVE); } bool AccessibleObject::isCheckable() const { //FIXME: Find better AccessibleObject::isCheckable //return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_); Role role = d->registryPrivate->role(*this); if (role == AccessibleObject::CheckBox || role == AccessibleObject::CheckableMenuItem || role == AccessibleObject::RadioButton || role == AccessibleObject::RadioMenuItem || role == AccessibleObject::ToggleButton) return true; return false; } bool AccessibleObject::isChecked() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_CHECKED); } bool AccessibleObject::isDefunct() const { return d->defunct; } bool AccessibleObject::isDefault() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_IS_DEFAULT); } bool AccessibleObject::isEditable() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_EDITABLE); } bool AccessibleObject::isEnabled() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_ENABLED); } bool AccessibleObject::isExpandable() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_EXPANDABLE); } bool AccessibleObject::isExpanded() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_EXPANDED); } bool AccessibleObject::isFocusable() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_FOCUSABLE); } bool AccessibleObject::isFocused() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_FOCUSED); } bool AccessibleObject::isMultiLine() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_MULTI_LINE); } bool AccessibleObject::isSelectable() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SELECTABLE); } bool AccessibleObject::isSelected() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SELECTED); } bool AccessibleObject::isSensitive() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SENSITIVE); } bool AccessibleObject::isSingleLine() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SINGLE_LINE); } +QString AccessibleObject::stateString() const +{ + QStringList s; + if (isActive()) s << QStringLiteral("Active"); + if (isCheckable()) s << QStringLiteral("Checkable"); + if (isChecked()) s << QStringLiteral("Checked"); + if (isEditable()) s << QStringLiteral("Editable"); + if (isExpandable()) s << QStringLiteral("Expandable"); + if (isExpanded()) s << QStringLiteral("Expanded"); + if (isFocusable()) s << QStringLiteral("Focusable"); + if (isFocused()) s << QStringLiteral("Focused"); + if (isMultiLine()) s << QStringLiteral("MultiLine"); + if (isSelectable()) s << QStringLiteral("Selectable"); + if (isSelected()) s << QStringLiteral("Selected"); + if (isSensitive()) s << QStringLiteral("Sensitive"); + if (isSingleLine()) s << QStringLiteral("SingleLine"); + return s.join(QLatin1String(", ")); +} + bool AccessibleObject::isVisible() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_VISIBLE); } bool AccessibleObject::supportsAutocompletion() const { return d->registryPrivate->state(*this) & (quint64(1) << ATSPI_STATE_SUPPORTS_AUTOCOMPLETION); } #ifndef QT_NO_DEBUG_STREAM QACCESSIBILITYCLIENT_EXPORT QDebug QAccessibleClient::operator<<(QDebug d, const AccessibleObject &object) { d.nospace(); d << "AccessibleObject("; if (object.d) { d << "service=" << object.d->service; d << " path=" << object.d->path; d << " name=" << object.name(); } else { d << "invalid"; } d << ")"; return d.space(); } #endif diff --git a/src/qaccessibilityclient/accessibleobject.h b/src/qaccessibilityclient/accessibleobject.h index 25bd550..f7d5cd8 100644 --- a/src/qaccessibilityclient/accessibleobject.h +++ b/src/qaccessibilityclient/accessibleobject.h @@ -1,772 +1,779 @@ /* Copyright 2012 Frederik Gladhorn This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H #define QACCESSIBILITYCLIENT_ACCESSIBLEOBJECT_H #include namespace QAccessibleClient { class AccessibleObject; } #include #include #include #include "qaccessibilityclient_export.h" namespace QAccessibleClient { class AccessibleObjectPrivate; class RegistryPrivate; #ifndef QT_NO_DEBUG_STREAM QACCESSIBILITYCLIENT_EXPORT QDebug operator<<(QDebug, const AccessibleObject &); #endif /** This class represents an accessible object. An accessible object equals usually a visible widget or some kind of other element the user can interact with but can also present a not visible object that offers certain functionality like for example actions which can be triggered. It is implicitly shared and only created by the library. */ class QACCESSIBILITYCLIENT_EXPORT AccessibleObject { public: /** This enum describes the different interfaces that an AccessibleObject can implement. Each AccessibleObject must implement the AccessibleInterface, otherwise it is invalid. All other interfaces are optional. If the ActionInterface is implement the object will have a list of actions that can be invoked. */ enum Interface { NoInterface = 0x0, AccessibleInterface = 0x1, CacheInterface = 0x2, ActionInterface = 0x4, ApplicationInterface = 0x8, CollectionInterface = 0x10, ComponentInterface = 0x20, DocumentInterface = 0x40, EditableTextInterface = 0x80, EventKeyboardInterface = 0x100, EventMouseInterface = 0x200, EventObjectInterface = 0x400, HyperlinkInterface = 0x800, HypertextInterface = 0x1000, ImageInterface = 0x2000, SelectionInterface = 0x4000, TableInterface = 0x8000, TextInterface = 0x10000, ValueInterface = 0x20000, SocketInterface = 0x40000, EventWindowInterface = 0x80000, EventFocusInterface = 0x100000, InvalidInterface = 0x80000000 }; Q_DECLARE_FLAGS(Interfaces, Interface) /** The role indicates the type of UI element that an AccessibleObject represents. */ enum Role { NoRole, /*!< The object is invalid and has no role set. This is generally a bug. */ CheckBox, CheckableMenuItem, ColumnHeader, ComboBox, DesktopFrame, Dial, Dialog, Filler, Frame, Icon, Label, ListView, ListItem, Menu, MenuBar, MenuItem, Tab, TabContainer, PasswordText, PopupMenu, ProgressBar, Button, RadioButton, RadioMenuItem, RowHeader, ScrollBar, ScrollArea, Separator, Slider, SpinButton, StatusBar, TableView, TableCell, TableColumnHeader, TableColumn, TableRowHeader, TableRow, Terminal, Text, ToggleButton, ToolBar, ToolTip, TreeView, Window, TreeItem // Roles in Qt, I don't think we want those // TitleBar = 0x00000001, // Grip = 0x00000004, // Sound = 0x00000005, // Cursor = 0x00000006, // Caret = 0x00000007, // AlertMessage = 0x00000008, // Client = 0x0000000A, // Application = 0x0000000E, // Document = 0x0000000F, // Pane = 0x00000010, // Chart = 0x00000011, // Border = 0x00000013, // Grouping = 0x00000014, // Cell = 0x0000001D, // Link = 0x0000001E, // HelpBalloon = 0x0000001F, // Assistant = 0x00000020, // PageTab = 0x00000025, // PropertyPage = 0x00000026, // Indicator = 0x00000027, // Graphic = 0x00000028, // StaticText = 0x00000029, // EditableText = 0x0000002A, // Editable, selectable, etc. // HotkeyField = 0x00000032, // SpinBox = 0x00000034, // Canvas = 0x00000035, // Animation = 0x00000036, // Equation = 0x00000037, // ButtonDropDown = 0x00000038, // ButtonMenu = 0x00000039, // ButtonDropGrid = 0x0000003A, // Whitespace = 0x0000003B, // PageTabList = 0x0000003C, // Clock = 0x0000003D, // Splitter = 0x0000003E, // LayeredPane = 0x00000080, }; /** \brief The TextBoundaries enum represents the different boundaries when asking for text at a certain offset. */ enum TextBoundary { CharBoundary, WordStartBoundary, WordEndBoundary, SentenceStartBoundary, SentenceEndBoundary, LineStartBoundary, LineEndBoundary }; /** \brief Construct an invalid AccessibleObject. */ AccessibleObject(); /** \brief Copy constructor. */ AccessibleObject(const AccessibleObject &other); /** Destroys the AccessibleObject */ ~AccessibleObject(); /** Assignment operator */ AccessibleObject &operator=(const AccessibleObject &other); /** Comparison operator */ bool operator==(const AccessibleObject &other) const; /** Inequality operator */ inline bool operator!=(const AccessibleObject &other) const { return !operator==(other); } /** \brief Returns a unique identifier for the object. */ QString id() const; /** \brief Returns a QUrl that references the AccessibleObject. This can be used to serialize/unserialize an AccessibleObject to pass it around as string and restore the AccessibleObject by using Registry::accessibleFromUrl later on. The returned QUrl returns a scheme of "accessibleobject", the dbus path as url path and the dbus service as url fragment. */ QUrl url() const; /** \brief Returns true if this object is valid. Invalid objects are for example returned when asking for the parent of the top most item, or for a child that is out of range. */ bool isValid() const; /** \brief Returns this object's parent. \return The parent AccessibleObject */ AccessibleObject parent() const; /** \brief Returns this accessible's index in it's parent's list of children. \return index */ int indexInParent() const; /** \brief Returns this accessible's children in a list. \return children */ QList children() const; /** \brief Returns this accessible's children according to there roles. \param roles The list of roles to query. \return A vector that contains the children of this object according to there roles. The number of vector-items equals to the number and sorting of the roles items. Example code demonstrating usage: \code QList roles; roles << Label << CheckBox; QVector< QList > c = children(roles); Q_ASSERT(c.count() == roles.count()); Q_ASSERT(c[0].isEmpty() || c[0].first().role() == Label); Q_ASSERT(c[1].isEmpty() || c[1].first().role() == CheckBox); \endcode */ QVector< QList > children(const QList &roles) const; /** \brief Returns the number of children for this accessible. \return number of children */ int childCount() const; /** \brief Returns a specific child at position \a index. The list of children is 0-based. \return number of children */ AccessibleObject child(int index) const; /** \brief Returns the name of this accessible. The name is a short descriptive one or two words. It is localized. */ QString name() const; /** \brief Returns the description for this accessible. The description is more of an explanation than the name. This can be a sentence. The string is localized. */ QString description() const; /** \brief Returns the role as integer value of this accessible. */ Role role() const; /** \brief Returns the name of the role of this accessible. This name is not localized to allow tools to work with the english string. */ QString roleName() const; /** \brief Returns the name of the role of this accessible. This name is localized and can be presented to the user. */ QString localizedRoleName() const; /** \brief The ComponentLayer in which this object resides. */ int layer() const; /** \brief Obtain the relative stacking order (i.e. 'Z' order) of an object. Larger values indicate that an object is on "top" of the stack, therefore objects with smaller MDIZOrder may be obscured by objects with a larger MDIZOrder, but not vice-versa. */ int mdiZOrder() const; /** \brief Obtain the alpha value of the component. An alpha value of 1.0 or greater indicates that the object is fully opaque, and an alpha value of 0.0 indicates that the object is fully transparent. Negative alpha values have no defined meaning at this time. Alpha values are used in conjunction with Z-order calculations to determine whether an object wholly or partially obscures another object's visual intersection, in the event that their bounds intersect. */ double alpha() const; /** \brief Returns a bounding rectangle for the accessible. It returns a QRect that bounds the accessible. This can be used to get the focus coordinates. \return QRect that bounds the accessible. */ QRect boundingRect() const; /** \brief Returns a bounding rectangle for the character at position \a offset. This function is only supported for accessibles that implement the text interface. It will return an empty rectangle for invalid offsets or accessibles. \return QRect that bounds the character. */ QRect characterRect(int offset) const; /** \brief Returns List of interfaces supported by the accessible. This function provides a list of accessibile interfaces that are implemented by an accessible object. This can be used to avoid calling functions that are not supported by the accessible. \return QStringList that contains list of supported interfaces */ Interfaces supportedInterfaces() const; /** \brief Returns the offset of the caret from the beginning of the text. This function provides the current offset of the caret from the beginning of the text in an accessible that implements org.a11y.atspi.Text. \return Caret Offset as an integer */ int caretOffset() const; /** \brief Returns the number of characters. \return Number of characters. */ int characterCount() const; /** \brief Returns a list of selections the text has. Code to demonstrate usage: \code QList< QPair > sel = acc.textSelections(); int startOffset = sel[0].first; int endOffset = sel[0].second; QString allText = acc.text(); QString selText = allText.mid(startOffset, endOffset - startOffset); \endcode \return The list of selections where every item in that list is a pair of integers representing startOffset and endOffset of the selection. */ QList< QPair > textSelections() const; /** Set text \a selections, usually only one selection will be set, use a list containing one QPair with the start and end offsets for that. */ void setTextSelections(const QList< QPair > &selections); /** \brief Returns the text of the TextInterface. This function provides the current text as displayed by the org.a11y.atspi.Text TextInterface component. \param startOffset The start caret offset to return the text from. \param endOffset The end caret offset to return the text from. If -1 then the endOffset is the end of the string what means all characters are included. \return The text as displayed by the TextInterface. */ QString text(int startOffset = 0, int endOffset = -1) const; /** \brief Returns the text of the TextInterface by boundary. Especially for larger text fields it may be more performant and easier to query the text at a certain position instead of the full text. For example the line where the cursor is currently can be retrieved with this function in a convenient way. \param offset is the position of the requested text. \param startOffset returns the beginning of the offset, for example the start of the line when asking for line boundaries. \param endOffset returns the end of the text section \return the text at the offset. */ QString textWithBoundary(int offset, TextBoundary boundary, int *startOffset = 0, int *endOffset = 0) const; /** \brief Set the text of the EditableTextInterface. \param text The text to set. \return true on success and false on error. */ bool setText(const QString &text); /** \brief Insert the text into the EditableTextInterface. \param text The text to insert. \param position The caret position at which to insert the text. \param length The length of the text to insert. \return true on success and false on error. */ bool insertText(const QString &text, int position = 0, int length = -1); /** \brief Copy the text from the EditableTextInterface into the clipboard. \param startPos The caret position from which to start to copy the text from. \param endPos The caret position from which to end to copy the text from. \return true on success and false on error. */ bool copyText(int startPos, int endPos); /** \brief Cut the text from the EditableTextInterface into the clipboard. \param startPos The caret position from which to start to cut the text from. \param endPos The caret position from which to end to cut the text from. \return true on success and false on error. */ bool cutText(int startPos, int endPos); /** \brief Delete the text from the EditableTextInterface. \param startPos The caret position from which to start to delete the text. \param endPos The caret position from which to end to delete the text. \return true on success and false on error. */ bool deleteText(int startPos, int endPos); /** \brief Paste the text from the clipboard into the EditableTextInterface. \param position The caret position at which to insert the text into. \return true on success and false on error. */ bool pasteText(int position); /** \brief Returns focus-point of the object \return The Focus Point of the object */ QPoint focusPoint() const; /** \brief Returns the application object. \return The top-level application object that expose an org.a11y.atspi.Application accessibility interface. */ AccessibleObject application() const; /** \brief Returns the toolkit name. \return The tookit name. This can be for example "Qt" or "gtk". */ QString appToolkitName() const; /** \brief Returns the toolkit version. \return The tookit version. This can be for example "4.8.3" for Qt 4.8.3. */ QString appVersion() const; /** \brief Returns the unique application identifier. \return The app id. The identifier will not last over session and everytime the app quits and restarts it gets another identifier that persists as long as the application is running. */ int appId() const; /** The type of locale */ enum LocaleType { LocaleTypeMessages, LocaleTypeCollate, LocaleTypeCType, LocaleTypeMonetary, LocaleTypeNumeric, LocaleTypeTime }; /** \brief The application locale. \param lctype The \a LocaleType for which the locale is queried. \return A string compliant with the POSIX standard for locale description. */ QString appLocale(LocaleType lctype = LocaleTypeMessages) const; /** \brief The application dbus address. */ QString appBusAddress() const; /** \brief The minimum value allowed by this valuator. If both, the \a minimumValue and \a maximumValue, are zero then there is no minimum or maximum values. The \a currentValue has no range restrictions. */ double minimumValue() const; /** \brief The maximum value allowed by this valuator. If both, the \a minimumValue and \a maximumValue, are zero then there is no minimum or maximum values. The \a currentValue has no range restrictions. */ double maximumValue() const; /** \brief The smallest incremental change which this valuator allows. This is a helper value to know in what steps the \a currentValue is incremented or decremented. If 0, the incremental changes to the valuator are limited only by the precision of a double precision value on the platform. */ double minimumValueIncrement() const; /** \brief The current value of the valuator. This is the value the org.a11y.atspi.Value accessibility interface has. */ double currentValue() const; /** \brief Set the value of the valuator. \param value the value to set. \return true on success and false on error. */ bool setCurrentValue(const double value); /** \brief Returns the selection of accessible objects. */ QList selection() const; /** \brief A description text of the image. It is recommended that imageDescription be the shorter of the available image descriptions, for instance "alt text" in HTML images, and a longer description be provided in Accessible::accessible-description, if available. A short, one or two word label for the image should be provided in Accessible::accessible-name. \return A UTF-8 string providing a textual description of what is visually depicted in the image. */ QString imageDescription() const; /** \brief The locale of the image. \return A string corresponding to the POSIX LC_MESSAGES locale used by the imageDescription. */ QString imageLocale() const; /** \brief The image boundaries. Obtain a bounding box which entirely contains the image contents, as displayed on screen. The bounds returned do not account for any viewport clipping or the fact that the image may be partially or wholly obscured by other onscreen content. This method returns the bounds of the current onscreen view, and not the nominal size of the source data in the event that the original image has been rescaled.\ \return A BoundingBox enclosing the image's onscreen representation. */ QRect imageRect() const; /** \brief Returns a list of actions supported by this accessible. Just trigger() the action to execute the underlying method at the accessible. */ QVector< QSharedPointer > actions() const; // states /// Returns if the AccessibleObject is currently active bool isActive() const; /// Returns if the AccessibleObject is checkable (often indicates a check action) bool isCheckable() const; /// Returns if the AccessibleObject is currently checked bool isChecked() const; /// Returns if the AccessibleObject is defunct - that means it does not properly respont to requests /// and should be ignored for accessibility purposes bool isDefunct() const; /// Returns if the AccessibleObject is an editable text bool isEditable() const; /// Returns if the AccessibleObject is currently enabled bool isEnabled() const; /// Returns if the AccessibleObject can be expanded to show more information bool isExpandable() const; /// Returns if the AccessibleObject is currently expanded bool isExpanded() const; /// Returns if the AccessibleObject is focusable bool isFocusable() const; /// Returns if the AccessibleObject is currently focused bool isFocused() const; /// Returns if the AccessibleObject is a multi line text edit bool isMultiLine() const; /// Returns if the AccessibleObject is selectable bool isSelectable() const; /// Returns if the AccessibleObject is currently selected bool isSelected() const; /// Returns if the AccessibleObject reacts to input events bool isSensitive() const; /// Returns if the AccessibleObject is a single line text edit bool isSingleLine() const; + /** + \brief Return a string representing states of this object. + + This is useful for debugging applications. + */ + QString stateString() const; + /* * \internal * \brief isTransient marks an object as being unreliable in that it can quickly disappear or change * * This is mostly a hint that the object should not be cached. * \return true if the object is transient */ // bool isTransient() const; /// Returns if the AccessibleObject is currently visible (it can still be off the screen, /// but there is nothing preventing the user from seeing it in general) bool isVisible() const; /* * \internal * \brief managesDescendants marks an object as being responsible for its children * * This is to notify that this object handles signals for it's children. * The property is typically used for tables and lists or other collection objects. * \return true if the object is transient */ // bool managesDescendants() const; // bool isRequired() const; // bool isAnimated() const; // bool isInvalidEntry() const; /// Returns if the AccessibleObject is the default widget (e.g. a button in a dialog) bool isDefault() const; // bool isVisited() const; /// Returns if the AccessibleObject allows text selections bool hasSelectableText() const; /// Returns if the AccessibleObject has a tool tip bool hasToolTip() const; /// Returns if the AccessibleObject supports automatic text completion bool supportsAutocompletion() const; private: AccessibleObject(RegistryPrivate *reg, const QString &service, const QString &path); AccessibleObject(const QSharedPointer &dd); QSharedPointer d; friend class Registry; friend class RegistryPrivate; friend class CacheWeakStrategy; friend class CacheStrongStrategy; #ifndef QT_NO_DEBUG_STREAM friend QDebug QAccessibleClient::operator<<(QDebug, const AccessibleObject &); #endif friend uint qHash(const QAccessibleClient::AccessibleObject& object) { return qHash(object.d); } }; } Q_DECLARE_METATYPE(QAccessibleClient::AccessibleObject) #endif