OLD | NEW |
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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/singleton.h" | |
12 #include "base/time.h" | 11 #include "base/time.h" |
13 #include "third_party/cros/chromeos_language.h" | 12 #include "third_party/cros/chromeos_language.h" |
14 | 13 |
15 namespace chromeos { | 14 namespace chromeos { |
16 | 15 |
17 // This class handles the interaction with the ChromeOS language library APIs. | 16 // This class handles the interaction with the ChromeOS language library APIs. |
18 // Classes can add themselves as observers. Users can get an instance of this | 17 // Classes can add themselves as observers. Users can get an instance of this |
19 // library class like this: LanguageLibrary::Get() | 18 // library class like this: LanguageLibrary::Get() |
20 class LanguageLibrary { | 19 class LanguageLibrary { |
21 public: | 20 public: |
22 class Observer { | 21 class Observer { |
23 public: | 22 public: |
24 virtual ~Observer() = 0; | 23 virtual ~Observer() = 0; |
25 virtual void LanguageChanged(LanguageLibrary* obj) = 0; | 24 virtual void LanguageChanged(LanguageLibrary* obj) = 0; |
26 virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0; | 25 virtual void ImePropertiesChanged(LanguageLibrary* obj) = 0; |
27 }; | 26 }; |
| 27 virtual ~LanguageLibrary() {} |
28 | 28 |
29 // This gets the singleton LanguageLibrary | 29 virtual void AddObserver(Observer* observer) = 0; |
30 static LanguageLibrary* Get(); | 30 virtual void RemoveObserver(Observer* observer) = 0; |
31 | |
32 void AddObserver(Observer* observer); | |
33 void RemoveObserver(Observer* observer); | |
34 | 31 |
35 // Returns the list of IMEs and keyboard layouts we can select | 32 // Returns the list of IMEs and keyboard layouts we can select |
36 // (i.e. active). If the cros library is not found or IBus/DBus daemon | 33 // (i.e. active). If the cros library is not found or IBus/DBus daemon |
37 // is not alive, this function returns a fallback language list (and | 34 // is not alive, this function returns a fallback language list (and |
38 // never returns NULL). | 35 // never returns NULL). |
39 InputLanguageList* GetActiveLanguages(); | 36 virtual InputLanguageList* GetActiveLanguages() = 0; |
40 | 37 |
41 // Returns the list of IMEs and keyboard layouts we support, including | 38 // Returns the list of IMEs and keyboard layouts we support, including |
42 // ones not active. If the cros library is not found or IBus/DBus | 39 // ones not active. If the cros library is not found or IBus/DBus |
43 // daemon is not alive, this function returns a fallback language list | 40 // daemon is not alive, this function returns a fallback language list |
44 // (and never returns NULL). | 41 // (and never returns NULL). |
45 InputLanguageList* GetSupportedLanguages(); | 42 virtual InputLanguageList* GetSupportedLanguages() = 0; |
46 | 43 |
47 // Changes the current IME engine to |id| and enable IME (when |category| | 44 // Changes the current IME engine to |id| and enable IME (when |category| |
48 // is LANGUAGE_CATEGORY_IME). Changes the current XKB layout to |id| and | 45 // is LANGUAGE_CATEGORY_IME). Changes the current XKB layout to |id| and |
49 // disable IME (when |category| is LANGUAGE_CATEGORY_XKB). |id| is a unique | 46 // disable IME (when |category| is LANGUAGE_CATEGORY_XKB). |id| is a unique |
50 // identifier of a IME engine or XKB layout. Please check chromeos_language.h | 47 // identifier of a IME engine or XKB layout. Please check chromeos_language.h |
51 // in src third_party/cros/ for details. | 48 // in src third_party/cros/ for details. |
52 void ChangeLanguage(LanguageCategory category, const std::string& id); | 49 virtual void ChangeLanguage(LanguageCategory category, |
| 50 const std::string& id) = 0; |
53 | 51 |
54 // Activates an IME property identified by |key|. Examples of keys are: | 52 // Activates an IME property identified by |key|. Examples of keys are: |
55 // "InputMode.Katakana", "InputMode.HalfWidthKatakana", "TypingMode.Romaji", | 53 // "InputMode.Katakana", "InputMode.HalfWidthKatakana", "TypingMode.Romaji", |
56 // and "TypingMode.Kana." | 54 // and "TypingMode.Kana." |
57 void ActivateImeProperty(const std::string& key); | 55 virtual void ActivateImeProperty(const std::string& key) = 0; |
58 | 56 |
59 // Deactivates an IME property identified by |key|. | 57 // Deactivates an IME property identified by |key|. |
60 void DeactivateImeProperty(const std::string& key); | 58 virtual void DeactivateImeProperty(const std::string& key) = 0; |
61 | 59 |
62 // Activates the language specified by |category| and |id|. Returns true | 60 // Activates the language specified by |category| and |id|. Returns true |
63 // on success. | 61 // on success. |
64 bool ActivateLanguage(LanguageCategory category, const std::string& id); | 62 virtual bool ActivateLanguage(LanguageCategory category, |
| 63 const std::string& id) = 0; |
65 | 64 |
66 // Dectivates the language specified by |category| and |id|. Returns | 65 // Dectivates the language specified by |category| and |id|. Returns |
67 // true on success. | 66 // true on success. |
68 bool DeactivateLanguage(LanguageCategory category, const std::string& id); | 67 virtual bool DeactivateLanguage(LanguageCategory category, |
| 68 const std::string& id) = 0; |
69 | 69 |
70 // Get a configuration of ibus-daemon or IBus engines and stores it on | 70 // Get a configuration of ibus-daemon or IBus engines and stores it on |
71 // |out_value|. Returns true if |out_value| is successfully updated. | 71 // |out_value|. Returns true if |out_value| is successfully updated. |
72 // When you would like to retrieve 'panel/custom_font', |section| should | 72 // When you would like to retrieve 'panel/custom_font', |section| should |
73 // be "panel", and |config_name| should be "custom_font". | 73 // be "panel", and |config_name| should be "custom_font". |
74 bool GetImeConfig( | 74 virtual bool GetImeConfig( |
75 const char* section, const char* config_name, ImeConfigValue* out_value); | 75 const char* section, const char* config_name, |
| 76 ImeConfigValue* out_value) = 0; |
76 | 77 |
77 // Updates a configuration of ibus-daemon or IBus engines with |value|. | 78 // Updates a configuration of ibus-daemon or IBus engines with |value|. |
78 // Returns true if the configuration is successfully updated. | 79 // Returns true if the configuration is successfully updated. |
79 // You can specify |section| and |config_name| arguments in the same way | 80 // You can specify |section| and |config_name| arguments in the same way |
80 // as GetImeConfig() above. | 81 // as GetImeConfig() above. |
81 bool SetImeConfig(const char* section, | 82 virtual bool SetImeConfig(const char* section, |
82 const char* config_name, | 83 const char* config_name, |
83 const ImeConfigValue& value); | 84 const ImeConfigValue& value) = 0; |
84 | 85 |
85 const InputLanguage& current_language() const { | 86 virtual const InputLanguage& current_language() const = 0; |
| 87 |
| 88 virtual const ImePropertyList& current_ime_properties() const = 0; |
| 89 |
| 90 }; |
| 91 |
| 92 // This class handles the interaction with the ChromeOS language library APIs. |
| 93 // Classes can add themselves as observers. Users can get an instance of this |
| 94 // library class like this: LanguageLibrary::Get() |
| 95 class LanguageLibraryImpl : public LanguageLibrary { |
| 96 public: |
| 97 LanguageLibraryImpl(); |
| 98 virtual ~LanguageLibraryImpl(); |
| 99 |
| 100 // LanguageLibrary overrides. |
| 101 virtual void AddObserver(Observer* observer); |
| 102 virtual void RemoveObserver(Observer* observer); |
| 103 virtual InputLanguageList* GetActiveLanguages(); |
| 104 virtual InputLanguageList* GetSupportedLanguages(); |
| 105 virtual void ChangeLanguage(LanguageCategory category, const std::string& id); |
| 106 virtual void ActivateImeProperty(const std::string& key); |
| 107 virtual void DeactivateImeProperty(const std::string& key); |
| 108 virtual bool ActivateLanguage(LanguageCategory category, |
| 109 const std::string& id); |
| 110 virtual bool DeactivateLanguage(LanguageCategory category, |
| 111 const std::string& id); |
| 112 virtual bool GetImeConfig( |
| 113 const char* section, const char* config_name, ImeConfigValue* out_value); |
| 114 virtual bool SetImeConfig(const char* section, |
| 115 const char* config_name, |
| 116 const ImeConfigValue& value); |
| 117 |
| 118 virtual const InputLanguage& current_language() const { |
86 return current_language_; | 119 return current_language_; |
87 } | 120 } |
88 | 121 |
89 const ImePropertyList& current_ime_properties() const { | 122 virtual const ImePropertyList& current_ime_properties() const { |
90 return current_ime_properties_; | 123 return current_ime_properties_; |
91 } | 124 } |
92 | 125 |
93 private: | 126 private: |
94 friend struct DefaultSingletonTraits<LanguageLibrary>; | |
95 | |
96 LanguageLibrary(); | |
97 ~LanguageLibrary(); | |
98 | |
99 // This method is called when there's a change in language status. | 127 // This method is called when there's a change in language status. |
100 static void LanguageChangedHandler( | 128 static void LanguageChangedHandler( |
101 void* object, const InputLanguage& current_language); | 129 void* object, const InputLanguage& current_language); |
102 | 130 |
103 // This method is called when an IME engine sends "RegisterProperties" signal. | 131 // This method is called when an IME engine sends "RegisterProperties" signal. |
104 static void RegisterPropertiesHandler( | 132 static void RegisterPropertiesHandler( |
105 void* object, const ImePropertyList& prop_list); | 133 void* object, const ImePropertyList& prop_list); |
106 | 134 |
107 // This method is called when an IME engine sends "UpdateProperty" signal. | 135 // This method is called when an IME engine sends "UpdateProperty" signal. |
108 static void UpdatePropertyHandler( | 136 static void UpdatePropertyHandler( |
(...skipping 24 matching lines...) Expand all Loading... |
133 LanguageStatusConnection* language_status_connection_; | 161 LanguageStatusConnection* language_status_connection_; |
134 ObserverList<Observer> observers_; | 162 ObserverList<Observer> observers_; |
135 | 163 |
136 // The language (IME or XKB layout) which currently selected. | 164 // The language (IME or XKB layout) which currently selected. |
137 InputLanguage current_language_; | 165 InputLanguage current_language_; |
138 | 166 |
139 // The IME properties which the current IME engine uses. The list might be | 167 // The IME properties which the current IME engine uses. The list might be |
140 // empty when no IME is used. | 168 // empty when no IME is used. |
141 ImePropertyList current_ime_properties_; | 169 ImePropertyList current_ime_properties_; |
142 | 170 |
143 DISALLOW_COPY_AND_ASSIGN(LanguageLibrary); | 171 DISALLOW_COPY_AND_ASSIGN(LanguageLibraryImpl); |
144 }; | 172 }; |
145 | 173 |
146 } // namespace chromeos | 174 } // namespace chromeos |
147 | 175 |
148 #endif // CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_ | 176 #endif // CHROME_BROWSER_CHROMEOS_CROS_LANGUAGE_LIBRARY_H_ |
149 | 177 |
OLD | NEW |