| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 UI.Dialog = class extends UI.GlassPane { | 31 UI.Dialog = class extends UI.GlassPane { |
| 32 constructor() { | 32 constructor() { |
| 33 super(); | 33 super(); |
| 34 this.registerRequiredCSS('ui/dialog.css'); | 34 this.registerRequiredCSS('ui/dialog.css'); |
| 35 this.contentElement.tabIndex = 0; | 35 this.contentElement.tabIndex = 0; |
| 36 this.contentElement.addEventListener('focus', this.focus.bind(this), false); | 36 this.contentElement.addEventListener('focus', () => this.widget().focus(), f
alse); |
| 37 this.contentElement.addEventListener('keydown', this._onKeyDown.bind(this),
false); | 37 this.contentElement.addEventListener('keydown', this._onKeyDown.bind(this),
false); |
| 38 this.setBlockPointerEvents(true); | 38 this.setBlockPointerEvents(true); |
| 39 this.setSetOutsideClickCallback(event => { | 39 this.setSetOutsideClickCallback(event => { |
| 40 this.hideDialog(); | 40 this.hide(); |
| 41 event.consume(true); | 41 event.consume(true); |
| 42 }); | 42 }); |
| 43 /** @type {!Map<!HTMLElement, number>} */ | 43 /** @type {!Map<!HTMLElement, number>} */ |
| 44 this._tabIndexMap = new Map(); | 44 this._tabIndexMap = new Map(); |
| 45 /** @type {?UI.WidgetFocusRestorer} */ | 45 /** @type {?UI.WidgetFocusRestorer} */ |
| 46 this._focusRestorer = null; | 46 this._focusRestorer = null; |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * @return {boolean} | 50 * @return {boolean} |
| 51 */ | 51 */ |
| 52 static hasInstance() { | 52 static hasInstance() { |
| 53 return !!UI.Dialog._instance; | 53 return !!UI.Dialog._instance; |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @override |
| 57 * @param {!Document|!Element=} where | 58 * @param {!Document|!Element=} where |
| 58 */ | 59 */ |
| 59 showDialog(where) { | 60 show(where) { |
| 60 var document = /** @type {!Document} */ ( | 61 var document = /** @type {!Document} */ ( |
| 61 where instanceof Document ? where : (where || UI.inspectorView.element).
ownerDocument); | 62 where instanceof Document ? where : (where || UI.inspectorView.element).
ownerDocument); |
| 62 if (UI.Dialog._instance) | 63 if (UI.Dialog._instance) |
| 63 UI.Dialog._instance.detach(); | 64 UI.Dialog._instance.detach(); |
| 64 UI.Dialog._instance = this; | 65 UI.Dialog._instance = this; |
| 65 this._disableTabIndexOnElements(document); | 66 this._disableTabIndexOnElements(document); |
| 66 this.showGlassPane(document); | 67 super.show(document); |
| 67 this._focusRestorer = new UI.WidgetFocusRestorer(this); | 68 this._focusRestorer = new UI.WidgetFocusRestorer(this.widget()); |
| 68 } | 69 } |
| 69 | 70 |
| 70 hideDialog() { | 71 /** |
| 72 * @override |
| 73 */ |
| 74 hide() { |
| 71 this._focusRestorer.restore(); | 75 this._focusRestorer.restore(); |
| 72 this.hideGlassPane(); | 76 super.hide(); |
| 73 this._restoreTabIndexOnElements(); | 77 this._restoreTabIndexOnElements(); |
| 74 delete UI.Dialog._instance; | 78 delete UI.Dialog._instance; |
| 75 } | 79 } |
| 76 | 80 |
| 77 addCloseButton() { | 81 addCloseButton() { |
| 78 var closeButton = this.contentElement.createChild('div', 'dialog-close-butto
n', 'dt-close-button'); | 82 var closeButton = this.contentElement.createChild('div', 'dialog-close-butto
n', 'dt-close-button'); |
| 79 closeButton.gray = true; | 83 closeButton.gray = true; |
| 80 closeButton.addEventListener('click', () => this.detach(), false); | 84 closeButton.addEventListener('click', () => this.hide(), false); |
| 81 } | 85 } |
| 82 | 86 |
| 83 /** | 87 /** |
| 84 * @param {!Document} document | 88 * @param {!Document} document |
| 85 */ | 89 */ |
| 86 _disableTabIndexOnElements(document) { | 90 _disableTabIndexOnElements(document) { |
| 87 this._tabIndexMap.clear(); | 91 this._tabIndexMap.clear(); |
| 88 for (var node = document; node; node = node.traverseNextNode(document)) { | 92 for (var node = document; node; node = node.traverseNextNode(document)) { |
| 89 if (node instanceof HTMLElement) { | 93 if (node instanceof HTMLElement) { |
| 90 var element = /** @type {!HTMLElement} */ (node); | 94 var element = /** @type {!HTMLElement} */ (node); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 102 element.tabIndex = /** @type {number} */ (this._tabIndexMap.get(element)); | 106 element.tabIndex = /** @type {number} */ (this._tabIndexMap.get(element)); |
| 103 this._tabIndexMap.clear(); | 107 this._tabIndexMap.clear(); |
| 104 } | 108 } |
| 105 | 109 |
| 106 /** | 110 /** |
| 107 * @param {!Event} event | 111 * @param {!Event} event |
| 108 */ | 112 */ |
| 109 _onKeyDown(event) { | 113 _onKeyDown(event) { |
| 110 if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code) { | 114 if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code) { |
| 111 event.consume(true); | 115 event.consume(true); |
| 112 this.hideDialog(); | 116 this.hide(); |
| 113 } | 117 } |
| 114 } | 118 } |
| 115 }; | 119 }; |
| OLD | NEW |