Skip to content

Commit

Permalink
Update the type of candidates from Candidates to CandidateWindow.
Browse files Browse the repository at this point in the history
* follow-up to cl/686787899

#codehealth

PiperOrigin-RevId: 688006418
  • Loading branch information
hiroyuki-komatsu committed Oct 21, 2024
1 parent 7042ce5 commit ad30419
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/unix/ibus/candidate_window_handler_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "testing/gmock.h"
#include "testing/gunit.h"

using mozc::commands::Candidates;
using mozc::commands::CandidateWindow;
using mozc::commands::Command;
using mozc::commands::Output;
using mozc::commands::RendererCommand;
Expand All @@ -49,7 +49,7 @@ using mozc::renderer::RendererMock;
using ::testing::AllOf;
using ::testing::Property;
using ::testing::Return;
typedef mozc::commands::Candidates_Candidate Candidate;
typedef mozc::commands::CandidateWindow_Candidate Candidate;
typedef mozc::commands::RendererCommand_ApplicationInfo ApplicationInfo;

namespace mozc {
Expand Down Expand Up @@ -250,7 +250,7 @@ TEST(CandidateWindowHandlerTest, UpdateTest) {
"If there is at least one candidate, "
"visibility expects true");
Output output;
Candidates *candidates = output.mutable_candidates();
CandidateWindow *candidates = output.mutable_candidates();
Candidate *candidate = candidates->add_candidate();
candidate->set_index(sample_idx1);
candidate->set_value(sample_candidate1);
Expand All @@ -264,8 +264,8 @@ TEST(CandidateWindowHandlerTest, UpdateTest) {
SCOPED_TRACE("Update last updated output protobuf object.");
Output output1;
Output output2;
Candidates *candidates1 = output1.mutable_candidates();
Candidates *candidates2 = output2.mutable_candidates();
CandidateWindow *candidates1 = output1.mutable_candidates();
CandidateWindow *candidates2 = output2.mutable_candidates();
Candidate *candidate1 = candidates1->add_candidate();
Candidate *candidate2 = candidates2->add_candidate();
candidate1->set_index(sample_idx1);
Expand Down
13 changes: 7 additions & 6 deletions src/unix/ibus/ibus_candidate_window_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace {
constexpr size_t kPageSize = 9;

// Returns a text for the candidate footer.
std::string GetFooterText(const commands::Candidates &candidates) {
std::string GetFooterText(const commands::CandidateWindow &candidates) {
if (!candidates.has_footer()) {
return "";
}
Expand Down Expand Up @@ -77,7 +77,7 @@ std::string GetFooterText(const commands::Candidates &candidates) {

void IBusCandidateWindowHandler::Update(IbusEngineWrapper *engine,
const commands::Output &output) {
UpdateCandidates(engine, output);
UpdateCandidateWindow(engine, output);
UpdateAuxiliaryText(engine, output);
}

Expand All @@ -97,14 +97,14 @@ void IBusCandidateWindowHandler::Show(IbusEngineWrapper *engine) {
}

// TODO(hsumita): Writes test for this method.
bool IBusCandidateWindowHandler::UpdateCandidates(
bool IBusCandidateWindowHandler::UpdateCandidateWindow(
IbusEngineWrapper *engine, const commands::Output &output) {
if (!output.has_candidates() || output.candidates().candidate_size() == 0) {
engine->HideLookupTable();
return true;
}

const commands::Candidates &candidates = output.candidates();
const commands::CandidateWindow &candidates = output.candidates();
const bool cursor_visible = candidates.has_focused_index();
int cursor_pos = 0;
if (candidates.has_focused_index()) {
Expand All @@ -122,14 +122,15 @@ bool IBusCandidateWindowHandler::UpdateCandidates(
page_size = candidates.candidate_size();
}
IbusLookupTableWrapper table(page_size, cursor_pos, cursor_visible);
if (candidates.direction() == commands::Candidates::VERTICAL) {
if (candidates.direction() == commands::CandidateWindow::VERTICAL) {
table.SetOrientation(IBUS_ORIENTATION_VERTICAL);
} else {
table.SetOrientation(IBUS_ORIENTATION_HORIZONTAL);
}

for (int i = 0; i < candidates.candidate_size(); ++i) {
const commands::Candidates::Candidate &candidate = candidates.candidate(i);
const commands::CandidateWindow::Candidate &candidate =
candidates.candidate(i);
table.AppendCandidate(candidate.value());

const bool has_label =
Expand Down
4 changes: 2 additions & 2 deletions src/unix/ibus/ibus_candidate_window_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class IBusCandidateWindowHandler : public CandidateWindowHandlerInterface {
private:
bool UpdateAuxiliaryText(IbusEngineWrapper *engine,
const commands::Output &output);
bool UpdateCandidates(IbusEngineWrapper *engine,
const commands::Output &output);
bool UpdateCandidateWindow(IbusEngineWrapper *engine,
const commands::Output &output);
};

} // namespace ibus
Expand Down
2 changes: 1 addition & 1 deletion src/unix/ibus/mozc_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ bool MozcEngine::UpdateCandidateIDMapping(const commands::Output &output) {
}

unique_candidate_ids_.clear();
const commands::Candidates &candidates = output.candidates();
const commands::CandidateWindow &candidates = output.candidates();
for (int i = 0; i < candidates.candidate_size(); ++i) {
if (candidates.candidate(i).has_id()) {
const int32_t id = candidates.candidate(i).id();
Expand Down

0 comments on commit ad30419

Please sign in to comment.