macOS: Deliver native events to windows, as well as to event filters

Qt has two APIs to intercept native events today:

 - QAbstractEventDispatcher::installNativeEventFilter()
 - Q{Window|Widget}::nativeEvent()

On macOS we only implemented one of them, the native event filter code
path, by calling filterNativeEvent from the Cocoa event dispatcher.

We now also propagate the native event to the corresponding QWindow,
and QWidget if applicable.

It would be nice if there was only one Qt API for this, or at least
only one codepath for platform plugins to care about, but since the
event filter might catch more event types than gets delivered to the
window, we probably need both code paths going forward.

Task-number: QTBUG-40116
Change-Id: I0796bd62a2b7c08b2eaaf6f15db8088e9703af02
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-06-29 16:25:56 +02:00
parent b282d11873
commit 8143f60026
2 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#include "qcocoahelpers.h"
#include "qcocoaeventdispatcher.h"
#include <qpa/qwindowsysteminterface.h>
#include <qoperatingsystemversion.h>
static bool isMouseEvent(NSEvent *ev)
@ -122,6 +123,12 @@ static bool isMouseEvent(NSEvent *ev)
if (!self.platformWindow)
return;
const char *eventType = object_getClassName(theEvent);
if (QWindowSystemInterface::handleNativeEvent(self.platformWindow->window(),
QByteArray::fromRawData(eventType, qstrlen(eventType)), theEvent, nullptr)) {
return;
}
[self.window superSendEvent:theEvent];
if (!self.platformWindow)

View File

@ -10001,6 +10001,7 @@ void QWidget::hideEvent(QHideEvent *)
\table
\header \li Platform \li Event Type Identifier \li Message Type \li Result Type
\row \li Windows \li "windows_generic_MSG" \li MSG * \li LRESULT
\row \li macOS \li "NSEvent" \li NSEvent * \li
\endtable
*/