summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms
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
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')
-rw-r--r--src/plugins/platforms/windows/accessible/comutils.h5
-rw-r--r--src/plugins/platforms/windows/accessible/iaccessible2.cpp129
-rw-r--r--src/plugins/platforms/windows/accessible/iaccessible2.h6
3 files changed, 134 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/accessible/comutils.h b/src/plugins/platforms/windows/accessible/comutils.h
index 4d8e603899..40b89ed991 100644
--- a/src/plugins/platforms/windows/accessible/comutils.h
+++ b/src/plugins/platforms/windows/accessible/comutils.h
@@ -54,6 +54,11 @@ class QVariant;
bool QVariantToVARIANT(const QVariant &var, VARIANT &arg, const QByteArray &typeName, bool out);
+inline QString BSTRToQString(const BSTR &bstr)
+{
+ return QString((QChar*)bstr);
+}
+
inline BSTR QStringToBSTR(const QString &str)
{
return SysAllocStringLen((OLECHAR*)str.unicode(), str.length());
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)
diff --git a/src/plugins/platforms/windows/accessible/iaccessible2.h b/src/plugins/platforms/windows/accessible/iaccessible2.h
index 0f9d3b3c41..bfd9031e88 100644
--- a/src/plugins/platforms/windows/accessible/iaccessible2.h
+++ b/src/plugins/platforms/windows/accessible/iaccessible2.h
@@ -73,7 +73,7 @@ QT_BEGIN_NAMESPACE
class QWindowsIA2Accessible : public QWindowsMsaaAccessible,
public IAccessibleAction,
public IAccessibleComponent,
- /*public IAccessibleEditableText,*/
+ public IAccessibleEditableText,
public IAccessibleTable2,
public IAccessibleTableCell,
public IAccessibleText,
@@ -122,7 +122,6 @@ public:
HRESULT STDMETHODCALLTYPE get_background(IA2Color *background);
/* IAccessibleEditableText */
- /*
HRESULT STDMETHODCALLTYPE copyText(long startOffset, long endOffset);
HRESULT STDMETHODCALLTYPE deleteText(long startOffset, long endOffset);
HRESULT STDMETHODCALLTYPE insertText(long offset, BSTR *text);
@@ -130,7 +129,6 @@ public:
HRESULT STDMETHODCALLTYPE pasteText(long offset);
HRESULT STDMETHODCALLTYPE replaceText(long startOffset, long endOffset, BSTR *text);
HRESULT STDMETHODCALLTYPE setAttributes(long startOffset, long endOffset, BSTR *attributes);
- */
/* IAccessibleTable2 */
HRESULT STDMETHODCALLTYPE get_cellAt( long row, long column, IUnknown **cell);
@@ -265,6 +263,8 @@ private:
HRESULT wrapListOfCells(const QList<QAccessibleInterface*> &inputCells, IUnknown ***outputAccessibles, long *nCellCount);
uint uniqueID() const;
QByteArray IIDToString(REFIID id);
+ QString textForRange(int startOffset, int endOffset) const;
+ void replaceTextFallback(long startOffset, long endOffset, const QString &txt);
};