| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/ibus/ibus_text.h" | 5 #include "chromeos/dbus/ibus/ibus_text.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chromeos/dbus/ibus/ibus_object.h" | 8 #include "chromeos/dbus/ibus/ibus_object.h" |
| 9 #include "dbus/message.h" | 9 #include "dbus/message.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 uint32 start_index; | 23 uint32 start_index; |
| 24 uint32 end_index; | 24 uint32 end_index; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 // Pops a IBusAttribute from |reader|. | 27 // Pops a IBusAttribute from |reader|. |
| 28 // Returns false if an error is occures. | 28 // Returns false if an error is occures. |
| 29 bool PopIBusAttribute(dbus::MessageReader* reader, IBusAttribute* attribute) { | 29 bool PopIBusAttribute(dbus::MessageReader* reader, IBusAttribute* attribute) { |
| 30 IBusObjectReader ibus_object_reader("IBusAttribute", reader); | 30 IBusObjectReader ibus_object_reader("IBusAttribute", reader); |
| 31 if (!ibus_object_reader.Init()) | 31 if (!ibus_object_reader.Init()) |
| 32 return false; | 32 return false; |
| 33 |
| 33 if (!ibus_object_reader.PopUint32(&attribute->type) || | 34 if (!ibus_object_reader.PopUint32(&attribute->type) || |
| 34 !ibus_object_reader.PopUint32(&attribute->value) || | 35 !ibus_object_reader.PopUint32(&attribute->value) || |
| 35 !ibus_object_reader.PopUint32(&attribute->start_index) || | 36 !ibus_object_reader.PopUint32(&attribute->start_index) || |
| 36 !ibus_object_reader.PopUint32(&attribute->end_index)) { | 37 !ibus_object_reader.PopUint32(&attribute->end_index)) { |
| 37 LOG(ERROR) << "Invalid variant structure[IBusAttribute]: " | 38 LOG(ERROR) << "Invalid variant structure[IBusAttribute]: " |
| 38 << "IBusAttribute should contain 4 unsigned integers."; | 39 << "IBusAttribute should contain 4 unsigned integers."; |
| 39 return false; | 40 return false; |
| 40 } | 41 } |
| 41 return true; | 42 return true; |
| 42 } | 43 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 96 |
| 96 void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text, | 97 void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text, |
| 97 dbus::MessageWriter* writer) { | 98 dbus::MessageWriter* writer) { |
| 98 IBusText ibus_text; | 99 IBusText ibus_text; |
| 99 ibus_text.set_text(text); | 100 ibus_text.set_text(text); |
| 100 AppendIBusText(ibus_text, writer); | 101 AppendIBusText(ibus_text, writer); |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) { | 104 bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) { |
| 104 IBusObjectReader ibus_text_reader("IBusText", reader); | 105 IBusObjectReader ibus_text_reader("IBusText", reader); |
| 105 if (!ibus_text_reader.Init()) | 106 |
| 107 dbus::MessageReader attachment_reader(NULL); |
| 108 if (!ibus_text_reader.InitWithAttachmentReader(&attachment_reader)) |
| 106 return false; | 109 return false; |
| 107 | 110 |
| 111 while (attachment_reader.HasMoreData()) { |
| 112 dbus::MessageReader dictionary_reader(NULL); |
| 113 if (!attachment_reader.PopDictEntry(&dictionary_reader)) { |
| 114 LOG(ERROR) << "Invalid attachment structure: " |
| 115 << "The attachment field is array of dictionary entry."; |
| 116 return false; |
| 117 } |
| 118 |
| 119 std::string key; |
| 120 if (!dictionary_reader.PopString(&key)) { |
| 121 LOG(ERROR) << "Invalid attachement structure: " |
| 122 << "The 1st dictionary entry should be string."; |
| 123 return false; |
| 124 } |
| 125 |
| 126 dbus::MessageReader variant_reader(NULL); |
| 127 if (!dictionary_reader.PopVariant(&variant_reader)) { |
| 128 LOG(ERROR) << "Invalid attachment structure: " |
| 129 << "The 2nd dictionary entry shuold be variant."; |
| 130 return false; |
| 131 } |
| 132 |
| 133 dbus::MessageReader sub_variant_reader(NULL); |
| 134 if (!variant_reader.PopVariant(&sub_variant_reader)) { |
| 135 LOG(ERROR) << "Invalid attachment structure: " |
| 136 << "The 2nd variant entry should contain variant."; |
| 137 return false; |
| 138 } |
| 139 |
| 140 std::string value; |
| 141 if (!sub_variant_reader.PopString(&value)) |
| 142 continue; // Ignore other attachment values. |
| 143 |
| 144 if (key == "annotation") |
| 145 ibus_text->set_annotation(value); |
| 146 else if (key == "description") |
| 147 ibus_text->set_description(value); |
| 148 else |
| 149 continue; // Ignore other fields. |
| 150 } |
| 151 |
| 108 std::string text; | 152 std::string text; |
| 109 if (!ibus_text_reader.PopString(&text)) { | 153 if (!ibus_text_reader.PopString(&text)) { |
| 110 LOG(ERROR) << "Invalid variant structure[IBusText]: " | 154 LOG(ERROR) << "Invalid variant structure[IBusText]: " |
| 111 << "1st argument should be string."; | 155 << "1st argument should be string."; |
| 112 return false; | 156 return false; |
| 113 } | 157 } |
| 114 | 158 |
| 115 ibus_text->set_text(text); | 159 ibus_text->set_text(text); |
| 116 | 160 |
| 117 // Start reading IBusAttrList object | 161 // Start reading IBusAttrList object |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 215 |
| 172 /////////////////////////////////////////////////////////////////////////////// | 216 /////////////////////////////////////////////////////////////////////////////// |
| 173 // IBusText | 217 // IBusText |
| 174 IBusText::IBusText() | 218 IBusText::IBusText() |
| 175 : text_("") { | 219 : text_("") { |
| 176 } | 220 } |
| 177 | 221 |
| 178 IBusText::~IBusText() { | 222 IBusText::~IBusText() { |
| 179 } | 223 } |
| 180 | 224 |
| 181 std::string IBusText::text() const { | |
| 182 return text_; | |
| 183 } | |
| 184 | |
| 185 void IBusText::set_text(const std::string& text) { | |
| 186 text_.assign(text); | |
| 187 } | |
| 188 | |
| 189 std::vector<IBusText::UnderlineAttribute>* | |
| 190 IBusText::mutable_underline_attributes() { | |
| 191 return &underline_attributes_; | |
| 192 } | |
| 193 | |
| 194 const std::vector<IBusText::UnderlineAttribute>& | |
| 195 IBusText::underline_attributes() const { | |
| 196 return underline_attributes_; | |
| 197 } | |
| 198 | |
| 199 std::vector<IBusText::SelectionAttribute>* | |
| 200 IBusText::mutable_selection_attributes() { | |
| 201 return &selection_attributes_; | |
| 202 } | |
| 203 | |
| 204 const std::vector<IBusText::SelectionAttribute>& | |
| 205 IBusText::selection_attributes() const { | |
| 206 return selection_attributes_; | |
| 207 } | |
| 208 | |
| 209 } // namespace ibus | 225 } // namespace ibus |
| 210 } // namespace chromeos | 226 } // namespace chromeos |
| OLD | NEW |