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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 | |
34 * @param {!WebInspector.DialogDelegate} delegate | 33 * @param {!WebInspector.DialogDelegate} delegate |
35 * @param {boolean=} modal | 34 * @param {boolean=} modal |
36 */ | 35 */ |
37 WebInspector.Dialog = function(relativeToElement, delegate, modal) | 36 WebInspector.Dialog = function(delegate, modal) |
38 { | 37 { |
39 this._delegate = delegate; | 38 this._delegate = delegate; |
40 this._relativeToElement = relativeToElement; | |
41 this._modal = modal; | 39 this._modal = modal; |
42 | 40 |
43 this._glassPane = new WebInspector.GlassPane(/** @type {!Document} */ (relat
iveToElement.ownerDocument)); | 41 this._glassPane = new WebInspector.GlassPane(/** @type {!Document} */ (WebIn
spector.Dialog._modalHostView.element.ownerDocument)); |
44 WebInspector.GlassPane.DefaultFocusedViewStack.push(this); | 42 WebInspector.GlassPane.DefaultFocusedViewStack.push(this); |
45 | 43 |
46 // Install glass pane capturing events. | 44 // Install glass pane capturing events. |
47 this._glassPane.element.tabIndex = 0; | 45 this._glassPane.element.tabIndex = 0; |
48 this._glassPane.element.addEventListener("focus", this._onGlassPaneFocus.bin
d(this), false); | 46 this._glassPane.element.addEventListener("focus", this._onGlassPaneFocus.bin
d(this), false); |
49 if (this._modal) | 47 if (this._modal) |
50 this._glassPane.element.classList.add("tinted"); | 48 this._glassPane.element.classList.add("tinted"); |
51 | 49 |
52 this._element = this._glassPane.element.createChild("div"); | 50 this._element = this._glassPane.element.createChild("div"); |
53 this._element.tabIndex = 0; | 51 this._element.tabIndex = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
66 | 64 |
67 /** | 65 /** |
68 * @return {?WebInspector.Dialog} | 66 * @return {?WebInspector.Dialog} |
69 */ | 67 */ |
70 WebInspector.Dialog.currentInstance = function() | 68 WebInspector.Dialog.currentInstance = function() |
71 { | 69 { |
72 return WebInspector.Dialog._instance; | 70 return WebInspector.Dialog._instance; |
73 } | 71 } |
74 | 72 |
75 /** | 73 /** |
76 * @param {?Element} relativeToElement | |
77 * @param {!WebInspector.DialogDelegate} delegate | 74 * @param {!WebInspector.DialogDelegate} delegate |
78 * @param {boolean=} modal | 75 * @param {boolean=} modal |
79 */ | 76 */ |
80 WebInspector.Dialog.show = function(relativeToElement, delegate, modal) | 77 WebInspector.Dialog.show = function(delegate, modal) |
81 { | 78 { |
82 if (WebInspector.Dialog._instance) | 79 if (WebInspector.Dialog._instance) |
83 return; | 80 return; |
84 WebInspector.Dialog._instance = new WebInspector.Dialog(relativeToElement ||
WebInspector.Dialog.modalHostView().element, delegate, modal); | 81 WebInspector.Dialog._instance = new WebInspector.Dialog(delegate, modal); |
85 WebInspector.Dialog._instance.focus(); | 82 WebInspector.Dialog._instance.focus(); |
86 } | 83 } |
87 | 84 |
88 WebInspector.Dialog.hide = function() | 85 WebInspector.Dialog.hide = function() |
89 { | 86 { |
90 if (!WebInspector.Dialog._instance) | 87 if (!WebInspector.Dialog._instance) |
91 return; | 88 return; |
92 WebInspector.Dialog._instance._hide(); | 89 WebInspector.Dialog._instance._hide(); |
93 } | 90 } |
94 | 91 |
(...skipping 26 matching lines...) Expand all Loading... |
121 this._hide(); | 118 this._hide(); |
122 }, | 119 }, |
123 | 120 |
124 _onFocus: function(event) | 121 _onFocus: function(event) |
125 { | 122 { |
126 this._delegate.focus(); | 123 this._delegate.focus(); |
127 }, | 124 }, |
128 | 125 |
129 _position: function() | 126 _position: function() |
130 { | 127 { |
131 this._delegate.position(this._element, this._relativeToElement); | 128 this._delegate.position(this._element, WebInspector.Dialog._modalHostVie
w.element); |
132 }, | 129 }, |
133 | 130 |
134 _onKeyDown: function(event) | 131 _onKeyDown: function(event) |
135 { | 132 { |
136 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { | 133 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) { |
137 event.preventDefault(); | 134 event.preventDefault(); |
138 return; | 135 return; |
139 } | 136 } |
140 | 137 |
141 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) | 138 if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code) |
(...skipping 23 matching lines...) Expand all Loading... |
165 */ | 162 */ |
166 show: function(element) | 163 show: function(element) |
167 { | 164 { |
168 element.appendChild(this.element); | 165 element.appendChild(this.element); |
169 this.element.classList.add("dialog-contents"); | 166 this.element.classList.add("dialog-contents"); |
170 element.classList.add("dialog"); | 167 element.classList.add("dialog"); |
171 }, | 168 }, |
172 | 169 |
173 /** | 170 /** |
174 * @param {!Element} element | 171 * @param {!Element} element |
175 * @param {!Element} relativeToElement | 172 * @param {!Element} container |
176 */ | 173 */ |
177 position: function(element, relativeToElement) | 174 position: function(element, container) |
178 { | 175 { |
179 var container = WebInspector.Dialog._modalHostView.element; | 176 var positionX = (container.offsetWidth - element.offsetWidth) / 2; |
180 var box = relativeToElement.boxInWindow(window).relativeToElement(contai
ner); | |
181 | |
182 var positionX = box.x + (relativeToElement.offsetWidth - element.offsetW
idth) / 2; | |
183 positionX = Number.constrain(positionX, 0, container.offsetWidth - eleme
nt.offsetWidth); | 177 positionX = Number.constrain(positionX, 0, container.offsetWidth - eleme
nt.offsetWidth); |
184 | 178 |
185 var positionY = box.y + (relativeToElement.offsetHeight - element.offset
Height) / 2; | 179 var positionY = (container.offsetHeight - element.offsetHeight) / 2; |
186 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem
ent.offsetHeight); | 180 positionY = Number.constrain(positionY, 0, container.offsetHeight - elem
ent.offsetHeight); |
187 | 181 |
188 element.style.position = "absolute"; | 182 element.style.position = "absolute"; |
189 element.positionAt(positionX, positionY, container); | 183 element.positionAt(positionX, positionY, container); |
190 }, | 184 }, |
191 | 185 |
192 focus: function() { }, | 186 focus: function() { }, |
193 | 187 |
194 /** | 188 /** |
195 * @param {!KeyboardEvent} event | 189 * @param {!KeyboardEvent} event |
(...skipping 30 matching lines...) Expand all Loading... |
226 { | 220 { |
227 return WebInspector.Dialog._modalHostView; | 221 return WebInspector.Dialog._modalHostView; |
228 }; | 222 }; |
229 | 223 |
230 WebInspector.Dialog.modalHostRepositioned = function() | 224 WebInspector.Dialog.modalHostRepositioned = function() |
231 { | 225 { |
232 if (WebInspector.Dialog._instance) | 226 if (WebInspector.Dialog._instance) |
233 WebInspector.Dialog._instance._position(); | 227 WebInspector.Dialog._instance._position(); |
234 }; | 228 }; |
235 | 229 |
OLD | NEW |