diff --git a/src/engine/BUILD.bazel b/src/engine/BUILD.bazel index 3ac7ec7d8..1ee3f105a 100644 --- a/src/engine/BUILD.bazel +++ b/src/engine/BUILD.bazel @@ -41,6 +41,9 @@ mozc_cc_library( name = "data_loader", srcs = ["data_loader.cc"], hdrs = ["data_loader.h"], + visibility = [ + "//engine:__subpackages__", + ], deps = [ ":modules", "//base:file_util", @@ -360,6 +363,9 @@ mozc_cc_library( name = "minimal_converter", srcs = ["minimal_converter.cc"], hdrs = ["minimal_converter.h"], + visibility = [ + "//engine:__subpackages__", + ], deps = [ ":engine_converter", ":engine_converter_interface", @@ -479,7 +485,6 @@ mozc_cc_library( hdrs = ["candidate_list.h"], visibility = [ "//engine:__subpackages__", - "//session:__subpackages__", ], deps = [ "//base:hash", @@ -496,7 +501,6 @@ mozc_cc_library( hdrs = ["engine_output.h"], visibility = [ "//engine:__subpackages__", - "//session:__subpackages__", ], deps = [ ":candidate_list", diff --git a/src/engine/engine_converter.cc b/src/engine/engine_converter.cc index ab12338e5..e2a76bb73 100644 --- a/src/engine/engine_converter.cc +++ b/src/engine/engine_converter.cc @@ -792,7 +792,7 @@ void EngineConverter::CommitPreedit(const composer::Composer &composer, const std::string key = composer.GetQueryForConversion(); const std::string preedit = composer.GetStringForSubmission(); std::string normalized_preedit = TextNormalizer::NormalizeText(preedit); - EngineOutput::FillPreeditResult(preedit, &result_); + output::FillPreeditResult(preedit, &result_); // Add ResultToken commands::ResultToken *token = result_.add_tokens(); @@ -800,8 +800,8 @@ void EngineConverter::CommitPreedit(const composer::Composer &composer, token->set_value(preedit); // Cursor offset needs to be calculated based on normalized text. - EngineOutput::FillCursorOffsetResult( - CalculateCursorOffset(normalized_preedit), &result_); + output::FillCursorOffsetResult(CalculateCursorOffset(normalized_preedit), + &result_); segments_.InitForCommit(key, normalized_preedit); CommitUsageStats(EngineConverterInterface::COMPOSITION, context); DCHECK(request_); @@ -828,9 +828,8 @@ void EngineConverter::CommitHead(size_t count, } Util::Utf8SubString(preedit, 0, *consumed_key_size, &preedit); const std::string composition = TextNormalizer::NormalizeText(preedit); - EngineOutput::FillPreeditResult(composition, &result_); - EngineOutput::FillCursorOffsetResult(CalculateCursorOffset(composition), - &result_); + output::FillPreeditResult(composition, &result_); + output::FillCursorOffsetResult(CalculateCursorOffset(composition), &result_); } void EngineConverter::Revert() { converter_->RevertConversion(&segments_); } @@ -1080,6 +1079,11 @@ void MaybeFillConfig(Segment::Candidate::Command command, } } // namespace +void EngineConverter::FillPreedit(const composer::Composer &composer, + commands::Preedit *preedit) const { + output::FillPreedit(composer, preedit); +} + void EngineConverter::FillOutput(const composer::Composer &composer, commands::Output *output) const { if (!output) { @@ -1091,7 +1095,7 @@ void EngineConverter::FillOutput(const composer::Composer &composer, } if (CheckState(COMPOSITION)) { if (!composer.Empty()) { - EngineOutput::FillPreedit(composer, output->mutable_preedit()); + output::FillPreedit(composer, output->mutable_preedit()); } } @@ -1106,7 +1110,7 @@ void EngineConverter::FillOutput(const composer::Composer &composer, // When the suggestion comes from zero query suggestion, the // composer is empty. In that case, preedit is not rendered. if (!composer.Empty()) { - EngineOutput::FillPreedit(composer, output->mutable_preedit()); + output::FillPreedit(composer, output->mutable_preedit()); } } else if (CheckState(PREDICTION | CONVERSION)) { // Conversion on Prediction or Conversion @@ -1128,7 +1132,7 @@ void EngineConverter::FillOutput(const composer::Composer &composer, // For debug. Removed candidate words through the conversion process. if (CheckState(SUGGESTION | PREDICTION | CONVERSION)) { - EngineOutput::FillRemovedCandidates( + output::FillRemovedCandidates( segments_.conversion_segment(segment_index_), output->mutable_removed_candidate_words_for_debug()); } @@ -1349,9 +1353,8 @@ bool EngineConverter::UpdateResult(size_t index, size_t size, if (consumed_key_size) { *consumed_key_size = GetConsumedPreeditSize(index, size); } - EngineOutput::FillConversionResult(preedit, conversion, &result_); - EngineOutput::FillCursorOffsetResult(CalculateCursorOffset(conversion), - &result_); + output::FillConversionResult(preedit, conversion, &result_); + output::FillCursorOffsetResult(CalculateCursorOffset(conversion), &result_); UpdateResultTokens(index, size); return true; } @@ -1480,8 +1483,8 @@ const Segment::Candidate &EngineConverter::GetSelectedCandidate( void EngineConverter::FillConversion(commands::Preedit *preedit) const { DCHECK(CheckState(PREDICTION | CONVERSION)); - EngineOutput::FillConversion(segments_, segment_index_, - candidate_list_.focused_id(), preedit); + output::FillConversion(segments_, segment_index_, + candidate_list_.focused_id(), preedit); } void EngineConverter::FillResult(commands::Result *result) const { @@ -1514,13 +1517,13 @@ void EngineConverter::FillCandidateWindow( } const Segment &segment = segments_.conversion_segment(segment_index_); - EngineOutput::FillCandidateWindow(segment, candidate_list_, position, - candidate_window); + output::FillCandidateWindow(segment, candidate_list_, position, + candidate_window); // Shortcut keys if (CheckState(PREDICTION | CONVERSION)) { - EngineOutput::FillShortcuts(GetCandidateShortcuts(selection_shortcut_), - candidate_window); + output::FillShortcuts(GetCandidateShortcuts(selection_shortcut_), + candidate_window); } // Store category @@ -1570,7 +1573,7 @@ void EngineConverter::FillCandidateWindow( } // Store footer. - EngineOutput::FillFooter(candidate_window->category(), candidate_window); + output::FillFooter(candidate_window->category(), candidate_window); } void EngineConverter::FillAllCandidateWords( @@ -1606,8 +1609,7 @@ void EngineConverter::FillAllCandidateWords( return; } const Segment &segment = segments_.conversion_segment(segment_index_); - EngineOutput::FillAllCandidateWords(segment, candidate_list_, category, - candidates); + output::FillAllCandidateWords(segment, candidate_list_, category, candidates); } void EngineConverter::FillIncognitoCandidateWords( diff --git a/src/engine/engine_converter.h b/src/engine/engine_converter.h index 886edbb94..435137d0d 100644 --- a/src/engine/engine_converter.h +++ b/src/engine/engine_converter.h @@ -226,6 +226,10 @@ class EngineConverter : public EngineConverterInterface { void PopOutput(const composer::Composer &composer, commands::Output *output) override; + // Fills preedit + void FillPreedit(const composer::Composer &composer, + commands::Preedit *preedit) const override; + // Fills protocol buffers void FillOutput(const composer::Composer &composer, commands::Output *output) const override; diff --git a/src/engine/engine_converter_interface.h b/src/engine/engine_converter_interface.h index 794536fc5..307b2095e 100644 --- a/src/engine/engine_converter_interface.h +++ b/src/engine/engine_converter_interface.h @@ -213,6 +213,10 @@ class EngineConverterInterface { virtual void PopOutput(const composer::Composer &composer, commands::Output *output) = 0; + // Fill preedit + virtual void FillPreedit(const composer::Composer &composer, + commands::Preedit *preedit) const = 0; + // Fill protocol buffers virtual void FillOutput(const composer::Composer &composer, commands::Output *output) const = 0; diff --git a/src/engine/engine_output.cc b/src/engine/engine_output.cc index a0e0bf148..54ab13662 100644 --- a/src/engine/engine_output.cc +++ b/src/engine/engine_output.cc @@ -161,13 +161,12 @@ void FillAllCandidateWordsInternal( candidate_word_proto); } } - } // namespace -// static -void EngineOutput::FillCandidate( - const Segment &segment, const Candidate &candidate, - commands::CandidateWindow_Candidate *candidate_proto) { +namespace output { + +void FillCandidate(const Segment &segment, const Candidate &candidate, + commands::CandidateWindow_Candidate *candidate_proto) { DCHECK(segment.is_valid_index(candidate.id())); if (candidate.HasSubcandidateList()) { @@ -191,10 +190,10 @@ void EngineOutput::FillCandidate( } } -// static -void EngineOutput::FillCandidateWindow( - const Segment &segment, const CandidateList &candidate_list, - const size_t position, commands::CandidateWindow *candidate_window_proto) { +void FillCandidateWindow(const Segment &segment, + const CandidateList &candidate_list, + const size_t position, + commands::CandidateWindow *candidate_window_proto) { if (candidate_list.focused()) { candidate_window_proto->set_focused_index(candidate_list.focused_index()); } @@ -233,20 +232,18 @@ void EngineOutput::FillCandidateWindow( FillUsages(segment, candidate_list, candidate_window_proto); } -// static -void EngineOutput::FillAllCandidateWords( - const Segment &segment, const CandidateList &candidate_list, - const commands::Category category, - commands::CandidateList *candidate_list_proto) { +void FillAllCandidateWords(const Segment &segment, + const CandidateList &candidate_list, + const commands::Category category, + commands::CandidateList *candidate_list_proto) { candidate_list_proto->set_category(category); FillAllCandidateWordsInternal(segment, candidate_list, candidate_list.focused_id(), candidate_list_proto); } -// static -void EngineOutput::FillRemovedCandidates( - const Segment &segment, commands::CandidateList *candidate_list_proto) { +void FillRemovedCandidates(const Segment &segment, + commands::CandidateList *candidate_list_proto) { int index = 1000; absl::Span candidates = segment.removed_candidates_for_debug_; @@ -258,9 +255,7 @@ void EngineOutput::FillRemovedCandidates( } } -// static -bool EngineOutput::ShouldShowUsages(const Segment &segment, - const CandidateList &cand_list) { +bool ShouldShowUsages(const Segment &segment, const CandidateList &cand_list) { // Check if the shown candidate have the usage data. for (const Candidate &candidate_ptr : cand_list.focused_page()) { if (candidate_ptr.HasSubcandidateList()) { @@ -273,10 +268,8 @@ bool EngineOutput::ShouldShowUsages(const Segment &segment, return false; } -// static -void EngineOutput::FillUsages( - const Segment &segment, const CandidateList &cand_list, - commands::CandidateWindow *candidate_window_proto) { +void FillUsages(const Segment &segment, const CandidateList &cand_list, + commands::CandidateWindow *candidate_window_proto) { if (!ShouldShowUsages(segment, cand_list)) { return; } @@ -319,10 +312,8 @@ void EngineOutput::FillUsages( } } -// static -void EngineOutput::FillShortcuts( - absl::string_view shortcuts, - commands::CandidateWindow *candidate_window_proto) { +void FillShortcuts(absl::string_view shortcuts, + commands::CandidateWindow *candidate_window_proto) { const size_t num_loop = std::min( candidate_window_proto->candidate_size(), shortcuts.size()); for (size_t i = 0; i < num_loop; ++i) { @@ -332,8 +323,7 @@ void EngineOutput::FillShortcuts( } } -// static -void EngineOutput::FillSubLabel(commands::Footer *footer) { +void FillSubLabel(commands::Footer *footer) { // Delete the label because sub_label will be drawn on the same // place for the label. footer->clear_label(); @@ -351,9 +341,8 @@ void EngineOutput::FillSubLabel(commands::Footer *footer) { } } -// static -bool EngineOutput::FillFooter(const commands::Category category, - commands::CandidateWindow *candidate_window) { +bool FillFooter(const commands::Category category, + commands::CandidateWindow *candidate_window) { if (category != commands::SUGGESTION && category != commands::PREDICTION && category != commands::CONVERSION) { return false; @@ -411,11 +400,8 @@ bool EngineOutput::FillFooter(const commands::Category category, return true; } -// static -bool EngineOutput::AddSegment(const absl::string_view key, - const absl::string_view value, - const uint32_t segment_type_mask, - commands::Preedit *preedit) { +bool AddSegment(const absl::string_view key, const absl::string_view value, + const uint32_t segment_type_mask, commands::Preedit *preedit) { // Key is always normalized as a preedit text. std::string normalized_key = TextNormalizer::NormalizeText(key); @@ -446,9 +432,8 @@ bool EngineOutput::AddSegment(const absl::string_view key, return true; } -// static -void EngineOutput::FillPreedit(const composer::Composer &composer, - commands::Preedit *preedit) { +void FillPreedit(const composer::Composer &composer, + commands::Preedit *preedit) { const std::string output = composer.GetStringForPreedit(); constexpr uint32_t kBaseType = PREEDIT; @@ -457,11 +442,8 @@ void EngineOutput::FillPreedit(const composer::Composer &composer, preedit->set_is_toggleable(composer.IsToggleable()); } -// static -void EngineOutput::FillConversion(const Segments &segments, - const size_t segment_index, - const int candidate_id, - commands::Preedit *preedit) { +void FillConversion(const Segments &segments, const size_t segment_index, + const int candidate_id, commands::Preedit *preedit) { constexpr uint32_t kBaseType = CONVERSION; // Cursor position in conversion state should be the end of the preedit. size_t cursor = 0; @@ -485,18 +467,16 @@ void EngineOutput::FillConversion(const Segments &segments, preedit->set_cursor(cursor); } -// static -void EngineOutput::FillConversionResultWithoutNormalization( - std::string key, std::string result, commands::Result *result_proto) { +void FillConversionResultWithoutNormalization(std::string key, + std::string result, + commands::Result *result_proto) { result_proto->set_type(commands::Result::STRING); result_proto->set_key(std::move(key)); result_proto->set_value(std::move(result)); } -// static -void EngineOutput::FillConversionResult(const absl::string_view key, - std::string result, - commands::Result *result_proto) { +void FillConversionResult(const absl::string_view key, std::string result, + commands::Result *result_proto) { // Key should be normalized as a preedit text. std::string normalized_key = TextNormalizer::NormalizeText(key); @@ -505,9 +485,8 @@ void EngineOutput::FillConversionResult(const absl::string_view key, std::move(result), result_proto); } -// static -void EngineOutput::FillPreeditResult(const absl::string_view preedit, - commands::Result *result_proto) { +void FillPreeditResult(const absl::string_view preedit, + commands::Result *result_proto) { std::string normalized_preedit = TextNormalizer::NormalizeText(preedit); // Copy before passing the value to FillConversionResultWithoutNormalization. // std::move() is evaluated out of order when used directly in the function @@ -517,11 +496,11 @@ void EngineOutput::FillPreeditResult(const absl::string_view preedit, std::move(key), std::move(normalized_preedit), result_proto); } -// static -void EngineOutput::FillCursorOffsetResult(int32_t cursor_offset, - commands::Result *result_proto) { +void FillCursorOffsetResult(int32_t cursor_offset, + commands::Result *result_proto) { result_proto->set_cursor_offset(cursor_offset); } +} // namespace output } // namespace engine } // namespace mozc diff --git a/src/engine/engine_output.h b/src/engine/engine_output.h index bd85fcc5f..d2c16b8db 100644 --- a/src/engine/engine_output.h +++ b/src/engine/engine_output.h @@ -45,95 +45,90 @@ namespace mozc { namespace engine { +namespace output { -class EngineOutput { - public: - EngineOutput(const EngineOutput &) = delete; - EngineOutput &operator=(const EngineOutput &) = delete; - - // Fill the CandidateWindow_Candidate protobuf with the contents of candidate. - static void FillCandidate( - const Segment &segment, const Candidate &candidate, - commands::CandidateWindow_Candidate *candidate_proto); - - // Fill the CandidateWindow protobuf with the contents of candidate_list. - static void FillCandidateWindow( - const Segment &segment, const CandidateList &candidate_list, - size_t position, commands::CandidateWindow *candidate_window_proto); - - // Fill the CandidateList protobuf with the contents of - // candidate_list. Candidates in the candidate_list are flatten - // even if the candidate_list contains sub-candidate lists. - static void FillAllCandidateWords( - const Segment &segment, const CandidateList &candidate_list, - commands::Category category, - commands::CandidateList *candidate_list_proto); - - // For debug. Fill the CandidateList protobuf with the - // removed_candidates_for_debug in the segment. - static void FillRemovedCandidates( - const Segment &segment, commands::CandidateList *candidate_list_proto); - - // Check if the usages should be rendered on the current CandidateList status. - static bool ShouldShowUsages(const Segment &segment, - const CandidateList &cand_list); - - // Fill the usages of Candidates protobuf with the contents of candidate_list. - static void FillUsages(const Segment &segment, const CandidateList &cand_list, +// Fill the CandidateWindow_Candidate protobuf with the contents of candidate. +void FillCandidate(const Segment &segment, const Candidate &candidate, + commands::CandidateWindow_Candidate *candidate_proto); + +// Fill the CandidateWindow protobuf with the contents of candidate_list. +void FillCandidateWindow(const Segment &segment, + const CandidateList &candidate_list, size_t position, commands::CandidateWindow *candidate_window_proto); - // Fill the access key of Candidates protobuf with the sequence of shortcuts. - static void FillShortcuts(absl::string_view shortcuts, - commands::CandidateWindow *candidate_window_proto); +// Fill the CandidateList protobuf with the contents of +// candidate_list. Candidates in the candidate_list are flatten +// even if the candidate_list contains sub-candidate lists. +void FillAllCandidateWords(const Segment &segment, + const CandidateList &candidate_list, + commands::Category category, + commands::CandidateList *candidate_list_proto); + +// For debug. Fill the CandidateList protobuf with the +// removed_candidates_for_debug in the segment. +void FillRemovedCandidates(const Segment &segment, + commands::CandidateList *candidate_list_proto); + +// Check if the usages should be rendered on the current CandidateList status. +bool ShouldShowUsages(const Segment &segment, const CandidateList &cand_list); + +// Fill the usages of Candidates protobuf with the contents of candidate_list. +void FillUsages(const Segment &segment, const CandidateList &cand_list, + commands::CandidateWindow *candidate_window_proto); + +// Fill the access key of Candidates protobuf with the sequence of shortcuts. +void FillShortcuts(absl::string_view shortcuts, + commands::CandidateWindow *candidate_window_proto); + +// Fill the sub_label of footer_proto. This function should be +// called on dev_channel and unittest. +void FillSubLabel(commands::Footer *footer_proto); + +// Fill the footer contents of Candidates protobuf. If category is +// modified, true is returned. Otherwise false is returned. +bool FillFooter(commands::Category category, + commands::CandidateWindow *candidate_window_proto); + +// Fill the Preedit protobuf with the contents of composer as a preedit. +void FillPreedit(const composer::Composer &composer, + commands::Preedit *preedit); + +// Fill the Preedit protobuf with the contents of segments as a conversion. +void FillConversion(const Segments &segments, size_t segment_index, + int candidate_id, commands::Preedit *preedit); + +enum SegmentType { + PREEDIT = 1, + CONVERSION = 2, + FOCUSED = 4, +}; - // Fill the sub_label of footer_proto. This function should be - // called on dev_channel and unittest. - static void FillSubLabel(commands::Footer *footer_proto); +// Add a Preedit::Segment protobuf to the Preedit protobuf with key +// and value. Return true iff. new segment is added to preedit. +bool AddSegment(absl::string_view, absl::string_view value, + uint32_t segment_type_mask, commands::Preedit *preedit); - // Fill the footer contents of Candidates protobuf. If category is - // modified, true is returned. Otherwise false is returned. - static bool FillFooter(commands::Category category, - commands::CandidateWindow *candidate_window_proto); +// Fill the Result protobuf with the key and result strings +// for a conversion result without any text normalization. +void FillConversionResultWithoutNormalization(std::string key, + std::string result, + commands::Result *result_proto); - // Fill the Preedit protobuf with the contents of composer as a preedit. - static void FillPreedit(const composer::Composer &composer, - commands::Preedit *preedit); - - // Fill the Preedit protobuf with the contents of segments as a conversion. - static void FillConversion(const Segments &segments, size_t segment_index, - int candidate_id, commands::Preedit *preedit); - - enum SegmentType { - PREEDIT = 1, - CONVERSION = 2, - FOCUSED = 4, - }; - // Add a Preedit::Segment protobuf to the Preedit protobuf with key - // and value. Return true iff. new segment is added to preedit. - static bool AddSegment(absl::string_view, absl::string_view value, - uint32_t segment_type_mask, - commands::Preedit *preedit); - - // Fill the Result protobuf with the key and result strings - // for a conversion result without any text normalization. - static void FillConversionResultWithoutNormalization( - std::string key, std::string result, commands::Result *result_proto); - - // Fill the Result protobuf with the key and result strings - // normalizing the string for a conversion result. - static void FillConversionResult(absl::string_view key, std::string result, - commands::Result *result_proto); - - // Fill the Result protobuf with the preedit string normalizing the - // string for a preedit result. - static void FillPreeditResult(absl::string_view preedit, - commands::Result *result_proto); - - // Fill the Result protobuf with cursor offset. - static void FillCursorOffsetResult(int32_t cursor_offset, - commands::Result *result_proto); -}; +// Fill the Result protobuf with the key and result strings +// normalizing the string for a conversion result. +void FillConversionResult(absl::string_view key, std::string result, + commands::Result *result_proto); + +// Fill the Result protobuf with the preedit string normalizing the +// string for a preedit result. +void FillPreeditResult(absl::string_view preedit, + commands::Result *result_proto); + +// Fill the Result protobuf with cursor offset. +void FillCursorOffsetResult(int32_t cursor_offset, + commands::Result *result_proto); +} // namespace output } // namespace engine } // namespace mozc diff --git a/src/engine/engine_output_test.cc b/src/engine/engine_output_test.cc index 2a42d03e9..b6765736d 100644 --- a/src/engine/engine_output_test.cc +++ b/src/engine/engine_output_test.cc @@ -94,7 +94,7 @@ TEST(EngineOutputTest, FillCandidate) { candidate_list.AddCandidate(-789, "minus 789"); candidate.set_id(13); - EngineOutput::FillCandidate(segment, candidate, &candidate_proto); + output::FillCandidate(segment, candidate, &candidate_proto); EXPECT_EQ(candidate_proto.id(), 13); EXPECT_EQ(candidate_proto.value(), kValue13); EXPECT_FALSE(candidate_proto.has_annotation()); @@ -102,7 +102,7 @@ TEST(EngineOutputTest, FillCandidate) { candidate.Clear(); candidate_proto.Clear(); candidate.set_id(42); - EngineOutput::FillCandidate(segment, candidate, &candidate_proto); + output::FillCandidate(segment, candidate, &candidate_proto); EXPECT_EQ(candidate_proto.id(), 42); EXPECT_EQ(candidate_proto.value(), kValue42); EXPECT_TRUE(candidate_proto.has_annotation()); @@ -113,7 +113,7 @@ TEST(EngineOutputTest, FillCandidate) { candidate.Clear(); candidate_proto.Clear(); candidate.set_subcandidate_list(&candidate_list); - EngineOutput::FillCandidate(segment, candidate, &candidate_proto); + output::FillCandidate(segment, candidate, &candidate_proto); EXPECT_TRUE(candidate_proto.has_id()); EXPECT_EQ(candidate_proto.id(), kFirstIdInSubList); EXPECT_EQ(candidate_proto.value(), kSubcandidateList); @@ -146,8 +146,8 @@ TEST(EngineOutputTest, FillCandidateWindow) { subcandidate_list.AddCandidate(4, "4"); // Focused index = 0. page_size = 9. - EngineOutput::FillCandidateWindow(segment, candidate_list, 0, - &candidate_window_proto); + output::FillCandidateWindow(segment, candidate_list, 0, + &candidate_window_proto); EXPECT_EQ(candidate_window_proto.page_size(), 9); EXPECT_EQ(candidate_window_proto.candidate_size(), 3); EXPECT_EQ(candidate_window_proto.position(), 0); @@ -162,8 +162,8 @@ TEST(EngineOutputTest, FillCandidateWindow) { candidate_window_proto.Clear(); candidate_list.MoveToId(3); candidate_list.set_page_size(5); - EngineOutput::FillCandidateWindow(segment, candidate_list, 1, - &candidate_window_proto); + output::FillCandidateWindow(segment, candidate_list, 1, + &candidate_window_proto); EXPECT_EQ(candidate_window_proto.page_size(), 5); EXPECT_EQ(candidate_window_proto.candidate_size(), 3); EXPECT_EQ(candidate_window_proto.position(), 1); @@ -194,8 +194,8 @@ TEST(EngineOutputTest, FillCandidateWindow) { candidate_window_proto.Clear(); candidate_list.set_focused(false); subcandidate_list.set_focused(true); - EngineOutput::FillCandidateWindow(segment, candidate_list, 0, - &candidate_window_proto); + output::FillCandidateWindow(segment, candidate_list, 0, + &candidate_window_proto); EXPECT_FALSE(candidate_window_proto.has_focused_index()); EXPECT_TRUE( candidate_window_proto.sub_candidate_window().has_focused_index()); @@ -203,8 +203,8 @@ TEST(EngineOutputTest, FillCandidateWindow) { candidate_window_proto.Clear(); candidate_list.set_focused(false); subcandidate_list.set_focused(false); - EngineOutput::FillCandidateWindow(segment, candidate_list, 0, - &candidate_window_proto); + output::FillCandidateWindow(segment, candidate_list, 0, + &candidate_window_proto); EXPECT_FALSE(candidate_window_proto.has_focused_index()); EXPECT_FALSE( candidate_window_proto.sub_candidate_window().has_focused_index()); @@ -212,8 +212,8 @@ TEST(EngineOutputTest, FillCandidateWindow) { candidate_window_proto.Clear(); candidate_list.set_focused(true); subcandidate_list.set_focused(false); - EngineOutput::FillCandidateWindow(segment, candidate_list, 0, - &candidate_window_proto); + output::FillCandidateWindow(segment, candidate_list, 0, + &candidate_window_proto); EXPECT_TRUE(candidate_window_proto.has_focused_index()); EXPECT_FALSE( candidate_window_proto.sub_candidate_window().has_focused_index()); @@ -289,8 +289,8 @@ TEST(EngineOutputTest, FillAllCandidateWords) { // Execute FillAllCandidateWords const commands::Category kCategory = commands::PREDICTION; - EngineOutput::FillAllCandidateWords(segment, main_list, kCategory, - &candidates_proto); + output::FillAllCandidateWords(segment, main_list, kCategory, + &candidates_proto); // Varidation EXPECT_EQ(candidates_proto.focused_index(), 1); @@ -387,8 +387,8 @@ TEST(EngineOutputTest, FillAllCandidateWords_Attributes) { // Execute FillAllCandidateWords const commands::Category kCategory = commands::PREDICTION; - EngineOutput::FillAllCandidateWords(segment, candidate_list, kCategory, - &candidates_proto); + output::FillAllCandidateWords(segment, candidate_list, kCategory, + &candidates_proto); // Varidation EXPECT_EQ(candidates_proto.focused_index(), 0); @@ -427,7 +427,7 @@ TEST(EngineOutputTest, ShouldShowUsages) { candidate_list.AddSubCandidateList(&sub); candidate_list.set_focused(true); ASSERT_TRUE(candidate_list.MoveToId(0)); - ASSERT_FALSE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_FALSE(output::ShouldShowUsages(segment, candidate_list)); } { Segment segment; @@ -441,7 +441,7 @@ TEST(EngineOutputTest, ShouldShowUsages) { candidate_list.AddSubCandidateList(&sub); candidate_list.set_focused(true); ASSERT_TRUE(candidate_list.MoveToId(0)); - ASSERT_TRUE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_TRUE(output::ShouldShowUsages(segment, candidate_list)); } { Segment segment; @@ -470,19 +470,19 @@ TEST(EngineOutputTest, ShouldShowUsages) { // [00-08],[09-17],[18-26],[27-29]+subcandidate candidate_list.set_focused(true); ASSERT_TRUE(candidate_list.MoveToId(0)); - ASSERT_TRUE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_TRUE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(8)); - ASSERT_TRUE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_TRUE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(9)); - ASSERT_TRUE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_TRUE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(17)); - ASSERT_TRUE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_TRUE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(18)); - ASSERT_FALSE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_FALSE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(26)); - ASSERT_FALSE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_FALSE(output::ShouldShowUsages(segment, candidate_list)); ASSERT_TRUE(candidate_list.MoveToId(27)); - ASSERT_FALSE(EngineOutput::ShouldShowUsages(segment, candidate_list)); + ASSERT_FALSE(output::ShouldShowUsages(segment, candidate_list)); } } @@ -533,7 +533,7 @@ TEST(EngineOutputTest, FillUsages) { candidate_list.MoveToId(2); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); // There is no focused usage. EXPECT_FALSE(candidate_window_proto.usages().has_focused_index()); @@ -551,7 +551,7 @@ TEST(EngineOutputTest, FillUsages) { candidate_list.MoveToId(12); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); // Focused usage index is 20 EXPECT_TRUE(candidate_window_proto.usages().has_focused_index()); @@ -580,7 +580,7 @@ TEST(EngineOutputTest, FillUsages) { candidate_list.MoveToId(19); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); EXPECT_TRUE(candidate_window_proto.usages().has_focused_index()); EXPECT_EQ(candidate_window_proto.usages().focused_index(), 0); @@ -599,7 +599,7 @@ TEST(EngineOutputTest, FillUsages) { candidate_list.MoveToId(20); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); EXPECT_TRUE(candidate_window_proto.usages().has_focused_index()); EXPECT_EQ(candidate_window_proto.usages().focused_index(), 1); @@ -607,7 +607,7 @@ TEST(EngineOutputTest, FillUsages) { // usages(id:100) of "val19" and "val21" are merged candidate_list.MoveToId(21); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); EXPECT_TRUE(candidate_window_proto.usages().has_focused_index()); EXPECT_EQ(candidate_window_proto.usages().focused_index(), 0); @@ -615,14 +615,14 @@ TEST(EngineOutputTest, FillUsages) { // usages(id:110) of "val20" and "val22" are merged candidate_list.MoveToId(22); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_TRUE(candidate_window_proto.has_usages()); EXPECT_TRUE(candidate_window_proto.usages().has_focused_index()); EXPECT_EQ(candidate_window_proto.usages().focused_index(), 1); candidate_list.MoveToId(28); candidate_window_proto.Clear(); - EngineOutput::FillUsages(segment, candidate_list, &candidate_window_proto); + output::FillUsages(segment, candidate_list, &candidate_window_proto); ASSERT_FALSE(candidate_window_proto.has_usages()); } @@ -635,7 +635,7 @@ TEST(EngineOutputTest, FillShortcuts) { } ASSERT_EQ(candidate_window_proto1.candidate_size(), 10); - EngineOutput::FillShortcuts(kDigits, &candidate_window_proto1); + output::FillShortcuts(kDigits, &candidate_window_proto1); EXPECT_EQ(candidate_window_proto1.candidate(0).annotation().shortcut(), kDigits.substr(0, 1)); EXPECT_EQ(candidate_window_proto1.candidate(8).annotation().shortcut(), @@ -649,7 +649,7 @@ TEST(EngineOutputTest, FillShortcuts) { } ASSERT_EQ(candidate_window_proto2.candidate_size(), 3); - EngineOutput::FillShortcuts(kDigits, &candidate_window_proto2); + output::FillShortcuts(kDigits, &candidate_window_proto2); EXPECT_EQ(candidate_window_proto2.candidate(0).annotation().shortcut(), kDigits.substr(0, 1)); EXPECT_EQ(candidate_window_proto2.candidate(2).annotation().shortcut(), @@ -658,8 +658,7 @@ TEST(EngineOutputTest, FillShortcuts) { TEST(EngineOutputTest, FillFooter) { commands::CandidateWindow candidate_window; - EXPECT_TRUE( - EngineOutput::FillFooter(commands::SUGGESTION, &candidate_window)); + EXPECT_TRUE(output::FillFooter(commands::SUGGESTION, &candidate_window)); EXPECT_TRUE(candidate_window.has_footer()); #if defined(CHANNEL_DEV) && defined(GOOGLE_JAPANESE_INPUT_BUILD) @@ -677,16 +676,14 @@ TEST(EngineOutputTest, FillFooter) { EXPECT_FALSE(candidate_window.footer().logo_visible()); candidate_window.Clear(); - EXPECT_TRUE( - EngineOutput::FillFooter(commands::PREDICTION, &candidate_window)); + EXPECT_TRUE(output::FillFooter(commands::PREDICTION, &candidate_window)); EXPECT_TRUE(candidate_window.has_footer()); EXPECT_FALSE(candidate_window.footer().has_label()); EXPECT_TRUE(candidate_window.footer().index_visible()); EXPECT_TRUE(candidate_window.footer().logo_visible()); candidate_window.Clear(); - EXPECT_TRUE( - EngineOutput::FillFooter(commands::CONVERSION, &candidate_window)); + EXPECT_TRUE(output::FillFooter(commands::CONVERSION, &candidate_window)); EXPECT_TRUE(candidate_window.has_footer()); EXPECT_FALSE(candidate_window.footer().has_label()); EXPECT_TRUE(candidate_window.footer().index_visible()); @@ -694,11 +691,11 @@ TEST(EngineOutputTest, FillFooter) { candidate_window.Clear(); EXPECT_FALSE( - EngineOutput::FillFooter(commands::TRANSLITERATION, &candidate_window)); + output::FillFooter(commands::TRANSLITERATION, &candidate_window)); EXPECT_FALSE(candidate_window.has_footer()); candidate_window.Clear(); - EXPECT_FALSE(EngineOutput::FillFooter(commands::USAGE, &candidate_window)); + EXPECT_FALSE(output::FillFooter(commands::USAGE, &candidate_window)); EXPECT_FALSE(candidate_window.has_footer()); candidate_window.Clear(); @@ -713,8 +710,7 @@ TEST(EngineOutputTest, FillFooter) { for (int i = 0; i < 20; ++i) { candidate_window.clear_footer(); candidate_window.set_focused_index(i); - EXPECT_TRUE( - EngineOutput::FillFooter(commands::PREDICTION, &candidate_window)); + EXPECT_TRUE(output::FillFooter(commands::PREDICTION, &candidate_window)); if (i % 2 == 0) { ASSERT_TRUE(candidate_window.has_footer()); ASSERT_TRUE(candidate_window.footer().has_label()); @@ -739,7 +735,7 @@ TEST(EngineOutputTest, FillFooter) { TEST(EngineOutputTest, FillSubLabel) { commands::Footer footer; footer.set_label("to be deleted"); - EngineOutput::FillSubLabel(&footer); + output::FillSubLabel(&footer); EXPECT_TRUE(footer.has_sub_label()); EXPECT_FALSE(footer.has_label()); EXPECT_GT(footer.sub_label().size(), 6); // 6 == strlen("build ") @@ -754,8 +750,8 @@ TEST(EngineOutputTest, AddSegment) { // "〜" is a character to be processed by TextNormalizer::NormalizeText const std::string kKey = "ゔ〜 preedit focused"; const std::string kValue = "ゔ〜 PREEDIT FOCUSED"; - const int types = EngineOutput::PREEDIT | EngineOutput::FOCUSED; - EXPECT_TRUE(EngineOutput::AddSegment(kKey, kValue, types, &preedit)); + const int types = output::PREEDIT | output::FOCUSED; + EXPECT_TRUE(output::AddSegment(kKey, kValue, types, &preedit)); EXPECT_EQ(preedit.segment_size(), index + 1); const commands::Preedit::Segment &segment = preedit.segment(index); @@ -771,8 +767,8 @@ TEST(EngineOutputTest, AddSegment) { { const std::string kKey = "ゔ〜 preedit"; const std::string kValue = "ゔ〜 PREEDIT"; - const int types = EngineOutput::PREEDIT; - EXPECT_TRUE(EngineOutput::AddSegment(kKey, kValue, types, &preedit)); + const int types = output::PREEDIT; + EXPECT_TRUE(output::AddSegment(kKey, kValue, types, &preedit)); EXPECT_EQ(preedit.segment_size(), index + 1); const commands::Preedit::Segment &segment = preedit.segment(index); @@ -788,8 +784,8 @@ TEST(EngineOutputTest, AddSegment) { { const std::string kKey = "ゔ〜 conversion focused"; const std::string kValue = "ゔ〜 CONVERSION FOCUSED"; - const int types = EngineOutput::CONVERSION | EngineOutput::FOCUSED; - EXPECT_TRUE(EngineOutput::AddSegment(kKey, kValue, types, &preedit)); + const int types = output::CONVERSION | output::FOCUSED; + EXPECT_TRUE(output::AddSegment(kKey, kValue, types, &preedit)); EXPECT_EQ(preedit.segment_size(), index + 1); const commands::Preedit::Segment &segment = preedit.segment(index); @@ -806,8 +802,8 @@ TEST(EngineOutputTest, AddSegment) { { const std::string kKey = "ゔ〜 conversion"; const std::string kValue = "ゔ〜 CONVERSION"; - const int types = EngineOutput::CONVERSION; - EXPECT_TRUE(EngineOutput::AddSegment(kKey, kValue, types, &preedit)); + const int types = output::CONVERSION; + EXPECT_TRUE(output::AddSegment(kKey, kValue, types, &preedit)); EXPECT_EQ(preedit.segment_size(), index + 1); const commands::Preedit::Segment &segment = preedit.segment(index); @@ -824,8 +820,8 @@ TEST(EngineOutputTest, AddSegment) { { const std::string kKey = "abc"; const std::string kValue = ""; // empty value - const int types = EngineOutput::CONVERSION; - EXPECT_FALSE(EngineOutput::AddSegment(kKey, kValue, types, &preedit)); + const int types = output::CONVERSION; + EXPECT_FALSE(output::AddSegment(kKey, kValue, types, &preedit)); EXPECT_EQ(preedit.segment_size(), index); } } @@ -834,8 +830,7 @@ TEST(EngineOutputTest, FillConversionResultWithoutNormalization) { constexpr char kInput[] = "ゔ"; commands::Result result; - EngineOutput::FillConversionResultWithoutNormalization(kInput, kInput, - &result); + output::FillConversionResultWithoutNormalization(kInput, kInput, &result); EXPECT_EQ(result.type(), commands::Result::STRING); EXPECT_EQ(result.key(), kInput); // should not be normalized EXPECT_EQ(result.value(), kInput); // should not be normalized @@ -843,7 +838,7 @@ TEST(EngineOutputTest, FillConversionResultWithoutNormalization) { TEST(EngineOutputTest, FillConversionResult) { commands::Result result; - EngineOutput::FillConversionResult("abc", "ABC", &result); + output::FillConversionResult("abc", "ABC", &result); EXPECT_EQ(result.type(), commands::Result::STRING); EXPECT_EQ(result.key(), "abc"); EXPECT_EQ(result.value(), "ABC"); @@ -851,13 +846,13 @@ TEST(EngineOutputTest, FillConversionResult) { TEST(EngineOutputTest, FillCursorOffsetResult) { commands::Result result; - EngineOutput::FillCursorOffsetResult(-1, &result); + output::FillCursorOffsetResult(-1, &result); EXPECT_EQ(result.cursor_offset(), -1); } TEST(EngineOutputTest, FillPreeditResult) { commands::Result result; - EngineOutput::FillPreeditResult("ABC", &result); + output::FillPreeditResult("ABC", &result); EXPECT_EQ(result.type(), commands::Result::STRING); EXPECT_EQ(result.key(), "ABC"); EXPECT_EQ(result.value(), "ABC"); @@ -883,8 +878,8 @@ TEST(EngineOutputTest, FillAllCandidateWords_NonFocused) { { // Execute FillAllCandidateWords const commands::Category kCategory = commands::SUGGESTION; - EngineOutput::FillAllCandidateWords(segment, main_list, kCategory, - &candidates_proto); + output::FillAllCandidateWords(segment, main_list, kCategory, + &candidates_proto); // Varidation EXPECT_FALSE(candidates_proto.has_focused_index()); @@ -895,8 +890,8 @@ TEST(EngineOutputTest, FillAllCandidateWords_NonFocused) { // When the category is SUGGESTION, has_focused_index never return true in // real usage. This is just a test case. const commands::Category kCategory = commands::SUGGESTION; - EngineOutput::FillAllCandidateWords(segment, main_list, kCategory, - &candidates_proto); + output::FillAllCandidateWords(segment, main_list, kCategory, + &candidates_proto); // Validation // If a candidate is focused, true is expected. @@ -918,7 +913,7 @@ TEST(EngineOutputTest, FillRemovedCandidateWords) { segment.removed_candidates_for_debug_.push_back(candidate); // Execute FillAllCandidateWords - EngineOutput::FillRemovedCandidates(segment, &candidates_proto); + output::FillRemovedCandidates(segment, &candidates_proto); } } // namespace engine diff --git a/src/session/BUILD.bazel b/src/session/BUILD.bazel index 45dad445b..c0bdd9faf 100644 --- a/src/session/BUILD.bazel +++ b/src/session/BUILD.bazel @@ -61,7 +61,6 @@ mozc_cc_library( "//composer:table", "//engine:engine_converter_interface", "//engine:engine_interface", - "//engine:engine_output", "//protocol:commands_cc_proto", "//protocol:config_cc_proto", "//testing:friend_test", diff --git a/src/session/session.cc b/src/session/session.cc index 0951025ef..8bfeaddcf 100644 --- a/src/session/session.cc +++ b/src/session/session.cc @@ -51,7 +51,6 @@ #include "composer/table.h" #include "engine/engine_converter_interface.h" #include "engine/engine_interface.h" -#include "engine/engine_output.h" #include "protocol/commands.pb.h" #include "protocol/config.pb.h" #include "session/ime_context.h" @@ -2749,9 +2748,8 @@ void Session::OutputMode(commands::Command *command) const { void Session::OutputComposition(commands::Command *command) const { OutputMode(command); - commands::Preedit *preedit = command->mutable_output()->mutable_preedit(); - // TODO(taku): Removes the dependency to SessionOutput. - engine::EngineOutput::FillPreedit(context_->composer(), preedit); + context_->converter().FillPreedit( + context_->composer(), command->mutable_output()->mutable_preedit()); } void Session::OutputKey(commands::Command *command) const {