OSX: check if we have a native drag before accessing it

We used to check if [sender draggingSource] != nil to determine
if the current drag was started by the application itself or
somewhere else. While this is correct use of the API, the problem
is that a drag can also be started by UIKit if e.g dragging the
file icon in the titlebar. And in that case, Qt has no no
native drag data. Since we didn't take this usecase into account, we
tried to access the data anyway, which led to a crash.

This patch will instead check if we have native drag data directly
before trying to access it, which will also cover the
usecase mentioned above.

Task-number: QTBUG-46598
Change-Id: Ic91b86f658670b895d90a1533246ba24a00dde41
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
bb10
Richard Moe Gustavsen 2015-06-11 10:37:21 +02:00 committed by Jani Heikkinen
parent 92cda94742
commit 827e195f17
1 changed files with 6 additions and 4 deletions

View File

@ -1913,8 +1913,9 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
QGuiApplicationPrivate::modifier_buttons = [QNSView convertKeyModifiers: [[NSApp currentEvent] modifierFlags]];
QPlatformDragQtResponse response(false, Qt::IgnoreAction, QRect());
if ([sender draggingSource] != nil) {
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
if (nativeDrag->currentDrag()) {
// The drag was started from within the application
response = QWindowSystemInterface::handleDrag(target, nativeDrag->platformDropData(), mapWindowCoordinates(m_window, target, qt_windowPoint), qtAllowed);
[self updateCursorFromDragResponse:response drag:nativeDrag];
} else {
@ -1950,8 +1951,9 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations([sender draggingSourceOperationMask]);
QPlatformDropQtResponse response(false, Qt::IgnoreAction);
if ([sender draggingSource] != nil) {
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
if (nativeDrag->currentDrag()) {
// The drag was started from within the application
response = QWindowSystemInterface::handleDrop(target, nativeDrag->platformDropData(), mapWindowCoordinates(m_window, target, qt_windowPoint), qtAllowed);
} else {
QCocoaDropData mimeData([sender draggingPasteboard]);