| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). | 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). |
| 5 * Copyright (C) 2009 Joseph Pecoraro | 5 * Copyright (C) 2009 Joseph Pecoraro |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * | 10 * |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 * @param {boolean=} dimmed | 277 * @param {boolean=} dimmed |
| 278 */ | 278 */ |
| 279 WebInspector.GlassPane = function(document, dimmed) | 279 WebInspector.GlassPane = function(document, dimmed) |
| 280 { | 280 { |
| 281 this.element = createElement("div"); | 281 this.element = createElement("div"); |
| 282 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent"; | 282 var background = dimmed ? "rgba(255, 255, 255, 0.5)" : "transparent"; |
| 283 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1
000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be
low. | 283 this._zIndex = WebInspector._glassPane ? WebInspector._glassPane._zIndex + 1
000 : 3000; // Deliberately starts with 3000 to hide other z-indexed elements be
low. |
| 284 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:
0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd
en;"; | 284 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:
0;background-color:" + background + ";z-index:" + this._zIndex + ";overflow:hidd
en;"; |
| 285 document.body.appendChild(this.element); | 285 document.body.appendChild(this.element); |
| 286 WebInspector._glassPane = this; | 286 WebInspector._glassPane = this; |
| 287 // TODO(dgozman): disallow focus outside of glass pane? |
| 287 } | 288 } |
| 288 | 289 |
| 289 WebInspector.GlassPane.prototype = { | 290 WebInspector.GlassPane.prototype = { |
| 290 dispose: function() | 291 dispose: function() |
| 291 { | 292 { |
| 292 delete WebInspector._glassPane; | 293 delete WebInspector._glassPane; |
| 293 this.element.remove(); | 294 this.element.remove(); |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 315 while (element) { | 316 while (element) { |
| 316 if (element.__editing) | 317 if (element.__editing) |
| 317 return true; | 318 return true; |
| 318 element = element.parentElementOrShadowHost(); | 319 element = element.parentElementOrShadowHost(); |
| 319 } | 320 } |
| 320 return false; | 321 return false; |
| 321 } | 322 } |
| 322 | 323 |
| 323 /** | 324 /** |
| 324 * @return {boolean} | 325 * @return {boolean} |
| 326 * @suppressGlobalPropertiesCheck |
| 325 */ | 327 */ |
| 326 WebInspector.isEditing = function() | 328 WebInspector.isEditing = function() |
| 327 { | 329 { |
| 328 if (WebInspector.__editingCount) | 330 if (WebInspector.__editingCount) |
| 329 return true; | 331 return true; |
| 330 | 332 |
| 331 var element = WebInspector.currentFocusElement(); | 333 var focused = document.deepActiveElement(); |
| 332 if (!element) | 334 if (!focused) |
| 333 return false; | 335 return false; |
| 334 return element.classList.contains("text-prompt") || element.nodeName === "IN
PUT" || element.nodeName === "TEXTAREA"; | 336 return focused.classList.contains("text-prompt") || focused.nodeName === "IN
PUT" || focused.nodeName === "TEXTAREA"; |
| 335 } | 337 } |
| 336 | 338 |
| 337 /** | 339 /** |
| 338 * @param {!Element} element | 340 * @param {!Element} element |
| 339 * @param {boolean} value | 341 * @param {boolean} value |
| 340 * @return {boolean} | 342 * @return {boolean} |
| 341 */ | 343 */ |
| 342 WebInspector.markBeingEdited = function(element, value) | 344 WebInspector.markBeingEdited = function(element, value) |
| 343 { | 345 { |
| 344 if (value) { | 346 if (value) { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 * @param {!Document} document | 787 * @param {!Document} document |
| 786 * @param {!Event} event | 788 * @param {!Event} event |
| 787 */ | 789 */ |
| 788 WebInspector._windowBlurred = function(document, event) | 790 WebInspector._windowBlurred = function(document, event) |
| 789 { | 791 { |
| 790 if (event.target.document.nodeType === Node.DOCUMENT_NODE) | 792 if (event.target.document.nodeType === Node.DOCUMENT_NODE) |
| 791 document.body.classList.add("inactive"); | 793 document.body.classList.add("inactive"); |
| 792 } | 794 } |
| 793 | 795 |
| 794 /** | 796 /** |
| 795 * @return {!Element} | |
| 796 */ | |
| 797 WebInspector.previousFocusElement = function() | |
| 798 { | |
| 799 return WebInspector._previousFocusElement; | |
| 800 } | |
| 801 | |
| 802 /** | |
| 803 * @return {!Element} | |
| 804 */ | |
| 805 WebInspector.currentFocusElement = function() | |
| 806 { | |
| 807 return WebInspector._currentFocusElement; | |
| 808 } | |
| 809 | |
| 810 /** | |
| 811 * @param {!Event} event | 797 * @param {!Event} event |
| 812 */ | 798 */ |
| 813 WebInspector._focusChanged = function(event) | 799 WebInspector._focusChanged = function(event) |
| 814 { | 800 { |
| 815 var node = event.deepActiveElement(); | 801 var node = event.deepActiveElement(); |
| 816 WebInspector.Widget.focusWidgetForNode(node); | 802 WebInspector.Widget.focusWidgetForNode(node); |
| 817 WebInspector.setCurrentFocusElement(node); | |
| 818 } | 803 } |
| 819 | 804 |
| 820 /** | 805 /** |
| 821 * @param {!Document} document | 806 * @param {!Element} element |
| 822 * @param {!Event} event | 807 * @constructor |
| 823 */ | 808 */ |
| 824 WebInspector._documentBlurred = function(document, event) | 809 WebInspector.ElementFocusRestorer = function(element) |
| 825 { | 810 { |
| 826 // We want to know when currentFocusElement loses focus to nowhere. | 811 this._element = element; |
| 827 // This is the case when event.relatedTarget is null (no element is being fo
cused) | 812 this._previous = element.ownerDocument.deepActiveElement(); |
| 828 // and document.activeElement is reset to default (this is not a window blur
). | 813 element.focus(); |
| 829 if (!event.relatedTarget && document.activeElement === document.body) | |
| 830 WebInspector.setCurrentFocusElement(null); | |
| 831 } | 814 } |
| 832 | 815 |
| 833 WebInspector._textInputTypes = new Set(["text", "search", "tel", "url", "email",
"password"]); | 816 WebInspector.ElementFocusRestorer.prototype = { |
| 834 WebInspector._isTextEditingElement = function(element) | 817 restore: function() |
| 835 { | 818 { |
| 836 if (element instanceof HTMLInputElement) | 819 if (!this._element) |
| 837 return WebInspector._textInputTypes.has(element.type); | 820 return; |
| 838 | 821 if (this._element.hasFocus() && this._previous) |
| 839 if (element instanceof HTMLTextAreaElement) | 822 this._previous.focus(); |
| 840 return true; | 823 this._previous = null; |
| 841 | 824 this._element = null; |
| 842 return false; | 825 } |
| 843 } | 826 } |
| 844 | 827 |
| 845 /** | 828 /** |
| 846 * @param {?Node} x | |
| 847 */ | |
| 848 WebInspector.setCurrentFocusElement = function(x) | |
| 849 { | |
| 850 if (WebInspector._glassPane && x && !WebInspector._glassPane.element.isAnces
tor(x)) | |
| 851 return; | |
| 852 if (x && !x.ownerDocument.isAncestor(x)) | |
| 853 return; | |
| 854 if (WebInspector._currentFocusElement !== x) | |
| 855 WebInspector._previousFocusElement = WebInspector._currentFocusElement; | |
| 856 WebInspector._currentFocusElement = x; | |
| 857 | |
| 858 if (x) { | |
| 859 x.focus(); | |
| 860 | |
| 861 // Make a caret selection inside the new element if there isn't a range
selection and there isn't already a caret selection inside. | |
| 862 // This is needed (at least) to remove caret from console when focus is
moved to some element in the panel. | |
| 863 // The code below should not be applied to text fields and text areas, h
ence _isTextEditingElement check. | |
| 864 var selection = x.getComponentSelection(); | |
| 865 if (!WebInspector._isTextEditingElement(x) && selection.isCollapsed && !
x.isInsertionCaretInside()) { | |
| 866 var selectionRange = x.ownerDocument.createRange(); | |
| 867 selectionRange.setStart(x, 0); | |
| 868 selectionRange.setEnd(x, 0); | |
| 869 | |
| 870 selection.removeAllRanges(); | |
| 871 selection.addRange(selectionRange); | |
| 872 } | |
| 873 } else if (WebInspector._previousFocusElement) | |
| 874 WebInspector._previousFocusElement.blur(); | |
| 875 } | |
| 876 | |
| 877 WebInspector.restoreFocusFromElement = function(element) | |
| 878 { | |
| 879 if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement())) | |
| 880 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement())
; | |
| 881 } | |
| 882 | |
| 883 /** | |
| 884 * @param {!Element} element | 829 * @param {!Element} element |
| 885 * @param {number} offset | 830 * @param {number} offset |
| 886 * @param {number} length | 831 * @param {number} length |
| 887 * @param {!Array.<!Object>=} domChanges | 832 * @param {!Array.<!Object>=} domChanges |
| 888 * @return {?Element} | 833 * @return {?Element} |
| 889 */ | 834 */ |
| 890 WebInspector.highlightSearchResult = function(element, offset, length, domChange
s) | 835 WebInspector.highlightSearchResult = function(element, offset, length, domChange
s) |
| 891 { | 836 { |
| 892 var result = WebInspector.highlightSearchResults(element, [new WebInspector.
SourceRange(offset, length)], domChanges); | 837 var result = WebInspector.highlightSearchResults(element, [new WebInspector.
SourceRange(offset, length)], domChanges); |
| 893 return result.length ? result[0] : null; | 838 return result.length ? result[0] : null; |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 | 1209 |
| 1265 /** | 1210 /** |
| 1266 * @param {!Document} document | 1211 * @param {!Document} document |
| 1267 * @param {!WebInspector.Setting} themeSetting | 1212 * @param {!WebInspector.Setting} themeSetting |
| 1268 */ | 1213 */ |
| 1269 WebInspector.initializeUIUtils = function(document, themeSetting) | 1214 WebInspector.initializeUIUtils = function(document, themeSetting) |
| 1270 { | 1215 { |
| 1271 document.defaultView.addEventListener("focus", WebInspector._windowFocused.b
ind(WebInspector, document), false); | 1216 document.defaultView.addEventListener("focus", WebInspector._windowFocused.b
ind(WebInspector, document), false); |
| 1272 document.defaultView.addEventListener("blur", WebInspector._windowBlurred.bi
nd(WebInspector, document), false); | 1217 document.defaultView.addEventListener("blur", WebInspector._windowBlurred.bi
nd(WebInspector, document), false); |
| 1273 document.addEventListener("focus", WebInspector._focusChanged.bind(WebInspec
tor), true); | 1218 document.addEventListener("focus", WebInspector._focusChanged.bind(WebInspec
tor), true); |
| 1274 document.addEventListener("blur", WebInspector._documentBlurred.bind(WebInsp
ector, document), true); | |
| 1275 | 1219 |
| 1276 if (!WebInspector.themeSupport) | 1220 if (!WebInspector.themeSupport) |
| 1277 WebInspector.themeSupport = new WebInspector.ThemeSupport(themeSetting); | 1221 WebInspector.themeSupport = new WebInspector.ThemeSupport(themeSetting); |
| 1278 WebInspector.themeSupport.applyTheme(document); | 1222 WebInspector.themeSupport.applyTheme(document); |
| 1279 | 1223 |
| 1280 var body = /** @type {!Element} */ (document.body); | 1224 var body = /** @type {!Element} */ (document.body); |
| 1281 WebInspector.appendStyle(body, "ui/inspectorStyle.css"); | 1225 WebInspector.appendStyle(body, "ui/inspectorStyle.css"); |
| 1282 WebInspector.appendStyle(body, "ui/popover.css"); | 1226 WebInspector.appendStyle(body, "ui/popover.css"); |
| 1283 } | 1227 } |
| 1284 | 1228 |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 * @param {string} title | 1956 * @param {string} title |
| 2013 * @return {!Element} | 1957 * @return {!Element} |
| 2014 */ | 1958 */ |
| 2015 WebInspector.linkifyDocumentationURLAsNode = function(article, title) | 1959 WebInspector.linkifyDocumentationURLAsNode = function(article, title) |
| 2016 { | 1960 { |
| 2017 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
s/chrome-devtools/" + article, title, undefined, true); | 1961 return WebInspector.linkifyURLAsNode("https://developers.google.com/web/tool
s/chrome-devtools/" + article, title, undefined, true); |
| 2018 } | 1962 } |
| 2019 | 1963 |
| 2020 /** @type {!WebInspector.ThemeSupport} */ | 1964 /** @type {!WebInspector.ThemeSupport} */ |
| 2021 WebInspector.themeSupport; | 1965 WebInspector.themeSupport; |
| OLD | NEW |