Commit 90e7b855 authored by My Nguyen's avatar My Nguyen Committed by Commit Bot

Add current_candidate_index and total_candidates to candidate_window

These fields are added as requested by ChromeVox's team to tell
ChromeVox user the true number of candidates and the current selection's
index.

Bug: 1074158
Change-Id: I697f96fe955fd5dc151543d47b26c605060f0a37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2162501
Commit-Queue: My Nguyen <myy@chromium.org>
Reviewed-by: default avatarKeith Lee <keithlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#762794}
parent 5491620b
......@@ -67,6 +67,8 @@ InputMethodEngine::CandidateWindowProperty::CandidateWindowProperty()
InputMethodEngine::CandidateWindowProperty::~CandidateWindowProperty() =
default;
InputMethodEngine::CandidateWindowProperty::CandidateWindowProperty(
const CandidateWindowProperty& other) = default;
InputMethodEngine::InputMethodEngine() = default;
......@@ -128,6 +130,8 @@ void InputMethodEngine::SetCandidateWindowProperty(
candidate_window_.GetProperty().cursor_position;
dest_property.auxiliary_text = property.auxiliary_text;
dest_property.is_auxiliary_text_visible = property.is_auxiliary_text_visible;
dest_property.current_candidate_index = property.current_candidate_index;
dest_property.total_candidates = property.total_candidates;
candidate_window_.SetProperty(dest_property);
candidate_window_property_ = property;
......
......@@ -74,6 +74,7 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase,
struct CandidateWindowProperty {
CandidateWindowProperty();
virtual ~CandidateWindowProperty();
CandidateWindowProperty(const CandidateWindowProperty& other);
int page_size;
bool is_cursor_visible;
bool is_vertical;
......@@ -83,6 +84,11 @@ class InputMethodEngine : public ::input_method::InputMethodEngineBase,
// window.
std::string auxiliary_text;
bool is_auxiliary_text_visible;
// The index of the current chosen candidate out of total candidates.
// value is -1 if there is no current chosen candidate.
int current_candidate_index = -1;
int total_candidates = 0;
};
InputMethodEngine();
......
......@@ -798,6 +798,46 @@ IN_PROC_BROWSER_TEST_P(InputMethodEngineBrowserTest,
EXPECT_TRUE(table.is_auxiliary_text_visible());
EXPECT_EQ("AUXILIARY_TEXT", table.auxiliary_text());
}
{
SCOPED_TRACE("setCandidateWindowProperties:currentCandidateIndex test");
mock_input_context->Reset();
mock_candidate_window->Reset();
const char set_candidate_window_properties_test_script[] =
"chrome.input.ime.setCandidateWindowProperties({"
" engineID: engineBridge.getActiveEngineID(),"
" properties: {"
" currentCandidateIndex: 1"
" }"
"});";
ASSERT_TRUE(content::ExecuteScript(
host->host_contents(), set_candidate_window_properties_test_script));
EXPECT_EQ(1, mock_candidate_window->update_lookup_table_call_count());
const ui::CandidateWindow& table =
mock_candidate_window->last_update_lookup_table_arg().lookup_table;
EXPECT_EQ(1, table.current_candidate_index());
}
{
SCOPED_TRACE("setCandidateWindowProperties:totalCandidates test");
mock_input_context->Reset();
mock_candidate_window->Reset();
const char set_candidate_window_properties_test_script[] =
"chrome.input.ime.setCandidateWindowProperties({"
" engineID: engineBridge.getActiveEngineID(),"
" properties: {"
" totalCandidates: 100"
" }"
"});";
ASSERT_TRUE(content::ExecuteScript(
host->host_contents(), set_candidate_window_properties_test_script));
EXPECT_EQ(1, mock_candidate_window->update_lookup_table_call_count());
const ui::CandidateWindow& table =
mock_candidate_window->last_update_lookup_table_arg().lookup_table;
EXPECT_EQ(100, table.total_candidates());
}
{
SCOPED_TRACE("setCandidates test");
mock_input_context->Reset();
......
......@@ -651,6 +651,17 @@ InputImeSetCandidateWindowPropertiesFunction::Run() {
modified = true;
}
if (properties.current_candidate_index) {
properties_out.current_candidate_index =
*properties.current_candidate_index;
modified = true;
}
if (properties.total_candidates) {
properties_out.total_candidates = *properties.total_candidates;
modified = true;
}
if (modified) {
engine->SetCandidateWindowProperty(properties_out);
}
......
......@@ -355,6 +355,16 @@
"optional": true,
"description": "True to display the auxiliary text, false to hide it."
},
"totalCandidates": {
"type": "integer",
"optional": true,
"description": "The total number of candidates for the candidate window."
},
"currentCandidateIndex": {
"type": "integer",
"optional": true,
"description": "The index of the current chosen candidate out of total candidates."
},
"windowPosition": {
"$ref": "WindowPosition",
"description": "Where to display the candidate window.",
......
......@@ -38,6 +38,10 @@ class COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindow {
// window.
std::string auxiliary_text;
bool is_auxiliary_text_visible;
// The index of the current chosen candidate out of total candidates
int current_candidate_index;
int total_candidates;
};
// Represents a candidate entry.
......@@ -113,6 +117,12 @@ class COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindow {
property_->auxiliary_text = auxiliary_text;
}
const int& current_candidate_index() const {
return property_->current_candidate_index;
}
const int& total_candidates() const { return property_->total_candidates; }
const std::vector<Entry>& candidates() const { return candidates_; }
std::vector<Entry>* mutable_candidates() { return &candidates_; }
......
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