qnsview_drag: only ignore key modifier while dragging 'within the application'

We return a mask containing several supported DND operations and if modifiers
were ignored, an external application can select a 'wrong' operation (not the
one we wanted when pressing a modifier). Saying that, the old logic of ignoring
still applies if we are dragging 'within the application'.

Fixes: QTBUG-99471
Change-Id: I67c9a656960e95d6d2298f4b3bdd2052faedb263
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Timur Pocheptsov 2022-01-05 16:42:23 +01:00
parent bb629a2e29
commit 4332cb3134
2 changed files with 10 additions and 3 deletions

View File

@ -109,6 +109,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
// Text
QString m_composingText;
QPointer<QObject> m_composingFocusObject;
NSDraggingContext m_lastSeenContext;
}
- (instancetype)initWithCocoaWindow:(QCocoaWindow *)platformWindow
@ -130,6 +131,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSViewMouseMoveHelper);
m_lastKeyDead = false;
m_sendKeyEvent = false;
m_currentlyInterpretedKeyEvent = nil;
m_lastSeenContext = NSDraggingContextWithinApplication;
}
return self;
}

View File

@ -45,8 +45,8 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context
{
Q_UNUSED(session);
Q_UNUSED(context);
m_lastSeenContext = context;
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
return qt_mac_mapDropActions(nativeDrag->currentDrag()->supportedActions());
}
@ -61,8 +61,11 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
//
// Since Qt already takes care of tracking the keyboard modifiers, we
// don't need (or want) Cocoa to filter anything. Instead, we'll let
// the application do the actual filtering.
return YES;
// the application do the actual filtering. But only while dragging
// within application, otherwise ignored modifiers may end up in a
// wrong drop operation executed.
return m_lastSeenContext == NSDraggingContextWithinApplication;
}
- (BOOL)wantsPeriodicDraggingUpdates
@ -250,6 +253,8 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin
Q_UNUSED(screenPoint);
Q_UNUSED(operation);
m_lastSeenContext = NSDraggingContextWithinApplication;
if (!m_platformWindow)
return;