summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkomatsu@chromium.org <komatsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 12:58:21 +0000
committerkomatsu@chromium.org <komatsu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-18 12:58:21 +0000
commit35adb3f605b817a4e8b8448826d7f5137298a5cc (patch)
tree80221ddfe3b9d40c8d448482951b6a9a86000f8c
parent6f6a49447982e0dc1484b2dd983cbcfb50322582 (diff)
downloadchromium_src-35adb3f605b817a4e8b8448826d7f5137298a5cc.zip
chromium_src-35adb3f605b817a4e8b8448826d7f5137298a5cc.tar.gz
chromium_src-35adb3f605b817a4e8b8448826d7f5137298a5cc.tar.bz2
Delete ibus_object and move ibus_text to chromeos/ime.
This patch focuses on the deletion and relocation keeping the logic as-is. BUG=275262 Review URL: https://codereview.chromium.org/61003004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235726 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_ibus.cc2
-rw-r--r--chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc2
-rw-r--r--chromeos/chromeos.gyp9
-rw-r--r--chromeos/dbus/ibus/ibus_object.cc316
-rw-r--r--chromeos/dbus/ibus/ibus_object.h241
-rw-r--r--chromeos/dbus/ibus/ibus_object_unittest.cc180
-rw-r--r--chromeos/dbus/ibus/ibus_text.cc239
-rw-r--r--chromeos/dbus/ibus/ibus_text.h190
-rw-r--r--chromeos/dbus/ibus/ibus_text_unittest.cc100
-rw-r--r--chromeos/ime/ibus_text.cc22
-rw-r--r--chromeos/ime/ibus_text.h86
-rw-r--r--chromeos/ime/ibus_text_unittest.cc72
-rw-r--r--chromeos/ime/mock_ime_input_context_handler.cc2
-rw-r--r--chromeos/ime/mock_ime_input_context_handler.h2
-rw-r--r--ui/base/ime/input_method_ibus.cc2
-rw-r--r--ui/base/ime/input_method_ibus_unittest.cc2
16 files changed, 189 insertions, 1278 deletions
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc b/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc
index c7046bc..682a529 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine_ibus.cc
@@ -15,11 +15,11 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
#include "chromeos/ime/candidate_window.h"
#include "chromeos/ime/component_extension_ime_manager.h"
#include "chromeos/ime/extension_ime_util.h"
#include "chromeos/ime/ibus_keymap.h"
+#include "chromeos/ime/ibus_text.h"
#include "chromeos/ime/input_method_manager.h"
#include "dbus/object_path.h"
diff --git a/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc b/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc
index 16c7df5..b045bf8 100644
--- a/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc
+++ b/chrome/browser/chromeos/input_method/input_method_engine_ibus_browserttests.cc
@@ -5,9 +5,9 @@
#include "base/bind_helpers.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
#include "chromeos/ime/component_extension_ime_manager.h"
#include "chromeos/ime/ibus_bridge.h"
+#include "chromeos/ime/ibus_text.h"
#include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_method_manager.h"
#include "chromeos/ime/mock_ime_candidate_window_handler.h"
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 3e6f8e2..6eab801 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -170,10 +170,6 @@
'dbus/shill_stub_helper.cc',
'dbus/shill_stub_helper.h',
'dbus/ibus/ibus_constants.h',
- 'dbus/ibus/ibus_object.cc',
- 'dbus/ibus/ibus_object.h',
- 'dbus/ibus/ibus_text.cc',
- 'dbus/ibus/ibus_text.h',
'dbus/image_burner_client.cc',
'dbus/image_burner_client.h',
'dbus/introspectable_client.cc',
@@ -216,6 +212,8 @@
'ime/ibus_daemon_controller.h',
'ime/ibus_keymap.cc',
'ime/ibus_keymap.h',
+ 'ime/ibus_text.cc',
+ 'ime/ibus_text.h',
'ime/input_method_config.cc',
'ime/input_method_config.h',
'ime/input_method_delegate.h',
@@ -477,8 +475,6 @@
'dbus/blocking_method_caller_unittest.cc',
'dbus/cros_disks_client_unittest.cc',
'dbus/gsm_sms_client_unittest.cc',
- 'dbus/ibus/ibus_object_unittest.cc',
- 'dbus/ibus/ibus_text_unittest.cc',
'dbus/introspectable_client_unittest.cc',
'dbus/modem_messaging_client_unittest.cc',
'dbus/nfc_client_unittest.cc',
@@ -496,6 +492,7 @@
'ime/candidate_window_unittest.cc',
'ime/component_extension_ime_manager_unittest.cc',
'ime/extension_ime_util_unittest.cc',
+ 'ime/ibus_text_unittest.cc',
'ime/input_method_manager.h',
'ime/input_method_property_unittest.cc',
'ime/input_method_whitelist_unittest.cc',
diff --git a/chromeos/dbus/ibus/ibus_object.cc b/chromeos/dbus/ibus/ibus_object.cc
deleted file mode 100644
index 67e5ca5..0000000
--- a/chromeos/dbus/ibus/ibus_object.cc
+++ /dev/null
@@ -1,316 +0,0 @@
-// 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_object.h"
-
-#include "base/logging.h"
-#include "base/values.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
-#include "dbus/message.h"
-#include "dbus/values_util.h"
-
-namespace chromeos {
-
-///////////////////////////////////////////////////////////////////////////////
-// IBusObjectReader
-IBusObjectReader::IBusObjectReader(const std::string& type_name,
- dbus::MessageReader* reader)
- : type_name_(type_name),
- original_reader_(reader),
- check_result_(IBUS_OBJECT_NOT_CHECKED) {}
-
-IBusObjectReader::~IBusObjectReader() {
- for (std::map<std::string, base::Value*>::iterator ite = attachments_.begin();
- ite != attachments_.end(); ++ite)
- delete ite->second;
-}
-
-bool IBusObjectReader::Init() {
- DCHECK(original_reader_);
- DCHECK_EQ(IBUS_OBJECT_NOT_CHECKED, check_result_);
-
- top_variant_reader_.reset(new dbus::MessageReader(NULL));
- contents_reader_.reset(new dbus::MessageReader(NULL));
- check_result_ = IBUS_OBJECT_INVALID;
-
- // IBus object has a variant on top-level.
- if (!original_reader_->PopVariant(top_variant_reader_.get())) {
- LOG(ERROR) << "Invalid object structure[" << type_name_ << "]: "
- << "can not find top variant field.";
- return false;
- }
-
- // IBus object has struct on second level.
- if (!top_variant_reader_->PopStruct(contents_reader_.get())) {
- LOG(ERROR) << "Invalid object structure[" << type_name_ << "]: "
- << "can not find top struct field.";
- return false;
- }
-
- // IBus object has type key at the first element.
- std::string type_name;
- if (!contents_reader_->PopString(&type_name)) {
- LOG(ERROR) << "Invalid object structure[" << type_name_ << "]: "
- << "Can not get type name field.";
- return false;
- }
-
- if (type_name != type_name_) {
- LOG(ERROR) << "Type check failed: Given variant is not " << type_name_
- << " and actual type is " << type_name << ".";
- return false;
- }
-
- dbus::MessageReader attachment_reader(NULL);
-
- // IBus object has array object at the second element, which is used in
- // attaching additional information.
- if (!contents_reader_->PopArray(&attachment_reader)) {
- LOG(ERROR) << "Invalid object structure[" << type_name_ << "] "
- << "can not find attachment array field.";
- 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 attachment structure: "
- << "The 1st dictionary entry should be string.";
- return false;
- }
-
- if (key.empty()) {
- LOG(ERROR) << "Invalid attachment key: key is empty.";
- return false;
- }
-
- dbus::MessageReader variant_reader(NULL);
- if (!dictionary_reader.PopVariant(&variant_reader)) {
- LOG(ERROR) << "Invalid attachment structure: "
- << "The 2nd dictionary entry should 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;
- }
-
- attachments_[key] = dbus::PopDataAsValue(&sub_variant_reader);
- }
- check_result_ = IBUS_OBJECT_VALID;
- return true;
-}
-
-bool IBusObjectReader::InitWithParentReader(dbus::MessageReader* reader) {
- original_reader_ = reader;
- return Init();
-}
-
-bool IBusObjectReader::PopString(std::string* out) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->PopString(out);
-}
-
-bool IBusObjectReader::PopUint32(uint32* out) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->PopUint32(out);
-}
-
-bool IBusObjectReader::PopInt32(int32* out) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->PopInt32(out);
-}
-
-bool IBusObjectReader::PopBool(bool* out) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->PopBool(out);
-}
-
-bool IBusObjectReader::PopArray(dbus::MessageReader* reader) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->PopArray(reader);
-}
-
-bool IBusObjectReader::PopIBusText(IBusText* text) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && chromeos::PopIBusText(contents_reader_.get(), text);
-}
-
-bool IBusObjectReader::PopStringFromIBusText(std::string* text) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && chromeos::PopStringFromIBusText(
- contents_reader_.get(), text);
-}
-
-const base::Value* IBusObjectReader::GetAttachment(const std::string& key) {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- if (!IsValid())
- return NULL;
- std::map<std::string, base::Value*>::iterator it = attachments_.find(key);
- if (it == attachments_.end())
- return NULL;
- return it->second;
-}
-
-bool IBusObjectReader::HasMoreData() {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- DCHECK(contents_reader_.get());
- return IsValid() && contents_reader_->HasMoreData();
-}
-
-bool IBusObjectReader::PopIBusObject(IBusObjectReader* reader) {
- DCHECK(contents_reader_.get());
- if (!IsValid())
- return false;
- return reader->InitWithParentReader(contents_reader_.get());
-}
-
-bool IBusObjectReader::IsValid() const {
- DCHECK_NE(IBUS_OBJECT_NOT_CHECKED, check_result_);
- return check_result_ == IBUS_OBJECT_VALID;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// IBusObjectWriter
-IBusObjectWriter::IBusObjectWriter(const std::string& type_name,
- const std::string& signature,
- dbus::MessageWriter* writer)
- : type_name_(type_name),
- signature_(signature),
- original_writer_(writer),
- state_(NOT_INITIALZED) {
- if (original_writer_)
- Init();
-}
-
-IBusObjectWriter::~IBusObjectWriter() {
-}
-
-void IBusObjectWriter::AppendString(const std::string& input) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->AppendString(input);
-}
-
-void IBusObjectWriter::AppendUint32(uint32 input) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->AppendUint32(input);
-}
-
-void IBusObjectWriter::AppendInt32(int32 input) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->AppendInt32(input);
-}
-
-void IBusObjectWriter::AppendBool(bool input) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->AppendBool(input);
-}
-
-void IBusObjectWriter::OpenArray(const std::string& signature,
- dbus::MessageWriter* writer) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->OpenArray(signature, writer);
-}
-
-void IBusObjectWriter::AppendIBusText(const IBusText& text) {
- DCHECK_EQ(state_, INITIALIZED);
- chromeos::AppendIBusText(text, contents_writer_.get());
-}
-
-void IBusObjectWriter::AppendStringAsIBusText(const std::string& text) {
- DCHECK_EQ(state_, INITIALIZED);
- chromeos::AppendStringAsIBusText(text, contents_writer_.get());
-}
-
-void IBusObjectWriter::CloseContainer(dbus::MessageWriter* writer) {
- DCHECK_EQ(state_, INITIALIZED);
- contents_writer_->CloseContainer(writer);
-}
-
-void IBusObjectWriter::AppendIBusObject(IBusObjectWriter* writer) {
- DCHECK_EQ(state_, INITIALIZED);
- writer->InitWithParentWriter(contents_writer_.get());
-}
-
-void IBusObjectWriter::Init() {
- DCHECK(original_writer_);
- DCHECK_EQ(state_, NOT_INITIALZED);
-
- top_variant_writer_.reset(new dbus::MessageWriter(NULL));
- contents_writer_.reset(new dbus::MessageWriter(NULL));
- attachment_writer_.reset(new dbus::MessageWriter(NULL));
-
- const std::string ibus_signature = "(sa{sv}" + signature_ + ")";
- original_writer_->OpenVariant(ibus_signature, top_variant_writer_.get());
- top_variant_writer_->OpenStruct(contents_writer_.get());
-
- contents_writer_->AppendString(type_name_);
-
- contents_writer_->OpenArray("{sv}", attachment_writer_.get());
- state_ = HEADER_OPEN;
-}
-
-void IBusObjectWriter::InitWithParentWriter(dbus::MessageWriter* writer) {
- DCHECK_EQ(state_, NOT_INITIALZED) << "Already initialized.";
- original_writer_ = writer;
- Init();
-}
-
-void IBusObjectWriter::CloseAll() {
- DCHECK(original_writer_);
- DCHECK_NE(state_, NOT_INITIALZED);
- if (state_ == HEADER_OPEN)
- CloseHeader();
-
- top_variant_writer_->CloseContainer(contents_writer_.get());
- original_writer_->CloseContainer(top_variant_writer_.get());
- top_variant_writer_.reset();
- contents_writer_.reset();
-}
-
-void IBusObjectWriter::CloseHeader() {
- DCHECK_EQ(state_, HEADER_OPEN) << "Header is already closed.";
- contents_writer_->CloseContainer(attachment_writer_.get());
- state_ = INITIALIZED;
-}
-
-bool IBusObjectWriter::AddAttachment(const std::string& key,
- const base::Value& value) {
- DCHECK_NE(state_, NOT_INITIALZED) << "Do not call before Init();";
- DCHECK_NE(state_, INITIALIZED) << "Do not call after CloseHeader().";
- DCHECK(attachment_writer_.get());
- DCHECK(!key.empty());
- DCHECK(!value.IsType(base::Value::TYPE_NULL));
-
- dbus::MessageWriter dict_writer(NULL);
- attachment_writer_->OpenDictEntry(&dict_writer);
- dict_writer.AppendString(key);
- dbus::MessageWriter variant_writer(NULL);
- dict_writer.OpenVariant("v", &variant_writer);
-
- dbus::AppendBasicTypeValueDataAsVariant(&variant_writer, value);
- dict_writer.CloseContainer(&variant_writer);
- attachment_writer_->CloseContainer(&variant_writer);
- return true;
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/ibus/ibus_object.h b/chromeos/dbus/ibus/ibus_object.h
deleted file mode 100644
index 9737dfa..0000000
--- a/chromeos/dbus/ibus/ibus_object.h
+++ /dev/null
@@ -1,241 +0,0 @@
-// 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.
-
-#ifndef CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_
-#define CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_
-
-#include <map>
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
-
-namespace base {
-class Value;
-} // namespace base
-
-namespace dbus {
-class MessageReader;
-class MessageWriter;
-} // namespace dbus
-
-namespace chromeos {
-
-// The data structure of IBusObject is represented as variant in "(sav...)"
-// signature. The IBusObject is constructed with two sections, header and
-// contents. The header section is represent as "sav" which contains type name
-// and attachment array. The contents section is corresponding to "..." in
-// above signature, which can store arbitrary type values including IBusObject.
-//
-// DATA STRUCTURE OVERVIEW:
-//
-// variant // Handle with top_variant_writer_/top_variant_reader_.
-// struct { // Handle with contents_writer_/contents_reader_.
-// // Header section
-// string typename // The type name of object, like "IBusText"
-// array [ // attachment array.
-// dict_entry (
-// string "mozc.candidates" // The key in the dictionary entry.
-// variant ... // The value in the dictionary entry.
-// )
-// ...
-// ]
-//
-// // Contents section
-// ... // The contents area.
-// }
-//
-// EXAMPLE: IBusText
-//
-// variant struct {
-// string "IBusText" // Header of IBusText
-// array[]
-// string "A" // The 1st value of IBusText
-// variant struct { // THe 2nd value of IBusText
-// string "IBusAttrList" // Header of IBusAttrList
-// array[]
-// array[ // The 1st value of IBusAttrList
-// variant struct{
-// string "IBusAttribute" // Header of IBusAttribute
-// array[]
-// uint32 1 // The 1st value of IBusAttribute
-// uint32 1 // The 2nd value of IBusAttribute
-// uint32 0 // The 3rd value of IBusAttribute
-// uint32 1 // The 4th value of IBusAttribute
-// }
-// ]
-// }
-// }
-//
-// The IBusObjectReader class provides reading IBusObject including attachment
-// field from dbus message. This class checks the IBusObject header structure
-// and type name before reading contents.
-//
-// EXAPMLE USAGE:
-// // Creates reader for IBusText
-// IBusObjectReader object_reader("IBusText", &reader);
-//
-// // Initialize for reading attachment field.
-// object_reader.Init();
-//
-// // Get attachment field.
-// base::Value* value = object_reader.GetAttachment("annotation");
-//
-// std::string text;
-// reader.PopString(&text); // Reading 1st value as string.
-//
-// // We can also read nested IBusObject.
-// IBusObjectReader nested_object_reader("IBusAttrList", NULL);
-// reader.PopIBusObject(&nested_object_reader);
-class CHROMEOS_EXPORT IBusObjectReader {
- public:
- // |reader| must be released by caller.
- IBusObjectReader(const std::string& type_name,
- dbus::MessageReader* reader);
- virtual ~IBusObjectReader();
-
- // Reads IBusObject headers and checks if the type name is valid.
- // Returns true on success. Uses InitWitAttachmentReader instead if you want
- // to read attachment field.
- bool Init();
-
- // Reads IBusOBject with |reader| and checks if the type name is valid.
- bool InitWithParentReader(dbus::MessageReader* reader);
-
- // Returns true if the IBusObject is valid.
- bool IsValid() const;
-
- // The following functions delegate dbus::MessageReader's functions.
- bool PopString(std::string* out);
- bool PopUint32(uint32* out);
- bool PopArray(dbus::MessageReader* reader);
- bool PopBool(bool* out);
- bool PopInt32(int32* out);
- bool HasMoreData();
-
- // Sets up |reader| for reading an IBusObject entry.
- bool PopIBusObject(IBusObjectReader* reader);
-
- // Pops a IBusText.
- // Returns true on success.
- bool PopIBusText(IBusText* text);
-
- // Pops a IBusText and store it's text field into |text|. Use PopIBusText
- // instead in the case of using any attribute entries in IBusText.
- // Return true on success.
- bool PopStringFromIBusText(std::string* text);
-
- // Gets attachment entry corresponding to |key|. Do not free returned value.
- // Returns NULL if there is no entry.
- const base::Value* GetAttachment(const std::string& key);
-
- private:
- enum CheckResult {
- IBUS_OBJECT_VALID, // Already checked and valid type.
- IBUS_OBJECT_INVALID, // Already checked but invalid type.
- IBUS_OBJECT_NOT_CHECKED, // Not checked yet.
- };
-
- std::string type_name_;
- dbus::MessageReader* original_reader_;
- scoped_ptr<dbus::MessageReader> top_variant_reader_;
- scoped_ptr<dbus::MessageReader> contents_reader_;
- CheckResult check_result_;
- std::map<std::string, base::Value*> attachments_;
-
- DISALLOW_COPY_AND_ASSIGN(IBusObjectReader);
-};
-
-// IBusObjectWriter class provides writing IBusObject to dbus message. This
-// class appends header section before appending contents values.
-// IBusObjectWriter does not support writing attachment field because writing
-// attachment field is not used in Chrome.
-//
-// EXAMPLE USAGE:
-// // Creates writer for IBusText
-// IBusObjectWriter object_writer("IBusText", "sv", &writer);
-//
-// // Add some attachments.
-// base::Value* value = base::Value::CreateStringValue("Noun");
-// object_writer.AddAttachment("annotation", *value);
-//
-// // Close header section.
-// object_writer.CloseHeader();
-//
-// const std::string text = "Sample Text";
-// writer.AppendString(text);
-//
-// // We can also write nested IBusObject.
-// IBusObjectWriter nested_object_writer("IBusAttrList", "av");
-// object_writer.AppendIBusObject(&nested_object_writer);
-// ... appends values
-//
-// nested_object_writer.CloseAll(); // To finish up, should call CloseAll.
-// object_writer.CloseAll();
-class CHROMEOS_EXPORT IBusObjectWriter {
- public:
- enum WriterState {
- NOT_INITIALZED, // Created but not initialized.
- HEADER_OPEN, // Ready for writing attachment field.
- INITIALIZED // Ready for writing content values.
- };
-
- // |writer| must be released by caller.
- IBusObjectWriter(const std::string& type_name,
- const std::string& signature,
- dbus::MessageWriter* writer);
- virtual ~IBusObjectWriter();
-
- // Closes header to write content values.
- void CloseHeader();
-
- // Appends IBusObject headers with |writer|, should be called once.
- void InitWithParentWriter(dbus::MessageWriter* writer);
-
- // Adds an attachment, this function can be called only before CloseHeader
- // function call.
- bool AddAttachment(const std::string& key, const base::Value& value);
-
- // The following functions delegate dbus::MessageReader's functions.
- void AppendString(const std::string& input);
- void AppendUint32(uint32 value);
- void AppendInt32(int32 value);
- void AppendBool(bool value);
- void OpenArray(const std::string& signature,
- dbus::MessageWriter* writer);
- void CloseContainer(dbus::MessageWriter* writer);
-
- // Sets up |writer| for writing new IBusObject entry.
- void AppendIBusObject(IBusObjectWriter* writer);
-
- // Closes all opened containers.
- void CloseAll();
-
- // Appends a IBusText.
- void AppendIBusText(const IBusText& text);
-
- // Appends a string as IBusText without any attributes. Use AppendIBusText
- // instead in the case of using any attribute entries.
- void AppendStringAsIBusText(const std::string& text);
-
- private:
- // Appends IBusObject headers, should be called once.
- void Init();
-
- std::string type_name_;
- std::string signature_;
- dbus::MessageWriter* original_writer_;
- WriterState state_;
- scoped_ptr<dbus::MessageWriter> top_variant_writer_;
- scoped_ptr<dbus::MessageWriter> contents_writer_;
- scoped_ptr<dbus::MessageWriter> attachment_writer_;
-
- DISALLOW_COPY_AND_ASSIGN(IBusObjectWriter);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_IBUS_IBUS_OBJECT_H_
diff --git a/chromeos/dbus/ibus/ibus_object_unittest.cc b/chromeos/dbus/ibus/ibus_object_unittest.cc
deleted file mode 100644
index e04e58b..0000000
--- a/chromeos/dbus/ibus/ibus_object_unittest.cc
+++ /dev/null
@@ -1,180 +0,0 @@
-// 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.
-// TODO(nona): Add more test case, especially fail case.
-
-#include "chromeos/dbus/ibus/ibus_object.h"
-
-#include <string>
-#include <vector>
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/values.h"
-#include "dbus/message.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace chromeos {
-
-TEST(IBusObjectTest, WriteReadTest) {
- scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
- dbus::MessageWriter writer(message.get());
-
- const char kSampleTypeName1[] = "Sample Type Name 1";
- const char kSampleTypeName2[] = "Sample Type Name 2";
- const char kSampleText1[] = "Sample Text 1";
- const char kSampleText2[] = "Sample Text 2";
- const uint32 kSampleUint32 = 12345UL;
- const int32 kSampleInt32 = 54321;
- const bool kSampleBool = false;
- const uint32 kSampleArrayOfUint32Count = 10UL;
- const char kAttachmentKey[] = "key";
- const char kStringAttachment[] = "Attachment String Value";
-
- // Create ibus object.
- IBusObjectWriter ibus_object_writer(kSampleTypeName1, "suibauv", &writer);
-
- // Write attachment field.
- scoped_ptr<base::Value> write_value(
- base::Value::CreateStringValue(kStringAttachment));
- ibus_object_writer.AddAttachment(kAttachmentKey, *write_value.get());
- ibus_object_writer.CloseHeader();
-
- // Write contents values.
- ibus_object_writer.AppendString(kSampleText1);
- ibus_object_writer.AppendUint32(kSampleUint32);
- ibus_object_writer.AppendInt32(kSampleInt32);
- ibus_object_writer.AppendBool(kSampleBool);
- dbus::MessageWriter array_writer(NULL);
- ibus_object_writer.OpenArray("u", &array_writer);
- for (uint32 i = 0; i < kSampleArrayOfUint32Count; ++i)
- array_writer.AppendUint32(i);
- ibus_object_writer.CloseContainer(&array_writer);
- IBusObjectWriter ibus_nested_object_writer(kSampleTypeName2, "s", NULL);
- ibus_object_writer.AppendIBusObject(&ibus_nested_object_writer);
- ibus_nested_object_writer.CloseHeader();
- ibus_nested_object_writer.AppendString(kSampleText2);
- ibus_object_writer.CloseAll();
-
- // Read ibus_object.
- dbus::MessageReader reader(message.get());
- IBusObjectReader ibus_object_reader(kSampleTypeName1, &reader);
- ASSERT_TRUE(ibus_object_reader.Init());
- // Check the attachment value;
- const base::Value* read_value =
- ibus_object_reader.GetAttachment(kAttachmentKey);
- ASSERT_TRUE(read_value);
- std::string attachment_value;
- ASSERT_TRUE(read_value->GetAsString(&attachment_value));
- EXPECT_EQ(kStringAttachment, attachment_value);
- // Check the first string value.
- std::string expected_string;
- ASSERT_TRUE(ibus_object_reader.PopString(&expected_string));
- EXPECT_EQ(kSampleText1, expected_string);
- // Check the second uint32 value.
- uint32 expected_uint32 = 0UL;
- ASSERT_TRUE(ibus_object_reader.PopUint32(&expected_uint32));
- EXPECT_EQ(kSampleUint32, expected_uint32);
- // Check the third int value.
- int32 expected_int32 = 0;
- ASSERT_TRUE(ibus_object_reader.PopInt32(&expected_int32));
- EXPECT_EQ(kSampleInt32, expected_int32);
- // Check the fourth boolean value.
- bool expected_bool = true;
- ASSERT_TRUE(ibus_object_reader.PopBool(&expected_bool));
- EXPECT_TRUE(kSampleBool == expected_bool);
- // Check the fifth value which is array of uint32.
- dbus::MessageReader array_reader(NULL);
- ASSERT_TRUE(ibus_object_reader.PopArray(&array_reader));
- for (uint32 i = 0; i < kSampleArrayOfUint32Count; ++i) {
- uint32 expected_uint32 = 0;
- ASSERT_TRUE(array_reader.PopUint32(&expected_uint32));
- EXPECT_EQ(i, expected_uint32);
- }
- // Check the sixth value which is IBusObject.
- IBusObjectReader ibus_nested_object_reader(kSampleTypeName2, NULL);
- ibus_object_reader.PopIBusObject(&ibus_nested_object_reader);
- std::string expected_text2;
- ASSERT_TRUE(ibus_nested_object_reader.PopString(&expected_text2));
- EXPECT_EQ(kSampleText2, expected_text2);
-
- EXPECT_FALSE(ibus_nested_object_reader.HasMoreData());
- EXPECT_FALSE(ibus_object_reader.HasMoreData());
- EXPECT_FALSE(array_reader.HasMoreData());
- EXPECT_FALSE(reader.HasMoreData());
-}
-
-TEST(IBusObjectTest, EmptyEntryTest) {
- const char kSampleTypeName[] = "Empty IBusObject Name";
- scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
-
- // Write empty IBusObject.
- dbus::MessageWriter writer(message.get());
- IBusObjectWriter ibus_object_writer(kSampleTypeName, "", &writer);
- ibus_object_writer.CloseHeader();
- ibus_object_writer.CloseAll();
-
- // Read empty IBusObject.
- dbus::MessageReader reader(message.get());
- IBusObjectReader ibus_object_reader(kSampleTypeName, &reader);
- ASSERT_TRUE(ibus_object_reader.Init());
- EXPECT_FALSE(ibus_object_reader.HasMoreData());
-}
-
-TEST(IBusObjectTest, PopAppendIBusTextTest) {
- const char kSampleTypeName[] = "Empty IBusObject Name";
- const char kSampleString[] = "Sapmle String";
- IBusText::SelectionAttribute selection_attribute;
- selection_attribute.start_index = 0UL;
- selection_attribute.end_index = 10UL;
- scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
-
- // Write IBusText.
- dbus::MessageWriter writer(message.get());
- IBusObjectWriter ibus_object_writer(kSampleTypeName, "v", &writer);
- ibus_object_writer.CloseHeader();
- IBusText ibus_text;
- ibus_text.mutable_selection_attributes()->push_back(selection_attribute);
- ibus_text.set_text(kSampleString);
- ibus_object_writer.AppendIBusText(ibus_text);
- ibus_object_writer.CloseAll();
-
- // Read IBusText;
- dbus::MessageReader reader(message.get());
- IBusObjectReader ibus_object_reader(kSampleTypeName, &reader);
- IBusText result_text;
- ASSERT_TRUE(ibus_object_reader.Init());
- ASSERT_TRUE(ibus_object_reader.PopIBusText(&result_text));
- EXPECT_FALSE(ibus_object_reader.HasMoreData());
- EXPECT_EQ(kSampleString, result_text.text());
- const std::vector<IBusText::SelectionAttribute>& selection_attributes =
- result_text.selection_attributes();
- ASSERT_EQ(1UL, selection_attributes.size());
- EXPECT_EQ(selection_attribute.start_index,
- selection_attributes[0].start_index);
- EXPECT_EQ(selection_attribute.end_index,
- selection_attributes[0].end_index);
-}
-
-TEST(IBusObjectTest, PopAppendStringAsIBusText) {
- const char kSampleTypeName[] = "Empty IBusObject Name";
- const char kSampleString[] = "Sapmle String";
- scoped_ptr<dbus::Response> message(dbus::Response::CreateEmpty());
-
- // Write string as IBusText.
- dbus::MessageWriter writer(message.get());
- IBusObjectWriter ibus_object_writer(kSampleTypeName, "v", &writer);
- ibus_object_writer.CloseHeader();
- ibus_object_writer.AppendStringAsIBusText(kSampleString);
- ibus_object_writer.CloseAll();
-
- // Read string from IBusText.
- dbus::MessageReader reader(message.get());
- IBusObjectReader ibus_object_reader(kSampleTypeName, &reader);
- std::string result_str;
- ASSERT_TRUE(ibus_object_reader.Init());
- ASSERT_TRUE(ibus_object_reader.PopStringFromIBusText(&result_str));
- EXPECT_FALSE(ibus_object_reader.HasMoreData());
- EXPECT_EQ(kSampleString, result_str);
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/ibus/ibus_text.cc b/chromeos/dbus/ibus/ibus_text.cc
deleted file mode 100644
index dfc5ab4..0000000
--- a/chromeos/dbus/ibus/ibus_text.cc
+++ /dev/null
@@ -1,239 +0,0 @@
-// 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_text.h"
-
-#include "base/logging.h"
-#include "base/values.h"
-#include "chromeos/dbus/ibus/ibus_object.h"
-#include "dbus/message.h"
-
-namespace chromeos {
-
-namespace {
-const uint32 kAttributeUnderline = 1; // Indicates underline attribute.
-const uint32 kAttributeSelection = 2; // Indicates background attribute.
-const char kAnnotationKey[] = "annotation";
-const char kDescriptionTitleKey[] = "description_title";
-const char kDescriptionBodyKey[] = "description_body";
-
-struct IBusAttribute {
- IBusAttribute() : type(0), value(0), start_index(0), end_index(0) {}
- uint32 type;
- uint32 value;
- uint32 start_index;
- uint32 end_index;
-};
-
-// Pops a IBusAttribute from |reader|.
-// Returns false if an error occurs.
-bool PopIBusAttribute(dbus::MessageReader* reader, IBusAttribute* attribute) {
- IBusObjectReader ibus_object_reader("IBusAttribute", reader);
- if (!ibus_object_reader.Init())
- return false;
-
- if (!ibus_object_reader.PopUint32(&attribute->type) ||
- !ibus_object_reader.PopUint32(&attribute->value) ||
- !ibus_object_reader.PopUint32(&attribute->start_index) ||
- !ibus_object_reader.PopUint32(&attribute->end_index)) {
- LOG(ERROR) << "Invalid variant structure[IBusAttribute]: "
- << "IBusAttribute should contain 4 unsigned integers.";
- return false;
- }
- return true;
-}
-
-// Appends a IBusAttribute into |writer|.
-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);
- ibus_attribute_writer.AppendUint32(attribute.end_index);
- ibus_attribute_writer.CloseAll();
-}
-
-} // namespace
-
-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_title().empty()) {
- scoped_ptr<base::Value> description_title(
- base::Value::CreateStringValue(ibus_text.description_title()));
- ibus_text_writer.AddAttachment(kDescriptionTitleKey,
- *description_title.get());
- }
- if (!ibus_text.description_body().empty()) {
- scoped_ptr<base::Value> description_body(
- base::Value::CreateStringValue(ibus_text.description_body()));
- ibus_text_writer.AddAttachment(kDescriptionBodyKey,
- *description_body.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);
-
- const std::vector<IBusText::UnderlineAttribute>& underline_attributes =
- ibus_text.underline_attributes();
- for (size_t i = 0; i < underline_attributes.size(); ++i) {
- IBusAttribute attribute;
- attribute.type = kAttributeUnderline;
- attribute.value = static_cast<uint32>(underline_attributes[i].type);
- attribute.start_index = underline_attributes[i].start_index;
- attribute.end_index = underline_attributes[i].end_index;
- AppendIBusAttribute(&attribute_array_writer, attribute);
- }
-
- const std::vector<IBusText::SelectionAttribute>& selection_attributes =
- ibus_text.selection_attributes();
- for (size_t i = 0; i < selection_attributes.size(); ++i) {
- IBusAttribute attribute;
- attribute.type = kAttributeSelection;
- attribute.value = 0;
- attribute.start_index = selection_attributes[i].start_index;
- attribute.end_index = selection_attributes[i].end_index;
- AppendIBusAttribute(&attribute_array_writer, attribute);
- }
-
- // Close all writers.
- ibus_attr_list_writer.CloseContainer(&attribute_array_writer);
- ibus_attr_list_writer.CloseAll();
- ibus_text_writer.CloseAll();
-}
-
-void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text,
- dbus::MessageWriter* writer) {
- IBusText ibus_text;
- ibus_text.set_text(text);
- AppendIBusText(ibus_text, writer);
-}
-
-bool PopIBusText(dbus::MessageReader* reader, IBusText* ibus_text) {
- IBusObjectReader ibus_text_reader("IBusText", reader);
-
- if (!ibus_text_reader.Init())
- return false;
-
- 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);
- }
-
- const base::Value* description_title_value =
- ibus_text_reader.GetAttachment(kDescriptionTitleKey);
- if (description_title_value) {
- std::string description_title;
- if (description_title_value->GetAsString(&description_title))
- ibus_text->set_description_title(description_title);
- }
-
- const base::Value* description_body_value =
- ibus_text_reader.GetAttachment(kDescriptionBodyKey);
- if (description_body_value) {
- std::string description_body;
- if (description_body_value->GetAsString(&description_body))
- ibus_text->set_description_body(description_body);
- }
-
- std::string text;
- if (!ibus_text_reader.PopString(&text)) {
- LOG(ERROR) << "Invalid variant structure[IBusText]: "
- << "1st argument should be string.";
- return false;
- }
-
- ibus_text->set_text(text);
-
- // Start reading IBusAttrList object
- IBusObjectReader ibus_attr_list_reader("IBusAttrList", NULL);
- if (!ibus_text_reader.PopIBusObject(&ibus_attr_list_reader)) {
- LOG(ERROR) << "Invalid variant structure[IBusText]: "
- << "2nd argument should be IBusAttrList.";
- return false;
- }
-
- dbus::MessageReader attribute_array_reader(NULL);
- if (!ibus_attr_list_reader.PopArray(&attribute_array_reader)) {
- LOG(ERROR) << "Invalid variant structure[IBusAttrList]: "
- << "1st argument should be array of IBusAttribute.";
- return false;
- }
-
- std::vector<IBusText::UnderlineAttribute>* underline_attributes =
- ibus_text->mutable_underline_attributes();
-
- std::vector<IBusText::SelectionAttribute>* selection_attributes =
- ibus_text->mutable_selection_attributes();
-
- while (attribute_array_reader.HasMoreData()) {
- IBusAttribute attribute;
- if (!PopIBusAttribute(&attribute_array_reader, &attribute))
- return false;
-
- if (attribute.type == kAttributeUnderline) {
- IBusText::UnderlineAttribute underline_attribute;
- underline_attribute.type =
- static_cast<IBusText::IBusTextUnderlineType>(attribute.value);
- underline_attribute.start_index = attribute.start_index;
- underline_attribute.end_index = attribute.end_index;
- underline_attributes->push_back(underline_attribute);
- } else if (attribute.type == kAttributeSelection) {
- IBusText::SelectionAttribute selection_attribute;
- selection_attribute.start_index = attribute.start_index;
- selection_attribute.end_index = attribute.end_index;
- selection_attributes->push_back(selection_attribute);
- } else {
- DVLOG(1) << "Chrome does not support background attribute.";
- }
- }
-
- return true;
-}
-
-bool CHROMEOS_EXPORT PopStringFromIBusText(dbus::MessageReader* reader,
- std::string* text) {
- IBusText ibus_text;
- if (!PopIBusText(reader, &ibus_text))
- return false;
- *text = ibus_text.text();
- return true;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// IBusText
-IBusText::IBusText()
- : text_("") {
-}
-
-IBusText::~IBusText() {
-}
-
-void IBusText::CopyFrom(const IBusText& obj) {
- text_ = obj.text();
- annotation_ = obj.annotation();
- description_title_ = obj.description_title();
- description_body_ = obj.description_body();
- underline_attributes_ = obj.underline_attributes();
- selection_attributes_ = obj.selection_attributes();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/ibus/ibus_text.h b/chromeos/dbus/ibus/ibus_text.h
deleted file mode 100644
index 1ed7ef1..0000000
--- a/chromeos/dbus/ibus/ibus_text.h
+++ /dev/null
@@ -1,190 +0,0 @@
-// 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.
-
-#ifndef CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_
-#define CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_
-
-#include <string>
-#include <vector>
-#include "base/basictypes.h"
-#include "chromeos/chromeos_export.h"
-
-namespace dbus {
-class MessageWriter;
-class MessageReader;
-} // dbus
-
-namespace chromeos {
-
-// The IBusText is one of IBusObjects and it contains IBusAttrList object which
-// contains array of IBusAttribute object. The overview of each data structure
-// is as follows:
-//
-// DATA STRUCTURE OVERVIEW:
-//
-// IBusAttribute: (signature is "uuuu")
-// variant struct {
-// string "IBusAttribute"
-// array[]
-// uint32 1 // Type of attribute.
-// uint32 1 // The value of attribute.
-// uint32 0 // The start index of the text.
-// uint32 1 // The end index of the text.
-// }
-//
-// IBusAttrList: (signature is "av")
-// variant struct {
-// string "IBusAttrList"
-// array[]
-// array[ // The array of IBusAttribute.
-// variant struct{
-// string "IBusAttribute"
-// ...
-// }
-// variant struct{
-// string "IBusAttribute"
-// ...
-// }
-// variant struct{
-// string "IBusAttribute"
-// ...
-// }
-// ]
-// }
-//
-// IBusText: (signature is "sv")
-// variant struct {
-// string "IBusText"
-// array[]
-// string "A"
-// variant struct {
-// string "IBusAttrList"
-// array[]
-// array[
-// variant struct{
-// string "IBusAttribute"
-// ...
-// }
-// variant struct{
-// string "IBusAttribute"
-// ...
-// }
-// ]
-// }
-// }
-//
-class IBusText;
-
-// Pops a IBusText from |reader|.
-// Returns false if an error occurs.
-bool CHROMEOS_EXPORT PopIBusText(dbus::MessageReader* reader,
- IBusText* ibus_text);
-// Pops a IBusText from |reader| and stores it's text field into text. Use
-// PopIBusText instead in the case of using any attribute entries in IBusText.
-// Returns true on success.
-bool CHROMEOS_EXPORT PopStringFromIBusText(dbus::MessageReader* reader,
- std::string* text);
-// Appends a IBusText to |writer|. Annotation and description field is not
-// filled with AppendIBusText.
-// TODO(nona): Support annotation/description appending if necessary.
-void CHROMEOS_EXPORT AppendIBusText(const IBusText& ibus_text,
- dbus::MessageWriter* writer);
-
-// Appends a string to |writer| as IBusText without any attributes. Use
-// AppendIBusText instead in the case of using any attribute entries.
-// TODO(nona): Support annotation/description appending if necessary.
-void CHROMEOS_EXPORT AppendStringAsIBusText(const std::string& text,
- dbus::MessageWriter* writer);
-
-// Handles IBusText object which is used in dbus communication with ibus-daemon.
-// The IBusAttribute has four uint32 variables and the IBusAttributes represents
-// three type of decoration based on it's values.
-// 1. Underline decoration (corresponds to UnderlineAttribute structure)
-// 1st value: indicates underline attribute.
-// 2nd value: type of decoration. Chrome only support single and double
-// underline and error line.
-// 3rd value: the start index of this attribute in multibyte.
-// 4th value: the end index of this attribute in multibyte.
-//
-// 2. Background decoration (corresponds to SelectionAttribute structure)
-// NOTE: Background decoration is treated as selection in Chrome.
-// 1st value: indicates background attribute.
-// 2nd value: Represents color but not supported in Chrome.
-// 3rd value: the start index of this attribute in multibyte.
-// 4th value: the end index of this attribute in multibyte.
-//
-// 3. Forward decoration
-// Not supported in Chrome.
-class CHROMEOS_EXPORT IBusText {
- public:
- enum IBusTextUnderlineType {
- IBUS_TEXT_UNDERLINE_SINGLE = 1,
- IBUS_TEXT_UNDERLINE_DOUBLE = 2,
- IBUS_TEXT_UNDERLINE_ERROR = 4,
- };
-
- struct UnderlineAttribute {
- IBusTextUnderlineType type;
- uint32 start_index; // The inclusive start index.
- uint32 end_index; // The exclusive end index.
- };
-
- struct SelectionAttribute {
- uint32 start_index; // The inclusive start index.
- uint32 end_index; // The exclusive end index.
- };
-
- // Accessors
- IBusText();
- virtual ~IBusText();
-
- const std::string& text() const { return text_; }
- void set_text(const std::string& text) { text_ = text; }
-
- const std::string& annotation() const { return annotation_; }
- void set_annotation(const std::string& annotation) {
- annotation_ = annotation;
- }
-
- const std::string& description_title() const { return description_title_; }
- void set_description_title(const std::string& title) {
- description_title_ = title;
- }
-
- const std::string& description_body() const { return description_body_; }
- void set_description_body(const std::string& body) {
- description_body_ = body;
- }
-
- const std::vector<UnderlineAttribute>& underline_attributes() const {
- return underline_attributes_;
- }
-
- std::vector<UnderlineAttribute>* mutable_underline_attributes() {
- return &underline_attributes_;
- }
-
- const std::vector<SelectionAttribute>& selection_attributes() const {
- return selection_attributes_;
- }
- std::vector<SelectionAttribute>* mutable_selection_attributes() {
- return &selection_attributes_;
- }
-
- void CopyFrom(const IBusText& obj);
-
- private:
- std::string text_;
- std::string annotation_;
- std::string description_title_;
- std::string description_body_;
- std::vector<UnderlineAttribute> underline_attributes_;
- std::vector<SelectionAttribute> selection_attributes_;
-
- DISALLOW_COPY_AND_ASSIGN(IBusText);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_IBUS_IBUS_TEXT_H_
diff --git a/chromeos/dbus/ibus/ibus_text_unittest.cc b/chromeos/dbus/ibus/ibus_text_unittest.cc
deleted file mode 100644
index 1757a2c..0000000
--- a/chromeos/dbus/ibus/ibus_text_unittest.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// 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.
-// TODO(nona): Add more tests.
-
-#include "chromeos/dbus/ibus/ibus_text.h"
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "chromeos/dbus/ibus/ibus_object.h"
-#include "dbus/message.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace chromeos {
-
-TEST(IBusTextTest, WriteReadTest) {
- const char kSampleText[] = "Sample Text";
- const char kAnnotation[] = "Annotation";
- const char kDescriptionTitle[] = "Description Title";
- const char kDescriptionBody[] = "Description Body";
- const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = {
- IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20};
-
- const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = {
- IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21};
-
- const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = {
- IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22};
-
- const IBusText::SelectionAttribute kSampleSelectionAttribute = {30, 40};
-
- // Make IBusText
- IBusText text;
- text.set_text(kSampleText);
- text.set_annotation(kAnnotation);
- text.set_description_title(kDescriptionTitle);
- text.set_description_body(kDescriptionBody);
- std::vector<IBusText::UnderlineAttribute>* underline_attributes =
- text.mutable_underline_attributes();
- underline_attributes->push_back(kSampleUnderlineAttribute1);
- underline_attributes->push_back(kSampleUnderlineAttribute2);
- underline_attributes->push_back(kSampleUnderlineAttribute3);
- std::vector<IBusText::SelectionAttribute>* selection_attributes =
- text.mutable_selection_attributes();
- selection_attributes->push_back(kSampleSelectionAttribute);
-
- // Write to Response object.
- scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
- dbus::MessageWriter writer(response.get());
- AppendIBusText(text, &writer);
-
- // Read from Response object.
- dbus::MessageReader reader(response.get());
- IBusText expected_text;
- ASSERT_TRUE(PopIBusText(&reader, &expected_text));
- EXPECT_EQ(kSampleText, expected_text.text());
- EXPECT_EQ(kAnnotation, expected_text.annotation());
- EXPECT_EQ(kDescriptionTitle, expected_text.description_title());
- EXPECT_EQ(kDescriptionBody, expected_text.description_body());
- EXPECT_EQ(3U, expected_text.underline_attributes().size());
- EXPECT_EQ(1U, expected_text.selection_attributes().size());
-}
-
-TEST(IBusTextTest, StringAsIBusTextTest) {
- const char kSampleText[] = "Sample Text";
-
- // Write to Response object.
- scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
- dbus::MessageWriter writer(response.get());
- AppendStringAsIBusText(kSampleText, &writer);
-
- // Read from Response object.
- dbus::MessageReader reader(response.get());
- IBusText ibus_text;
- ASSERT_TRUE(PopIBusText(&reader, &ibus_text));
- EXPECT_EQ(kSampleText, ibus_text.text());
- EXPECT_TRUE(ibus_text.underline_attributes().empty());
- EXPECT_TRUE(ibus_text.selection_attributes().empty());
-}
-
-TEST(IBusTextTest, PopStringFromIBusTextTest) {
- const char kSampleText[] = "Sample Text";
-
- // Write to Response object.
- scoped_ptr<dbus::Response> response(dbus::Response::CreateEmpty());
- dbus::MessageWriter writer(response.get());
- AppendStringAsIBusText(kSampleText, &writer);
-
- // Read from Response object.
- dbus::MessageReader reader(response.get());
- std::string result;
- ASSERT_TRUE(PopStringFromIBusText(&reader, &result));
- EXPECT_EQ(kSampleText, result);
-}
-
-} // namespace chromeos
diff --git a/chromeos/ime/ibus_text.cc b/chromeos/ime/ibus_text.cc
new file mode 100644
index 0000000..ffdbfaf
--- /dev/null
+++ b/chromeos/ime/ibus_text.cc
@@ -0,0 +1,22 @@
+// Copyright 2013 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/ime/ibus_text.h"
+
+namespace chromeos {
+
+IBusText::IBusText() {}
+
+IBusText::~IBusText() {}
+
+void IBusText::CopyFrom(const IBusText& obj) {
+ text_ = obj.text();
+ annotation_ = obj.annotation();
+ description_title_ = obj.description_title();
+ description_body_ = obj.description_body();
+ underline_attributes_ = obj.underline_attributes();
+ selection_attributes_ = obj.selection_attributes();
+}
+
+} // namespace chromeos
diff --git a/chromeos/ime/ibus_text.h b/chromeos/ime/ibus_text.h
new file mode 100644
index 0000000..8d98a16
--- /dev/null
+++ b/chromeos/ime/ibus_text.h
@@ -0,0 +1,86 @@
+// Copyright 2013 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.
+
+#ifndef CHROMEOS_IME_IBUS_TEXT_H_
+#define CHROMEOS_IME_IBUS_TEXT_H_
+
+#include <string>
+#include <vector>
+#include "base/basictypes.h"
+#include "chromeos/chromeos_export.h"
+
+namespace chromeos {
+
+class CHROMEOS_EXPORT IBusText {
+ public:
+ enum IBusTextUnderlineType {
+ IBUS_TEXT_UNDERLINE_SINGLE = 1,
+ IBUS_TEXT_UNDERLINE_DOUBLE = 2,
+ IBUS_TEXT_UNDERLINE_ERROR = 4,
+ };
+
+ struct UnderlineAttribute {
+ IBusTextUnderlineType type;
+ uint32 start_index; // The inclusive start index.
+ uint32 end_index; // The exclusive end index.
+ };
+
+ struct SelectionAttribute {
+ uint32 start_index; // The inclusive start index.
+ uint32 end_index; // The exclusive end index.
+ };
+
+ // Accessors
+ IBusText();
+ virtual ~IBusText();
+
+ const std::string& text() const { return text_; }
+ void set_text(const std::string& text) { text_ = text; }
+
+ const std::string& annotation() const { return annotation_; }
+ void set_annotation(const std::string& annotation) {
+ annotation_ = annotation;
+ }
+
+ const std::string& description_title() const { return description_title_; }
+ void set_description_title(const std::string& title) {
+ description_title_ = title;
+ }
+
+ const std::string& description_body() const { return description_body_; }
+ void set_description_body(const std::string& body) {
+ description_body_ = body;
+ }
+
+ const std::vector<UnderlineAttribute>& underline_attributes() const {
+ return underline_attributes_;
+ }
+
+ std::vector<UnderlineAttribute>* mutable_underline_attributes() {
+ return &underline_attributes_;
+ }
+
+ const std::vector<SelectionAttribute>& selection_attributes() const {
+ return selection_attributes_;
+ }
+ std::vector<SelectionAttribute>* mutable_selection_attributes() {
+ return &selection_attributes_;
+ }
+
+ void CopyFrom(const IBusText& obj);
+
+ private:
+ std::string text_;
+ std::string annotation_;
+ std::string description_title_;
+ std::string description_body_;
+ std::vector<UnderlineAttribute> underline_attributes_;
+ std::vector<SelectionAttribute> selection_attributes_;
+
+ DISALLOW_COPY_AND_ASSIGN(IBusText);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_IME_IBUS_TEXT_H_
diff --git a/chromeos/ime/ibus_text_unittest.cc b/chromeos/ime/ibus_text_unittest.cc
new file mode 100644
index 0000000..bcbd639
--- /dev/null
+++ b/chromeos/ime/ibus_text_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2013 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.
+// TODO(nona): Add more tests.
+
+#include "chromeos/ime/ibus_text.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+TEST(IBusTextTest, CopyTest) {
+ const char kSampleText[] = "Sample Text";
+ const char kAnnotation[] = "Annotation";
+ const char kDescriptionTitle[] = "Description Title";
+ const char kDescriptionBody[] = "Description Body";
+ const IBusText::UnderlineAttribute kSampleUnderlineAttribute1 = {
+ IBusText::IBUS_TEXT_UNDERLINE_SINGLE, 10, 20};
+
+ const IBusText::UnderlineAttribute kSampleUnderlineAttribute2 = {
+ IBusText::IBUS_TEXT_UNDERLINE_DOUBLE, 11, 21};
+
+ const IBusText::UnderlineAttribute kSampleUnderlineAttribute3 = {
+ IBusText::IBUS_TEXT_UNDERLINE_ERROR, 12, 22};
+
+ const IBusText::SelectionAttribute kSampleSelectionAttribute = {30, 40};
+
+ // Make IBusText
+ IBusText text;
+ text.set_text(kSampleText);
+ text.set_annotation(kAnnotation);
+ text.set_description_title(kDescriptionTitle);
+ text.set_description_body(kDescriptionBody);
+ std::vector<IBusText::UnderlineAttribute>* underline_attributes =
+ text.mutable_underline_attributes();
+ underline_attributes->push_back(kSampleUnderlineAttribute1);
+ underline_attributes->push_back(kSampleUnderlineAttribute2);
+ underline_attributes->push_back(kSampleUnderlineAttribute3);
+ std::vector<IBusText::SelectionAttribute>* selection_attributes =
+ text.mutable_selection_attributes();
+ selection_attributes->push_back(kSampleSelectionAttribute);
+
+ IBusText text2;
+ text2.CopyFrom(text);
+
+ EXPECT_EQ(text.text(), text2.text());
+ EXPECT_EQ(text.annotation(), text2.annotation());
+ EXPECT_EQ(text.description_title(), text2.description_title());
+ EXPECT_EQ(text.description_body(), text2.description_body());
+
+ EXPECT_EQ(text.underline_attributes().size(),
+ text2.underline_attributes().size());
+ for (size_t i = 0; i < text.underline_attributes().size(); ++i) {
+ EXPECT_EQ(text.underline_attributes()[i].type,
+ text2.underline_attributes()[i].type);
+ EXPECT_EQ(text.underline_attributes()[i].start_index,
+ text2.underline_attributes()[i].start_index);
+ EXPECT_EQ(text.underline_attributes()[i].end_index,
+ text2.underline_attributes()[i].end_index);
+ }
+
+ EXPECT_EQ(text.selection_attributes().size(),
+ text2.selection_attributes().size());
+ for (size_t i = 0; i < text.selection_attributes().size(); ++i) {
+ EXPECT_EQ(text.selection_attributes()[i].start_index,
+ text2.selection_attributes()[i].start_index);
+ EXPECT_EQ(text.selection_attributes()[i].end_index,
+ text2.selection_attributes()[i].end_index);
+ }
+}
+
+} // namespace chromeos
diff --git a/chromeos/ime/mock_ime_input_context_handler.cc b/chromeos/ime/mock_ime_input_context_handler.cc
index 135e0f6..43f1c7c 100644
--- a/chromeos/ime/mock_ime_input_context_handler.cc
+++ b/chromeos/ime/mock_ime_input_context_handler.cc
@@ -4,7 +4,7 @@
#include "chromeos/ime/mock_ime_input_context_handler.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
+#include "chromeos/ime/ibus_text.h"
namespace chromeos {
diff --git a/chromeos/ime/mock_ime_input_context_handler.h b/chromeos/ime/mock_ime_input_context_handler.h
index 6d5630a..bb4a34d 100644
--- a/chromeos/ime/mock_ime_input_context_handler.h
+++ b/chromeos/ime/mock_ime_input_context_handler.h
@@ -5,8 +5,8 @@
#ifndef CHROMEOS_IME_MOCK_IME_INPUT_CONTEXT_HANDLER_H_
#define CHROMEOS_IME_MOCK_IME_INPUT_CONTEXT_HANDLER_H_
-#include "chromeos/dbus/ibus/ibus_text.h"
#include "chromeos/ime/ibus_bridge.h"
+#include "chromeos/ime/ibus_text.h"
namespace chromeos {
diff --git a/ui/base/ime/input_method_ibus.cc b/ui/base/ime/input_method_ibus.cc
index 15d4fc1..9a3a0e8 100644
--- a/ui/base/ime/input_method_ibus.cc
+++ b/ui/base/ime/input_method_ibus.cc
@@ -22,7 +22,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/third_party/icu/icu_utf.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
+#include "chromeos/ime/ibus_text.h"
#include "chromeos/ime/input_method_descriptor.h"
#include "chromeos/ime/input_method_manager.h"
#include "ui/base/ime/text_input_client.h"
diff --git a/ui/base/ime/input_method_ibus_unittest.cc b/ui/base/ime/input_method_ibus_unittest.cc
index 92cd2f6..22722cd 100644
--- a/ui/base/ime/input_method_ibus_unittest.cc
+++ b/ui/base/ime/input_method_ibus_unittest.cc
@@ -14,9 +14,9 @@
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/ibus/ibus_text.h"
#include "chromeos/ime/ibus_bridge.h"
#include "chromeos/ime/ibus_keymap.h"
+#include "chromeos/ime/ibus_text.h"
#include "chromeos/ime/mock_ime_candidate_window_handler.h"
#include "chromeos/ime/mock_ime_engine_handler.h"
#include "testing/gtest/include/gtest/gtest.h"