Skip to content

Commit

Permalink
Separate the generated date from xkeyboard.cc for ease of udpate.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mazda@chromium.org committed Jan 26, 2012
1 parent 1e685c0 commit 417d78c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 77 deletions.
52 changes: 1 addition & 51 deletions chrome/browser/chromeos/input_method/xkeyboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "chrome/browser/chromeos/input_method/input_method_util.h"
#include "chrome/browser/chromeos/input_method/xkeyboard_data.h"
#include "chrome/browser/chromeos/system/runtime_environment.h"
#include "content/public/browser/browser_thread.h"
#include "ui/base/x/x11_util.h"
Expand Down Expand Up @@ -45,57 +46,6 @@ ModifierKey kCustomizableKeys[] = {
kLeftAltKey
};

// These arrays are generated by 'gen_keyboard_overlay_data.py --altgr'
// These are the input method IDs that shouldn't remap the right alt key.
const char* kKeepRightAltInputMethods[] = {
"mozc-hangul",
"xkb:be::fra",
"xkb:be::ger",
"xkb:be::nld",
"xkb:bg::bul",
"xkb:bg:phonetic:bul",
"xkb:br::por",
"xkb:ca::fra",
"xkb:ca:eng:eng",
"xkb:ch::ger",
"xkb:ch:fr:fra",
"xkb:cz::cze",
"xkb:de::ger",
"xkb:de:neo:ger",
"xkb:dk::dan",
"xkb:ee::est",
"xkb:es::spa",
"xkb:es:cat:cat",
"xkb:fi::fin",
"xkb:fr::fra",
"xkb:gb:dvorak:eng",
"xkb:gb:extd:eng",
"xkb:gr::gre",
"xkb:hr::scr",
"xkb:il::heb",
"xkb:it::ita",
"xkb:kr:kr104:kor",
"xkb:latam::spa",
"xkb:lt::lit",
"xkb:no::nob",
"xkb:pl::pol",
"xkb:pt::por",
"xkb:ro::rum",
"xkb:se::swe",
"xkb:si::slv",
"xkb:sk::slo",
"xkb:tr::tur",
"xkb:ua::ukr",
"xkb:us:altgr-intl:eng",
"xkb:us:intl:eng",
};

// These are the overlay names with caps lock remapped
const char* kCapsLockRemapped[] = {
"xkb:de:neo:ger",
"xkb:us:colemak:eng",
};

// A string for obtaining a mask value for Num Lock.
const char kNumLockVirtualModifierString[] = "NumLock";

Expand Down
66 changes: 66 additions & 0 deletions chrome/browser/chromeos/input_method/xkeyboard_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

// 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[] = {
"mozc-hangul",
"xkb:be::fra",
"xkb:be::ger",
"xkb:be::nld",
"xkb:bg::bul",
"xkb:bg:phonetic:bul",
"xkb:br::por",
"xkb:ca::fra",
"xkb:ca:eng:eng",
"xkb:ch::ger",
"xkb:ch:fr:fra",
"xkb:cz::cze",
"xkb:de::ger",
"xkb:de:neo:ger",
"xkb:dk::dan",
"xkb:ee::est",
"xkb:es::spa",
"xkb:es:cat:cat",
"xkb:fi::fin",
"xkb:fr::fra",
"xkb:gb:dvorak:eng",
"xkb:gb:extd:eng",
"xkb:gr::gre",
"xkb:hr::scr",
"xkb:il::heb",
"xkb:it::ita",
"xkb:kr:kr104:kor",
"xkb:latam::spa",
"xkb:lt::lit",
"xkb:no::nob",
"xkb:pl::pol",
"xkb:pt::por",
"xkb:ro::rum",
"xkb:se::swe",
"xkb:si::slv",
"xkb:sk::slo",
"xkb:tr::tur",
"xkb:ua::ukr",
"xkb:us:altgr-intl:eng",
"xkb:us:intl:eng",
};

// These are the overlay names with caps lock remapped
const char* kCapsLockRemapped[] = {
"xkb:de:neo:ger",
"xkb:us:colemak:eng",
};

} // input_method
} // chromeos

#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_DATA_H_
1 change: 1 addition & 0 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@
'browser/chromeos/input_method/virtual_keyboard_selector.h',
'browser/chromeos/input_method/xkeyboard.cc',
'browser/chromeos/input_method/xkeyboard.h',
'browser/chromeos/input_method/xkeyboard_data.h',
'browser/chromeos/language_preferences.cc',
'browser/chromeos/language_preferences.h',
'browser/chromeos/legacy_window_manager/initial_browser_window_observer.cc',
Expand Down
70 changes: 44 additions & 26 deletions tools/gen_keyboard_overlay_data/gen_keyboard_overlay_data.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -54,14 +54,12 @@
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',
Expand Down Expand Up @@ -179,7 +177,15 @@
"""

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
};
Expand All @@ -189,6 +195,10 @@
%s
};
} // input_method
} // chromeos
#endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_DATA_H_
""")

def SplitBehavior(behavior):
Expand Down Expand Up @@ -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)


Expand All @@ -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()
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 417d78c

Please sign in to comment.