Accessibility: Make it possible to send events with no QObject
Change-Id: Icbb9d15ec52ff5f7718eaf3600cab140971274aa Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
This commit is contained in:
parent
8fd9fe2099
commit
9a369a25dd
@ -1270,8 +1270,16 @@ QAccessibleInterface::~QAccessibleInterface()
|
||||
/*! \fn QAccessibleEvent::QAccessibleEvent(QObject *object, QAccessible::Event type)
|
||||
|
||||
Constructs a QAccessibleEvent to notify that \a object has changed.
|
||||
The event \a type explains what changed.
|
||||
*/
|
||||
The event \a type describes what changed.
|
||||
*/
|
||||
|
||||
/*! \fn QAccessibleEvent::QAccessibleEvent(QAccessibleInterface *interface, QAccessible::Event type)
|
||||
|
||||
Constructs a QAccessibleEvent to notify that \a interface has changed.
|
||||
The event \a type describes what changed.
|
||||
Use this function if you already have a QAccessibleInterface or no QObject, otherwise consider
|
||||
the overload taking a \l QObject parameter as it might be cheaper.
|
||||
*/
|
||||
|
||||
/*! \fn QAccessibleEvent::~QAccessibleEvent()
|
||||
Destroys the event.
|
||||
@ -1293,6 +1301,22 @@ QAccessibleInterface::~QAccessibleInterface()
|
||||
Returns the child index.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Returns the uniqueId of the QAccessibleInterface represented by this event.
|
||||
|
||||
In case the object() function returns 0 this is the only way to access the
|
||||
interface.
|
||||
*/
|
||||
QAccessible::Id QAccessibleEvent::uniqueId() const
|
||||
{
|
||||
if (!m_object)
|
||||
return m_uniqueId;
|
||||
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
|
||||
if (m_child != -1)
|
||||
iface = iface->child(m_child);
|
||||
return QAccessible::uniqueId(iface);
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QAccessibleValueChangeEvent
|
||||
@ -1530,6 +1554,9 @@ QAccessibleInterface::~QAccessibleInterface()
|
||||
*/
|
||||
QAccessibleInterface *QAccessibleEvent::accessibleInterface() const
|
||||
{
|
||||
if (m_object == 0)
|
||||
return QAccessible::accessibleInterface(m_uniqueId);
|
||||
|
||||
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(m_object);
|
||||
if (!iface || !iface->isValid()) {
|
||||
static bool hasWarned = false;
|
||||
@ -1681,9 +1708,13 @@ QDebug operator<<(QDebug d, const QAccessibleEvent &ev)
|
||||
d << "QAccessibleEvent(null)";
|
||||
return d;
|
||||
}
|
||||
d.nospace() << "QAccessibleEvent(object=" << hex << ev.object();
|
||||
d.nospace() << dec;
|
||||
d.nospace() << "child=" << ev.child();
|
||||
d.nospace() << "QAccessibleEvent(";
|
||||
if (ev.object()) {
|
||||
d.nospace() << "object=" << hex << ev.object() << dec;
|
||||
d.nospace() << "child=" << ev.child();
|
||||
} else {
|
||||
d.nospace() << "no object, uniqueId=" << ev.uniqueId();
|
||||
}
|
||||
d << " event=" << qAccessibleEventString(ev.type());
|
||||
if (ev.type() == QAccessible::StateChanged) {
|
||||
QAccessible::State changed = static_cast<const QAccessibleStateChangeEvent*>(&ev)->changedStates();
|
||||
|
@ -597,6 +597,7 @@ class Q_GUI_EXPORT QAccessibleEvent
|
||||
{
|
||||
Q_DISABLE_COPY(QAccessibleEvent)
|
||||
public:
|
||||
|
||||
inline QAccessibleEvent(QObject *obj, QAccessible::Event typ)
|
||||
: m_type(typ), m_object(obj), m_child(-1)
|
||||
{
|
||||
@ -613,11 +614,27 @@ public:
|
||||
Q_ASSERT(m_type != QAccessible::TableModelChanged);
|
||||
}
|
||||
|
||||
inline QAccessibleEvent(QAccessibleInterface *iface, QAccessible::Event typ)
|
||||
: m_type(typ), m_object(0)
|
||||
{
|
||||
Q_ASSERT(iface);
|
||||
Q_ASSERT(m_type != QAccessible::ValueChanged);
|
||||
Q_ASSERT(m_type != QAccessible::StateChanged);
|
||||
Q_ASSERT(m_type != QAccessible::TextCaretMoved);
|
||||
Q_ASSERT(m_type != QAccessible::TextSelectionChanged);
|
||||
Q_ASSERT(m_type != QAccessible::TextInserted);
|
||||
Q_ASSERT(m_type != QAccessible::TextRemoved);
|
||||
Q_ASSERT(m_type != QAccessible::TextUpdated);
|
||||
Q_ASSERT(m_type != QAccessible::TableModelChanged);
|
||||
m_uniqueId = QAccessible::uniqueId(iface);
|
||||
}
|
||||
|
||||
virtual ~QAccessibleEvent()
|
||||
{}
|
||||
|
||||
QAccessible::Event type() const { return m_type; }
|
||||
QObject *object() const { return m_object; }
|
||||
QAccessible::Id uniqueId() const;
|
||||
|
||||
void setChild(int chld) { m_child = chld; }
|
||||
int child() const { return m_child; }
|
||||
@ -627,7 +644,11 @@ public:
|
||||
protected:
|
||||
QAccessible::Event m_type;
|
||||
QObject *m_object;
|
||||
int m_child;
|
||||
union {
|
||||
int m_child;
|
||||
QAccessible::Id m_uniqueId;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
class Q_GUI_EXPORT QAccessibleStateChangeEvent :public QAccessibleEvent
|
||||
@ -638,6 +659,11 @@ public:
|
||||
{
|
||||
m_type = QAccessible::StateChanged;
|
||||
}
|
||||
inline QAccessibleStateChangeEvent(QAccessibleInterface *iface, QAccessible::State state)
|
||||
: QAccessibleEvent(iface, QAccessible::InvalidEvent), m_changedStates(state)
|
||||
{
|
||||
m_type = QAccessible::StateChanged;
|
||||
}
|
||||
|
||||
QAccessible::State changedStates() const {
|
||||
return m_changedStates;
|
||||
@ -657,6 +683,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TextCaretMoved;
|
||||
}
|
||||
inline QAccessibleTextCursorEvent(QAccessibleInterface *iface, int cursorPos)
|
||||
: QAccessibleEvent(iface, QAccessible::InvalidEvent)
|
||||
, m_cursorPosition(cursorPos)
|
||||
{
|
||||
m_type = QAccessible::TextCaretMoved;
|
||||
}
|
||||
|
||||
void setCursorPosition(int position) { m_cursorPosition = position; }
|
||||
int cursorPosition() const { return m_cursorPosition; }
|
||||
@ -675,6 +707,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TextSelectionChanged;
|
||||
}
|
||||
inline QAccessibleTextSelectionEvent(QAccessibleInterface *iface, int start, int end)
|
||||
: QAccessibleTextCursorEvent(iface, (start == -1) ? 0 : end)
|
||||
, m_selectionStart(start), m_selectionEnd(end)
|
||||
{
|
||||
m_type = QAccessible::TextSelectionChanged;
|
||||
}
|
||||
|
||||
void setSelection(int start, int end) {
|
||||
m_selectionStart = start;
|
||||
@ -698,6 +736,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TextInserted;
|
||||
}
|
||||
inline QAccessibleTextInsertEvent(QAccessibleInterface *iface, int position, const QString &text)
|
||||
: QAccessibleTextCursorEvent(iface, position + text.length())
|
||||
, m_position(position), m_text(text)
|
||||
{
|
||||
m_type = QAccessible::TextInserted;
|
||||
}
|
||||
|
||||
QString textInserted() const {
|
||||
return m_text;
|
||||
@ -720,6 +764,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TextRemoved;
|
||||
}
|
||||
inline QAccessibleTextRemoveEvent(QAccessibleInterface *iface, int position, const QString &text)
|
||||
: QAccessibleTextCursorEvent(iface, position)
|
||||
, m_position(position), m_text(text)
|
||||
{
|
||||
m_type = QAccessible::TextRemoved;
|
||||
}
|
||||
|
||||
QString textRemoved() const {
|
||||
return m_text;
|
||||
@ -742,6 +792,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TextUpdated;
|
||||
}
|
||||
inline QAccessibleTextUpdateEvent(QAccessibleInterface *iface, int position, const QString &oldText, const QString &text)
|
||||
: QAccessibleTextCursorEvent(iface, position + text.length())
|
||||
, m_position(position), m_oldText(oldText), m_text(text)
|
||||
{
|
||||
m_type = QAccessible::TextUpdated;
|
||||
}
|
||||
QString textRemoved() const {
|
||||
return m_oldText;
|
||||
}
|
||||
@ -767,6 +823,12 @@ public:
|
||||
{
|
||||
m_type = QAccessible::ValueChanged;
|
||||
}
|
||||
inline QAccessibleValueChangeEvent(QAccessibleInterface *iface, const QVariant &val)
|
||||
: QAccessibleEvent(iface, QAccessible::InvalidEvent)
|
||||
, m_value(val)
|
||||
{
|
||||
m_type = QAccessible::ValueChanged;
|
||||
}
|
||||
|
||||
void setValue(const QVariant & val) { m_value= val; }
|
||||
QVariant value() const { return m_value; }
|
||||
@ -794,6 +856,14 @@ public:
|
||||
{
|
||||
m_type = QAccessible::TableModelChanged;
|
||||
}
|
||||
inline QAccessibleTableModelChangeEvent(QAccessibleInterface *iface, ModelChangeType changeType)
|
||||
: QAccessibleEvent(iface, QAccessible::InvalidEvent)
|
||||
, m_modelChangeType(changeType)
|
||||
, m_firstRow(-1), m_firstColumn(-1), m_lastRow(-1), m_lastColumn(-1)
|
||||
{
|
||||
m_type = QAccessible::TableModelChanged;
|
||||
}
|
||||
|
||||
void setModelChangeType(ModelChangeType changeType) { m_modelChangeType = changeType; }
|
||||
ModelChangeType modelChangeType() const { return m_modelChangeType; }
|
||||
|
||||
|
@ -56,12 +56,8 @@ QCocoaAccessibility::~QCocoaAccessibility()
|
||||
|
||||
void QCocoaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
|
||||
{
|
||||
QObject *object = event->object();
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
QAccessibleInterface *interface = event->accessibleInterface();
|
||||
if (!interface)
|
||||
QAccessible::Id interfaceId = event->uniqueId();
|
||||
if (!interfaceId)
|
||||
return;
|
||||
|
||||
switch (event->type()) {
|
||||
@ -69,7 +65,7 @@ void QCocoaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event)
|
||||
case QAccessible::TextInserted :
|
||||
case QAccessible::TextRemoved :
|
||||
case QAccessible::TextUpdated : {
|
||||
QCocoaAccessibleElement *element = [QCocoaAccessibleElement createElementWithId : QAccessible::uniqueId(interface) parent : nil];
|
||||
QCocoaAccessibleElement *element = [QCocoaAccessibleElement createElementWithId : interfaceId parent : nil];
|
||||
[element autorelease];
|
||||
NSAccessibilityPostNotification(element, NSAccessibilityValueChangedNotification);
|
||||
break; }
|
||||
|
Loading…
Reference in New Issue
Block a user