fix: restore window event redispatching on mac (#27701)

This commit is contained in:
Calvin 2021-02-17 18:31:53 -07:00 committed by GitHub
parent b0a6eb6a53
commit 64eb02b671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
#include "shell/browser/web_contents_preferences.h"
#include "ui/base/cocoa/command_dispatcher.h"
#include "ui/events/keycodes/keyboard_codes.h"
#import <Cocoa/Cocoa.h>
@ -58,6 +59,7 @@ bool WebContents::PlatformHandleKeyboardEvent(
[[NSApp mainMenu] performKeyEquivalent:event.os_event])
return true;
// Let the window redispatch the OS event
if (event.os_event.window &&
[event.os_event.window isKindOfClass:[EventDispatchingWindow class]]) {
[event.os_event.window redispatchKeyEvent:event.os_event];
@ -65,6 +67,16 @@ bool WebContents::PlatformHandleKeyboardEvent(
// devtools windows as Widgets in order to take advantage of the
// pre-existing redispatch code in bridged_native_widget.
return false;
} else if (event.os_event.window &&
[event.os_event.window
conformsToProtocol:@protocol(CommandDispatchingWindow)]) {
NSObject<CommandDispatchingWindow>* window =
static_cast<NSObject<CommandDispatchingWindow>*>(event.os_event.window);
[[window commandDispatcher] redispatchKeyEvent:event.os_event];
// FIXME(clavin): Not exactly sure what to return here, likely the same
// situation as the branch above. If a future refactor removes
// |EventDispatchingWindow| then only this branch will need to remain.
return false;
}
return false;