| 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 /** | 5 /** |
| 6 * @fileoverview Provides dialog-like behaviors for the tracing UI. | 6 * @fileoverview Provides dialog-like behaviors for the tracing UI. |
| 7 */ | 7 */ |
| 8 cr.define('cr.ui.overlay', function() { | 8 cr.define('cr.ui.overlay', function() { |
| 9 /** | 9 /** |
| 10 * Gets the top, visible overlay. It makes the assumption that if multiple | 10 * Gets the top, visible overlay. It makes the assumption that if multiple |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 * Makes initializations which must hook at the document level. | 43 * Makes initializations which must hook at the document level. |
| 44 */ | 44 */ |
| 45 function globalInitialization() { | 45 function globalInitialization() { |
| 46 if (!globallyInitialized) { | 46 if (!globallyInitialized) { |
| 47 document.addEventListener('keydown', function(e) { | 47 document.addEventListener('keydown', function(e) { |
| 48 var overlay = getTopOverlay(); | 48 var overlay = getTopOverlay(); |
| 49 if (!overlay) | 49 if (!overlay) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 // Close the overlay on escape. | 52 // Close the overlay on escape. |
| 53 if (e.keyIdentifier == 'U+001B') | 53 if (e.key == 'Escape') |
| 54 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); | 54 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); |
| 55 | 55 |
| 56 // Execute the overlay's default button on enter, unless focus is on an | 56 // Execute the overlay's default button on enter, unless focus is on an |
| 57 // element that has standard behavior for the enter key. | 57 // element that has standard behavior for the enter key. |
| 58 var forbiddenTagNames = /^(A|BUTTON|SELECT|TEXTAREA)$/; | 58 var forbiddenTagNames = /^(A|BUTTON|SELECT|TEXTAREA)$/; |
| 59 if (e.keyIdentifier == 'Enter' && | 59 if (e.key == 'Enter' && |
| 60 !forbiddenTagNames.test(document.activeElement.tagName)) { | 60 !forbiddenTagNames.test(document.activeElement.tagName)) { |
| 61 var button = getDefaultButton(overlay); | 61 var button = getDefaultButton(overlay); |
| 62 if (button) { | 62 if (button) { |
| 63 button.click(); | 63 button.click(); |
| 64 // Executing the default button may result in focus moving to a | 64 // Executing the default button may result in focus moving to a |
| 65 // different button. Calling preventDefault is necessary to not have | 65 // different button. Calling preventDefault is necessary to not have |
| 66 // that button execute as well. | 66 // that button execute as well. |
| 67 e.preventDefault(); | 67 e.preventDefault(); |
| 68 } | 68 } |
| 69 } | 69 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 e.target.classList.remove('pulse'); | 131 e.target.classList.remove('pulse'); |
| 132 }); | 132 }); |
| 133 } | 133 } |
| 134 | 134 |
| 135 return { | 135 return { |
| 136 getDefaultButton: getDefaultButton, | 136 getDefaultButton: getDefaultButton, |
| 137 globalInitialization: globalInitialization, | 137 globalInitialization: globalInitialization, |
| 138 setupOverlay: setupOverlay, | 138 setupOverlay: setupOverlay, |
| 139 }; | 139 }; |
| 140 }); | 140 }); |
| OLD | NEW |