Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / chromeos / dbus / ibus / ibus_text.h
blobb1b62727b94dad0ad9ccadb3ef9c00c42b261000
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_TEXT_H_
6 #define CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_
8 #include <string>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "chromeos/chromeos_export.h"
13 namespace dbus {
14 class MessageWriter;
15 class MessageReader;
16 } // dbus
18 namespace chromeos {
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:
24 // DATA STRUCTURE OVERVIEW:
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 // }
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 // }
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 // }
77 class IBusText;
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);
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);
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.
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.
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,
127 struct UnderlineAttribute {
128 IBusTextUnderlineType type;
129 uint32 start_index; // The inclusive start index.
130 uint32 end_index; // The exclusive end index.
133 struct SelectionAttribute {
134 uint32 start_index; // The inclusive start index.
135 uint32 end_index; // The exclusive end index.
138 // Accessors
139 IBusText();
140 virtual ~IBusText();
142 const std::string& text() const { return text_; }
143 void set_text(const std::string& text) { text_ = text; }
145 const std::string& annotation() const { return annotation_; }
146 void set_annotation(const std::string& annotation) {
147 annotation_ = annotation;
150 const std::string& description_title() const { return description_title_; }
151 void set_description_title(const std::string& title) {
152 description_title_ = title;
155 const std::string& description_body() const { return description_body_; }
156 void set_description_body(const std::string& body) {
157 description_body_ = body;
160 const std::vector<UnderlineAttribute>& underline_attributes() const {
161 return underline_attributes_;
164 std::vector<UnderlineAttribute>* mutable_underline_attributes() {
165 return &underline_attributes_;
168 const std::vector<SelectionAttribute>& selection_attributes() const {
169 return selection_attributes_;
171 std::vector<SelectionAttribute>* mutable_selection_attributes() {
172 return &selection_attributes_;
175 private:
176 std::string text_;
177 std::string annotation_;
178 std::string description_title_;
179 std::string description_body_;
180 std::vector<UnderlineAttribute> underline_attributes_;
181 std::vector<SelectionAttribute> selection_attributes_;
183 DISALLOW_COPY_AND_ASSIGN(IBusText);
186 } // namespace chromeos
188 #endif // CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_