Index: chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
diff --git a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
index 4f21a46c14982239141d146e9f52e3f3432b1dcf..72893d79014a9c43023c49b51ce49817f52110ef 100644 |
--- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
+++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
@@ -108,8 +108,60 @@ const struct MigrationHangulKeyboardToInputMethodID { |
{ "ro", "_comp_ime_bdgdidmhaijohebebipajioienkglgfohangul_romaja" }, |
}; |
+static bool ContainsTwoLetterLanguageCode( |
+ const std::vector<InputMethodManagerImpl::TwoLetterLanguageCode>& all, |
+ const std::string& lang) { |
+ if (lang.size() < 2) { |
+ return false; |
+ } |
+ return std::binary_search( |
+ all.begin(), |
+ all.end(), |
+ InputMethodManagerImpl::TwoLetterLanguageCode(lang.c_str())); |
+} |
+ |
+// A list of languages having full 26 latin letter set on keyboard. |
+// (If all input methods of a given language can be used at login screen.) |
+const char* kFullLatinKeyboardLanguageList[] = { |
Seigo Nonaka
2013/07/11 09:43:56
Please notice that there is "xkb:jp::jpn" keyboard
Alexander Alekseev
2013/07/12 20:10:49
That's a good point. I've been waiting for somethi
|
+ "ca", // Catalan |
+ "cs", // Czech |
+ "da", // Danish |
+ "de", // German |
+ "en", // English |
+ "es", // Spanish |
+ "et", // Estonian |
+ "fi", // Finnish |
+ "fr", // French |
+ "hr", // Croatian |
+ "hu", // Hungarian |
+ "is", // Icelandic |
+ "it", // Italian |
+ "lt", // Lithuanian |
+ "lv", // Latvian |
+ "nb", // Norwegian (Bokmal) |
+ "nl", // Dutch |
+ "pl", // Polish |
+ "pt", // Portuguese |
+ "ro", // Romanian |
+ "sk", // Slovak |
+ "sl", // Slovenian |
+ "sv", // Swedish |
+ "tr", // Turkish |
+}; |
+ |
} // namespace |
+// Note, that language may be longer than 2 letters. Like "en-US". |
+// but ContainsTwoLetterLanguageCode() compares only 2 first letters. |
+bool InputMethodManagerImpl::IsLanguageFullLatinKeyboard( |
+ const std::string& lang) const { |
+ return ContainsTwoLetterLanguageCode(full_latin_keyboard_languages_, lang); |
+} |
+ |
+InputMethodManagerImpl::TwoLetterLanguageCode::TwoLetterLanguageCode( |
+ const char* lang) |
+ : val(base::ToLowerASCII(lang[0]) * 256 + base::ToLowerASCII(lang[1])) {} |
+ |
InputMethodManagerImpl::InputMethodManagerImpl( |
scoped_ptr<InputMethodDelegate> delegate) |
: delegate_(delegate.Pass()), |
@@ -118,6 +170,16 @@ InputMethodManagerImpl::InputMethodManagerImpl( |
component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
weak_ptr_factory_(this) { |
IBusDaemonController::GetInstance()->AddObserver(this); |
+ |
+ full_latin_keyboard_languages_.reserve( |
+ arraysize(kFullLatinKeyboardLanguageList)); |
+ |
+ for (size_t i = 0; i < arraysize(kFullLatinKeyboardLanguageList); ++i) { |
+ full_latin_keyboard_languages_.push_back( |
+ TwoLetterLanguageCode(kFullLatinKeyboardLanguageList[i])); |
+ } |
+ std::sort(full_latin_keyboard_languages_.begin(), |
+ full_latin_keyboard_languages_.end()); |
} |
InputMethodManagerImpl::~InputMethodManagerImpl() { |
@@ -207,6 +269,11 @@ InputMethodManagerImpl::GetActiveInputMethods() const { |
return result.Pass(); |
} |
+const std::vector<std::string>& |
+InputMethodManagerImpl::GetActiveInputMethodIds() const { |
+ return active_input_method_ids_; |
+} |
+ |
size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { |
return active_input_method_ids_.size(); |
} |
@@ -250,6 +317,46 @@ void InputMethodManagerImpl::EnableLayouts(const std::string& language_code, |
ChangeInputMethod(initial_layout); // you can pass empty |initial_layout|. |
} |
+// Adds new input method to given list. |
+bool InputMethodManagerImpl::EnableInputMethodImpl( |
+ const std::string& input_method_id, |
+ std::vector<std::string>& new_active_input_method_ids) const { |
+ if (!util_.IsValidInputMethodId(input_method_id)) { |
+ DVLOG(1) << "EnableInputMethod: Invalid ID: " << input_method_id; |
+ return false; |
+ } |
+ |
+ if (!Contains(new_active_input_method_ids, input_method_id)) |
+ new_active_input_method_ids.push_back(input_method_id); |
+ |
+ return true; |
+} |
+ |
+// starts or stops the system input method framework as needed. |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
nit: Starts
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+void InputMethodManagerImpl::ReconfigureIMFramework() { |
+ if (component_extension_ime_manager_->IsInitialized()) |
+ LoadNecessaryComponentExtensions(); |
+ |
+ if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
nit: ContainOnlyKeyboardLayout should be ContainsO
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ // Do NOT call ibus_controller_->Stop(); here to work around a crash issue |
+ // at crosbug.com/27051. |
Mattias Nissler (ping if slow)
2013/07/11 10:05:49
nit: new code should refer to crbug.com IMHO
Alexander Alekseev
2013/07/12 20:10:49
Done.
|
+ // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 |
+ // is implemented. |
+ } else { |
+ MaybeInitializeCandidateWindowController(); |
+ IBusDaemonController::GetInstance()->Start(); |
+ } |
+} |
+ |
+bool InputMethodManagerImpl::EnableInputMethod( |
+ const std::string& input_method_id) { |
+ if (!EnableInputMethodImpl(input_method_id, active_input_method_ids_)) |
+ return false; |
+ |
+ ReconfigureIMFramework(); |
+ return true; |
+} |
+ |
bool InputMethodManagerImpl::EnableInputMethods( |
const std::vector<std::string>& new_active_input_method_ids) { |
if (state_ == STATE_TERMINATING) |
@@ -258,13 +365,9 @@ bool InputMethodManagerImpl::EnableInputMethods( |
// Filter unknown or obsolete IDs. |
std::vector<std::string> new_active_input_method_ids_filtered; |
- for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) { |
- const std::string& input_method_id = new_active_input_method_ids[i]; |
- if (util_.IsValidInputMethodId(input_method_id)) |
- new_active_input_method_ids_filtered.push_back(input_method_id); |
- else |
- DVLOG(1) << "EnableInputMethods: Invalid ID: " << input_method_id; |
- } |
+ for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) |
+ EnableInputMethodImpl(new_active_input_method_ids[i], |
+ new_active_input_method_ids_filtered); |
if (new_active_input_method_ids_filtered.empty()) { |
DVLOG(1) << "EnableInputMethods: No valid input method ID"; |
@@ -280,18 +383,7 @@ bool InputMethodManagerImpl::EnableInputMethods( |
} |
active_input_method_ids_.swap(new_active_input_method_ids_filtered); |
- if (component_extension_ime_manager_->IsInitialized()) |
- LoadNecessaryComponentExtensions(); |
- |
- if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { |
- // Do NOT call ibus_controller_->Stop(); here to work around a crash issue |
- // at crosbug.com/27051. |
- // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 |
- // is implemented. |
- } else { |
- MaybeInitializeCandidateWindowController(); |
- IBusDaemonController::GetInstance()->Start(); |
- } |
+ ReconfigureIMFramework(); |
// If |current_input_method| is no longer in |active_input_method_ids_|, |
// ChangeInputMethod() picks the first one in |active_input_method_ids_|. |