OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" | 5 #include "chrome/browser/chromeos/input_method/input_method_manager_impl.h" |
6 | 6 |
7 #include <algorithm> // std::find | 7 #include <algorithm> // std::find |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 bool Contains(const std::vector<std::string>& container, | 26 bool Contains(const std::vector<std::string>& container, |
27 const std::string& value) { | 27 const std::string& value) { |
28 return std::find(container.begin(), container.end(), value) != | 28 return std::find(container.begin(), container.end(), value) != |
29 container.end(); | 29 container.end(); |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 InputMethodManagerImpl::InputMethodManagerImpl() | 34 InputMethodManagerImpl::InputMethodManagerImpl() |
35 : ignore_hotkeys_(false), | 35 : state_(STATE_LOGIN_SCREEN), |
36 state_(STATE_LOGIN_SCREEN), | |
37 util_(GetSupportedInputMethods()) { | 36 util_(GetSupportedInputMethods()) { |
38 } | 37 } |
39 | 38 |
40 InputMethodManagerImpl::~InputMethodManagerImpl() { | 39 InputMethodManagerImpl::~InputMethodManagerImpl() { |
41 if (ibus_controller_.get()) | 40 if (ibus_controller_.get()) |
42 ibus_controller_->RemoveObserver(this); | 41 ibus_controller_->RemoveObserver(this); |
43 if (candidate_window_controller_.get()) | 42 if (candidate_window_controller_.get()) |
44 candidate_window_controller_->RemoveObserver(this); | 43 candidate_window_controller_->RemoveObserver(this); |
45 } | 44 } |
46 | 45 |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // at crosbug.com/27051. | 333 // at crosbug.com/27051. |
335 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 | 334 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 |
336 // is implemented. | 335 // is implemented. |
337 } | 336 } |
338 | 337 |
339 // If |current_input_method| is no longer in |active_input_method_ids_|, | 338 // If |current_input_method| is no longer in |active_input_method_ids_|, |
340 // switch to the first one in |active_input_method_ids_|. | 339 // switch to the first one in |active_input_method_ids_|. |
341 ChangeInputMethod(current_input_method_.id()); | 340 ChangeInputMethod(current_input_method_.id()); |
342 } | 341 } |
343 | 342 |
344 void InputMethodManagerImpl::EnableHotkeys() { | |
345 ignore_hotkeys_ = false; | |
346 } | |
347 | |
348 void InputMethodManagerImpl::DisableHotkeys() { | |
349 ignore_hotkeys_ = true; | |
350 } | |
351 | |
352 bool InputMethodManagerImpl::SwitchToNextInputMethod() { | 343 bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
353 if (ignore_hotkeys_) | |
354 return false; | |
355 | |
356 // Sanity checks. | 344 // Sanity checks. |
357 if (active_input_method_ids_.empty()) { | 345 if (active_input_method_ids_.empty()) { |
358 DVLOG(1) << "active input method is empty"; | 346 DVLOG(1) << "active input method is empty"; |
359 return false; | 347 return false; |
360 } | 348 } |
361 if (current_input_method_.id().empty()) { | 349 if (current_input_method_.id().empty()) { |
362 DVLOG(1) << "current_input_method_ is unknown"; | 350 DVLOG(1) << "current_input_method_ is unknown"; |
363 return false; | 351 return false; |
364 } | 352 } |
365 | 353 |
366 // Find the next input method and switch to it. | 354 // Find the next input method and switch to it. |
367 SwitchToNextInputMethodInternal(active_input_method_ids_, | 355 SwitchToNextInputMethodInternal(active_input_method_ids_, |
368 current_input_method_.id()); | 356 current_input_method_.id()); |
369 return true; | 357 return true; |
370 } | 358 } |
371 | 359 |
372 bool InputMethodManagerImpl::SwitchToPreviousInputMethod() { | 360 bool InputMethodManagerImpl::SwitchToPreviousInputMethod() { |
373 if (ignore_hotkeys_) | |
374 return false; | |
375 | |
376 // Sanity check. | 361 // Sanity check. |
377 if (active_input_method_ids_.empty()) { | 362 if (active_input_method_ids_.empty()) { |
378 DVLOG(1) << "active input method is empty"; | 363 DVLOG(1) << "active input method is empty"; |
379 return false; | 364 return false; |
380 } | 365 } |
381 | 366 |
382 if (previous_input_method_.id().empty() || | 367 if (previous_input_method_.id().empty() || |
383 previous_input_method_.id() == current_input_method_.id()) { | 368 previous_input_method_.id() == current_input_method_.id()) { |
384 return SwitchToNextInputMethod(); | 369 return SwitchToNextInputMethod(); |
385 } | 370 } |
386 | 371 |
387 std::vector<std::string>::const_iterator iter = | 372 std::vector<std::string>::const_iterator iter = |
388 std::find(active_input_method_ids_.begin(), | 373 std::find(active_input_method_ids_.begin(), |
389 active_input_method_ids_.end(), | 374 active_input_method_ids_.end(), |
390 previous_input_method_.id()); | 375 previous_input_method_.id()); |
391 if (iter == active_input_method_ids_.end()) { | 376 if (iter == active_input_method_ids_.end()) { |
392 // previous_input_method_ is not supported. | 377 // previous_input_method_ is not supported. |
393 return SwitchToNextInputMethod(); | 378 return SwitchToNextInputMethod(); |
394 } | 379 } |
395 ChangeInputMethodInternal(*iter, true); | 380 ChangeInputMethodInternal(*iter, true); |
396 return true; | 381 return true; |
397 } | 382 } |
398 | 383 |
399 bool InputMethodManagerImpl::SwitchInputMethod( | 384 bool InputMethodManagerImpl::SwitchInputMethod( |
400 const ui::Accelerator& accelerator) { | 385 const ui::Accelerator& accelerator) { |
401 if (ignore_hotkeys_) | |
402 return false; | |
403 | |
404 // Sanity check. | 386 // Sanity check. |
405 if (active_input_method_ids_.empty()) { | 387 if (active_input_method_ids_.empty()) { |
406 DVLOG(1) << "active input method is empty"; | 388 DVLOG(1) << "active input method is empty"; |
407 return false; | 389 return false; |
408 } | 390 } |
409 | 391 |
410 // Get the list of input method ids for the |accelerator|. For example, get | 392 // Get the list of input method ids for the |accelerator|. For example, get |
411 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. | 393 // { "mozc-hangul", "xkb:kr:kr104:kor" } for ui::VKEY_DBE_SBCSCHAR. |
412 std::vector<std::string> input_method_ids_to_switch; | 394 std::vector<std::string> input_method_ids_to_switch; |
413 switch (accelerator.key_code()) { | 395 switch (accelerator.key_code()) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 DVLOG(1) << "Failed to initialize the candidate window controller"; | 579 DVLOG(1) << "Failed to initialize the candidate window controller"; |
598 } | 580 } |
599 | 581 |
600 // static | 582 // static |
601 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { | 583 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { |
602 return new InputMethodManagerImpl; | 584 return new InputMethodManagerImpl; |
603 } | 585 } |
604 | 586 |
605 } // namespace input_method | 587 } // namespace input_method |
606 } // namespace chromeos | 588 } // namespace chromeos |
OLD | NEW |