OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_ | |
6 #define CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 #include "base/basictypes.h" | |
11 #include "chromeos/chromeos_export.h" | |
12 | |
13 namespace dbus { | |
14 class MessageWriter; | |
15 class MessageReader; | |
16 } // dbus | |
17 | |
18 namespace chromeos { | |
19 | |
20 // The IBusText is one of IBusObjects and it contains IBusAttrList object which | |
21 // contains array of IBusAttribute object. The overview of each data structure | |
22 // is as follows: | |
23 // | |
24 // DATA STRUCTURE OVERVIEW: | |
25 // | |
26 // IBusAttribute: (signature is "uuuu") | |
27 // variant struct { | |
28 // string "IBusAttribute" | |
29 // array[] | |
30 // uint32 1 // Type of attribute. | |
31 // uint32 1 // The value of attribute. | |
32 // uint32 0 // The start index of the text. | |
33 // uint32 1 // The end index of the text. | |
34 // } | |
35 // | |
36 // IBusAttrList: (signature is "av") | |
37 // variant struct { | |
38 // string "IBusAttrList" | |
39 // array[] | |
40 // array[ // The array of IBusAttribute. | |
41 // variant struct{ | |
42 // string "IBusAttribute" | |
43 // ... | |
44 // } | |
45 // variant struct{ | |
46 // string "IBusAttribute" | |
47 // ... | |
48 // } | |
49 // variant struct{ | |
50 // string "IBusAttribute" | |
51 // ... | |
52 // } | |
53 // ] | |
54 // } | |
55 // | |
56 // IBusText: (signature is "sv") | |
57 // variant struct { | |
58 // string "IBusText" | |
59 // array[] | |
60 // string "A" | |
61 // variant struct { | |
62 // string "IBusAttrList" | |
63 // array[] | |
64 // array[ | |
65 // variant struct{ | |
66 // string "IBusAttribute" | |
67 // ... | |
68 // } | |
69 // variant struct{ | |
70 // string "IBusAttribute" | |
71 // ... | |
72 // } | |
73 // ] | |
74 // } | |
75 // } | |
76 // | |
77 class IBusText; | |
78 | |
79 // Pops a IBusText from |reader|. | |
80 // Returns false if an error occurs. | |
81 bool CHROMEOS_EXPORT PopIBusText(dbus::MessageReader* reader, | |
82 IBusText* ibus_text); | |
83 // Pops a IBusText from |reader| and stores it's text field into text. Use | |
84 // PopIBusText instead in the case of using any attribute entries in IBusText. | |
85 // Returns true on success. | |
86 bool CHROMEOS_EXPORT PopStringFromIBusText(dbus::MessageReader* reader, | |
87 std::string* text); | |
88 // Appends a IBusText to |writer|. Annotation and description field is not | |
89 // filled with AppendIBusText. | |
90 // TODO(nona): Support annotation/description appending if necessary. | |
91 void CHROMEOS_EXPORT AppendIBusText(const IBusText& ibus_text, | |
92 dbus::MessageWriter* writer); | |
93 | |
94 // Appends a string to |writer| as IBusText without any attributes. Use | |
95 // AppendIBusText instead in the case of using any attribute entries. | |
96 // TODO(nona): Support annotation/description appending if necessary. | |
97 void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text, | |
98 dbus::MessageWriter* writer); | |
99 | |
100 // Handles IBusText object which is used in dbus communication with ibus-daemon. | |
101 // The IBusAttribute has four uint32 variables and the IBusAttributes represents | |
102 // three type of decoration based on it's values. | |
103 // 1. Underline decoration (corresponds to UnderlineAttribute structure) | |
104 // 1st value: indicates underline attribute. | |
105 // 2nd value: type of decoration. Chrome only support single and double | |
106 // underline and error line. | |
107 // 3rd value: the start index of this attribute in multibyte. | |
108 // 4th value: the end index of this attribute in multibyte. | |
109 // | |
110 // 2. Background decoration (corresponds to SelectionAttribute structure) | |
111 // NOTE: Background decoration is treated as selection in Chrome. | |
112 // 1st value: indicates background attribute. | |
113 // 2nd value: Represents color but not supported in Chrome. | |
114 // 3rd value: the start index of this attribute in multibyte. | |
115 // 4th value: the end index of this attribute in multibyte. | |
116 // | |
117 // 3. Forward decoration | |
118 // Not supported in Chrome. | |
119 class CHROMEOS_EXPORT IBusText { | |
120 public: | |
121 enum IBusTextUnderlineType { | |
122 IBUS_TEXT_UNDERLINE_SINGLE = 1, | |
123 IBUS_TEXT_UNDERLINE_DOUBLE = 2, | |
124 IBUS_TEXT_UNDERLINE_ERROR = 4, | |
125 }; | |
126 | |
127 struct UnderlineAttribute { | |
128 IBusTextUnderlineType type; | |
129 uint32 start_index; // The inclusive start index. | |
130 uint32 end_index; // The exclusive end index. | |
131 }; | |
132 | |
133 struct SelectionAttribute { | |
134 uint32 start_index; // The inclusive start index. | |
135 uint32 end_index; // The exclusive end index. | |
136 }; | |
137 | |
138 // Accessors | |
139 IBusText(); | |
140 virtual ~IBusText(); | |
141 | |
142 const std::string& text() const { return text_; } | |
143 void set_text(const std::string& text) { text_ = text; } | |
144 | |
145 const std::string& annotation() const { return annotation_; } | |
146 void set_annotation(const std::string& annotation) { | |
147 annotation_ = annotation; | |
148 } | |
149 | |
150 const std::string& description_title() const { return description_title_; } | |
151 void set_description_title(const std::string& title) { | |
152 description_title_ = title; | |
153 } | |
154 | |
155 const std::string& description_body() const { return description_body_; } | |
156 void set_description_body(const std::string& body) { | |
157 description_body_ = body; | |
158 } | |
159 | |
160 const std::vector<UnderlineAttribute>& underline_attributes() const { | |
161 return underline_attributes_; | |
162 } | |
163 | |
164 std::vector<UnderlineAttribute>* mutable_underline_attributes() { | |
165 return &underline_attributes_; | |
166 } | |
167 | |
168 const std::vector<SelectionAttribute>& selection_attributes() const { | |
169 return selection_attributes_; | |
170 } | |
171 std::vector<SelectionAttribute>* mutable_selection_attributes() { | |
172 return &selection_attributes_; | |
173 } | |
174 | |
175 void CopyFrom(const IBusText& obj); | |
176 | |
177 private: | |
178 std::string text_; | |
179 std::string annotation_; | |
180 std::string description_title_; | |
181 std::string description_body_; | |
182 std::vector<UnderlineAttribute> underline_attributes_; | |
183 std::vector<SelectionAttribute> selection_attributes_; | |
184 | |
185 DISALLOW_COPY_AND_ASSIGN(IBusText); | |
186 }; | |
187 | |
188 } // namespace chromeos | |
189 | |
190 #endif // CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_ | |
OLD | NEW |