summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 02:37:02 +0000
committermazda@chromium.org <mazda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-16 02:37:02 +0000
commita6b3a1ae8b4e9e6c6a8b120620dc929a8e382248 (patch)
tree3c1eff0e975359f33617130727a2095f6767ea5a
parente7dbdddeb7aa7ad45e778dec273219e4fea2c4de (diff)
downloadchromium_src-a6b3a1ae8b4e9e6c6a8b120620dc929a8e382248.zip
chromium_src-a6b3a1ae8b4e9e6c6a8b120620dc929a8e382248.tar.gz
chromium_src-a6b3a1ae8b4e9e6c6a8b120620dc929a8e382248.tar.bz2
Merge 176826
> Adjust keyboard overlay when the layout has a diamond key. > > BUG=163916 > TEST=Manually check keyboard overlay that has a diamond key is shown with --has-chromeos-has-diamond-key specified > > > Review URL: https://chromiumcodereview.appspot.com/11862003 TBR=mazda@chromium.org Review URL: https://codereview.chromium.org/11962007 git-svn-id: svn://svn.chromium.org/chrome/branches/1364/src@177060 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/chromeos/keyboard_overlay.js76
-rw-r--r--chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc5
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h1
4 files changed, 79 insertions, 6 deletions
diff --git a/chrome/browser/resources/chromeos/keyboard_overlay.js b/chrome/browser/resources/chromeos/keyboard_overlay.js
index 41aa374..7344bee 100644
--- a/chrome/browser/resources/chromeos/keyboard_overlay.js
+++ b/chrome/browser/resources/chromeos/keyboard_overlay.js
@@ -111,11 +111,19 @@ var keyboardOverlayId = 'en_US';
var identifierMap = {};
/**
- * Returns layouts data.
- * @return {Object} Keyboard layout data.
+ * Returns the layout name.
+ * @return {string} layout name.
*/
-function getLayouts() {
- return keyboardOverlayData['layouts'];
+function getLayoutName() {
+ return getKeyboardGlyphData().layoutName;
+}
+
+/**
+ * Returns layout data.
+ * @return {Array} Keyboard layout data.
+ */
+function getLayout() {
+ return keyboardOverlayData['layouts'][getLayoutName()];
}
// Cache the shortcut data after it is constructed.
@@ -432,7 +440,7 @@ function update(modifiers) {
var keyboardGlyphData = getKeyboardGlyphData();
var shortcutData = getShortcutData();
- var layout = getLayouts()[keyboardGlyphData.layoutName];
+ var layout = getLayout();
for (var i = 0; i < layout.length; ++i) {
var identifier = remapIdentifier(layout[i][0]);
var keyData = keyboardGlyphData.keys[identifier];
@@ -513,7 +521,7 @@ function initLayout() {
// Add data for the special key representing a disabled key
keys['DISABLED'] = {label: 'disabled', format: 'left'};
- var layout = getLayouts()[getKeyboardGlyphData().layoutName];
+ var layout = getLayout();
var keyboard = document.body;
var minX = window.innerWidth;
var maxX = 0;
@@ -602,6 +610,58 @@ function initLayout() {
}
/**
+ * Returns true if the device has a diamond key.
+ * @return {boolean} Returns true if the device has a diamond key.
+ */
+function hasDiamondKey() {
+ return (loadTimeData.getString('keyboardOverlayHasChromeOSDiamondKey') ==
+ 'true');
+}
+
+/**
+ * Initializes the layout and the key labels for the keyboard that has a diamond
+ * key.
+ */
+function initDiamondKey() {
+ var newLayoutData = {
+ '1D': [65.0, 287.0, 60.0, 60.0], // left Ctrl
+ '38': [185.0, 287.0, 60.0, 60.0], // left Alt
+ 'E0 5B': [125.0, 287.0, 60.0, 60.0], // search
+ '3A': [5.0, 167.0, 105.0, 60.0], // caps lock
+ '5B': [803.0, 6.0, 72.0, 35.0], // lock key
+ '5D': [5.0, 287.0, 60.0, 60.0] // diamond key
+ };
+
+ var layout = getLayout();
+ var powerKeyIndex = -1;
+ var powerKeyId = '00';
+ for (var i = 0; i < layout.length; i++) {
+ var keyId = layout[i][0];
+ if (keyId in newLayoutData) {
+ layout[i] = [keyId].concat(newLayoutData[keyId]);
+ delete newLayoutData[keyId];
+ }
+ if (keyId == powerKeyId)
+ powerKeyIndex = i;
+ }
+ for (var keyId in newLayoutData)
+ layout.push([keyId].concat(newLayoutData[keyId]));
+
+ // Remove the power key.
+ if (powerKeyIndex != -1)
+ layout.splice(powerKeyIndex, 1);
+
+ var keyData = getKeyboardGlyphData()['keys'];
+ var newKeyData = {
+ '3A': {'label': 'caps lock', 'format': 'left'},
+ '5B': {'label': 'lock'},
+ '5D': {'label': 'diamond', 'format': 'left'}
+ };
+ for (var keyId in newKeyData)
+ keyData[keyId] = newKeyData[keyId];
+}
+
+/**
* A callback function for the onload event of the body element.
*/
function init() {
@@ -651,6 +711,10 @@ function initKeyboardOverlayId(inputMethodId) {
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
+ // We show Japanese layout as-is because the user has chosen the layout
+ // that is quite diffrent from the physical layout that has a diamond key.
+ if (hasDiamondKey() && getLayoutName() != 'J')
+ initDiamondKey();
initLayout();
update([]);
window.webkitRequestAnimationFrame(function() {
diff --git a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
index 67be76c..9923dd3 100644
--- a/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.cc
@@ -247,6 +247,11 @@ ChromeWebUIDataSource* CreateKeyboardOverlayUIHTMLSource() {
}
source->AddString("keyboardOverlayLearnMoreURL", UTF8ToUTF16(kLearnMoreURL));
+ const char* has_diamond_key_value =
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kHasChromeOSDiamondKey) ? "true" : "false";
+ source->AddString("keyboardOverlayHasChromeOSDiamondKey",
+ has_diamond_key_value);
source->set_json_path("strings.js");
source->set_use_json_js_format_v2();
source->add_resource_path("keyboard_overlay.js", IDR_KEYBOARD_OVERLAY_JS);
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index d3c5930..efddea9 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1464,6 +1464,9 @@ const char kFirstBoot[] = "first-boot";
// Chromeboxes.
const char kHasChromeOSKeyboard[] = "has-chromeos-keyboard";
+// If true, the Chromebook has a keyboard with a diamond key.
+const char kHasChromeOSDiamondKey[] = "has-chromeos-diamond-key";
+
// Path for the screensaver used in Kiosk mode
const char kKioskModeScreensaverPath[] = "kiosk-mode-screensaver-path";
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 27ae4ff..245fc7a 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -405,6 +405,7 @@ extern const char kEnableRequestTabletSite[];
extern const char kEnableStaticIPConfig[];
extern const char kFirstBoot[];
extern const char kHasChromeOSKeyboard[];
+extern const char kHasChromeOSDiamondKey[];
extern const char kKioskModeScreensaverPath[];
extern const char kLoginManager[];
// TODO(avayvod): Remove this flag when it's unnecessary for testing