1 // Copyright 2010-2018, Google Inc. 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are 6 // met: 7 // 8 // * Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // * Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following disclaimer 12 // in the documentation and/or other materials provided with the 13 // distribution. 14 // * Neither the name of Google Inc. nor the names of its 15 // contributors may be used to endorse or promote products derived from 16 // this software without specific prior written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 // Class functions to be used for output by the Session class. 31 32 #ifndef MOZC_SESSION_INTERNAL_SESSION_OUTPUT_H_ 33 #define MOZC_SESSION_INTERNAL_SESSION_OUTPUT_H_ 34 35 #include <string> 36 37 #include "base/port.h" 38 #include "protocol/commands.pb.h" 39 40 namespace mozc { 41 42 class Segment; 43 class Segments; 44 45 namespace composer { 46 class Composer; 47 } 48 49 namespace session { 50 51 class CandidateList; 52 class Candidate; 53 54 class SessionOutput { 55 public: 56 // Fill the Candidates_Candidate protobuf with the contents of candidate. 57 static void FillCandidate(const Segment &segment, 58 const Candidate &candidate, 59 commands::Candidates_Candidate *candidate_proto); 60 61 // Fill the Candidates protobuf with the contents of candidate_list. 62 static void FillCandidates(const Segment &segment, 63 const CandidateList &candidate_list, 64 size_t position, 65 commands::Candidates *candidates_proto); 66 67 // Fill the CandidateList protobuf with the contents of 68 // candidate_list. Candidates in the candidate_list are flatten 69 // even if the candidate_list contains sub-candidate lists. 70 static void FillAllCandidateWords( 71 const Segment &segment, 72 const CandidateList &candidate_list, 73 const commands::Category category, 74 commands::CandidateList *candidate_list_proto); 75 76 // Check if the usages should be rendered on the current CandidateList status. 77 static bool ShouldShowUsages(const Segment &segment, 78 const CandidateList &cand_list); 79 80 // Fill the usages of Candidates protobuf with the contents of candidate_list. 81 static void FillUsages(const Segment &segment, 82 const CandidateList &candidate_list, 83 commands::Candidates *candidates_proto); 84 85 // Fill the access key of Candidates protobuf with the sequence of shortcuts. 86 static void FillShortcuts(const string &shortcuts, 87 commands::Candidates *candidates_proto); 88 89 // Fill the sub_label of footer_proto. This function should be 90 // called on dev_channel and unittest. 91 static void FillSubLabel(commands::Footer *footer_proto); 92 93 // Fill the footer contents of Candidates protobuf. If category is 94 // modified, true is returned. Otherwise false is returned. 95 static bool FillFooter(commands::Category category, 96 commands::Candidates *candidates_proto); 97 98 // Fill the Preedit protobuf with the contents of composer as a preedit. 99 static void FillPreedit(const composer::Composer &composer, 100 commands::Preedit *preedit); 101 102 // Fill the Preedit protobuf with the contents of segments as a conversion. 103 static void FillConversion(const Segments &segments, 104 size_t segment_index, 105 int candidate_id, 106 commands::Preedit *preedit); 107 108 enum SegmentType { 109 PREEDIT = 1, 110 CONVERSION = 2, 111 FOCUSED = 4, 112 }; 113 // Add a Preedit::Segment protobuf to the Preedit protobuf with key 114 // and value. Return true iff. new segment is added to preedit. 115 static bool AddSegment(const string &key, 116 const string &value, 117 uint32 segment_type_mask, 118 commands::Preedit *preedit); 119 120 // Fill the Result protobuf with the key and result strings 121 // for a conversion result without any text normalization. 122 static void FillConversionResultWithoutNormalization( 123 const string &key, 124 const string &result, 125 commands::Result *result_proto); 126 127 // Fill the Result protobuf with the key and result strings 128 // nomalizing the string for a conversion result. 129 static void FillConversionResult(const string &key, 130 const string &result, 131 commands::Result *result_proto); 132 133 // Fill the Result protobuf with the preedit string nomalizing the 134 // string for a preedit result. 135 static void FillPreeditResult(const string &preedit, 136 commands::Result *result_proto); 137 138 139 private: 140 DISALLOW_COPY_AND_ASSIGN(SessionOutput); 141 }; 142 143 } // namespace session 144 } // namespace mozc 145 146 #endif // MOZC_SESSION_INTERNAL_SESSION_OUTPUT_H_ 147