summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/accessible/iaccessible2.cpp
diff options
context:
space:
mode:
authorJan-Arve Saether <jan-arve.saether@nokia.com>2012-03-07 11:59:30 +0100
committerQt by Nokia <qt-info@nokia.com>2012-07-11 02:47:34 +0200
commit159b28d97226c9b40e3e47188396a17cee70852e (patch)
tree1abec302b1433a111a6df8127ce5a15ce88252ce /src/plugins/platforms/windows/accessible/iaccessible2.cpp
parent825cd7b9e5ac16546fe224d48e5ea319fc171248 (diff)
Remove clipboard operations from QAccessibleEditableTextInterface
Also, remove its subclass QAccessibleSimpleEditableTextInterface Instead of having the subclass that implements this conveniently, we move this behaviour over to the bridge. The bridge should check if role() == EditableText is set, and then it should try to support the IAccessibleEditableText interface (i.e. it should accept the calls to replaceText(), deleteText() and insertText()) and change the text with the following operations: 1. Query the text using QAccessibleTextInterface::text() or by using QAccessibleInterface::text(QAccessible::Value) as a fallback 2. Do the requested delete/insert/replace manipulation 3. Update the text with setText(QAccessible::Value, newText); Change-Id: Iee5e41faf14351951e2bfca8c9eac970a113e878 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Diffstat (limited to 'src/plugins/platforms/windows/accessible/iaccessible2.cpp')
-rw-r--r--src/plugins/platforms/windows/accessible/iaccessible2.cpp129
1 files changed, 126 insertions, 3 deletions
diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.cpp b/src/plugins/platforms/windows/accessible/iaccessible2.cpp
index 71a26aff6b..5a82936a03 100644
--- a/src/plugins/platforms/windows/accessible/iaccessible2.cpp
+++ b/src/plugins/platforms/windows/accessible/iaccessible2.cpp
@@ -45,6 +45,7 @@
#include "qwindowsaccessibility.h"
#include <QtGui/qaccessible2.h>
+#include <QtGui/qclipboard.h>
#include <QtWidgets/qapplication.h>
#include <QtCore/qdebug.h>
@@ -241,9 +242,11 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::QueryInterface(REFIID id, LPVOI
} else if (id == IID_IAccessibleComponent) {
*iface = (IAccessibleComponent*)this;
} else if (id == IID_IAccessibleEditableText) {
- //if (accessible->editableTextInterface()) {
- //*iface = (IAccessibleEditableText*)this;
- //}
+ if (accessible->editableTextInterface() ||
+ accessible->role() == QAccessible::EditableText)
+ {
+ *iface = (IAccessibleEditableText*)this;
+ }
} else if (id == IID_IAccessibleHyperlink) {
//*iface = (IAccessibleHyperlink*)this;
} else if (id == IID_IAccessibleHypertext) {
@@ -673,6 +676,126 @@ HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_background(IA2Color *backgr
}
/**************************************************************\
+ * IAccessibleEditableText *
+ **************************************************************/
+#ifndef QT_NO_CLIPBOARD
+/*!
+ \internal
+
+ if \a endOffset == -1 it means end of the text
+*/
+QString QWindowsIA2Accessible::textForRange(int startOffset, int endOffset) const
+{
+ if (QAccessibleTextInterface *textIface = accessible->textInterface()) {
+ if (endOffset == IA2_TEXT_OFFSET_LENGTH)
+ endOffset = textIface->characterCount();
+ return textIface->text(startOffset, endOffset);
+ }
+ QString txt = accessible->text(QAccessible::Value);
+ if (endOffset == IA2_TEXT_OFFSET_LENGTH)
+ endOffset = txt.length();
+ return txt.mid(startOffset, endOffset - startOffset);
+}
+#endif
+
+/*!
+ \internal
+*/
+void QWindowsIA2Accessible::replaceTextFallback(long startOffset, long endOffset, const QString &txt)
+{
+ QString t = textForRange(0, -1);
+ if (endOffset == IA2_TEXT_OFFSET_LENGTH)
+ endOffset = t.length();
+ if (endOffset - startOffset == 0) {
+ t.insert(startOffset, txt);
+ } else {
+ t.replace(startOffset, endOffset - startOffset, txt);
+ }
+ accessible->setText(QAccessible::Value, t);
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::copyText(long startOffset, long endOffset)
+{
+ accessibleDebugClientCalls(accessible);
+#ifndef QT_NO_CLIPBOARD
+ const QString t = textForRange(startOffset, endOffset);
+ QGuiApplication::clipboard()->setText(t);
+ return S_OK;
+#else
+ return E_NOTIMPL;
+#endif
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::deleteText(long startOffset, long endOffset)
+{
+ accessibleDebugClientCalls(accessible);
+ if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
+ editableTextIface->deleteText(startOffset, endOffset);
+ else
+ replaceTextFallback(startOffset, endOffset, QString());
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::insertText(long offset, BSTR *text)
+{
+ accessibleDebugClientCalls(accessible);
+ const QString txt(BSTRToQString(*text));
+ if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
+ editableTextIface->insertText(offset, txt);
+ else
+ replaceTextFallback(offset, offset, txt);
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::cutText(long startOffset, long endOffset)
+{
+ accessibleDebugClientCalls(accessible);
+#ifndef QT_NO_CLIPBOARD
+ const QString t = textForRange(startOffset, endOffset);
+ if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
+ editableTextIface->deleteText(startOffset, endOffset);
+ else
+ replaceTextFallback(startOffset, endOffset, QString());
+ QGuiApplication::clipboard()->setText(t);
+ return S_OK;
+#else
+ return E_NOTIMPL;
+#endif
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::pasteText(long offset)
+{
+ accessibleDebugClientCalls(accessible);
+#ifndef QT_NO_CLIPBOARD
+ const QString txt = QGuiApplication::clipboard()->text();
+ if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
+ editableTextIface->insertText(offset, txt);
+ else
+ replaceTextFallback(offset, offset, txt);
+ return S_OK;
+#else
+ return E_NOTIMPL;
+#endif
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::replaceText(long startOffset, long endOffset, BSTR *text)
+{
+ accessibleDebugClientCalls(accessible);
+ const QString txt(BSTRToQString(*text));
+ if (QAccessibleEditableTextInterface *editableTextIface = accessible->editableTextInterface())
+ editableTextIface->replaceText(startOffset, endOffset, txt);
+ else
+ replaceTextFallback(startOffset, endOffset, txt);
+ return S_OK;
+}
+
+HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::setAttributes(long /*startOffset*/, long /*endOffset*/, BSTR * /*attributes*/)
+{
+ return E_NOTIMPL;
+}
+
+
+/**************************************************************\
* IAccessibleTable2 *
**************************************************************/
HRESULT STDMETHODCALLTYPE QWindowsIA2Accessible::get_cellAt( long row, long column, IUnknown **cell)