Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / ibus / ibus_lookup_table.h
blobbf328cff62d406090c89f20b791241193b2029aa
1 // Copyright (c) 2012 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.
5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_
6 #define CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_
8 #include <string>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chromeos/chromeos_export.h"
14 namespace dbus {
15 class MessageWriter;
16 class MessageReader;
17 } // namespace dbus
19 namespace chromeos {
21 // The IBusLookupTable is one of IBusObjects. IBusLookupTable contains IBusTexts
22 // but all of them are used as plain string. The overview of each data
23 // structure is as follows:
25 // DATA STRUCTURE OVERVIEW:
26 // variant struct {
27 // string "IBusLookupTable"
28 // array [
29 // dict_entry (
30 // string "window_show_at_composition"
31 // variant variant boolean false
32 // ]
33 // )
34 // ]
35 // uint32 9 // Page size
36 // uint32 1 // Cursor position
37 // boolean true // Cursor visibility.
38 // boolean true // Round lookup table or not. Not used in Chrome.
39 // int32 1 // Orientation
40 // array [ // Array of candidate text.
41 // variant struct {
42 // string "IBusText"
43 // array []
44 // string "Candidate Text"
45 // variant struct {
46 // string "IBusAttrList"
47 // array []
48 // array []
49 // }
50 // }
51 // ... more IBusTexts
52 // ]
53 // array [ // Array of label text
54 // variant struct {
55 // string "IBusText"
56 // array []
57 // string "1"
58 // variant struct {
59 // string "IBusAttrList"
60 // array []
61 // array []
62 // }
63 // }
64 // ... more IBusTexts
65 // ]
66 // }
67 // TODO(nona): Clean up the structure.(crbug.com/129403)
68 class IBusLookupTable;
70 // Pops a IBusLookupTable from |reader|.
71 // Returns false if an error occurs.
72 bool CHROMEOS_EXPORT PopIBusLookupTable(dbus::MessageReader* reader,
73 IBusLookupTable* table);
74 // Appends a IBusLookupTable to |writer| except mozc_candidates_ in |table|.
75 void CHROMEOS_EXPORT AppendIBusLookupTable(const IBusLookupTable& table,
76 dbus::MessageWriter* writer);
78 // An representation of IBusLookupTable object which is used in dbus
79 // communication with ibus-daemon.
80 class CHROMEOS_EXPORT IBusLookupTable {
81 public:
82 enum Orientation {
83 HORIZONTAL = 0,
84 VERTICAL = 1,
87 // Represents a candidate entry. In dbus communication, each
88 // field is represented as IBusText, but attributes are not used in Chrome.
89 // So just simple string is sufficient in this case.
90 struct Entry {
91 Entry();
92 virtual ~Entry();
93 std::string value;
94 std::string label;
95 std::string annotation;
96 std::string description_title;
97 std::string description_body;
100 IBusLookupTable();
101 virtual ~IBusLookupTable();
103 // Returns true if the given |table| is equal to myself.
104 bool IsEqual(const IBusLookupTable& table) const;
106 // Copies |table| to myself.
107 void CopyFrom(const IBusLookupTable& table);
109 // Returns the number of candidates in one page.
110 uint32 page_size() const { return page_size_; }
111 void set_page_size(uint32 page_size) { page_size_ = page_size; }
113 // Returns the cursor index of the currently selected candidate.
114 uint32 cursor_position() const { return cursor_position_; }
115 void set_cursor_position(uint32 cursor_position) {
116 cursor_position_ = cursor_position;
119 // Returns true if the cursor is visible.
120 bool is_cursor_visible() const { return is_cursor_visible_; }
121 void set_is_cursor_visible(bool is_cursor_visible) {
122 is_cursor_visible_ = is_cursor_visible;
125 // Returns the orientation of lookup table.
126 Orientation orientation() const { return orientation_; }
127 void set_orientation(Orientation orientation) {
128 orientation_ = orientation;
131 const std::vector<Entry>& candidates() const { return candidates_; }
132 std::vector<Entry>* mutable_candidates() { return &candidates_; }
134 bool show_window_at_composition() const {
135 return show_window_at_composition_;
137 void set_show_window_at_composition(bool show_window_at_composition) {
138 show_window_at_composition_ = show_window_at_composition;
141 private:
142 uint32 page_size_;
143 uint32 cursor_position_;
144 bool is_cursor_visible_;
145 Orientation orientation_;
146 std::vector<Entry> candidates_;
147 bool show_window_at_composition_;
149 DISALLOW_COPY_AND_ASSIGN(IBusLookupTable);
152 } // namespace chromeos
154 #endif // CHROMEOS_DBUS_IBUS_IBUS_LOOKUP_TABLE_H_