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 072a3b2b8dac7e0f5986b41a6fab648adda4cd35..98fb9c6bb7f0cca62b9d6f404079de10f10f1ef7 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,90 @@ 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_; |
+ |
+ // 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 << "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( |
+ scoped_refptr<InputMethodManager::State> state) { |
+ LOG(ERROR) << "InputMethodManagerImpl::SetState(): Called."; |
Shu Chen
2014/08/07 15:40:19
I suppose these logs will be removed before submit
Alexander Alekseev
2014/08/07 17:26:19
Yes. As this CL is still in "concept" state, here
Alexander Alekseev
2014/08/13 10:14:15
Done.
|
+ 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(); |
Shu Chen
2014/08/09 15:49:22
Considering user A and B. ReconfigureIMFramework()
Alexander Alekseev
2014/08/13 10:14:15
Done.
|
+ ChangeInputMethodInternal(state_->current_input_method_, false); |
+ } |
+} |
+ |
InputMethodManagerImpl::InputMethodManagerImpl( |
scoped_ptr<InputMethodDelegate> delegate) |
: delegate_(delegate.Pass()), |
- state_(STATE_LOGIN_SCREEN), |
+ ui_session_(STATE_LOGIN_SCREEN), |
+ state_(NULL), |
util_(delegate_.get()), |
component_extension_ime_manager_(new ComponentExtensionIMEManager()), |
weak_ptr_factory_(this) { |
+ SetState(CreateNewState("default")); |
if (base::SysInfo::IsRunningOnChromeOS()) |
keyboard_.reset(ImeKeyboard::Create()); |
else |
@@ -94,14 +173,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::SetUISessionState(UISessionState new_ui_session) { |
+ const UISessionState old_ui_session = ui_session_; |
+ ui_session_ = new_ui_session; |
+ switch (ui_session_) { |
case STATE_LOGIN_SCREEN: |
break; |
case STATE_BROWSER_SCREEN: |
- if (old_state == STATE_LOCK_SCREEN) |
+ if (old_ui_session == STATE_LOCK_SCREEN) |
OnScreenUnlocked(); |
break; |
case STATE_LOCK_SCREEN: |
@@ -125,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) { |
@@ -151,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( |
@@ -174,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_session_ == STATE_TERMINATING) |
return; |
+ LOG(ERROR) << "InputMethodManagerImpl::EnableLoginLayouts(): old state_: " |
+ << state_->Dump(); |
// First, hardware keyboard layout should be shown. |
std::vector<std::string> candidates = |
@@ -219,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|. |
@@ -260,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(); |
@@ -269,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_session_ == 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; |
@@ -286,32 +378,52 @@ 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); |
Shu Chen
2014/08/09 15:49:22
Per our offline discussion, there is no need to ha
Alexander Alekseev
2014/08/13 10:14:15
I had to split "Lookup" and "Change" to enable mod
|
+} |
+ |
+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::ChangeInputMethodInternal( |
+void InputMethodManagerImpl::LookupAndChangeInputMethodInternal( |
const std::string& input_method_id, |
bool show_message) { |
- if (state_ == STATE_TERMINATING) |
- return false; |
+ if (ui_session_ == STATE_TERMINATING) |
+ return; |
std::string input_method_id_to_switch = input_method_id; |
@@ -333,7 +445,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 |
@@ -357,8 +469,8 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
} |
DCHECK(descriptor); |
- previous_input_method_ = current_input_method_; |
- current_input_method_ = *descriptor; |
+ state_->previous_input_method_ = state_->current_input_method_; |
+ state_->current_input_method_ = *descriptor; |
} |
// Disable the current engine handler. |
@@ -376,44 +488,41 @@ bool InputMethodManagerImpl::ChangeInputMethodInternal( |
const std::string& component_id = |
extension_ime_util::GetComponentIDByInputMethodID( |
input_method_id_to_switch); |
- engine = engine_map_[extension_id]; |
+ engine = state_->engine_map_[extension_id]; |
IMEBridge::Get()->SetCurrentEngineHandler(engine); |
if (engine) |
engine->Enable(component_id); |
- // 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(); |
- } |
- |
- // Update input method indicators (e.g. "US", "DV") in Chrome windows. |
- FOR_EACH_OBSERVER(InputMethodManager::Observer, |
- observers_, |
- InputMethodChanged(this, show_message)); |
- return true; |
+ ChangeInputMethodInternal(state_->current_input_method_, show_message); |
+ return; |
Shu Chen
2014/08/07 15:40:19
useless return;
Alexander Alekseev
2014/08/13 10:14:15
Done.
|
} |
void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { |
+ 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(); |
} |
void InputMethodManagerImpl::ActivateInputMethodMenuItem( |
@@ -436,18 +545,22 @@ void InputMethodManagerImpl::AddInputMethodExtension( |
const std::string& extension_id, |
const InputMethodDescriptors& descriptors, |
InputMethodEngineInterface* engine) { |
- if (state_ == STATE_TERMINATING) |
+ if (ui_session_ == STATE_TERMINATING) |
return; |
+ LOG(ERROR) |
+ << "InputMethodManagerImpl::AddInputMethodExtension(): old state_: " |
+ << state_->Dump(); |
DCHECK(engine); |
+ DCHECK(state_); |
- engine_map_[extension_id] = engine; |
+ state_->engine_map_[extension_id] = engine; |
if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID( |
- current_input_method_.id())) { |
+ state_->current_input_method_.id())) { |
IMEBridge::Get()->SetCurrentEngineHandler(engine); |
engine->Enable(extension_ime_util::GetComponentIDByInputMethodID( |
- current_input_method_.id())); |
+ state_->current_input_method_.id())); |
} |
bool contain = false; |
@@ -456,8 +569,11 @@ void InputMethodManagerImpl::AddInputMethodExtension( |
const std::string& id = descriptor.id(); |
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: already added: " << id << ", " |
<< descriptor.name(); |
@@ -473,14 +589,19 @@ void InputMethodManagerImpl::AddInputMethodExtension( |
void InputMethodManagerImpl::RemoveInputMethodExtension( |
const std::string& extension_id) { |
+ LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('" |
+ << extension_id << "'): old state_: " << state_->Dump(); |
+ |
+ DCHECK(state_); |
// Remove the active input methods with |extension_id|. |
std::vector<std::string> new_active_input_method_ids; |
- for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { |
+ for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) { |
if (extension_id != extension_ime_util::GetExtensionIDFromInputMethodID( |
- active_input_method_ids_[i])) |
- new_active_input_method_ids.push_back(active_input_method_ids_[i]); |
+ state_->active_input_method_ids_[i])) |
+ new_active_input_method_ids.push_back( |
+ state_->active_input_method_ids_[i]); |
} |
- active_input_method_ids_.swap(new_active_input_method_ids); |
+ state_->active_input_method_ids_.swap(new_active_input_method_ids); |
// Remove the extra input methods with |extension_id|. |
std::map<std::string, InputMethodDescriptor> new_extra_input_methods; |
@@ -494,15 +615,18 @@ void InputMethodManagerImpl::RemoveInputMethodExtension( |
} |
extra_input_methods_.swap(new_extra_input_methods); |
- if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id]) |
+ if (IMEBridge::Get()->GetCurrentEngineHandler() == |
+ state_->engine_map_[extension_id]) |
IMEBridge::Get()->SetCurrentEngineHandler(NULL); |
- engine_map_.erase(extension_id); |
+ state_->engine_map_.erase(extension_id); |
+ LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('" |
+ << extension_id << "'): new state_: " << state_->Dump(); |
// No need to switch input method when terminating. |
- if (state_ != STATE_TERMINATING) { |
+ if (ui_session_ != 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()); |
} |
} |
@@ -524,6 +648,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; |
@@ -533,29 +660,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()); |
} |
} |
@@ -624,65 +756,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; |
} |
@@ -721,7 +857,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()) { |
@@ -730,7 +866,7 @@ bool InputMethodManagerImpl::SwitchInputMethod( |
return false; |
} |
- SwitchToNextInputMethodInternal(ids, current_input_method_.id()); |
+ SwitchToNextInputMethodInternal(ids, state_->current_input_method_.id()); |
return true; // consume the accelerator. |
} |
@@ -745,14 +881,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 { |
@@ -823,24 +960,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); |
} |
@@ -849,25 +990,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() { |