| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
| 8 | 8 |
| 9 #include "ash/ime/input_method_menu_item.h" | 9 #include "ash/ime/input_method_menu_item.h" |
| 10 #include "ash/ime/input_method_menu_manager.h" | 10 #include "ash/ime/input_method_menu_manager.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chromeos/ime/input_method_delegate.h" | 29 #include "chromeos/ime/input_method_delegate.h" |
| 30 #include "third_party/icu/source/common/unicode/uloc.h" | 30 #include "third_party/icu/source/common/unicode/uloc.h" |
| 31 #include "ui/base/accelerators/accelerator.h" | 31 #include "ui/base/accelerators/accelerator.h" |
| 32 | 32 |
| 33 namespace chromeos { | 33 namespace chromeos { |
| 34 namespace input_method { | 34 namespace input_method { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 const char nacl_mozc_jp_id[] = | 38 const char nacl_mozc_jp_id[] = |
| 39 "_comp_ime_fpfbhcjppmaeaijcidgiibchfbnhbeljnacl_mozc_jp"; | 39 "_comp_ime_gjaehgfemfahhmlgpdfknkhdnemmolopnacl_mozc_jp"; |
| 40 | 40 |
| 41 bool Contains(const std::vector<std::string>& container, | 41 bool Contains(const std::vector<std::string>& container, |
| 42 const std::string& value) { | 42 const std::string& value) { |
| 43 return std::find(container.begin(), container.end(), value) != | 43 return std::find(container.begin(), container.end(), value) != |
| 44 container.end(); | 44 container.end(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 bool InputMethodManagerImpl::IsLoginKeyboard( | 49 bool InputMethodManagerImpl::IsLoginKeyboard( |
| 50 const std::string& layout) const { | 50 const std::string& layout) const { |
| 51 return util_.IsLoginKeyboard(layout); | 51 return util_.IsLoginKeyboard(layout); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool InputMethodManagerImpl::MigrateXkbInputMethods( | 54 bool InputMethodManagerImpl::MigrateInputMethods( |
| 55 std::vector<std::string>* input_method_ids) { | 55 std::vector<std::string>* input_method_ids) { |
| 56 return util_.MigrateXkbInputMethods(input_method_ids); | 56 return util_.MigrateInputMethods(input_method_ids); |
| 57 } | 57 } |
| 58 | 58 |
| 59 InputMethodManagerImpl::InputMethodManagerImpl( | 59 InputMethodManagerImpl::InputMethodManagerImpl( |
| 60 scoped_ptr<InputMethodDelegate> delegate) | 60 scoped_ptr<InputMethodDelegate> delegate) |
| 61 : delegate_(delegate.Pass()), | 61 : delegate_(delegate.Pass()), |
| 62 state_(STATE_LOGIN_SCREEN), | 62 state_(STATE_LOGIN_SCREEN), |
| 63 util_(delegate_.get(), whitelist_.GetSupportedInputMethods()), | 63 util_(delegate_.get(), whitelist_.GetSupportedInputMethods()), |
| 64 component_extension_ime_manager_(new ComponentExtensionIMEManager()), | 64 component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
| 65 weak_ptr_factory_(this) { | 65 weak_ptr_factory_(this) { |
| 66 } | 66 } |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 // Add candidates to layouts, while skipping duplicates. | 212 // Add candidates to layouts, while skipping duplicates. |
| 213 for (size_t i = 0; i < candidates.size(); ++i) { | 213 for (size_t i = 0; i < candidates.size(); ++i) { |
| 214 const std::string& candidate = candidates[i]; | 214 const std::string& candidate = candidates[i]; |
| 215 // Not efficient, but should be fine, as the two vectors are very | 215 // Not efficient, but should be fine, as the two vectors are very |
| 216 // short (2-5 items). | 216 // short (2-5 items). |
| 217 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) | 217 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) |
| 218 layouts.push_back(candidate); | 218 layouts.push_back(candidate); |
| 219 } | 219 } |
| 220 | 220 |
| 221 MigrateXkbInputMethods(&layouts); | 221 MigrateInputMethods(&layouts); |
| 222 active_input_method_ids_.swap(layouts); | 222 active_input_method_ids_.swap(layouts); |
| 223 | 223 |
| 224 // Initialize candidate window controller and widgets such as | 224 // Initialize candidate window controller and widgets such as |
| 225 // candidate window, infolist and mode indicator. Note, mode | 225 // candidate window, infolist and mode indicator. Note, mode |
| 226 // indicator is used by only keyboard layout input methods. | 226 // indicator is used by only keyboard layout input methods. |
| 227 if (active_input_method_ids_.size() > 1) | 227 if (active_input_method_ids_.size() > 1) |
| 228 MaybeInitializeCandidateWindowController(); | 228 MaybeInitializeCandidateWindowController(); |
| 229 | 229 |
| 230 // you can pass empty |initial_layout|. | 230 // you can pass empty |initial_layout|. |
| 231 ChangeInputMethod(initial_layouts.empty() ? "" : | 231 ChangeInputMethod(initial_layouts.empty() ? "" : |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to | 288 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to |
| 289 // keep relative order of the extension input method IDs. | 289 // keep relative order of the extension input method IDs. |
| 290 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { | 290 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
| 291 const std::string& input_method_id = active_input_method_ids_[i]; | 291 const std::string& input_method_id = active_input_method_ids_[i]; |
| 292 if (extension_ime_util::IsExtensionIME(input_method_id)) | 292 if (extension_ime_util::IsExtensionIME(input_method_id)) |
| 293 new_active_input_method_ids_filtered.push_back(input_method_id); | 293 new_active_input_method_ids_filtered.push_back(input_method_id); |
| 294 } | 294 } |
| 295 active_input_method_ids_.swap(new_active_input_method_ids_filtered); | 295 active_input_method_ids_.swap(new_active_input_method_ids_filtered); |
| 296 MigrateXkbInputMethods(&active_input_method_ids_); | 296 MigrateInputMethods(&active_input_method_ids_); |
| 297 | 297 |
| 298 ReconfigureIMFramework(); | 298 ReconfigureIMFramework(); |
| 299 | 299 |
| 300 // If |current_input_method| is no longer in |active_input_method_ids_|, | 300 // If |current_input_method| is no longer in |active_input_method_ids_|, |
| 301 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. | 301 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. |
| 302 ChangeInputMethod(current_input_method_.id()); | 302 ChangeInputMethod(current_input_method_.id()); |
| 303 return true; | 303 return true; |
| 304 } | 304 } |
| 305 | 305 |
| 306 void InputMethodManagerImpl::ChangeInputMethod( | 306 void InputMethodManagerImpl::ChangeInputMethod( |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 break; | 667 break; |
| 668 default: | 668 default: |
| 669 NOTREACHED(); | 669 NOTREACHED(); |
| 670 break; | 670 break; |
| 671 } | 671 } |
| 672 if (input_method_ids_to_switch.empty()) { | 672 if (input_method_ids_to_switch.empty()) { |
| 673 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); | 673 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); |
| 674 return false; | 674 return false; |
| 675 } | 675 } |
| 676 | 676 |
| 677 MigrateXkbInputMethods(&input_method_ids_to_switch); | 677 MigrateInputMethods(&input_method_ids_to_switch); |
| 678 | 678 |
| 679 // Obtain the intersection of input_method_ids_to_switch and | 679 // Obtain the intersection of input_method_ids_to_switch and |
| 680 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is | 680 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is |
| 681 // preserved. | 681 // preserved. |
| 682 std::vector<std::string> ids; | 682 std::vector<std::string> ids; |
| 683 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { | 683 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { |
| 684 const std::string& id = input_method_ids_to_switch[i]; | 684 const std::string& id = input_method_ids_to_switch[i]; |
| 685 if (Contains(active_input_method_ids_, id)) | 685 if (Contains(active_input_method_ids_, id)) |
| 686 ids.push_back(id); | 686 ids.push_back(id); |
| 687 } | 687 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 CandidateWindowController::CreateCandidateWindowController()); | 854 CandidateWindowController::CreateCandidateWindowController()); |
| 855 candidate_window_controller_->AddObserver(this); | 855 candidate_window_controller_->AddObserver(this); |
| 856 } | 856 } |
| 857 | 857 |
| 858 Profile* InputMethodManagerImpl::GetProfile() const { | 858 Profile* InputMethodManagerImpl::GetProfile() const { |
| 859 return ProfileManager::GetActiveUserProfile(); | 859 return ProfileManager::GetActiveUserProfile(); |
| 860 } | 860 } |
| 861 | 861 |
| 862 } // namespace input_method | 862 } // namespace input_method |
| 863 } // namespace chromeos | 863 } // namespace chromeos |
| OLD | NEW |