| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 5 /** |
| 6 * @fileoverview Assertion support. | 6 * @fileoverview Assertion support. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Verify |condition| is truthy and return |condition| if so. | 10 * Verify |condition| is truthy and return |condition| if so. |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 | 832 |
| 833 /** | 833 /** |
| 834 * This is used to identify keyboard shortcuts. | 834 * This is used to identify keyboard shortcuts. |
| 835 * @param {string} shortcut The text used to describe the keys for this | 835 * @param {string} shortcut The text used to describe the keys for this |
| 836 * keyboard shortcut. | 836 * keyboard shortcut. |
| 837 * @constructor | 837 * @constructor |
| 838 */ | 838 */ |
| 839 function KeyboardShortcut(shortcut) { | 839 function KeyboardShortcut(shortcut) { |
| 840 var mods = {}; | 840 var mods = {}; |
| 841 var ident = ''; | 841 var ident = ''; |
| 842 shortcut.split('-').forEach(function(part) { | 842 shortcut.split('|').forEach(function(part) { |
| 843 var partLc = part.toLowerCase(); | 843 var partLc = part.toLowerCase(); |
| 844 switch (partLc) { | 844 switch (partLc) { |
| 845 case 'alt': | 845 case 'alt': |
| 846 case 'ctrl': | 846 case 'ctrl': |
| 847 case 'meta': | 847 case 'meta': |
| 848 case 'shift': | 848 case 'shift': |
| 849 mods[partLc + 'Key'] = true; | 849 mods[partLc + 'Key'] = true; |
| 850 break; | 850 break; |
| 851 default: | 851 default: |
| 852 if (ident) | 852 if (ident) |
| 853 throw Error('Invalid shortcut'); | 853 throw Error('Invalid shortcut'); |
| 854 ident = part; | 854 ident = part; |
| 855 } | 855 } |
| 856 }); | 856 }); |
| 857 | 857 |
| 858 this.ident_ = ident; | 858 this.ident_ = ident; |
| 859 this.mods_ = mods; | 859 this.mods_ = mods; |
| 860 } | 860 } |
| 861 | 861 |
| 862 KeyboardShortcut.prototype = { | 862 KeyboardShortcut.prototype = { |
| 863 /** | 863 /** |
| 864 * Whether the keyboard shortcut object matches a keyboard event. | 864 * Whether the keyboard shortcut object matches a keyboard event. |
| 865 * @param {!Event} e The keyboard event object. | 865 * @param {!Event} e The keyboard event object. |
| 866 * @return {boolean} Whether we found a match or not. | 866 * @return {boolean} Whether we found a match or not. |
| 867 */ | 867 */ |
| 868 matchesEvent: function(e) { | 868 matchesEvent: function(e) { |
| 869 if (e.keyIdentifier == this.ident_) { | 869 if (e.key == this.ident_) { |
| 870 // All keyboard modifiers needs to match. | 870 // All keyboard modifiers needs to match. |
| 871 var mods = this.mods_; | 871 var mods = this.mods_; |
| 872 return ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].every(function(k) { | 872 return ['altKey', 'ctrlKey', 'metaKey', 'shiftKey'].every(function(k) { |
| 873 return e[k] == !!mods[k]; | 873 return e[k] == !!mods[k]; |
| 874 }); | 874 }); |
| 875 } | 875 } |
| 876 return false; | 876 return false; |
| 877 } | 877 } |
| 878 }; | 878 }; |
| 879 | 879 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 * command can be executed or not. | 920 * command can be executed or not. |
| 921 * @param {Node=} opt_node Node for which to actuate command state. | 921 * @param {Node=} opt_node Node for which to actuate command state. |
| 922 */ | 922 */ |
| 923 canExecuteChange: function(opt_node) { | 923 canExecuteChange: function(opt_node) { |
| 924 dispatchCanExecuteEvent(this, | 924 dispatchCanExecuteEvent(this, |
| 925 opt_node || this.ownerDocument.activeElement); | 925 opt_node || this.ownerDocument.activeElement); |
| 926 }, | 926 }, |
| 927 | 927 |
| 928 /** | 928 /** |
| 929 * The keyboard shortcut that triggers the command. This is a string | 929 * The keyboard shortcut that triggers the command. This is a string |
| 930 * consisting of a keyIdentifier (as reported by WebKit in keydown) as | 930 * consisting of a key (as reported by WebKit in keydown) as |
| 931 * well as optional key modifiers joinded with a '-'. | 931 * well as optional key modifiers joinded with a '|'. |
| 932 * | 932 * |
| 933 * Multiple keyboard shortcuts can be provided by separating them by | 933 * Multiple keyboard shortcuts can be provided by separating them by |
| 934 * whitespace. | 934 * whitespace. |
| 935 * | 935 * |
| 936 * For example: | 936 * For example: |
| 937 * "F1" | 937 * "F1" |
| 938 * "U+0008-Meta" for Apple command backspace. | 938 * "Backspace-Meta" for Apple command backspace. |
| 939 * "U+0041-Ctrl" for Control A | 939 * "a-Ctrl" for Control A |
| 940 * "U+007F U+0008-Meta" for Delete and Command Backspace | 940 * "Delete Backspace-Meta" for Delete and Command Backspace |
| 941 * | 941 * |
| 942 * @type {string} | 942 * @type {string} |
| 943 */ | 943 */ |
| 944 shortcut_: '', | 944 shortcut_: '', |
| 945 get shortcut() { | 945 get shortcut() { |
| 946 return this.shortcut_; | 946 return this.shortcut_; |
| 947 }, | 947 }, |
| 948 set shortcut(shortcut) { | 948 set shortcut(shortcut) { |
| 949 var oldShortcut = this.shortcut_; | 949 var oldShortcut = this.shortcut_; |
| 950 if (shortcut !== oldShortcut) { | 950 if (shortcut !== oldShortcut) { |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 var KEY_IDENTIFIER = { | 1707 var KEY_IDENTIFIER = { |
| 1708 'U+0008': 'backspace', | 1708 'U+0008': 'backspace', |
| 1709 'U+0009': 'tab', | 1709 'U+0009': 'tab', |
| 1710 'U+001B': 'esc', | 1710 'U+001B': 'esc', |
| 1711 'U+0020': 'space', | 1711 'U+0020': 'space', |
| 1712 'U+007F': 'del' | 1712 'U+007F': 'del' |
| 1713 }; | 1713 }; |
| 1714 | 1714 |
| 1715 /** | 1715 /** |
| 1716 * Special table for KeyboardEvent.keyCode. | 1716 * Special table for KeyboardEvent.keyCode. |
| 1717 * KeyboardEvent.keyIdentifier is better, and KeyBoardEvent.key is even bett
er | 1717 * KeyBoardEvent.key is even better than that. |
| 1718 * than that. | |
| 1719 * | 1718 * |
| 1720 * Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve
nt.keyCode#Value_of_keyCode | 1719 * Values from: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEve
nt.keyCode#Value_of_keyCode |
| 1721 */ | 1720 */ |
| 1722 var KEY_CODE = { | 1721 var KEY_CODE = { |
| 1723 8: 'backspace', | 1722 8: 'backspace', |
| 1724 9: 'tab', | 1723 9: 'tab', |
| 1725 13: 'enter', | 1724 13: 'enter', |
| 1726 27: 'esc', | 1725 27: 'esc', |
| 1727 33: 'pageup', | 1726 33: 'pageup', |
| 1728 34: 'pagedown', | 1727 34: 'pagedown', |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1752 /** | 1751 /** |
| 1753 * KeyboardEvent.key is mostly represented by printable character made by | 1752 * KeyboardEvent.key is mostly represented by printable character made by |
| 1754 * the keyboard, with unprintable keys labeled nicely. | 1753 * the keyboard, with unprintable keys labeled nicely. |
| 1755 * | 1754 * |
| 1756 * However, on OS X, Alt+char can make a Unicode character that follows an | 1755 * However, on OS X, Alt+char can make a Unicode character that follows an |
| 1757 * Apple-specific mapping. In this case, we fall back to .keyCode. | 1756 * Apple-specific mapping. In this case, we fall back to .keyCode. |
| 1758 */ | 1757 */ |
| 1759 var KEY_CHAR = /[a-z0-9*]/; | 1758 var KEY_CHAR = /[a-z0-9*]/; |
| 1760 | 1759 |
| 1761 /** | 1760 /** |
| 1762 * Matches a keyIdentifier string. | |
| 1763 */ | |
| 1764 var IDENT_CHAR = /U\+/; | |
| 1765 | |
| 1766 /** | |
| 1767 * Matches arrow keys in Gecko 27.0+ | 1761 * Matches arrow keys in Gecko 27.0+ |
| 1768 */ | 1762 */ |
| 1769 var ARROW_KEY = /^arrow/; | 1763 var ARROW_KEY = /^arrow/; |
| 1770 | 1764 |
| 1771 /** | 1765 /** |
| 1772 * Matches space keys everywhere (notably including IE10's exceptional name | 1766 * Matches space keys everywhere (notably including IE10's exceptional name |
| 1773 * `spacebar`). | 1767 * `spacebar`). |
| 1774 */ | 1768 */ |
| 1775 var SPACE_KEY = /^space(bar)?/; | 1769 var SPACE_KEY = /^space(bar)?/; |
| 1776 | 1770 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1804 } else if (lKey == 'multiply') { | 1798 } else if (lKey == 'multiply') { |
| 1805 // numpad '*' can map to Multiply on IE/Windows | 1799 // numpad '*' can map to Multiply on IE/Windows |
| 1806 validKey = '*'; | 1800 validKey = '*'; |
| 1807 } else { | 1801 } else { |
| 1808 validKey = lKey; | 1802 validKey = lKey; |
| 1809 } | 1803 } |
| 1810 } | 1804 } |
| 1811 return validKey; | 1805 return validKey; |
| 1812 } | 1806 } |
| 1813 | 1807 |
| 1814 function transformKeyIdentifier(keyIdent) { | |
| 1815 var validKey = ''; | |
| 1816 if (keyIdent) { | |
| 1817 if (keyIdent in KEY_IDENTIFIER) { | |
| 1818 validKey = KEY_IDENTIFIER[keyIdent]; | |
| 1819 } else if (IDENT_CHAR.test(keyIdent)) { | |
| 1820 keyIdent = parseInt(keyIdent.replace('U+', '0x'), 16); | |
| 1821 validKey = String.fromCharCode(keyIdent).toLowerCase(); | |
| 1822 } else { | |
| 1823 validKey = keyIdent.toLowerCase(); | |
| 1824 } | |
| 1825 } | |
| 1826 return validKey; | |
| 1827 } | |
| 1828 | |
| 1829 function transformKeyCode(keyCode) { | 1808 function transformKeyCode(keyCode) { |
| 1830 var validKey = ''; | 1809 var validKey = ''; |
| 1831 if (Number(keyCode)) { | 1810 if (Number(keyCode)) { |
| 1832 if (keyCode >= 65 && keyCode <= 90) { | 1811 if (keyCode >= 65 && keyCode <= 90) { |
| 1833 // ascii a-z | 1812 // ascii a-z |
| 1834 // lowercase is 32 offset from uppercase | 1813 // lowercase is 32 offset from uppercase |
| 1835 validKey = String.fromCharCode(32 + keyCode); | 1814 validKey = String.fromCharCode(32 + keyCode); |
| 1836 } else if (keyCode >= 112 && keyCode <= 123) { | 1815 } else if (keyCode >= 112 && keyCode <= 123) { |
| 1837 // function keys f1-f12 | 1816 // function keys f1-f12 |
| 1838 validKey = 'f' + (keyCode - 112); | 1817 validKey = 'f' + (keyCode - 112); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1853 * Calculates the normalized key for a KeyboardEvent. | 1832 * Calculates the normalized key for a KeyboardEvent. |
| 1854 * @param {KeyboardEvent} keyEvent | 1833 * @param {KeyboardEvent} keyEvent |
| 1855 * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key | 1834 * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key |
| 1856 * transformation to alpha-numeric chars. This is useful with key | 1835 * transformation to alpha-numeric chars. This is useful with key |
| 1857 * combinations like shift + 2, which on FF for MacOS produces | 1836 * combinations like shift + 2, which on FF for MacOS produces |
| 1858 * keyEvent.key = @ | 1837 * keyEvent.key = @ |
| 1859 * To get 2 returned, set noSpecialChars = true | 1838 * To get 2 returned, set noSpecialChars = true |
| 1860 * To get @ returned, set noSpecialChars = false | 1839 * To get @ returned, set noSpecialChars = false |
| 1861 */ | 1840 */ |
| 1862 function normalizedKeyForEvent(keyEvent, noSpecialChars) { | 1841 function normalizedKeyForEvent(keyEvent, noSpecialChars) { |
| 1863 // Fall back from .key, to .keyIdentifier, to .keyCode, and then to | 1842 // Fall back from .key, to .keyCode, and then to |
| 1864 // .detail.key to support artificial keyboard events. | 1843 // .detail.key to support artificial keyboard events. |
| 1865 return transformKey(keyEvent.key, noSpecialChars) || | 1844 return transformKey(keyEvent.key, noSpecialChars) || |
| 1866 transformKeyIdentifier(keyEvent.keyIdentifier) || | |
| 1867 transformKeyCode(keyEvent.keyCode) || | 1845 transformKeyCode(keyEvent.keyCode) || |
| 1868 transformKey(keyEvent.detail ? keyEvent.detail.key : keyEvent.detail, no
SpecialChars) || ''; | 1846 transformKey(keyEvent.detail ? keyEvent.detail.key : keyEvent.detail, no
SpecialChars) || ''; |
| 1869 } | 1847 } |
| 1870 | 1848 |
| 1871 function keyComboMatchesEvent(keyCombo, event) { | 1849 function keyComboMatchesEvent(keyCombo, event) { |
| 1872 // For combos with modifiers we support only alpha-numeric keys | 1850 // For combos with modifiers we support only alpha-numeric keys |
| 1873 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); | 1851 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); |
| 1874 return keyEvent === keyCombo.key && | 1852 return keyEvent === keyCombo.key && |
| 1875 (!keyCombo.hasModifiers || ( | 1853 (!keyCombo.hasModifiers || ( |
| 1876 !!event.shiftKey === !!keyCombo.shiftKey && | 1854 !!event.shiftKey === !!keyCombo.shiftKey && |
| (...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4171 | 4149 |
| 4172 /** @this {ActionLink} */ | 4150 /** @this {ActionLink} */ |
| 4173 createdCallback: function() { | 4151 createdCallback: function() { |
| 4174 // Action links can start disabled (e.g. <a is="action-link" disabled>). | 4152 // Action links can start disabled (e.g. <a is="action-link" disabled>). |
| 4175 this.tabIndex = this.disabled ? -1 : 0; | 4153 this.tabIndex = this.disabled ? -1 : 0; |
| 4176 | 4154 |
| 4177 if (!this.hasAttribute('role')) | 4155 if (!this.hasAttribute('role')) |
| 4178 this.setAttribute('role', 'link'); | 4156 this.setAttribute('role', 'link'); |
| 4179 | 4157 |
| 4180 this.addEventListener('keydown', function(e) { | 4158 this.addEventListener('keydown', function(e) { |
| 4181 if (!this.disabled && e.keyIdentifier == 'Enter' && !this.href) { | 4159 if (!this.disabled && e.key == 'Enter' && !this.href) { |
| 4182 // Schedule a click asynchronously because other 'keydown' handlers | 4160 // Schedule a click asynchronously because other 'keydown' handlers |
| 4183 // may still run later (e.g. document.addEventListener('keydown')). | 4161 // may still run later (e.g. document.addEventListener('keydown')). |
| 4184 // Specifically options dialogs break when this timeout isn't here. | 4162 // Specifically options dialogs break when this timeout isn't here. |
| 4185 // NOTE: this affects the "trusted" state of the ensuing click. I | 4163 // NOTE: this affects the "trusted" state of the ensuing click. I |
| 4186 // haven't found anything that breaks because of this (yet). | 4164 // haven't found anything that breaks because of this (yet). |
| 4187 window.setTimeout(this.click.bind(this), 0); | 4165 window.setTimeout(this.click.bind(this), 0); |
| 4188 } | 4166 } |
| 4189 }); | 4167 }); |
| 4190 | 4168 |
| 4191 function preventDefault(e) { | 4169 function preventDefault(e) { |
| (...skipping 7347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11539 Manager.updateItem = function(index, data) { | 11517 Manager.updateItem = function(index, data) { |
| 11540 Manager.get().updateItem_(index, data); | 11518 Manager.get().updateItem_(index, data); |
| 11541 }; | 11519 }; |
| 11542 | 11520 |
| 11543 return {Manager: Manager}; | 11521 return {Manager: Manager}; |
| 11544 }); | 11522 }); |
| 11545 // Copyright 2015 The Chromium Authors. All rights reserved. | 11523 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 11546 // Use of this source code is governed by a BSD-style license that can be | 11524 // Use of this source code is governed by a BSD-style license that can be |
| 11547 // found in the LICENSE file. | 11525 // found in the LICENSE file. |
| 11548 | 11526 |
| 11549 window.addEventListener('load', downloads.Manager.onLoad); | 11527 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |