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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" | 13 #include "chrome/browser/chromeos/input_method/browser_state_monitor.h" |
14 #include "chrome/browser/chromeos/input_method/candidate_window.h" | 14 #include "chrome/browser/chromeos/input_method/candidate_window.h" |
| 15 #include "chrome/browser/chromeos/input_method/input_method_engine_ibus.h" |
15 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 16 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
16 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 17 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
17 #include "chrome/browser/chromeos/language_preferences.h" | 18 #include "chrome/browser/chromeos/language_preferences.h" |
18 #include "ui/base/accelerators/accelerator.h" | 19 #include "ui/base/accelerators/accelerator.h" |
19 #include "unicode/uloc.h" | 20 #include "unicode/uloc.h" |
20 | 21 |
21 namespace chromeos { | 22 namespace chromeos { |
22 namespace input_method { | 23 namespace input_method { |
23 | 24 |
24 namespace { | 25 namespace { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 void InputMethodManagerImpl::ActivateInputMethodProperty( | 286 void InputMethodManagerImpl::ActivateInputMethodProperty( |
286 const std::string& key) { | 287 const std::string& key) { |
287 DCHECK(!key.empty()); | 288 DCHECK(!key.empty()); |
288 ibus_controller_->ActivateInputMethodProperty(key); | 289 ibus_controller_->ActivateInputMethodProperty(key); |
289 } | 290 } |
290 | 291 |
291 void InputMethodManagerImpl::AddInputMethodExtension( | 292 void InputMethodManagerImpl::AddInputMethodExtension( |
292 const std::string& id, | 293 const std::string& id, |
293 const std::string& name, | 294 const std::string& name, |
294 const std::vector<std::string>& layouts, | 295 const std::vector<std::string>& layouts, |
295 const std::string& language) { | 296 const std::string& language, |
| 297 InputMethodEngine* engine) { |
296 if (state_ == STATE_TERMINATING) | 298 if (state_ == STATE_TERMINATING) |
297 return; | 299 return; |
298 | 300 |
299 if (!InputMethodUtil::IsExtensionInputMethod(id)) { | 301 if (!InputMethodUtil::IsExtensionInputMethod(id)) { |
300 DVLOG(1) << id << " is not a valid extension input method ID."; | 302 DVLOG(1) << id << " is not a valid extension input method ID."; |
301 return; | 303 return; |
302 } | 304 } |
303 | 305 |
304 const std::string layout = layouts.empty() ? "" : layouts[0]; | 306 const std::string layout = layouts.empty() ? "" : layouts[0]; |
305 extra_input_methods_[id] = | 307 extra_input_methods_[id] = |
306 InputMethodDescriptor(id, name, layout, language, true); | 308 InputMethodDescriptor(id, name, layout, language, true); |
307 | 309 |
308 if (!Contains(active_input_method_ids_, id)) { | 310 if (!Contains(active_input_method_ids_, id)) { |
309 active_input_method_ids_.push_back(id); | 311 active_input_method_ids_.push_back(id); |
310 } else { | 312 } else { |
311 DVLOG(1) << "AddInputMethodExtension: alread added: " | 313 DVLOG(1) << "AddInputMethodExtension: alread added: " |
312 << id << ", " << name; | 314 << id << ", " << name; |
313 // Call Start() anyway, just in case. | 315 // Call Start() anyway, just in case. |
314 } | 316 } |
315 | 317 |
316 // Ensure that the input method daemon is running. | 318 // Ensure that the input method daemon is running. |
317 MaybeInitializeCandidateWindowController(); | 319 MaybeInitializeCandidateWindowController(); |
318 ibus_controller_->Start(); | 320 ibus_controller_->Start(); |
| 321 |
| 322 extra_input_method_instances_[id] = |
| 323 static_cast<InputMethodEngineIBus*>(engine); |
319 } | 324 } |
320 | 325 |
321 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { | 326 void InputMethodManagerImpl::RemoveInputMethodExtension(const std::string& id) { |
322 if (!InputMethodUtil::IsExtensionInputMethod(id)) | 327 if (!InputMethodUtil::IsExtensionInputMethod(id)) |
323 DVLOG(1) << id << " is not a valid extension input method ID."; | 328 DVLOG(1) << id << " is not a valid extension input method ID."; |
324 | 329 |
325 std::vector<std::string>::iterator i = std::find( | 330 std::vector<std::string>::iterator i = std::find( |
326 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); | 331 active_input_method_ids_.begin(), active_input_method_ids_.end(), id); |
327 if (i != active_input_method_ids_.end()) | 332 if (i != active_input_method_ids_.end()) |
328 active_input_method_ids_.erase(i); | 333 active_input_method_ids_.erase(i); |
329 extra_input_methods_.erase(id); | 334 extra_input_methods_.erase(id); |
330 | 335 |
331 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { | 336 if (ContainOnlyKeyboardLayout(active_input_method_ids_)) { |
332 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue | 337 // Do NOT call ibus_controller_->Stop(); here to work around a crash issue |
333 // at crosbug.com/27051. | 338 // at crosbug.com/27051. |
334 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 | 339 // TODO(yusukes): We can safely call Stop(); here once crosbug.com/26443 |
335 // is implemented. | 340 // is implemented. |
336 } | 341 } |
337 | 342 |
338 // If |current_input_method| is no longer in |active_input_method_ids_|, | 343 // If |current_input_method| is no longer in |active_input_method_ids_|, |
339 // switch to the first one in |active_input_method_ids_|. | 344 // switch to the first one in |active_input_method_ids_|. |
340 ChangeInputMethod(current_input_method_.id()); | 345 ChangeInputMethod(current_input_method_.id()); |
| 346 |
| 347 std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 348 extra_input_method_instances_.find(id); |
| 349 if (ite == extra_input_method_instances_.end()) { |
| 350 DVLOG(1) << "The engine instance of " << id << " has already gone."; |
| 351 } else { |
| 352 // Do NOT release the actual instance here. This class does not take an |
| 353 // onwership of engine instance. |
| 354 extra_input_method_instances_.erase(ite); |
| 355 } |
341 } | 356 } |
342 | 357 |
343 bool InputMethodManagerImpl::SwitchToNextInputMethod() { | 358 bool InputMethodManagerImpl::SwitchToNextInputMethod() { |
344 // Sanity checks. | 359 // Sanity checks. |
345 if (active_input_method_ids_.empty()) { | 360 if (active_input_method_ids_.empty()) { |
346 DVLOG(1) << "active input method is empty"; | 361 DVLOG(1) << "active input method is empty"; |
347 return false; | 362 return false; |
348 } | 363 } |
349 if (current_input_method_.id().empty()) { | 364 if (current_input_method_.id().empty()) { |
350 DVLOG(1) << "current_input_method_ is unknown"; | 365 DVLOG(1) << "current_input_method_ is unknown"; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 481 } |
467 | 482 |
468 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { | 483 XKeyboard* InputMethodManagerImpl::GetXKeyboard() { |
469 return xkeyboard_.get(); | 484 return xkeyboard_.get(); |
470 } | 485 } |
471 | 486 |
472 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { | 487 InputMethodUtil* InputMethodManagerImpl::GetInputMethodUtil() { |
473 return &util_; | 488 return &util_; |
474 } | 489 } |
475 | 490 |
| 491 void InputMethodManagerImpl::OnConnected() { |
| 492 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 493 extra_input_method_instances_.begin(); |
| 494 ite != extra_input_method_instances_.end(); |
| 495 ite++) { |
| 496 ite->second->OnConnected(); |
| 497 } |
| 498 } |
| 499 |
| 500 void InputMethodManagerImpl::OnDisconnected() { |
| 501 for (std::map<std::string, InputMethodEngineIBus*>::iterator ite = |
| 502 extra_input_method_instances_.begin(); |
| 503 ite != extra_input_method_instances_.end(); |
| 504 ite++) { |
| 505 ite->second->OnDisconnected(); |
| 506 } |
| 507 } |
| 508 |
476 void InputMethodManagerImpl::Init() { | 509 void InputMethodManagerImpl::Init() { |
477 DCHECK(!ibus_controller_.get()); | 510 DCHECK(!ibus_controller_.get()); |
478 | 511 |
479 browser_state_monitor_.reset(new BrowserStateMonitor(this)); | 512 browser_state_monitor_.reset(new BrowserStateMonitor(this)); |
480 ibus_controller_.reset(IBusController::Create()); | 513 ibus_controller_.reset(IBusController::Create()); |
481 xkeyboard_.reset(XKeyboard::Create(util_)); | 514 xkeyboard_.reset(XKeyboard::Create(util_)); |
482 ibus_controller_->AddObserver(this); | 515 ibus_controller_->AddObserver(this); |
483 } | 516 } |
484 | 517 |
485 void InputMethodManagerImpl::SetIBusControllerForTesting( | 518 void InputMethodManagerImpl::SetIBusControllerForTesting( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 DVLOG(1) << "Failed to initialize the candidate window controller"; | 612 DVLOG(1) << "Failed to initialize the candidate window controller"; |
580 } | 613 } |
581 | 614 |
582 // static | 615 // static |
583 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { | 616 InputMethodManagerImpl* InputMethodManagerImpl::GetInstanceForTesting() { |
584 return new InputMethodManagerImpl; | 617 return new InputMethodManagerImpl; |
585 } | 618 } |
586 | 619 |
587 } // namespace input_method | 620 } // namespace input_method |
588 } // namespace chromeos | 621 } // namespace chromeos |
OLD | NEW |