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" | |
kinaba
2012/04/16 10:22:53
Also #include "base/memory/scoped_ptr.h"
Yusuke Sato
2012/04/16 11:25:43
Done.
| |
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() const OVERRIDE; | |
41 virtual InputMethodDescriptors* GetActiveInputMethods() const 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; | |
Zachary Kuznia
2012/04/17 01:26:36
nit: Indent 4 spaces.
Yusuke Sato
2012/04/17 02:23:32
Done.
| |
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 DisableHotkeys() is called to temporarily disable IME hotkeys. | |
121 // EnableHotkeys() resets the flag to the default value, false. | |
122 bool ignore_hotkeys_; | |
123 | |
124 // The current browser status. | |
125 State state_; | |
126 | |
127 // A list of objects that monitor the manager. | |
128 ObserverList<InputMethodManager::Observer> observers_; | |
129 ObserverList<CandidateWindowObserver> candidate_window_observers_; | |
130 | |
131 // The input method which was/is selected. | |
132 InputMethodDescriptor previous_input_method_; | |
133 InputMethodDescriptor current_input_method_; | |
134 // The active input method ids cache. | |
135 std::vector<std::string> active_input_method_ids_; | |
136 | |
137 // For screen locker. When the screen is locked, |previous_input_method_|, | |
138 // |current_input_method_|, and |active_input_method_ids_| above are copied | |
139 // to these "saved" variables. | |
140 InputMethodDescriptor saved_previous_input_method_; | |
141 InputMethodDescriptor saved_current_input_method_; | |
142 std::vector<std::string> saved_active_input_method_ids_; | |
143 | |
144 // Extra input methods that have been explicitly added to the menu, such as | |
145 // those created by extension. | |
146 std::map<std::string, InputMethodDescriptor> extra_input_methods_; | |
147 | |
148 // The browser state monitor is used to receive notifications from the browser | |
149 // and call SetState() method of |this| class. | |
150 scoped_ptr<BrowserStateMonitor> browser_state_monitor_; | |
151 | |
152 // The IBus controller is used to control the input method status and | |
153 // allow callbacks when the input method status changes. | |
154 scoped_ptr<IBusController> ibus_controller_; | |
155 | |
156 // The candidate window. This will be deleted when the APP_TERMINATING | |
157 // message is sent. | |
158 scoped_ptr<CandidateWindowController> candidate_window_controller_; | |
159 | |
160 // The object which can create an InputMethodDescriptor object. | |
161 InputMethodWhitelist whitelist_; | |
162 | |
163 // An object which provides miscellaneous input method utility functions. Note | |
164 // that |util_| is required to initialize |xkeyboard_|. | |
165 InputMethodUtil util_; | |
166 | |
167 // An object for switching XKB layouts and keyboard status like caps lock and | |
168 // auto-repeat interval. | |
169 scoped_ptr<XKeyboard> xkeyboard_; | |
170 | |
171 DISALLOW_COPY_AND_ASSIGN(InputMethodManagerImpl); | |
172 }; | |
173 | |
174 } // namespace input_method | |
175 } // namespace chromeos | |
176 | |
177 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_MANAGER_IMPL_H_ | |
OLD | NEW |