diff options
author | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-29 08:43:24 +0000 |
---|---|---|
committer | nona@chromium.org <nona@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-29 08:43:24 +0000 |
commit | 799b443b0b3a6834b8a04b1e3d41a7f6cd45357c (patch) | |
tree | 3cf04e497025c2db9b28043d097db027dce6174d /chrome/browser/chromeos/input_method | |
parent | 1b4a9530d513314e70b01b16e849ec17294b6666 (diff) | |
download | chromium_src-799b443b0b3a6834b8a04b1e3d41a7f6cd45357c.zip chromium_src-799b443b0b3a6834b8a04b1e3d41a7f6cd45357c.tar.gz chromium_src-799b443b0b3a6834b8a04b1e3d41a7f6cd45357c.tar.bz2 |
Extract input_method_whitelist.{h|cc} from c/b/chromeos.
This is the 2nd try of https://codereview.chromium.org/12438012/
It turned out that c/b/chromeos/input_methods/input_methods.txt is also used by chromeos side.
So keeping c/b/chromeos/input_methods/input_methods.txt as is for migration and after change is in chromeos tree, I will remove it.
BUG=164375
TEST=None
TBR=sky
Review URL: https://chromiumcodereview.appspot.com/13042007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191325 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/input_method')
11 files changed, 7 insertions, 290 deletions
diff --git a/chrome/browser/chromeos/input_method/gen_input_methods.py b/chrome/browser/chromeos/input_method/gen_input_methods.py deleted file mode 100755 index a9f90bf..0000000 --- a/chrome/browser/chromeos/input_method/gen_input_methods.py +++ /dev/null @@ -1,123 +0,0 @@ -#!/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/chrome/browser/chromeos/input_method/ibus_controller_impl.h b/chrome/browser/chromeos/input_method/ibus_controller_impl.h index b27ecb8..ca63e07 100644 --- a/chrome/browser/chromeos/input_method/ibus_controller_impl.h +++ b/chrome/browser/chromeos/input_method/ibus_controller_impl.h @@ -11,9 +11,9 @@ #include "base/process_util.h" #include "base/threading/thread_checker.h" #include "chrome/browser/chromeos/input_method/ibus_controller_base.h" -#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" #include "chromeos/dbus/ibus/ibus_panel_service.h" #include "chromeos/ime/ibus_daemon_controller.h" +#include "chromeos/ime/input_method_whitelist.h" namespace ui { class InputMethodIBus; diff --git a/chrome/browser/chromeos/input_method/input_method.gyp b/chrome/browser/chromeos/input_method/input_method.gyp deleted file mode 100644 index a88ded1..0000000 --- a/chrome/browser/chromeos/input_method/input_method.gyp +++ /dev/null @@ -1,40 +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. - -{ - 'variables': { - 'input_method_out_dir': - '<(SHARED_INTERMEDIATE_DIR)/chrome/browser/chromeos/input_method', - }, - '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/chrome/browser/chromeos/input_method/input_method_manager_impl.h b/chrome/browser/chromeos/input_method/input_method_manager_impl.h index 00b67a0..abaae6d 100644 --- a/chrome/browser/chromeos/input_method/input_method_manager_impl.h +++ b/chrome/browser/chromeos/input_method/input_method_manager_impl.h @@ -15,8 +15,8 @@ #include "chrome/browser/chromeos/input_method/ibus_controller.h" #include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" -#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" #include "chromeos/ime/ibus_daemon_controller.h" +#include "chromeos/ime/input_method_whitelist.h" namespace chromeos { class InputMethodEngineIBus; diff --git a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc index 204ff91..04285853 100644 --- a/chrome/browser/chromeos/input_method/input_method_util_unittest.cc +++ b/chrome/browser/chromeos/input_method/input_method_util_unittest.cc @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/utf_string_conversions.h" #include "chrome/browser/chromeos/input_method/input_method_manager.h" -#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" +#include "chromeos/ime/input_method_whitelist.h" #include "chromeos/ime/mock_input_method_delegate.h" #include "grit/generated_resources.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/chromeos/input_method/input_method_whitelist.cc b/chrome/browser/chromeos/input_method/input_method_whitelist.cc deleted file mode 100644 index bba13d5..0000000 --- a/chrome/browser/chromeos/input_method/input_method_whitelist.cc +++ /dev/null @@ -1,45 +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 "chrome/browser/chromeos/input_method/input_method_whitelist.h" - -#include <vector> - -#include "chrome/browser/chromeos/input_method/input_methods.h" -#include "chromeos/ime/input_method_descriptor.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/chrome/browser/chromeos/input_method/input_method_whitelist.h b/chrome/browser/chromeos/input_method/input_method_whitelist.h deleted file mode 100644 index f6accdc..0000000 --- a/chrome/browser/chromeos/input_method/input_method_whitelist.h +++ /dev/null @@ -1,44 +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 CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_WHITELIST_H_ -#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_WHITELIST_H_ - -#include <set> -#include <string> -#include <vector> - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" - -namespace chromeos { -namespace input_method { - -class InputMethodDescriptor; -typedef std::vector<InputMethodDescriptor> InputMethodDescriptors; - -// -class 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 // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_WHITELIST_H_ diff --git a/chrome/browser/chromeos/input_method/input_method_whitelist_unittest.cc b/chrome/browser/chromeos/input_method/input_method_whitelist_unittest.cc deleted file mode 100644 index 8718d8a..0000000 --- a/chrome/browser/chromeos/input_method/input_method_whitelist_unittest.cc +++ /dev/null @@ -1,32 +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 "base/logging.h" -#include "chrome/browser/chromeos/input_method/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/chrome/browser/chromeos/input_method/input_methods.txt b/chrome/browser/chromeos/input_method/input_methods.txt index 64774a0..8440fee 100644 --- a/chrome/browser/chromeos/input_method/input_methods.txt +++ b/chrome/browser/chromeos/input_method/input_methods.txt @@ -1,3 +1,4 @@ +# TODO(nona): Remove this file, this is only for migration. # The list of input methods that we support. The input methods metadata is # also defined here. We use this data for the following purposes. # @@ -49,7 +50,7 @@ # and update the following files by running this script. # # * chrome/app/generated_resources.grd -# * chrome/browser/resources/keyboard_overlay_data.js +# * 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 diff --git a/chrome/browser/chromeos/input_method/mock_input_method_manager.h b/chrome/browser/chromeos/input_method/mock_input_method_manager.h index 141b459..f0b48ef 100644 --- a/chrome/browser/chromeos/input_method/mock_input_method_manager.h +++ b/chrome/browser/chromeos/input_method/mock_input_method_manager.h @@ -7,8 +7,8 @@ #include "chrome/browser/chromeos/input_method/input_method_manager.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" -#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" #include "chrome/browser/chromeos/input_method/mock_xkeyboard.h" +#include "chromeos/ime/input_method_whitelist.h" #include "chromeos/ime/mock_input_method_delegate.h" namespace chromeos { diff --git a/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc b/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc index 113e551..22749dd 100644 --- a/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc +++ b/chrome/browser/chromeos/input_method/xkeyboard_unittest.cc @@ -12,7 +12,7 @@ #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" -#include "chrome/browser/chromeos/input_method/input_method_whitelist.h" +#include "chromeos/ime/input_method_whitelist.h" #include "chromeos/ime/mock_input_method_delegate.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" |