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_
10 #include "base/basictypes.h"
11 #include "chromeos/chromeos_export.h"
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
24 // DATA STRUCTURE OVERVIEW:
26 // IBusAttribute: (signature is "uuuu")
28 // string "IBusAttribute"
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.
36 // IBusAttrList: (signature is "av")
38 // string "IBusAttrList"
40 // array[ // The array of IBusAttribute.
42 // string "IBusAttribute"
46 // string "IBusAttribute"
50 // string "IBusAttribute"
56 // IBusText: (signature is "sv")
62 // string "IBusAttrList"
66 // string "IBusAttribute"
70 // string "IBusAttribute"
79 // Pops a IBusText from |reader|.
80 // Returns false if an error occurs.
81 bool CHROMEOS_EXPORT
PopIBusText(dbus::MessageReader
* reader
,
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
,
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
{
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.
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_
;
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_