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