diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 06:56:51 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-24 06:56:51 +0000 |
commit | 241508e9a25e0ba119c9b8b52730b5f48ba0819e (patch) | |
tree | 48ff1bad428af5c5a9c24d9b22c497fe0a67f5ef /chromeos/ime | |
parent | 69fbed1756fd299dcf23f72be39d6de4424a3268 (diff) | |
download | chromium_src-241508e9a25e0ba119c9b8b52730b5f48ba0819e.zip chromium_src-241508e9a25e0ba119c9b8b52730b5f48ba0819e.tar.gz chromium_src-241508e9a25e0ba119c9b8b52730b5f48ba0819e.tar.bz2 |
Move InputMethodDescriptor from c/b/chromeos to chromeos/ime
This is part of extraction work for input method from chrome/browser/chromeos.
BUG=164375
TEST=None
TBR=sky
Review URL: https://chromiumcodereview.appspot.com/12902005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/ime')
-rw-r--r-- | chromeos/ime/input_method_descriptor.cc | 68 | ||||
-rw-r--r-- | chromeos/ime/input_method_descriptor.h | 68 | ||||
-rw-r--r-- | chromeos/ime/input_method_descriptor_unittest.cc | 40 |
3 files changed, 176 insertions, 0 deletions
diff --git a/chromeos/ime/input_method_descriptor.cc b/chromeos/ime/input_method_descriptor.cc new file mode 100644 index 0000000..4ded598 --- /dev/null +++ b/chromeos/ime/input_method_descriptor.cc @@ -0,0 +1,68 @@ +// 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/input_method_descriptor.h" + +#include <sstream> + +#include "base/logging.h" +#include "base/strings/string_split.h" + +namespace chromeos { +namespace input_method { + +namespace { +const char kFallbackLayout[] = "us"; +} // namespace + +InputMethodDescriptor::InputMethodDescriptor(const std::string& id, + const std::string& name, + const std::string& keyboard_layout, + const std::string& language_code, + bool third_party) + : id_(id), + name_(name), + keyboard_layout_(keyboard_layout), + language_code_(language_code), + third_party_(third_party) { +} + +InputMethodDescriptor::InputMethodDescriptor() : third_party_(false) { +} + +InputMethodDescriptor::~InputMethodDescriptor() { +} + +bool InputMethodDescriptor::operator==( + const InputMethodDescriptor& other) const { + return id() == other.id(); +} + +bool InputMethodDescriptor::operator!=( + const InputMethodDescriptor& other) const { + return !(*this == other); +} + +// static +InputMethodDescriptor +InputMethodDescriptor::GetFallbackInputMethodDescriptor() { + return InputMethodDescriptor("xkb:us::eng", + "", + kFallbackLayout, + "en-US", + false); +} + +std::string InputMethodDescriptor::ToString() const { + std::stringstream stream; + stream << "id=" << id() + << ", name=" << name() + << ", keyboard_layout=" << keyboard_layout() + << ", language_code=" << language_code() + << ", third_party=" << third_party(); + return stream.str(); +} + +} // namespace input_method +} // namespace chromeos diff --git a/chromeos/ime/input_method_descriptor.h b/chromeos/ime/input_method_descriptor.h new file mode 100644 index 0000000..53a92a9 --- /dev/null +++ b/chromeos/ime/input_method_descriptor.h @@ -0,0 +1,68 @@ +// 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_INPUT_METHOD_DESCRIPTOR_H_ +#define CHROMEOS_IME_INPUT_METHOD_DESCRIPTOR_H_ + +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "chromeos/chromeos_export.h" + +namespace chromeos { +namespace input_method { + +class InputMethodWhitelist; + +// A structure which represents an input method. +class CHROMEOS_EXPORT InputMethodDescriptor { + public: + InputMethodDescriptor(); + InputMethodDescriptor(const std::string& id, + const std::string& name, + const std::string& keyboard_layout, + const std::string& language_code, + bool third_party); + ~InputMethodDescriptor(); + + bool operator==(const InputMethodDescriptor& other) const; + bool operator!=(const InputMethodDescriptor& other) const; + + // Debug print function. + std::string ToString() const; + + const std::string& id() const { return id_; } + const std::string& name() const { return name_; } + const std::string& keyboard_layout() const { return keyboard_layout_; } + const std::string& language_code() const { return language_code_; } + bool third_party() const { return third_party_; } + + // Returns the fallback input method descriptor (the very basic US + // keyboard). This function is mostly used for testing, but may be used + // as the fallback, when there is no other choice. + static InputMethodDescriptor GetFallbackInputMethodDescriptor(); + + private: + // An ID that identifies an input method engine (e.g., "t:latn-post", + // "pinyin", "hangul"). + std::string id_; + // A name used to specify the user-visible name of this input method. It is + // only used by extension IMEs, and should be blank for internal IMEs. + std::string name_; + // A preferred physical keyboard layout for the input method (e.g., "us", + // "us(dvorak)", "jp"). Comma separated layout names do NOT appear. + std::string keyboard_layout_; + // Language code like "ko", "ja", "en-US", and "zh-CN". + std::string language_code_; + // Indicates if this is a third party ime + bool third_party_; +}; + +typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; + +} // namespace input_method +} // namespace chromeos + +#endif // CHROMEOS_IME_INPUT_METHOD_DESCRIPTOR_H_ diff --git a/chromeos/ime/input_method_descriptor_unittest.cc b/chromeos/ime/input_method_descriptor_unittest.cc new file mode 100644 index 0000000..0b22eb9 --- /dev/null +++ b/chromeos/ime/input_method_descriptor_unittest.cc @@ -0,0 +1,40 @@ +// 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 "base/logging.h" +#include "chromeos/ime/input_method_descriptor.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace chromeos { +namespace input_method { + +namespace { + +const char kFallbackLayout[] = "us"; + +class InputMethodDescriptorTest : public testing::Test { + public: + InputMethodDescriptorTest() { + } + + protected: + InputMethodDescriptor GetDescById(const std::string& id) { + return InputMethodDescriptor(id, + "", // name + "us", + "language_code", + false); + } +}; + +} // namespace + +TEST_F(InputMethodDescriptorTest, TestOperatorEqual) { + EXPECT_EQ(GetDescById("xkb:us::eng"), GetDescById("xkb:us::eng")); + EXPECT_NE(GetDescById("xkb:us::eng"), GetDescById("xkb:us:dvorak:eng")); + EXPECT_NE(GetDescById("xkb:fr::fra"), GetDescById("xkb:us::eng")); +} + +} // namespace input_method +} // namespace chromeos |