| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // <include src="keyboard_overlay_data.js"> | 5 // <include src="keyboard_overlay_data.js"> |
| 6 | 6 |
| 7 var BASE_KEYBOARD = { | 7 var BASE_KEYBOARD = {top: 0, left: 0, width: 1237, height: 514}; |
| 8 top: 0, | |
| 9 left: 0, | |
| 10 width: 1237, | |
| 11 height: 514 | |
| 12 }; | |
| 13 | 8 |
| 14 var BASE_INSTRUCTIONS = { | 9 var BASE_INSTRUCTIONS = {top: 194, left: 370, width: 498, height: 142}; |
| 15 top: 194, | |
| 16 left: 370, | |
| 17 width: 498, | |
| 18 height: 142 | |
| 19 }; | |
| 20 | 10 |
| 21 var MODIFIER_TO_CLASS = { | 11 var MODIFIER_TO_CLASS = { |
| 22 'SHIFT': 'modifier-shift', | 12 'SHIFT': 'modifier-shift', |
| 23 'CTRL': 'modifier-ctrl', | 13 'CTRL': 'modifier-ctrl', |
| 24 'ALT': 'modifier-alt', | 14 'ALT': 'modifier-alt', |
| 25 'SEARCH': 'modifier-search' | 15 'SEARCH': 'modifier-search' |
| 26 }; | 16 }; |
| 27 | 17 |
| 28 var IDENTIFIER_TO_CLASS = { | 18 var IDENTIFIER_TO_CLASS = { |
| 29 '2A': 'is-shift', | 19 '2A': 'is-shift', |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 221: ']', | 103 221: ']', |
| 114 222: '\'', | 104 222: '\'', |
| 115 232: 'bright up', | 105 232: 'bright up', |
| 116 }; | 106 }; |
| 117 | 107 |
| 118 /** | 108 /** |
| 119 * When the top row keys setting is changed so that they're treated as function | 109 * When the top row keys setting is changed so that they're treated as function |
| 120 * keys, their labels should change as well. | 110 * keys, their labels should change as well. |
| 121 */ | 111 */ |
| 122 var TOP_ROW_KEY_LABEL_TO_FUNCTION_LABEL = { | 112 var TOP_ROW_KEY_LABEL_TO_FUNCTION_LABEL = { |
| 123 'back' : 'f1', | 113 'back': 'f1', |
| 124 'forward' : 'f2', | 114 'forward': 'f2', |
| 125 'reload' : 'f3', | 115 'reload': 'f3', |
| 126 'full screen' : 'f4', | 116 'full screen': 'f4', |
| 127 'switch window' : 'f5', | 117 'switch window': 'f5', |
| 128 'bright down' : 'f6', | 118 'bright down': 'f6', |
| 129 'bright up' : 'f7', | 119 'bright up': 'f7', |
| 130 'mute' : 'f8', | 120 'mute': 'f8', |
| 131 'vol. down' : 'f9', | 121 'vol. down': 'f9', |
| 132 'vol. up' : 'f10', | 122 'vol. up': 'f10', |
| 133 }; | 123 }; |
| 134 | 124 |
| 135 /** | 125 /** |
| 136 * Some key labels define actions (like for example 'vol. up' or 'mute'). | 126 * Some key labels define actions (like for example 'vol. up' or 'mute'). |
| 137 * These labels should be localized. (crbug.com/471025). | 127 * These labels should be localized. (crbug.com/471025). |
| 138 */ | 128 */ |
| 139 var LABEL_TO_LOCALIZED_LABEL_ID = { | 129 var LABEL_TO_LOCALIZED_LABEL_ID = { |
| 140 'esc' : 'keyboardOverlayEscKeyLabel', | 130 'esc': 'keyboardOverlayEscKeyLabel', |
| 141 'back' : 'keyboardOverlayBackKeyLabel', | 131 'back': 'keyboardOverlayBackKeyLabel', |
| 142 'forward' : 'keyboardOverlayForwardKeyLabel', | 132 'forward': 'keyboardOverlayForwardKeyLabel', |
| 143 'reload' : 'keyboardOverlayReloadKeyLabel', | 133 'reload': 'keyboardOverlayReloadKeyLabel', |
| 144 'full screen' : 'keyboardOverlayFullScreenKeyLabel', | 134 'full screen': 'keyboardOverlayFullScreenKeyLabel', |
| 145 'switch window' : 'keyboardOverlaySwitchWinKeyLabel', | 135 'switch window': 'keyboardOverlaySwitchWinKeyLabel', |
| 146 'bright down' : 'keyboardOverlayBrightDownKeyLabel', | 136 'bright down': 'keyboardOverlayBrightDownKeyLabel', |
| 147 'bright up' : 'keyboardOverlayBrightUpKeyLabel', | 137 'bright up': 'keyboardOverlayBrightUpKeyLabel', |
| 148 'mute' : 'keyboardOverlayMuteKeyLabel', | 138 'mute': 'keyboardOverlayMuteKeyLabel', |
| 149 'vol. down' : 'keyboardOverlayVolDownKeyLabel', | 139 'vol. down': 'keyboardOverlayVolDownKeyLabel', |
| 150 'vol. up' : 'keyboardOverlayVolUpKeyLabel', | 140 'vol. up': 'keyboardOverlayVolUpKeyLabel', |
| 151 'power' : 'keyboardOverlayPowerKeyLabel', | 141 'power': 'keyboardOverlayPowerKeyLabel', |
| 152 'backspace' : 'keyboardOverlayBackspaceKeyLabel', | 142 'backspace': 'keyboardOverlayBackspaceKeyLabel', |
| 153 'tab' : 'keyboardOverlayTabKeyLabel', | 143 'tab': 'keyboardOverlayTabKeyLabel', |
| 154 'search' : 'keyboardOverlaySearchKeyLabel', | 144 'search': 'keyboardOverlaySearchKeyLabel', |
| 155 'enter' : 'keyboardOverlayEnterKeyLabel', | 145 'enter': 'keyboardOverlayEnterKeyLabel', |
| 156 'shift' : 'keyboardOverlayShiftKeyLabel', | 146 'shift': 'keyboardOverlayShiftKeyLabel', |
| 157 'ctrl' : 'keyboardOverlayCtrlKeyLabel', | 147 'ctrl': 'keyboardOverlayCtrlKeyLabel', |
| 158 'alt' : 'keyboardOverlayAltKeyLabel', | 148 'alt': 'keyboardOverlayAltKeyLabel', |
| 159 'left' : 'keyboardOverlayLeftKeyLabel', | 149 'left': 'keyboardOverlayLeftKeyLabel', |
| 160 'right' : 'keyboardOverlayRightKeyLabel', | 150 'right': 'keyboardOverlayRightKeyLabel', |
| 161 'up' : 'keyboardOverlayUpKeyLabel', | 151 'up': 'keyboardOverlayUpKeyLabel', |
| 162 'down' : 'keyboardOverlayDownKeyLabel', | 152 'down': 'keyboardOverlayDownKeyLabel', |
| 163 'f1' : 'keyboardOverlayF1', | 153 'f1': 'keyboardOverlayF1', |
| 164 'f2' : 'keyboardOverlayF2', | 154 'f2': 'keyboardOverlayF2', |
| 165 'f3' : 'keyboardOverlayF3', | 155 'f3': 'keyboardOverlayF3', |
| 166 'f4' : 'keyboardOverlayF4', | 156 'f4': 'keyboardOverlayF4', |
| 167 'f5' : 'keyboardOverlayF5', | 157 'f5': 'keyboardOverlayF5', |
| 168 'f6' : 'keyboardOverlayF6', | 158 'f6': 'keyboardOverlayF6', |
| 169 'f7' : 'keyboardOverlayF7', | 159 'f7': 'keyboardOverlayF7', |
| 170 'f8' : 'keyboardOverlayF8', | 160 'f8': 'keyboardOverlayF8', |
| 171 'f9' : 'keyboardOverlayF9', | 161 'f9': 'keyboardOverlayF9', |
| 172 'f10' : 'keyboardOverlayF10', | 162 'f10': 'keyboardOverlayF10', |
| 173 }; | 163 }; |
| 174 | 164 |
| 175 var COMPOUND_ENTER_KEY_DATA = [815, 107, 60, 120]; | 165 var COMPOUND_ENTER_KEY_DATA = [815, 107, 60, 120]; |
| 176 var COMPOUND_ENTER_KEY_CLIP_PATH = | 166 var COMPOUND_ENTER_KEY_CLIP_PATH = |
| 177 'polygon(0% 0%, 100% 0%, 100% 100%, 28% 100%, 28% 47%, 0% 47%)'; | 167 'polygon(0% 0%, 100% 0%, 100% 100%, 28% 100%, 28% 47%, 0% 47%)'; |
| 178 var COMPOUND_ENTER_KEY_OVERLAY_DIV_CLIP_PATH = | 168 var COMPOUND_ENTER_KEY_OVERLAY_DIV_CLIP_PATH = |
| 179 'polygon(12% 0%, 100% 0%, 100% 97%, 12% 97%)'; | 169 'polygon(12% 0%, 100% 0%, 100% 97%, 12% 97%)'; |
| 180 | 170 |
| 181 var IME_ID_PREFIX = '_comp_ime_'; | 171 var IME_ID_PREFIX = '_comp_ime_'; |
| 182 var EXTENSION_ID_LEN = 32; | 172 var EXTENSION_ID_LEN = 32; |
| 183 | 173 |
| 184 var keyboardOverlayId = 'en_US'; | 174 var keyboardOverlayId = 'en_US'; |
| 185 var identifierMap = {}; | 175 var identifierMap = {}; |
| 186 | 176 |
| 187 /** | 177 /** |
| 188 * True after at least one keydown event has been received. | 178 * True after at least one keydown event has been received. |
| 189 */ | 179 */ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 function hex2char(hex) { | 260 function hex2char(hex) { |
| 271 if (!hex) { | 261 if (!hex) { |
| 272 return ''; | 262 return ''; |
| 273 } | 263 } |
| 274 var result = ''; | 264 var result = ''; |
| 275 var n = parseInt(hex, 16); | 265 var n = parseInt(hex, 16); |
| 276 if (n <= 0xFFFF) { | 266 if (n <= 0xFFFF) { |
| 277 result += String.fromCharCode(n); | 267 result += String.fromCharCode(n); |
| 278 } else if (n <= 0x10FFFF) { | 268 } else if (n <= 0x10FFFF) { |
| 279 n -= 0x10000; | 269 n -= 0x10000; |
| 280 result += (String.fromCharCode(0xD800 | (n >> 10)) + | 270 result += |
| 281 String.fromCharCode(0xDC00 | (n & 0x3FF))); | 271 (String.fromCharCode(0xD800 | (n >> 10)) + |
| 272 String.fromCharCode(0xDC00 | (n & 0x3FF))); |
| 282 } else { | 273 } else { |
| 283 console.error('hex2Char error: Code point out of range :' + hex); | 274 console.error('hex2Char error: Code point out of range :' + hex); |
| 284 } | 275 } |
| 285 return result; | 276 return result; |
| 286 } | 277 } |
| 287 | 278 |
| 288 /** | 279 /** |
| 289 * Returns a list of modifiers normalized to ignore the distinction between | 280 * Returns a list of modifiers normalized to ignore the distinction between |
| 290 * right or left keys. | 281 * right or left keys. |
| 291 * @param {Array} modifiers List of modifiers with distinction between right | 282 * @param {Array} modifiers List of modifiers with distinction between right |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 var side = (e.location == DOM_KEY_LOCATION_LEFT) ? 'L_' : 'R_'; | 335 var side = (e.location == DOM_KEY_LOCATION_LEFT) ? 'L_' : 'R_'; |
| 345 var isKeyDown = (e.type == 'keydown'); | 336 var isKeyDown = (e.type == 'keydown'); |
| 346 | 337 |
| 347 if (modifierWithKeyCode == 'SEARCH') { | 338 if (modifierWithKeyCode == 'SEARCH') { |
| 348 isPressed['SEARCH'] = isKeyDown; | 339 isPressed['SEARCH'] = isKeyDown; |
| 349 } else { | 340 } else { |
| 350 isPressed[side + modifierWithKeyCode] = isKeyDown; | 341 isPressed[side + modifierWithKeyCode] = isKeyDown; |
| 351 } | 342 } |
| 352 | 343 |
| 353 // make the result array | 344 // make the result array |
| 354 return result = ['L_SHIFT', 'R_SHIFT', 'L_CTRL', 'R_CTRL', 'L_ALT', 'R_ALT', | 345 return result = |
| 355 'SEARCH'].filter( | 346 [ |
| 356 function(modifier) { | 347 'L_SHIFT', 'R_SHIFT', 'L_CTRL', 'R_CTRL', 'L_ALT', 'R_ALT', |
| 357 return isPressed[modifier]; | 348 'SEARCH' |
| 358 }).sort(); | 349 ] |
| 350 .filter(function(modifier) { |
| 351 return isPressed[modifier]; |
| 352 }) |
| 353 .sort(); |
| 359 } | 354 } |
| 360 | 355 |
| 361 /** | 356 /** |
| 362 * Returns an ID of the key. | 357 * Returns an ID of the key. |
| 363 * @param {string} identifier Key identifier. | 358 * @param {string} identifier Key identifier. |
| 364 * @param {number} i Key number. | 359 * @param {number} i Key number. |
| 365 * @return {string} Key ID. | 360 * @return {string} Key ID. |
| 366 */ | 361 */ |
| 367 function keyId(identifier, i) { | 362 function keyId(identifier, i) { |
| 368 return identifier + '-key-' + i; | 363 return identifier + '-key-' + i; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 461 } |
| 467 var keyLabel = ''; | 462 var keyLabel = ''; |
| 468 for (var j = 1; j <= 9; j++) { | 463 for (var j = 1; j <= 9; j++) { |
| 469 var pos = keyData['p' + j]; | 464 var pos = keyData['p' + j]; |
| 470 if (!pos) { | 465 if (!pos) { |
| 471 continue; | 466 continue; |
| 472 } | 467 } |
| 473 keyLabel = hex2char(pos); | 468 keyLabel = hex2char(pos); |
| 474 if (!keyLabel) { | 469 if (!keyLabel) { |
| 475 continue; | 470 continue; |
| 476 } | 471 } |
| 477 if (isAscii(keyLabel) && | 472 if (isAscii(keyLabel) && |
| 478 getShortcutData()[getAction(keyLabel, modifiers)]) { | 473 getShortcutData()[getAction(keyLabel, modifiers)]) { |
| 479 break; | 474 break; |
| 480 } | 475 } |
| 481 } | 476 } |
| 482 return keyLabel; | 477 return keyLabel; |
| 483 } | 478 } |
| 484 | 479 |
| 485 /** | 480 /** |
| 486 * Returns a normalized string used for a key of shortcutData. | 481 * Returns a normalized string used for a key of shortcutData. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 517 |
| 523 // some key labels define actions such as 'mute' or 'vol. up'. Those actions | 518 // some key labels define actions such as 'mute' or 'vol. up'. Those actions |
| 524 // should be localized (crbug.com/471025). | 519 // should be localized (crbug.com/471025). |
| 525 var localizedLabelId = null; | 520 var localizedLabelId = null; |
| 526 var labelToBeLocalized = keyData.label; | 521 var labelToBeLocalized = keyData.label; |
| 527 if (topRowKeysAreFunctionKeys()) { | 522 if (topRowKeysAreFunctionKeys()) { |
| 528 // If this is a top row key label, we need to convert that label to | 523 // If this is a top row key label, we need to convert that label to |
| 529 // function-keys label (i.e. mute --> f8), and then use that label to get | 524 // function-keys label (i.e. mute --> f8), and then use that label to get |
| 530 // a localized one. | 525 // a localized one. |
| 531 var topRowKeyAsFunctionLabel = | 526 var topRowKeyAsFunctionLabel = |
| 532 TOP_ROW_KEY_LABEL_TO_FUNCTION_LABEL[labelToBeLocalized]; | 527 TOP_ROW_KEY_LABEL_TO_FUNCTION_LABEL[labelToBeLocalized]; |
| 533 | 528 |
| 534 labelToBeLocalized = | 529 labelToBeLocalized = |
| 535 topRowKeyAsFunctionLabel ? topRowKeyAsFunctionLabel : keyData.label; | 530 topRowKeyAsFunctionLabel ? topRowKeyAsFunctionLabel : keyData.label; |
| 536 } | 531 } |
| 537 | 532 |
| 538 localizedLabelId = LABEL_TO_LOCALIZED_LABEL_ID[labelToBeLocalized]; | 533 localizedLabelId = LABEL_TO_LOCALIZED_LABEL_ID[labelToBeLocalized]; |
| 539 | 534 |
| 540 if (localizedLabelId) | 535 if (localizedLabelId) |
| 541 return loadTimeData.getString(localizedLabelId); | 536 return loadTimeData.getString(localizedLabelId); |
| 542 | 537 |
| 543 return keyData.label; | 538 return keyData.label; |
| 544 } | 539 } |
| 545 | 540 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 562 function update(modifiers, normModifiers) { | 557 function update(modifiers, normModifiers) { |
| 563 var keyboardGlyphData = getKeyboardGlyphData(); | 558 var keyboardGlyphData = getKeyboardGlyphData(); |
| 564 var shortcutData = getShortcutData(); | 559 var shortcutData = getShortcutData(); |
| 565 var layout = getLayout(); | 560 var layout = getLayout(); |
| 566 for (var i = 0; i < layout.length; ++i) { | 561 for (var i = 0; i < layout.length; ++i) { |
| 567 var identifier = remapIdentifier(layout[i][0]); | 562 var identifier = remapIdentifier(layout[i][0]); |
| 568 var keyData = keyboardGlyphData.keys[identifier]; | 563 var keyData = keyboardGlyphData.keys[identifier]; |
| 569 var classes = getKeyClasses(identifier, modifiers, normModifiers); | 564 var classes = getKeyClasses(identifier, modifiers, normModifiers); |
| 570 var keyLabel = getKeyLabel(keyData, normModifiers); | 565 var keyLabel = getKeyLabel(keyData, normModifiers); |
| 571 var shortcutId = shortcutData[getAction(keyLabel, normModifiers)]; | 566 var shortcutId = shortcutData[getAction(keyLabel, normModifiers)]; |
| 572 if (modifiers.length == 0 && | 567 if (modifiers.length == 0 && (identifier == '2A' || identifier == '36')) { |
| 573 (identifier == '2A' || identifier == '36')) { | |
| 574 // Either the right or left shift keys are used to disable the caps lock | 568 // Either the right or left shift keys are used to disable the caps lock |
| 575 // if it was enabled. To fix crbug.com/453623. | 569 // if it was enabled. To fix crbug.com/453623. |
| 576 shortcutId = 'keyboardOverlayDisableCapsLock'; | 570 shortcutId = 'keyboardOverlayDisableCapsLock'; |
| 577 } | 571 } |
| 578 | 572 |
| 579 classes.push('keyboard-overlay-key-background'); | 573 classes.push('keyboard-overlay-key-background'); |
| 580 | 574 |
| 581 if (shortcutId == 'keyboardOverlayVoiceInteraction' && | 575 if (shortcutId == 'keyboardOverlayVoiceInteraction' && |
| 582 !isVoiceInteractionEnabled()) { | 576 !isVoiceInteractionEnabled()) { |
| 583 continue; | 577 continue; |
| 584 } | 578 } |
| 585 | 579 |
| 586 if (shortcutId) { | 580 if (shortcutId) { |
| 587 classes.push('is-shortcut'); | 581 classes.push('is-shortcut'); |
| 588 classes.push('keyboard-overlay-shortcut-key-background'); | 582 classes.push('keyboard-overlay-shortcut-key-background'); |
| 589 } | 583 } |
| 590 | 584 |
| 591 var key = $(keyId(identifier, i)); | 585 var key = $(keyId(identifier, i)); |
| 592 key.className = classes.join(' '); | 586 key.className = classes.join(' '); |
| 593 | 587 |
| 594 if (!keyData) { | 588 if (!keyData) { |
| 595 continue; | 589 continue; |
| 596 } | 590 } |
| 597 | 591 |
| 598 var keyText = $(keyTextId(identifier, i)); | 592 var keyText = $(keyTextId(identifier, i)); |
| 599 var keyTextValue = getKeyTextValue(keyData); | 593 var keyTextValue = getKeyTextValue(keyData); |
| 600 if (keyTextValue) { | 594 if (keyTextValue) { |
| 601 keyText.style.visibility = 'visible'; | 595 keyText.style.visibility = 'visible'; |
| 602 } else { | 596 } else { |
| 603 keyText.style.visibility = 'hidden'; | 597 keyText.style.visibility = 'hidden'; |
| 604 } | 598 } |
| 605 keyText.textContent = keyTextValue; | 599 keyText.textContent = keyTextValue; |
| 606 | 600 |
| 607 var shortcutText = $(shortcutTextId(identifier, i)); | 601 var shortcutText = $(shortcutTextId(identifier, i)); |
| 608 if (shortcutId) { | 602 if (shortcutId) { |
| 609 shortcutText.style.visibility = 'visible'; | 603 shortcutText.style.visibility = 'visible'; |
| 610 shortcutText.textContent = loadTimeData.getString(shortcutId); | 604 shortcutText.textContent = loadTimeData.getString(shortcutId); |
| 611 } else { | 605 } else { |
| 612 shortcutText.style.visibility = 'hidden'; | 606 shortcutText.style.visibility = 'hidden'; |
| 613 } | 607 } |
| 614 | 608 |
| 615 if (layout[i][1] == 'COMPOUND_ENTER_KEY') { | 609 if (layout[i][1] == 'COMPOUND_ENTER_KEY') { |
| 616 var overlayDivClasses = | 610 var overlayDivClasses = |
| 617 getKeyClasses(identifier, modifiers, normModifiers); | 611 getKeyClasses(identifier, modifiers, normModifiers); |
| 618 if (shortcutId) | 612 if (shortcutId) |
| 619 overlayDivClasses.push('is-shortcut'); | 613 overlayDivClasses.push('is-shortcut'); |
| 620 $(keyId(identifier, i) + '-sub').className = overlayDivClasses.join(' '); | 614 $(keyId(identifier, i) + '-sub').className = overlayDivClasses.join(' '); |
| 621 } | 615 } |
| 622 | 616 |
| 623 var format = keyboardGlyphData.keys[layout[i][0]].format; | 617 var format = keyboardGlyphData.keys[layout[i][0]].format; |
| 624 if (format) { | 618 if (format) { |
| 625 if (format == 'left' || format == 'right') { | 619 if (format == 'left' || format == 'right') { |
| 626 shortcutText.style.textAlign = format; | 620 shortcutText.style.textAlign = format; |
| 627 keyText.style.textAlign = format; | 621 keyText.style.textAlign = format; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 var overlayDivX = x - 3; | 774 var overlayDivX = x - 3; |
| 781 var overlayDivY = y + Math.round(h * 0.47) + 2; | 775 var overlayDivY = y + Math.round(h * 0.47) + 2; |
| 782 var overlayDivW = Math.round(w * 0.28); | 776 var overlayDivW = Math.round(w * 0.28); |
| 783 var overlayDivH = Math.round(h * (1 - 0.47)) + 1; | 777 var overlayDivH = Math.round(h * (1 - 0.47)) + 1; |
| 784 | 778 |
| 785 overlayDiv.style.left = overlayDivX + 'px'; | 779 overlayDiv.style.left = overlayDivX + 'px'; |
| 786 overlayDiv.style.top = overlayDivY + 'px'; | 780 overlayDiv.style.top = overlayDivY + 'px'; |
| 787 overlayDiv.style.width = overlayDivW + 'px'; | 781 overlayDiv.style.width = overlayDivW + 'px'; |
| 788 overlayDiv.style.height = overlayDivH + 'px'; | 782 overlayDiv.style.height = overlayDivH + 'px'; |
| 789 overlayDiv.style.webkitClipPath = | 783 overlayDiv.style.webkitClipPath = |
| 790 COMPOUND_ENTER_KEY_OVERLAY_DIV_CLIP_PATH; | 784 COMPOUND_ENTER_KEY_OVERLAY_DIV_CLIP_PATH; |
| 791 keyboard.appendChild(overlayDiv); | 785 keyboard.appendChild(overlayDiv); |
| 792 } | 786 } |
| 793 | 787 |
| 794 keyboard.appendChild(key); | 788 keyboard.appendChild(key); |
| 795 | 789 |
| 796 minX = Math.min(minX, x); | 790 minX = Math.min(minX, x); |
| 797 maxX = Math.max(maxX, x + w); | 791 maxX = Math.max(maxX, x + w); |
| 798 minY = Math.min(minY, y); | 792 minY = Math.min(minY, y); |
| 799 maxY = Math.max(maxY, y + h); | 793 maxY = Math.max(maxY, y + h); |
| 800 } | 794 } |
| 801 | 795 |
| 802 var width = maxX - minX + 1; | 796 var width = maxX - minX + 1; |
| 803 var height = maxY - minY + 1; | 797 var height = maxY - minY + 1; |
| 804 keyboard.style.width = (width + 2 * (minX + 1)) + 'px'; | 798 keyboard.style.width = (width + 2 * (minX + 1)) + 'px'; |
| 805 keyboard.style.height = (height + 2 * (minY + 1)) + 'px'; | 799 keyboard.style.height = (height + 2 * (minY + 1)) + 'px'; |
| 806 | 800 |
| 807 instructions.style.left = ((BASE_INSTRUCTIONS.left - BASE_KEYBOARD.left) * | 801 instructions.style.left = ((BASE_INSTRUCTIONS.left - BASE_KEYBOARD.left) * |
| 808 width / BASE_KEYBOARD.width + minX) + 'px'; | 802 width / BASE_KEYBOARD.width + |
| 803 minX) + |
| 804 'px'; |
| 809 instructions.style.top = ((BASE_INSTRUCTIONS.top - BASE_KEYBOARD.top) * | 805 instructions.style.top = ((BASE_INSTRUCTIONS.top - BASE_KEYBOARD.top) * |
| 810 height / BASE_KEYBOARD.height + minY) + 'px'; | 806 height / BASE_KEYBOARD.height + |
| 811 instructions.style.width = (width * BASE_INSTRUCTIONS.width / | 807 minY) + |
| 812 BASE_KEYBOARD.width) + 'px'; | 808 'px'; |
| 813 instructions.style.height = (height * BASE_INSTRUCTIONS.height / | 809 instructions.style.width = |
| 814 BASE_KEYBOARD.height) + 'px'; | 810 (width * BASE_INSTRUCTIONS.width / BASE_KEYBOARD.width) + 'px'; |
| 811 instructions.style.height = |
| 812 (height * BASE_INSTRUCTIONS.height / BASE_KEYBOARD.height) + 'px'; |
| 815 } | 813 } |
| 816 | 814 |
| 817 /** | 815 /** |
| 818 * Returns true if the device has a diamond key. | 816 * Returns true if the device has a diamond key. |
| 819 * @return {boolean} Returns true if the device has a diamond key. | 817 * @return {boolean} Returns true if the device has a diamond key. |
| 820 */ | 818 */ |
| 821 function hasDiamondKey() { | 819 function hasDiamondKey() { |
| 822 return loadTimeData.getBoolean('keyboardOverlayHasChromeOSDiamondKey'); | 820 return loadTimeData.getBoolean('keyboardOverlayHasChromeOSDiamondKey'); |
| 823 } | 821 } |
| 824 | 822 |
| 825 /** | 823 /** |
| 826 * Returns true if display scaling feature is enabled. | 824 * Returns true if display scaling feature is enabled. |
| 827 * @return {boolean} True if display scaling feature is enabled. | 825 * @return {boolean} True if display scaling feature is enabled. |
| 828 */ | 826 */ |
| 829 function isDisplayUIScalingEnabled() { | 827 function isDisplayUIScalingEnabled() { |
| 830 return loadTimeData.getBoolean('keyboardOverlayIsDisplayUIScalingEnabled'); | 828 return loadTimeData.getBoolean('keyboardOverlayIsDisplayUIScalingEnabled'); |
| 831 } | 829 } |
| 832 | 830 |
| 833 /** | 831 /** |
| 834 * Initializes the layout and the key labels for the keyboard that has a diamond | 832 * Initializes the layout and the key labels for the keyboard that has a diamond |
| 835 * key. | 833 * key. |
| 836 */ | 834 */ |
| 837 function initDiamondKey() { | 835 function initDiamondKey() { |
| 838 var newLayoutData = { | 836 var newLayoutData = { |
| 839 '1D': [65.0, 287.0, 60.0, 60.0], // left Ctrl | 837 '1D': [65.0, 287.0, 60.0, 60.0], // left Ctrl |
| 840 '38': [185.0, 287.0, 60.0, 60.0], // left Alt | 838 '38': [185.0, 287.0, 60.0, 60.0], // left Alt |
| 841 'E0 5B': [125.0, 287.0, 60.0, 60.0], // search | 839 'E0 5B': [125.0, 287.0, 60.0, 60.0], // search |
| 842 '3A': [5.0, 167.0, 105.0, 60.0], // caps lock | 840 '3A': [5.0, 167.0, 105.0, 60.0], // caps lock |
| 843 '5B': [803.0, 6.0, 72.0, 35.0], // lock key | 841 '5B': [803.0, 6.0, 72.0, 35.0], // lock key |
| 844 '5D': [5.0, 287.0, 60.0, 60.0] // diamond key | 842 '5D': [5.0, 287.0, 60.0, 60.0] // diamond key |
| 845 }; | 843 }; |
| 846 | 844 |
| 847 var layout = getLayout(); | 845 var layout = getLayout(); |
| 848 var powerKeyIndex = -1; | 846 var powerKeyIndex = -1; |
| 849 var powerKeyId = '00'; | 847 var powerKeyId = '00'; |
| 850 for (var i = 0; i < layout.length; i++) { | 848 for (var i = 0; i < layout.length; i++) { |
| 851 var keyId = layout[i][0]; | 849 var keyId = layout[i][0]; |
| 852 if (keyId in newLayoutData) { | 850 if (keyId in newLayoutData) { |
| 853 layout[i] = [keyId].concat(newLayoutData[keyId]); | 851 layout[i] = [keyId].concat(newLayoutData[keyId]); |
| 854 delete newLayoutData[keyId]; | 852 delete newLayoutData[keyId]; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 884 | 882 |
| 885 /** | 883 /** |
| 886 * Initializes the global map for remapping identifiers of modifier keys based | 884 * Initializes the global map for remapping identifiers of modifier keys based |
| 887 * on the preference. | 885 * on the preference. |
| 888 * Called after sending the 'getLabelMap' message. | 886 * Called after sending the 'getLabelMap' message. |
| 889 * @param {Object} remap Identifier map. | 887 * @param {Object} remap Identifier map. |
| 890 */ | 888 */ |
| 891 function initIdentifierMap(remap) { | 889 function initIdentifierMap(remap) { |
| 892 for (var key in remap) { | 890 for (var key in remap) { |
| 893 var val = remap[key]; | 891 var val = remap[key]; |
| 894 if ((key in LABEL_TO_IDENTIFIER) && | 892 if ((key in LABEL_TO_IDENTIFIER) && (val in LABEL_TO_IDENTIFIER)) { |
| 895 (val in LABEL_TO_IDENTIFIER)) { | 893 identifierMap[LABEL_TO_IDENTIFIER[key]] = LABEL_TO_IDENTIFIER[val]; |
| 896 identifierMap[LABEL_TO_IDENTIFIER[key]] = | |
| 897 LABEL_TO_IDENTIFIER[val]; | |
| 898 } else { | 894 } else { |
| 899 console.error('Invalid label map element: ' + key + ', ' + val); | 895 console.error('Invalid label map element: ' + key + ', ' + val); |
| 900 } | 896 } |
| 901 } | 897 } |
| 902 chrome.send('getInputMethodId'); | 898 chrome.send('getInputMethodId'); |
| 903 } | 899 } |
| 904 | 900 |
| 905 /** | 901 /** |
| 906 * Initializes the global keyboad overlay ID and the layout of keys. | 902 * Initializes the global keyboad overlay ID and the layout of keys. |
| 907 * Called after sending the 'getInputMethodId' message. | 903 * Called after sending the 'getInputMethodId' message. |
| 908 * @param {inputMethodId} inputMethodId Input Method Identifier. | 904 * @param {inputMethodId} inputMethodId Input Method Identifier. |
| 909 */ | 905 */ |
| 910 function initKeyboardOverlayId(inputMethodId) { | 906 function initKeyboardOverlayId(inputMethodId) { |
| 911 // Libcros returns an empty string when it cannot find the keyboard overlay ID | 907 // Libcros returns an empty string when it cannot find the keyboard overlay ID |
| 912 // corresponding to the current input method. | 908 // corresponding to the current input method. |
| 913 // In such a case, fallback to the default ID (en_US). | 909 // In such a case, fallback to the default ID (en_US). |
| 914 var inputMethodIdToOverlayId = | 910 var inputMethodIdToOverlayId = |
| 915 keyboardOverlayData['inputMethodIdToOverlayId']; | 911 keyboardOverlayData['inputMethodIdToOverlayId']; |
| 916 if (inputMethodId) { | 912 if (inputMethodId) { |
| 917 if (inputMethodId.startsWith(IME_ID_PREFIX)) { | 913 if (inputMethodId.startsWith(IME_ID_PREFIX)) { |
| 918 // If the input method is a component extension IME, remove the prefix: | 914 // If the input method is a component extension IME, remove the prefix: |
| 919 // _comp_ime_<ext_id> | 915 // _comp_ime_<ext_id> |
| 920 // The extension id is a hash value with 32 characters. | 916 // The extension id is a hash value with 32 characters. |
| 921 inputMethodId = inputMethodId.slice( | 917 inputMethodId = |
| 922 IME_ID_PREFIX.length + EXTENSION_ID_LEN); | 918 inputMethodId.slice(IME_ID_PREFIX.length + EXTENSION_ID_LEN); |
| 923 } | 919 } |
| 924 keyboardOverlayId = inputMethodIdToOverlayId[inputMethodId]; | 920 keyboardOverlayId = inputMethodIdToOverlayId[inputMethodId]; |
| 925 } | 921 } |
| 926 if (!keyboardOverlayId) { | 922 if (!keyboardOverlayId) { |
| 927 console.error('No keyboard overlay ID for ' + inputMethodId); | 923 console.error('No keyboard overlay ID for ' + inputMethodId); |
| 928 keyboardOverlayId = 'en_US'; | 924 keyboardOverlayId = 'en_US'; |
| 929 } | 925 } |
| 930 while (document.body.firstChild) { | 926 while (document.body.firstChild) { |
| 931 document.body.removeChild(document.body.firstChild); | 927 document.body.removeChild(document.body.firstChild); |
| 932 } | 928 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 957 function onWidgetShown() { | 953 function onWidgetShown() { |
| 958 setTimeout(function() { | 954 setTimeout(function() { |
| 959 // Show and focus the instructions div after a delay so that chrome vox | 955 // Show and focus the instructions div after a delay so that chrome vox |
| 960 // speaks it correctly. | 956 // speaks it correctly. |
| 961 $('instructions').style.visibility = 'visible'; | 957 $('instructions').style.visibility = 'visible'; |
| 962 $('instructions').focus(); | 958 $('instructions').focus(); |
| 963 }, 500); | 959 }, 500); |
| 964 } | 960 } |
| 965 | 961 |
| 966 document.addEventListener('DOMContentLoaded', init); | 962 document.addEventListener('DOMContentLoaded', init); |
| OLD | NEW |