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

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

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

Powered by Google App Engine
This is Rietveld 408576698