| 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 /** | 10 /** |
| 11 * Gets the top, visible overlay. It makes the assumption that if multiple | 11 * Gets the top, visible overlay. It makes the assumption that if multiple |
| 12 * overlays are visible, the last in the byte order is topmost. | 12 * overlays are visible, the last in the byte order is topmost. |
| 13 * TODO(estade): rely on aria-visibility instead? | 13 * TODO(estade): rely on aria-visibility instead? |
| 14 * @return {HTMLElement} The overlay. | 14 * @return {HTMLElement} The overlay. |
| 15 */ | 15 */ |
| 16 function getTopOverlay() { | 16 function getTopOverlay() { |
| 17 var overlays = document.querySelectorAll('.overlay:not([hidden])'); | 17 var overlays = document.querySelectorAll('.overlay:not([hidden])'); |
| 18 return overlays[overlays.length - 1]; | 18 return overlays[overlays.length - 1]; |
| 19 } | 19 } |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Makes initializations which must hook at the document level. | 22 * Makes initializations which must hook at the document level. |
| 23 */ | 23 */ |
| 24 function globalInitialization() { | 24 function globalInitialization() { |
| 25 // Listen to focus events and make sure focus doesn't move outside of a | |
| 26 // visible overlay .page. | |
| 27 document.addEventListener('focus', function(e) { | |
| 28 // Only run this event handler if there is no FocusManager. | |
| 29 // TODO(khorimoto): Remove this function once FocusManager can be used | |
| 30 // to manage focus on other pages besides the Settings page. | |
| 31 // (https://code.google.com/p/chromium/issues/detail?id=127681) | |
| 32 var focusManagerExists = options && options.OptionsFocusManager; | |
| 33 if (focusManagerExists) | |
| 34 return; | |
| 35 | |
| 36 var overlay = getTopOverlay(); | |
| 37 var page = overlay ? overlay.querySelector('.page:not([hidden])') : null; | |
| 38 if (!page || page.contains(e.target)) | |
| 39 return; | |
| 40 | |
| 41 var focusElement = page.querySelector('button, input, list, select, a'); | |
| 42 if (focusElement) | |
| 43 focusElement.focus(); | |
| 44 }, true); | |
| 45 | |
| 46 // Close the overlay on escape. | 25 // Close the overlay on escape. |
| 47 document.addEventListener('keydown', function(e) { | 26 document.addEventListener('keydown', function(e) { |
| 48 if (e.keyCode == 27) { // Escape | 27 if (e.keyCode == 27) { // Escape |
| 49 var overlay = getTopOverlay(); | 28 var overlay = getTopOverlay(); |
| 50 if (!overlay) | 29 if (!overlay) |
| 51 return; | 30 return; |
| 52 | 31 |
| 53 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); | 32 cr.dispatchSimpleEvent(overlay, 'cancelOverlay'); |
| 54 } | 33 } |
| 55 }); | 34 }); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 92 } |
| 114 | 93 |
| 115 return { | 94 return { |
| 116 globalInitialization: globalInitialization, | 95 globalInitialization: globalInitialization, |
| 117 setupOverlay: setupOverlay, | 96 setupOverlay: setupOverlay, |
| 118 }; | 97 }; |
| 119 }); | 98 }); |
| 120 | 99 |
| 121 document.addEventListener('DOMContentLoaded', | 100 document.addEventListener('DOMContentLoaded', |
| 122 cr.ui.overlay.globalInitialization); | 101 cr.ui.overlay.globalInitialization); |
| OLD | NEW |