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

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

Issue 10907196: Add the ability to filter out extension IMEs from the language settings page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mock input manager Created 8 years, 3 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 | Annotate | Revision Log
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 "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
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
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 void InputMethodManagerImpl::GetInputMethodExtensions(
370 InputMethodDescriptors* result) {
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 }
379
380 void InputMethodManagerImpl::SetFilteredExtensionImes(
381 std::vector<std::string>* ids) {
382 filtered_extension_imes_.clear();
383 filtered_extension_imes_.insert(filtered_extension_imes_.end(),
384 ids->begin(),
385 ids->end());
386
387 bool active_imes_changed = false;
388
389 for (std::map<std::string, InputMethodDescriptor>::iterator extra_iter =
390 extra_input_methods_.begin(); extra_iter != extra_input_methods_.end();
391 ++extra_iter) {
392 std::vector<std::string>::iterator active_iter = std::find(
393 active_input_method_ids_.begin(), active_input_method_ids_.end(),
394 extra_iter->first);
395
396 bool active = active_iter != active_input_method_ids_.end();
397 bool filtered = Contains(filtered_extension_imes_, extra_iter->first);
398
399 if (active && filtered)
400 active_input_method_ids_.erase(active_iter);
401
402 if (!active && !filtered)
403 active_input_method_ids_.push_back(extra_iter->first);
404
405 if (active == filtered)
406 active_imes_changed = true;
407 }
408
409 if (active_imes_changed) {
410 MaybeInitializeCandidateWindowController();
411 ibus_controller_->Start();
412
413 // If |current_input_method| is no longer in |active_input_method_ids_|,
414 // switch to the first one in |active_input_method_ids_|.
415 ChangeInputMethod(current_input_method_.id());
416 }
417 }
418
368 bool InputMethodManagerImpl::SwitchToNextInputMethod() { 419 bool InputMethodManagerImpl::SwitchToNextInputMethod() {
369 // Sanity checks. 420 // Sanity checks.
370 if (active_input_method_ids_.empty()) { 421 if (active_input_method_ids_.empty()) {
371 DVLOG(1) << "active input method is empty"; 422 DVLOG(1) << "active input method is empty";
372 return false; 423 return false;
373 } 424 }
374 if (current_input_method_.id().empty()) { 425 if (current_input_method_.id().empty()) {
375 DVLOG(1) << "current_input_method_ is unknown"; 426 DVLOG(1) << "current_input_method_ is unknown";
376 return false; 427 return false;
377 } 428 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 547
497 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { 548 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() {
498 return &util_; 549 return &util_;
499 } 550 }
500 551
501 void InputMethodManagerImpl::OnConnected() { 552 void InputMethodManagerImpl::OnConnected() {
502 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = 553 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite =
503 extra_input_method_instances_.begin(); 554 extra_input_method_instances_.begin();
504 ite != extra_input_method_instances_.end(); 555 ite != extra_input_method_instances_.end();
505 ite++) { 556 ite++) {
506 ite->second->OnConnected(); 557 if (!Contains(filtered_extension_imes_, ite->first))
558 ite->second->OnConnected();
507 } 559 }
508 } 560 }
509 561
510 void InputMethodManagerImpl::OnDisconnected() { 562 void InputMethodManagerImpl::OnDisconnected() {
511 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = 563 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite =
512 extra_input_method_instances_.begin(); 564 extra_input_method_instances_.begin();
513 ite != extra_input_method_instances_.end(); 565 ite != extra_input_method_instances_.end();
514 ite++) { 566 ite++) {
515 ite->second->OnDisconnected(); 567 if (!Contains(filtered_extension_imes_, ite->first))
568 ite->second->OnDisconnected();
516 } 569 }
517 } 570 }
518 571
519 void InputMethodManagerImpl::Init() { 572 void InputMethodManagerImpl::Init() {
520 DCHECK(!ibus_controller_.get()); 573 DCHECK(!ibus_controller_.get());
521 574
522 browser_state_monitor_.reset(new BrowserStateMonitor(this)); 575 browser_state_monitor_.reset(new BrowserStateMonitor(this));
523 ibus_controller_.reset(IBusController::Create()); 576 ibus_controller_.reset(IBusController::Create());
524 xkeyboard_.reset(XKeyboard::Create(util_)); 577 xkeyboard_.reset(XKeyboard::Create(util_));
525 ibus_controller_->AddObserver(this); 578 ibus_controller_->AddObserver(this);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 DVLOG(1) << "Failed to initialize the candidate window controller"; 675 DVLOG(1) << "Failed to initialize the candidate window controller";
623 } 676 }
624 677
625 // static 678 // static
626 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { 679 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() {
627 return new InputMethodManagerImpl; 680 return new InputMethodManagerImpl;
628 } 681 }
629 682
630 } // namespace input_method 683 } // namespace input_method
631 } // namespace chromeos 684 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698