Commit a43765d0 authored by nona@chromium.org's avatar nona@chromium.org

Add usage display support for Extension IME.

In the case of Japanese, IME shows word usage or its description. This
feature is already supported in Chrome OS native ibus IME engines.
With this patch, Chrome supports same feature for Extension IME.

This change does not affect existing extension implementation in terms of
backward compatibility.

BUG=158486
TEST=manually done one lumpy.


Review URL: https://chromiumcodereview.appspot.com/11412268

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170670 0039d316-1c4b-4281-b951-d872f2087c98
parent a592c043
...@@ -78,6 +78,11 @@ class InputMethodEngine { ...@@ -78,6 +78,11 @@ class InputMethodEngine {
std::string type; std::string type;
}; };
struct UsageEntry {
std::string title;
std::string body;
};
struct Candidate { struct Candidate {
Candidate(); Candidate();
virtual ~Candidate(); virtual ~Candidate();
...@@ -86,6 +91,7 @@ class InputMethodEngine { ...@@ -86,6 +91,7 @@ class InputMethodEngine {
int id; int id;
std::string label; std::string label;
std::string annotation; std::string annotation;
UsageEntry usage;
std::vector<Candidate> candidates; std::vector<Candidate> candidates;
}; };
......
...@@ -276,6 +276,8 @@ bool InputMethodEngineIBus::SetCandidates( ...@@ -276,6 +276,8 @@ bool InputMethodEngineIBus::SetCandidates(
entry.value = ix->value; entry.value = ix->value;
entry.label = ix->label; entry.label = ix->label;
entry.annotation = ix->annotation; entry.annotation = ix->annotation;
entry.description_title = ix->usage.title;
entry.description_body = ix->usage.body;
// Store a mapping from the user defined ID to the candidate index. // Store a mapping from the user defined ID to the candidate index.
candidate_indexes_[ix->id] = candidate_ids_.size(); candidate_indexes_[ix->id] = candidate_ids_.size();
......
...@@ -661,6 +661,7 @@ bool SetCandidatesFunction::ReadCandidates( ...@@ -661,6 +661,7 @@ bool SetCandidatesFunction::ReadCandidates(
int id; int id;
std::string label; std::string label;
std::string annotation; std::string annotation;
chromeos::InputMethodEngine::UsageEntry usage_entry;
EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kCandidateKey, EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetString(keys::kCandidateKey,
&candidate)); &candidate));
...@@ -676,11 +677,22 @@ bool SetCandidatesFunction::ReadCandidates( ...@@ -676,11 +677,22 @@ bool SetCandidatesFunction::ReadCandidates(
&annotation)); &annotation));
} }
if (candidate_dict->HasKey(keys::kUsageKey)) {
DictionaryValue* usage_dict;
EXTENSION_FUNCTION_VALIDATE(candidate_dict->GetDictionary(keys::kUsageKey,
&usage_dict));
EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageTitleKey,
&usage_entry.title));
EXTENSION_FUNCTION_VALIDATE(usage_dict->GetString(keys::kUsageBodyKey,
&usage_entry.body));
}
output->push_back(chromeos::InputMethodEngine::Candidate()); output->push_back(chromeos::InputMethodEngine::Candidate());
output->back().value = candidate; output->back().value = candidate;
output->back().id = id; output->back().id = id;
output->back().label = label; output->back().label = label;
output->back().annotation = annotation; output->back().annotation = annotation;
output->back().usage = usage_entry;
if (candidate_dict->HasKey(keys::kCandidatesKey)) { if (candidate_dict->HasKey(keys::kCandidatesKey)) {
ListValue* sub_list; ListValue* sub_list;
......
...@@ -34,6 +34,9 @@ const char kStyleDoubleUnderline[] = "doubleUnderline"; ...@@ -34,6 +34,9 @@ const char kStyleDoubleUnderline[] = "doubleUnderline";
const char kStyleKey[] = "style"; const char kStyleKey[] = "style";
const char kStyleUnderline[] = "underline"; const char kStyleUnderline[] = "underline";
const char kTextKey[] = "text"; const char kTextKey[] = "text";
const char kUsageBodyKey[] = "body";
const char kUsageKey[] = "usage";
const char kUsageTitleKey[] = "title";
const char kVerticalKey[] = "vertical"; const char kVerticalKey[] = "vertical";
const char kVisibleKey[] = "visible"; const char kVisibleKey[] = "visible";
......
...@@ -38,6 +38,9 @@ extern const char kStyleDoubleUnderline[]; ...@@ -38,6 +38,9 @@ extern const char kStyleDoubleUnderline[];
extern const char kStyleKey[]; extern const char kStyleKey[];
extern const char kStyleUnderline[]; extern const char kStyleUnderline[];
extern const char kTextKey[]; extern const char kTextKey[];
extern const char kUsageBodyKey[];
extern const char kUsageKey[];
extern const char kUsageTitleKey[];
extern const char kVerticalKey[]; extern const char kVerticalKey[];
extern const char kVisibleKey[]; extern const char kVisibleKey[];
......
...@@ -250,7 +250,16 @@ ...@@ -250,7 +250,16 @@
"id": {"type": "integer", "description": "The candidate's id"}, "id": {"type": "integer", "description": "The candidate's id"},
"parentId": {"type": "integer", "optional": true, "description": "The id to add these candidates under"}, "parentId": {"type": "integer", "optional": true, "description": "The id to add these candidates under"},
"label": {"type": "string", "optional": true, "description": "Short string displayed to next to the candidate, often the shortcut key or index"}, "label": {"type": "string", "optional": true, "description": "Short string displayed to next to the candidate, often the shortcut key or index"},
"annotation": {"type": "string", "optional": true, "description": "Additional text describing the candidate"} "annotation": {"type": "string", "optional": true, "description": "Additional text describing the candidate"},
"usage": {
"type": "object",
"optional": true,
"description": "The usage or detail description of word.",
"properties": {
"title": { "type": "string", "description": "The title string of details description."},
"body": { "type": "string", "description": "The body string of detail description."}
}
}
} }
} }
} }
......
...@@ -46,6 +46,8 @@ void AppendIBusLookupTable(const IBusLookupTable& table, ...@@ -46,6 +46,8 @@ void AppendIBusLookupTable(const IBusLookupTable& table,
ibus::IBusText text; ibus::IBusText text;
text.set_text(candidates[i].value); text.set_text(candidates[i].value);
text.set_annotation(candidates[i].annotation); text.set_annotation(candidates[i].annotation);
text.set_description_title(candidates[i].description_title);
text.set_description_body(candidates[i].description_body);
AppendIBusText(text, &text_writer); AppendIBusText(text, &text_writer);
if (!candidates[i].label.empty()) if (!candidates[i].label.empty())
have_labels = true; have_labels = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment