Commit 619cd145 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Mac: ignore CmdT/N from key repeats

Bug: 635853
Change-Id: I4f4c475e8326b3dc3a5c3014185f027b8656176a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2372739Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801401}
parent 79b68ce7
......@@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h"
#include "base/check.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/global_keyboard_shortcuts_mac.h"
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
......@@ -91,6 +92,13 @@
// By not passing the event to AppKit, we do lose out on the brief
// highlighting of the NSMenu.
CommandForKeyEventResult result = CommandForKeyEvent(event);
// Ignore new tab/window events if |event| is a key repeat to prevent
// users from accidentally opening too many empty tabs or windows.
if (event.isARepeat && (result.chrome_command == IDC_NEW_TAB ||
result.chrome_command == IDC_NEW_WINDOW)) {
return ui::PerformKeyEquivalentResult::kDrop;
}
if (result.found()) {
auto* bridge =
remote_cocoa::NativeWidgetNSWindowBridge::GetFromNativeWindow(window);
......
......@@ -86,6 +86,11 @@ enum class PerformKeyEquivalentResult {
// the event to be passed to the MainMenu, which will handle the key
// equivalent.
kPassToMainMenu,
// The CommandDispatcherDelegate determined the event should not be handled.
// This can occur when an event has been sent via key repeat that we've
// determined should not be triggered via repeat.
kDrop,
};
} // namespace ui
......
......@@ -130,7 +130,8 @@ NSEvent* KeyEventForWindow(NSWindow* window, NSEvent* event) {
// First, give the delegate an opportunity to consume this event.
ui::PerformKeyEquivalentResult result =
[_delegate prePerformKeyEquivalent:event window:_owner];
if (result == ui::PerformKeyEquivalentResult::kHandled)
if (result == ui::PerformKeyEquivalentResult::kHandled ||
result == ui::PerformKeyEquivalentResult::kDrop)
return YES;
if (result == ui::PerformKeyEquivalentResult::kPassToMainMenu)
return NO;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment