Skip to content

Commit

Permalink
Rename Output.candidates to Output.candidate_window for better re…
Browse files Browse the repository at this point in the history
…adability.

PiperOrigin-RevId: 688146644
  • Loading branch information
Ruihao Huang authored and hiroyuki-komatsu committed Oct 21, 2024
1 parent 20b02d2 commit ec4ff27
Show file tree
Hide file tree
Showing 25 changed files with 434 additions and 387 deletions.
2 changes: 1 addition & 1 deletion src/client/client_scenario_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ int Loop(std::istream *input) {

if (renderer_client != nullptr) {
renderer_command.set_type(commands::RendererCommand::UPDATE);
renderer_command.set_visible(output.has_candidates());
renderer_command.set_visible(output.has_candidate_window());
*renderer_command.mutable_output() = output;
MOZC_VLOG(2) << "Sending to Renderer: " << renderer_command;
renderer_client->ExecCommand(renderer_command);
Expand Down
4 changes: 2 additions & 2 deletions src/client/client_stress_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

// TODO(taku)
// 1. multi-thread testing
// 2. change/config the senario
// 2. change/config the scenario

ABSL_FLAG(int32_t, max_keyevents, 100000,
"test at most |max_keyevents| key sequences");
Expand Down Expand Up @@ -137,7 +137,7 @@ int main(int argc, char **argv) {

if (renderer_client != nullptr) {
renderer_command.set_type(mozc::commands::RendererCommand::UPDATE);
renderer_command.set_visible(output.has_candidates());
renderer_command.set_visible(output.has_candidate_window());
*renderer_command.mutable_output() = output;
MOZC_VLOG(2) << "Sending to Renderer: " << renderer_command;
renderer_client->ExecCommand(renderer_command);
Expand Down
2 changes: 1 addition & 1 deletion src/ios/ios_engine_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ int main(int argc, char **argv) {
} else {
std::cout << "----- preedit -----\n"
<< absl::StrCat(command.output().preedit()) << std::endl;
const auto &cands = command.output().candidates();
const auto &cands = command.output().candidate_window();
const int size =
std::min(absl::GetFlag(FLAGS_candsize), cands.candidate_size());
for (int i = 0; i < size; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions src/mac/mozc_imk_input_controller.mm
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ - (void)delayedUpdateCandidates {
}

// If there is no candidate, the candidate window is closed.
if (rendererCommand_.output().candidates().candidate_size() == 0) {
if (rendererCommand_.output().candidate_window().candidate_size() == 0) {
rendererCommand_.set_visible(false);
mozcRenderer_->ExecCommand(rendererCommand_);
return;
Expand All @@ -736,7 +736,7 @@ - (void)delayedUpdateCandidates {
rendererCommand_.set_visible(true);

NSRect preeditRect = NSZeroRect;
const int32_t position = rendererCommand_.output().candidates().position();
const int32_t position = rendererCommand_.output().candidate_window().position();
// Some applications throws error when we call attributesForCharacterIndex.
DLOG(INFO) << "attributesForCharacterIndex: " << position;
@try {
Expand Down
2 changes: 1 addition & 1 deletion src/mac/mozc_imk_input_controller_test.mm
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ BOOL SendKeyEvent(unsigned short keyCode, MozcImkInputController *controller,
// create an output
commands::Output output;
// a candidate has to have at least a candidate
commands::CandidateWindow *candidate_window = output.mutable_candidates();
commands::CandidateWindow *candidate_window = output.mutable_candidate_window();
candidate_window->set_focused_index(0);
candidate_window->set_size(1);
commands::CandidateWindow::Candidate *candidate = candidate_window->add_candidate();
Expand Down
3 changes: 1 addition & 2 deletions src/protocol/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1339,8 +1339,7 @@ message Output {
optional bool consumed = 3;
optional Result result = 4;
optional Preedit preedit = 5;
// TODO(b/372854886): Follow up renaming to candidate_window.
optional CandidateWindow candidates = 6;
optional CandidateWindow candidate_window = 6;
optional KeyEvent key = 7;

// when URL is non empty, UI can open the page with a browser,
Expand Down
24 changes: 13 additions & 11 deletions src/renderer/mac/CandidateController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,20 @@ int GetBaseScreenHeight() {
return true;
}

candidate_window_->SetCandidateWindow(command_.output().candidates());
candidate_window_->SetCandidateWindow(command_.output().candidate_window());

bool cascading_visible = false;
if (command_.output().has_candidates() && command_.output().candidates().has_subcandidates()) {
cascading_window_->SetCandidateWindow(command_.output().candidates().subcandidates());
if (command_.output().has_candidate_window() &&
command_.output().candidate_window().has_subcandidates()) {
cascading_window_->SetCandidateWindow(command_.output().candidate_window().subcandidates());
cascading_visible = true;
}

bool infolist_visible = false;
if (command_.output().has_candidates() && command_.output().candidates().has_usages() &&
command_.output().candidates().usages().information_size() > 0) {
infolist_window_->SetCandidateWindow(command_.output().candidates());
if (command_.output().has_candidate_window() &&
command_.output().candidate_window().has_usages() &&
command_.output().candidate_window().usages().information_size() > 0) {
infolist_window_->SetCandidateWindow(command_.output().candidate_window());
infolist_visible = true;
}

Expand All @@ -171,7 +173,7 @@ int GetBaseScreenHeight() {
}

if (infolist_visible && !cascading_visible) {
const commands::CandidateWindow &candidate_window = command_.output().candidates();
const commands::CandidateWindow &candidate_window = command_.output().candidate_window();
if (candidate_window.has_focused_index() && candidate_window.candidate_size() > 0) {
const int focused_row =
candidate_window.focused_index() - candidate_window.candidate(0).index();
Expand Down Expand Up @@ -247,15 +249,15 @@ int GetBaseScreenHeight() {

// If there is no need to show cascading window, we just finish the
// function here.
if (!command_.output().has_candidates() ||
!(command_.output().candidates().candidate_size() > 0) ||
!command_.output().candidates().has_subcandidates()) {
if (!command_.output().has_candidate_window() ||
!(command_.output().candidate_window().candidate_size() > 0) ||
!command_.output().candidate_window().has_subcandidates()) {
return;
}

// Fix cascading window position
// 1. starting position is at the focused row
const commands::CandidateWindow &candidate_window = command_.output().candidates();
const commands::CandidateWindow &candidate_window = command_.output().candidate_window();
const int focused_row = candidate_window.focused_index() - candidate_window.candidate(0).index();
mozc::Rect focused_rect = candidate_layout->GetRowRect(focused_row);
// move the focused_rect to the monitor's coordinates
Expand Down
25 changes: 14 additions & 11 deletions src/renderer/qt/qt_window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ void QtWindowManager::OnClicked(int row, int column) {
if (send_command_interface_ == nullptr) {
return;
}
if (row < 0 || row >= prev_command_.output().candidates().candidate_size()) {
if (row < 0 ||
row >= prev_command_.output().candidate_window().candidate_size()) {
return;
}
const int cand_id = prev_command_.output().candidates().candidate(row).id();
const int cand_id =
prev_command_.output().candidate_window().candidate(row).id();
commands::SessionCommand command;
command.set_type(commands::SessionCommand::SELECT_CANDIDATE);
command.set_id(cand_id);
Expand Down Expand Up @@ -141,11 +143,11 @@ bool QtWindowManager::ShouldShowCandidateWindow(
DCHECK(command.has_output());
const commands::Output &output = command.output();

if (!output.has_candidates()) {
if (!output.has_candidate_window()) {
return false;
}

const commands::CandidateWindow &candidate_window = output.candidates();
const commands::CandidateWindow &candidate_window = output.candidate_window();
if (candidate_window.candidate_size() == 0) {
return false;
}
Expand Down Expand Up @@ -204,9 +206,9 @@ Rect GetRect(const commands::RendererCommand::Rectangle &prect) {
bool IsUpdated(const commands::RendererCommand &prev_command,
const commands::RendererCommand &new_command) {
const commands::CandidateWindow &prev_cands =
prev_command.output().candidates();
prev_command.output().candidate_window();
const commands::CandidateWindow &new_cands =
new_command.output().candidates();
new_command.output().candidate_window();
if (prev_cands.candidate_size() != new_cands.candidate_size()) {
return true;
}
Expand Down Expand Up @@ -426,7 +428,7 @@ Point QtWindowManager::GetWindowPosition(
Rect QtWindowManager::UpdateCandidateWindow(
const commands::RendererCommand &command) {
const commands::CandidateWindow &candidate_window =
command.output().candidates();
command.output().candidate_window();

if (IsUpdated(prev_command_, command)) {
FillCandidates(candidate_window, candidates_);
Expand All @@ -435,7 +437,8 @@ Rect QtWindowManager::UpdateCandidateWindow(
candidates_->move(win_pos.x, win_pos.y);
} else {
// Reset the previous focused highlight
const int prev_focused = GetFocusedRow(prev_command_.output().candidates());
const int prev_focused =
GetFocusedRow(prev_command_.output().candidate_window());
FillCandidateHighlight(candidate_window, prev_focused, candidates_);
}

Expand All @@ -454,12 +457,12 @@ Rect QtWindowManager::UpdateCandidateWindow(

bool QtWindowManager::ShouldShowInfolistWindow(
const commands::RendererCommand &command) {
if (!command.output().has_candidates()) {
if (!command.output().has_candidate_window()) {
return false;
}

const commands::CandidateWindow &candidate_window =
command.output().candidates();
command.output().candidate_window();
if (candidate_window.candidate_size() <= 0) {
return false;
}
Expand Down Expand Up @@ -510,7 +513,7 @@ void QtWindowManager::UpdateInfolistWindow(
infolist_->clear();

const commands::InformationList &info =
command.output().candidates().usages();
command.output().candidate_window().usages();
const size_t size = info.information_size();

infolist_->setColumnCount(1);
Expand Down
17 changes: 9 additions & 8 deletions src/renderer/win32/window_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ void WindowManager::UpdateLayout(const commands::RendererCommand &command) {

bool is_suggest = false;
bool is_convert_or_predict = false;
if (output.has_candidates() && output.candidates().has_category()) {
switch (output.candidates().category()) {
if (output.has_candidate_window() &&
output.candidate_window().has_category()) {
switch (output.candidate_window().category()) {
case commands::SUGGESTION:
is_suggest = true;
break;
Expand All @@ -178,7 +179,7 @@ void WindowManager::UpdateLayout(const commands::RendererCommand &command) {
indicator_window_->OnUpdate(command, layout_manager_.get());
}

if (!output.has_candidates()) {
if (!output.has_candidate_window()) {
// Hide candidate windows because there is no candidate to be displayed.
cascading_window_->ShowWindow(SW_HIDE);
main_window_->ShowWindow(SW_HIDE);
Expand All @@ -203,7 +204,7 @@ void WindowManager::UpdateLayout(const commands::RendererCommand &command) {
return;
}

const commands::CandidateWindow &candidate_window = output.candidates();
const commands::CandidateWindow &candidate_window = output.candidate_window();
if (candidate_window.candidate_size() == 0) {
cascading_window_->ShowWindow(SW_HIDE);
main_window_->ShowWindow(SW_HIDE);
Expand Down Expand Up @@ -291,9 +292,9 @@ void WindowManager::UpdateLayout(const commands::RendererCommand &command) {
}

bool infolist_visible = false;
if (command.output().has_candidates() &&
command.output().candidates().has_usages() &&
command.output().candidates().usages().information_size() > 0) {
if (command.output().has_candidate_window() &&
command.output().candidate_window().has_usages() &&
command.output().candidate_window().usages().information_size() > 0) {
infolist_visible = true;
}

Expand Down Expand Up @@ -321,7 +322,7 @@ void WindowManager::UpdateLayout(const commands::RendererCommand &command) {
candidate_window.candidate(focused_row).has_information_id()) {
const uint32_t delay =
std::max(static_cast<uint32_t>(0),
command.output().candidates().usages().delay());
command.output().candidate_window().usages().delay());
infolist_window_->DelayShow(delay);
} else {
infolist_window_->DelayHide(kHideWindowDelay);
Expand Down
2 changes: 1 addition & 1 deletion src/session/session_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ void SessionConverter::FillOutput(const composer::Composer &composer,
// Candidate list
if (CheckState(SUGGESTION | PREDICTION | CONVERSION) &&
candidate_list_visible_) {
FillCandidates(output->mutable_candidates());
FillCandidates(output->mutable_candidate_window());
}

// All candidate words
Expand Down
Loading

0 comments on commit ec4ff27

Please sign in to comment.