input_method_manager_impl.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 3// found in the LICENSE file. 4 5#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 6#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 7 8#include <map> 9#include <string> 10#include <vector> 11 12#include "base/memory/scoped_ptr.h" 13#include "base/observer_list.h" 14#include "chrome/browser/chromeos/input_method/candidate_window_controller.h" 15#include "chrome/browser/chromeos/input_method/ibus_controller.h" 16#include "chrome/browser/chromeos/input_method/input_method_manager.h" 17#include "chrome/browser/chromeos/input_method/input_method_util.h" 18#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" 19#include "chromeos/ime/ibus_daemon_controller.h" 20 21namespace chromeos { 22class InputMethodEngineIBus; 23namespace input_method { 24class InputMethodDelegate; 25class XKeyboard; 26 27// The implementation of InputMethodManager. 28class InputMethodManagerImpl : public InputMethodManager, 29 public CandidateWindowController::Observer, 30 public IBusController::Observer, 31 public IBusDaemonController::Observer { 32 public: 33 // Constructs an InputMethodManager instance. The client is responsible for 34 // calling |SetState| in response to relevant changes in browser state. 35 explicit InputMethodManagerImpl(scoped_ptr<InputMethodDelegate> delegate); 36 virtual ~InputMethodManagerImpl(); 37 38 // Attach IBusController, CandidateWindowController, and XKeyboard objects 39 // to the InputMethodManagerImpl object. You don't have to call this function 40 // if you attach them yourself (e.g. in unit tests) using the protected 41 // setters. 42 void Init(); 43 44 // Receives notification of an InputMethodManager::State transition. 45 void SetState(State new_state); 46 47 // InputMethodManager override: 48 virtual void AddObserver(InputMethodManager::Observer* observer) OVERRIDE; 49 virtual void AddCandidateWindowObserver( 50 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 51 virtual void RemoveObserver(InputMethodManager::Observer* observer) OVERRIDE; 52 virtual void RemoveCandidateWindowObserver( 53 InputMethodManager::CandidateWindowObserver* observer) OVERRIDE; 54 virtual scoped_ptr<InputMethodDescriptors> 55 GetSupportedInputMethods() const OVERRIDE; 56 virtual scoped_ptr<InputMethodDescriptors> 57 GetActiveInputMethods() const OVERRIDE; 58 virtual size_t GetNumActiveInputMethods() const OVERRIDE; 59 virtual void EnableLayouts(const std::string& language_code, 60 const std::string& initial_layout) OVERRIDE; 61 virtual bool EnableInputMethods( 62 const std::vector<std::string>& new_active_input_method_ids) OVERRIDE; 63 virtual bool SetInputMethodConfig( 64 const std::string& section, 65 const std::string& config_name, 66 const InputMethodConfigValue& value) OVERRIDE; 67 virtual void ChangeInputMethod(const std::string& input_method_id) OVERRIDE; 68 virtual void ActivateInputMethodProperty(const std::string& key) OVERRIDE; 69 virtual void AddInputMethodExtension( 70 const std::string& id, 71 const std::string& name, 72 const std::vector<std::string>& layouts, 73 const std::string& language, 74 InputMethodEngine* instance) OVERRIDE; 75 virtual void RemoveInputMethodExtension(const std::string& id) OVERRIDE; 76 virtual void GetInputMethodExtensions( 77 InputMethodDescriptors* result) OVERRIDE; 78 virtual void SetFilteredExtensionImes(std::vector<std::string>* ids) OVERRIDE; 79 virtual bool SwitchToNextInputMethod() OVERRIDE; 80 virtual bool SwitchToPreviousInputMethod() OVERRIDE; 81 virtual bool SwitchInputMethod(const ui::Accelerator& accelerator) OVERRIDE; 82 virtual InputMethodDescriptor GetCurrentInputMethod() const OVERRIDE; 83 virtual InputMethodPropertyList 84 GetCurrentInputMethodProperties() const OVERRIDE; 85 virtual XKeyboard* GetXKeyboard() OVERRIDE; 86 virtual InputMethodUtil* GetInputMethodUtil() OVERRIDE; 87 88 // Sets |ibus_controller_|. 89 void SetIBusControllerForTesting(IBusController* ibus_controller); 90 // Sets |candidate_window_controller_|. 91 void SetCandidateWindowControllerForTesting( 92 CandidateWindowController* candidate_window_controller); 93 // Sets |xkeyboard_|. 94 void SetXKeyboardForTesting(XKeyboard* xkeyboard); 95 96 private: 97 // IBusController overrides: 98 virtual void PropertyChanged() OVERRIDE; 99 100 // IBusDaemonController overrides: 101 virtual void OnConnected() OVERRIDE; 102 virtual void OnDisconnected() OVERRIDE; 103 104 105 // CandidateWindowController::Observer overrides: 106 virtual void CandidateWindowOpened() OVERRIDE; 107 virtual void CandidateWindowClosed() OVERRIDE; 108 109 // Temporarily deactivates all input methods (e.g. Chinese, Japanese, Arabic) 110 // since they are not necessary to input a login password. Users are still 111 // able to use/switch active keyboard layouts (e.g. US qwerty, US dvorak, 112 // French). 113 void OnScreenLocked(); 114 115 // Resumes the original state by activating input methods and/or changing the 116 // current input method as needed. 117 void OnScreenUnlocked(); 118 119 // Returns true if |input_method_id| is in |active_input_method_ids_|. 120 bool InputMethodIsActivated(const std::string& input_method_id); 121 122 // Returns true if the given input method config value is a string list 123 // that only contains an input method ID of a keyboard layout. 124 bool ContainOnlyKeyboardLayout(const std::vector<std::string>& value); 125 126 // Creates and initializes |candidate_window_controller_| if it hasn't been 127 // done. 128 void MaybeInitializeCandidateWindowController(); 129 130 // If |current_input_method_id_| is not in |input_method_ids|, switch to 131 // input_method_ids[0]. If the ID is equal to input_method_ids[N], switch to 132 // input_method_ids[N+1]. 133 void SwitchToNextInputMethodInternal( 134 const std::vector<std::string>& input_method_ids, 135 const std::string& current_input_method_id); 136 137 void ChangeInputMethodInternal(const std::string& input_method_id, 138 bool show_message); 139 140 scoped_ptr<InputMethodDelegate> delegate_; 141 142 // The current browser status. 143 State state_; 144 145 // A list of objects that monitor the manager. 146 ObserverList<InputMethodManager::Observer> observers_; 147 ObserverList<CandidateWindowObserver> candidate_window_observers_; 148 149 // The input method which was/is selected. 150 InputMethodDescriptor previous_input_method_; 151 InputMethodDescriptor current_input_method_; 152 // The active input method ids cache. 153 std::vector<std::string> active_input_method_ids_; 154 155 // The list of IMEs that are filtered from the IME list. 156 std::vector<std::string> filtered_extension_imes_; 157 158 // For screen locker. When the screen is locked, |previous_input_method_|, 159 // |current_input_method_|, and |active_input_method_ids_| above are copied 160 // to these "saved" variables. 161 InputMethodDescriptor saved_previous_input_method_; 162 InputMethodDescriptor saved_current_input_method_; 163 std::vector<std::string> saved_active_input_method_ids_; 164 165 // Extra input methods that have been explicitly added to the menu, such as 166 // those created by extension. 167 std::map<std::string, InputMethodDescriptor> extra_input_methods_; 168 std::map<std::string, InputMethodEngineIBus*> extra_input_method_instances_; 169 170 // The IBus controller is used to control the input method status and 171 // allow callbacks when the input method status changes. 172 scoped_ptr<IBusController> ibus_controller_; 173 174 // The candidate window. This will be deleted when the APP_TERMINATING 175 // message is sent. 176 scoped_ptr<CandidateWindowController> candidate_window_controller_; 177 178 // The object which can create an InputMethodDescriptor object. 179 InputMethodWhitelist whitelist_; 180 181 // An object which provides miscellaneous input method utility functions. Note 182 // that |util_| is required to initialize |xkeyboard_|. 183 InputMethodUtil util_; 184 185 // An object for switching XKB layouts and keyboard status like caps lock and 186 // auto-repeat interval. 187 scoped_ptr<XKeyboard> xkeyboard_; 188 189 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); 190}; 191 192} // namespace input_method 193} // namespace chromeos 194 195#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ 196