Chromium Code Reviews| 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 b89db86fbb9bd2782507aaddfeb76bb2da07a0db..54174be7f686965927e668fd69a04fd274b5eec7 100644 |
| --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.cc |
| @@ -6,6 +6,8 @@ |
| #include <algorithm> // std::find |
| +#include <sstream> |
| + |
| #include "ash/ime/input_method_menu_item.h" |
| #include "ash/ime/input_method_menu_manager.h" |
| #include "base/basictypes.h" |
| @@ -56,13 +58,92 @@ bool InputMethodManagerImpl::MigrateInputMethods( |
| return util_.MigrateInputMethods(input_method_ids); |
| } |
| +InputMethodManagerImpl::State::State() { |
| +} |
| + |
| +InputMethodManagerImpl::State::~State() { |
| +} |
| + |
| +void InputMethodManagerImpl::State::InitFrom(const State& other) { |
| + // debug_name is not copied. |
| + |
| + previous_input_method_ = other.previous_input_method_; |
| + current_input_method_ = other.current_input_method_; |
| + |
| + active_input_method_ids_ = other.active_input_method_ids_; |
| + |
| + saved_previous_input_method_ = other.saved_previous_input_method_; |
| + saved_current_input_method_ = other.saved_current_input_method_; |
| + saved_active_input_method_ids_ = other.saved_active_input_method_ids_; |
| + |
| + pending_input_method_ = other.pending_input_method_; |
| + |
| + // TODO: recreate all input engines? |
| + // typedef std::map<std::string, InputMethodEngineInterface*> EngineMap; |
| + engine_map_ = other.engine_map_; |
| +} |
| + |
| +std::string InputMethodManagerImpl::State::Dump() const { |
| + std::ostringstream os; |
| + |
| + os << "################# " << state_name << " #################\n"; |
| + |
| + os << "previous_input_method_: '" |
| + << previous_input_method_.GetPreferredKeyboardLayout() << "'\n"; |
| + os << "current_input_method_: '" |
| + << current_input_method_.GetPreferredKeyboardLayout() << "'\n"; |
| + os << "active_input_method_ids_ (size=" << active_input_method_ids_.size() |
| + << "):"; |
| + for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
| + os << " '" << active_input_method_ids_[i] << "',"; |
| + } |
| + os << "\n"; |
| + os << "saved_previous_input_method_: '" |
| + << saved_previous_input_method_.GetPreferredKeyboardLayout() << "'\n"; |
| + os << "saved_current_input_method_: '" |
| + << saved_current_input_method_.GetPreferredKeyboardLayout() << "'\n"; |
| + os << "saved_active_input_method_ids_ (size=" |
| + << saved_active_input_method_ids_.size() << "):"; |
| + for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| + os << " '" << saved_active_input_method_ids_[i] << "'\n"; |
| + } |
| + os << "pending_input_method_: '" << pending_input_method_ << "'\n"; |
| + os << "engine_map_ (size=" << engine_map_.size() << "): ...\n "; |
| + |
| + return os.str(); |
| +} |
| + |
| +scoped_refptr<InputMethodManager::State> InputMethodManagerImpl::CreateNewState( |
| + const std::string& debug_name) const { |
| + scoped_refptr<InputMethodManagerImpl::State> new_state( |
| + new InputMethodManagerImpl::State); |
| + new_state->state_name = debug_name; |
| + |
| + return scoped_refptr<InputMethodManager::State>(new_state.get()); |
| +} |
| + |
| +void InputMethodManagerImpl::SetState( |
|
Shu Chen
2014/08/04 14:55:23
I guess this is for fast user switching, correct?
Alexander Alekseev
2014/08/06 23:39:45
Yes, this was one of my concerns, when I've upload
Shu Chen
2014/08/07 15:40:19
I think enabled_extension_imes_ should not be shar
Alexander Alekseev
2014/08/07 17:26:19
But it is still shared. (I don't understand why.)
|
| + scoped_refptr<InputMethodManager::State> state) { |
| + LOG(ERROR) << "InputMethodManagerImpl::SetState(): Called."; |
| + LOG(ERROR) << "InputMethodManagerImpl::SetState(): old state_: " |
| + << (state_ ? state_->Dump() : std::string("NULL")); |
| + state_ = static_cast<InputMethodManagerImpl::State*>(state.get()); |
| + LOG(ERROR) << "InputMethodManagerImpl::SetState(): new state_: " |
| + << (state_ ? state_->Dump() : std::string("NULL")); |
| + if (state_->active_input_method_ids_.size()) { |
| + ReconfigureIMFramework(); |
| + ChangeInputMethodInternal(state_->current_input_method_, false); |
|
Shu Chen
2014/08/04 14:55:23
Is there particular reason of calling ChangeInputM
Alexander Alekseev
2014/08/06 23:39:45
The idea is that SetState should be lightweight, b
Shu Chen
2014/08/07 15:40:19
I think ReconfigureIMEFramework() is not heavy, be
Alexander Alekseev
2014/08/07 17:26:18
Extensions are not unloaded. From the extensions p
|
| + } |
| +} |
| + |
| InputMethodManagerImpl::InputMethodManagerImpl( |
| scoped_ptr<InputMethodDelegate> delegate) |
| : delegate_(delegate.Pass()), |
| - state_(STATE_LOGIN_SCREEN), |
| + ui_state_(STATE_LOGIN_SCREEN), |
| util_(delegate_.get(), whitelist_.GetSupportedInputMethods()), |
| component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
| weak_ptr_factory_(this) { |
| + SetState(CreateNewState("default")); |
| } |
| InputMethodManagerImpl::~InputMethodManagerImpl() { |
| @@ -90,14 +171,14 @@ void InputMethodManagerImpl::RemoveCandidateWindowObserver( |
| candidate_window_observers_.RemoveObserver(observer); |
| } |
| -void InputMethodManagerImpl::SetState(State new_state) { |
| - const State old_state = state_; |
| - state_ = new_state; |
| - switch (state_) { |
| +void InputMethodManagerImpl::SetUIState(UIState new_ui_state) { |
| + const UIState old_ui_state = ui_state_; |
| + ui_state_ = new_ui_state; |
| + switch (ui_state_) { |
| case STATE_LOGIN_SCREEN: |
| break; |
| case STATE_BROWSER_SCREEN: |
| - if (old_state == STATE_LOCK_SCREEN) |
| + if (old_ui_state == STATE_LOCK_SCREEN) |
| OnScreenUnlocked(); |
| break; |
| case STATE_LOCK_SCREEN: |
| @@ -123,8 +204,9 @@ InputMethodManagerImpl::GetActiveInputMethods() const { |
| scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); |
| // Build the active input method descriptors from the active input |
| // methods cache |active_input_method_ids_|. |
| - for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
| - const std::string& input_method_id = active_input_method_ids_[i]; |
| + DCHECK(state_); |
| + for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) { |
| + const std::string& input_method_id = state_->active_input_method_ids_[i]; |
| const InputMethodDescriptor* descriptor = |
| util_.GetInputMethodDescriptorFromId(input_method_id); |
| if (descriptor) { |
| @@ -149,11 +231,13 @@ InputMethodManagerImpl::GetActiveInputMethods() const { |
| const std::vector<std::string>& |
| InputMethodManagerImpl::GetActiveInputMethodIds() const { |
| - return active_input_method_ids_; |
| + DCHECK(state_); |
| + return state_->active_input_method_ids_; |
| } |
| size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { |
| - return active_input_method_ids_.size(); |
| + DCHECK(state_); |
| + return state_->active_input_method_ids_.size(); |
| } |
| const InputMethodDescriptor* InputMethodManagerImpl::GetInputMethodFromId( |
| @@ -172,8 +256,10 @@ const InputMethodDescriptor* InputMethodManagerImpl::GetInputMethodFromId( |
| void InputMethodManagerImpl::EnableLoginLayouts( |
| const std::string& language_code, |
| const std::vector<std::string>& initial_layouts) { |
| - if (state_ == STATE_TERMINATING) |
| + if (ui_state_ == STATE_TERMINATING) |
| return; |
| + LOG(ERROR) << "InputMethodManagerImpl::EnableLoginLayouts(): old state_: " |
| + << state_->Dump(); |
| // First, hardware keyboard layout should be shown. |
| std::vector<std::string> candidates = |
| @@ -217,12 +303,15 @@ void InputMethodManagerImpl::EnableLoginLayouts( |
| } |
| MigrateInputMethods(&layouts); |
| - active_input_method_ids_.swap(layouts); |
| + DCHECK(state_); |
| + state_->active_input_method_ids_.swap(layouts); |
| + LOG(ERROR) << "InputMethodManagerImpl::EnableLoginLayouts(): new state_: " |
| + << state_->Dump(); |
| // Initialize candidate window controller and widgets such as |
| // candidate window, infolist and mode indicator. Note, mode |
| // indicator is used by only keyboard layout input methods. |
| - if (active_input_method_ids_.size() > 1) |
| + if (state_->active_input_method_ids_.size() > 1) |
| MaybeInitializeCandidateWindowController(); |
| // you can pass empty |initial_layout|. |
| @@ -258,7 +347,9 @@ void InputMethodManagerImpl::ReconfigureIMFramework() { |
| bool InputMethodManagerImpl::EnableInputMethod( |
| const std::string& input_method_id) { |
| - if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_)) |
| + DCHECK(state_); |
| + if (!EnableInputMethodImpl(input_method_id, |
| + &(state_->active_input_method_ids_))) |
| return false; |
| ReconfigureIMFramework(); |
| @@ -267,8 +358,11 @@ bool InputMethodManagerImpl::EnableInputMethod( |
| bool InputMethodManagerImpl::ReplaceEnabledInputMethods( |
| const std::vector<std::string>& new_active_input_method_ids) { |
| - if (state_ == STATE_TERMINATING) |
| + if (ui_state_ == STATE_TERMINATING) |
| return false; |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::ReplaceEnabledInputMethods(): old state_: " |
| + << state_->Dump(); |
| // Filter unknown or obsolete IDs. |
| std::vector<std::string> new_active_input_method_ids_filtered; |
| @@ -284,31 +378,51 @@ bool InputMethodManagerImpl::ReplaceEnabledInputMethods( |
| // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to |
| // keep relative order of the extension input method IDs. |
| - for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
| - const std::string& input_method_id = active_input_method_ids_[i]; |
| + DCHECK(state_); |
| + for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) { |
| + const std::string& input_method_id = state_->active_input_method_ids_[i]; |
| if (extension_ime_util::IsExtensionIME(input_method_id)) |
| new_active_input_method_ids_filtered.push_back(input_method_id); |
| } |
| - active_input_method_ids_.swap(new_active_input_method_ids_filtered); |
| - MigrateInputMethods(&active_input_method_ids_); |
| + state_->active_input_method_ids_.swap(new_active_input_method_ids_filtered); |
| + MigrateInputMethods(&(state_->active_input_method_ids_)); |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::ReplaceEnabledInputMethods(): new state_: " |
| + << state_->Dump(); |
| ReconfigureIMFramework(); |
| // If |current_input_method| is no longer in |active_input_method_ids_|, |
| // ChangeInputMethod() picks the first one in |active_input_method_ids_|. |
| - ChangeInputMethod(current_input_method_.id()); |
| + ChangeInputMethod(state_->current_input_method_.id()); |
| return true; |
| } |
| void InputMethodManagerImpl::ChangeInputMethod( |
| const std::string& input_method_id) { |
| - ChangeInputMethodInternal(input_method_id, false); |
| + LookupAndChangeInputMethodInternal(input_method_id, false); |
| } |
| -bool InputMethodManagerImpl::ChangeInputMethodInternal( |
| +void InputMethodManagerImpl::ChangeInputMethodInternal( |
| + const InputMethodDescriptor& descriptor, |
| + bool show_message) { |
| + // Change the keyboard layout to a preferred layout for the input method. |
| + if (!keyboard_->SetCurrentKeyboardLayoutByName( |
| + descriptor.GetPreferredKeyboardLayout())) { |
| + LOG(ERROR) << "Failed to change keyboard layout to " |
| + << descriptor.GetPreferredKeyboardLayout(); |
| + } |
| + |
| + // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
| + FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| + observers_, |
| + InputMethodChanged(this, show_message)); |
| +} |
| + |
| +bool InputMethodManagerImpl::LookupAndChangeInputMethodInternal( |
|
Shu Chen
2014/08/04 14:55:23
looks like the bool return value never gets used.
Alexander Alekseev
2014/08/06 23:39:45
Done.
|
| const std::string& input_method_id, |
| bool show_message) { |
| - if (state_ == STATE_TERMINATING) |
| + if (ui_state_ == STATE_TERMINATING) |
| return false; |
| std::string input_method_id_to_switch = input_method_id; |
| @@ -331,10 +445,10 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
| // component extension ime manager. ChangeInputMethod will be |
| // called with |pending_input_method_| when the initialization is |
| // done. |
| - pending_input_method_ = input_method_id_to_switch; |
| + state_->pending_input_method_ = input_method_id_to_switch; |
| return false; |
| } |
| - pending_input_method_.clear(); |
| + state_->pending_input_method_.clear(); |
| // Hide candidate window and info list. |
| if (candidate_window_controller_.get()) |
| @@ -353,7 +467,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
| IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
| } else { |
| IMEEngineHandlerInterface* next_engine = |
| - profile_engine_map_[GetProfile()][input_method_id_to_switch]; |
| + state_->engine_map_[input_method_id_to_switch]; |
| if (next_engine) { |
| IMEBridge::Get()->SetCurrentEngineHandler(next_engine); |
| next_engine->Enable(); |
| @@ -362,7 +476,7 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
| // TODO(komatsu): Check if it is necessary to perform the above routine |
| // when the current input method is equal to |input_method_id_to_swich|. |
| - if (current_input_method_.id() != input_method_id_to_switch) { |
| + if (state_->current_input_method_.id() != input_method_id_to_switch) { |
| // Clear property list. Property list would be updated by |
| // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. |
| // If the current input method is a keyboard layout, empty |
| @@ -386,21 +500,11 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
| } |
| DCHECK(descriptor); |
| - previous_input_method_ = current_input_method_; |
| - current_input_method_ = *descriptor; |
| - } |
| - |
| - // Change the keyboard layout to a preferred layout for the input method. |
| - if (!keyboard_->SetCurrentKeyboardLayoutByName( |
| - current_input_method_.GetPreferredKeyboardLayout())) { |
| - LOG(ERROR) << "Failed to change keyboard layout to " |
| - << current_input_method_.GetPreferredKeyboardLayout(); |
| + state_->previous_input_method_ = state_->current_input_method_; |
| + state_->current_input_method_ = *descriptor; |
| } |
| - // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
| - FOR_EACH_OBSERVER(InputMethodManager::Observer, |
| - observers_, |
| - InputMethodChanged(this, show_message)); |
| + ChangeInputMethodInternal(state_->current_input_method_, show_message); |
| return true; |
| } |
| @@ -432,31 +536,39 @@ void InputMethodManagerImpl::OnComponentExtensionInitialized( |
| LoadNecessaryComponentExtensions(); |
| - if (!pending_input_method_.empty()) |
| - ChangeInputMethodInternal(pending_input_method_, false); |
| + DCHECK(state_); |
| + if (!state_->pending_input_method_.empty()) |
| + LookupAndChangeInputMethodInternal(state_->pending_input_method_, false); |
| } |
| void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { |
| if (!component_extension_ime_manager_->IsInitialized()) |
| return; |
| + LOG(ERROR) << "InputMethodManagerImpl::LoadNecessaryComponentExtensions(): " |
| + "old state_: " << state_->Dump(); |
| // Load component extensions but also update |active_input_method_ids_| as |
| // some component extension IMEs may have been removed from the Chrome OS |
| // image. If specified component extension IME no longer exists, falling back |
| // to an existing IME. |
| + DCHECK(state_); |
| std::vector<std::string> unfiltered_input_method_ids; |
| - unfiltered_input_method_ids.swap(active_input_method_ids_); |
| + unfiltered_input_method_ids.swap(state_->active_input_method_ids_); |
| for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { |
| if (!extension_ime_util::IsComponentExtensionIME( |
| unfiltered_input_method_ids[i])) { |
| // Legacy IMEs or xkb layouts are alwayes active. |
| - active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
| + state_->active_input_method_ids_.push_back( |
| + unfiltered_input_method_ids[i]); |
| } else if (component_extension_ime_manager_->IsWhitelisted( |
| unfiltered_input_method_ids[i])) { |
| component_extension_ime_manager_->LoadComponentExtensionIME( |
| unfiltered_input_method_ids[i]); |
| - active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); |
| + state_->active_input_method_ids_.push_back( |
| + unfiltered_input_method_ids[i]); |
| } |
| } |
| + LOG(ERROR) << "InputMethodManagerImpl::LoadNecessaryComponentExtensions(): " |
| + "new state_: " << state_->Dump(); |
| // TODO(shuchen): move this call in ComponentExtensionIMEManager. |
| component_extension_ime_manager_->NotifyInitialized(); |
| } |
| @@ -480,14 +592,18 @@ void InputMethodManagerImpl::ActivateInputMethodMenuItem( |
| void InputMethodManagerImpl::AddInputMethodExtension( |
| const std::string& id, |
| InputMethodEngineInterface* engine) { |
| - if (state_ == STATE_TERMINATING) |
| + if (ui_state_ == STATE_TERMINATING) |
| return; |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::AddInputMethodExtension(): old state_: " |
| + << state_->Dump(); |
| DCHECK(engine); |
| + DCHECK(state_); |
| - profile_engine_map_[GetProfile()][id] = engine; |
| + state_->engine_map_[id] = engine; |
|
Shu Chen
2014/08/04 14:55:23
I think this will break something. GetProfile() is
Alexander Alekseev
2014/08/06 23:39:45
state_ is per-user, so this would never happen.
I
|
| - if (id == current_input_method_.id()) { |
| + if (id == state_->current_input_method_.id()) { |
| IMEBridge::Get()->SetCurrentEngineHandler(engine); |
| engine->Enable(); |
| } |
| @@ -502,8 +618,11 @@ void InputMethodManagerImpl::AddInputMethodExtension( |
| extra_input_methods_[id] = descriptor; |
| if (Contains(enabled_extension_imes_, id)) { |
| - if (!Contains(active_input_method_ids_, id)) { |
| - active_input_method_ids_.push_back(id); |
| + if (!Contains(state_->active_input_method_ids_, id)) { |
| + state_->active_input_method_ids_.push_back(id); |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::AddInputMethodExtension(): new state_: " |
| + << state_->Dump(); |
| } else { |
| DVLOG(1) << "AddInputMethodExtension: alread added: " |
| << id << ", " << descriptor.name(); |
| @@ -517,23 +636,29 @@ void InputMethodManagerImpl::AddInputMethodExtension( |
| void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { |
| if (!extension_ime_util::IsExtensionIME(id)) |
| DVLOG(1) << id << " is not a valid extension input method ID."; |
| - |
| - std::vector<std::string>::iterator i = std::find( |
| - active_input_method_ids_.begin(), active_input_method_ids_.end(), id); |
| - if (i != active_input_method_ids_.end()) |
| - active_input_method_ids_.erase(i); |
| + LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('" << id |
| + << "'): old state_: " << state_->Dump(); |
| + |
| + DCHECK(state_); |
| + std::vector<std::string>::iterator i = |
| + std::find(state_->active_input_method_ids_.begin(), |
| + state_->active_input_method_ids_.end(), |
| + id); |
| + if (i != state_->active_input_method_ids_.end()) |
| + state_->active_input_method_ids_.erase(i); |
| extra_input_methods_.erase(id); |
| - EngineMap& engine_map = profile_engine_map_[GetProfile()]; |
| - if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map[id]) |
| + if (IMEBridge::Get()->GetCurrentEngineHandler() == state_->engine_map_[id]) |
| IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
| - engine_map.erase(id); |
| + state_->engine_map_.erase(id); |
| + LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('" << id |
| + << "'): new state_: " << state_->Dump(); |
| // No need to switch input method when terminating. |
| - if (state_ != STATE_TERMINATING) { |
| + if (ui_state_ != STATE_TERMINATING) { |
| // If |current_input_method| is no longer in |active_input_method_ids_|, |
| // switch to the first one in |active_input_method_ids_|. |
| - ChangeInputMethod(current_input_method_.id()); |
| + ChangeInputMethod(state_->current_input_method_.id()); |
| } |
| } |
| @@ -555,6 +680,9 @@ void InputMethodManagerImpl::SetEnabledExtensionImes( |
| enabled_extension_imes_.insert(enabled_extension_imes_.end(), |
| ids->begin(), |
| ids->end()); |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::SetEnabledExtensionImes(): old state_: " |
| + << state_->Dump(); |
| bool active_imes_changed = false; |
| @@ -564,29 +692,34 @@ void InputMethodManagerImpl::SetEnabledExtensionImes( |
| if (extension_ime_util::IsComponentExtensionIME( |
| extra_iter->first)) |
| continue; // Do not filter component extension. |
| - std::vector<std::string>::iterator active_iter = std::find( |
| - active_input_method_ids_.begin(), active_input_method_ids_.end(), |
| - extra_iter->first); |
| + DCHECK(state_); |
| + std::vector<std::string>::iterator active_iter = |
| + std::find(state_->active_input_method_ids_.begin(), |
| + state_->active_input_method_ids_.end(), |
| + extra_iter->first); |
| - bool active = active_iter != active_input_method_ids_.end(); |
| + bool active = active_iter != state_->active_input_method_ids_.end(); |
| bool enabled = Contains(enabled_extension_imes_, extra_iter->first); |
| if (active && !enabled) |
| - active_input_method_ids_.erase(active_iter); |
| + state_->active_input_method_ids_.erase(active_iter); |
| if (!active && enabled) |
| - active_input_method_ids_.push_back(extra_iter->first); |
| + state_->active_input_method_ids_.push_back(extra_iter->first); |
| if (active == !enabled) |
| active_imes_changed = true; |
| } |
| + LOG(ERROR) |
| + << "InputMethodManagerImpl::SetEnabledExtensionImes(): new state_: " |
| + << state_->Dump(); |
| if (active_imes_changed) { |
| MaybeInitializeCandidateWindowController(); |
| // If |current_input_method| is no longer in |active_input_method_ids_|, |
| // switch to the first one in |active_input_method_ids_|. |
| - ChangeInputMethod(current_input_method_.id()); |
| + ChangeInputMethod(state_->current_input_method_.id()); |
| } |
| } |
| @@ -653,65 +786,69 @@ void InputMethodManagerImpl::SetInputMethodLoginDefault() { |
| } |
| bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
| + DCHECK(state_); |
| // Sanity checks. |
| - if (active_input_method_ids_.empty()) { |
| + if (state_->active_input_method_ids_.empty()) { |
| DVLOG(1) << "active input method is empty"; |
| return false; |
| } |
| - if (current_input_method_.id().empty()) { |
| + if (state_->current_input_method_.id().empty()) { |
| DVLOG(1) << "current_input_method_ is unknown"; |
| return false; |
| } |
| // Do not consume key event if there is only one input method is enabled. |
| // Ctrl+Space or Alt+Shift may be used by other application. |
| - if (active_input_method_ids_.size() == 1) |
| + if (state_->active_input_method_ids_.size() == 1) |
| return false; |
| // Find the next input method and switch to it. |
| - SwitchToNextInputMethodInternal(active_input_method_ids_, |
| - current_input_method_.id()); |
| + SwitchToNextInputMethodInternal(state_->active_input_method_ids_, |
| + state_->current_input_method_.id()); |
| return true; |
| } |
| bool InputMethodManagerImpl::SwitchToPreviousInputMethod( |
| const ui::Accelerator& accelerator) { |
| + DCHECK(state_); |
| // Sanity check. |
| - if (active_input_method_ids_.empty()) { |
| + if (state_->active_input_method_ids_.empty()) { |
| DVLOG(1) << "active input method is empty"; |
| return false; |
| } |
| // Do not consume key event if there is only one input method is enabled. |
| // Ctrl+Space or Alt+Shift may be used by other application. |
| - if (active_input_method_ids_.size() == 1) |
| + if (state_->active_input_method_ids_.size() == 1) |
| return false; |
| if (accelerator.type() == ui::ET_KEY_RELEASED) |
| return true; |
| - if (previous_input_method_.id().empty() || |
| - previous_input_method_.id() == current_input_method_.id()) { |
| + if (state_->previous_input_method_.id().empty() || |
| + state_->previous_input_method_.id() == |
| + state_->current_input_method_.id()) { |
| return SwitchToNextInputMethod(); |
| } |
| std::vector<std::string>::const_iterator iter = |
| - std::find(active_input_method_ids_.begin(), |
| - active_input_method_ids_.end(), |
| - previous_input_method_.id()); |
| - if (iter == active_input_method_ids_.end()) { |
| + std::find(state_->active_input_method_ids_.begin(), |
| + state_->active_input_method_ids_.end(), |
| + state_->previous_input_method_.id()); |
| + if (iter == state_->active_input_method_ids_.end()) { |
| // previous_input_method_ is not supported. |
| return SwitchToNextInputMethod(); |
| } |
| - ChangeInputMethodInternal(*iter, true); |
| + LookupAndChangeInputMethodInternal(*iter, true); |
| return true; |
| } |
| bool InputMethodManagerImpl::SwitchInputMethod( |
| const ui::Accelerator& accelerator) { |
| + DCHECK(state_); |
| // Sanity check. |
| - if (active_input_method_ids_.empty()) { |
| + if (state_->active_input_method_ids_.empty()) { |
| DVLOG(1) << "active input method is empty"; |
| return false; |
| } |
| @@ -750,7 +887,7 @@ bool InputMethodManagerImpl::SwitchInputMethod( |
| std::vector<std::string> ids; |
| for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { |
| const std::string& id = input_method_ids_to_switch[i]; |
| - if (Contains(active_input_method_ids_, id)) |
| + if (Contains(state_->active_input_method_ids_, id)) |
| ids.push_back(id); |
| } |
| if (ids.empty()) { |
| @@ -759,7 +896,7 @@ bool InputMethodManagerImpl::SwitchInputMethod( |
| return false; |
| } |
| - SwitchToNextInputMethodInternal(ids, current_input_method_.id()); |
| + SwitchToNextInputMethodInternal(ids, state_->current_input_method_.id()); |
| return true; // consume the accelerator. |
| } |
| @@ -774,14 +911,15 @@ void InputMethodManagerImpl::SwitchToNextInputMethodInternal( |
| ++iter; |
| if (iter == input_method_ids.end()) |
| iter = input_method_ids.begin(); |
| - ChangeInputMethodInternal(*iter, true); |
| + LookupAndChangeInputMethodInternal(*iter, true); |
| } |
| InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { |
| - if (current_input_method_.id().empty()) |
| + DCHECK(state_); |
| + if (state_->current_input_method_.id().empty()) |
| return InputMethodUtil::GetFallbackInputMethodDescriptor(); |
| - return current_input_method_; |
| + return state_->current_input_method_; |
| } |
| bool InputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() const { |
| @@ -867,24 +1005,28 @@ void InputMethodManagerImpl::CandidateWindowClosed() { |
| } |
| void InputMethodManagerImpl::OnScreenLocked() { |
| - saved_previous_input_method_ = previous_input_method_; |
| - saved_current_input_method_ = current_input_method_; |
| - saved_active_input_method_ids_ = active_input_method_ids_; |
| + DCHECK(state_); |
| + LOG(ERROR) << "InputMethodManagerImpl::OnScreenLocked(): old state_: " |
| + << state_->Dump(); |
| + state_->saved_previous_input_method_ = state_->previous_input_method_; |
| + state_->saved_current_input_method_ = state_->current_input_method_; |
| + state_->saved_active_input_method_ids_ = state_->active_input_method_ids_; |
| std::set<std::string> added_ids_; |
| const std::vector<std::string>& hardware_keyboard_ids = |
| util_.GetHardwareLoginInputMethodIds(); |
| - active_input_method_ids_.clear(); |
| - for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { |
| - const std::string& input_method_id = saved_active_input_method_ids_[i]; |
| + state_->active_input_method_ids_.clear(); |
| + for (size_t i = 0; i < state_->saved_active_input_method_ids_.size(); ++i) { |
| + const std::string& input_method_id = |
| + state_->saved_active_input_method_ids_[i]; |
| // Skip if it's not a keyboard layout. Drop input methods including |
| // extension ones. |
| if (!IsLoginKeyboard(input_method_id) || |
| added_ids_.find(input_method_id) != added_ids_.end()) |
| continue; |
| - active_input_method_ids_.push_back(input_method_id); |
| + state_->active_input_method_ids_.push_back(input_method_id); |
| added_ids_.insert(input_method_id); |
| } |
| @@ -893,25 +1035,32 @@ void InputMethodManagerImpl::OnScreenLocked() { |
| // keyboard on the screen locker. |
| for (size_t i = 0; i < hardware_keyboard_ids.size(); ++i) { |
| if (added_ids_.find(hardware_keyboard_ids[i]) == added_ids_.end()) { |
| - active_input_method_ids_.push_back(hardware_keyboard_ids[i]); |
| + state_->active_input_method_ids_.push_back(hardware_keyboard_ids[i]); |
| added_ids_.insert(hardware_keyboard_ids[i]); |
| } |
| } |
| - ChangeInputMethod(current_input_method_.id()); |
| + LOG(ERROR) << "InputMethodManagerImpl::OnScreenLocked(): new state_: " |
| + << state_->Dump(); |
| + ChangeInputMethod(state_->current_input_method_.id()); |
| } |
| void InputMethodManagerImpl::OnScreenUnlocked() { |
| - previous_input_method_ = saved_previous_input_method_; |
| - current_input_method_ = saved_current_input_method_; |
| - active_input_method_ids_ = saved_active_input_method_ids_; |
| - |
| - ChangeInputMethod(current_input_method_.id()); |
| + LOG(ERROR) << "InputMethodManagerImpl::OnScreenUnLocked(): old state_: " |
| + << state_->Dump(); |
| + state_->previous_input_method_ = state_->saved_previous_input_method_; |
| + state_->current_input_method_ = state_->saved_current_input_method_; |
| + state_->active_input_method_ids_ = state_->saved_active_input_method_ids_; |
| + |
| + LOG(ERROR) << "InputMethodManagerImpl::OnScreenUnLocked(): new state_: " |
| + << state_->Dump(); |
| + ChangeInputMethod(state_->current_input_method_.id()); |
| } |
| bool InputMethodManagerImpl::InputMethodIsActivated( |
| const std::string& input_method_id) { |
| - return Contains(active_input_method_ids_, input_method_id); |
| + DCHECK(state_); |
| + return Contains(state_->active_input_method_ids_, input_method_id); |
| } |
| void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { |
| @@ -923,9 +1072,5 @@ void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { |
| candidate_window_controller_->AddObserver(this); |
| } |
| -Profile* InputMethodManagerImpl::GetProfile() const { |
| - return ProfileManager::GetActiveUserProfile(); |
| -} |
| - |
| } // namespace input_method |
| } // namespace chromeos |