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

Side by Side Diff: chromeos/dbus/ibus/ibus_lookup_table.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/dbus/ibus/ibus_lookup_table.h ('k') | chromeos/dbus/ibus/ibus_object.h » ('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_lookup_table.h" 5 #include "chromeos/dbus/ibus/ibus_lookup_table.h"
6 6
7 #include <string> 7 #include <string>
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/values.h"
10 #include "chromeos/dbus/ibus/ibus_object.h"
11 #include "chromeos/dbus/ibus/ibus_text.h"
9 #include "dbus/message.h" 12 #include "dbus/message.h"
10 #include "chromeos/dbus/ibus/ibus_text.h"
11 #include "chromeos/dbus/ibus/ibus_object.h"
12 13
13 namespace chromeos { 14 namespace chromeos {
14 // TODO(nona): Remove ibus namespace after complete libibus removal. 15 // TODO(nona): Remove ibus namespace after complete libibus removal.
15 namespace ibus { 16 namespace ibus {
16 17
17 namespace { 18 namespace {
18 // The default entry number of a page in IBusLookupTable. 19 // The default entry number of a page in IBusLookupTable.
19 const int kDefaultPageSize = 9; 20 const int kDefaultPageSize = 9;
21 const char kShowWindowAtCompositionKey[] = "show_window_at_composition";
20 } // namespace 22 } // namespace
21 23
22 void AppendIBusLookupTable(const IBusLookupTable& table, 24 void AppendIBusLookupTable(const IBusLookupTable& table,
23 dbus::MessageWriter* writer) { 25 dbus::MessageWriter* writer) {
24 IBusObjectWriter ibus_lookup_table_writer("IBusLookupTable", 26 IBusObjectWriter ibus_lookup_table_writer("IBusLookupTable",
25 "uubbiavav", 27 "uubbiavav",
26 writer); 28 writer);
29 scoped_ptr<base::Value> show_position(
30 base::Value::CreateBooleanValue(table.show_window_at_composition()));
31 ibus_lookup_table_writer.AddAttachment(kShowWindowAtCompositionKey,
32 *show_position.get());
33 ibus_lookup_table_writer.CloseHeader();
27 ibus_lookup_table_writer.AppendUint32(table.page_size()); 34 ibus_lookup_table_writer.AppendUint32(table.page_size());
28 ibus_lookup_table_writer.AppendUint32(table.cursor_position()); 35 ibus_lookup_table_writer.AppendUint32(table.cursor_position());
29 ibus_lookup_table_writer.AppendBool(table.is_cursor_visible()); 36 ibus_lookup_table_writer.AppendBool(table.is_cursor_visible());
30 ibus_lookup_table_writer.AppendBool(false); // Not used in Chrome. 37 ibus_lookup_table_writer.AppendBool(false); // Not used in Chrome.
31 ibus_lookup_table_writer.AppendInt32(static_cast<int32>(table.orientation())); 38 ibus_lookup_table_writer.AppendInt32(static_cast<int32>(table.orientation()));
32 39
33 const std::vector<IBusLookupTable::Entry>& candidates = table.candidates(); 40 const std::vector<IBusLookupTable::Entry>& candidates = table.candidates();
34 dbus::MessageWriter text_writer(NULL); 41 dbus::MessageWriter text_writer(NULL);
35 ibus_lookup_table_writer.OpenArray("v", &text_writer); 42 ibus_lookup_table_writer.OpenArray("v", &text_writer);
36 bool have_labels = false; 43 bool have_labels = false;
(...skipping 16 matching lines...) Expand all
53 } 60 }
54 } 61 }
55 ibus_lookup_table_writer.CloseContainer(&label_writer); 62 ibus_lookup_table_writer.CloseContainer(&label_writer);
56 63
57 ibus_lookup_table_writer.CloseAll(); 64 ibus_lookup_table_writer.CloseAll();
58 } 65 }
59 66
60 bool PopIBusLookupTable(dbus::MessageReader* reader, IBusLookupTable* table) { 67 bool PopIBusLookupTable(dbus::MessageReader* reader, IBusLookupTable* table) {
61 IBusObjectReader ibus_object_reader("IBusLookupTable", reader); 68 IBusObjectReader ibus_object_reader("IBusLookupTable", reader);
62 69
63 dbus::MessageReader attachment_reader(NULL); 70 if (!ibus_object_reader.Init())
64 if (!ibus_object_reader.InitWithAttachmentReader(&attachment_reader))
65 return false; 71 return false;
66 72
67 while (attachment_reader.HasMoreData()) { 73 const base::Value* value =
68 dbus::MessageReader dictionary_reader(NULL); 74 ibus_object_reader.GetAttachment(kShowWindowAtCompositionKey);
69 if (!attachment_reader.PopDictEntry(&dictionary_reader)) { 75 if (value) {
70 LOG(ERROR) << "Invalid attachment structure: " 76 bool show_window_at_composition;
71 << "The attachment field is array of dictionary entry."; 77 if (value->GetAsBoolean(&show_window_at_composition))
72 return false; 78 table->set_show_window_at_composition(show_window_at_composition);
73 }
74
75 std::string key;
76 if (!dictionary_reader.PopString(&key)) {
77 LOG(ERROR) << "Invalid attachement structure: "
78 << "The 1st dictionary entry should be string.";
79 return false;
80 }
81 if (key != "show_window_at_composition")
82 continue;
83
84 dbus::MessageReader variant_reader(NULL);
85 if (!dictionary_reader.PopVariant(&variant_reader)) {
86 LOG(ERROR) << "Invalid attachment structure: "
87 << "The 2nd dictionary entry shuold be variant.";
88 return false;
89 }
90
91 dbus::MessageReader sub_variant_reader(NULL);
92 if (!variant_reader.PopVariant(&sub_variant_reader)) {
93 LOG(ERROR) << "Invalid attachment structure: "
94 << "The 2nd variant entry should contain variant.";
95 return false;
96 }
97
98 bool show_window_at_composition = false;
99 if (!sub_variant_reader.PopBool(&show_window_at_composition))
100 continue; // Ignores other field.
101
102 table->set_show_window_at_composition(show_window_at_composition);
103 } 79 }
104 80
105 uint32 page_size = 0; 81 uint32 page_size = 0;
106 if (!ibus_object_reader.PopUint32(&page_size)) { 82 if (!ibus_object_reader.PopUint32(&page_size)) {
107 LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " 83 LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: "
108 << "1st argument should be uint32."; 84 << "1st argument should be uint32.";
109 return false; 85 return false;
110 } 86 }
111 table->set_page_size(page_size); 87 table->set_page_size(page_size);
112 88
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 171 }
196 return true; 172 return true;
197 } 173 }
198 174
199 /////////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////////
200 // IBusLookupTable 176 // IBusLookupTable
201 IBusLookupTable::IBusLookupTable() 177 IBusLookupTable::IBusLookupTable()
202 : page_size_(kDefaultPageSize), 178 : page_size_(kDefaultPageSize),
203 cursor_position_(0), 179 cursor_position_(0),
204 is_cursor_visible_(true), 180 is_cursor_visible_(true),
205 orientation_(IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL) { 181 orientation_(IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL),
182 show_window_at_composition_(false) {
206 } 183 }
207 184
208 IBusLookupTable::~IBusLookupTable() { 185 IBusLookupTable::~IBusLookupTable() {
209 } 186 }
210 187
211 IBusLookupTable::Entry::Entry() { 188 IBusLookupTable::Entry::Entry() {
212 } 189 }
213 190
214 IBusLookupTable::Entry::~Entry() { 191 IBusLookupTable::Entry::~Entry() {
215 } 192 }
216 193
217 } // namespace ibus 194 } // namespace ibus
218 } // namespace chromeos 195 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_lookup_table.h ('k') | chromeos/dbus/ibus/ibus_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698