Chromium Code Reviews| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 return; | 309 return; |
| 310 | 310 |
| 311 if (!InputMethodUtil::IsExtensionInputMethod(id)) { | 311 if (!InputMethodUtil::IsExtensionInputMethod(id)) { |
| 312 DVLOG(1) << id << " is not a valid extension input method ID."; | 312 DVLOG(1) << id << " is not a valid extension input method ID."; |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 | 315 |
| 316 const std::string layout = layouts.empty() ? "" : layouts[0]; | 316 const std::string layout = layouts.empty() ? "" : layouts[0]; |
| 317 extra_input_methods_[id] = | 317 extra_input_methods_[id] = |
| 318 InputMethodDescriptor(id, name, layout, language, true); | 318 InputMethodDescriptor(id, name, layout, language, true); |
| 319 if (!Contains(filtered_extension_imes_, id)) { | |
| 320 if (!Contains(active_input_method_ids_, id)) { | |
| 321 active_input_method_ids_.push_back(id); | |
| 322 } else { | |
| 323 DVLOG(1) << "AddInputMethodExtension: alread added: " | |
| 324 << id << ", " << name; | |
| 325 // Call Start() anyway, just in case. | |
| 326 } | |
| 319 | 327 |
| 320 if (!Contains(active_input_method_ids_, id)) { | 328 // Ensure that the input method daemon is running. |
| 321 active_input_method_ids_.push_back(id); | 329 MaybeInitializeCandidateWindowController(); |
| 322 } else { | 330 ibus_controller_->Start(); |
| 323 DVLOG(1) << "AddInputMethodExtension: alread added: " | |
| 324 << id << ", " << name; | |
| 325 // Call Start() anyway, just in case. | |
| 326 } | 331 } |
| 327 | 332 |
| 328 // Ensure that the input method daemon is running. | |
| 329 MaybeInitializeCandidateWindowController(); | |
| 330 ibus_controller_->Start(); | |
| 331 | |
| 332 extra_input_method_instances_[id] = | 333 extra_input_method_instances_[id] = |
| 333 static_cast<InputMethodEngineIBus*>(engine); | 334 static_cast<InputMethodEngineIBus*>(engine); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { | 337 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { |
| 337 if (!InputMethodUtil::IsExtensionInputMethod(id)) | 338 if (!InputMethodUtil::IsExtensionInputMethod(id)) |
| 338 DVLOG(1) << id << " is not a valid extension input method ID."; | 339 DVLOG(1) << id << " is not a valid extension input method ID."; |
| 339 | 340 |
| 340 std::vector<std::string>::iterator i = std::find( | 341 std::vector<std::string>::iterator i = std::find( |
| 341 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); | 342 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 358 extra_input_method_instances_.find(id); | 359 extra_input_method_instances_.find(id); |
| 359 if (ite == extra_input_method_instances_.end()) { | 360 if (ite == extra_input_method_instances_.end()) { |
| 360 DVLOG(1) << "The engine instance of " << id << " has already gone."; | 361 DVLOG(1) << "The engine instance of " << id << " has already gone."; |
| 361 } else { | 362 } else { |
| 362 // Do NOT release the actual instance here. This class does not take an | 363 // Do NOT release the actual instance here. This class does not take an |
| 363 // onwership of engine instance. | 364 // onwership of engine instance. |
| 364 extra_input_method_instances_.erase(ite); | 365 extra_input_method_instances_.erase(ite); |
| 365 } | 366 } |
| 366 } | 367 } |
| 367 | 368 |
| 369 InputMethodDescriptors* InputMethodManagerImpl::GetInputMethodExtensions() { | |
| 370 InputMethodDescriptors* result = new InputMethodDescriptors; | |
|
Seigo Nonaka
2012/09/12 16:50:37
Caller takes ownership of returned value?
Please l
Zachary Kuznia
2012/09/13 09:28:32
Done.
| |
| 371 // Build the extension input method descriptors from the extra input | |
| 372 // methods cache |extra_input_methods_|. | |
| 373 std::map<std::string, InputMethodDescriptor>::iterator iter; | |
| 374 for (iter = extra_input_methods_.begin(); iter != extra_input_methods_.end(); | |
| 375 ++iter) { | |
| 376 result->push_back(iter->second); | |
| 377 } | |
| 378 return result; | |
| 379 } | |
| 380 | |
| 381 void InputMethodManagerImpl::SetFilteredExtensionImes( | |
| 382 std::vector<std::string>& ids) { | |
| 383 | |
| 384 filtered_extension_imes_.insert(filtered_extension_imes_.end(), | |
| 385 ids.begin(), | |
| 386 ids.end()); | |
| 387 | |
| 388 bool active_imes_changed = false; | |
| 389 | |
| 390 for (std::map<std::string, InputMethodDescriptor>::iterator extra_iter = | |
| 391 extra_input_methods_.begin(); extra_iter != extra_input_methods_.end(); | |
| 392 ++extra_iter) { | |
| 393 std::vector<std::string>::iterator active_iter = std::find( | |
| 394 active_input_method_ids_.begin(), active_input_method_ids_.end(), | |
| 395 extra_iter->first); | |
| 396 | |
| 397 bool active = active_iter != active_input_method_ids_.end(); | |
| 398 bool filtered = Contains(filtered_extension_imes_, extra_iter->first); | |
| 399 | |
| 400 if (active && filtered) | |
| 401 active_input_method_ids_.erase(active_iter); | |
| 402 | |
| 403 if (!active && !filtered) | |
| 404 active_input_method_ids_.push_back(extra_iter->first); | |
| 405 | |
| 406 if (active == filtered) | |
| 407 active_imes_changed = true; | |
| 408 } | |
| 409 | |
| 410 if (active_imes_changed) { | |
| 411 MaybeInitializeCandidateWindowController(); | |
| 412 ibus_controller_->Start(); | |
| 413 | |
| 414 // If |current_input_method| is no longer in |active_input_method_ids_|, | |
| 415 // switch to the first one in |active_input_method_ids_|. | |
| 416 ChangeInputMethod(current_input_method_.id()); | |
| 417 } | |
| 418 } | |
| 419 | |
| 368 bool InputMethodManagerImpl::SwitchToNextInputMethod() { | 420 bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
| 369 // Sanity checks. | 421 // Sanity checks. |
| 370 if (active_input_method_ids_.empty()) { | 422 if (active_input_method_ids_.empty()) { |
| 371 DVLOG(1) << "active input method is empty"; | 423 DVLOG(1) << "active input method is empty"; |
| 372 return false; | 424 return false; |
| 373 } | 425 } |
| 374 if (current_input_method_.id().empty()) { | 426 if (current_input_method_.id().empty()) { |
| 375 DVLOG(1) << "current_input_method_ is unknown"; | 427 DVLOG(1) << "current_input_method_ is unknown"; |
| 376 return false; | 428 return false; |
| 377 } | 429 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 | 548 |
| 497 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { | 549 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { |
| 498 return &util_; | 550 return &util_; |
| 499 } | 551 } |
| 500 | 552 |
| 501 void InputMethodManagerImpl::OnConnected() { | 553 void InputMethodManagerImpl::OnConnected() { |
| 502 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = | 554 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 503 extra_input_method_instances_.begin(); | 555 extra_input_method_instances_.begin(); |
| 504 ite != extra_input_method_instances_.end(); | 556 ite != extra_input_method_instances_.end(); |
| 505 ite++) { | 557 ite++) { |
| 506 ite->second->OnConnected(); | 558 if (!Contains(filtered_extension_imes_, ite->first)) |
| 559 ite->second->OnConnected(); | |
| 507 } | 560 } |
| 508 } | 561 } |
| 509 | 562 |
| 510 void InputMethodManagerImpl::OnDisconnected() { | 563 void InputMethodManagerImpl::OnDisconnected() { |
| 511 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = | 564 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 512 extra_input_method_instances_.begin(); | 565 extra_input_method_instances_.begin(); |
| 513 ite != extra_input_method_instances_.end(); | 566 ite != extra_input_method_instances_.end(); |
| 514 ite++) { | 567 ite++) { |
| 515 ite->second->OnDisconnected(); | 568 if (!Contains(filtered_extension_imes_, ite->first)) |
| 569 ite->second->OnDisconnected(); | |
| 516 } | 570 } |
| 517 } | 571 } |
| 518 | 572 |
| 519 void InputMethodManagerImpl::Init() { | 573 void InputMethodManagerImpl::Init() { |
| 520 DCHECK(!ibus_controller_.get()); | 574 DCHECK(!ibus_controller_.get()); |
| 521 | 575 |
| 522 browser_state_monitor_.reset(new BrowserStateMonitor(this)); | 576 browser_state_monitor_.reset(new BrowserStateMonitor(this)); |
| 523 ibus_controller_.reset(IBusController::Create()); | 577 ibus_controller_.reset(IBusController::Create()); |
| 524 xkeyboard_.reset(XKeyboard::Create(util_)); | 578 xkeyboard_.reset(XKeyboard::Create(util_)); |
| 525 ibus_controller_->AddObserver(this); | 579 ibus_controller_->AddObserver(this); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 DVLOG(1) << "Failed to initialize the candidate window controller"; | 676 DVLOG(1) << "Failed to initialize the candidate window controller"; |
| 623 } | 677 } |
| 624 | 678 |
| 625 // static | 679 // static |
| 626 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { | 680 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { |
| 627 return new InputMethodManagerImpl; | 681 return new InputMethodManagerImpl; |
| 628 } | 682 } |
| 629 | 683 |
| 630 } // namespace input_method | 684 } // namespace input_method |
| 631 } // namespace chromeos | 685 } // namespace chromeos |
| OLD | NEW |