File: candidate_window.h

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 (156 lines) | stat: -rw-r--r-- 4,879 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// 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.

#ifndef UI_BASE_IME_CANDIDATE_WINDOW_H_
#define UI_BASE_IME_CANDIDATE_WINDOW_H_

#include <stdint.h>

#include <memory>
#include <string>
#include <vector>

#include "base/component_export.h"
#include "ui/base/ime/infolist_entry.h"

namespace ui {

// CandidateWindow represents the structure of candidates generated from IME.
class COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindow {
 public:
  enum Orientation {
    HORIZONTAL = 0,
    VERTICAL = 1,
  };

  struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) CandidateWindowProperty {
    CandidateWindowProperty();
    virtual ~CandidateWindowProperty();
    int page_size;
    int cursor_position;
    bool is_cursor_visible;
    bool is_vertical;
    bool show_window_at_composition;

    // Auxiliary text is typically displayed in the footer of the candidate
    // window.
    std::string auxiliary_text;
    bool is_auxiliary_text_visible;

    // The index of the current chosen candidate out of total candidates
    int current_candidate_index;
    int total_candidates;

    // If the user is selecting from candidates.
    // If this is false, candidate window is not shown or is showing
    // suggestions.
    bool is_user_selecting;
  };

  // Represents a candidate entry.
  struct COMPONENT_EXPORT(UI_BASE_IME_TYPES) Entry {
    Entry();
    Entry(const Entry& other);
    virtual ~Entry();
    std::u16string value;
    std::u16string label;
    std::u16string annotation;
    std::u16string description_title;
    std::u16string description_body;
  };

  CandidateWindow();

  CandidateWindow(const CandidateWindow&) = delete;
  CandidateWindow& operator=(const CandidateWindow&) = delete;

  virtual ~CandidateWindow();

  // Returns true if the given |candidate_window| is equal to myself.
  bool IsEqual(const CandidateWindow& candidate_window) const;

  // Copies |candidate_window| to myself.
  void CopyFrom(const CandidateWindow& candidate_window);

  const CandidateWindowProperty& GetProperty() const {
    return *property_;
  }
  void SetProperty(const CandidateWindowProperty& property) {
    *property_ = property;
  }

  // Gets the infolist entry models. Sets |has_highlighted| to true if |entries|
  // contains highlighted entry.
  void GetInfolistEntries(std::vector<InfolistEntry>* entries,
                          bool* has_highlighted) const;

  // Returns the number of candidates in one page.
  uint32_t page_size() const { return property_->page_size; }
  void set_page_size(uint32_t page_size) { property_->page_size = page_size; }

  // Returns the cursor index of the currently selected candidate.
  uint32_t cursor_position() const { return property_->cursor_position; }
  void set_cursor_position(uint32_t cursor_position) {
    property_->cursor_position = cursor_position;
  }

  // Returns true if the cursor is visible.
  bool is_cursor_visible() const { return property_->is_cursor_visible; }
  void set_is_cursor_visible(bool is_cursor_visible) {
    property_->is_cursor_visible = is_cursor_visible;
  }

  // Returns the orientation of the candidate window.
  Orientation orientation() const {
    return property_->is_vertical ? VERTICAL : HORIZONTAL;
  }
  void set_orientation(Orientation orientation) {
    property_->is_vertical = (orientation == VERTICAL);
  }

  // Returns true if the auxiliary text is visible.
  bool is_auxiliary_text_visible() const {
    return property_->is_auxiliary_text_visible;
  }
  void set_is_auxiliary_text_visible(bool is_auxiliary_text_visible) const {
    property_->is_auxiliary_text_visible = is_auxiliary_text_visible;
  }

  // Accessors of auxiliary_text.
  const std::string& auxiliary_text() const {
    return property_->auxiliary_text;
  }
  void set_auxiliary_text(const std::string& auxiliary_text) const {
    property_->auxiliary_text = auxiliary_text;
  }

  const int& current_candidate_index() const {
    return property_->current_candidate_index;
  }

  const int& total_candidates() const { return property_->total_candidates; }

  const std::vector<Entry>& candidates() const { return candidates_; }
  std::vector<Entry>* mutable_candidates() { return &candidates_; }

  bool show_window_at_composition() const {
    return property_->show_window_at_composition;
  }
  void set_show_window_at_composition(bool show_window_at_composition) {
    property_->show_window_at_composition = show_window_at_composition;
  }

  bool is_user_selecting() const { return property_->is_user_selecting; }
  void set_is_user_selecting(bool is_user_selecting) {
    property_->is_user_selecting = is_user_selecting;
  }

 private:
  std::unique_ptr<CandidateWindowProperty> property_;
  std::vector<Entry> candidates_;
};

}  // namespace ui

#endif  // UI_BASE_IME_CANDIDATE_WINDOW_H_