diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-09-21 12:29:19 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-10-03 13:03:54 +0000 |
commit | 9c839f95a20904ae66d962f24225dabf13f85266 (patch) | |
tree | 096fc54d193e9479f085424c5be3c79f2f60c8c6 | |
parent | 114c4593b6950122ad10326903c986647adb2dc0 (diff) |
macOS: Ensure QFontDialog picks up changes in NSFontPanel
When the font changes in NSFontPanel, it notifies NSFontManager via
-[NSFontManager modifyFontViaPanel:], which in turn sends the font
manager's action (by default changeFont:) to its target (nil, unless set).
Sending the action in -[NSApplication(NSResponder) sendAction:to:from:]
will sanitize the 'to' argument via _NSTargetForSendAction.
If the argument is non-nill (if we've set the NSFontManager target
explicitly), and we're running in an app-modal session (which we are),
the target is checked for worksWhenModal -- a property which is defined
on NSWindow, and only supposed to be set for subclasses of NSPanel.
Since our QNSFontPanelDelegate class doesn't implement this method, the
_NSTargetForSendAction function will return nil, and the action is never
sent.
If we don't set the NSFontManager target (leaving it as nil), the function
will skip the worksWhenModal check, and fall back to resolving the target
via the responder chain, which includes taking the NSPanel's delegate
into account:
#0 -[NSWindow delegate] ()
#1 -[NSWindow(NSEventRouting) supplementalTargetForAction:sender:] ()
#2 _objectFromResponderChainWhichRespondsToAction ()
#3 _NSTargetForSendAction ()
#4 -[NSApplication(NSResponder) sendAction:to:from:] ()
#5 -[NSFontManager sendAction] ()
...
Since we want to end up in the QNSFontPanelDelegate, we can rely on the
default logic to resolve the target based on the responder chain. But in
case _NSTargetForSendAction will at some point also check the resolved
target for worksWhenModal, we also implement the worksWhenModal method,
to be on the safe side.
Fixes: QTBUG-69878
Change-Id: Ie739d016fe0efd17b3d8a99cc1fb1ace81807aff
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 33b102f3eb..8c0af97a68 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -108,8 +108,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); [mFontPanel setRestorable:NO]; [mFontPanel setDelegate:self]; - [NSFontManager sharedFontManager].target = self; // Action is changeFont: - [mFontPanel retain]; } return self; @@ -119,7 +117,6 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); { [mStolenContentView release]; [mFontPanel setDelegate:nil]; - [NSFontManager sharedFontManager].target = nil; [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; @@ -224,6 +221,13 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); return (mResultCode == NSModalResponseOK); } +// Future proofing in case _NSTargetForSendAction checks this +// property before sending us the changeFont: message. +- (BOOL)worksWhenModal +{ + return YES; +} + - (QPlatformDialogHelper::DialogCode)dialogResultCode { return (mResultCode == NSModalResponseOK) ? QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected; |