diff options
author | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-26 21:21:04 +0000 |
---|---|---|
committer | mazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-26 21:21:04 +0000 |
commit | 417d78cf12cf44f235a7ec6b884b0af7d09ec60e (patch) | |
tree | 18fcb821da1009ef024048eb4f9a38ba7b789b97 /tools/gen_keyboard_overlay_data | |
parent | 1e685c007135b7d1a9ade81380104ac7ef725096 (diff) | |
download | chromium_src-417d78cf12cf44f235a7ec6b884b0af7d09ec60e.zip chromium_src-417d78cf12cf44f235a7ec6b884b0af7d09ec60e.tar.gz chromium_src-417d78cf12cf44f235a7ec6b884b0af7d09ec60e.tar.bz2 |
Separate the generated date from xkeyboard.cc for ease of udpate.
Currently we need to be careful not to delete the start and the end marker lines so that gen_keyboard_overlay_data.py work properly. This change move the generated part of xkeyboard.cc to a different file in order to make it easy to update the data and xkeyboard.cc.
BUG=None
TEST=unit_tests --gtest_filter="XKeyboardTest.*" passes
Review URL: http://codereview.chromium.org/9289044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119293 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gen_keyboard_overlay_data')
-rwxr-xr-x | tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py | 70 |
1 files changed, 44 insertions, 26 deletions
diff --git a/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py b/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py index 7be6f29..f736130 100755 --- a/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py +++ b/tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# 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. @@ -54,14 +54,12 @@ GRD_FILENAME = 'generated_resources.grd' JS_OUTDIR = 'chrome/browser/resources/chromeos' JS_FILENAME = 'keyboard_overlay_data.js' ALTGR_OUTDIR = 'chrome/browser/chromeos/input_method' -ALTGR_FILENAME = 'xkeyboard.cc' +ALTGR_FILENAME = 'xkeyboard_data.h' CC_START = r'IDS_KEYBOARD_OVERLAY_INSTRUCTIONS_HIDE },' CC_END = r'};' GRD_START = """Escape to hide </message>""" GRD_END = r' </if>' -ALTGR_START = r"arrays are generated by 'gen_keyboard_overlay_data.py --altgr'" -ALTGR_END = r'class XkbLayoutSets {' LABEL_MAP = { 'glyph_arrow_down': 'down', @@ -179,7 +177,15 @@ CC_SNIPPET_TEMPLATE=""" { "%s", %s }, """ ALTGR_TEMPLATE=( -"""// These are the input method IDs that shouldn't remap the right alt key. +"""// This file was generated by 'gen_keyboard_overlay_data.py --altgr' + +#ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_DATA_H_ +#define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_DATA_H_ + +namespace chromeos { +namespace input_method { + +// These are the input method IDs that shouldn't remap the right alt key. const char* kKeepRightAltInputMethods[] = { %s }; @@ -189,6 +195,10 @@ const char* kCapsLockRemapped[] = { %s }; +} // input_method +} // chromeos + +#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_DATA_H_ """) def SplitBehavior(behavior): @@ -446,26 +456,11 @@ def GetPath(path_from_src): return path -def OutputJson(keyboard_glyph_data, hotkey_data, layouts, var_name, outdir): - """Outputs the keyboard overlay data as a JSON file.""" - action_to_id = {} - for (behavior, action, _) in hotkey_data: - i18nContent = Toi18nContent(behavior) - action_to_id[action] = i18nContent - data = {'keyboardGlyph': keyboard_glyph_data, - 'shortcut': action_to_id, - 'layouts': layouts, - 'inputMethodIdToOverlayId': INPUT_METHOD_ID_TO_OVERLAY_ID} - if outdir: - outpath = os.path.join(outdir, JS_FILENAME) - else: - outpath = GetPath(os.path.join(JS_OUTDIR, JS_FILENAME)) +def OutputFile(outpath, snippet): + """Output the snippet into the specified path.""" out = file(outpath, 'w') out.write(GenerateCopyrightHeader() + '\n') - json_data = json.dumps(data, sort_keys=True, indent=2) - # Remove redundant spaces after ',' - json_data = json_data.replace(', \n', ',\n') - out.write('var %s = %s;\n' % (var_name, json_data)) + out.write(snippet) print 'Output ' + os.path.normpath(outpath) @@ -490,6 +485,27 @@ def RewriteFile(start, end, original_dir, original_filename, snippet, print 'Output ' + os.path.normpath(outpath) +def OutputJson(keyboard_glyph_data, hotkey_data, layouts, var_name, outdir): + """Outputs the keyboard overlay data as a JSON file.""" + action_to_id = {} + for (behavior, action, _) in hotkey_data: + i18nContent = Toi18nContent(behavior) + action_to_id[action] = i18nContent + data = {'keyboardGlyph': keyboard_glyph_data, + 'shortcut': action_to_id, + 'layouts': layouts, + 'inputMethodIdToOverlayId': INPUT_METHOD_ID_TO_OVERLAY_ID} + + if not outdir: + outdir = JS_OUTDIR + outpath = GetPath(os.path.join(outdir, JS_FILENAME)) + json_data = json.dumps(data, sort_keys=True, indent=2) + # Remove redundant spaces after ',' + json_data = json_data.replace(', \n', ',\n') + snippet = 'var %s = %s;\n' % (var_name, json_data) + OutputFile(outpath, snippet) + + def OutputGrd(hotkey_data, outdir): """Outputs a part of messages in the grd file.""" snippet = cStringIO.StringIO() @@ -539,11 +555,13 @@ def OutputAltGr(keyboard_glyph_data, outdir): caps_lock_output.append(' "%s",' % input_method_id) except KeyError: pass + + if not outdir: + outdir = ALTGR_OUTDIR + outpath = GetPath(os.path.join(outdir, ALTGR_FILENAME)) snippet = ALTGR_TEMPLATE % ("\n".join(sorted(altgr_output)), "\n".join(sorted(caps_lock_output))) - - RewriteFile(ALTGR_START, ALTGR_END, ALTGR_OUTDIR, ALTGR_FILENAME, snippet, - outdir) + OutputFile(outpath, snippet) def main(): |