diff options
author | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 04:32:24 +0000 |
---|---|---|
committer | yusukes@google.com <yusukes@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 04:32:24 +0000 |
commit | f410d61469606a7aaa42520ff581e813b3db8e9b (patch) | |
tree | 32e6c6f90fe7c1c780c5ef487dcd168ce35a1639 | |
parent | 357ce204ef613d512390581d6884dbff880c8464 (diff) | |
download | chromium_src-f410d61469606a7aaa42520ff581e813b3db8e9b.zip chromium_src-f410d61469606a7aaa42520ff581e813b3db8e9b.tar.gz chromium_src-f410d61469606a7aaa42520ff581e813b3db8e9b.tar.bz2 |
Add pref entry for virtual keyboard.
This CL depends on http://codereview.chromium.org/7497028/.
BUG=None
TEST=manual, ran unit_tests
Review URL: http://codereview.chromium.org/7493077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95578 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 100 insertions, 3 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_manager.cc b/chrome/browser/chromeos/input_method/input_method_manager.cc index 0f532f8..f1cf15c 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager.cc +++ b/chrome/browser/chromeos/input_method/input_method_manager.cc @@ -310,6 +310,16 @@ class InputMethodManagerImpl : public InputMethodManager, is_system); } + virtual bool SetVirtualKeyboardPreference(const std::string& input_method_id, + const GURL& extention_url) { + return virtual_keyboard_selector_.SetUserPreference( + input_method_id, extention_url); + } + + virtual void ClearAllVirtualKeyboardPreferences() { + return virtual_keyboard_selector_.ClearAllUserPreferences(); + } + static InputMethodManagerImpl* GetInstance() { return Singleton<InputMethodManagerImpl, DefaultSingletonTraits<InputMethodManagerImpl> >::get(); diff --git a/chrome/browser/chromeos/input_method/input_method_manager.h b/chrome/browser/chromeos/input_method/input_method_manager.h index 1c0d14b..37576e4 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager.h +++ b/chrome/browser/chromeos/input_method/input_method_manager.h @@ -26,7 +26,6 @@ namespace input_method { class VirtualKeyboard; - // This class manages input methodshandles. Classes can add themselves as // observers. Clients can get an instance of this library class by: // InputMethodManager::GetInstance(). @@ -170,6 +169,15 @@ class InputMethodManager { const std::set<std::string>& layouts, bool is_system) = 0; + // Sets user preference on virtual keyboard selection. + // See virtual_keyboard_selector.h for details. + virtual bool SetVirtualKeyboardPreference(const std::string& input_method_id, + const GURL& extention_url) = 0; + + // Clears all preferences on virtual keyboard selection. + // See virtual_keyboard_selector.h for details. + virtual void ClearAllVirtualKeyboardPreferences() = 0; + virtual input_method::InputMethodDescriptor previous_input_method() const = 0; virtual input_method::InputMethodDescriptor current_input_method() const = 0; diff --git a/chrome/browser/chromeos/input_method/virtual_keyboard_selector.cc b/chrome/browser/chromeos/input_method/virtual_keyboard_selector.cc index fb04aba..056ef0a 100644 --- a/chrome/browser/chromeos/input_method/virtual_keyboard_selector.cc +++ b/chrome/browser/chromeos/input_method/virtual_keyboard_selector.cc @@ -145,6 +145,10 @@ void VirtualKeyboardSelector::RemoveUserPreference(const std::string& layout) { user_preference_.erase(layout); } +void VirtualKeyboardSelector::ClearAllUserPreferences() { + user_preference_.clear(); +} + const VirtualKeyboard* VirtualKeyboardSelector::SelectVirtualKeyboardWithoutPreferences( const std::string& layout) { diff --git a/chrome/browser/chromeos/input_method/virtual_keyboard_selector.h b/chrome/browser/chromeos/input_method/virtual_keyboard_selector.h index 9da69d9..357a868 100644 --- a/chrome/browser/chromeos/input_method/virtual_keyboard_selector.h +++ b/chrome/browser/chromeos/input_method/virtual_keyboard_selector.h @@ -92,6 +92,9 @@ class VirtualKeyboardSelector { // Removes the preference for the |layout| added by SetUserPreference. void RemoveUserPreference(const std::string& layout); + // Removes all preferences added by SetUserPreference. + void ClearAllUserPreferences(); + protected: // Selects and returns the most suitable virtual keyboard extension for the // |layout|. Unlike SelectVirtualKeyboard(), this function only scans diff --git a/chrome/browser/chromeos/input_method/virtual_keyboard_selector_unittest.cc b/chrome/browser/chromeos/input_method/virtual_keyboard_selector_unittest.cc index 5eb5125..3e3b89f 100644 --- a/chrome/browser/chromeos/input_method/virtual_keyboard_selector_unittest.cc +++ b/chrome/browser/chromeos/input_method/virtual_keyboard_selector_unittest.cc @@ -400,6 +400,40 @@ TEST(VirtualKeyboardSelectorTest, TestSetUserPreference2) { EXPECT_EQ(3U, selector.user_preference().size()); } +TEST(VirtualKeyboardSelectorTest, TestRemoveUserPreference) { + static const char* layouts[] = { "a", "b", "c" }; + + VirtualKeyboard user_virtual_keyboard_1( + GURL("http://user1"), CreateLayoutSet(layouts), false /* is_system */); + VirtualKeyboard user_virtual_keyboard_2( + GURL("http://user2"), CreateLayoutSet(layouts), false /* is_system */); + + TestableVirtualKeyboardSelector selector; + EXPECT_TRUE(selector.AddVirtualKeyboard( + user_virtual_keyboard_1.url(), + user_virtual_keyboard_1.supported_layouts(), + user_virtual_keyboard_1.is_system())); + EXPECT_TRUE(selector.AddVirtualKeyboard( + user_virtual_keyboard_2.url(), + user_virtual_keyboard_2.supported_layouts(), + user_virtual_keyboard_2.is_system())); + + EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://user1"))); + EXPECT_TRUE(selector.SetUserPreference("b", GURL("http://user1"))); + EXPECT_TRUE(selector.SetUserPreference("c", GURL("http://user1"))); + EXPECT_EQ(3U, selector.user_preference().size()); + + selector.RemoveUserPreference("b"); + EXPECT_EQ(2U, selector.user_preference().size()); + ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("b")); + // user_virtual_keyboard_2 should be selected here since the keyboard is + // added most recently and the user preference on "b" is already removed. + EXPECT_TRUE(user_virtual_keyboard_2 == *selector.SelectVirtualKeyboard("b")); + + selector.ClearAllUserPreferences(); + EXPECT_EQ(0U, selector.user_preference().size()); +} + TEST(VirtualKeyboardSelectorTest, TestSetUserPreferenceUserSystemMixed) { static const char* ulayouts_1[] = { "a", "b", "c" }; static const char* ulayouts_2[] = { "a", "c", "d" }; @@ -433,9 +467,10 @@ TEST(VirtualKeyboardSelectorTest, TestSetUserPreferenceUserSystemMixed) { system_virtual_keyboard_2.supported_layouts(), system_virtual_keyboard_2.is_system())); - // Set and then remove user pref (=NOP). + // Set and then remove user prefs (=NOP). EXPECT_TRUE(selector.SetUserPreference("a", GURL("http://system1"))); - selector.RemoveUserPreference("a"); + EXPECT_TRUE(selector.SetUserPreference("z", GURL("http://system2"))); + selector.ClearAllUserPreferences(); // At this point, user_virtual_keyboard_2 has the highest priority. ASSERT_TRUE(selector.SelectVirtualKeyboardWithoutPreferences("a")); diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 27e399b..ef02d20 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -174,6 +174,9 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) { language_prefs::kXkbAutoRepeatIntervalInMs, PrefService::UNSYNCABLE_PREF); + prefs->RegisterDictionaryPref(prefs::kLanguagePreferredVirtualKeyboard, + PrefService::SYNCABLE_PREF); + // Screen lock default to off. prefs->RegisterBooleanPref(prefs::kEnableScreenLock, false, @@ -280,6 +283,9 @@ void Preferences::Init(PrefService* prefs) { // Initialize preferences to currently saved state. NotifyPrefChanged(NULL); + // Initialize virtual keyboard settings to currently saved state. + UpdateVirturalKeyboardPreference(prefs); + // If a guest is logged in, initialize the prefs as if this is the first // login. if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) { @@ -570,4 +576,25 @@ void Preferences::UpdateAutoRepeatRate() { input_method::SetAutoRepeatRate(rate); } +void Preferences::UpdateVirturalKeyboardPreference(PrefService* prefs) { + const DictionaryValue* virtual_keyboard_pref = + prefs->GetDictionary(prefs::kLanguagePreferredVirtualKeyboard); + DCHECK(virtual_keyboard_pref); + + input_method::InputMethodManager* input_method_manager = + input_method::InputMethodManager::GetInstance(); + input_method_manager->ClearAllVirtualKeyboardPreferences(); + + std::string url; + for (DictionaryValue::key_iterator iter = virtual_keyboard_pref->begin_keys(); + iter != virtual_keyboard_pref->end_keys(); + ++iter) { + const std::string& input_method_id = *iter; + if (!virtual_keyboard_pref->GetString(input_method_id, &url)) + continue; + input_method_manager->SetVirtualKeyboardPreference( + input_method_id, GURL(url)); + } +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index 1446aba..1da0a30 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -29,6 +29,10 @@ class Preferences : public NotificationObserver { // This method will register the prefs associated with Chrome OS settings. static void RegisterUserPrefs(PrefService* prefs); + // This method is called when kLanguagePreferredVirtualKeyboard is updated to + // change the virtual keyboard settings to reflect the new value. + static void UpdateVirturalKeyboardPreference(PrefService* prefs); + // This method will initialize Chrome OS settings to values in user prefs. void Init(PrefService* prefs); diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index fd8833d..019138f 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -480,6 +480,11 @@ const char kLanguageXkbAutoRepeatInterval[] = // "_r2" suffixes are added to the three prefs above when we change the // preferences not user-configurable, not to sync them with cloud. +// A dictionary pref which determines a preferred virtual keyboard per layout. +// e.g. { "us(dvorak)": "http://asdfg..yuiop/" } +const char kLanguagePreferredVirtualKeyboard[] = + "settings.language.preferred_virtual_keyboard"; + // 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 6b54fa8..2d11928 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -166,6 +166,7 @@ extern const char kLanguageXkbRemapAltKeyTo[]; extern const char kLanguageXkbAutoRepeatEnabled[]; extern const char kLanguageXkbAutoRepeatDelay[]; extern const char kLanguageXkbAutoRepeatInterval[]; +extern const char kLanguagePreferredVirtualKeyboard[]; extern const char kAccessibilityEnabled[]; extern const char kLabsAdvancedFilesystemEnabled[]; extern const char kLabsMediaplayerEnabled[]; |