macOS: Fix alert dialog display (fixes issue #2726)

This commit is contained in:
Marshall Greenblatt 2019-07-25 12:28:41 -04:00
parent c038bf8198
commit 1d3b911b16
1 changed files with 14 additions and 7 deletions

View File

@ -26,8 +26,9 @@
(CefJavaScriptDialogRunner::DialogClosedCallback)callback; (CefJavaScriptDialogRunner::DialogClosedCallback)callback;
- (NSAlert*)alert; - (NSAlert*)alert;
- (NSTextField*)textField; - (NSTextField*)textField;
- (void)alertDidEndWithResult:(NSModalResponse)returnCode - (void)alertDidEnd:(NSAlert*)alert
dialog:(CefJavaScriptDialogRunnerMac*)dialog; returnCode:(int)returnCode
contextInfo:(void*)contextInfo;
- (void)cancel; - (void)cancel;
@end @end
@ -57,8 +58,9 @@
return textField_; return textField_;
} }
- (void)alertDidEndWithResult:(NSModalResponse)returnCode - (void)alertDidEnd:(NSAlert*)alert
dialog:(CefJavaScriptDialogRunnerMac*)dialog { returnCode:(int)returnCode
contextInfo:(void*)contextInfo {
if (returnCode == NSModalResponseStop) if (returnCode == NSModalResponseStop)
return; return;
@ -139,11 +141,16 @@ void CefJavaScriptDialogRunnerMac::Run(
// around the "callee requires a non-null argument" error that occurs when // around the "callee requires a non-null argument" error that occurs when
// building with the 10.11 SDK. See http://crbug.com/383820 for related // building with the 10.11 SDK. See http://crbug.com/383820 for related
// discussion. // discussion.
// We can't use the newer beginSheetModalForWindow:completionHandler: variant
// because it fails silently when passed a nil argument (see issue #2726).
id nilArg = nil; id nilArg = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[alert beginSheetModalForWindow:nilArg // nil here makes it app-modal [alert beginSheetModalForWindow:nilArg // nil here makes it app-modal
completionHandler:^void(NSModalResponse returnCode) { modalDelegate:helper_
[helper_ alertDidEndWithResult:returnCode dialog:this]; didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
}]; contextInfo:this];
#pragma clang diagnostic pop
if ([alert accessoryView]) if ([alert accessoryView])
[[alert window] makeFirstResponder:[alert accessoryView]]; [[alert window] makeFirstResponder:[alert accessoryView]];