1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_BASE_IME_CANDIDATE_WINDOW_H_
6#define UI_BASE_IME_CANDIDATE_WINDOW_H_
7
8#include <string>
9#include <vector>
10#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
12#include "ui/base/ime/infolist_entry.h"
13#include "ui/base/ui_base_export.h"
14
15namespace ui {
16
17// CandidateWindow represents the structure of candidates generated from IME.
18class UI_BASE_EXPORT CandidateWindow {
19 public:
20  enum Orientation {
21    HORIZONTAL = 0,
22    VERTICAL = 1,
23  };
24
25  struct UI_BASE_EXPORT CandidateWindowProperty {
26    CandidateWindowProperty();
27    virtual ~CandidateWindowProperty();
28    int page_size;
29    int cursor_position;
30    bool is_cursor_visible;
31    bool is_vertical;
32    bool show_window_at_composition;
33
34    // Auxiliary text is typically displayed in the footer of the candidate
35    // window.
36    std::string auxiliary_text;
37    bool is_auxiliary_text_visible;
38  };
39
40  // Represents a candidate entry.
41  struct UI_BASE_EXPORT Entry {
42    Entry();
43    virtual ~Entry();
44    base::string16 value;
45    base::string16 label;
46    base::string16 annotation;
47    base::string16 description_title;
48    base::string16 description_body;
49  };
50
51  CandidateWindow();
52  virtual ~CandidateWindow();
53
54  // Returns true if the given |candidate_window| is equal to myself.
55  bool IsEqual(const CandidateWindow& candidate_window) const;
56
57  // Copies |candidate_window| to myself.
58  void CopyFrom(const CandidateWindow& candidate_window);
59
60  const CandidateWindowProperty& GetProperty() const {
61    return *property_;
62  }
63  void SetProperty(const CandidateWindowProperty& property) {
64    *property_ = property;
65  }
66
67  // Gets the infolist entry models. Sets |has_highlighted| to true if |entries|
68  // contains highlighted entry.
69  void GetInfolistEntries(std::vector<InfolistEntry>* entries,
70                          bool* has_highlighted) const;
71
72  // Returns the number of candidates in one page.
73  uint32 page_size() const { return property_->page_size; }
74  void set_page_size(uint32 page_size) { property_->page_size = page_size; }
75
76  // Returns the cursor index of the currently selected candidate.
77  uint32 cursor_position() const { return property_->cursor_position; }
78  void set_cursor_position(uint32 cursor_position) {
79    property_->cursor_position = cursor_position;
80  }
81
82  // Returns true if the cursor is visible.
83  bool is_cursor_visible() const { return property_->is_cursor_visible; }
84  void set_is_cursor_visible(bool is_cursor_visible) {
85    property_->is_cursor_visible = is_cursor_visible;
86  }
87
88  // Returns the orientation of the candidate window.
89  Orientation orientation() const {
90    return property_->is_vertical ? VERTICAL : HORIZONTAL;
91  }
92  void set_orientation(Orientation orientation) {
93    property_->is_vertical = (orientation == VERTICAL);
94  }
95
96  // Returns true if the auxiliary text is visible.
97  bool is_auxiliary_text_visible() const {
98    return property_->is_auxiliary_text_visible;
99  }
100  void set_is_auxiliary_text_visible(bool is_auxiliary_text_visible) const {
101    property_->is_auxiliary_text_visible = is_auxiliary_text_visible;
102  }
103
104  // Accessors of auxiliary_text.
105  const std::string& auxiliary_text() const {
106    return property_->auxiliary_text;
107  }
108  void set_auxiliary_text(const std::string& auxiliary_text) const {
109    property_->auxiliary_text = auxiliary_text;
110  }
111
112  const std::vector<Entry>& candidates() const { return candidates_; }
113  std::vector<Entry>* mutable_candidates() { return &candidates_; }
114
115  bool show_window_at_composition() const {
116    return property_->show_window_at_composition;
117  }
118  void set_show_window_at_composition(bool show_window_at_composition) {
119    property_->show_window_at_composition = show_window_at_composition;
120  }
121
122 private:
123  scoped_ptr<CandidateWindowProperty> property_;
124  std::vector<Entry> candidates_;
125
126  DISALLOW_COPY_AND_ASSIGN(CandidateWindow);
127};
128
129}  // namespace ui
130
131#endif  // UI_BASE_IME_CANDIDATE_WINDOW_H_
132