Commit ccb5d3f8 authored by erikchen's avatar erikchen Committed by Commit Bot

Remove throttling interval for quickly repeated key equivalents.

The system preferences for key repeat rate already limits the rate that
events are generated, so there's no need for another, arbitrary throttle.

Bug: 836947
Change-Id: I35927d4b475a45d7ff43d3d8f7e746e86f11f746
Reviewed-on: https://chromium-review.googlesource.com/1112561Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569796}
parent f0e98036
......@@ -13,9 +13,6 @@
// shortcuts and executing them with chrome::ExecuteCommand.
@interface ChromeCommandDispatcherDelegate : NSObject<CommandDispatcherDelegate>
// Permanently disabled throttling of repeated commands.
+ (void)disableThrottleForTesting;
@end
#endif // CHROME_BROWSER_UI_COCOA_CHROME_COMMAND_DISPATCHER_DELEGATE_H_
......@@ -16,54 +16,10 @@
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#include "content/public/browser/native_web_keyboard_event.h"
namespace {
// For commands that bypass the main menu, we need a custom throttle
// implementation since we don't have main menu's 100ms throttle. If a command
// is repeated, and less than 50ms has passed, ignore it. 50ms was chosen as a
// time that feels good - 100ms feels too long.
constexpr NSTimeInterval kThrottleTimeIntervalSeconds = 0.05;
// Browser tests disable throttling so that they can quickly send key events.
bool g_throttling_enabled = true;
} // namespace
@interface ChromeCommandDispatcherDelegate ()
// We track the last time we let a hotkey bypass the main menu. This allows us
// to implement a custom throttle. By default, the main menu has a built-in
// 100ms throttle [also used to highlight the .
@property(nonatomic, retain) NSDate* lastMainMenuBypassDate;
@property(nonatomic, assign) int lastMainMenuBypassChromeCommand;
@end
@implementation ChromeCommandDispatcherDelegate
@synthesize lastMainMenuBypassDate = lastMainMenuBypassDate_;
@synthesize lastMainMenuBypassChromeCommand = lastMainMenuBypassChromeCommand_;
+ (void)disableThrottleForTesting {
g_throttling_enabled = false;
}
- (void)dealloc {
[lastMainMenuBypassDate_ release];
[super dealloc];
}
- (BOOL)shouldThrottleChromeCommand:(int)command {
if (!g_throttling_enabled)
return NO;
return self.lastMainMenuBypassChromeCommand == command &&
self.lastMainMenuBypassDate &&
fabs([self.lastMainMenuBypassDate timeIntervalSinceNow]) <
kThrottleTimeIntervalSeconds;
}
- (void)executeChromeCommandBypassingMainMenu:(int)command
browser:(Browser*)browser {
self.lastMainMenuBypassDate = [NSDate date];
self.lastMainMenuBypassChromeCommand = command;
chrome::ExecuteCommand(browser, command);
}
......@@ -135,15 +91,7 @@ bool g_throttling_enabled = true;
// This is based on the rough approximation that reserved commands are
// also the ones that we want to be quickly repeatable.
// https://crbug.com/836947.
if ([self shouldThrottleChromeCommand:result.chrome_command]) {
// Claim to have handled the command to prevent anyone else from
// processing it.
return ui::PerformKeyEquivalentResult::kHandled;
}
[self executeChromeCommandBypassingMainMenu:result.chrome_command
browser:browser];
chrome::ExecuteCommand(browser, result.chrome_command);
return ui::PerformKeyEquivalentResult::kHandled;
}
}
......@@ -178,14 +126,7 @@ bool g_throttling_enabled = true;
return ui::PerformKeyEquivalentResult::kPassToMainMenu;
}
if ([self shouldThrottleChromeCommand:result.chrome_command]) {
// Claim to have handled the command to prevent anyone else from
// processing it.
return ui::PerformKeyEquivalentResult::kHandled;
}
[self executeChromeCommandBypassingMainMenu:result.chrome_command
browser:browser];
chrome::ExecuteCommand(browser, result.chrome_command);
return ui::PerformKeyEquivalentResult::kHandled;
}
}
......
......@@ -245,9 +245,6 @@ void InProcessBrowserTest::SetUp() {
CHECK(base::PathService::Override(chrome::DIR_DEFAULT_DOWNLOADS,
default_download_dir_.GetPath()));
#if defined(OS_MACOSX)
InProcessBrowserTest::SetUpMacOS();
#endif
BrowserTestBase::SetUp();
}
......
......@@ -229,9 +229,6 @@ class InProcessBrowserTest : public content::BrowserTestBase {
base::mac::ScopedNSAutoreleasePool* AutoreleasePool() const {
return autorelease_pool_;
}
// Initializes macOS-only state.
void SetUpMacOS();
#endif // OS_MACOSX
void set_exit_when_last_browser_closes(bool value) {
......
......@@ -90,7 +90,3 @@ Browser* InProcessBrowserTest::CreateBrowserForApp(const std::string& app_name,
AddBlankTabAndShow(browser);
return browser;
}
void InProcessBrowserTest::SetUpMacOS() {
[ChromeCommandDispatcherDelegate disableThrottleForTesting];
}
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