summaryrefslogtreecommitdiffstats
path: root/chromeos/ime
diff options
context:
space:
mode:
authornona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-23 22:44:36 +0000
committernona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-23 22:44:36 +0000
commit6f8c7b9174688742b20bf3ec29f030cf0db3e5ce (patch)
treeb14c3e2c819f4500ae9599cd46ed6efd1201c93f /chromeos/ime
parent1e2764628245fa5e049997dcb134c242fbd0cae3 (diff)
downloadchromium_src-6f8c7b9174688742b20bf3ec29f030cf0db3e5ce.zip
chromium_src-6f8c7b9174688742b20bf3ec29f030cf0db3e5ce.tar.gz
chromium_src-6f8c7b9174688742b20bf3ec29f030cf0db3e5ce.tar.bz2
Supporting multiple keyboard layouts.
Before starting InputMethodDescription refactoring, let me add multiple keyboard layout support. BUG=170601 TEST=ran unit_tests and chromeos_unittests and also checked manually there is no regression around keyboard selection. Review URL: https://chromiumcodereview.appspot.com/13949015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/ime')
-rw-r--r--chromeos/ime/component_extension_ime_manager.cc18
-rw-r--r--chromeos/ime/component_extension_ime_manager.h16
-rw-r--r--chromeos/ime/component_extension_ime_manager_unittest.cc38
-rw-r--r--chromeos/ime/input_method_descriptor.cc10
-rw-r--r--chromeos/ime/input_method_descriptor.h18
-rw-r--r--chromeos/ime/input_method_whitelist.cc5
6 files changed, 69 insertions, 36 deletions
diff --git a/chromeos/ime/component_extension_ime_manager.cc b/chromeos/ime/component_extension_ime_manager.cc
index a55e9c4..4ed9fb4 100644
--- a/chromeos/ime/component_extension_ime_manager.cc
+++ b/chromeos/ime/component_extension_ime_manager.cc
@@ -11,6 +11,12 @@ namespace {
const char* kComponentExtensionIMEPrefix = "_comp_ime_";
} // namespace
+ComponentExtensionEngine::ComponentExtensionEngine() {
+}
+
+ComponentExtensionEngine::~ComponentExtensionEngine() {
+}
+
ComponentExtensionIME::ComponentExtensionIME() {
}
@@ -93,7 +99,7 @@ bool ComponentExtensionIMEManager::IsWhitelistedExtension(
std::string ComponentExtensionIMEManager::GetId(
const std::string& extension_id,
const std::string& engine_id) {
- IBusComponent::EngineDescription engine;
+ ComponentExtensionEngine engine;
const std::string& input_method_id =
GetComponentExtensionIMEId(extension_id, engine_id);
if (!FindEngineEntry(input_method_id, NULL, &engine))
@@ -103,7 +109,7 @@ std::string ComponentExtensionIMEManager::GetId(
std::string ComponentExtensionIMEManager::GetName(
const std::string& input_method_id) {
- IBusComponent::EngineDescription engine;
+ ComponentExtensionEngine engine;
if (!FindEngineEntry(input_method_id, NULL, &engine))
return "";
return engine.display_name;
@@ -111,7 +117,7 @@ std::string ComponentExtensionIMEManager::GetName(
std::string ComponentExtensionIMEManager::GetDescription(
const std::string& input_method_id) {
- IBusComponent::EngineDescription engine;
+ ComponentExtensionEngine engine;
if (!FindEngineEntry(input_method_id, NULL, &engine))
return "";
return engine.description;
@@ -143,7 +149,7 @@ input_method::InputMethodDescriptors
component_extension_imes_[i].id,
component_extension_imes_[i].engines[j].engine_id),
component_extension_imes_[i].engines[j].display_name,
- component_extension_imes_[i].engines[j].layout,
+ component_extension_imes_[i].engines[j].layouts,
component_extension_imes_[i].engines[j].language_code,
component_extension_imes_[i].options_page_url));
}
@@ -162,12 +168,12 @@ void ComponentExtensionIMEManager::RemoveObserver(Observer* observer) {
bool ComponentExtensionIMEManager::FindEngineEntry(
const std::string& input_method_id,
ComponentExtensionIME* out_extension,
- IBusComponent::EngineDescription* out_engine) {
+ ComponentExtensionEngine* out_engine) {
if (!IsComponentExtensionIMEId(input_method_id))
return false;
for (size_t i = 0; i < component_extension_imes_.size(); ++i) {
const std::string extension_id = component_extension_imes_[i].id;
- const std::vector<IBusComponent::EngineDescription>& engines =
+ const std::vector<ComponentExtensionEngine>& engines =
component_extension_imes_[i].engines;
for (size_t j = 0; j < engines.size(); ++j) {
diff --git a/chromeos/ime/component_extension_ime_manager.h b/chromeos/ime/component_extension_ime_manager.h
index b8dee570..2c1f470 100644
--- a/chromeos/ime/component_extension_ime_manager.h
+++ b/chromeos/ime/component_extension_ime_manager.h
@@ -9,11 +9,21 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/ibus/ibus_component.h"
#include "chromeos/ime/input_method_descriptor.h"
namespace chromeos {
+// Represents an engine in component extension IME.
+struct CHROMEOS_EXPORT ComponentExtensionEngine {
+ ComponentExtensionEngine();
+ ~ComponentExtensionEngine();
+ std::string engine_id; // The engine id.
+ std::string display_name; // The display name.
+ std::string language_code; // The engine's language(ex. "en").
+ std::string description; // The engine description.
+ std::vector<std::string> layouts; // The list of keyboard layout of engine.
+};
+
// Represents a component extension IME.
// TODO(nona): Use GURL for |option_page_url| instead of string.
struct CHROMEOS_EXPORT ComponentExtensionIME {
@@ -24,7 +34,7 @@ struct CHROMEOS_EXPORT ComponentExtensionIME {
std::string description; // description of extension.
std::string options_page_url; // We can't use GURL due to deps restriction.
base::FilePath path;
- std::vector<IBusComponent::EngineDescription> engines;
+ std::vector<ComponentExtensionEngine> engines;
};
// Provides an interface to list/load/unload for component extension IME.
@@ -125,7 +135,7 @@ class CHROMEOS_EXPORT ComponentExtensionIMEManager {
// returns false. |out_extension| and |out_engine| can be NULL.
bool FindEngineEntry(const std::string& input_method_id,
ComponentExtensionIME* out_extension,
- IBusComponent::EngineDescription* out_engine);
+ ComponentExtensionEngine* out_engine);
scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
std::vector<ComponentExtensionIME> component_extension_imes_;
diff --git a/chromeos/ime/component_extension_ime_manager_unittest.cc b/chromeos/ime/component_extension_ime_manager_unittest.cc
index 65065f5..5de1657 100644
--- a/chromeos/ime/component_extension_ime_manager_unittest.cc
+++ b/chromeos/ime/component_extension_ime_manager_unittest.cc
@@ -37,25 +37,25 @@ class ComponentExtensionIMEManagerTest :
ext1.options_page_url = "chrome-extension://" + ext1.id + "/options.html";
ext1.path = base::FilePath("ext1_file_path");
- IBusComponent::EngineDescription ext1_engine1;
+ ComponentExtensionEngine ext1_engine1;
ext1_engine1.engine_id = "ext1_engine1_engine_id";
ext1_engine1.display_name = "ext1_engine_1_display_name";
ext1_engine1.language_code = "en";
- ext1_engine1.layout = "us";
+ ext1_engine1.layouts.push_back("us");
ext1.engines.push_back(ext1_engine1);
- IBusComponent::EngineDescription ext1_engine2;
+ ComponentExtensionEngine ext1_engine2;
ext1_engine2.engine_id = "ext1_engine2_engine_id";
ext1_engine2.display_name = "ext1_engine2_display_name";
ext1_engine2.language_code = "en";
- ext1_engine2.layout = "us";
+ ext1_engine2.layouts.push_back("us");
ext1.engines.push_back(ext1_engine2);
- IBusComponent::EngineDescription ext1_engine3;
+ ComponentExtensionEngine ext1_engine3;
ext1_engine3.engine_id = "ext1_engine3_engine_id";
ext1_engine3.display_name = "ext1_engine3_display_name";
ext1_engine3.language_code = "ja";
- ext1_engine3.layout = "us";
+ ext1_engine3.layouts.push_back("us");
ext1.engines.push_back(ext1_engine3);
ime_list_.push_back(ext1);
@@ -65,25 +65,25 @@ class ComponentExtensionIMEManagerTest :
ext2.description = "ext2_description";
ext2.path = base::FilePath("ext2_file_path");
- IBusComponent::EngineDescription ext2_engine1;
+ ComponentExtensionEngine ext2_engine1;
ext2_engine1.engine_id = "ext2_engine1_engine_id";
ext2_engine1.display_name = "ext2_engine_1_display_name";
ext2_engine1.language_code = "en";
- ext2_engine1.layout = "us";
+ ext2_engine1.layouts.push_back("us");
ext2.engines.push_back(ext2_engine1);
- IBusComponent::EngineDescription ext2_engine2;
+ ComponentExtensionEngine ext2_engine2;
ext2_engine2.engine_id = "ext2_engine2_engine_id";
ext2_engine2.display_name = "ext2_engine2_display_name";
ext2_engine2.language_code = "hi";
- ext2_engine2.layout = "us";
+ ext2_engine2.layouts.push_back("us");
ext2.engines.push_back(ext2_engine2);
- IBusComponent::EngineDescription ext2_engine3;
+ ComponentExtensionEngine ext2_engine3;
ext2_engine3.engine_id = "ext2_engine3_engine_id";
ext2_engine3.display_name = "ext2_engine3_display_name";
ext2_engine3.language_code = "ja";
- ext2_engine3.layout = "jp";
+ ext2_engine3.layouts.push_back("jp");
ext2.engines.push_back(ext2_engine3);
ime_list_.push_back(ext2);
@@ -94,25 +94,25 @@ class ComponentExtensionIMEManagerTest :
ext1.options_page_url = "chrome-extension://" + ext3.id + "/options.html";
ext3.path = base::FilePath("ext3_file_path");
- IBusComponent::EngineDescription ext3_engine1;
+ ComponentExtensionEngine ext3_engine1;
ext3_engine1.engine_id = "ext3_engine1_engine_id";
ext3_engine1.display_name = "ext3_engine_1_display_name";
ext3_engine1.language_code = "hi";
- ext3_engine1.layout = "us";
+ ext3_engine1.layouts.push_back("us");
ext3.engines.push_back(ext3_engine1);
- IBusComponent::EngineDescription ext3_engine2;
+ ComponentExtensionEngine ext3_engine2;
ext3_engine2.engine_id = "ext3_engine2_engine_id";
ext3_engine2.display_name = "ext3_engine2_display_name";
ext3_engine2.language_code = "en";
- ext3_engine2.layout = "us";
+ ext3_engine2.layouts.push_back("us");
ext3.engines.push_back(ext3_engine2);
- IBusComponent::EngineDescription ext3_engine3;
+ ComponentExtensionEngine ext3_engine3;
ext3_engine3.engine_id = "ext3_engine3_engine_id";
ext3_engine3.display_name = "ext3_engine3_display_name";
ext3_engine3.language_code = "en";
- ext3_engine3.layout = "us";
+ ext3_engine3.layouts.push_back("us");
ext3.engines.push_back(ext3_engine3);
ime_list_.push_back(ext3);
@@ -204,7 +204,7 @@ TEST_F(ComponentExtensionIMEManagerTest, IsWhitelistedExtensionTest) {
TEST_F(ComponentExtensionIMEManagerTest, GetNameDescriptionTest) {
for (size_t i = 0; i < ime_list_.size(); ++i) {
for (size_t j = 0; j < ime_list_[i].engines.size(); ++j) {
- const IBusComponent::EngineDescription& engine
+ const ComponentExtensionEngine& engine
= ime_list_[i].engines[j];
const std::string input_method_id =
diff --git a/chromeos/ime/input_method_descriptor.cc b/chromeos/ime/input_method_descriptor.cc
index 3215b68..9ceab2e 100644
--- a/chromeos/ime/input_method_descriptor.cc
+++ b/chromeos/ime/input_method_descriptor.cc
@@ -15,16 +15,22 @@ namespace input_method {
InputMethodDescriptor::InputMethodDescriptor(
const std::string& id,
const std::string& name,
- const std::string& keyboard_layout,
+ const std::vector<std::string>& keyboard_layouts,
const std::string& language_code,
const std::string& options_page_url)
: id_(id),
name_(name),
- keyboard_layout_(keyboard_layout),
+ keyboard_layouts_(keyboard_layouts),
language_code_(language_code),
options_page_url_(options_page_url) {
}
+std::string InputMethodDescriptor::GetPreferredKeyboardLayout() const {
+ // TODO(nona): Investigate better way to guess the preferred layout
+ // http://crbug.com/170601.
+ return keyboard_layouts_.empty() ? "us" : keyboard_layouts_[0];
+}
+
InputMethodDescriptor::InputMethodDescriptor() {
}
diff --git a/chromeos/ime/input_method_descriptor.h b/chromeos/ime/input_method_descriptor.h
index 29f4f02..fd0c27d 100644
--- a/chromeos/ime/input_method_descriptor.h
+++ b/chromeos/ime/input_method_descriptor.h
@@ -14,37 +14,45 @@
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::vector<std::string>& keyboard_layouts,
const std::string& language_code,
const std::string& options_page_url);
~InputMethodDescriptor();
+ // Accessors
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_; }
const std::string& options_page_url() const { return options_page_url_; }
+ const std::vector<std::string>& keyboard_layouts() const {
+ return keyboard_layouts_;
+ }
+
+ // Returns preferred keyboard layout.
+ std::string GetPreferredKeyboardLayout() const;
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_;
+ std::vector<std::string> keyboard_layouts_;
+
// Language code like "ko", "ja", "en-US", and "zh-CN".
std::string language_code_;
+
// Options page URL e.g.
// "chrome-extension://ceaajjmckiakobniehbjpdcidfpohlin/options.html".
// We can't use GURL here due to dependency policy. This field is valid only
diff --git a/chromeos/ime/input_method_whitelist.cc b/chromeos/ime/input_method_whitelist.cc
index d9a718c..31a81b2 100644
--- a/chromeos/ime/input_method_whitelist.cc
+++ b/chromeos/ime/input_method_whitelist.cc
@@ -31,10 +31,13 @@ InputMethodWhitelist::GetSupportedInputMethods() const {
scoped_ptr<InputMethodDescriptors> input_methods(new InputMethodDescriptors);
input_methods->reserve(arraysize(kInputMethods));
for (size_t i = 0; i < arraysize(kInputMethods); ++i) {
+ std::vector<std::string> layouts;
+ layouts.push_back(kInputMethods[i].xkb_layout_id);
+
input_methods->push_back(InputMethodDescriptor(
kInputMethods[i].input_method_id,
"",
- kInputMethods[i].xkb_layout_id,
+ layouts,
kInputMethods[i].language_code,
"")); // options page url, not available for non-extension input
// method.