OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_LANGUAGE_H_ | 5 #ifndef CHROMEOS_LANGUAGE_H_ |
6 #define CHROMEOS_LANGUAGE_H_ | 6 #define CHROMEOS_LANGUAGE_H_ |
7 | 7 |
| 8 #include <sstream> |
8 #include <string> | 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include <base/basictypes.h> | 12 #include <base/basictypes.h> |
| 13 #include <base/logging.h> // DCHECK |
12 | 14 |
13 static const char kFallbackXKBId[] = "USA"; | 15 static const char kFallbackXKBId[] = "USA"; |
14 static const char kFallbackXKBDisplayName[] = "US"; | 16 static const char kFallbackXKBDisplayName[] = "US"; |
| 17 static const int kInvalidSelectionItemId = -1; |
15 | 18 |
16 namespace chromeos { | 19 namespace chromeos { |
17 | 20 |
18 enum LanguageCategory { | 21 enum LanguageCategory { |
19 LANGUAGE_CATEGORY_XKB, | 22 LANGUAGE_CATEGORY_XKB, |
20 LANGUAGE_CATEGORY_IME, | 23 LANGUAGE_CATEGORY_IME, |
21 }; | 24 }; |
22 | 25 |
23 // A structure which represents an IME language or a XKB layout. | 26 // A structure which represents an IME language or a XKB layout. |
24 struct InputLanguage { | 27 struct InputLanguage { |
25 InputLanguage(LanguageCategory category, | 28 InputLanguage(LanguageCategory in_category, |
26 const std::string& id, | 29 const std::string& in_id, |
27 const std::string& display_name, | 30 const std::string& in_display_name, |
28 const std::string& icon_path) | 31 const std::string& in_icon_path) |
29 : category(category), | 32 : category(in_category), |
30 id(id), | 33 id(in_id), |
31 display_name(display_name), | 34 display_name(in_display_name), |
32 icon_path(icon_path) { | 35 icon_path(in_icon_path) { |
33 } | 36 } |
34 | 37 |
35 InputLanguage() | 38 InputLanguage() : category(LANGUAGE_CATEGORY_XKB) { |
36 : category(LANGUAGE_CATEGORY_XKB) { | |
37 } | 39 } |
38 | 40 |
39 // Languages are sorted by category, then by display_name, then by id. | 41 // Languages are sorted by category, then by display_name, then by id. |
40 bool operator<(const InputLanguage& other) const { | 42 bool operator<(const InputLanguage& other) const { |
41 if (category == other.category) { | 43 if (category == other.category) { |
42 if (display_name == other.display_name) { | 44 if (display_name == other.display_name) { |
43 return id < other.id; | 45 return id < other.id; |
44 } | 46 } |
45 return display_name < other.display_name; | 47 return display_name < other.display_name; |
46 } | 48 } |
(...skipping 10 matching lines...) Expand all Loading... |
57 // "t:latn-post", "chewing"). | 59 // "t:latn-post", "chewing"). |
58 std::string id; | 60 std::string id; |
59 // An IME or layout name which is used in the UI (e.g., "Anthy"). | 61 // An IME or layout name which is used in the UI (e.g., "Anthy"). |
60 std::string display_name; | 62 std::string display_name; |
61 // Path to an icon (e.g., "/usr/share/ibus-chewing/icons/ibus-chewing.png"). | 63 // Path to an icon (e.g., "/usr/share/ibus-chewing/icons/ibus-chewing.png"). |
62 // Empty if it does not exist. | 64 // Empty if it does not exist. |
63 std::string icon_path; | 65 std::string icon_path; |
64 }; | 66 }; |
65 typedef std::vector<InputLanguage> InputLanguageList; | 67 typedef std::vector<InputLanguage> InputLanguageList; |
66 | 68 |
| 69 // A structure which represents a property for an IME engine. For details, |
| 70 // please check a comment for the LanguageRegisterImePropertiesFunction typedef |
| 71 // below. |
| 72 struct ImeProperty { |
| 73 // TODO(yusukes): it might be better to use protocol buffers rather than the |
| 74 // plain C++ struct. |
| 75 ImeProperty(const std::string& in_key, |
| 76 const std::string& in_icon_path, |
| 77 const std::string& in_label, |
| 78 bool in_is_selection_item, |
| 79 bool in_is_selection_item_checked, |
| 80 int in_selection_item_id) |
| 81 : key(in_key), |
| 82 icon_path(in_icon_path), |
| 83 label(in_label), |
| 84 is_selection_item(in_is_selection_item), |
| 85 is_selection_item_checked(in_is_selection_item_checked), |
| 86 selection_item_id(in_selection_item_id) { |
| 87 DCHECK(!key.empty()); |
| 88 } |
| 89 |
| 90 ImeProperty() |
| 91 : is_selection_item(false), |
| 92 is_selection_item_checked(false), |
| 93 selection_item_id(kInvalidSelectionItemId) { |
| 94 } |
| 95 |
| 96 // Debug print function. |
| 97 std::string ToString() const { |
| 98 std::stringstream stream; |
| 99 stream << "key=" << key |
| 100 << ", icon_path=" << icon_path |
| 101 << ", label=" << label |
| 102 << ", is_selection_item=" << is_selection_item |
| 103 << ", is_selection_item_checked=" << is_selection_item_checked |
| 104 << ", selection_item_id=" << selection_item_id; |
| 105 return stream.str(); |
| 106 } |
| 107 |
| 108 std::string key; // A key which identifies the property. Non-empty string. |
| 109 // (e.g. "InputMode.HalfWidthKatakana") |
| 110 std::string icon_path; // Path to an icon. Can be empty. |
| 111 std::string label; // A description of the property. Non-empty string. |
| 112 // (e.g. "Switch to full punctuation mode", "Hiragana") |
| 113 bool is_selection_item; // true if the property is a selection item. |
| 114 bool is_selection_item_checked; // true if |is_selection_item| is true and |
| 115 // the selection_item is selected. |
| 116 int selection_item_id; // A group ID (>= 0) of the selection item. |
| 117 // kInvalidSelectionItemId if |id_selection_item| is |
| 118 // false. |
| 119 }; |
| 120 typedef std::vector<ImeProperty> ImePropertyList; |
| 121 |
67 // Creates dummy InputLanguageList object. Usually, this function is called only | 122 // Creates dummy InputLanguageList object. Usually, this function is called only |
68 // on development enviromnent where libcros.so does not exist. So, obviously | 123 // on development enviromnent where libcros.so does not exist. So, obviously |
69 // you can not move this function to libcros.so. This function is called by | 124 // you can not move this function to libcros.so. This function is called by |
70 // src/chrome/browser/chromeos/language_library.cc when EnsureLoaded() fails. | 125 // src/chrome/browser/chromeos/language_library.cc when EnsureLoaded() fails. |
71 inline InputLanguageList* CreateFallbackInputLanguageList() { | 126 inline InputLanguageList* CreateFallbackInputLanguageList() { |
72 InputLanguageList* language_list = new InputLanguageList; | 127 InputLanguageList* language_list = new InputLanguageList; |
73 language_list->push_back( | 128 language_list->push_back( |
74 InputLanguage(LANGUAGE_CATEGORY_XKB, | 129 InputLanguage(LANGUAGE_CATEGORY_XKB, |
75 kFallbackXKBId, | 130 kFallbackXKBId, |
76 kFallbackXKBDisplayName, | 131 kFallbackXKBDisplayName, |
77 "" /* no icon */)); | 132 "" /* no icon */)); |
78 return language_list; | 133 return language_list; |
79 } | 134 } |
80 | 135 |
81 class LanguageStatusConnection; | 136 // A monitor function which is called when current IME language or XKB layout |
82 typedef void(*LanguageStatusMonitorFunction)( | 137 // is changed by user. |
| 138 typedef void(*LanguageCurrentLanguageMonitorFunction)( |
83 void* language_library, const InputLanguage& current_language); | 139 void* language_library, const InputLanguage& current_language); |
84 | 140 |
| 141 // A monitor function which is called when "RegisterProperties" signal is sent |
| 142 // from the candidate_window process. The signal contains a list of properties |
| 143 // for a specific IME engine. For example, Japanese IME (ibus-anthy) might have |
| 144 // the following properties: |
| 145 // |
| 146 // ---------------------------------- |
| 147 // key: InputMode.Hiragana |
| 148 // label: Hiragana |
| 149 // is_selection_item: true |
| 150 // is_selection_item_checked: true |
| 151 // selection_item_id: 1 |
| 152 // ---------------------------------- |
| 153 // key: InputMode.Katakana |
| 154 // label: Katakana |
| 155 // is_selection_item: true |
| 156 // is_selection_item_checked: false |
| 157 // selection_item_id: 1 |
| 158 // ---------------------------------- |
| 159 // ... |
| 160 // ---------------------------------- |
| 161 typedef void(*LanguageRegisterImePropertiesFunction)( |
| 162 void* language_library, const ImePropertyList& prop_list); |
| 163 |
| 164 // A monitor function which is called when "UpdateProperty" signal is sent |
| 165 // from the candidate_window process. The signal contains one or more |
| 166 // properties which is updated recently. Keys the signal contains are a subset |
| 167 // of keys registered by the "RegisterProperties" signal above. For example, |
| 168 // Japanese IME (ibus-anthy) might send the following properties: |
| 169 // |
| 170 // ---------------------------------- |
| 171 // key: InputMode.Hiragana |
| 172 // label: Hiragana |
| 173 // is_selection_item: true |
| 174 // is_selection_item_checked: false |
| 175 // selection_item_id: ... |
| 176 // ---------------------------------- |
| 177 // key: InputMode.Katakana |
| 178 // label: Katakana |
| 179 // is_selection_item: true |
| 180 // is_selection_item_checked: true |
| 181 // selection_item_id: ... |
| 182 // ---------------------------------- |
| 183 // |
| 184 // Note: Please do not use selection_item_ids in |prop_list|. Dummy values are |
| 185 // filled in the field. |
| 186 typedef void(*LanguageUpdateImePropertyFunction)( |
| 187 void* language_library, const ImePropertyList& prop_list); |
| 188 |
| 189 struct LanguageStatusMonitorFunctions { |
| 190 LanguageStatusMonitorFunctions() |
| 191 : current_language(NULL), |
| 192 register_ime_properties(NULL), |
| 193 update_ime_property(NULL) { |
| 194 } |
| 195 LanguageCurrentLanguageMonitorFunction current_language; |
| 196 LanguageRegisterImePropertiesFunction register_ime_properties; |
| 197 LanguageUpdateImePropertyFunction update_ime_property; |
| 198 }; |
| 199 |
85 // Establishes IBus connection to the ibus-daemon and DBus connection to | 200 // Establishes IBus connection to the ibus-daemon and DBus connection to |
86 // the candidate window process. |monitor_function| will be called when IME | 201 // the candidate window process. |monitor_function| will be called when IME |
87 // language or XKB layout is changed. | 202 // language or XKB layout is changed. |
| 203 class LanguageStatusConnection; |
88 extern LanguageStatusConnection* (*MonitorLanguageStatus)( | 204 extern LanguageStatusConnection* (*MonitorLanguageStatus)( |
89 LanguageStatusMonitorFunction monitor_funcion, void* language_library); | 205 LanguageStatusMonitorFunctions monitor_funcions, void* language_library); |
90 | 206 |
91 // Terminates IBus and DBus connections. | 207 // Terminates IBus and DBus connections. |
92 extern void (*DisconnectLanguageStatus)(LanguageStatusConnection* connection); | 208 extern void (*DisconnectLanguageStatus)(LanguageStatusConnection* connection); |
93 | 209 |
94 // Gets all IME languages and XKB layouts that are currently active. Caller | 210 // Gets all IME languages and XKB layouts that are currently active. Caller |
95 // has to delete the returned list. This function might return NULL on error. | 211 // has to delete the returned list. This function might return NULL on error. |
96 extern InputLanguageList* (*GetLanguages)(LanguageStatusConnection* connection); | 212 extern InputLanguageList* (*GetLanguages)(LanguageStatusConnection* connection); |
97 | 213 |
98 // Gets all IME languages and XKB layouts that are supported, including ones | 214 // Gets all IME languages and XKB layouts that are supported, including ones |
99 // not active. Caller has to delete the returned list. This function might | 215 // not active. Caller has to delete the returned list. This function might |
(...skipping 10 matching lines...) Expand all Loading... |
110 // Activates the language specified by |category| and |name|. Returns true on | 226 // Activates the language specified by |category| and |name|. Returns true on |
111 // success. | 227 // success. |
112 extern bool (*ActivateLanguage)(LanguageStatusConnection* connection, | 228 extern bool (*ActivateLanguage)(LanguageStatusConnection* connection, |
113 LanguageCategory category, const char* name); | 229 LanguageCategory category, const char* name); |
114 | 230 |
115 // Deactivates the language specified by |category| and |name|. Returns true | 231 // Deactivates the language specified by |category| and |name|. Returns true |
116 // on success. | 232 // on success. |
117 extern bool (*DeactivateLanguage)(LanguageStatusConnection* connection, | 233 extern bool (*DeactivateLanguage)(LanguageStatusConnection* connection, |
118 LanguageCategory category, const char* name); | 234 LanguageCategory category, const char* name); |
119 | 235 |
| 236 // Activates an IME property identified by |key|. Examples of keys are: |
| 237 // "InputMode.Katakana", "InputMode.HalfWidthKatakana", "TypingMode.Romaji", |
| 238 // "TypingMode.Kana." |
| 239 extern void (*ActivateImeProperty)(LanguageStatusConnection* connection, |
| 240 const char* key); |
| 241 |
| 242 // Deactivates an IME property identified by |key|. |
| 243 extern void (*DeactivateImeProperty)(LanguageStatusConnection* connection, |
| 244 const char* key); |
| 245 |
120 } // namespace chromeos | 246 } // namespace chromeos |
121 | 247 |
122 #endif // CHROMEOS_POWER_H_ | 248 #endif // CHROMEOS_POWER_H_ |
OLD | NEW |