Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 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 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @param {!Element} relativeToElement | 33 * @param {!Element} relativeToElement |
| 34 * @param {!WebInspector.DialogDelegate} delegate | 34 * @param {!WebInspector.DialogDelegate} delegate |
| 35 * @param {boolean=} modal | |
| 35 */ | 36 */ |
| 36 WebInspector.Dialog = function(relativeToElement, delegate) | 37 WebInspector.Dialog = function(relativeToElement, delegate, modal) |
| 37 { | 38 { |
| 38 this._delegate = delegate; | 39 this._delegate = delegate; |
| 39 this._relativeToElement = relativeToElement; | 40 this._relativeToElement = relativeToElement; |
| 41 this._modal = modal; | |
| 40 | 42 |
| 41 this._glassPane = new WebInspector.GlassPane(/** @type {!Document} */ (relat iveToElement.ownerDocument)); | 43 this._glassPane = new WebInspector.GlassPane(/** @type {!Document} */ (relat iveToElement.ownerDocument)); |
| 42 WebInspector.GlassPane.DefaultFocusedViewStack.push(this); | 44 WebInspector.GlassPane.DefaultFocusedViewStack.push(this); |
| 43 | 45 |
| 44 // Install glass pane capturing events. | 46 // Install glass pane capturing events. |
| 45 this._glassPane.element.tabIndex = 0; | 47 this._glassPane.element.tabIndex = 0; |
| 46 this._glassPane.element.addEventListener("focus", this._onGlassPaneFocus.bin d(this), false); | 48 this._glassPane.element.addEventListener("focus", this._onGlassPaneFocus.bin d(this), false); |
| 47 | 49 |
| 48 this._element = this._glassPane.element.createChild("div"); | 50 this._element = this._glassPane.element.createChild("div"); |
| 49 this._element.tabIndex = 0; | 51 this._element.tabIndex = 0; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 64 * @return {?WebInspector.Dialog} | 66 * @return {?WebInspector.Dialog} |
| 65 */ | 67 */ |
| 66 WebInspector.Dialog.currentInstance = function() | 68 WebInspector.Dialog.currentInstance = function() |
| 67 { | 69 { |
| 68 return WebInspector.Dialog._instance; | 70 return WebInspector.Dialog._instance; |
| 69 } | 71 } |
| 70 | 72 |
| 71 /** | 73 /** |
| 72 * @param {?Element} relativeToElement | 74 * @param {?Element} relativeToElement |
| 73 * @param {!WebInspector.DialogDelegate} delegate | 75 * @param {!WebInspector.DialogDelegate} delegate |
| 76 * @param {boolean=} modal | |
| 74 */ | 77 */ |
| 75 WebInspector.Dialog.show = function(relativeToElement, delegate) | 78 WebInspector.Dialog.show = function(relativeToElement, delegate, modal) |
|
caseq
2015/08/28 23:36:55
Let's rename modal?
alph
2015/08/29 00:49:38
Left it as is. Can't find a better short enough na
| |
| 76 { | 79 { |
| 77 if (WebInspector.Dialog._instance) | 80 if (WebInspector.Dialog._instance) |
| 78 return; | 81 return; |
| 79 WebInspector.Dialog._instance = new WebInspector.Dialog(relativeToElement || WebInspector.Dialog.modalHostView().element, delegate); | 82 WebInspector.Dialog._instance = new WebInspector.Dialog(relativeToElement || WebInspector.Dialog.modalHostView().element, delegate, modal); |
| 80 } | 83 } |
| 81 | 84 |
| 82 WebInspector.Dialog.hide = function() | 85 WebInspector.Dialog.hide = function() |
| 83 { | 86 { |
| 84 if (!WebInspector.Dialog._instance) | 87 if (!WebInspector.Dialog._instance) |
| 85 return; | 88 return; |
| 86 WebInspector.Dialog._instance._hide(); | 89 WebInspector.Dialog._instance._hide(); |
| 87 } | 90 } |
| 88 | 91 |
| 89 WebInspector.Dialog.prototype = { | 92 WebInspector.Dialog.prototype = { |
| 90 focus: function() | 93 focus: function() |
| 91 { | 94 { |
| 92 this._element.focus(); | 95 this._element.focus(); |
| 93 }, | 96 }, |
| 94 | 97 |
| 95 _hide: function() | 98 _hide: function() |
| 96 { | 99 { |
| 97 if (this._isHiding) | 100 if (this._isHiding) |
| 98 return; | 101 return; |
| 99 this._isHiding = true; | 102 this._isHiding = true; |
| 100 | 103 |
| 101 this._delegate.willHide(); | 104 this._delegate.willHide(); |
| 102 | 105 |
| 103 delete WebInspector.Dialog._instance; | 106 delete WebInspector.Dialog._instance; |
| 104 WebInspector.GlassPane.DefaultFocusedViewStack.pop(); | 107 WebInspector.GlassPane.DefaultFocusedViewStack.pop(); |
| 105 this._glassPane.dispose(); | 108 this._glassPane.dispose(); |
| 106 }, | 109 }, |
| 107 | 110 |
| 111 /** | |
| 112 * @param {!Event} event | |
| 113 */ | |
| 108 _onGlassPaneFocus: function(event) | 114 _onGlassPaneFocus: function(event) |
| 109 { | 115 { |
| 116 if (this._modal) | |
| 117 return; | |
| 110 this._hide(); | 118 this._hide(); |
| 111 }, | 119 }, |
| 112 | 120 |
| 113 _onFocus: function(event) | 121 _onFocus: function(event) |
| 114 { | 122 { |
| 115 this._delegate.focus(); | 123 this._delegate.focus(); |
| 116 }, | 124 }, |
| 117 | 125 |
| 118 _position: function() | 126 _position: function() |
| 119 { | 127 { |
| 120 this._delegate.position(this._element, this._relativeToElement); | 128 this._delegate.position(this._element, this._relativeToElement); |
| 121 }, | 129 }, |
| 122 | 130 |
| 123 _onKeyDown: function(event) | 131 _onKeyDown: function(event) |
| 124 { | 132 { |
| 125 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { | 133 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { |
| 126 event.preventDefault(); | 134 event.preventDefault(); |
| 127 return; | 135 return; |
| 128 } | 136 } |
| 129 | 137 |
| 130 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) | 138 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) |
| 131 this._delegate.onEnter(event); | 139 this._delegate.onEnter(event); |
| 132 | 140 |
| 141 this._delegate.onKeyDown(event); | |
| 142 | |
| 133 if (!event.handled && this._closeKeys.indexOf(event.keyCode) >= 0) { | 143 if (!event.handled && this._closeKeys.indexOf(event.keyCode) >= 0) { |
| 134 this._hide(); | 144 this._hide(); |
| 135 event.consume(true); | 145 event.consume(true); |
| 136 } | 146 } |
| 137 } | 147 } |
| 138 }; | 148 }; |
| 139 | 149 |
| 140 /** | 150 /** |
| 141 * @constructor | 151 * @constructor |
| 142 * @extends {WebInspector.Object} | 152 * @extends {WebInspector.Object} |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 171 | 181 |
| 172 var positionY = box.y + (relativeToElement.offsetHeight - element.offset Height) / 2; | 182 var positionY = box.y + (relativeToElement.offsetHeight - element.offset Height) / 2; |
| 173 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem ent.offsetHeight); | 183 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem ent.offsetHeight); |
| 174 | 184 |
| 175 element.style.position = "absolute"; | 185 element.style.position = "absolute"; |
| 176 element.positionAt(positionX, positionY, container); | 186 element.positionAt(positionX, positionY, container); |
| 177 }, | 187 }, |
| 178 | 188 |
| 179 focus: function() { }, | 189 focus: function() { }, |
| 180 | 190 |
| 191 /** | |
| 192 * @param {!KeyboardEvent} event | |
| 193 */ | |
| 181 onEnter: function(event) { }, | 194 onEnter: function(event) { }, |
| 182 | 195 |
| 196 /** | |
| 197 * @param {!KeyboardEvent} event | |
| 198 */ | |
| 199 onKeyDown: function(event) { }, | |
| 200 | |
| 183 willHide: function() { }, | 201 willHide: function() { }, |
| 184 | 202 |
| 185 __proto__: WebInspector.Object.prototype | 203 __proto__: WebInspector.Object.prototype |
| 186 } | 204 } |
| 187 | 205 |
| 188 /** @type {?WebInspector.Widget} */ | 206 /** @type {?WebInspector.Widget} */ |
| 189 WebInspector.Dialog._modalHostView = null; | 207 WebInspector.Dialog._modalHostView = null; |
| 190 | 208 |
| 191 /** | 209 /** |
| 192 * @param {!WebInspector.Widget} view | 210 * @param {!WebInspector.Widget} view |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 205 { | 223 { |
| 206 return WebInspector.Dialog._modalHostView; | 224 return WebInspector.Dialog._modalHostView; |
| 207 }; | 225 }; |
| 208 | 226 |
| 209 WebInspector.Dialog.modalHostRepositioned = function() | 227 WebInspector.Dialog.modalHostRepositioned = function() |
| 210 { | 228 { |
| 211 if (WebInspector.Dialog._instance) | 229 if (WebInspector.Dialog._instance) |
| 212 WebInspector.Dialog._instance._position(); | 230 WebInspector.Dialog._instance._position(); |
| 213 }; | 231 }; |
| 214 | 232 |
| OLD | NEW |