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

Unified Diff: chromeos_language.h

Issue 521058: Support intra-IME switching. Cros part. (Closed)
Patch Set: addressed issues Created 10 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromeos_language.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos_language.h
diff --git a/chromeos_language.h b/chromeos_language.h
index 1dfa7af63a3209933e343f22128c6c05e886f416..78e38eaad2b0bcf0d6522e336bdc2cda6c68fdaf 100644
--- a/chromeos_language.h
+++ b/chromeos_language.h
@@ -5,13 +5,16 @@
#ifndef CHROMEOS_LANGUAGE_H_
#define CHROMEOS_LANGUAGE_H_
+#include <sstream>
#include <string>
#include <vector>
#include <base/basictypes.h>
+#include <base/logging.h> // DCHECK
static const char kFallbackXKBId[] = "USA";
static const char kFallbackXKBDisplayName[] = "US";
+static const int kInvalidSelectionItemId = -1;
namespace chromeos {
@@ -22,18 +25,17 @@ enum LanguageCategory {
// A structure which represents an IME language or a XKB layout.
struct InputLanguage {
- InputLanguage(LanguageCategory category,
- const std::string& id,
- const std::string& display_name,
- const std::string& icon_path)
- : category(category),
- id(id),
- display_name(display_name),
- icon_path(icon_path) {
+ InputLanguage(LanguageCategory in_category,
+ const std::string& in_id,
+ const std::string& in_display_name,
+ const std::string& in_icon_path)
+ : category(in_category),
+ id(in_id),
+ display_name(in_display_name),
+ icon_path(in_icon_path) {
}
- InputLanguage()
- : category(LANGUAGE_CATEGORY_XKB) {
+ InputLanguage() : category(LANGUAGE_CATEGORY_XKB) {
}
// Languages are sorted by category, then by display_name, then by id.
@@ -64,6 +66,59 @@ struct InputLanguage {
};
typedef std::vector<InputLanguage> InputLanguageList;
+// A structure which represents a property for an IME engine. For details,
+// please check a comment for the LanguageRegisterImePropertiesFunction typedef
+// below.
+struct ImeProperty {
+ // TODO(yusukes): it might be better to use protocol buffers rather than the
+ // plain C++ struct.
+ ImeProperty(const std::string& in_key,
+ const std::string& in_icon_path,
+ const std::string& in_label,
+ bool in_is_selection_item,
+ bool in_is_selection_item_checked,
+ int in_selection_item_id)
+ : key(in_key),
+ icon_path(in_icon_path),
+ label(in_label),
+ is_selection_item(in_is_selection_item),
+ is_selection_item_checked(in_is_selection_item_checked),
+ selection_item_id(in_selection_item_id) {
+ DCHECK(!key.empty());
+ }
+
+ ImeProperty()
+ : is_selection_item(false),
+ is_selection_item_checked(false),
+ selection_item_id(kInvalidSelectionItemId) {
+ }
+
+ // Debug print function.
+ std::string ToString() const {
+ std::stringstream stream;
+ stream << "key=" << key
+ << ", icon_path=" << icon_path
+ << ", label=" << label
+ << ", is_selection_item=" << is_selection_item
+ << ", is_selection_item_checked=" << is_selection_item_checked
+ << ", selection_item_id=" << selection_item_id;
+ return stream.str();
+ }
+
+ std::string key; // A key which identifies the property. Non-empty string.
+ // (e.g. "InputMode.HalfWidthKatakana")
+ std::string icon_path; // Path to an icon. Can be empty.
+ std::string label; // A description of the property. Non-empty string.
+ // (e.g. "Switch to full punctuation mode", "Hiragana")
+ bool is_selection_item; // true if the property is a selection item.
+ bool is_selection_item_checked; // true if |is_selection_item| is true and
+ // the selection_item is selected.
+ int selection_item_id; // A group ID (>= 0) of the selection item.
+ // kInvalidSelectionItemId if |id_selection_item| is
+ // false.
+};
+typedef std::vector<ImeProperty> ImePropertyList;
+
// Creates dummy InputLanguageList object. Usually, this function is called only
// on development enviromnent where libcros.so does not exist. So, obviously
// you can not move this function to libcros.so. This function is called by
@@ -78,15 +133,76 @@ inline InputLanguageList* CreateFallbackInputLanguageList() {
return language_list;
}
-class LanguageStatusConnection;
-typedef void(*LanguageStatusMonitorFunction)(
+// A monitor function which is called when current IME language or XKB layout
+// is changed by user.
+typedef void(*LanguageCurrentLanguageMonitorFunction)(
void* language_library, const InputLanguage& current_language);
+// A monitor function which is called when "RegisterProperties" signal is sent
+// from the candidate_window process. The signal contains a list of properties
+// for a specific IME engine. For example, Japanese IME (ibus-anthy) might have
+// the following properties:
+//
+// ----------------------------------
+// key: InputMode.Hiragana
+// label: Hiragana
+// is_selection_item: true
+// is_selection_item_checked: true
+// selection_item_id: 1
+// ----------------------------------
+// key: InputMode.Katakana
+// label: Katakana
+// is_selection_item: true
+// is_selection_item_checked: false
+// selection_item_id: 1
+// ----------------------------------
+// ...
+// ----------------------------------
+typedef void(*LanguageRegisterImePropertiesFunction)(
+ void* language_library, const ImePropertyList& prop_list);
+
+// A monitor function which is called when "UpdateProperty" signal is sent
+// from the candidate_window process. The signal contains one or more
+// properties which is updated recently. Keys the signal contains are a subset
+// of keys registered by the "RegisterProperties" signal above. For example,
+// Japanese IME (ibus-anthy) might send the following properties:
+//
+// ----------------------------------
+// key: InputMode.Hiragana
+// label: Hiragana
+// is_selection_item: true
+// is_selection_item_checked: false
+// selection_item_id: ...
+// ----------------------------------
+// key: InputMode.Katakana
+// label: Katakana
+// is_selection_item: true
+// is_selection_item_checked: true
+// selection_item_id: ...
+// ----------------------------------
+//
+// Note: Please do not use selection_item_ids in |prop_list|. Dummy values are
+// filled in the field.
+typedef void(*LanguageUpdateImePropertyFunction)(
+ void* language_library, const ImePropertyList& prop_list);
+
+struct LanguageStatusMonitorFunctions {
+ LanguageStatusMonitorFunctions()
+ : current_language(NULL),
+ register_ime_properties(NULL),
+ update_ime_property(NULL) {
+ }
+ LanguageCurrentLanguageMonitorFunction current_language;
+ LanguageRegisterImePropertiesFunction register_ime_properties;
+ LanguageUpdateImePropertyFunction update_ime_property;
+};
+
// Establishes IBus connection to the ibus-daemon and DBus connection to
// the candidate window process. |monitor_function| will be called when IME
// language or XKB layout is changed.
+class LanguageStatusConnection;
extern LanguageStatusConnection* (*MonitorLanguageStatus)(
- LanguageStatusMonitorFunction monitor_funcion, void* language_library);
+ LanguageStatusMonitorFunctions monitor_funcions, void* language_library);
// Terminates IBus and DBus connections.
extern void (*DisconnectLanguageStatus)(LanguageStatusConnection* connection);
@@ -117,6 +233,16 @@ extern bool (*ActivateLanguage)(LanguageStatusConnection* connection,
extern bool (*DeactivateLanguage)(LanguageStatusConnection* connection,
LanguageCategory category, const char* name);
+// Activates an IME property identified by |key|. Examples of keys are:
+// "InputMode.Katakana", "InputMode.HalfWidthKatakana", "TypingMode.Romaji",
+// "TypingMode.Kana."
+extern void (*ActivateImeProperty)(LanguageStatusConnection* connection,
+ const char* key);
+
+// Deactivates an IME property identified by |key|.
+extern void (*DeactivateImeProperty)(LanguageStatusConnection* connection,
+ const char* key);
+
} // namespace chromeos
#endif // CHROMEOS_POWER_H_
« no previous file with comments | « no previous file | chromeos_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698