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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 { | 66 { |
67 if (WebInspector.Dialog._instance) | 67 if (WebInspector.Dialog._instance) |
68 WebInspector.Dialog._instance.detach(); | 68 WebInspector.Dialog._instance.detach(); |
69 WebInspector.Dialog._instance = this; | 69 WebInspector.Dialog._instance = this; |
70 | 70 |
71 var document = /** @type {!Document} */ (WebInspector.Dialog._modalHostV
iew.element.ownerDocument); | 71 var document = /** @type {!Document} */ (WebInspector.Dialog._modalHostV
iew.element.ownerDocument); |
72 this._disableTabIndexOnElements(document); | 72 this._disableTabIndexOnElements(document); |
73 | 73 |
74 this._glassPane = new WebInspector.GlassPane(document, this._dimmed); | 74 this._glassPane = new WebInspector.GlassPane(document, this._dimmed); |
75 this._glassPane.element.addEventListener("click", this._onGlassPaneClick
.bind(this), false); | 75 this._glassPane.element.addEventListener("click", this._onGlassPaneClick
.bind(this), false); |
76 WebInspector.GlassPane.DefaultFocusedViewStack.push(this); | 76 |
| 77 // When a dialog closes, focus should be restored to the previous focuse
d element when |
| 78 // possible, otherwise the default inspector view element. |
| 79 WebInspector.Dialog._previousFocusedElement = WebInspector.currentFocusE
lement() || WebInspector.Dialog._modalHostView.defaultFocusedElement(); |
77 | 80 |
78 WebInspector.Widget.prototype.show.call(this, this._glassPane.element); | 81 WebInspector.Widget.prototype.show.call(this, this._glassPane.element); |
79 | 82 |
80 this._position(); | 83 this._position(); |
81 this.focus(); | 84 this.focus(); |
82 }, | 85 }, |
83 | 86 |
84 /** | 87 /** |
85 * @override | 88 * @override |
86 */ | 89 */ |
87 detach: function() | 90 detach: function() |
88 { | 91 { |
89 WebInspector.Widget.prototype.detach.call(this); | 92 WebInspector.Widget.prototype.detach.call(this); |
90 | 93 |
91 WebInspector.GlassPane.DefaultFocusedViewStack.pop(); | |
92 this._glassPane.dispose(); | 94 this._glassPane.dispose(); |
93 delete this._glassPane; | 95 delete this._glassPane; |
94 | 96 |
| 97 if (WebInspector.Dialog._previousFocusedElement) |
| 98 WebInspector.Dialog._previousFocusedElement.focus(); |
| 99 delete WebInspector.Dialog._previousFocusedElement; |
| 100 |
95 this._restoreTabIndexOnElements(); | 101 this._restoreTabIndexOnElements(); |
96 | 102 |
97 delete WebInspector.Dialog._instance; | 103 delete WebInspector.Dialog._instance; |
98 }, | 104 }, |
99 | 105 |
100 addCloseButton: function() | 106 addCloseButton: function() |
101 { | 107 { |
102 var closeButton = this.contentElement.createChild("div", "dialog-close-b
utton", "dt-close-button"); | 108 var closeButton = this.contentElement.createChild("div", "dialog-close-b
utton", "dt-close-button"); |
103 closeButton.gray = true; | 109 closeButton.gray = true; |
104 closeButton.addEventListener("click", this.detach.bind(this, false), fal
se); | 110 closeButton.addEventListener("click", this.detach.bind(this, false), fal
se); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 { | 250 { |
245 var children = this.children(); | 251 var children = this.children(); |
246 if (children.length) | 252 if (children.length) |
247 return children[0].defaultFocusedElement(); | 253 return children[0].defaultFocusedElement(); |
248 return this.element; | 254 return this.element; |
249 }, | 255 }, |
250 | 256 |
251 __proto__: WebInspector.Widget.prototype | 257 __proto__: WebInspector.Widget.prototype |
252 }; | 258 }; |
253 | 259 |
| 260 /** @type {?Element} */ |
| 261 WebInspector.Dialog._previousFocusedElement = null; |
| 262 |
254 /** @type {?WebInspector.Widget} */ | 263 /** @type {?WebInspector.Widget} */ |
255 WebInspector.Dialog._modalHostView = null; | 264 WebInspector.Dialog._modalHostView = null; |
256 | 265 |
257 /** | 266 /** |
258 * @param {!WebInspector.Widget} view | 267 * @param {!WebInspector.Widget} view |
259 */ | 268 */ |
260 WebInspector.Dialog.setModalHostView = function(view) | 269 WebInspector.Dialog.setModalHostView = function(view) |
261 { | 270 { |
262 WebInspector.Dialog._modalHostView = view; | 271 WebInspector.Dialog._modalHostView = view; |
263 }; | 272 }; |
264 | 273 |
265 /** | 274 /** |
266 * FIXME: make utility method in Dialog, so clients use it instead of this gette
r. | 275 * FIXME: make utility method in Dialog, so clients use it instead of this gette
r. |
267 * Method should be like Dialog.showModalElement(position params, reposition cal
lback). | 276 * Method should be like Dialog.showModalElement(position params, reposition cal
lback). |
268 * @return {?WebInspector.Widget} | 277 * @return {?WebInspector.Widget} |
269 */ | 278 */ |
270 WebInspector.Dialog.modalHostView = function() | 279 WebInspector.Dialog.modalHostView = function() |
271 { | 280 { |
272 return WebInspector.Dialog._modalHostView; | 281 return WebInspector.Dialog._modalHostView; |
273 }; | 282 }; |
274 | 283 |
275 WebInspector.Dialog.modalHostRepositioned = function() | 284 WebInspector.Dialog.modalHostRepositioned = function() |
276 { | 285 { |
277 if (WebInspector.Dialog._instance) | 286 if (WebInspector.Dialog._instance) |
278 WebInspector.Dialog._instance._position(); | 287 WebInspector.Dialog._instance._position(); |
279 }; | 288 }; |
280 | 289 |
OLD | NEW |