Chromium Code Reviews| Index: chromeos/dbus/ibus/ibus_lookup_table.cc |
| diff --git a/chromeos/dbus/ibus/ibus_lookup_table.cc b/chromeos/dbus/ibus/ibus_lookup_table.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d7a6748066d8376cfc2126f5986f70526536ad0a |
| --- /dev/null |
| +++ b/chromeos/dbus/ibus/ibus_lookup_table.cc |
| @@ -0,0 +1,196 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/ibus/ibus_lookup_table.h" |
| + |
| +#include <string> |
| +#include "base/logging.h" |
| +#include "dbus/message.h" |
| +#include "chromeos/dbus/ibus/ibus_text.h" |
| +#include "chromeos/dbus/ibus/ibus_object.h" |
| + |
| +namespace chromeos { |
| + |
| +void AppendIBusLookupTable(const IBusLookupTable& table, |
| + dbus::MessageWriter* writer) { |
| + IBusObjectWriter ibus_lookup_table_writer("IBusLookupTable", |
| + "uubbiavav", |
| + writer); |
| + ibus_lookup_table_writer.AppendUint32(table.page_size()); |
| + ibus_lookup_table_writer.AppendUint32(table.cursor_position()); |
| + ibus_lookup_table_writer.AppendBool(table.is_cursor_visible()); |
| + ibus_lookup_table_writer.AppendBool(false); // Not used in Chrome. |
| + ibus_lookup_table_writer.AppendInt32(static_cast<int32>(table.orientation())); |
| + |
| + const std::vector<std::string>& candidates = table.candidates(); |
| + dbus::MessageWriter text_writer(NULL); |
| + ibus_lookup_table_writer.OpenArray("v", &text_writer); |
| + for (size_t i = 0; i < candidates.size(); ++i) { |
| + // Write candidate string as IBusText. |
| + IBusText text; |
| + text.set_text(candidates[i]); |
| + AppendIBusText(text, &text_writer); |
| + } |
| + ibus_lookup_table_writer.CloseContainer(&text_writer); |
| + |
| + const std::vector<std::string>& labels = table.labels(); |
| + dbus::MessageWriter label_writer(NULL); |
| + ibus_lookup_table_writer.OpenArray("v", &label_writer); |
| + for (size_t i = 0; i < labels.size(); ++i) { |
| + // Write label string as IBusText. |
| + IBusText text; |
| + text.set_text(labels[i]); |
| + AppendIBusText(text, &label_writer); |
| + } |
| + ibus_lookup_table_writer.CloseContainer(&label_writer); |
| + |
| + ibus_lookup_table_writer.CloseAll(); |
| +} |
| + |
| +bool PopIBusLookupTable(dbus::MessageReader* reader, IBusLookupTable* table) { |
| + IBusObjectReader ibus_object_reader("IBusLookupTable", reader); |
| + if (!ibus_object_reader.Init()) |
| + return false; |
| + |
| + uint32 page_size = 0; |
| + if (!ibus_object_reader.PopUint32(&page_size)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "1st argument should be uint32."; |
| + return false; |
| + } |
| + table->set_page_size(page_size); |
| + |
| + uint32 cursor_position = 0; |
| + if (!ibus_object_reader.PopUint32(&cursor_position)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "2nd argument should be uint32."; |
| + return false; |
| + } |
| + table->set_cursor_position(cursor_position); |
| + |
| + bool cursor_visible = true; |
| + if (!ibus_object_reader.PopBool(&cursor_visible)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "3rd arugment should be boolean."; |
| + return false; |
| + } |
| + table->set_is_cursor_visible(cursor_visible); |
| + |
| + bool unused_round_value = true; |
| + if (!ibus_object_reader.PopBool(&unused_round_value)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "4th argument should be boolean."; |
| + return false; |
| + } |
| + |
| + int32 orientation = 0; |
| + if (!ibus_object_reader.PopInt32(&orientation)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "5th arguemnt should be int32."; |
| + return false; |
| + } |
| + table->set_orientation( |
| + static_cast<IBusLookupTable::Orientation>(orientation)); |
| + |
| + dbus::MessageReader text_array_reader(NULL); |
| + if (!ibus_object_reader.PopArray(&text_array_reader)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "6th argument should be array."; |
| + return false; |
| + } |
| + |
| + std::vector<std::string>* candidates = table->mutable_candidates(); |
| + while (text_array_reader.HasMoreData()) { |
| + IBusText text; |
| + if (!PopIBusText(&text_array_reader, &text)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "6th argument should be array of IBusText."; |
| + return false; |
| + } |
| + // The attributes in IBusText are not used in Chrome. |
| + candidates->push_back(text.text()); |
| + } |
| + |
| + dbus::MessageReader label_array_reader(NULL); |
| + if (!ibus_object_reader.PopArray(&label_array_reader)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "7th argument should be array."; |
| + return false; |
| + } |
| + |
| + std::vector<std::string>* labels = table->mutable_labels(); |
| + while (label_array_reader.HasMoreData()) { |
| + IBusText text; |
| + if (!PopIBusText(&label_array_reader, &text)) { |
| + LOG(ERROR) << "Invalid variant structure[IBusLookupTable]: " |
| + << "7th argument should be array of IBusText."; |
| + return false; |
| + } |
| + // The attributes in IBusText are not used in Chrome. |
| + labels->push_back(text.text()); |
| + } |
| + return true; |
| +} |
| + |
| +/////////////////////////////////////////////////////////////////////////////// |
| +// IBusLookupTable |
| +IBusLookupTable::IBusLookupTable() |
| + : page_size_(0), |
| + cursor_position_(0), |
| + is_cursor_visible_(true), |
| + orientation_(IBUS_LOOKUP_TABLE_ORIENTATION_HORIZONTAL) { |
| +} |
| + |
| +IBusLookupTable::~IBusLookupTable() { |
| +} |
| + |
| +uint32 IBusLookupTable::page_size() const { |
| + return page_size_; |
| +} |
|
satorux1
2012/05/11 22:55:29
Please incline simpler getters/setters in .h file.
Seigo Nonaka
2012/05/18 17:57:46
Done.
|
| + |
| +void IBusLookupTable::set_page_size(uint32 page_size) { |
| + page_size_ = page_size; |
| +} |
| + |
| +uint32 IBusLookupTable::cursor_position() const { |
| + return cursor_position_; |
| +} |
| + |
| +void IBusLookupTable::set_cursor_position(uint32 cursor_position) { |
| + cursor_position_ = cursor_position; |
| +} |
| + |
| +bool IBusLookupTable::is_cursor_visible() const { |
| + return is_cursor_visible_; |
| +} |
| + |
| +void IBusLookupTable::set_is_cursor_visible(bool is_cursor_visible) { |
| + is_cursor_visible_ = is_cursor_visible; |
| +} |
| + |
| +IBusLookupTable::Orientation IBusLookupTable::orientation() const { |
| + return orientation_; |
| +} |
| + |
| +void IBusLookupTable::set_orientation(Orientation orientation) { |
| + orientation_ = orientation; |
| +} |
| + |
| +const std::vector<std::string>& IBusLookupTable::candidates() const { |
| + return candidates_; |
| +} |
| + |
| +std::vector<std::string>* IBusLookupTable::mutable_candidates() { |
| + return &candidates_; |
| +} |
| + |
| +const std::vector<std::string>& IBusLookupTable::labels() const { |
| + return labels_; |
| +} |
| + |
| +std::vector<std::string>* IBusLookupTable::mutable_labels() { |
| + return &labels_; |
| +} |
| + |
| +} // namespace chromeos |