Skip to content

Commit

Permalink
Move key repeat enabled, delay, and interval preferences into Ash.
Browse files Browse the repository at this point in the history
This is in preparation for forwarding these preferences to Exo; see https://crrev.com/c/2131548

Bug: 1062816

Change-Id: I306b06469ba82add5828ae66e156b588abcf50b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2143422
Commit-Queue: Chloe Pelling <cpelling@google.com>
Reviewed-by: Nic Hollingum <hollingum@google.com>
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Esmael Elmoslimany <aee@chromium.org>
Auto-Submit: Chloe Pelling <cpelling@google.com>
Cr-Commit-Position: refs/heads/master@{#762708}
  • Loading branch information
cpelling authored and Commit Bot committed Apr 27, 2020
1 parent cc001a1 commit 186ed3e
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 69 deletions.
2 changes: 2 additions & 0 deletions ash/ash_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ash/detachable_base/detachable_base_handler.h"
#include "ash/display/display_prefs.h"
#include "ash/display/privacy_screen_controller.h"
#include "ash/keyboard/keyboard_controller_impl.h"
#include "ash/login/login_screen_controller.h"
#include "ash/magnifier/docked_magnifier_controller_impl.h"
#include "ash/media/media_controller_impl.h"
Expand Down Expand Up @@ -52,6 +53,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
GestureEducationNotificationController::RegisterProfilePrefs(registry);
LoginScreenController::RegisterProfilePrefs(registry, for_test);
LogoutButtonTray::RegisterProfilePrefs(registry);
KeyboardControllerImpl::RegisterProfilePrefs(registry);
MediaControllerImpl::RegisterProfilePrefs(registry);
MessageCenterController::RegisterProfilePrefs(registry);
NightLightControllerImpl::RegisterProfilePrefs(registry);
Expand Down
19 changes: 19 additions & 0 deletions ash/keyboard/keyboard_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "ash/keyboard/ui/keyboard_ui_controller.h"
#include "ash/keyboard/ui/keyboard_ui_factory.h"
#include "ash/keyboard/virtual_keyboard_controller.h"
#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/keyboard/keyboard_switches.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
Expand All @@ -19,6 +21,7 @@
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/optional.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "ui/aura/env.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/ui_base_features.h"
Expand Down Expand Up @@ -60,6 +63,22 @@ KeyboardControllerImpl::~KeyboardControllerImpl() {
session_controller_->RemoveObserver(this);
}

// static
void KeyboardControllerImpl::RegisterProfilePrefs(
PrefRegistrySimple* registry) {
registry->RegisterBooleanPref(
ash::prefs::kXkbAutoRepeatEnabled, ash::kDefaultKeyAutoRepeatEnabled,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
ash::prefs::kXkbAutoRepeatDelay,
ash::kDefaultKeyAutoRepeatDelay.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
ash::prefs::kXkbAutoRepeatInterval,
ash::kDefaultKeyAutoRepeatInterval.InMilliseconds(),
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
}

void KeyboardControllerImpl::CreateVirtualKeyboard(
std::unique_ptr<keyboard::KeyboardUIFactory> keyboard_ui_factory) {
DCHECK(keyboard_ui_factory);
Expand Down
4 changes: 4 additions & 0 deletions ash/keyboard/keyboard_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "base/macros.h"
#include "base/optional.h"

class PrefRegistrySimple;

namespace gfx {
class Rect;
}
Expand Down Expand Up @@ -45,6 +47,8 @@ class ASH_EXPORT KeyboardControllerImpl
explicit KeyboardControllerImpl(SessionControllerImpl* session_controller);
~KeyboardControllerImpl() override;

static void RegisterProfilePrefs(PrefRegistrySimple* registry);

// Create or destroy the virtual keyboard. Called from Shell. TODO(stevenjb):
// Fix dependencies so that the virtual keyboard can be created with the
// keyboard controller.
Expand Down
11 changes: 11 additions & 0 deletions ash/public/cpp/ash_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ constexpr FloatingMenuPosition kDefaultFloatingMenuPosition =
// The default frame color.
constexpr SkColor kDefaultFrameColor = SkColorSetRGB(0xFD, 0xFE, 0xFF);

// Whether keyboard auto repeat is enabled by default.
constexpr bool kDefaultKeyAutoRepeatEnabled = true;

// The default delay before a held keypress will start to auto repeat.
constexpr base::TimeDelta kDefaultKeyAutoRepeatDelay =
base::TimeDelta::FromMilliseconds(500);

// The default interval between auto-repeated key events.
constexpr base::TimeDelta kDefaultKeyAutoRepeatInterval =
base::TimeDelta::FromMilliseconds(50);

} // namespace ash

#endif // ASH_PUBLIC_CPP_ASH_CONSTANTS_H_
15 changes: 15 additions & 0 deletions ash/public/cpp/ash_pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,21 @@ const char kAssistantPrivacyInfoDismissedInLauncher[] =
const char kLockScreenMediaControlsEnabled[] =
"ash.lock_screen_media_controls_enabled";

// Boolean pref which determines whether key repeat is enabled.
const char kXkbAutoRepeatEnabled[] =
"settings.language.xkb_auto_repeat_enabled_r2";

// Integer pref which determines key repeat delay (in ms).
const char kXkbAutoRepeatDelay[] = "settings.language.xkb_auto_repeat_delay_r2";

// Integer pref which determines key repeat interval (in ms).
const char kXkbAutoRepeatInterval[] =
"settings.language.xkb_auto_repeat_interval_r2";
// "_r2" suffixes were added to the three prefs above when we changed the
// preferences to not be user-configurable or sync with the cloud. The prefs are
// now user-configurable and syncable again, but we don't want to overwrite the
// current values with the old synced values, so we continue to use this suffix.

// A boolean pref which is true if touchpad reverse scroll is enabled.
const char kNaturalScroll[] = "settings.touchpad.natural_scroll";
// A boolean pref which is true if mouse reverse scroll is enabled.
Expand Down
4 changes: 4 additions & 0 deletions ash/public/cpp/ash_pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ ASH_PUBLIC_EXPORT extern const char kAssistantPrivacyInfoDismissedInLauncher[];

ASH_PUBLIC_EXPORT extern const char kLockScreenMediaControlsEnabled[];

ASH_PUBLIC_EXPORT extern const char kXkbAutoRepeatDelay[];
ASH_PUBLIC_EXPORT extern const char kXkbAutoRepeatEnabled[];
ASH_PUBLIC_EXPORT extern const char kXkbAutoRepeatInterval[];

ASH_PUBLIC_EXPORT extern const char kNaturalScroll[];
ASH_PUBLIC_EXPORT extern const char kMouseReverseScroll[];

Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/chromeos/language_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const char kPreloadEnginesConfigName[] = "preload_engines";
// ---------------------------------------------------------------------------
// For keyboard stuff
// ---------------------------------------------------------------------------
const bool kXkbAutoRepeatEnabled = true;
const int kXkbAutoRepeatDelayInMs = 500;
const int kXkbAutoRepeatIntervalInMs = 50;
const char kPreferredKeyboardLayout[] = "PreferredKeyboardLayout";

void RegisterPrefs(PrefRegistrySimple* registry) {
Expand Down
7 changes: 0 additions & 7 deletions chrome/browser/chromeos/language_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ extern const char kPreloadEnginesConfigName[];
// ---------------------------------------------------------------------------
// For keyboard stuff
// ---------------------------------------------------------------------------
// A flag indicating whether the keyboard auto repeat is enabled.
extern const bool kXkbAutoRepeatEnabled;
// A delay between the first and the start of the rest.
extern const int kXkbAutoRepeatDelayInMs;
// An interval between the repeated keys.
extern const int kXkbAutoRepeatIntervalInMs;

// A string Chrome preference (Local State) of the preferred keyboard layout in
// the login screen.
extern const char kPreferredKeyboardLayout[];
Expand Down
16 changes: 9 additions & 7 deletions chrome/browser/chromeos/login/lock_screen_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#include "chrome/browser/chromeos/login/lock_screen_utils.h"

#include "ash/public/cpp/ash_constants.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/language_preferences.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/ui/ash/ime_controller_client.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -135,9 +136,9 @@ void StopEnforcingPolicyInputMethods() {
}

void SetKeyboardSettings(const AccountId& account_id) {
bool auto_repeat_enabled = language_prefs::kXkbAutoRepeatEnabled;
bool auto_repeat_enabled = ash::kDefaultKeyAutoRepeatEnabled;
if (user_manager::known_user::GetBooleanPref(
account_id, prefs::kLanguageXkbAutoRepeatEnabled,
account_id, ash::prefs::kXkbAutoRepeatEnabled,
&auto_repeat_enabled) &&
!auto_repeat_enabled) {
input_method::InputMethodManager::Get()
Expand All @@ -146,12 +147,13 @@ void SetKeyboardSettings(const AccountId& account_id) {
return;
}

int auto_repeat_delay = language_prefs::kXkbAutoRepeatDelayInMs;
int auto_repeat_interval = language_prefs::kXkbAutoRepeatIntervalInMs;
int auto_repeat_delay = ash::kDefaultKeyAutoRepeatDelay.InMilliseconds();
int auto_repeat_interval =
ash::kDefaultKeyAutoRepeatInterval.InMilliseconds();
user_manager::known_user::GetIntegerPref(
account_id, prefs::kLanguageXkbAutoRepeatDelay, &auto_repeat_delay);
account_id, ash::prefs::kXkbAutoRepeatDelay, &auto_repeat_delay);
user_manager::known_user::GetIntegerPref(
account_id, prefs::kLanguageXkbAutoRepeatInterval, &auto_repeat_interval);
account_id, ash::prefs::kXkbAutoRepeatInterval, &auto_repeat_interval);
input_method::AutoRepeatRate rate;
rate.initial_delay_in_ms = auto_repeat_delay;
rate.repeat_interval_in_ms = auto_repeat_interval;
Expand Down
40 changes: 14 additions & 26 deletions chrome/browser/chromeos/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,18 +312,6 @@ void Preferences::RegisterProfilePrefs(
// depending on whether an external keyboard is attached to a particular
// device.
registry->RegisterBooleanPref(prefs::kLanguageSendFunctionKeys, false);
registry->RegisterBooleanPref(
prefs::kLanguageXkbAutoRepeatEnabled,
language_prefs::kXkbAutoRepeatEnabled,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kLanguageXkbAutoRepeatDelay,
language_prefs::kXkbAutoRepeatDelayInMs,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);
registry->RegisterIntegerPref(
prefs::kLanguageXkbAutoRepeatInterval,
language_prefs::kXkbAutoRepeatIntervalInMs,
user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF);

// Don't sync the note-taking app; it may not be installed on other devices.
registry->RegisterStringPref(prefs::kNoteTakingAppId, std::string());
Expand Down Expand Up @@ -503,12 +491,12 @@ void Preferences::InitUserPrefs(sync_preferences::PrefServiceSyncable* prefs) {
if (ime_menu_activated_.GetValue())
input_method::InputMethodManager::Get()->ImeMenuActivationChanged(true);

xkb_auto_repeat_enabled_.Init(
prefs::kLanguageXkbAutoRepeatEnabled, prefs, callback);
xkb_auto_repeat_delay_pref_.Init(
prefs::kLanguageXkbAutoRepeatDelay, prefs, callback);
xkb_auto_repeat_interval_pref_.Init(
prefs::kLanguageXkbAutoRepeatInterval, prefs, callback);
xkb_auto_repeat_enabled_.Init(ash::prefs::kXkbAutoRepeatEnabled, prefs,
callback);
xkb_auto_repeat_delay_pref_.Init(ash::prefs::kXkbAutoRepeatDelay, prefs,
callback);
xkb_auto_repeat_interval_pref_.Init(ash::prefs::kXkbAutoRepeatInterval, prefs,
callback);

wake_on_wifi_darkconnect_.Init(prefs::kWakeOnWifiDarkConnect, prefs,
callback);
Expand Down Expand Up @@ -827,20 +815,20 @@ void Preferences::ApplyPreferences(ApplyReason reason,
}

if (reason != REASON_PREF_CHANGED ||
pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
pref_name == ash::prefs::kXkbAutoRepeatEnabled) {
if (user_is_active) {
const bool enabled = xkb_auto_repeat_enabled_.GetValue();
input_method::InputMethodManager::Get()
->GetImeKeyboard()
->SetAutoRepeatEnabled(enabled);

user_manager::known_user::SetBooleanPref(
user_->GetAccountId(), prefs::kLanguageXkbAutoRepeatEnabled, enabled);
user_->GetAccountId(), ash::prefs::kXkbAutoRepeatEnabled, enabled);
}
}
if (reason != REASON_PREF_CHANGED ||
pref_name == prefs::kLanguageXkbAutoRepeatDelay ||
pref_name == prefs::kLanguageXkbAutoRepeatInterval) {
pref_name == ash::prefs::kXkbAutoRepeatDelay ||
pref_name == ash::prefs::kXkbAutoRepeatInterval) {
if (user_is_active)
UpdateAutoRepeatRate();
}
Expand Down Expand Up @@ -1071,11 +1059,11 @@ void Preferences::UpdateAutoRepeatRate() {
->SetAutoRepeatRate(rate);

user_manager::known_user::SetIntegerPref(user_->GetAccountId(),
prefs::kLanguageXkbAutoRepeatDelay,
ash::prefs::kXkbAutoRepeatDelay,
rate.initial_delay_in_ms);
user_manager::known_user::SetIntegerPref(
user_->GetAccountId(), prefs::kLanguageXkbAutoRepeatInterval,
rate.repeat_interval_in_ms);
user_manager::known_user::SetIntegerPref(user_->GetAccountId(),
ash::prefs::kXkbAutoRepeatInterval,
rate.repeat_interval_in_ms);
}

void Preferences::ActiveUserChanged(user_manager::User* active_user) {
Expand Down
12 changes: 6 additions & 6 deletions chrome/browser/chromeos/preferences_chromeos_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class PreferencesTest : public LoginManagerTest {
prefs->SetInteger(prefs::kMouseScrollSensitivity, variant ? 1 : 4);
prefs->SetInteger(prefs::kTouchpadSensitivity, variant);
prefs->SetInteger(prefs::kTouchpadScrollSensitivity, variant ? 1 : 4);
prefs->SetBoolean(prefs::kLanguageXkbAutoRepeatEnabled, variant);
prefs->SetInteger(prefs::kLanguageXkbAutoRepeatDelay, variant ? 100 : 500);
prefs->SetInteger(prefs::kLanguageXkbAutoRepeatInterval, variant ? 1 : 4);
prefs->SetBoolean(ash::prefs::kXkbAutoRepeatEnabled, variant);
prefs->SetInteger(ash::prefs::kXkbAutoRepeatDelay, variant ? 100 : 500);
prefs->SetInteger(ash::prefs::kXkbAutoRepeatInterval, variant ? 1 : 4);
prefs->SetString(prefs::kLanguagePreloadEngines,
variant ? "xkb:us::eng,xkb:us:dvorak:eng"
: "xkb:us::eng,xkb:ru::rus");
Expand Down Expand Up @@ -108,12 +108,12 @@ class PreferencesTest : public LoginManagerTest {
EXPECT_EQ(
prefs->GetInteger(prefs::kTouchpadScrollSensitivity),
input_settings_->current_touchpad_settings().GetScrollSensitivity());
EXPECT_EQ(prefs->GetBoolean(prefs::kLanguageXkbAutoRepeatEnabled),
EXPECT_EQ(prefs->GetBoolean(ash::prefs::kXkbAutoRepeatEnabled),
keyboard_->auto_repeat_is_enabled_);
input_method::AutoRepeatRate rate = keyboard_->last_auto_repeat_rate_;
EXPECT_EQ(prefs->GetInteger(prefs::kLanguageXkbAutoRepeatDelay),
EXPECT_EQ(prefs->GetInteger(ash::prefs::kXkbAutoRepeatDelay),
(int)rate.initial_delay_in_ms);
EXPECT_EQ(prefs->GetInteger(prefs::kLanguageXkbAutoRepeatInterval),
EXPECT_EQ(prefs->GetInteger(ash::prefs::kXkbAutoRepeatInterval),
(int)rate.repeat_interval_in_ms);
EXPECT_EQ(prefs->GetString(prefs::kLanguageCurrentInputMethod),
input_method::InputMethodManager::Get()
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/extensions/api/settings_private/prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,11 @@ const PrefsUtil::TypedPrefMap& PrefsUtil::GetWhitelistedKeys() {
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_whitelist)[::prefs::kLanguageSendFunctionKeys] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::prefs::kLanguageXkbAutoRepeatEnabled] =
(*s_whitelist)[::ash::prefs::kXkbAutoRepeatEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
(*s_whitelist)[::prefs::kLanguageXkbAutoRepeatDelay] =
(*s_whitelist)[::ash::prefs::kXkbAutoRepeatDelay] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_whitelist)[::prefs::kLanguageXkbAutoRepeatInterval] =
(*s_whitelist)[::ash::prefs::kXkbAutoRepeatInterval] =
settings_api::PrefType::PREF_TYPE_NUMBER;
(*s_whitelist)[chromeos::kDeviceDisplayResolution] =
settings_api::PrefType::PREF_TYPE_DICTIONARY;
Expand Down
14 changes: 0 additions & 14 deletions chrome/common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,20 +600,6 @@ const char kLanguageShouldMergeInputMethods[] =
const char kLanguageSendFunctionKeys[] =
"settings.language.send_function_keys";

// A boolean pref which determines whether key repeat is enabled.
const char kLanguageXkbAutoRepeatEnabled[] =
"settings.language.xkb_auto_repeat_enabled_r2";
// A integer pref which determines key repeat delay (in ms).
const char kLanguageXkbAutoRepeatDelay[] =
"settings.language.xkb_auto_repeat_delay_r2";
// A integer pref which determines key repeat interval (in ms).
const char kLanguageXkbAutoRepeatInterval[] =
"settings.language.xkb_auto_repeat_interval_r2";
// "_r2" suffixes were added to the three prefs above when we changed the
// preferences to not be user-configurable or sync with the cloud. The prefs are
// now user-configurable and syncable again, but we don't want to overwrite the
// current values with the old synced values, so we continue to use this suffix.

// A boolean pref which turns on Advanced Filesystem
// (USB support, SD card, etc).
const char kLabsAdvancedFilesystemEnabled[] =
Expand Down
3 changes: 0 additions & 3 deletions chrome/common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,6 @@ extern const char kLanguageImeMenuActivated[];
extern const char kLanguageInputMethodSpecificSettings[];
extern const char kLanguageShouldMergeInputMethods[];
extern const char kLanguageSendFunctionKeys[];
extern const char kLanguageXkbAutoRepeatEnabled[];
extern const char kLanguageXkbAutoRepeatDelay[];
extern const char kLanguageXkbAutoRepeatInterval[];

extern const char kLabsAdvancedFilesystemEnabled[];
extern const char kLabsMediaplayerEnabled[];
Expand Down

0 comments on commit 186ed3e

Please sign in to comment.