Commit f410d614 authored by yusukes@google.com's avatar yusukes@google.com

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
parent 357ce204
......@@ -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();
......
......@@ -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;
......
......@@ -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) {
......
......@@ -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
......
......@@ -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"));
......
......@@ -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
......@@ -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);
......
......@@ -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";
......
......@@ -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[];
......
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