File: candidate_window.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (111 lines) | stat: -rw-r--r-- 3,269 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/base/ime/candidate_window.h"

#include <stddef.h>

#include <string>
#include "base/check.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"

namespace ui {

namespace {
// The default entry number of a page in CandidateWindow.
const int kDefaultPageSize = 9;
}  // namespace

CandidateWindow::CandidateWindow()
    : property_(new CandidateWindowProperty) {
}

CandidateWindow::~CandidateWindow() {
}

bool CandidateWindow::IsEqual(const CandidateWindow& cw) const {
  if (page_size() != cw.page_size() ||
      cursor_position() != cw.cursor_position() ||
      is_cursor_visible() != cw.is_cursor_visible() ||
      orientation() != cw.orientation() ||
      show_window_at_composition() != cw.show_window_at_composition() ||
      is_auxiliary_text_visible() != cw.is_auxiliary_text_visible() ||
      auxiliary_text() != cw.auxiliary_text() ||
      candidates_.size() != cw.candidates_.size() ||
      is_user_selecting() != cw.is_user_selecting()) {
    return false;
  }

  for (size_t i = 0; i < candidates_.size(); ++i) {
    const Entry& left = candidates_[i];
    const Entry& right = cw.candidates_[i];
    if (left.value != right.value ||
        left.label != right.label ||
        left.annotation != right.annotation ||
        left.description_title != right.description_title ||
        left.description_body != right.description_body)
      return false;
  }
  return true;
}

void CandidateWindow::CopyFrom(const CandidateWindow& cw) {
  SetProperty(cw.GetProperty());
  candidates_.clear();
  candidates_ = cw.candidates_;
}


void CandidateWindow::GetInfolistEntries(
    std::vector<ui::InfolistEntry>* infolist_entries,
    bool* has_highlighted) const {
  DCHECK(infolist_entries);
  DCHECK(has_highlighted);
  infolist_entries->clear();
  *has_highlighted = false;

  const size_t cursor_index_in_page = cursor_position() % page_size();

  for (size_t i = 0; i < candidates().size(); ++i) {
    const CandidateWindow::Entry& candidate_entry = candidates()[i];
    if (candidate_entry.description_title.empty() &&
        candidate_entry.description_body.empty())
      continue;

    InfolistEntry entry(candidate_entry.description_title,
                        candidate_entry.description_body);
    if (i == cursor_index_in_page) {
      entry.highlighted = true;
      *has_highlighted = true;
    }
    infolist_entries->push_back(entry);
  }
}

// When the default values are changed, please modify
// InputMethodEngineInterface::CandidateWindowProperty too.
CandidateWindow::CandidateWindowProperty::CandidateWindowProperty()
    : page_size(kDefaultPageSize),
      cursor_position(0),
      is_cursor_visible(true),
      is_vertical(false),
      show_window_at_composition(false),
      is_auxiliary_text_visible(false),
      current_candidate_index(-1),
      total_candidates(0),
      is_user_selecting(false) {}

CandidateWindow::CandidateWindowProperty::~CandidateWindowProperty() {
}

CandidateWindow::Entry::Entry() {
}

CandidateWindow::Entry::Entry(const Entry& other) = default;

CandidateWindow::Entry::~Entry() {
}

}  // namespace ui