diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-26 08:36:14 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-26 08:36:14 +0000 |
commit | daf17c15aa4ba562d832149b45b5b9ed58b2db39 (patch) | |
tree | d891688db2d54f3a773962cc05e199b81d6466c2 /chromeos/ime | |
parent | a916d89c22d2702fd5f238b34f203ebccf9efe66 (diff) | |
download | chromium_src-daf17c15aa4ba562d832149b45b5b9ed58b2db39.zip chromium_src-daf17c15aa4ba562d832149b45b5b9ed58b2db39.tar.gz chromium_src-daf17c15aa4ba562d832149b45b5b9ed58b2db39.tar.bz2 |
Extract input_method_whitelist.{h|cc} from c/b/chromeos.
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/12438012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190596 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos/ime')
-rwxr-xr-x | chromeos/ime/gen_input_methods.py | 123 | ||||
-rw-r--r-- | chromeos/ime/input_method.gyp | 40 | ||||
-rw-r--r-- | chromeos/ime/input_method_whitelist.cc | 45 | ||||
-rw-r--r-- | chromeos/ime/input_method_whitelist.h | 46 | ||||
-rw-r--r-- | chromeos/ime/input_method_whitelist_unittest.cc | 32 | ||||
-rw-r--r-- | chromeos/ime/input_methods.txt | 212 |
6 files changed, 498 insertions, 0 deletions
diff --git a/chromeos/ime/gen_input_methods.py b/chromeos/ime/gen_input_methods.py new file mode 100755 index 0000000..a9f90bf --- /dev/null +++ b/chromeos/ime/gen_input_methods.py @@ -0,0 +1,123 @@ +#!/usr/bin/env python +# 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. + +"""Generate a C++ header from ibus_input_methods.txt. + +This program generates a C++ header file containing the information on +available input methods. It parses input_methods.txt, and then generates a +static array definition from the information extracted. The input and output +file names are specified on the command line. + +Run it like: + gen_input_methods.py input_methods.txt input_methods.h + +It will produce output that looks like: + +// This file is automatically generated by gen_input_methods.py +#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ +#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ + +namespace chromeos { +namespace input_method { + +struct InputMethodsInfo { + const char* input_method_id; + const char* language_code; + const char* xkb_keyboard_id; +}; +const InputMethodsInfo kInputMethods[] = { + {"mozc-chewing", "zh-TW", "us"}, + {"xkb:us::eng", "en-US", "us"}, + {"xkb:us:dvorak:eng", "en-US", "us(dvorak)"}, + {"xkb:be::fra", "fr", "be"}, + {"xkb:br::por", "pt-BR", "br"}, +}; + +} // namespace input_method +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ + +""" + +import fileinput +import re +import sys + +OUTPUT_HEADER = """// Automatically generated by gen_input_methods.py +#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ +#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ + +namespace chromeos { +namespace input_method { + +struct InputMethodsInfo { + const char* input_method_id; + const char* language_code; + const char* xkb_layout_id; +}; +const InputMethodsInfo kInputMethods[] = { +""" + +CPP_FORMAT = '#if %s\n' +ENGINE_FORMAT = (' {"%(input_method_id)s", "%(language_code)s", ' + + '"%(xkb_layout_id)s"},\n') + +OUTPUT_FOOTER = """ +}; + +} // namespace input_method +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ +""" + +def CreateEngineHeader(engines): + """Create the header file from a list of engines. + + Arguments: + engines: list of engine objects + Returns: + The text of a C++ header file containing the engine data. + """ + output = [] + output.append(OUTPUT_HEADER) + for engine in engines: + if engine.has_key('if'): + output.append(CPP_FORMAT % engine['if']) + output.append(ENGINE_FORMAT % engine) + if engine.has_key('if'): + output.append('#endif\n') + output.append(OUTPUT_FOOTER) + + return "".join(output) + + +def main(argv): + if len(argv) != 3: + print 'Usage: gen_input_methods.py [whitelist] [output]' + sys.exit(1) + engines = [] + for line in fileinput.input(sys.argv[1]): + line = line.strip() + if not line or re.match(r'#', line): + continue + columns = line.split() + assert len(columns) == 3 or len(columns) == 4, "Invalid format: " + line + engine = {} + engine['input_method_id'] = columns[0] + engine['xkb_layout_id'] = columns[1] + engine['language_code'] = columns[2] + if len(columns) == 4: + engine['if'] = columns[3] + engines.append(engine) + + output = CreateEngineHeader(engines) + output_file = open(sys.argv[2], 'w') + output_file.write(output) + + +if __name__ == '__main__': + main(sys.argv) diff --git a/chromeos/ime/input_method.gyp b/chromeos/ime/input_method.gyp new file mode 100644 index 0000000..1da130e --- /dev/null +++ b/chromeos/ime/input_method.gyp @@ -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. + +{ + 'variables': { + 'input_method_out_dir': + '<(SHARED_INTERMEDIATE_DIR)/chromeos/ime', + }, + 'targets': [ + { + 'target_name': 'gencode', + 'type': 'none', + 'actions': [ + { + 'inputs': [ + 'input_methods.txt', + 'gen_input_methods.py', + ], + 'outputs': [ + '<(input_method_out_dir)/input_methods.h', + ], + 'action_name': 'gen_input_methods', + 'action': [ + 'python', + 'gen_input_methods.py', + 'input_methods.txt', + '<(input_method_out_dir)/input_methods.h', + ], + 'message': 'Generating input_methods.h', + }, + ], + 'direct_dependent_settings': { + 'include_dirs': [ + '<(SHARED_INTERMEDIATE_DIR)', + ], + }, + }, + ] +} diff --git a/chromeos/ime/input_method_whitelist.cc b/chromeos/ime/input_method_whitelist.cc new file mode 100644 index 0000000..ba0b7b8 --- /dev/null +++ b/chromeos/ime/input_method_whitelist.cc @@ -0,0 +1,45 @@ +// 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_whitelist.h" + +#include <vector> + +#include "chromeos/ime/input_method_descriptor.h" +#include "chromeos/ime/input_methods.h" + +namespace chromeos { +namespace input_method { + +InputMethodWhitelist::InputMethodWhitelist() { + for (size_t i = 0; i < arraysize(kInputMethods); ++i) { + supported_input_methods_.insert(kInputMethods[i].input_method_id); + } +} + +InputMethodWhitelist::~InputMethodWhitelist() { +} + +bool InputMethodWhitelist::InputMethodIdIsWhitelisted( + const std::string& input_method_id) const { + return supported_input_methods_.count(input_method_id) > 0; +} + +scoped_ptr<InputMethodDescriptors> +InputMethodWhitelist::GetSupportedInputMethods() const { + scoped_ptr<InputMethodDescriptors> input_methods(new InputMethodDescriptors); + input_methods->reserve(arraysize(kInputMethods)); + for (size_t i = 0; i < arraysize(kInputMethods); ++i) { + input_methods->push_back(InputMethodDescriptor( + kInputMethods[i].input_method_id, + "", + kInputMethods[i].xkb_layout_id, + kInputMethods[i].language_code, + false)); + } + return input_methods.Pass(); +} + +} // namespace input_method +} // namespace chromeos diff --git a/chromeos/ime/input_method_whitelist.h b/chromeos/ime/input_method_whitelist.h new file mode 100644 index 0000000..3a22493 --- /dev/null +++ b/chromeos/ime/input_method_whitelist.h @@ -0,0 +1,46 @@ +// 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_WHITELIST_H_ +#define CHROMEOS_IME_INPUT_METHOD_WHITELIST_H_ + +#include <set> +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "chromeos/chromeos_export.h" + +namespace chromeos { +namespace input_method { + +class InputMethodDescriptor; +typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; + +// A class which has white listed input method list. The list is generated by +// gen_input_methods.py from input_methods.txt. +class CHROMEOS_EXPORT InputMethodWhitelist { + public: + InputMethodWhitelist(); + ~InputMethodWhitelist(); + + // Returns true if |input_method_id| is whitelisted. + bool InputMethodIdIsWhitelisted(const std::string& input_method_id) const; + + // Returns all input methods that are supported, including ones not active. + // This function never returns NULL. Note that input method extensions are not + // included in the result. + scoped_ptr<InputMethodDescriptors> GetSupportedInputMethods() const; + + private: + std::set<std::string> supported_input_methods_; + + DISALLOW_COPY_AND_ASSIGN(InputMethodWhitelist); +}; + +} // namespace input_method +} // namespace chromeos + +#endif // CHROMEOS_IME_INPUT_METHOD_WHITELIST_H_ diff --git a/chromeos/ime/input_method_whitelist_unittest.cc b/chromeos/ime/input_method_whitelist_unittest.cc new file mode 100644 index 0000000..eb4ed28 --- /dev/null +++ b/chromeos/ime/input_method_whitelist_unittest.cc @@ -0,0 +1,32 @@ +// 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_whitelist.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace chromeos { +namespace input_method { + +namespace { + +class InputMethodWhitelistTest : public testing::Test { + protected: + const InputMethodWhitelist whitelist_; +}; + +} // namespace + +TEST_F(InputMethodWhitelistTest, TestInputMethodIdIsWhitelisted) { + EXPECT_TRUE(whitelist_.InputMethodIdIsWhitelisted("mozc")); + EXPECT_TRUE(whitelist_.InputMethodIdIsWhitelisted("xkb:us:dvorak:eng")); + EXPECT_FALSE(whitelist_.InputMethodIdIsWhitelisted("mozc,")); + EXPECT_FALSE(whitelist_.InputMethodIdIsWhitelisted("mozc,xkb:us:dvorak:eng")); + EXPECT_FALSE(whitelist_.InputMethodIdIsWhitelisted("not-supported-id")); + EXPECT_FALSE(whitelist_.InputMethodIdIsWhitelisted(",")); + EXPECT_FALSE(whitelist_.InputMethodIdIsWhitelisted("")); +} + +} // namespace input_method +} // namespace chromeos diff --git a/chromeos/ime/input_methods.txt b/chromeos/ime/input_methods.txt new file mode 100644 index 0000000..1d1d9ab --- /dev/null +++ b/chromeos/ime/input_methods.txt @@ -0,0 +1,212 @@ +# The list of input methods that we support. The input methods metadata is +# also defined here. We use this data for the following purposes. +# +# 1. Exclude unnecessary input methods. For example, we don't need +# "ja:anthy", and "zh:pinyin" engines in ibus-m17n since we have better +# alternatives outside of ibus-m17n. Excluding these input methods from +# the IBus engine XML files, such as /usr/share/ibus/component/m17n.xml, +# makes the startup time of the IBus daemon faster. This filtering is +# done using a python script at build time of ibus-m17n. +# See crosbug.com/4161 for details. +# +# 2. Provide the input methods metadata to Chrome at build time. Chrome +# needs to know about the supported input methods for the input method +# features, such as the input method switching and the options page, +# to work. Note that we can retrieve the same metadata from the IBus +# daemon, but Chrome needs be able to get the metadata without talking +# to the IBus daemon. This requirement comes from the fact that the +# IBus daemon should not run if the user is just using keyboard layouts +# such as US keyboard. The metadata generation is done using a python +# script at build time of Chrome. See crosbug.com/16961 for details. +# +# The order of the list is important. In Chrome's "Languages and input" options +# page, we list input methods in this order, when more than one input methods +# are available for a language (ex. French). +# +# Each non-comment line contains the following tab-separated columns. +# +# 1) The input method ID used by Chrome. (ex. "xkb:ca::fra") You should *NEVER* +# change the ID since the ID might be written in user's ~/Preferences. For +# example, three-letter ISO 639-2/B codes are used for IDs start with "xkb:" +# for histrical reason, but we should not replace them with two-letter 639-1 +# codes that are currently in use in the 3rd column. +# 2) The keyboard layout ID used by XKB. (ex. "us", "us(dvorak)", "ca", +# "handwriting-vk,jp"). See also: /usr/share/X11/xkb/symbols. +# 3) The language code (ex. "fr"). Only one format, ISO 639-1 compliant two- +# letter language code which can be recognized by ICU, is allowed. Do not use +# three-letter ones (ISO 639-2/T and 639-2/B) here. For "en", "pt", and "zh", +# two-letter upper-case country code should be added (ex. "en-US", "zh-TW"). +# See http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for details. +# 4) [optional] The #if condition for the input method. +# (ex. "defined(A)", "!defined(A)||defined(B)") +# +# Notes: +# When adding a line to this list, please also add a mapping from the input +# method ID to the keyboard overlay ID to INPUT_METHOD_ID_TO_OVERLAY_ID in +# +# * tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py +# +# and update the following files by running this script. +# +# * chrome/app/generated_resources.grd +# * chrome/browser/resources/chromeos/keyboard_overlay_data.js +# * chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc +# +# If you add an XKB layout which depends on X11's Mod3Mask (e.g. Germany Neo2 +# XKB layout), you should also update IsMod3UsedByCurrentInputMethod() method +# in chrome/browser/ui/ash/event_rewriter.cc. Otherwise, Mod3Mask might be +# removed unexpectedly by the rewriter. + +# U.S. English +xkb:us::eng us en-US +xkb:us:intl:eng us(intl) en-US +xkb:us:altgr-intl:eng us(altgr-intl) en-US +xkb:us:dvorak:eng us(dvorak) en-US +xkb:us:colemak:eng us(colemak) en-US +english-m us en-US +# U.S. English entiries have to be above the Dutch entry so that xkb:us:intl:eng +# will be selected as the default keyboard when the UI language is set to Dutch. + +# Dutch +xkb:be::nld be nl +# We don't support xkb:nl::nld. See b/4430951. + +# French +xkb:fr::fra fr fr +xkb:be::fra be fr +xkb:ca::fra ca fr +xkb:ch:fr:fra ch(fr) fr + +# German +xkb:de::ger de de +xkb:de:neo:ger de(neo) de +xkb:be::ger be de +xkb:ch::ger ch de + +# Japanese +mozc us ja +mozc-jp jp ja +mozc-dv us(dvorak) ja +# |kMozcJaInputMethodIds| in ibus_ui_controller.cc should also be updated when +# a new Mozc Japanese IME for another keyboard layout is added. +xkb:jp::jpn jp ja + +# Russian +xkb:ru::rus ru ru +xkb:ru:phonetic:rus ru(phonetic) ru + +# Thai +m17n:th:kesmanee us th +m17n:th:pattachote us th +m17n:th:tis820 us th + +# Simplified Chinese +pinyin us zh-CN +pinyin-dv us(dvorak) zh-CN + +# Traditional Chinese +mozc-chewing us zh-TW +m17n:zh:cangjie us zh-TW +m17n:zh:quick us zh-TW + +# Vietnamese +m17n:vi:tcvn us vi +m17n:vi:telex us vi +m17n:vi:viqr us vi +m17n:vi:vni us vi +# Note: Since Chrome does not support "get surrounding text" feature yet, +# Vietnames input methods, except 4 input methods above, in m17n-db should +# not work fine. The 4 input methods in m17n-db (>= 1.6.0) don't require the +# feature. + +# Korean +mozc-hangul kr(kr104) ko +xkb:kr:kr104:kor kr(kr104) ko + +# Arabic +m17n:ar:kbd us ar +# TODO(yusukes,jshin): Check if we can use ibux-xkb-layouts for Arabic, Hindi, +# etc. + +# Hindi +m17n:hi:itrans us hi +# Note: the m17n-contrib package has some more Hindi IMEs. + +# Farsi (Persian) +m17n:fa:isiri us fa + +# Bengali +m17n:bn:itrans us bn +# TODO(yusukes): Support the following IMEs in m17n-db (unijoy) and +# m17n-db-contrib (inscript, probhat). +# m17n:bn:unijoy us bn +# m17n:bn:inscript us bn +# m17n:bn:probhat us bn + +# Gujarati +m17n:gu:itrans us gu +# TODO(yusukes): Support the following IMEs in m17n-db-contrib. +# m17n:gu:phonetic us gu +# m17n:gu:inscript us gu + +# Malayalam +m17n:ml:itrans us ml +# TODO(yusukes): Support the following IMEs in m17n-db-contrib. +# m17n:ml:inscript us ml +# m17n:ml:mozhi us ml + +# Marathi +# Note: m17n:mr:itrans is in m17n-db-contrib. +m17n:mr:itrans us mr +# TODO(yusukes): Support the following IMEs in m17n-db-contrib. +# m17n:mr:phonetic us mr +# m17n:mr:inscript us mr + +# Tamil +m17n:ta:phonetic us ta +m17n:ta:inscript us ta +m17n:ta:tamil99 us ta +m17n:ta:itrans us ta +m17n:ta:typewriter us ta + +# Telugu +m17n:te:itrans us te +# Kannada +m17n:kn:itrans us kn + +# Amharic +m17n:am:sera us am + +# Keyboard layouts. +xkb:br::por br pt-BR +xkb:bg::bul bg bg +xkb:bg:phonetic:bul bg(phonetic) bg +xkb:ca:eng:eng ca(eng) en-CA +xkb:cz::cze cz cs +xkb:ee::est ee et +xkb:es::spa es es +xkb:es:cat:cat es(cat) ca +xkb:dk::dan dk da +xkb:gr::gre gr el +xkb:il::heb il he +xkb:latam::spa latam es +xkb:lt::lit lt lt +xkb:lv:apostrophe:lav lv(apostrophe) lv +xkb:hr::scr hr hr +xkb:gb:extd:eng gb(extd) en-GB +xkb:gb:dvorak:eng gb(dvorak) en-GB +xkb:fi::fin fi fi +xkb:hu::hun hu hu +xkb:it::ita it it +xkb:no::nob no nb +xkb:pl::pol pl pl +xkb:pt::por pt pt-PT +xkb:ro::rum ro ro +xkb:se::swe se sv +xkb:sk::slo sk sk +xkb:si::slv si sl +xkb:rs::srp rs sr +xkb:tr::tur tr tr +xkb:ua::ukr ua uk +# TODO(yusukes): Support xkb:latam:deadtilde:spa and/or xkb:latam:nodeadkeys:spa +# if necessary. |