• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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 CHROMEOS_IME_CANDIDATE_WINDOW_H_
6 #define CHROMEOS_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 "chromeos/chromeos_export.h"
13 
14 namespace chromeos {
15 namespace input_method {
16 
17 // CandidateWindow represents the structure of candidates generated from IME.
18 class CHROMEOS_EXPORT CandidateWindow {
19  public:
20   enum Orientation {
21     HORIZONTAL = 0,
22     VERTICAL = 1,
23   };
24 
25   struct 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 
35   // Represents a candidate entry.
36   struct Entry {
37     Entry();
38     virtual ~Entry();
39     std::string value;
40     std::string label;
41     std::string annotation;
42     std::string description_title;
43     std::string description_body;
44   };
45 
46   CandidateWindow();
47   virtual ~CandidateWindow();
48 
49   // Returns true if the given |candidate_window| is equal to myself.
50   bool IsEqual(const CandidateWindow& candidate_window) const;
51 
52   // Copies |candidate_window| to myself.
53   void CopyFrom(const CandidateWindow& candidate_window);
54 
GetProperty()55   const CandidateWindowProperty& GetProperty() const {
56     return *property_;
57   }
SetProperty(const CandidateWindowProperty & property)58   void SetProperty(const CandidateWindowProperty& property) {
59     *property_ = property;
60   }
61 
62   // Returns the number of candidates in one page.
page_size()63   uint32 page_size() const { return property_->page_size; }
set_page_size(uint32 page_size)64   void set_page_size(uint32 page_size) { property_->page_size = page_size; }
65 
66   // Returns the cursor index of the currently selected candidate.
cursor_position()67   uint32 cursor_position() const { return property_->cursor_position; }
set_cursor_position(uint32 cursor_position)68   void set_cursor_position(uint32 cursor_position) {
69     property_->cursor_position = cursor_position;
70   }
71 
72   // Returns true if the cursor is visible.
is_cursor_visible()73   bool is_cursor_visible() const { return property_->is_cursor_visible; }
set_is_cursor_visible(bool is_cursor_visible)74   void set_is_cursor_visible(bool is_cursor_visible) {
75     property_->is_cursor_visible = is_cursor_visible;
76   }
77 
78   // Returns the orientation of the candidate window.
orientation()79   Orientation orientation() const {
80     return property_->is_vertical ? VERTICAL : HORIZONTAL;
81   }
set_orientation(Orientation orientation)82   void set_orientation(Orientation orientation) {
83     property_->is_vertical = (orientation == VERTICAL);
84   }
85 
candidates()86   const std::vector<Entry>& candidates() const { return candidates_; }
mutable_candidates()87   std::vector<Entry>* mutable_candidates() { return &candidates_; }
88 
show_window_at_composition()89   bool show_window_at_composition() const {
90     return property_->show_window_at_composition;
91   }
set_show_window_at_composition(bool show_window_at_composition)92   void set_show_window_at_composition(bool show_window_at_composition) {
93     property_->show_window_at_composition = show_window_at_composition;
94   }
95 
96  private:
97   scoped_ptr<CandidateWindowProperty> property_;
98   std::vector<Entry> candidates_;
99 
100   DISALLOW_COPY_AND_ASSIGN(CandidateWindow);
101 };
102 
103 }  // namespace input_method
104 }  // namespace chromeos
105 
106 #endif  // CHROMEOS_IME_CANDIDATE_WINDOW_H_
107