| 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) |
| 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); |
| 83 WebInspector.Dialog._instance.focus(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 WebInspector.Dialog.hide = function() | 86 WebInspector.Dialog.hide = function() |
| 83 { | 87 { |
| 84 if (!WebInspector.Dialog._instance) | 88 if (!WebInspector.Dialog._instance) |
| 85 return; | 89 return; |
| 86 WebInspector.Dialog._instance._hide(); | 90 WebInspector.Dialog._instance._hide(); |
| 87 } | 91 } |
| 88 | 92 |
| 89 WebInspector.Dialog.prototype = { | 93 WebInspector.Dialog.prototype = { |
| 90 focus: function() | 94 focus: function() |
| 91 { | 95 { |
| 92 this._element.focus(); | 96 this._element.focus(); |
| 93 }, | 97 }, |
| 94 | 98 |
| 95 _hide: function() | 99 _hide: function() |
| 96 { | 100 { |
| 97 if (this._isHiding) | 101 if (this._isHiding) |
| 98 return; | 102 return; |
| 99 this._isHiding = true; | 103 this._isHiding = true; |
| 100 | 104 |
| 101 this._delegate.willHide(); | 105 this._delegate.willHide(); |
| 102 | 106 |
| 103 delete WebInspector.Dialog._instance; | 107 delete WebInspector.Dialog._instance; |
| 104 WebInspector.GlassPane.DefaultFocusedViewStack.pop(); | 108 WebInspector.GlassPane.DefaultFocusedViewStack.pop(); |
| 105 this._glassPane.dispose(); | 109 this._glassPane.dispose(); |
| 106 }, | 110 }, |
| 107 | 111 |
| 112 /** |
| 113 * @param {!Event} event |
| 114 */ |
| 108 _onGlassPaneFocus: function(event) | 115 _onGlassPaneFocus: function(event) |
| 109 { | 116 { |
| 117 if (this._modal) |
| 118 return; |
| 110 this._hide(); | 119 this._hide(); |
| 111 }, | 120 }, |
| 112 | 121 |
| 113 _onFocus: function(event) | 122 _onFocus: function(event) |
| 114 { | 123 { |
| 115 this._delegate.focus(); | 124 this._delegate.focus(); |
| 116 }, | 125 }, |
| 117 | 126 |
| 118 _position: function() | 127 _position: function() |
| 119 { | 128 { |
| 120 this._delegate.position(this._element, this._relativeToElement); | 129 this._delegate.position(this._element, this._relativeToElement); |
| 121 }, | 130 }, |
| 122 | 131 |
| 123 _onKeyDown: function(event) | 132 _onKeyDown: function(event) |
| 124 { | 133 { |
| 125 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { | 134 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { |
| 126 event.preventDefault(); | 135 event.preventDefault(); |
| 127 return; | 136 return; |
| 128 } | 137 } |
| 129 | 138 |
| 130 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) | 139 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) |
| 131 this._delegate.onEnter(event); | 140 this._delegate.onEnter(event); |
| 132 | 141 |
| 142 this._delegate.onKeyDown(event); |
| 143 |
| 133 if (!event.handled && this._closeKeys.indexOf(event.keyCode) >= 0) { | 144 if (!event.handled && this._closeKeys.indexOf(event.keyCode) >= 0) { |
| 134 this._hide(); | 145 this._hide(); |
| 135 event.consume(true); | 146 event.consume(true); |
| 136 } | 147 } |
| 137 } | 148 } |
| 138 }; | 149 }; |
| 139 | 150 |
| 140 /** | 151 /** |
| 141 * @constructor | 152 * @constructor |
| 142 * @extends {WebInspector.Object} | 153 * @extends {WebInspector.Object} |
| (...skipping 28 matching lines...) Expand all Loading... |
| 171 | 182 |
| 172 var positionY = box.y + (relativeToElement.offsetHeight - element.offset
Height) / 2; | 183 var positionY = box.y + (relativeToElement.offsetHeight - element.offset
Height) / 2; |
| 173 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem
ent.offsetHeight); | 184 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem
ent.offsetHeight); |
| 174 | 185 |
| 175 element.style.position = "absolute"; | 186 element.style.position = "absolute"; |
| 176 element.positionAt(positionX, positionY, container); | 187 element.positionAt(positionX, positionY, container); |
| 177 }, | 188 }, |
| 178 | 189 |
| 179 focus: function() { }, | 190 focus: function() { }, |
| 180 | 191 |
| 192 /** |
| 193 * @param {!KeyboardEvent} event |
| 194 */ |
| 181 onEnter: function(event) { }, | 195 onEnter: function(event) { }, |
| 182 | 196 |
| 197 /** |
| 198 * @param {!KeyboardEvent} event |
| 199 */ |
| 200 onKeyDown: function(event) { }, |
| 201 |
| 183 willHide: function() { }, | 202 willHide: function() { }, |
| 184 | 203 |
| 185 __proto__: WebInspector.Object.prototype | 204 __proto__: WebInspector.Object.prototype |
| 186 } | 205 } |
| 187 | 206 |
| 188 /** @type {?WebInspector.Widget} */ | 207 /** @type {?WebInspector.Widget} */ |
| 189 WebInspector.Dialog._modalHostView = null; | 208 WebInspector.Dialog._modalHostView = null; |
| 190 | 209 |
| 191 /** | 210 /** |
| 192 * @param {!WebInspector.Widget} view | 211 * @param {!WebInspector.Widget} view |
| (...skipping 12 matching lines...) Expand all Loading... |
| 205 { | 224 { |
| 206 return WebInspector.Dialog._modalHostView; | 225 return WebInspector.Dialog._modalHostView; |
| 207 }; | 226 }; |
| 208 | 227 |
| 209 WebInspector.Dialog.modalHostRepositioned = function() | 228 WebInspector.Dialog.modalHostRepositioned = function() |
| 210 { | 229 { |
| 211 if (WebInspector.Dialog._instance) | 230 if (WebInspector.Dialog._instance) |
| 212 WebInspector.Dialog._instance._position(); | 231 WebInspector.Dialog._instance._position(); |
| 213 }; | 232 }; |
| 214 | 233 |
| OLD | NEW |