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

Side by Side Diff: chromeos/dbus/ibus/ibus_text.cc

Issue 11362111: Fix: infolist requries description title. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments on 11361210 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/ibus/ibus_text.h ('k') | chromeos/dbus/ibus/ibus_text_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/values.h" 8 #include "base/values.h"
9 #include "chromeos/dbus/ibus/ibus_object.h" 9 #include "chromeos/dbus/ibus/ibus_object.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
11 11
12 namespace chromeos { 12 namespace chromeos {
13 // TODO(nona): Remove ibus namespace after complete libibus removal. 13 // TODO(nona): Remove ibus namespace after complete libibus removal.
14 namespace ibus { 14 namespace ibus {
15 15
16 namespace { 16 namespace {
17 const uint32 kAttributeUnderline = 1; // Indicates underline attribute. 17 const uint32 kAttributeUnderline = 1; // Indicates underline attribute.
18 const uint32 kAttributeSelection = 2; // Indicates background attribute. 18 const uint32 kAttributeSelection = 2; // Indicates background attribute.
19 const char kAnnotationKey[] = "annotation"; 19 const char kAnnotationKey[] = "annotation";
20 const char kDescriptionKey[] = "description"; 20 const char kDescriptionTitleKey[] = "description_title";
21 const char kDescriptionBodyKey[] = "description_body";
21 22
22 struct IBusAttribute { 23 struct IBusAttribute {
23 IBusAttribute() : type(0), value(0), start_index(0), end_index(0) {} 24 IBusAttribute() : type(0), value(0), start_index(0), end_index(0) {}
24 uint32 type; 25 uint32 type;
25 uint32 value; 26 uint32 value;
26 uint32 start_index; 27 uint32 start_index;
27 uint32 end_index; 28 uint32 end_index;
28 }; 29 };
29 30
30 // Pops a IBusAttribute from |reader|. 31 // Pops a IBusAttribute from |reader|.
(...skipping 29 matching lines...) Expand all
60 } // namespace 61 } // namespace
61 62
62 void AppendIBusText(const IBusText& ibus_text, dbus::MessageWriter* writer) { 63 void AppendIBusText(const IBusText& ibus_text, dbus::MessageWriter* writer) {
63 IBusObjectWriter ibus_text_writer("IBusText", "sv", writer); 64 IBusObjectWriter ibus_text_writer("IBusText", "sv", writer);
64 65
65 if (!ibus_text.annotation().empty()) { 66 if (!ibus_text.annotation().empty()) {
66 scoped_ptr<base::Value> annotation( 67 scoped_ptr<base::Value> annotation(
67 base::Value::CreateStringValue(ibus_text.annotation())); 68 base::Value::CreateStringValue(ibus_text.annotation()));
68 ibus_text_writer.AddAttachment(kAnnotationKey, *annotation.get()); 69 ibus_text_writer.AddAttachment(kAnnotationKey, *annotation.get());
69 } 70 }
70 71 if (!ibus_text.description_title().empty()) {
71 if (!ibus_text.description().empty()) { 72 scoped_ptr<base::Value> description_title(
72 scoped_ptr<base::Value> description( 73 base::Value::CreateStringValue(ibus_text.description_title()));
73 base::Value::CreateStringValue(ibus_text.description())); 74 ibus_text_writer.AddAttachment(kDescriptionTitleKey,
74 ibus_text_writer.AddAttachment(kDescriptionKey, *description.get()); 75 *description_title.get());
76 }
77 if (!ibus_text.description_body().empty()) {
78 scoped_ptr<base::Value> description_body(
79 base::Value::CreateStringValue(ibus_text.description_body()));
80 ibus_text_writer.AddAttachment(kDescriptionBodyKey,
81 *description_body.get());
75 } 82 }
76 ibus_text_writer.CloseHeader(); 83 ibus_text_writer.CloseHeader();
77 84
78 ibus_text_writer.AppendString(ibus_text.text()); 85 ibus_text_writer.AppendString(ibus_text.text());
79 86
80 // Start appending IBusAttrList into IBusText 87 // Start appending IBusAttrList into IBusText
81 IBusObjectWriter ibus_attr_list_writer("IBusAttrList", "av", NULL); 88 IBusObjectWriter ibus_attr_list_writer("IBusAttrList", "av", NULL);
82 ibus_text_writer.AppendIBusObject(&ibus_attr_list_writer); 89 ibus_text_writer.AppendIBusObject(&ibus_attr_list_writer);
83 ibus_attr_list_writer.CloseHeader(); 90 ibus_attr_list_writer.CloseHeader();
84 dbus::MessageWriter attribute_array_writer(NULL); 91 dbus::MessageWriter attribute_array_writer(NULL);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return false; 133 return false;
127 134
128 const base::Value* annotation_value = 135 const base::Value* annotation_value =
129 ibus_text_reader.GetAttachment(kAnnotationKey); 136 ibus_text_reader.GetAttachment(kAnnotationKey);
130 if (annotation_value) { 137 if (annotation_value) {
131 std::string annotation; 138 std::string annotation;
132 if (annotation_value->GetAsString(&annotation)) 139 if (annotation_value->GetAsString(&annotation))
133 ibus_text->set_annotation(annotation); 140 ibus_text->set_annotation(annotation);
134 } 141 }
135 142
136 const base::Value* description_value = 143 const base::Value* description_title_value =
137 ibus_text_reader.GetAttachment(kDescriptionKey); 144 ibus_text_reader.GetAttachment(kDescriptionTitleKey);
138 if (description_value) { 145 if (description_title_value) {
139 std::string description; 146 std::string description_title;
140 if (description_value->GetAsString(&description)) 147 if (description_title_value->GetAsString(&description_title))
141 ibus_text->set_description(description); 148 ibus_text->set_description_title(description_title);
149 }
150
151 const base::Value* description_body_value =
152 ibus_text_reader.GetAttachment(kDescriptionBodyKey);
153 if (description_body_value) {
154 std::string description_body;
155 if (description_body_value->GetAsString(&description_body))
156 ibus_text->set_description_body(description_body);
142 } 157 }
143 158
144 std::string text; 159 std::string text;
145 if (!ibus_text_reader.PopString(&text)) { 160 if (!ibus_text_reader.PopString(&text)) {
146 LOG(ERROR) << "Invalid variant structure[IBusText]: " 161 LOG(ERROR) << "Invalid variant structure[IBusText]: "
147 << "1st argument should be string."; 162 << "1st argument should be string.";
148 return false; 163 return false;
149 } 164 }
150 165
151 ibus_text->set_text(text); 166 ibus_text->set_text(text);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // IBusText 224 // IBusText
210 IBusText::IBusText() 225 IBusText::IBusText()
211 : text_("") { 226 : text_("") {
212 } 227 }
213 228
214 IBusText::~IBusText() { 229 IBusText::~IBusText() {
215 } 230 }
216 231
217 } // namespace ibus 232 } // namespace ibus
218 } // namespace chromeos 233 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_text.h ('k') | chromeos/dbus/ibus/ibus_text_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698