summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaaccessibility.mm
diff options
context:
space:
mode:
authorMorten Johan Sorvig <morten.sorvig@digia.com>2012-11-01 12:59:11 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-15 16:03:57 +0100
commit65866bcff560abcab329958ce1980284a81ced94 (patch)
treea481f6854838cc0111992c59aaecbc3d8ee536e2 /src/plugins/platforms/cocoa/qcocoaaccessibility.mm
parent2ca6606dca44253df49f4805028a9878e4fa0237 (diff)
Implement EditableText accessibility for Mac.
Change-Id: Ibe03975bafc5a6a420b3bd69dfaa93dbf65c9958 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaaccessibility.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaaccessibility.mm86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm
index 4b897fc211..2a03829b7a 100644
--- a/src/plugins/platforms/cocoa/qcocoaaccessibility.mm
+++ b/src/plugins/platforms/cocoa/qcocoaaccessibility.mm
@@ -39,6 +39,58 @@
**
****************************************************************************/
#include "qcocoaaccessibility.h"
+#include "qcocoaaccessibilityelement.h"
+#include <qaccessible.h>
+#include <qaccessible2.h>
+#include <private/qcore_mac_p.h>
+
+QCococaAccessibility::QCococaAccessibility()
+{
+
+}
+
+QCococaAccessibility::~QCococaAccessibility()
+{
+
+}
+
+void QCococaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
+{
+ QObject *object = event->object();
+ if (!object)
+ return;
+
+ QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(object);
+ if (!interface)
+ return;
+
+ switch (event->type()) {
+ case QAccessible::TextInserted :
+ case QAccessible::TextRemoved :
+ case QAccessible::TextUpdated : {
+ QCocoaAccessibleElement *element = [QCocoaAccessibleElement elementWithInterface : interface parent : nil];
+ NSAccessibilityPostNotification(element, NSAccessibilityValueChangedNotification);
+ break; }
+ default:
+ delete interface;
+ break;
+ }
+}
+
+void QCococaAccessibility::setRootObject(QObject *o)
+{
+ Q_UNUSED(o)
+}
+
+void QCococaAccessibility::initialize()
+{
+
+}
+
+void QCococaAccessibility::cleanup()
+{
+
+}
namespace QCocoaAccessible {
@@ -218,4 +270,38 @@ QString translateAction(NSString *nsAction)
return QString();
}
+bool hasValueAttribute(QAccessibleInterface *interface)
+{
+ const QAccessible::Role qtrole = interface->role();
+ if (qtrole == QAccessible::EditableText) {
+ return true;
+ }
+
+ return false;
+}
+
+id getValueAttribute(QAccessibleInterface *interface)
+{
+ const QAccessible::Role qtrole = interface->role();
+ if (qtrole == QAccessible::EditableText) {
+ if (QAccessibleTextInterface *textInterface = interface->textInterface()) {
+ // VoiceOver will read out the entire text string at once when returning
+ // text as a value. For large text edits the size of the returned string
+ // needs to be limited and text range attributes need to be used instead.
+ // NSTextEdit returns the first sentence as the value, Do the same here:
+ int begin = 0;
+ int end = textInterface->characterCount();
+ // ### call to textAfterOffset hangs. Booo!
+ //if (textInterface->characterCount() > 0)
+ // textInterface->textAfterOffset(0, QAccessible2::SentenceBoundary, &begin, &end);
+
+ QString text = textInterface->text(begin, end);
+ //qDebug() << "text" << begin << end << text;
+ return QCFString::toNSString(text);
+ }
+ }
+
+ return nil;
+}
+
} // namespace QCocoaAccessible