Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Unified Diff: chromeos/dbus/ibus/ibus_text.cc

Issue 11361210: Extends IBusObject to handle attachment field. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix include order Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/ibus/ibus_property.cc ('k') | chromeos/dbus/ibus/ibus_text_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/ibus/ibus_text.cc
diff --git a/chromeos/dbus/ibus/ibus_text.cc b/chromeos/dbus/ibus/ibus_text.cc
index a80973274b604100dceb97d4a6f124809018e65a..ea290cc39752b6e751e298a55fbb7b43a2f57ebc 100644
--- a/chromeos/dbus/ibus/ibus_text.cc
+++ b/chromeos/dbus/ibus/ibus_text.cc
@@ -5,6 +5,7 @@
#include "chromeos/dbus/ibus/ibus_text.h"
#include "base/logging.h"
+#include "base/values.h"
#include "chromeos/dbus/ibus/ibus_object.h"
#include "dbus/message.h"
@@ -15,6 +16,8 @@ namespace ibus {
namespace {
const uint32 kAttributeUnderline = 1; // Indicates underline attribute.
const uint32 kAttributeSelection = 2; // Indicates background attribute.
+const char kAnnotationKey[] = "annotation";
+const char kDescriptionKey[] = "description";
struct IBusAttribute {
IBusAttribute() : type(0), value(0), start_index(0), end_index(0) {}
@@ -46,6 +49,7 @@ bool PopIBusAttribute(dbus::MessageReader* reader, IBusAttribute* attribute) {
void AppendIBusAttribute(dbus::MessageWriter* writer,
const IBusAttribute& attribute) {
IBusObjectWriter ibus_attribute_writer("IBusAttribute", "uuuu", writer);
+ ibus_attribute_writer.CloseHeader();
ibus_attribute_writer.AppendUint32(attribute.type);
ibus_attribute_writer.AppendUint32(attribute.value);
ibus_attribute_writer.AppendUint32(attribute.start_index);
@@ -58,11 +62,25 @@ void AppendIBusAttribute(dbus::MessageWriter* writer,
void AppendIBusText(const IBusText& ibus_text, dbus::MessageWriter* writer) {
IBusObjectWriter ibus_text_writer("IBusText", "sv", writer);
+ if (!ibus_text.annotation().empty()) {
+ scoped_ptr<base::Value> annotation(
+ base::Value::CreateStringValue(ibus_text.annotation()));
+ ibus_text_writer.AddAttachment(kAnnotationKey, *annotation.get());
+ }
+
+ if (!ibus_text.description().empty()) {
+ scoped_ptr<base::Value> description(
+ base::Value::CreateStringValue(ibus_text.description()));
+ ibus_text_writer.AddAttachment(kDescriptionKey, *description.get());
+ }
+ ibus_text_writer.CloseHeader();
+
ibus_text_writer.AppendString(ibus_text.text());
// Start appending IBusAttrList into IBusText
IBusObjectWriter ibus_attr_list_writer("IBusAttrList", "av", NULL);
ibus_text_writer.AppendIBusObject(&ibus_attr_list_writer);
+ ibus_attr_list_writer.CloseHeader();
dbus::MessageWriter attribute_array_writer(NULL);
ibus_attr_list_writer.OpenArray("v", &attribute_array_writer);
@@ -104,49 +122,23 @@ void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text,
bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) {
IBusObjectReader ibus_text_reader("IBusText", reader);
- dbus::MessageReader attachment_reader(NULL);
- if (!ibus_text_reader.InitWithAttachmentReader(&attachment_reader))
+ if (!ibus_text_reader.Init())
return false;
- while (attachment_reader.HasMoreData()) {
- dbus::MessageReader dictionary_reader(NULL);
- if (!attachment_reader.PopDictEntry(&dictionary_reader)) {
- LOG(ERROR) << "Invalid attachment structure: "
- << "The attachment field is array of dictionary entry.";
- return false;
- }
-
- std::string key;
- if (!dictionary_reader.PopString(&key)) {
- LOG(ERROR) << "Invalid attachement structure: "
- << "The 1st dictionary entry should be string.";
- return false;
- }
-
- dbus::MessageReader variant_reader(NULL);
- if (!dictionary_reader.PopVariant(&variant_reader)) {
- LOG(ERROR) << "Invalid attachment structure: "
- << "The 2nd dictionary entry shuold be variant.";
- return false;
- }
-
- dbus::MessageReader sub_variant_reader(NULL);
- if (!variant_reader.PopVariant(&sub_variant_reader)) {
- LOG(ERROR) << "Invalid attachment structure: "
- << "The 2nd variant entry should contain variant.";
- return false;
- }
-
- std::string value;
- if (!sub_variant_reader.PopString(&value))
- continue; // Ignore other attachment values.
+ const base::Value* annotation_value =
+ ibus_text_reader.GetAttachment(kAnnotationKey);
+ if (annotation_value) {
+ std::string annotation;
+ if (annotation_value->GetAsString(&annotation))
+ ibus_text->set_annotation(annotation);
+ }
- if (key == "annotation")
- ibus_text->set_annotation(value);
- else if (key == "description")
- ibus_text->set_description(value);
- else
- continue; // Ignore other fields.
+ const base::Value* description_value =
+ ibus_text_reader.GetAttachment(kDescriptionKey);
+ if (description_value) {
+ std::string description;
+ if (description_value->GetAsString(&description))
+ ibus_text->set_description(description);
}
std::string text;
« no previous file with comments | « chromeos/dbus/ibus/ibus_property.cc ('k') | chromeos/dbus/ibus/ibus_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698