| 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 <include src="keyboard_overlay_accessibility_helper.js"/> | 6 <include src="keyboard_overlay_accessibility_helper.js"/> |
| 7 | 7 |
| 8 var BASE_KEYBOARD = { | 8 var BASE_KEYBOARD = { |
| 9 top: 0, | 9 top: 0, |
| 10 left: 0, | 10 left: 0, |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 289 } |
| 290 } | 290 } |
| 291 return chars.join(' '); | 291 return chars.join(' '); |
| 292 } | 292 } |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * Updates the whole keyboard. | 295 * Updates the whole keyboard. |
| 296 * @param {Array} modifiers Key Modifier list. | 296 * @param {Array} modifiers Key Modifier list. |
| 297 */ | 297 */ |
| 298 function update(modifiers) { | 298 function update(modifiers) { |
| 299 var instructions = document.getElementById('instructions'); | 299 var instructions = $('instructions'); |
| 300 if (modifiers.length == 0) { | 300 if (modifiers.length == 0) { |
| 301 instructions.style.visibility = 'visible'; | 301 instructions.style.visibility = 'visible'; |
| 302 } else { | 302 } else { |
| 303 instructions.style.visibility = 'hidden'; | 303 instructions.style.visibility = 'hidden'; |
| 304 } | 304 } |
| 305 | 305 |
| 306 var keyboardGlyphData = getKeyboardGlyphData(); | 306 var keyboardGlyphData = getKeyboardGlyphData(); |
| 307 var shortcutData = getShortcutData(); | 307 var shortcutData = getShortcutData(); |
| 308 var layout = getLayouts()[keyboardGlyphData.layoutName]; | 308 var layout = getLayouts()[keyboardGlyphData.layoutName]; |
| 309 for (var i = 0; i < layout.length; ++i) { | 309 for (var i = 0; i < layout.length; ++i) { |
| 310 var identifier = remapIdentifier(layout[i][0]); | 310 var identifier = remapIdentifier(layout[i][0]); |
| 311 var keyData = keyboardGlyphData.keys[identifier]; | 311 var keyData = keyboardGlyphData.keys[identifier]; |
| 312 var classes = getKeyClasses(identifier, modifiers, keyData); | 312 var classes = getKeyClasses(identifier, modifiers, keyData); |
| 313 var keyLabel = getKeyLabel(keyData, modifiers); | 313 var keyLabel = getKeyLabel(keyData, modifiers); |
| 314 var shortcutId = shortcutData[getAction(keyLabel, modifiers)]; | 314 var shortcutId = shortcutData[getAction(keyLabel, modifiers)]; |
| 315 if (modifiers.length == 1 && modifiers[0] == 'SHIFT' && | 315 if (modifiers.length == 1 && modifiers[0] == 'SHIFT' && |
| 316 identifier == '2A') { | 316 identifier == '2A') { |
| 317 // Currently there is no way to identify whether the left shift or the | 317 // Currently there is no way to identify whether the left shift or the |
| 318 // right shift is preesed from the key event, so I assume the left shift | 318 // right shift is preesed from the key event, so I assume the left shift |
| 319 // key is pressed here and do not show keyboard shortcut description for | 319 // key is pressed here and do not show keyboard shortcut description for |
| 320 // 'Shift - Shift' (Toggle caps lock) on the left shift key, the | 320 // 'Shift - Shift' (Toggle caps lock) on the left shift key, the |
| 321 // identifier of which is '2A'. | 321 // identifier of which is '2A'. |
| 322 // TODO(mazda): Remove this workaround (http://crosbug.com/18047) | 322 // TODO(mazda): Remove this workaround (http://crosbug.com/18047) |
| 323 shortcutId = null; | 323 shortcutId = null; |
| 324 } | 324 } |
| 325 if (shortcutId) { | 325 if (shortcutId) { |
| 326 classes.push('is-shortcut'); | 326 classes.push('is-shortcut'); |
| 327 } | 327 } |
| 328 | 328 |
| 329 var key = document.getElementById(keyId(identifier, i)); | 329 var key = $(keyId(identifier, i)); |
| 330 key.className = classes.join(' '); | 330 key.className = classes.join(' '); |
| 331 | 331 |
| 332 if (!keyData) { | 332 if (!keyData) { |
| 333 continue; | 333 continue; |
| 334 } | 334 } |
| 335 | 335 |
| 336 var keyText = document.getElementById(keyTextId(identifier, i)); | 336 var keyText = $(keyTextId(identifier, i)); |
| 337 var keyTextValue = getKeyTextValue(keyData); | 337 var keyTextValue = getKeyTextValue(keyData); |
| 338 if (keyTextValue) { | 338 if (keyTextValue) { |
| 339 keyText.style.visibility = 'visible'; | 339 keyText.style.visibility = 'visible'; |
| 340 } else { | 340 } else { |
| 341 keyText.style.visibility = 'hidden'; | 341 keyText.style.visibility = 'hidden'; |
| 342 } | 342 } |
| 343 keyText.textContent = keyTextValue; | 343 keyText.textContent = keyTextValue; |
| 344 | 344 |
| 345 var shortcutText = document.getElementById(shortcutTextId(identifier, i)); | 345 var shortcutText = $(shortcutTextId(identifier, i)); |
| 346 if (shortcutId) { | 346 if (shortcutId) { |
| 347 shortcutText.style.visibility = 'visible'; | 347 shortcutText.style.visibility = 'visible'; |
| 348 shortcutText.textContent = templateData[shortcutId]; | 348 shortcutText.textContent = loadTimeData.getString('shortcutId'); |
| 349 } else { | 349 } else { |
| 350 shortcutText.style.visibility = 'hidden'; | 350 shortcutText.style.visibility = 'hidden'; |
| 351 } | 351 } |
| 352 | 352 |
| 353 if (keyData.format) { | 353 if (keyData.format) { |
| 354 var format = keyData.format; | 354 var format = keyData.format; |
| 355 if (format == 'left' || format == 'right') { | 355 if (format == 'left' || format == 'right') { |
| 356 shortcutText.style.textAlign = format; | 356 shortcutText.style.textAlign = format; |
| 357 keyText.style.textAlign = format; | 357 keyText.style.textAlign = format; |
| 358 } | 358 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 instructions.style.top = ((BASE_INSTRUCTIONS.top - BASE_KEYBOARD.top) * | 443 instructions.style.top = ((BASE_INSTRUCTIONS.top - BASE_KEYBOARD.top) * |
| 444 height / BASE_KEYBOARD.height + minY) + 'px'; | 444 height / BASE_KEYBOARD.height + minY) + 'px'; |
| 445 instructions.style.width = (width * BASE_INSTRUCTIONS.width / | 445 instructions.style.width = (width * BASE_INSTRUCTIONS.width / |
| 446 BASE_KEYBOARD.width) + 'px'; | 446 BASE_KEYBOARD.width) + 'px'; |
| 447 instructions.style.height = (height * BASE_INSTRUCTIONS.height / | 447 instructions.style.height = (height * BASE_INSTRUCTIONS.height / |
| 448 BASE_KEYBOARD.height) + 'px'; | 448 BASE_KEYBOARD.height) + 'px'; |
| 449 | 449 |
| 450 var instructionsText = document.createElement('div'); | 450 var instructionsText = document.createElement('div'); |
| 451 instructionsText.id = 'instructions-text'; | 451 instructionsText.id = 'instructions-text'; |
| 452 instructionsText.className = 'keyboard-overlay-instructions-text'; | 452 instructionsText.className = 'keyboard-overlay-instructions-text'; |
| 453 instructionsText.innerHTML = templateData.keyboardOverlayInstructions; | 453 instructionsText.innerHTML = |
| 454 loadTimeData.getString('keyboardOverlayInstructions'); |
| 454 instructions.appendChild(instructionsText); | 455 instructions.appendChild(instructionsText); |
| 455 var instructionsHideText = document.createElement('div'); | 456 var instructionsHideText = document.createElement('div'); |
| 456 instructionsHideText.id = 'instructions-hide-text'; | 457 instructionsHideText.id = 'instructions-hide-text'; |
| 457 instructionsHideText.className = 'keyboard-overlay-instructions-hide-text'; | 458 instructionsHideText.className = 'keyboard-overlay-instructions-hide-text'; |
| 458 instructionsHideText.innerHTML = templateData.keyboardOverlayInstructionsHide; | 459 instructionsHideText.innerHTML = |
| 460 loadTimeData.getString('keyboardOverlayInstructionsHide'); |
| 459 instructions.appendChild(instructionsHideText); | 461 instructions.appendChild(instructionsHideText); |
| 460 var learnMoreLinkText = document.createElement('div'); | 462 var learnMoreLinkText = document.createElement('div'); |
| 461 learnMoreLinkText.id = 'learn-more-text'; | 463 learnMoreLinkText.id = 'learn-more-text'; |
| 462 learnMoreLinkText.className = 'keyboard-overlay-learn-more-text'; | 464 learnMoreLinkText.className = 'keyboard-overlay-learn-more-text'; |
| 463 learnMoreLinkText.addEventListener('click', learnMoreClicked); | 465 learnMoreLinkText.addEventListener('click', learnMoreClicked); |
| 464 var learnMoreLinkAnchor = document.createElement('a'); | 466 var learnMoreLinkAnchor = document.createElement('a'); |
| 465 learnMoreLinkAnchor.href = templateData.keyboardOverlayLearnMoreURL; | 467 learnMoreLinkAnchor.href = |
| 466 learnMoreLinkAnchor.textContent = templateData.keyboardOverlayLearnMore; | 468 loadTimeData.getString('keyboardOverlayLearnMoreURL'); |
| 469 learnMoreLinkAnchor.textContent = |
| 470 loadTimeData.getString('keyboardOverlayLearnMore'); |
| 467 learnMoreLinkText.appendChild(learnMoreLinkAnchor); | 471 learnMoreLinkText.appendChild(learnMoreLinkAnchor); |
| 468 instructions.appendChild(learnMoreLinkText); | 472 instructions.appendChild(learnMoreLinkText); |
| 469 keyboard.appendChild(instructions); | 473 keyboard.appendChild(instructions); |
| 470 } | 474 } |
| 471 | 475 |
| 472 /** | 476 /** |
| 473 * A callback function for the onload event of the body element. | 477 * A callback function for the onload event of the body element. |
| 474 */ | 478 */ |
| 475 function init() { | 479 function init() { |
| 476 document.addEventListener('keydown', handleKeyEvent); | 480 document.addEventListener('keydown', handleKeyEvent); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 * Handles click events of the learn more link. | 531 * Handles click events of the learn more link. |
| 528 * @param {Event} e Mouse click event. | 532 * @param {Event} e Mouse click event. |
| 529 */ | 533 */ |
| 530 function learnMoreClicked(e) { | 534 function learnMoreClicked(e) { |
| 531 chrome.send('openLearnMorePage'); | 535 chrome.send('openLearnMorePage'); |
| 532 chrome.send('DialogClose'); | 536 chrome.send('DialogClose'); |
| 533 e.preventDefault(); | 537 e.preventDefault(); |
| 534 } | 538 } |
| 535 | 539 |
| 536 document.addEventListener('DOMContentLoaded', init); | 540 document.addEventListener('DOMContentLoaded', init); |
| OLD | NEW |