Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/chromeos/input_method/input_method_manager_impl.cc

Issue 419293002: IME refactoring: ChromeOS introduce input methods State. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <sstream>
10
9 #include "ash/ime/input_method_menu_item.h" 11 #include "ash/ime/input_method_menu_item.h"
10 #include "ash/ime/input_method_menu_manager.h" 12 #include "ash/ime/input_method_menu_manager.h"
11 #include "base/basictypes.h" 13 #include "base/basictypes.h"
12 #include "base/bind.h" 14 #include "base/bind.h"
13 #include "base/location.h" 15 #include "base/location.h"
14 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
15 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
(...skipping 30 matching lines...) Expand all
49 bool InputMethodManagerImpl::IsLoginKeyboard( 51 bool InputMethodManagerImpl::IsLoginKeyboard(
50 const std::string& layout) const { 52 const std::string& layout) const {
51 return util_.IsLoginKeyboard(layout); 53 return util_.IsLoginKeyboard(layout);
52 } 54 }
53 55
54 bool InputMethodManagerImpl::MigrateInputMethods( 56 bool InputMethodManagerImpl::MigrateInputMethods(
55 std::vector<std::string>* input_method_ids) { 57 std::vector<std::string>* input_method_ids) {
56 return util_.MigrateInputMethods(input_method_ids); 58 return util_.MigrateInputMethods(input_method_ids);
57 } 59 }
58 60
61 InputMethodManagerImpl::State::State() {
62 }
63
64 InputMethodManagerImpl::State::~State() {
65 }
66
67 void InputMethodManagerImpl::State::InitFrom(const State& other) {
68 // debug_name is not copied.
69
70 previous_input_method_ = other.previous_input_method_;
71 current_input_method_ = other.current_input_method_;
72
73 active_input_method_ids_ = other.active_input_method_ids_;
74
75 saved_previous_input_method_ = other.saved_previous_input_method_;
76 saved_current_input_method_ = other.saved_current_input_method_;
77 saved_active_input_method_ids_ = other.saved_active_input_method_ids_;
78
79 // TODO: recreate all input engines?
80 // typedef std::map<std::string, InputMethodEngineInterface*> EngineMap;
81 engine_map_ = other.engine_map_;
82 }
83
84 std::string InputMethodManagerImpl::State::Dump() const {
85 std::ostringstream os;
86
87 os << "################# " << state_name << " #################\n";
88
89 os << "previous_input_method_: '"
90 << previous_input_method_.GetPreferredKeyboardLayout() << "'\n";
91 os << "current_input_method_: '"
92 << current_input_method_.GetPreferredKeyboardLayout() << "'\n";
93 os << "active_input_method_ids_ (size=" << active_input_method_ids_.size()
94 << "):";
95 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) {
96 os << " '" << active_input_method_ids_[i] << "',";
97 }
98 os << "\n";
99 os << "saved_previous_input_method_: '"
100 << saved_previous_input_method_.GetPreferredKeyboardLayout() << "'\n";
101 os << "saved_current_input_method_: '"
102 << saved_current_input_method_.GetPreferredKeyboardLayout() << "'\n";
103 os << "saved_active_input_method_ids_ (size="
104 << saved_active_input_method_ids_.size() << "):";
105 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) {
106 os << " '" << saved_active_input_method_ids_[i] << "'\n";
107 }
108 os << "engine_map_ (size=" << engine_map_.size() << "): ...\n ";
109
110 return os.str();
111 }
112
113 scoped_refptr<InputMethodManager::State> InputMethodManagerImpl::CreateNewState(
114 const std::string& debug_name) const {
115 scoped_refptr<InputMethodManagerImpl::State> new_state(
116 new InputMethodManagerImpl::State);
117 new_state->state_name = debug_name;
118
119 return scoped_refptr<InputMethodManager::State>(new_state.get());
120 }
121
122 void InputMethodManagerImpl::SetState(
123 scoped_refptr<InputMethodManager::State> state) {
124 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.
125 LOG(ERROR) << "InputMethodManagerImpl::SetState(): old state_: "
126 << (state_ ? state_->Dump() : std::string("NULL"));
127 state_ = static_cast<InputMethodManagerImpl::State*>(state.get());
128 LOG(ERROR) << "InputMethodManagerImpl::SetState(): new state_: "
129 << (state_ ? state_->Dump() : std::string("NULL"));
130 if (state_->active_input_method_ids_.size()) {
131 ReconfigureIMFramework();
Shu Chen 2014/08/09 15:49:22 Considering user A and B. ReconfigureIMFramework()
Alexander Alekseev 2014/08/13 10:14:15 Done.
132 ChangeInputMethodInternal(state_->current_input_method_, false);
133 }
134 }
135
59 InputMethodManagerImpl::InputMethodManagerImpl( 136 InputMethodManagerImpl::InputMethodManagerImpl(
60 scoped_ptr<InputMethodDelegate> delegate) 137 scoped_ptr<InputMethodDelegate> delegate)
61 : delegate_(delegate.Pass()), 138 : delegate_(delegate.Pass()),
62 state_(STATE_LOGIN_SCREEN), 139 ui_session_(STATE_LOGIN_SCREEN),
140 state_(NULL),
63 util_(delegate_.get()), 141 util_(delegate_.get()),
64 component_extension_ime_manager_(new ComponentExtensionIMEManager()), 142 component_extension_ime_manager_(new ComponentExtensionIMEManager()),
65 weak_ptr_factory_(this) { 143 weak_ptr_factory_(this) {
144 SetState(CreateNewState("default"));
66 if (base::SysInfo::IsRunningOnChromeOS()) 145 if (base::SysInfo::IsRunningOnChromeOS())
67 keyboard_.reset(ImeKeyboard::Create()); 146 keyboard_.reset(ImeKeyboard::Create());
68 else 147 else
69 keyboard_.reset(new FakeImeKeyboard()); 148 keyboard_.reset(new FakeImeKeyboard());
70 } 149 }
71 150
72 InputMethodManagerImpl::~InputMethodManagerImpl() { 151 InputMethodManagerImpl::~InputMethodManagerImpl() {
73 if (candidate_window_controller_.get()) 152 if (candidate_window_controller_.get())
74 candidate_window_controller_->RemoveObserver(this); 153 candidate_window_controller_->RemoveObserver(this);
75 } 154 }
(...skipping 11 matching lines...) Expand all
87 void InputMethodManagerImpl::RemoveObserver( 166 void InputMethodManagerImpl::RemoveObserver(
88 InputMethodManager::Observer* observer) { 167 InputMethodManager::Observer* observer) {
89 observers_.RemoveObserver(observer); 168 observers_.RemoveObserver(observer);
90 } 169 }
91 170
92 void InputMethodManagerImpl::RemoveCandidateWindowObserver( 171 void InputMethodManagerImpl::RemoveCandidateWindowObserver(
93 InputMethodManager::CandidateWindowObserver* observer) { 172 InputMethodManager::CandidateWindowObserver* observer) {
94 candidate_window_observers_.RemoveObserver(observer); 173 candidate_window_observers_.RemoveObserver(observer);
95 } 174 }
96 175
97 void InputMethodManagerImpl::SetState(State new_state) { 176 void InputMethodManagerImpl::SetUISessionState(UISessionState new_ui_session) {
98 const State old_state = state_; 177 const UISessionState old_ui_session = ui_session_;
99 state_ = new_state; 178 ui_session_ = new_ui_session;
100 switch (state_) { 179 switch (ui_session_) {
101 case STATE_LOGIN_SCREEN: 180 case STATE_LOGIN_SCREEN:
102 break; 181 break;
103 case STATE_BROWSER_SCREEN: 182 case STATE_BROWSER_SCREEN:
104 if (old_state == STATE_LOCK_SCREEN) 183 if (old_ui_session == STATE_LOCK_SCREEN)
105 OnScreenUnlocked(); 184 OnScreenUnlocked();
106 break; 185 break;
107 case STATE_LOCK_SCREEN: 186 case STATE_LOCK_SCREEN:
108 OnScreenLocked(); 187 OnScreenLocked();
109 break; 188 break;
110 case STATE_TERMINATING: { 189 case STATE_TERMINATING: {
111 if (candidate_window_controller_.get()) 190 if (candidate_window_controller_.get())
112 candidate_window_controller_.reset(); 191 candidate_window_controller_.reset();
113 break; 192 break;
114 } 193 }
115 } 194 }
116 } 195 }
117 196
118 scoped_ptr<InputMethodDescriptors> 197 scoped_ptr<InputMethodDescriptors>
119 InputMethodManagerImpl::GetSupportedInputMethods() const { 198 InputMethodManagerImpl::GetSupportedInputMethods() const {
120 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass(); 199 return scoped_ptr<InputMethodDescriptors>(new InputMethodDescriptors).Pass();
121 } 200 }
122 201
123 scoped_ptr<InputMethodDescriptors> 202 scoped_ptr<InputMethodDescriptors>
124 InputMethodManagerImpl::GetActiveInputMethods() const { 203 InputMethodManagerImpl::GetActiveInputMethods() const {
125 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors); 204 scoped_ptr<InputMethodDescriptors> result(new InputMethodDescriptors);
126 // Build the active input method descriptors from the active input 205 // Build the active input method descriptors from the active input
127 // methods cache |active_input_method_ids_|. 206 // methods cache |active_input_method_ids_|.
128 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 207 DCHECK(state_);
129 const std::string& input_method_id = active_input_method_ids_[i]; 208 for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) {
209 const std::string& input_method_id = state_->active_input_method_ids_[i];
130 const InputMethodDescriptor* descriptor = 210 const InputMethodDescriptor* descriptor =
131 util_.GetInputMethodDescriptorFromId(input_method_id); 211 util_.GetInputMethodDescriptorFromId(input_method_id);
132 if (descriptor) { 212 if (descriptor) {
133 result->push_back(*descriptor); 213 result->push_back(*descriptor);
134 } else { 214 } else {
135 std::map<std::string, InputMethodDescriptor>::const_iterator ix = 215 std::map<std::string, InputMethodDescriptor>::const_iterator ix =
136 extra_input_methods_.find(input_method_id); 216 extra_input_methods_.find(input_method_id);
137 if (ix != extra_input_methods_.end()) 217 if (ix != extra_input_methods_.end())
138 result->push_back(ix->second); 218 result->push_back(ix->second);
139 else 219 else
140 DVLOG(1) << "Descriptor is not found for: " << input_method_id; 220 DVLOG(1) << "Descriptor is not found for: " << input_method_id;
141 } 221 }
142 } 222 }
143 if (result->empty()) { 223 if (result->empty()) {
144 // Initially |active_input_method_ids_| is empty. browser_tests might take 224 // Initially |active_input_method_ids_| is empty. browser_tests might take
145 // this path. 225 // this path.
146 result->push_back( 226 result->push_back(
147 InputMethodUtil::GetFallbackInputMethodDescriptor()); 227 InputMethodUtil::GetFallbackInputMethodDescriptor());
148 } 228 }
149 return result.Pass(); 229 return result.Pass();
150 } 230 }
151 231
152 const std::vector<std::string>& 232 const std::vector<std::string>&
153 InputMethodManagerImpl::GetActiveInputMethodIds() const { 233 InputMethodManagerImpl::GetActiveInputMethodIds() const {
154 return active_input_method_ids_; 234 DCHECK(state_);
235 return state_->active_input_method_ids_;
155 } 236 }
156 237
157 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const { 238 size_t InputMethodManagerImpl::GetNumActiveInputMethods() const {
158 return active_input_method_ids_.size(); 239 DCHECK(state_);
240 return state_->active_input_method_ids_.size();
159 } 241 }
160 242
161 const InputMethodDescriptor* InputMethodManagerImpl::GetInputMethodFromId( 243 const InputMethodDescriptor* InputMethodManagerImpl::GetInputMethodFromId(
162 const std::string& input_method_id) const { 244 const std::string& input_method_id) const {
163 const InputMethodDescriptor* ime = util_.GetInputMethodDescriptorFromId( 245 const InputMethodDescriptor* ime = util_.GetInputMethodDescriptorFromId(
164 input_method_id); 246 input_method_id);
165 if (!ime) { 247 if (!ime) {
166 std::map<std::string, InputMethodDescriptor>::const_iterator ix = 248 std::map<std::string, InputMethodDescriptor>::const_iterator ix =
167 extra_input_methods_.find(input_method_id); 249 extra_input_methods_.find(input_method_id);
168 if (ix != extra_input_methods_.end()) 250 if (ix != extra_input_methods_.end())
169 ime = &ix->second; 251 ime = &ix->second;
170 } 252 }
171 return ime; 253 return ime;
172 } 254 }
173 255
174 void InputMethodManagerImpl::EnableLoginLayouts( 256 void InputMethodManagerImpl::EnableLoginLayouts(
175 const std::string& language_code, 257 const std::string& language_code,
176 const std::vector<std::string>& initial_layouts) { 258 const std::vector<std::string>& initial_layouts) {
177 if (state_ == STATE_TERMINATING) 259 if (ui_session_ == STATE_TERMINATING)
178 return; 260 return;
261 LOG(ERROR) << "InputMethodManagerImpl::EnableLoginLayouts(): old state_: "
262 << state_->Dump();
179 263
180 // First, hardware keyboard layout should be shown. 264 // First, hardware keyboard layout should be shown.
181 std::vector<std::string> candidates = 265 std::vector<std::string> candidates =
182 util_.GetHardwareLoginInputMethodIds(); 266 util_.GetHardwareLoginInputMethodIds();
183 267
184 // Seocnd, locale based input method should be shown. 268 // Seocnd, locale based input method should be shown.
185 // Add input methods associated with the language. 269 // Add input methods associated with the language.
186 std::vector<std::string> layouts_from_locale; 270 std::vector<std::string> layouts_from_locale;
187 util_.GetInputMethodIdsFromLanguageCode(language_code, 271 util_.GetInputMethodIdsFromLanguageCode(language_code,
188 kKeyboardLayoutsOnly, 272 kKeyboardLayoutsOnly,
(...skipping 23 matching lines...) Expand all
212 // Add candidates to layouts, while skipping duplicates. 296 // Add candidates to layouts, while skipping duplicates.
213 for (size_t i = 0; i < candidates.size(); ++i) { 297 for (size_t i = 0; i < candidates.size(); ++i) {
214 const std::string& candidate = candidates[i]; 298 const std::string& candidate = candidates[i];
215 // Not efficient, but should be fine, as the two vectors are very 299 // Not efficient, but should be fine, as the two vectors are very
216 // short (2-5 items). 300 // short (2-5 items).
217 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate)) 301 if (!Contains(layouts, candidate) && IsLoginKeyboard(candidate))
218 layouts.push_back(candidate); 302 layouts.push_back(candidate);
219 } 303 }
220 304
221 MigrateInputMethods(&layouts); 305 MigrateInputMethods(&layouts);
222 active_input_method_ids_.swap(layouts); 306 DCHECK(state_);
307 state_->active_input_method_ids_.swap(layouts);
308 LOG(ERROR) << "InputMethodManagerImpl::EnableLoginLayouts(): new state_: "
309 << state_->Dump();
223 310
224 // Initialize candidate window controller and widgets such as 311 // Initialize candidate window controller and widgets such as
225 // candidate window, infolist and mode indicator. Note, mode 312 // candidate window, infolist and mode indicator. Note, mode
226 // indicator is used by only keyboard layout input methods. 313 // indicator is used by only keyboard layout input methods.
227 if (active_input_method_ids_.size() > 1) 314 if (state_->active_input_method_ids_.size() > 1)
228 MaybeInitializeCandidateWindowController(); 315 MaybeInitializeCandidateWindowController();
229 316
230 // you can pass empty |initial_layout|. 317 // you can pass empty |initial_layout|.
231 ChangeInputMethod(initial_layouts.empty() ? "" : 318 ChangeInputMethod(initial_layouts.empty() ? "" :
232 extension_ime_util::GetInputMethodIDByEngineID(initial_layouts[0])); 319 extension_ime_util::GetInputMethodIDByEngineID(initial_layouts[0]));
233 } 320 }
234 321
235 // Adds new input method to given list. 322 // Adds new input method to given list.
236 bool InputMethodManagerImpl::EnableInputMethodImpl( 323 bool InputMethodManagerImpl::EnableInputMethodImpl(
237 const std::string& input_method_id, 324 const std::string& input_method_id,
(...skipping 15 matching lines...) Expand all
253 LoadNecessaryComponentExtensions(); 340 LoadNecessaryComponentExtensions();
254 341
255 // Initialize candidate window controller and widgets such as 342 // Initialize candidate window controller and widgets such as
256 // candidate window, infolist and mode indicator. Note, mode 343 // candidate window, infolist and mode indicator. Note, mode
257 // indicator is used by only keyboard layout input methods. 344 // indicator is used by only keyboard layout input methods.
258 MaybeInitializeCandidateWindowController(); 345 MaybeInitializeCandidateWindowController();
259 } 346 }
260 347
261 bool InputMethodManagerImpl::EnableInputMethod( 348 bool InputMethodManagerImpl::EnableInputMethod(
262 const std::string& input_method_id) { 349 const std::string& input_method_id) {
263 if (!EnableInputMethodImpl(input_method_id, &active_input_method_ids_)) 350 DCHECK(state_);
351 if (!EnableInputMethodImpl(input_method_id,
352 &(state_->active_input_method_ids_)))
264 return false; 353 return false;
265 354
266 ReconfigureIMFramework(); 355 ReconfigureIMFramework();
267 return true; 356 return true;
268 } 357 }
269 358
270 bool InputMethodManagerImpl::ReplaceEnabledInputMethods( 359 bool InputMethodManagerImpl::ReplaceEnabledInputMethods(
271 const std::vector<std::string>& new_active_input_method_ids) { 360 const std::vector<std::string>& new_active_input_method_ids) {
272 if (state_ == STATE_TERMINATING) 361 if (ui_session_ == STATE_TERMINATING)
273 return false; 362 return false;
363 LOG(ERROR)
364 << "InputMethodManagerImpl::ReplaceEnabledInputMethods(): old state_: "
365 << state_->Dump();
274 366
275 // Filter unknown or obsolete IDs. 367 // Filter unknown or obsolete IDs.
276 std::vector<std::string> new_active_input_method_ids_filtered; 368 std::vector<std::string> new_active_input_method_ids_filtered;
277 369
278 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i) 370 for (size_t i = 0; i < new_active_input_method_ids.size(); ++i)
279 EnableInputMethodImpl(new_active_input_method_ids[i], 371 EnableInputMethodImpl(new_active_input_method_ids[i],
280 &new_active_input_method_ids_filtered); 372 &new_active_input_method_ids_filtered);
281 373
282 if (new_active_input_method_ids_filtered.empty()) { 374 if (new_active_input_method_ids_filtered.empty()) {
283 DVLOG(1) << "ReplaceEnabledInputMethods: No valid input method ID"; 375 DVLOG(1) << "ReplaceEnabledInputMethods: No valid input method ID";
284 return false; 376 return false;
285 } 377 }
286 378
287 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to 379 // Copy extension IDs to |new_active_input_method_ids_filtered|. We have to
288 // keep relative order of the extension input method IDs. 380 // keep relative order of the extension input method IDs.
289 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 381 DCHECK(state_);
290 const std::string& input_method_id = active_input_method_ids_[i]; 382 for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) {
383 const std::string& input_method_id = state_->active_input_method_ids_[i];
291 if (extension_ime_util::IsExtensionIME(input_method_id)) 384 if (extension_ime_util::IsExtensionIME(input_method_id))
292 new_active_input_method_ids_filtered.push_back(input_method_id); 385 new_active_input_method_ids_filtered.push_back(input_method_id);
293 } 386 }
294 active_input_method_ids_.swap(new_active_input_method_ids_filtered); 387 state_->active_input_method_ids_.swap(new_active_input_method_ids_filtered);
295 MigrateInputMethods(&active_input_method_ids_); 388 MigrateInputMethods(&(state_->active_input_method_ids_));
296 389
390 LOG(ERROR)
391 << "InputMethodManagerImpl::ReplaceEnabledInputMethods(): new state_: "
392 << state_->Dump();
297 ReconfigureIMFramework(); 393 ReconfigureIMFramework();
298 394
299 // If |current_input_method| is no longer in |active_input_method_ids_|, 395 // If |current_input_method| is no longer in |active_input_method_ids_|,
300 // ChangeInputMethod() picks the first one in |active_input_method_ids_|. 396 // ChangeInputMethod() picks the first one in |active_input_method_ids_|.
301 ChangeInputMethod(current_input_method_.id()); 397 ChangeInputMethod(state_->current_input_method_.id());
302 return true; 398 return true;
303 } 399 }
304 400
305 void InputMethodManagerImpl::ChangeInputMethod( 401 void InputMethodManagerImpl::ChangeInputMethod(
306 const std::string& input_method_id) { 402 const std::string& input_method_id) {
307 ChangeInputMethodInternal(input_method_id, false); 403 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
308 } 404 }
309 405
310 bool InputMethodManagerImpl::ChangeInputMethodInternal( 406 void InputMethodManagerImpl::ChangeInputMethodInternal(
407 const InputMethodDescriptor& descriptor,
408 bool show_message) {
409 // Change the keyboard layout to a preferred layout for the input method.
410 if (!keyboard_->SetCurrentKeyboardLayoutByName(
411 descriptor.GetPreferredKeyboardLayout())) {
412 LOG(ERROR) << "Failed to change keyboard layout to "
413 << descriptor.GetPreferredKeyboardLayout();
414 }
415
416 // Update input method indicators (e.g. "US", "DV") in Chrome windows.
417 FOR_EACH_OBSERVER(InputMethodManager::Observer,
418 observers_,
419 InputMethodChanged(this, show_message));
420 }
421
422 void InputMethodManagerImpl::LookupAndChangeInputMethodInternal(
311 const std::string& input_method_id, 423 const std::string& input_method_id,
312 bool show_message) { 424 bool show_message) {
313 if (state_ == STATE_TERMINATING) 425 if (ui_session_ == STATE_TERMINATING)
314 return false; 426 return;
315 427
316 std::string input_method_id_to_switch = input_method_id; 428 std::string input_method_id_to_switch = input_method_id;
317 429
318 // Sanity check. 430 // Sanity check.
319 if (!InputMethodIsActivated(input_method_id)) { 431 if (!InputMethodIsActivated(input_method_id)) {
320 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods()); 432 scoped_ptr<InputMethodDescriptors> input_methods(GetActiveInputMethods());
321 DCHECK(!input_methods->empty()); 433 DCHECK(!input_methods->empty());
322 input_method_id_to_switch = input_methods->at(0).id(); 434 input_method_id_to_switch = input_methods->at(0).id();
323 if (!input_method_id.empty()) { 435 if (!input_method_id.empty()) {
324 DVLOG(1) << "Can't change the current input method to " 436 DVLOG(1) << "Can't change the current input method to "
325 << input_method_id << " since the engine is not enabled. " 437 << input_method_id << " since the engine is not enabled. "
326 << "Switch to " << input_method_id_to_switch << " instead."; 438 << "Switch to " << input_method_id_to_switch << " instead.";
327 } 439 }
328 } 440 }
329 441
330 // Hide candidate window and info list. 442 // Hide candidate window and info list.
331 if (candidate_window_controller_.get()) 443 if (candidate_window_controller_.get())
332 candidate_window_controller_->Hide(); 444 candidate_window_controller_->Hide();
333 445
334 // TODO(komatsu): Check if it is necessary to perform the above routine 446 // TODO(komatsu): Check if it is necessary to perform the above routine
335 // when the current input method is equal to |input_method_id_to_swich|. 447 // when the current input method is equal to |input_method_id_to_swich|.
336 if (current_input_method_.id() != input_method_id_to_switch) { 448 if (state_->current_input_method_.id() != input_method_id_to_switch) {
337 // Clear property list. Property list would be updated by 449 // Clear property list. Property list would be updated by
338 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems. 450 // extension IMEs via InputMethodEngine::(Set|Update)MenuItems.
339 // If the current input method is a keyboard layout, empty 451 // If the current input method is a keyboard layout, empty
340 // properties are sufficient. 452 // properties are sufficient.
341 const ash::ime::InputMethodMenuItemList empty_menu_item_list; 453 const ash::ime::InputMethodMenuItemList empty_menu_item_list;
342 ash::ime::InputMethodMenuManager* input_method_menu_manager = 454 ash::ime::InputMethodMenuManager* input_method_menu_manager =
343 ash::ime::InputMethodMenuManager::GetInstance(); 455 ash::ime::InputMethodMenuManager::GetInstance();
344 input_method_menu_manager->SetCurrentInputMethodMenuItemList( 456 input_method_menu_manager->SetCurrentInputMethodMenuItemList(
345 empty_menu_item_list); 457 empty_menu_item_list);
346 458
347 const InputMethodDescriptor* descriptor = NULL; 459 const InputMethodDescriptor* descriptor = NULL;
348 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) { 460 if (extension_ime_util::IsExtensionIME(input_method_id_to_switch)) {
349 DCHECK(extra_input_methods_.find(input_method_id_to_switch) != 461 DCHECK(extra_input_methods_.find(input_method_id_to_switch) !=
350 extra_input_methods_.end()); 462 extra_input_methods_.end());
351 descriptor = &(extra_input_methods_[input_method_id_to_switch]); 463 descriptor = &(extra_input_methods_[input_method_id_to_switch]);
352 } else { 464 } else {
353 descriptor = 465 descriptor =
354 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch); 466 util_.GetInputMethodDescriptorFromId(input_method_id_to_switch);
355 if (!descriptor) 467 if (!descriptor)
356 LOG(ERROR) << "Unknown input method id: " << input_method_id_to_switch; 468 LOG(ERROR) << "Unknown input method id: " << input_method_id_to_switch;
357 } 469 }
358 DCHECK(descriptor); 470 DCHECK(descriptor);
359 471
360 previous_input_method_ = current_input_method_; 472 state_->previous_input_method_ = state_->current_input_method_;
361 current_input_method_ = *descriptor; 473 state_->current_input_method_ = *descriptor;
362 } 474 }
363 475
364 // Disable the current engine handler. 476 // Disable the current engine handler.
365 IMEEngineHandlerInterface* engine = 477 IMEEngineHandlerInterface* engine =
366 IMEBridge::Get()->GetCurrentEngineHandler(); 478 IMEBridge::Get()->GetCurrentEngineHandler();
367 if (engine) 479 if (engine)
368 engine->Disable(); 480 engine->Disable();
369 481
370 // Configure the next engine handler. 482 // Configure the next engine handler.
371 // This must be after |current_input_method_| has been set to new input 483 // This must be after |current_input_method_| has been set to new input
372 // method, because engine's Enable() method needs to access it. 484 // method, because engine's Enable() method needs to access it.
373 const std::string& extension_id = 485 const std::string& extension_id =
374 extension_ime_util::GetExtensionIDFromInputMethodID( 486 extension_ime_util::GetExtensionIDFromInputMethodID(
375 input_method_id_to_switch); 487 input_method_id_to_switch);
376 const std::string& component_id = 488 const std::string& component_id =
377 extension_ime_util::GetComponentIDByInputMethodID( 489 extension_ime_util::GetComponentIDByInputMethodID(
378 input_method_id_to_switch); 490 input_method_id_to_switch);
379 engine = engine_map_[extension_id]; 491 engine = state_->engine_map_[extension_id];
380 IMEBridge::Get()->SetCurrentEngineHandler(engine); 492 IMEBridge::Get()->SetCurrentEngineHandler(engine);
381 if (engine) 493 if (engine)
382 engine->Enable(component_id); 494 engine->Enable(component_id);
383 495
384 // Change the keyboard layout to a preferred layout for the input method. 496 ChangeInputMethodInternal(state_->current_input_method_, show_message);
385 if (!keyboard_->SetCurrentKeyboardLayoutByName( 497 return;
Shu Chen 2014/08/07 15:40:19 useless return;
Alexander Alekseev 2014/08/13 10:14:15 Done.
386 current_input_method_.GetPreferredKeyboardLayout())) {
387 LOG(ERROR) << "Failed to change keyboard layout to "
388 << current_input_method_.GetPreferredKeyboardLayout();
389 }
390
391 // Update input method indicators (e.g. "US", "DV") in Chrome windows.
392 FOR_EACH_OBSERVER(InputMethodManager::Observer,
393 observers_,
394 InputMethodChanged(this, show_message));
395 return true;
396 } 498 }
397 499
398 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() { 500 void InputMethodManagerImpl::LoadNecessaryComponentExtensions() {
501 LOG(ERROR) << "InputMethodManagerImpl::LoadNecessaryComponentExtensions(): "
502 "old state_: " << state_->Dump();
399 // Load component extensions but also update |active_input_method_ids_| as 503 // Load component extensions but also update |active_input_method_ids_| as
400 // some component extension IMEs may have been removed from the Chrome OS 504 // some component extension IMEs may have been removed from the Chrome OS
401 // image. If specified component extension IME no longer exists, falling back 505 // image. If specified component extension IME no longer exists, falling back
402 // to an existing IME. 506 // to an existing IME.
507 DCHECK(state_);
403 std::vector<std::string> unfiltered_input_method_ids; 508 std::vector<std::string> unfiltered_input_method_ids;
404 unfiltered_input_method_ids.swap(active_input_method_ids_); 509 unfiltered_input_method_ids.swap(state_->active_input_method_ids_);
405 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) { 510 for (size_t i = 0; i < unfiltered_input_method_ids.size(); ++i) {
406 if (!extension_ime_util::IsComponentExtensionIME( 511 if (!extension_ime_util::IsComponentExtensionIME(
407 unfiltered_input_method_ids[i])) { 512 unfiltered_input_method_ids[i])) {
408 // Legacy IMEs or xkb layouts are alwayes active. 513 // Legacy IMEs or xkb layouts are alwayes active.
409 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 514 state_->active_input_method_ids_.push_back(
515 unfiltered_input_method_ids[i]);
410 } else if (component_extension_ime_manager_->IsWhitelisted( 516 } else if (component_extension_ime_manager_->IsWhitelisted(
411 unfiltered_input_method_ids[i])) { 517 unfiltered_input_method_ids[i])) {
412 component_extension_ime_manager_->LoadComponentExtensionIME( 518 component_extension_ime_manager_->LoadComponentExtensionIME(
413 unfiltered_input_method_ids[i]); 519 unfiltered_input_method_ids[i]);
414 active_input_method_ids_.push_back(unfiltered_input_method_ids[i]); 520 state_->active_input_method_ids_.push_back(
521 unfiltered_input_method_ids[i]);
415 } 522 }
416 } 523 }
524 LOG(ERROR) << "InputMethodManagerImpl::LoadNecessaryComponentExtensions(): "
525 "new state_: " << state_->Dump();
417 } 526 }
418 527
419 void InputMethodManagerImpl::ActivateInputMethodMenuItem( 528 void InputMethodManagerImpl::ActivateInputMethodMenuItem(
420 const std::string& key) { 529 const std::string& key) {
421 DCHECK(!key.empty()); 530 DCHECK(!key.empty());
422 531
423 if (ash::ime::InputMethodMenuManager::GetInstance()-> 532 if (ash::ime::InputMethodMenuManager::GetInstance()->
424 HasInputMethodMenuItemForKey(key)) { 533 HasInputMethodMenuItemForKey(key)) {
425 IMEEngineHandlerInterface* engine = 534 IMEEngineHandlerInterface* engine =
426 IMEBridge::Get()->GetCurrentEngineHandler(); 535 IMEBridge::Get()->GetCurrentEngineHandler();
427 if (engine) 536 if (engine)
428 engine->PropertyActivate(key); 537 engine->PropertyActivate(key);
429 return; 538 return;
430 } 539 }
431 540
432 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key; 541 DVLOG(1) << "ActivateInputMethodMenuItem: unknown key: " << key;
433 } 542 }
434 543
435 void InputMethodManagerImpl::AddInputMethodExtension( 544 void InputMethodManagerImpl::AddInputMethodExtension(
436 const std::string& extension_id, 545 const std::string& extension_id,
437 const InputMethodDescriptors& descriptors, 546 const InputMethodDescriptors& descriptors,
438 InputMethodEngineInterface* engine) { 547 InputMethodEngineInterface* engine) {
439 if (state_ == STATE_TERMINATING) 548 if (ui_session_ == STATE_TERMINATING)
440 return; 549 return;
550 LOG(ERROR)
551 << "InputMethodManagerImpl::AddInputMethodExtension(): old state_: "
552 << state_->Dump();
441 553
442 DCHECK(engine); 554 DCHECK(engine);
555 DCHECK(state_);
443 556
444 engine_map_[extension_id] = engine; 557 state_->engine_map_[extension_id] = engine;
445 558
446 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID( 559 if (extension_id == extension_ime_util::GetExtensionIDFromInputMethodID(
447 current_input_method_.id())) { 560 state_->current_input_method_.id())) {
448 IMEBridge::Get()->SetCurrentEngineHandler(engine); 561 IMEBridge::Get()->SetCurrentEngineHandler(engine);
449 engine->Enable(extension_ime_util::GetComponentIDByInputMethodID( 562 engine->Enable(extension_ime_util::GetComponentIDByInputMethodID(
450 current_input_method_.id())); 563 state_->current_input_method_.id()));
451 } 564 }
452 565
453 bool contain = false; 566 bool contain = false;
454 for (size_t i = 0; i < descriptors.size(); i++) { 567 for (size_t i = 0; i < descriptors.size(); i++) {
455 const InputMethodDescriptor& descriptor = descriptors[i]; 568 const InputMethodDescriptor& descriptor = descriptors[i];
456 const std::string& id = descriptor.id(); 569 const std::string& id = descriptor.id();
457 extra_input_methods_[id] = descriptor; 570 extra_input_methods_[id] = descriptor;
458 if (Contains(enabled_extension_imes_, id)) { 571 if (Contains(enabled_extension_imes_, id)) {
459 if (!Contains(active_input_method_ids_, id)) { 572 if (!Contains(state_->active_input_method_ids_, id)) {
460 active_input_method_ids_.push_back(id); 573 state_->active_input_method_ids_.push_back(id);
574 LOG(ERROR)
575 << "InputMethodManagerImpl::AddInputMethodExtension(): new state_: "
576 << state_->Dump();
461 } else { 577 } else {
462 DVLOG(1) << "AddInputMethodExtension: already added: " << id << ", " 578 DVLOG(1) << "AddInputMethodExtension: already added: " << id << ", "
463 << descriptor.name(); 579 << descriptor.name();
464 } 580 }
465 contain = true; 581 contain = true;
466 } 582 }
467 } 583 }
468 584
469 // Ensure that the input method daemon is running. 585 // Ensure that the input method daemon is running.
470 if (contain) 586 if (contain)
471 MaybeInitializeCandidateWindowController(); 587 MaybeInitializeCandidateWindowController();
472 } 588 }
473 589
474 void InputMethodManagerImpl::RemoveInputMethodExtension( 590 void InputMethodManagerImpl::RemoveInputMethodExtension(
475 const std::string& extension_id) { 591 const std::string& extension_id) {
592 LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('"
593 << extension_id << "'): old state_: " << state_->Dump();
594
595 DCHECK(state_);
476 // Remove the active input methods with |extension_id|. 596 // Remove the active input methods with |extension_id|.
477 std::vector<std::string> new_active_input_method_ids; 597 std::vector<std::string> new_active_input_method_ids;
478 for (size_t i = 0; i < active_input_method_ids_.size(); ++i) { 598 for (size_t i = 0; i < state_->active_input_method_ids_.size(); ++i) {
479 if (extension_id != extension_ime_util::GetExtensionIDFromInputMethodID( 599 if (extension_id != extension_ime_util::GetExtensionIDFromInputMethodID(
480 active_input_method_ids_[i])) 600 state_->active_input_method_ids_[i]))
481 new_active_input_method_ids.push_back(active_input_method_ids_[i]); 601 new_active_input_method_ids.push_back(
602 state_->active_input_method_ids_[i]);
482 } 603 }
483 active_input_method_ids_.swap(new_active_input_method_ids); 604 state_->active_input_method_ids_.swap(new_active_input_method_ids);
484 605
485 // Remove the extra input methods with |extension_id|. 606 // Remove the extra input methods with |extension_id|.
486 std::map<std::string, InputMethodDescriptor> new_extra_input_methods; 607 std::map<std::string, InputMethodDescriptor> new_extra_input_methods;
487 for (std::map<std::string, InputMethodDescriptor>::iterator i = 608 for (std::map<std::string, InputMethodDescriptor>::iterator i =
488 extra_input_methods_.begin(); 609 extra_input_methods_.begin();
489 i != extra_input_methods_.end(); 610 i != extra_input_methods_.end();
490 ++i) { 611 ++i) {
491 if (extension_id != 612 if (extension_id !=
492 extension_ime_util::GetExtensionIDFromInputMethodID(i->first)) 613 extension_ime_util::GetExtensionIDFromInputMethodID(i->first))
493 new_extra_input_methods[i->first] = i->second; 614 new_extra_input_methods[i->first] = i->second;
494 } 615 }
495 extra_input_methods_.swap(new_extra_input_methods); 616 extra_input_methods_.swap(new_extra_input_methods);
496 617
497 if (IMEBridge::Get()->GetCurrentEngineHandler() == engine_map_[extension_id]) 618 if (IMEBridge::Get()->GetCurrentEngineHandler() ==
619 state_->engine_map_[extension_id])
498 IMEBridge::Get()->SetCurrentEngineHandler(NULL); 620 IMEBridge::Get()->SetCurrentEngineHandler(NULL);
499 engine_map_.erase(extension_id); 621 state_->engine_map_.erase(extension_id);
622 LOG(ERROR) << "InputMethodManagerImpl::RemoveInputMethodExtension('"
623 << extension_id << "'): new state_: " << state_->Dump();
500 624
501 // No need to switch input method when terminating. 625 // No need to switch input method when terminating.
502 if (state_ != STATE_TERMINATING) { 626 if (ui_session_ != STATE_TERMINATING) {
503 // If |current_input_method| is no longer in |active_input_method_ids_|, 627 // If |current_input_method| is no longer in |active_input_method_ids_|,
504 // switch to the first one in |active_input_method_ids_|. 628 // switch to the first one in |active_input_method_ids_|.
505 ChangeInputMethod(current_input_method_.id()); 629 ChangeInputMethod(state_->current_input_method_.id());
506 } 630 }
507 } 631 }
508 632
509 void InputMethodManagerImpl::GetInputMethodExtensions( 633 void InputMethodManagerImpl::GetInputMethodExtensions(
510 InputMethodDescriptors* result) { 634 InputMethodDescriptors* result) {
511 // Build the extension input method descriptors from the extra input 635 // Build the extension input method descriptors from the extra input
512 // methods cache |extra_input_methods_|. 636 // methods cache |extra_input_methods_|.
513 std::map<std::string, InputMethodDescriptor>::iterator iter; 637 std::map<std::string, InputMethodDescriptor>::iterator iter;
514 for (iter = extra_input_methods_.begin(); iter != extra_input_methods_.end(); 638 for (iter = extra_input_methods_.begin(); iter != extra_input_methods_.end();
515 ++iter) { 639 ++iter) {
516 if (extension_ime_util::IsExtensionIME(iter->first)) 640 if (extension_ime_util::IsExtensionIME(iter->first))
517 result->push_back(iter->second); 641 result->push_back(iter->second);
518 } 642 }
519 } 643 }
520 644
521 void InputMethodManagerImpl::SetEnabledExtensionImes( 645 void InputMethodManagerImpl::SetEnabledExtensionImes(
522 std::vector<std::string>* ids) { 646 std::vector<std::string>* ids) {
523 enabled_extension_imes_.clear(); 647 enabled_extension_imes_.clear();
524 enabled_extension_imes_.insert(enabled_extension_imes_.end(), 648 enabled_extension_imes_.insert(enabled_extension_imes_.end(),
525 ids->begin(), 649 ids->begin(),
526 ids->end()); 650 ids->end());
651 LOG(ERROR)
652 << "InputMethodManagerImpl::SetEnabledExtensionImes(): old state_: "
653 << state_->Dump();
527 654
528 bool active_imes_changed = false; 655 bool active_imes_changed = false;
529 656
530 for (std::map<std::string, InputMethodDescriptor>::iterator extra_iter = 657 for (std::map<std::string, InputMethodDescriptor>::iterator extra_iter =
531 extra_input_methods_.begin(); extra_iter != extra_input_methods_.end(); 658 extra_input_methods_.begin(); extra_iter != extra_input_methods_.end();
532 ++extra_iter) { 659 ++extra_iter) {
533 if (extension_ime_util::IsComponentExtensionIME( 660 if (extension_ime_util::IsComponentExtensionIME(
534 extra_iter->first)) 661 extra_iter->first))
535 continue; // Do not filter component extension. 662 continue; // Do not filter component extension.
536 std::vector<std::string>::iterator active_iter = std::find( 663 DCHECK(state_);
537 active_input_method_ids_.begin(), active_input_method_ids_.end(), 664 std::vector<std::string>::iterator active_iter =
538 extra_iter->first); 665 std::find(state_->active_input_method_ids_.begin(),
666 state_->active_input_method_ids_.end(),
667 extra_iter->first);
539 668
540 bool active = active_iter != active_input_method_ids_.end(); 669 bool active = active_iter != state_->active_input_method_ids_.end();
541 bool enabled = Contains(enabled_extension_imes_, extra_iter->first); 670 bool enabled = Contains(enabled_extension_imes_, extra_iter->first);
542 671
543 if (active && !enabled) 672 if (active && !enabled)
544 active_input_method_ids_.erase(active_iter); 673 state_->active_input_method_ids_.erase(active_iter);
545 674
546 if (!active && enabled) 675 if (!active && enabled)
547 active_input_method_ids_.push_back(extra_iter->first); 676 state_->active_input_method_ids_.push_back(extra_iter->first);
548 677
549 if (active == !enabled) 678 if (active == !enabled)
550 active_imes_changed = true; 679 active_imes_changed = true;
551 } 680 }
681 LOG(ERROR)
682 << "InputMethodManagerImpl::SetEnabledExtensionImes(): new state_: "
683 << state_->Dump();
552 684
553 if (active_imes_changed) { 685 if (active_imes_changed) {
554 MaybeInitializeCandidateWindowController(); 686 MaybeInitializeCandidateWindowController();
555 687
556 // If |current_input_method| is no longer in |active_input_method_ids_|, 688 // If |current_input_method| is no longer in |active_input_method_ids_|,
557 // switch to the first one in |active_input_method_ids_|. 689 // switch to the first one in |active_input_method_ids_|.
558 ChangeInputMethod(current_input_method_.id()); 690 ChangeInputMethod(state_->current_input_method_.id());
559 } 691 }
560 } 692 }
561 693
562 void InputMethodManagerImpl::SetInputMethodLoginDefaultFromVPD( 694 void InputMethodManagerImpl::SetInputMethodLoginDefaultFromVPD(
563 const std::string& locale, const std::string& oem_layout) { 695 const std::string& locale, const std::string& oem_layout) {
564 std::string layout; 696 std::string layout;
565 if (!oem_layout.empty()) { 697 if (!oem_layout.empty()) {
566 // If the OEM layout information is provided, use it. 698 // If the OEM layout information is provided, use it.
567 layout = oem_layout; 699 layout = oem_layout;
568 } else { 700 } else {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 input_methods_to_be_enabled = util_.GetHardwareLoginInputMethodIds(); 749 input_methods_to_be_enabled = util_.GetHardwareLoginInputMethodIds();
618 } else { 750 } else {
619 input_methods_to_be_enabled.push_back(initial_input_method_id); 751 input_methods_to_be_enabled.push_back(initial_input_method_id);
620 } 752 }
621 EnableLoginLayouts(locale, input_methods_to_be_enabled); 753 EnableLoginLayouts(locale, input_methods_to_be_enabled);
622 LoadNecessaryComponentExtensions(); 754 LoadNecessaryComponentExtensions();
623 } 755 }
624 } 756 }
625 757
626 bool InputMethodManagerImpl::SwitchToNextInputMethod() { 758 bool InputMethodManagerImpl::SwitchToNextInputMethod() {
759 DCHECK(state_);
627 // Sanity checks. 760 // Sanity checks.
628 if (active_input_method_ids_.empty()) { 761 if (state_->active_input_method_ids_.empty()) {
629 DVLOG(1) << "active input method is empty"; 762 DVLOG(1) << "active input method is empty";
630 return false; 763 return false;
631 } 764 }
632 765
633 if (current_input_method_.id().empty()) { 766 if (state_->current_input_method_.id().empty()) {
634 DVLOG(1) << "current_input_method_ is unknown"; 767 DVLOG(1) << "current_input_method_ is unknown";
635 return false; 768 return false;
636 } 769 }
637 770
638 // Do not consume key event if there is only one input method is enabled. 771 // Do not consume key event if there is only one input method is enabled.
639 // Ctrl+Space or Alt+Shift may be used by other application. 772 // Ctrl+Space or Alt+Shift may be used by other application.
640 if (active_input_method_ids_.size() == 1) 773 if (state_->active_input_method_ids_.size() == 1)
641 return false; 774 return false;
642 775
643 // Find the next input method and switch to it. 776 // Find the next input method and switch to it.
644 SwitchToNextInputMethodInternal(active_input_method_ids_, 777 SwitchToNextInputMethodInternal(state_->active_input_method_ids_,
645 current_input_method_.id()); 778 state_->current_input_method_.id());
646 return true; 779 return true;
647 } 780 }
648 781
649 bool InputMethodManagerImpl::SwitchToPreviousInputMethod( 782 bool InputMethodManagerImpl::SwitchToPreviousInputMethod(
650 const ui::Accelerator& accelerator) { 783 const ui::Accelerator& accelerator) {
784 DCHECK(state_);
651 // Sanity check. 785 // Sanity check.
652 if (active_input_method_ids_.empty()) { 786 if (state_->active_input_method_ids_.empty()) {
653 DVLOG(1) << "active input method is empty"; 787 DVLOG(1) << "active input method is empty";
654 return false; 788 return false;
655 } 789 }
656 790
657 // Do not consume key event if there is only one input method is enabled. 791 // Do not consume key event if there is only one input method is enabled.
658 // Ctrl+Space or Alt+Shift may be used by other application. 792 // Ctrl+Space or Alt+Shift may be used by other application.
659 if (active_input_method_ids_.size() == 1) 793 if (state_->active_input_method_ids_.size() == 1)
660 return false; 794 return false;
661 795
662 if (accelerator.type() == ui::ET_KEY_RELEASED) 796 if (accelerator.type() == ui::ET_KEY_RELEASED)
663 return true; 797 return true;
664 798
665 if (previous_input_method_.id().empty() || 799 if (state_->previous_input_method_.id().empty() ||
666 previous_input_method_.id() == current_input_method_.id()) { 800 state_->previous_input_method_.id() ==
801 state_->current_input_method_.id()) {
667 return SwitchToNextInputMethod(); 802 return SwitchToNextInputMethod();
668 } 803 }
669 804
670 std::vector<std::string>::const_iterator iter = 805 std::vector<std::string>::const_iterator iter =
671 std::find(active_input_method_ids_.begin(), 806 std::find(state_->active_input_method_ids_.begin(),
672 active_input_method_ids_.end(), 807 state_->active_input_method_ids_.end(),
673 previous_input_method_.id()); 808 state_->previous_input_method_.id());
674 if (iter == active_input_method_ids_.end()) { 809 if (iter == state_->active_input_method_ids_.end()) {
675 // previous_input_method_ is not supported. 810 // previous_input_method_ is not supported.
676 return SwitchToNextInputMethod(); 811 return SwitchToNextInputMethod();
677 } 812 }
678 ChangeInputMethodInternal(*iter, true); 813 LookupAndChangeInputMethodInternal(*iter, true);
679 return true; 814 return true;
680 } 815 }
681 816
682 bool InputMethodManagerImpl::SwitchInputMethod( 817 bool InputMethodManagerImpl::SwitchInputMethod(
683 const ui::Accelerator& accelerator) { 818 const ui::Accelerator& accelerator) {
819 DCHECK(state_);
684 // Sanity check. 820 // Sanity check.
685 if (active_input_method_ids_.empty()) { 821 if (state_->active_input_method_ids_.empty()) {
686 DVLOG(1) << "active input method is empty"; 822 DVLOG(1) << "active input method is empty";
687 return false; 823 return false;
688 } 824 }
689 825
690 // Get the list of input method ids for the |accelerator|. For example, get 826 // Get the list of input method ids for the |accelerator|. For example, get
691 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. 827 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR.
692 std::vector<std::string> input_method_ids_to_switch; 828 std::vector<std::string> input_method_ids_to_switch;
693 switch (accelerator.key_code()) { 829 switch (accelerator.key_code()) {
694 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard 830 case ui::VKEY_CONVERT: // Henkan key on JP106 keyboard
695 input_method_ids_to_switch.push_back( 831 input_method_ids_to_switch.push_back(
(...skipping 18 matching lines...) Expand all
714 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code(); 850 DVLOG(1) << "Unexpected VKEY: " << accelerator.key_code();
715 return false; 851 return false;
716 } 852 }
717 853
718 // Obtain the intersection of input_method_ids_to_switch and 854 // Obtain the intersection of input_method_ids_to_switch and
719 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is 855 // active_input_method_ids_. The order of IDs in active_input_method_ids_ is
720 // preserved. 856 // preserved.
721 std::vector<std::string> ids; 857 std::vector<std::string> ids;
722 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) { 858 for (size_t i = 0; i < input_method_ids_to_switch.size(); ++i) {
723 const std::string& id = input_method_ids_to_switch[i]; 859 const std::string& id = input_method_ids_to_switch[i];
724 if (Contains(active_input_method_ids_, id)) 860 if (Contains(state_->active_input_method_ids_, id))
725 ids.push_back(id); 861 ids.push_back(id);
726 } 862 }
727 if (ids.empty()) { 863 if (ids.empty()) {
728 // No input method for the accelerator is active. For example, we should 864 // No input method for the accelerator is active. For example, we should
729 // just ignore VKEY_HANGUL when mozc-hangul is not active. 865 // just ignore VKEY_HANGUL when mozc-hangul is not active.
730 return false; 866 return false;
731 } 867 }
732 868
733 SwitchToNextInputMethodInternal(ids, current_input_method_.id()); 869 SwitchToNextInputMethodInternal(ids, state_->current_input_method_.id());
734 return true; // consume the accelerator. 870 return true; // consume the accelerator.
735 } 871 }
736 872
737 void InputMethodManagerImpl::SwitchToNextInputMethodInternal( 873 void InputMethodManagerImpl::SwitchToNextInputMethodInternal(
738 const std::vector<std::string>& input_method_ids, 874 const std::vector<std::string>& input_method_ids,
739 const std::string& current_input_method_id) { 875 const std::string& current_input_method_id) {
740 std::vector<std::string>::const_iterator iter = 876 std::vector<std::string>::const_iterator iter =
741 std::find(input_method_ids.begin(), 877 std::find(input_method_ids.begin(),
742 input_method_ids.end(), 878 input_method_ids.end(),
743 current_input_method_id); 879 current_input_method_id);
744 if (iter != input_method_ids.end()) 880 if (iter != input_method_ids.end())
745 ++iter; 881 ++iter;
746 if (iter == input_method_ids.end()) 882 if (iter == input_method_ids.end())
747 iter = input_method_ids.begin(); 883 iter = input_method_ids.begin();
748 ChangeInputMethodInternal(*iter, true); 884 LookupAndChangeInputMethodInternal(*iter, true);
749 } 885 }
750 886
751 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const { 887 InputMethodDescriptor InputMethodManagerImpl::GetCurrentInputMethod() const {
752 if (current_input_method_.id().empty()) 888 DCHECK(state_);
889 if (state_->current_input_method_.id().empty())
753 return InputMethodUtil::GetFallbackInputMethodDescriptor(); 890 return InputMethodUtil::GetFallbackInputMethodDescriptor();
754 891
755 return current_input_method_; 892 return state_->current_input_method_;
756 } 893 }
757 894
758 bool InputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() const { 895 bool InputMethodManagerImpl::IsISOLevel5ShiftUsedByCurrentInputMethod() const {
759 return keyboard_->IsISOLevel5ShiftAvailable(); 896 return keyboard_->IsISOLevel5ShiftAvailable();
760 } 897 }
761 898
762 bool InputMethodManagerImpl::IsAltGrUsedByCurrentInputMethod() const { 899 bool InputMethodManagerImpl::IsAltGrUsedByCurrentInputMethod() const {
763 return keyboard_->IsAltGrAvailable(); 900 return keyboard_->IsAltGrAvailable();
764 } 901 }
765 902
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 CandidateWindowOpened(this)); 953 CandidateWindowOpened(this));
817 } 954 }
818 955
819 void InputMethodManagerImpl::CandidateWindowClosed() { 956 void InputMethodManagerImpl::CandidateWindowClosed() {
820 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver, 957 FOR_EACH_OBSERVER(InputMethodManager::CandidateWindowObserver,
821 candidate_window_observers_, 958 candidate_window_observers_,
822 CandidateWindowClosed(this)); 959 CandidateWindowClosed(this));
823 } 960 }
824 961
825 void InputMethodManagerImpl::OnScreenLocked() { 962 void InputMethodManagerImpl::OnScreenLocked() {
826 saved_previous_input_method_ = previous_input_method_; 963 DCHECK(state_);
827 saved_current_input_method_ = current_input_method_; 964 LOG(ERROR) << "InputMethodManagerImpl::OnScreenLocked(): old state_: "
828 saved_active_input_method_ids_ = active_input_method_ids_; 965 << state_->Dump();
966 state_->saved_previous_input_method_ = state_->previous_input_method_;
967 state_->saved_current_input_method_ = state_->current_input_method_;
968 state_->saved_active_input_method_ids_ = state_->active_input_method_ids_;
829 969
830 std::set<std::string> added_ids_; 970 std::set<std::string> added_ids_;
831 971
832 const std::vector<std::string>& hardware_keyboard_ids = 972 const std::vector<std::string>& hardware_keyboard_ids =
833 util_.GetHardwareLoginInputMethodIds(); 973 util_.GetHardwareLoginInputMethodIds();
834 974
835 active_input_method_ids_.clear(); 975 state_->active_input_method_ids_.clear();
836 for (size_t i = 0; i < saved_active_input_method_ids_.size(); ++i) { 976 for (size_t i = 0; i < state_->saved_active_input_method_ids_.size(); ++i) {
837 const std::string& input_method_id = saved_active_input_method_ids_[i]; 977 const std::string& input_method_id =
978 state_->saved_active_input_method_ids_[i];
838 // Skip if it's not a keyboard layout. Drop input methods including 979 // Skip if it's not a keyboard layout. Drop input methods including
839 // extension ones. 980 // extension ones.
840 if (!IsLoginKeyboard(input_method_id) || 981 if (!IsLoginKeyboard(input_method_id) ||
841 added_ids_.find(input_method_id) != added_ids_.end()) 982 added_ids_.find(input_method_id) != added_ids_.end())
842 continue; 983 continue;
843 active_input_method_ids_.push_back(input_method_id); 984 state_->active_input_method_ids_.push_back(input_method_id);
844 added_ids_.insert(input_method_id); 985 added_ids_.insert(input_method_id);
845 } 986 }
846 987
847 // We'll add the hardware keyboard if it's not included in 988 // We'll add the hardware keyboard if it's not included in
848 // |active_input_method_ids_| so that the user can always use the hardware 989 // |active_input_method_ids_| so that the user can always use the hardware
849 // keyboard on the screen locker. 990 // keyboard on the screen locker.
850 for (size_t i = 0; i < hardware_keyboard_ids.size(); ++i) { 991 for (size_t i = 0; i < hardware_keyboard_ids.size(); ++i) {
851 if (added_ids_.find(hardware_keyboard_ids[i]) == added_ids_.end()) { 992 if (added_ids_.find(hardware_keyboard_ids[i]) == added_ids_.end()) {
852 active_input_method_ids_.push_back(hardware_keyboard_ids[i]); 993 state_->active_input_method_ids_.push_back(hardware_keyboard_ids[i]);
853 added_ids_.insert(hardware_keyboard_ids[i]); 994 added_ids_.insert(hardware_keyboard_ids[i]);
854 } 995 }
855 } 996 }
856 997
857 ChangeInputMethod(current_input_method_.id()); 998 LOG(ERROR) << "InputMethodManagerImpl::OnScreenLocked(): new state_: "
999 << state_->Dump();
1000 ChangeInputMethod(state_->current_input_method_.id());
858 } 1001 }
859 1002
860 void InputMethodManagerImpl::OnScreenUnlocked() { 1003 void InputMethodManagerImpl::OnScreenUnlocked() {
861 previous_input_method_ = saved_previous_input_method_; 1004 LOG(ERROR) << "InputMethodManagerImpl::OnScreenUnLocked(): old state_: "
862 current_input_method_ = saved_current_input_method_; 1005 << state_->Dump();
863 active_input_method_ids_ = saved_active_input_method_ids_; 1006 state_->previous_input_method_ = state_->saved_previous_input_method_;
1007 state_->current_input_method_ = state_->saved_current_input_method_;
1008 state_->active_input_method_ids_ = state_->saved_active_input_method_ids_;
864 1009
865 ChangeInputMethod(current_input_method_.id()); 1010 LOG(ERROR) << "InputMethodManagerImpl::OnScreenUnLocked(): new state_: "
1011 << state_->Dump();
1012 ChangeInputMethod(state_->current_input_method_.id());
866 } 1013 }
867 1014
868 bool InputMethodManagerImpl::InputMethodIsActivated( 1015 bool InputMethodManagerImpl::InputMethodIsActivated(
869 const std::string& input_method_id) { 1016 const std::string& input_method_id) {
870 return Contains(active_input_method_ids_, input_method_id); 1017 DCHECK(state_);
1018 return Contains(state_->active_input_method_ids_, input_method_id);
871 } 1019 }
872 1020
873 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() { 1021 void InputMethodManagerImpl::MaybeInitializeCandidateWindowController() {
874 if (candidate_window_controller_.get()) 1022 if (candidate_window_controller_.get())
875 return; 1023 return;
876 1024
877 candidate_window_controller_.reset( 1025 candidate_window_controller_.reset(
878 CandidateWindowController::CreateCandidateWindowController()); 1026 CandidateWindowController::CreateCandidateWindowController());
879 candidate_window_controller_->AddObserver(this); 1027 candidate_window_controller_->AddObserver(this);
880 } 1028 }
881 1029
882 } // namespace input_method 1030 } // namespace input_method
883 } // namespace chromeos 1031 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698