Skip to content

Commit

Permalink
Rename Candidates to CandidateWindow for better readability.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 686787899
  • Loading branch information
Ruihao Huang authored and hiroyuki-komatsu committed Oct 17, 2024
1 parent 2eaa6aa commit 2deaf6d
Show file tree
Hide file tree
Showing 29 changed files with 608 additions and 551 deletions.
8 changes: 4 additions & 4 deletions src/mac/mozc_imk_input_controller_test.mm
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ BOOL SendKeyEvent(unsigned short keyCode, MozcImkInputController *controller,
// create an output
commands::Output output;
// a candidate has to have at least a candidate
commands::Candidates *candidates = output.mutable_candidates();
candidates->set_focused_index(0);
candidates->set_size(1);
commands::Candidates::Candidate *candidate = candidates->add_candidate();
commands::CandidateWindow *candidate_window = output.mutable_candidates();
candidate_window->set_focused_index(0);
candidate_window->set_size(1);
commands::CandidateWindow::Candidate *candidate = candidate_window->add_candidate();
candidate->set_index(0);
candidate->set_value("abc");

Expand Down
11 changes: 6 additions & 5 deletions src/protocol/candidates.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// Protocol messages of candidates to be used for mozc client/server
// Protocol messages of candidate window to be used for mozc client/server
// communication and client/renderer communication.
// TODO(b/372854886): Rename file to candidate_window.proto.

syntax = "proto2";

Expand Down Expand Up @@ -96,7 +97,7 @@ enum CandidateAttribute {
USER_DICTIONARY = 1;
USER_HISTORY = 2;
SPELLING_CORRECTION = 3; // "ふいんき"→"雰囲気"
TYPING_CORRECTION = 4; // "やんしょん"(with 12-key)→"マンション"
TYPING_CORRECTION = 4; // "やんしょん"(with 12-key)→"マンション"
}

message InformationList {
Expand Down Expand Up @@ -163,8 +164,7 @@ message CandidateList {
optional Category category = 3 [default = CONVERSION];
}

// TODO(komatsu) rename it to CandidateWindow.
message Candidates {
message CandidateWindow {
// TODO(komatsu): Use CandidateList.
// When has_focused_index() is true, this message contains predicted and
// normally converted candidates. Otherwise, when the field is not set,
Expand Down Expand Up @@ -195,7 +195,8 @@ message Candidates {
required uint32 position = 6;

// Nested candidates aka cascading window.
optional Candidates subcandidates = 8;
// TODO(b/372854886): Follow up renaming to sub_candidate_window.
optional CandidateWindow subcandidates = 8;

// Usages of candidates.
optional InformationList usages = 10;
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/commands.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,8 @@ message Output {
optional bool consumed = 3;
optional Result result = 4;
optional Preedit preedit = 5;
optional Candidates candidates = 6;
// TODO(b/372854886): Follow up renaming to candidate_window.
optional CandidateWindow candidates = 6;
optional KeyEvent key = 7;

// when URL is non empty, UI can open the page with a browser,
Expand Down
3 changes: 2 additions & 1 deletion src/protocol/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ message SessionState {
optional mozc.commands.Preedit preedit = 20;

// last candidates state
optional mozc.commands.Candidates candidates = 21;
// TODO(b/372854886): Follow up renaming to candidate_window.
optional mozc.commands.CandidateWindow candidates = 21;

reserved 22;
reserved "all_candidate_words";
Expand Down
24 changes: 12 additions & 12 deletions src/renderer/mac/CandidateController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
namespace mozc {
using client::SendCommandInterface;
using commands::RendererCommand;
using commands::Candidates;

namespace renderer {
namespace mac {
Expand Down Expand Up @@ -148,18 +147,18 @@ int GetBaseScreenHeight() {
return true;
}

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

bool cascading_visible = false;
if (command_.output().has_candidates() && command_.output().candidates().has_subcandidates()) {
cascading_window_->SetCandidates(command_.output().candidates().subcandidates());
cascading_window_->SetCandidateWindow(command_.output().candidates().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_->SetCandidates(command_.output().candidates());
infolist_window_->SetCandidateWindow(command_.output().candidates());
infolist_visible = true;
}

Expand All @@ -172,12 +171,13 @@ int GetBaseScreenHeight() {
}

if (infolist_visible && !cascading_visible) {
const Candidates &candidates = command_.output().candidates();
if (candidates.has_focused_index() && candidates.candidate_size() > 0) {
const int focused_row = candidates.focused_index() - candidates.candidate(0).index();
if (candidates.candidate_size() >= focused_row &&
candidates.candidate(focused_row).has_information_id()) {
infolist_window_->DelayShow(candidates.usages().delay());
const commands::CandidateWindow &candidate_window = command_.output().candidates();
if (candidate_window.has_focused_index() && candidate_window.candidate_size() > 0) {
const int focused_row =
candidate_window.focused_index() - candidate_window.candidate(0).index();
if (candidate_window.candidate_size() >= focused_row &&
candidate_window.candidate(focused_row).has_information_id()) {
infolist_window_->DelayShow(candidate_window.usages().delay());
} else {
infolist_window_->DelayHide(kHideWindowDelay);
}
Expand Down Expand Up @@ -255,8 +255,8 @@ int GetBaseScreenHeight() {

// Fix cascading window position
// 1. starting position is at the focused row
const Candidates &candidates = command_.output().candidates();
const int focused_row = candidates.focused_index() - candidates.candidate(0).index();
const commands::CandidateWindow &candidate_window = command_.output().candidates();
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
focused_rect.origin.x += candidate_rect.origin.x;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/mac/CandidateView.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ enum COLUMN_TYPE {
// according to the current candidates.
@interface CandidateView : NSView

// setCandidates: sets the candidates to be rendered.
- (void)setCandidates:(const mozc::commands::Candidates *)candidates;
// setCandidateWindow: sets the candidate window to be rendered.
- (void)setCandidateWindow:(const mozc::commands::CandidateWindow *)candidate_window;

// setController: sets the reference of MozcImkInputController.
// It will be used when mouse clicks. It doesn't take ownerships of
Expand Down
60 changes: 30 additions & 30 deletions src/renderer/mac/CandidateView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include "renderer/table_layout.h"

using mozc::client::SendCommandInterface;
using mozc::commands::Candidates;
using mozc::commands::CandidateWindow;
using mozc::commands::Output;
using mozc::commands::SessionCommand;
using mozc::renderer::RendererStyleHandler;
Expand Down Expand Up @@ -73,7 +73,7 @@ @implementation CandidateView {
const NSImage *logoImage_;
int columnMinimumWidth_;

mozc::commands::Candidates candidates_;
mozc::commands::CandidateWindow candidate_window_;
mozc::renderer::TableLayout tableLayout_;
mozc::renderer::RendererStyle style_;

Expand Down Expand Up @@ -126,8 +126,8 @@ - (void)initializeDefaultStyle {
[NSBezierPath setDefaultLineJoinStyle:NSLineJoinStyleMiter];
}

- (void)setCandidates:(const Candidates *)candidates {
candidates_ = *candidates;
- (void)setCandidateWindow:(const CandidateWindow *)candidate_window {
candidate_window_ = *candidate_window;
}

- (void)setSendCommandInterface:(SendCommandInterface *)command_sender {
Expand All @@ -151,22 +151,22 @@ - (const TableLayout *)tableLayout {

- (NSSize)updateLayout {
candidateStringsCache_ = nil;
tableLayout_.Initialize(candidates_.candidate_size(), NUMBER_OF_COLUMNS);
tableLayout_.Initialize(candidate_window_.candidate_size(), NUMBER_OF_COLUMNS);
tableLayout_.SetWindowBorder(style_.window_border());

// calculating focusedRow_
if (candidates_.has_focused_index() && candidates_.candidate_size() > 0) {
const int focusedIndex = candidates_.focused_index();
focusedRow_ = focusedIndex - candidates_.candidate(0).index();
if (candidate_window_.has_focused_index() && candidate_window_.candidate_size() > 0) {
const int focusedIndex = candidate_window_.focused_index();
focusedRow_ = focusedIndex - candidate_window_.candidate(0).index();
} else {
focusedRow_ = -1;
}

// Reserve footer space.
if (candidates_.has_footer()) {
if (candidate_window_.has_footer()) {
NSSize footerSize = NSZeroSize;

const mozc::commands::Footer &footer = candidates_.footer();
const mozc::commands::Footer &footer = candidate_window_.footer();

if (footer.has_label()) {
const NSAttributedString *footerLabel =
Expand All @@ -193,8 +193,8 @@ - (NSSize)updateLayout {
}

if (footer.index_visible()) {
const int focusedIndex = candidates_.focused_index();
const int totalItems = candidates_.size();
const int focusedIndex = candidate_window_.focused_index();
const int totalItems = candidate_window_.size();
const NSString *footerIndex =
[NSString stringWithFormat:@"%d/%d", focusedIndex + 1, totalItems];
const NSAttributedString *footerAttributedIndex =
Expand All @@ -210,7 +210,7 @@ - (NSSize)updateLayout {
}

tableLayout_.SetRowRectPadding(style_.row_rect_padding());
if (candidates_.candidate_size() < candidates_.size()) {
if (candidate_window_.candidate_size() < candidate_window_.size()) {
tableLayout_.SetVScrollBar(style_.scrollbar_width());
}

Expand All @@ -219,8 +219,8 @@ - (NSSize)updateLayout {
tableLayout_.EnsureCellSize(COLUMN_GAP1, MacViewUtil::ToSize([gap1 size]));

NSMutableArray *newCache = [[NSMutableArray array] init];
for (size_t i = 0; i < candidates_.candidate_size(); ++i) {
const Candidates::Candidate &candidate = candidates_.candidate(i);
for (size_t i = 0; i < candidate_window_.candidate_size(); ++i) {
const CandidateWindow::Candidate &candidate = candidate_window_.candidate(i);
const NSAttributedString *shortcut = MacViewUtil::ToNSAttributedString(
candidate.annotation().shortcut(), style_.text_styles(COLUMN_SHORTCUT));
std::string value = candidate.value();
Expand Down Expand Up @@ -266,16 +266,16 @@ - (NSSize)updateLayout {
}

- (void)drawRect:(NSRect)rect {
if (!Category_IsValid(candidates_.category())) {
LOG(WARNING) << "Unknown candidates category: " << candidates_.category();
if (!Category_IsValid(candidate_window_.category())) {
LOG(WARNING) << "Unknown candidates category: " << candidate_window_.category();
return;
}

for (int i = 0; i < candidates_.candidate_size(); ++i) {
for (int i = 0; i < candidate_window_.candidate_size(); ++i) {
[self drawRow:i];
}

if (candidates_.candidate_size() < candidates_.size()) {
if (candidate_window_.candidate_size() < candidate_window_.size()) {
[self drawVScrollBar];
}
[self drawFooter];
Expand Down Expand Up @@ -326,7 +326,7 @@ - (void)drawRow:(int)row {
[text drawAtPoint:candidatePosition];
}

if (candidates_.candidate(row).has_information_id()) {
if (candidate_window_.candidate(row).has_information_id()) {
NSRect rect = MacViewUtil::ToNSRect(tableLayout_.GetRowRect(row));
[MacViewUtil::ToNSColor(style_.focused_border_color()) set];
rect.origin.x += rect.size.width - 6.0;
Expand All @@ -338,10 +338,10 @@ - (void)drawRow:(int)row {
}

- (void)drawFooter {
if (!candidates_.has_footer()) {
if (!candidate_window_.has_footer()) {
return;
}
const mozc::commands::Footer &footer = candidates_.footer();
const mozc::commands::Footer &footer = candidate_window_.footer();
NSRect footerRect = MacViewUtil::ToNSRect(tableLayout_.GetFooterRect());

// Draw footer border
Expand Down Expand Up @@ -401,8 +401,8 @@ - (void)drawFooter {
if (footer.index_visible()) {
const std::string footerIndex =
absl::StrFormat("%d/%d",
candidates_.focused_index() + 1, // +1 to 1-origin from 0-origin.
candidates_.size());
candidate_window_.focused_index() + 1, // +1 to 1-origin from 0-origin.
candidate_window_.size());
const NSAttributedString *footerAttributedIndex =
MacViewUtil::ToNSAttributedString(footerIndex, style_.footer_style());
const NSSize footerSize = [footerAttributedIndex size];
Expand All @@ -415,13 +415,13 @@ - (void)drawFooter {

- (void)drawVScrollBar {
const mozc::Rect vscrollRect = tableLayout_.GetVScrollBarRect();
if (vscrollRect.IsRectEmpty() || candidates_.candidate_size() <= 0) {
if (vscrollRect.IsRectEmpty() || candidate_window_.candidate_size() <= 0) {
return;
}

const int beginIndex = candidates_.candidate(0).index();
const int candidatesTotal = candidates_.size();
const int endIndex = candidates_.candidate(candidates_.candidate_size() - 1).index();
const int beginIndex = candidate_window_.candidate(0).index();
const int candidatesTotal = candidate_window_.size();
const int endIndex = candidate_window_.candidate(candidate_window_.candidate_size() - 1).index();

[MacViewUtil::ToNSColor(style_.scrollbar_background_color()) set];
[NSBezierPath fillRect:MacViewUtil::ToNSRect(vscrollRect)];
Expand Down Expand Up @@ -458,15 +458,15 @@ - (void)mouseUp:(NSEvent *)event {
if (command_sender_ == nullptr) {
return;
}
if (candidates_.candidate_size() < tableLayout_.number_of_rows()) {
if (candidate_window_.candidate_size() < tableLayout_.number_of_rows()) {
return;
}
for (int i = 0; i < tableLayout_.number_of_rows(); ++i) {
const mozc::Rect rowRect = tableLayout_.GetRowRect(i);
if (rowRect.PtrInRect(localPos)) {
SessionCommand command;
command.set_type(SessionCommand::SELECT_CANDIDATE);
command.set_id(candidates_.candidate(i).id());
command.set_id(candidate_window_.candidate(i).id());
Output dummy_output;
command_sender_->SendCommand(command, &dummy_output);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/mac/CandidateWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace client {
class SendCommandInterface;
} // namespace client
namespace commands {
class Candidates;
class CandidateWindow;
} // namespace commands
namespace renderer {
class TableLayout;
Expand All @@ -55,7 +55,7 @@ class CandidateWindow : public RendererBaseWindow {
virtual ~CandidateWindow();
void SetSendCommandInterface(
client::SendCommandInterface *send_command_interface);
void SetCandidates(const commands::Candidates &candidates);
void SetCandidateWindow(const commands::CandidateWindow &candidate_window);
const renderer::TableLayout *GetTableLayout() const;

private:
Expand Down
10 changes: 4 additions & 6 deletions src/renderer/mac/CandidateWindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#include "protocol/commands.pb.h"
#include "renderer/mac/CandidateWindow.h"

using mozc::commands::Candidates;

namespace mozc {
namespace renderer {
namespace mac {
Expand Down Expand Up @@ -66,17 +64,17 @@
return [candidate_view tableLayout];
}

void CandidateWindow::SetCandidates(const Candidates& candidates) {
DLOG(INFO) << "CandidateWindow::SetCandidates";
if (candidates.candidate_size() == 0) {
void CandidateWindow::SetCandidateWindow(const commands::CandidateWindow& candidate_window) {
DLOG(INFO) << "CandidateWindow::SetCandidateWindow";
if (candidate_window.candidate_size() == 0) {
return;
}

if (!window_) {
InitWindow();
}
CandidateView* candidate_view = (CandidateView*)view_;
[candidate_view setCandidates:&candidates];
[candidate_view setCandidateWindow:&candidate_window];
[candidate_view setNeedsDisplay:YES];
NSSize size = [candidate_view updateLayout];
ResizeWindow(size.width, size.height);
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/mac/InfolistView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class RendererStyle;
// according to the current candidates.
@interface InfolistView : NSView {
@private
mozc::commands::Candidates candidates_;
mozc::commands::CandidateWindow candidate_window_;
const mozc::renderer::RendererStyle *style_;
// The row which has focused background.
int focusedRow_;
}

// setCandidates: sets the candidates to be rendered.
- (void)setCandidates:(const mozc::commands::Candidates *)candidates;
// setCandidateWindow: sets the candidate window to be rendered.
- (void)setCandidateWindow:(const mozc::commands::CandidateWindow *)candidate_window;

// Checks the |candidates_| and recalculates the layout.
// It also returns the size which is necessary to draw all GUI elements.
Expand Down
Loading

0 comments on commit 2deaf6d

Please sign in to comment.