diff options
author | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 04:38:59 +0000 |
---|---|---|
committer | yusukes@chromium.org <yusukes@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-11 04:38:59 +0000 |
commit | a995b3951040512507269b70b527fd7fc408da2b (patch) | |
tree | 59686a66ed2405c8357e9a20e29141590e12555c | |
parent | 4605be79a582881a1987b79694437be52df959af (diff) | |
download | chromium_src-a995b3951040512507269b70b527fd7fc408da2b.zip chromium_src-a995b3951040512507269b70b527fd7fc408da2b.tar.gz chromium_src-a995b3951040512507269b70b527fd7fc408da2b.tar.bz2 |
Add Views UI for setting keyboard repeat delay and repeat interval.
BUG=chromium-os:4102
TEST=ran unit_tests
Review URL: http://codereview.chromium.org/3023044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55670 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 28 | ||||
-rw-r--r-- | chrome/browser/chromeos/language_preferences.h | 11 | ||||
-rw-r--r-- | chrome/browser/chromeos/language_preferences_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/settings_page_view.cc | 16 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/settings_page_view.h | 2 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/system_page_view.cc | 115 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.cc | 29 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.h | 8 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 10 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 3 |
10 files changed, 216 insertions, 10 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 56acd3e..e12775f 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -8541,6 +8541,34 @@ Keep your key file in a safe place. You will need it to create new versions of y desc="The label for 'Configure modifier keys' drop-down"> Swap Left Control and Left Alt keys </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_ENABLED" + desc="The label for the Chrome OS configuration dialog"> + Repeat keys + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY" + desc="The label for the Chrome OS configuration dialog"> + Key repeat delay: + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY_SHORT" + desc="The label for the Chrome OS configuration dialog"> + short + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY_LONG" + desc="The label for the Chrome OS configuration dialog"> + long + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED" + desc="The label for the Chrome OS configuration dialog"> + Key repeat speed: + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED_FAST" + desc="The label for the Chrome OS configuration dialog"> + fast + </message> + <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED_SLOW" + desc="The label for the Chrome OS configuration dialog"> + slow + </message> <message name="IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_MODIFIER_REMAP_SEARCH_CTRL" desc="The label for 'Configure modifier keys' drop-down"> Swap Search and Left Control keys diff --git a/chrome/browser/chromeos/language_preferences.h b/chrome/browser/chromeos/language_preferences.h index bc08750..1e8116b 100644 --- a/chrome/browser/chromeos/language_preferences.h +++ b/chrome/browser/chromeos/language_preferences.h @@ -113,6 +113,17 @@ const LanguageMultipleChoicePreference<int> kXkbModifierMultipleChoicePrefs = { 0, // does not use the label. }; +const LanguageIntegerRangePreference kXkbAutoRepeatDelayPref = { + prefs::kLanguageXkbAutoRepeatDelay, 500, 100, 2000, + NULL, // does not use the ibus configuration service. + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY, +}; +const LanguageIntegerRangePreference kXkbAutoRepeatIntervalPref = { + prefs::kLanguageXkbAutoRepeatInterval, 33, 9, 100, + NULL, // does not use the ibus configuration service. + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED, +}; + const LanguageMultipleChoicePreference<const char*> kChewingMultipleChoicePrefs[] = { { prefs::kLanguageChewingKeyboardType, diff --git a/chrome/browser/chromeos/language_preferences_unittest.cc b/chrome/browser/chromeos/language_preferences_unittest.cc index d941e72..02e744e 100644 --- a/chrome/browser/chromeos/language_preferences_unittest.cc +++ b/chrome/browser/chromeos/language_preferences_unittest.cc @@ -131,6 +131,10 @@ TEST(LanguagePreferencesTest, TestDefaultValuesOfIntegerRangePrefs) { kChewingIntegerPrefs, kNumChewingIntegerPrefs)); EXPECT_TRUE(CheckDefaultValueOfIntegerRangePrefs( kMozcIntegerPrefs, kNumMozcIntegerPrefs)); + EXPECT_TRUE(CheckDefaultValueOfIntegerRangePrefs( + &kXkbAutoRepeatDelayPref, 1)); + EXPECT_TRUE(CheckDefaultValueOfIntegerRangePrefs( + &kXkbAutoRepeatIntervalPref, 1)); } } // namespace chromeos diff --git a/chrome/browser/chromeos/options/settings_page_view.cc b/chrome/browser/chromeos/options/settings_page_view.cc index 84d9654..6518cdf 100644 --- a/chrome/browser/chromeos/options/settings_page_view.cc +++ b/chrome/browser/chromeos/options/settings_page_view.cc @@ -47,7 +47,8 @@ SettingsPageSection::SettingsPageSection(Profile* profile, int title_msg_id) title_msg_id_(title_msg_id), // Using 1000 so that it does not clash with ids defined in subclasses. single_column_view_set_id_(1000), - double_column_view_set_id_(1001) { + double_column_view_set_id_(1001), + quad_column_view_set_id_(1003) { } void SettingsPageSection::InitControlLayout() { @@ -90,6 +91,19 @@ void SettingsPageSection::InitControlLayout() { column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, GridLayout::USE_PREF, 0, 0); + column_set = child_layout->AddColumnSet(quad_column_view_set_id_); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, + GridLayout::USE_PREF, 0, 0); + column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); + column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, + GridLayout::USE_PREF, 0, 0); + InitContents(child_layout); layout->AddView(contents); } diff --git a/chrome/browser/chromeos/options/settings_page_view.h b/chrome/browser/chromeos/options/settings_page_view.h index 35e9934..86d21e9 100644 --- a/chrome/browser/chromeos/options/settings_page_view.h +++ b/chrome/browser/chromeos/options/settings_page_view.h @@ -49,6 +49,7 @@ class SettingsPageSection : public OptionsPageView { int single_column_view_set_id() const { return single_column_view_set_id_; } int double_column_view_set_id() const { return double_column_view_set_id_; } + int quad_column_view_set_id() const { return quad_column_view_set_id_; } private: // The message id for the title of this section. @@ -56,6 +57,7 @@ class SettingsPageSection : public OptionsPageView { int single_column_view_set_id_; int double_column_view_set_id_; + int quad_column_view_set_id_; DISALLOW_COPY_AND_ASSIGN(SettingsPageSection); }; diff --git a/chrome/browser/chromeos/options/system_page_view.cc b/chrome/browser/chromeos/options/system_page_view.cc index 416a474..0c1e375 100644 --- a/chrome/browser/chromeos/options/system_page_view.cc +++ b/chrome/browser/chromeos/options/system_page_view.cc @@ -14,6 +14,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/cros/cros_library.h" #include "chrome/browser/chromeos/cros/system_library.h" +#include "chrome/browser/chromeos/language_preferences.h" #include "chrome/browser/chromeos/options/language_config_util.h" #include "chrome/browser/chromeos/options/language_config_view.h" #include "chrome/browser/chromeos/options/options_window_view.h" @@ -353,7 +354,8 @@ void TouchpadSection::NotifyPrefChanged(const std::string* pref_name) { // TextInput section for text input settings. class LanguageSection : public SettingsPageSection, public views::ButtonListener, - public views::Combobox::Listener { + public views::Combobox::Listener, + public views::SliderListener { public: explicit LanguageSection(Profile* profile); virtual ~LanguageSection() {} @@ -361,6 +363,7 @@ class LanguageSection : public SettingsPageSection, private: enum ButtonTag { kCustomizeLanguagesButton, + kEnableAutoRepeatButton, }; // Overridden from SettingsPageSection: virtual void InitContents(GridLayout* layout); @@ -375,10 +378,21 @@ class LanguageSection : public SettingsPageSection, int prev_index, int new_index); - IntegerPrefMember xkb_pref_; + // Overridden from views::SliderListener. + virtual void SliderValueChanged(views::Slider* sender); + + IntegerPrefMember xkb_modifier_pref_; views::Combobox* xkb_modifier_combobox_; chromeos::LanguageComboboxModel<int> xkb_modifier_combobox_model_; + BooleanPrefMember xkb_auto_repeat_pref_; + views::Checkbox* xkb_auto_repeat_checkbox_; + + IntegerPrefMember xkb_auto_repeat_delay_pref_; + views::Slider* xkb_auto_repeat_delay_slider_; + IntegerPrefMember xkb_auto_repeat_interval_pref_; + views::Slider* xkb_auto_repeat_interval_slider_; + DISALLOW_COPY_AND_ASSIGN(LanguageSection); }; @@ -386,8 +400,17 @@ LanguageSection::LanguageSection(Profile* profile) : SettingsPageSection(profile, IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE), xkb_modifier_combobox_(NULL), - xkb_modifier_combobox_model_(&kXkbModifierMultipleChoicePrefs) { - xkb_pref_.Init(prefs::kLanguageXkbModifierRemap, profile->GetPrefs(), this); + xkb_modifier_combobox_model_(&kXkbModifierMultipleChoicePrefs), + xkb_auto_repeat_delay_slider_(NULL), + xkb_auto_repeat_interval_slider_(NULL) { + xkb_modifier_pref_.Init( + kXkbModifierMultipleChoicePrefs.pref_name, profile->GetPrefs(), this); + xkb_auto_repeat_pref_.Init( + prefs::kLanguageXkbAutoRepeatEnabled, profile->GetPrefs(), this); + xkb_auto_repeat_delay_pref_.Init( + kXkbAutoRepeatDelayPref.pref_name, profile->GetPrefs(), this); + xkb_auto_repeat_interval_pref_.Init( + kXkbAutoRepeatIntervalPref.pref_name, profile->GetPrefs(), this); } void LanguageSection::InitContents(GridLayout* layout) { @@ -397,16 +420,67 @@ void LanguageSection::InitContents(GridLayout* layout) { this, l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE)); customize_languages_button->set_tag(kCustomizeLanguagesButton); - layout->AddView(customize_languages_button, 1, 1, - GridLayout::LEADING, GridLayout::CENTER); xkb_modifier_combobox_ = new views::Combobox(&xkb_modifier_combobox_model_); xkb_modifier_combobox_->set_listener(this); + + xkb_auto_repeat_checkbox_ = new views::Checkbox(l10n_util::GetString( + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_ENABLED)); + xkb_auto_repeat_checkbox_->set_tag(kEnableAutoRepeatButton); + xkb_auto_repeat_checkbox_->set_listener(this); + + xkb_auto_repeat_delay_slider_ = new views::Slider( + kXkbAutoRepeatDelayPref.min_pref_value, + kXkbAutoRepeatDelayPref.max_pref_value, + 1, + static_cast<views::Slider::StyleFlags>( + views::Slider::STYLE_UPDATE_ON_RELEASE), + this); + xkb_auto_repeat_interval_slider_ = new views::Slider( + kXkbAutoRepeatIntervalPref.min_pref_value, + kXkbAutoRepeatIntervalPref.max_pref_value, + 1, + static_cast<views::Slider::StyleFlags>( + views::Slider::STYLE_UPDATE_ON_RELEASE), + this); + // Initialize the combobox to what's saved in user preferences. Otherwise, // ItemChanged() will be called with |new_index| == 0. NotifyPrefChanged(NULL); + layout->AddView(customize_languages_button, 1, 1, + GridLayout::LEADING, GridLayout::CENTER); layout->AddView(xkb_modifier_combobox_); + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, single_column_view_set_id()); + layout->AddView(xkb_auto_repeat_checkbox_); + + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, quad_column_view_set_id()); + layout->AddView(new views::Label( + l10n_util::GetString(kXkbAutoRepeatDelayPref.message_id)), + 1, 1, GridLayout::LEADING, GridLayout::CENTER); + layout->AddView(new views::Label( + l10n_util::GetString( + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY_SHORT))); + layout->AddView(xkb_auto_repeat_delay_slider_); + layout->AddView(new views::Label( + l10n_util::GetString( + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_DELAY_LONG))); + + layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); + layout->StartRow(0, quad_column_view_set_id()); + layout->AddView(new views::Label( + l10n_util::GetString(kXkbAutoRepeatIntervalPref.message_id)), + 1, 1, GridLayout::LEADING, GridLayout::CENTER); + layout->AddView(new views::Label( + l10n_util::GetString( + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED_FAST))); + layout->AddView(xkb_auto_repeat_interval_slider_); + layout->AddView(new views::Label( + l10n_util::GetString( + IDS_OPTIONS_SETTINGS_LANGUAGES_XKB_KEY_REPEAT_SPEED_SLOW))); + layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); } @@ -414,6 +488,9 @@ void LanguageSection::ButtonPressed( views::Button* sender, const views::Event& event) { if (sender->tag() == kCustomizeLanguagesButton) { LanguageConfigView::Show(profile(), GetOptionsViewParent()); + } else if (sender->tag() == kEnableAutoRepeatButton) { + const bool enabled = xkb_auto_repeat_checkbox_->checked(); + xkb_auto_repeat_pref_.SetValue(enabled); } } @@ -421,16 +498,36 @@ void LanguageSection::ItemChanged(views::Combobox* sender, int prev_index, int new_index) { LOG(INFO) << "Changing XKB modofier pref to " << new_index; - xkb_pref_.SetValue(new_index); + xkb_modifier_pref_.SetValue(new_index); +} + +void LanguageSection::SliderValueChanged(views::Slider* sender) { + if (xkb_auto_repeat_delay_slider_ == sender) { + xkb_auto_repeat_delay_pref_.SetValue(sender->value()); + } else if (xkb_auto_repeat_interval_slider_ == sender) { + xkb_auto_repeat_interval_pref_.SetValue(sender->value()); + } } void LanguageSection::NotifyPrefChanged(const std::string* pref_name) { - if (!pref_name || *pref_name == prefs::kLanguageXkbModifierRemap) { - const int id = xkb_pref_.GetValue(); + if (!pref_name || *pref_name == kXkbModifierMultipleChoicePrefs.pref_name) { + const int id = xkb_modifier_pref_.GetValue(); if (id >= 0) { xkb_modifier_combobox_->SetSelectedItem(id); } } + if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { + const bool enabled = xkb_auto_repeat_pref_.GetValue(); + xkb_auto_repeat_checkbox_->SetChecked(enabled); + } + if (!pref_name || *pref_name == kXkbAutoRepeatDelayPref.pref_name) { + const int delay_value = xkb_auto_repeat_delay_pref_.GetValue(); + xkb_auto_repeat_delay_slider_->SetValue(delay_value); + } + if (!pref_name || *pref_name == kXkbAutoRepeatIntervalPref.pref_name) { + const int interval_value = xkb_auto_repeat_interval_pref_.GetValue(); + xkb_auto_repeat_interval_slider_->SetValue(interval_value); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 30a53d8..15594bb 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -87,6 +87,11 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterIntegerPref( kXkbModifierMultipleChoicePrefs.pref_name, kXkbModifierMultipleChoicePrefs.default_pref_value); + prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled, true); + prefs->RegisterIntegerPref(kXkbAutoRepeatDelayPref.pref_name, + kXkbAutoRepeatDelayPref.default_pref_value); + prefs->RegisterIntegerPref(kXkbAutoRepeatIntervalPref.pref_name, + kXkbAutoRepeatIntervalPref.default_pref_value); } void Preferences::Init(PrefService* prefs) { @@ -143,6 +148,12 @@ void Preferences::Init(PrefService* prefs) { } language_xkb_modifier_remap_.Init( kXkbModifierMultipleChoicePrefs.pref_name, prefs, this); + language_xkb_auto_repeat_enabled_.Init( + prefs::kLanguageXkbAutoRepeatEnabled, prefs, this); + language_xkb_auto_repeat_delay_pref_.Init( + kXkbAutoRepeatDelayPref.pref_name, prefs, this); + language_xkb_auto_repeat_interval_pref_.Init( + kXkbAutoRepeatIntervalPref.pref_name, prefs, this); std::string locale(g_browser_process->GetApplicationLocale()); // Add input methods based on the application locale when the user first @@ -333,6 +344,14 @@ void Preferences::NotifyPrefChanged(const std::string* pref_name) { } CrosLibrary::Get()->GetKeyboardLibrary()->RemapModifierKeys(modifier_map); } + if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) { + const bool enabled = language_xkb_auto_repeat_enabled_.GetValue(); + CrosLibrary::Get()->GetKeyboardLibrary()->SetAutoRepeatEnabled(enabled); + } + if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) || + (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) { + UpdateAutoRepeatRate(); + } } void Preferences::SetLanguageConfigBoolean(const char* section, @@ -392,4 +411,14 @@ void Preferences::SetLanguageConfigStringListAsCSV(const char* section, SetLanguageConfigStringList(section, name, split_values); } +void Preferences::UpdateAutoRepeatRate() { + AutoRepeatRate rate; + rate.initial_delay_in_ms = language_xkb_auto_repeat_delay_pref_.GetValue(); + rate.repeat_interval_in_ms = + language_xkb_auto_repeat_interval_pref_.GetValue(); + DCHECK(rate.initial_delay_in_ms > 0); + DCHECK(rate.repeat_interval_in_ms > 0); + CrosLibrary::Get()->GetKeyboardLibrary()->SetAutoRepeatRate(rate); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index b1b8649..9dd86e1 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -75,6 +75,11 @@ class Preferences : public NotificationObserver { const char* name, const std::string& value); + // Updates the initial key repeat delay and key repeat interval following + // current prefs values. We set the delay and interval at once since an + // underlying XKB API requires it. + void UpdateAutoRepeatRate(); + BooleanPrefMember tap_to_click_enabled_; BooleanPrefMember vert_edge_scroll_enabled_; BooleanPrefMember accessibility_enabled_; @@ -101,6 +106,9 @@ class Preferences : public NotificationObserver { kNumMozcMultipleChoicePrefs]; IntegerPrefMember language_mozc_integer_prefs_[kNumMozcIntegerPrefs]; IntegerPrefMember language_xkb_modifier_remap_; + BooleanPrefMember language_xkb_auto_repeat_enabled_; + IntegerPrefMember language_xkb_auto_repeat_delay_pref_; + IntegerPrefMember language_xkb_auto_repeat_interval_pref_; DISALLOW_COPY_AND_ASSIGN(Preferences); }; diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index ad8433a..cd47625 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -336,6 +336,16 @@ const char kLanguageMozcSuggestionsSize[] = // DOM UI) is implemented. See crosbug.com/2636. const char kLanguageXkbModifierRemap[] = "settings.language.xkb_modifier_remap"; +// A boolean pref which determines whether key repeat is enabled. +const char kLanguageXkbAutoRepeatEnabled[] = + "settings.language.xkb_auto_repeat_enabled"; +// A integer pref which determines key repeat delay (in ms). +const char kLanguageXkbAutoRepeatDelay[] = + "settings.language.xkb_auto_repeat_delay"; +// A integer pref which determines key repeat interval (in ms). +const char kLanguageXkbAutoRepeatInterval[] = + "settings.language.xkb_auto_repeat_interval"; + // A boolean pref which determines whether accessibility is enabled. const char kAccessibilityEnabled[] = "settings.accessibility"; diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index c77bf26..61e87bf 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -129,6 +129,9 @@ extern const char kLanguageMozcUseHistorySuggest[]; extern const char kLanguageMozcUseDictionarySuggest[]; extern const char kLanguageMozcSuggestionsSize[]; extern const char kLanguageXkbModifierRemap[]; +extern const char kLanguageXkbAutoRepeatEnabled[]; +extern const char kLanguageXkbAutoRepeatDelay[]; +extern const char kLanguageXkbAutoRepeatInterval[]; extern const char kAccessibilityEnabled[]; extern const char kLabsAdvancedFilesystemEnabled[]; extern const char kLabsMediaplayerEnabled[]; |