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

Side by Side Diff: chrome/browser/chromeos/cros/language_library.h

Issue 2767001: Don't use disabled (gray) state for the language indicator. (Closed)
Patch Set: fixed all Created 10 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/language_library.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
6 #define CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_ 6 #define CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/observer_list.h" 12 #include "base/observer_list.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "third_party/cros/chromeos_input_method.h" 15 #include "third_party/cros/chromeos_input_method.h"
16 16
17 namespace chromeos { 17 namespace chromeos {
18 18
19 // This class handles the interaction with the ChromeOS language library APIs. 19 // This class handles the interaction with the ChromeOS language library APIs.
20 // Classes can add themselves as observers. Users can get an instance of this 20 // Classes can add themselves as observers. Users can get an instance of this
21 // library class like this: LanguageLibrary::Get() 21 // library class like this: LanguageLibrary::Get()
22 class LanguageLibrary { 22 class LanguageLibrary {
23 public: 23 public:
24 class Observer { 24 class Observer {
25 public: 25 public:
26 virtual ~Observer() = 0; 26 virtual ~Observer() = 0;
27 virtual void InputMethodChanged(LanguageLibrary* obj) = 0; 27 virtual void InputMethodChanged(LanguageLibrary* obj) = 0;
28 virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0; 28 virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0;
29 virtual void FocusChanged(LanguageLibrary* obj) = 0;
30 }; 29 };
31 virtual ~LanguageLibrary() {} 30 virtual ~LanguageLibrary() {}
32 31
33 virtual void AddObserver(Observer* observer) = 0; 32 virtual void AddObserver(Observer* observer) = 0;
34 virtual void RemoveObserver(Observer* observer) = 0; 33 virtual void RemoveObserver(Observer* observer) = 0;
35 34
36 // Returns the list of input methods we can select (i.e. active). If the cros 35 // Returns the list of input methods we can select (i.e. active). If the cros
37 // library is not found or IBus/DBus daemon is not alive, this function 36 // library is not found or IBus/DBus daemon is not alive, this function
38 // returns a fallback input method list (and never returns NULL). 37 // returns a fallback input method list (and never returns NULL).
39 virtual InputMethodDescriptors* GetActiveInputMethods() = 0; 38 virtual InputMethodDescriptors* GetActiveInputMethods() = 0;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 // the request and returns false. 72 // the request and returns false.
74 // You can specify |section| and |config_name| arguments in the same way 73 // You can specify |section| and |config_name| arguments in the same way
75 // as GetImeConfig() above. 74 // as GetImeConfig() above.
76 virtual bool SetImeConfig(const char* section, 75 virtual bool SetImeConfig(const char* section,
77 const char* config_name, 76 const char* config_name,
78 const ImeConfigValue& value) = 0; 77 const ImeConfigValue& value) = 0;
79 78
80 virtual const InputMethodDescriptor& current_input_method() const = 0; 79 virtual const InputMethodDescriptor& current_input_method() const = 0;
81 80
82 virtual const ImePropertyList& current_ime_properties() const = 0; 81 virtual const ImePropertyList& current_ime_properties() const = 0;
83 virtual bool is_focused() const = 0;
84 82
85 // Normalizes the language code and returns the normalized version. The 83 // Normalizes the language code and returns the normalized version. The
86 // function normalizes the given language code to be compatible with the 84 // function normalizes the given language code to be compatible with the
87 // one used in Chrome's application locales. Otherwise, returns the 85 // one used in Chrome's application locales. Otherwise, returns the
88 // given language code as-is. 86 // given language code as-is.
89 // 87 //
90 // Examples: 88 // Examples:
91 // 89 //
92 // - "zh_CN" => "zh-CN" (Use - instead of _) 90 // - "zh_CN" => "zh-CN" (Use - instead of _)
93 // - "jpn" => "ja" (Use two-letter code) 91 // - "jpn" => "ja" (Use two-letter code)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 const ImeConfigValue& value); 135 const ImeConfigValue& value);
138 136
139 virtual const InputMethodDescriptor& current_input_method() const { 137 virtual const InputMethodDescriptor& current_input_method() const {
140 return current_input_method_; 138 return current_input_method_;
141 } 139 }
142 140
143 virtual const ImePropertyList& current_ime_properties() const { 141 virtual const ImePropertyList& current_ime_properties() const {
144 return current_ime_properties_; 142 return current_ime_properties_;
145 } 143 }
146 144
147 virtual bool is_focused() const {
148 return is_focused_;
149 }
150
151 private: 145 private:
152 // This method is called when there's a change in input method status. 146 // This method is called when there's a change in input method status.
153 static void InputMethodChangedHandler( 147 static void InputMethodChangedHandler(
154 void* object, const InputMethodDescriptor& current_input_method); 148 void* object, const InputMethodDescriptor& current_input_method);
155 149
156 // This method is called when an input method sends "RegisterProperties" 150 // This method is called when an input method sends "RegisterProperties"
157 // signal. 151 // signal.
158 static void RegisterPropertiesHandler( 152 static void RegisterPropertiesHandler(
159 void* object, const ImePropertyList& prop_list); 153 void* object, const ImePropertyList& prop_list);
160 154
(...skipping 19 matching lines...) Expand all
180 // This will notify all the Observers. 174 // This will notify all the Observers.
181 void UpdateCurrentInputMethod( 175 void UpdateCurrentInputMethod(
182 const InputMethodDescriptor& current_input_method); 176 const InputMethodDescriptor& current_input_method);
183 177
184 // Called by the handler to register input method properties. 178 // Called by the handler to register input method properties.
185 void RegisterProperties(const ImePropertyList& prop_list); 179 void RegisterProperties(const ImePropertyList& prop_list);
186 180
187 // Called by the handler to update input method properties. 181 // Called by the handler to update input method properties.
188 void UpdateProperty(const ImePropertyList& prop_list); 182 void UpdateProperty(const ImePropertyList& prop_list);
189 183
190 // Called by the handler to notify focus changes.
191 void FocusChanged(bool is_focused);
192
193 // Tries to send all pending SetImeConfig requests to the input method config 184 // Tries to send all pending SetImeConfig requests to the input method config
194 // daemon. 185 // daemon.
195 void FlushImeConfig(); 186 void FlushImeConfig();
196 187
197 // A reference to the language api, to allow callbacks when the input method 188 // A reference to the language api, to allow callbacks when the input method
198 // status changes. 189 // status changes.
199 InputMethodStatusConnection* input_method_status_connection_; 190 InputMethodStatusConnection* input_method_status_connection_;
200 ObserverList<Observer> observers_; 191 ObserverList<Observer> observers_;
201 192
202 // The input method which is currently selected. 193 // The input method which is currently selected.
203 InputMethodDescriptor current_input_method_; 194 InputMethodDescriptor current_input_method_;
204 195
205 // The input method properties which the current input method uses. The list 196 // The input method properties which the current input method uses. The list
206 // might be empty when no input method is used. 197 // might be empty when no input method is used.
207 ImePropertyList current_ime_properties_; 198 ImePropertyList current_ime_properties_;
208 199
209 // true if a text input area in Chrome is focused.
210 bool is_focused_;
211
212 typedef std::pair<std::string, std::string> ConfigKeyType; 200 typedef std::pair<std::string, std::string> ConfigKeyType;
213 typedef std::map<ConfigKeyType, ImeConfigValue> InputMethodConfigRequests; 201 typedef std::map<ConfigKeyType, ImeConfigValue> InputMethodConfigRequests;
214 // SetImeConfig requests that are not yet completed. 202 // SetImeConfig requests that are not yet completed.
215 // Use a map to queue config requests, so we only send the last request for 203 // Use a map to queue config requests, so we only send the last request for
216 // the same config key (i.e. we'll discard ealier requests for the same 204 // the same config key (i.e. we'll discard ealier requests for the same
217 // config key). As we discard old requests for the same config key, the order 205 // config key). As we discard old requests for the same config key, the order
218 // of requests doesn't matter, so it's safe to use a map. 206 // of requests doesn't matter, so it's safe to use a map.
219 InputMethodConfigRequests pending_config_requests_; 207 InputMethodConfigRequests pending_config_requests_;
220 208
221 // A timer for retrying to send |pendning_config_commands_| to the input 209 // A timer for retrying to send |pendning_config_commands_| to the input
222 // method config daemon. 210 // method config daemon.
223 base::OneShotTimer<LanguageLibraryImpl> timer_; 211 base::OneShotTimer<LanguageLibraryImpl> timer_;
224 212
225 DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl); 213 DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl);
226 }; 214 };
227 215
228 } // namespace chromeos 216 } // namespace chromeos
229 217
230 #endif // CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_ 218 #endif // CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/language_library.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698