Mac: Never dispatch keyEquivalents to the web contents if the window is not Key.
When pressing a hotkey on Mac, AppKit asks pretty much everything in the
UI if it wants to handle it. When a dialog is showing, we want the
browser window to handle commands such as "change tabs". So events can
propagate up to a browser window, but WebContents shouldn't see events
when a dialog is active.
In fact, the WebContents doesn't: the dialog machinery invokes
RenderWidgetHostImpl::SetIgnoreInputEvents(..) while the dialog is
showing, but RenderWidgetHostImpl ignores the event only *after*
[RenderWidgetHostViewCocoa performKeyEquivalent:] has returned NO.
Ignored events are not sent over IPC, so they are never sent back
"unhandled" to be redispatched. So this prevents other parts of the UI
(such as the mainMenu) from participating in event dispatch - the event
This became an issue when dialogs started doing their own command
propagation rather than hooking the -[NSWindow _sharesParentKeyState]
SPI which causes a bunch of other weird issues.
To fix, have RenderWidgetHostViewCocoa return NO immediately if its
window is not the keyWindow. It currently just checks if it's the
firstResponder in its window.
TEST=On Mac, Enable chrome://flags/#secondary-ui-md, Navigate to
, cancel the dialog, then
refresh the page (dialog should show a second time). Type some text and
press Cmd+x to 'Cut' - text should be cut and Edit menu should flash.