| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 WebInspector.ElementsPanel.prototype = { | 120 WebInspector.ElementsPanel.prototype = { |
| 121 _updateTreeOutlineVisibleWidth: function() | 121 _updateTreeOutlineVisibleWidth: function() |
| 122 { | 122 { |
| 123 if (!this.treeOutline) | 123 if (!this.treeOutline) |
| 124 return; | 124 return; |
| 125 | 125 |
| 126 var width = this._splitView.element.offsetWidth; | 126 var width = this._splitView.element.offsetWidth; |
| 127 if (this._splitView.isVertical()) | 127 if (this._splitView.isVertical()) |
| 128 width -= this._splitView.sidebarSize(); | 128 width -= this._splitView.sidebarSize(); |
| 129 this.treeOutline.setVisibleWidth(width); | 129 this.treeOutline.setVisibleWidth(width); |
| 130 this.treeOutline.updateSelection(); |
| 130 this.updateBreadcrumbSizes(); | 131 this.updateBreadcrumbSizes(); |
| 131 this.treeOutline.updateSelection(); | |
| 132 }, | 132 }, |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * @return {!Element} | 135 * @return {!Element} |
| 136 */ | 136 */ |
| 137 defaultFocusedElement: function() | 137 defaultFocusedElement: function() |
| 138 { | 138 { |
| 139 return this.treeOutline.element; | 139 return this.treeOutline.element; |
| 140 }, | 140 }, |
| 141 | 141 |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 748 |
| 749 if (!crumb.childNodes.length) { | 749 if (!crumb.childNodes.length) { |
| 750 var nameElement = document.createElement("span"); | 750 var nameElement = document.createElement("span"); |
| 751 nameElement.textContent = crumbTitle; | 751 nameElement.textContent = crumbTitle; |
| 752 crumb.appendChild(nameElement); | 752 crumb.appendChild(nameElement); |
| 753 crumb.title = crumbTitle; | 753 crumb.title = crumbTitle; |
| 754 } | 754 } |
| 755 | 755 |
| 756 if (current === this.selectedDOMNode()) | 756 if (current === this.selectedDOMNode()) |
| 757 crumb.classList.add("selected"); | 757 crumb.classList.add("selected"); |
| 758 if (!crumbs.childNodes.length) | |
| 759 crumb.classList.add("end"); | |
| 760 | |
| 761 crumbs.insertBefore(crumb, crumbs.firstChild); | 758 crumbs.insertBefore(crumb, crumbs.firstChild); |
| 762 } | 759 } |
| 763 | 760 |
| 764 if (crumbs.hasChildNodes()) | |
| 765 crumbs.lastChild.classList.add("start"); | |
| 766 | |
| 767 this.updateBreadcrumbSizes(); | 761 this.updateBreadcrumbSizes(); |
| 768 }, | 762 }, |
| 769 | 763 |
| 770 /** | 764 /** |
| 771 * @param {!Element=} focusedCrumb | 765 * @param {!Element=} focusedCrumb |
| 772 */ | 766 */ |
| 773 updateBreadcrumbSizes: function(focusedCrumb) | 767 updateBreadcrumbSizes: function(focusedCrumb) |
| 774 { | 768 { |
| 775 if (!this.isShowing()) | 769 if (!this.isShowing()) |
| 776 return; | 770 return; |
| 777 | 771 |
| 778 if (document.body.offsetWidth <= 0) { | 772 var crumbs = this.crumbsElement; |
| 779 // The stylesheet hasn't loaded yet or the window is closed, | 773 if (!crumbs.firstChild) |
| 780 // so we can't calculate what is need. Return early. | |
| 781 return; | 774 return; |
| 782 } | |
| 783 | 775 |
| 784 var crumbs = this.crumbsElement; | |
| 785 if (!crumbs.childNodes.length || crumbs.offsetWidth <= 0) | |
| 786 return; // No crumbs, do nothing. | |
| 787 | |
| 788 // A Zero index is the right most child crumb in the breadcrumb. | |
| 789 var selectedIndex = 0; | 776 var selectedIndex = 0; |
| 790 var focusedIndex = 0; | 777 var focusedIndex = 0; |
| 791 var selectedCrumb; | 778 var selectedCrumb; |
| 792 | 779 |
| 793 var i = 0; | 780 // Reset crumb styles. |
| 794 var crumb = crumbs.firstChild; | 781 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 795 while (crumb) { | 782 var crumb = crumbs.childNodes[i]; |
| 796 // Find the selected crumb and index. | 783 // Find the selected crumb and index. |
| 797 if (!selectedCrumb && crumb.classList.contains("selected")) { | 784 if (!selectedCrumb && crumb.classList.contains("selected")) { |
| 798 selectedCrumb = crumb; | 785 selectedCrumb = crumb; |
| 799 selectedIndex = i; | 786 selectedIndex = i; |
| 800 } | 787 } |
| 801 | 788 |
| 802 // Find the focused crumb index. | 789 // Find the focused crumb index. |
| 803 if (crumb === focusedCrumb) | 790 if (crumb === focusedCrumb) |
| 804 focusedIndex = i; | 791 focusedIndex = i; |
| 805 | 792 |
| 806 // Remove any styles that affect size before | 793 crumb.classList.remove("compact", "collapsed", "hidden"); |
| 807 // deciding to shorten any crumbs. | |
| 808 if (crumb !== crumbs.lastChild) | |
| 809 crumb.classList.remove("start"); | |
| 810 if (crumb !== crumbs.firstChild) | |
| 811 crumb.classList.remove("end"); | |
| 812 | |
| 813 crumb.classList.remove("compact"); | |
| 814 crumb.classList.remove("collapsed"); | |
| 815 crumb.classList.remove("hidden"); | |
| 816 | |
| 817 crumb = crumb.nextSibling; | |
| 818 ++i; | |
| 819 } | 794 } |
| 820 | 795 |
| 821 // Restore the start and end crumb classes in case they got removed in c
oalesceCollapsedCrumbs(). | 796 // Layout 1: Measure total and normal crumb sizes |
| 822 // The order of the crumbs in the document is opposite of the visual ord
er. | 797 var contentElementWidth = this.contentElement.offsetWidth; |
| 823 crumbs.firstChild.classList.add("end"); | 798 var normalSizes = []; |
| 824 crumbs.lastChild.classList.add("start"); | 799 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 800 var crumb = crumbs.childNodes[i]; |
| 801 normalSizes[i] = crumb.offsetWidth; |
| 802 } |
| 825 | 803 |
| 826 var contentElement = this.contentElement; | 804 // Layout 2: Measure collapsed crumb sizes |
| 805 var compactSizes = []; |
| 806 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 807 var crumb = crumbs.childNodes[i]; |
| 808 crumb.classList.add("compact"); |
| 809 } |
| 810 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 811 var crumb = crumbs.childNodes[i]; |
| 812 compactSizes[i] = crumb.offsetWidth; |
| 813 } |
| 814 |
| 815 // Layout 3: Measure collapsed crumb size |
| 816 crumbs.firstChild.classList.add("collapsed"); |
| 817 var collapsedSize = crumbs.firstChild.offsetWidth; |
| 818 |
| 819 // Clean up. |
| 820 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 821 var crumb = crumbs.childNodes[i]; |
| 822 crumb.classList.remove("compact", "collapsed"); |
| 823 } |
| 824 |
| 827 function crumbsAreSmallerThanContainer() | 825 function crumbsAreSmallerThanContainer() |
| 828 { | 826 { |
| 827 var totalSize = 0; |
| 828 for (var i = 0; i < crumbs.childNodes.length; ++i) { |
| 829 var crumb = crumbs.childNodes[i]; |
| 830 if (crumb.classList.contains("hidden")) |
| 831 continue; |
| 832 if (crumb.classList.contains("collapsed")) { |
| 833 totalSize += collapsedSize; |
| 834 continue; |
| 835 } |
| 836 totalSize += crumb.classList.contains("compact") ? compactSizes[
i] : normalSizes[i]; |
| 837 } |
| 829 const rightPadding = 10; | 838 const rightPadding = 10; |
| 830 return crumbs.offsetWidth + rightPadding < contentElement.offsetWidt
h; | 839 return totalSize + rightPadding < contentElementWidth; |
| 831 } | 840 } |
| 832 | 841 |
| 833 if (crumbsAreSmallerThanContainer()) | 842 if (crumbsAreSmallerThanContainer()) |
| 834 return; // No need to compact the crumbs, they all fit at full size. | 843 return; // No need to compact the crumbs, they all fit at full size. |
| 835 | 844 |
| 836 var BothSides = 0; | 845 var BothSides = 0; |
| 837 var AncestorSide = -1; | 846 var AncestorSide = -1; |
| 838 var ChildSide = 1; | 847 var ChildSide = 1; |
| 839 | 848 |
| 840 /** | 849 /** |
| 841 * @param {boolean=} significantCrumb | 850 * @param {function(!Element)} shrinkingFunction |
| 851 * @param {number} direction |
| 842 */ | 852 */ |
| 843 function makeCrumbsSmaller(shrinkingFunction, direction, significantCrum
b) | 853 function makeCrumbsSmaller(shrinkingFunction, direction) |
| 844 { | 854 { |
| 845 if (!significantCrumb) | 855 var significantCrumb = focusedCrumb || selectedCrumb; |
| 846 significantCrumb = (focusedCrumb || selectedCrumb); | 856 var significantIndex = significantCrumb === selectedCrumb ? selected
Index : focusedIndex; |
| 847 | |
| 848 if (significantCrumb === selectedCrumb) | |
| 849 var significantIndex = selectedIndex; | |
| 850 else if (significantCrumb === focusedCrumb) | |
| 851 var significantIndex = focusedIndex; | |
| 852 else { | |
| 853 var significantIndex = 0; | |
| 854 for (var i = 0; i < crumbs.childNodes.length; ++i) { | |
| 855 if (crumbs.childNodes[i] === significantCrumb) { | |
| 856 significantIndex = i; | |
| 857 break; | |
| 858 } | |
| 859 } | |
| 860 } | |
| 861 | 857 |
| 862 function shrinkCrumbAtIndex(index) | 858 function shrinkCrumbAtIndex(index) |
| 863 { | 859 { |
| 864 var shrinkCrumb = crumbs.childNodes[index]; | 860 var shrinkCrumb = crumbs.childNodes[index]; |
| 865 if (shrinkCrumb && shrinkCrumb !== significantCrumb) | 861 if (shrinkCrumb && shrinkCrumb !== significantCrumb) |
| 866 shrinkingFunction(shrinkCrumb); | 862 shrinkingFunction(shrinkCrumb); |
| 867 if (crumbsAreSmallerThanContainer()) | 863 if (crumbsAreSmallerThanContainer()) |
| 868 return true; // No need to compact the crumbs more. | 864 return true; // No need to compact the crumbs more. |
| 869 return false; | 865 return false; |
| 870 } | 866 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 while (crumb) { | 940 while (crumb) { |
| 945 if (!crumb.classList.contains("hidden")) { | 941 if (!crumb.classList.contains("hidden")) { |
| 946 crumb.classList.add("start"); | 942 crumb.classList.add("start"); |
| 947 break; | 943 break; |
| 948 } | 944 } |
| 949 crumb = crumb.previousSibling; | 945 crumb = crumb.previousSibling; |
| 950 } | 946 } |
| 951 } | 947 } |
| 952 } | 948 } |
| 953 | 949 |
| 950 /** |
| 951 * @param {!Element} crumb |
| 952 */ |
| 954 function compact(crumb) | 953 function compact(crumb) |
| 955 { | 954 { |
| 956 if (crumb.classList.contains("hidden")) | 955 if (crumb.classList.contains("hidden")) |
| 957 return; | 956 return; |
| 958 crumb.classList.add("compact"); | 957 crumb.classList.add("compact"); |
| 959 } | 958 } |
| 960 | 959 |
| 960 /** |
| 961 * @param {!Element} crumb |
| 962 * @param {boolean=} dontCoalesce |
| 963 */ |
| 961 function collapse(crumb, dontCoalesce) | 964 function collapse(crumb, dontCoalesce) |
| 962 { | 965 { |
| 963 if (crumb.classList.contains("hidden")) | 966 if (crumb.classList.contains("hidden")) |
| 964 return; | 967 return; |
| 965 crumb.classList.add("collapsed"); | 968 crumb.classList.add("collapsed"); |
| 966 crumb.classList.remove("compact"); | 969 crumb.classList.remove("compact"); |
| 967 if (!dontCoalesce) | 970 if (!dontCoalesce) |
| 968 coalesceCollapsedCrumbs(); | 971 coalesceCollapsedCrumbs(); |
| 969 } | 972 } |
| 970 | 973 |
| 971 if (!focusedCrumb) { | 974 if (!focusedCrumb) { |
| 972 // When not focused on a crumb we can be biased and collapse less im
portant | 975 // When not focused on a crumb we can be biased and collapse less im
portant |
| 973 // crumbs that the user might not care much about. | 976 // crumbs that the user might not care much about. |
| 974 | 977 |
| 975 // Compact child crumbs. | 978 // Compact child crumbs. |
| 976 if (makeCrumbsSmaller(compact, ChildSide)) | 979 if (makeCrumbsSmaller(compact, ChildSide)) |
| 977 return; | 980 return; |
| 978 | 981 |
| 979 // Collapse child crumbs. | 982 // Collapse child crumbs. |
| 980 if (makeCrumbsSmaller(collapse, ChildSide)) | 983 if (makeCrumbsSmaller(collapse, ChildSide)) |
| 981 return; | 984 return; |
| 982 } | 985 } |
| 983 | 986 |
| 984 // Compact ancestor crumbs, or from both sides if focused. | 987 // Compact ancestor crumbs, or from both sides if focused. |
| 985 if (makeCrumbsSmaller(compact, (focusedCrumb ? BothSides : AncestorSide)
)) | 988 if (makeCrumbsSmaller(compact, focusedCrumb ? BothSides : AncestorSide)) |
| 986 return; | 989 return; |
| 987 | 990 |
| 988 // Collapse ancestor crumbs, or from both sides if focused. | 991 // Collapse ancestor crumbs, or from both sides if focused. |
| 989 if (makeCrumbsSmaller(collapse, (focusedCrumb ? BothSides : AncestorSide
))) | 992 if (makeCrumbsSmaller(collapse, focusedCrumb ? BothSides : AncestorSide)
) |
| 990 return; | 993 return; |
| 991 | 994 |
| 992 if (!selectedCrumb) | 995 if (!selectedCrumb) |
| 993 return; | 996 return; |
| 994 | 997 |
| 995 // Compact the selected crumb. | 998 // Compact the selected crumb. |
| 996 compact(selectedCrumb); | 999 compact(selectedCrumb); |
| 997 if (crumbsAreSmallerThanContainer()) | 1000 if (crumbsAreSmallerThanContainer()) |
| 998 return; | 1001 return; |
| 999 | 1002 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 return; | 1349 return; |
| 1347 | 1350 |
| 1348 if (WebInspector.inspectElementModeController && WebInspector.inspectEle
mentModeController.enabled()) { | 1351 if (WebInspector.inspectElementModeController && WebInspector.inspectEle
mentModeController.enabled()) { |
| 1349 InspectorFrontendHost.bringToFront(); | 1352 InspectorFrontendHost.bringToFront(); |
| 1350 WebInspector.inspectElementModeController.disable(); | 1353 WebInspector.inspectElementModeController.disable(); |
| 1351 } | 1354 } |
| 1352 | 1355 |
| 1353 /** @type {!WebInspector.ElementsPanel} */ (WebInspector.inspectorView.p
anel("elements")).revealAndSelectNode(node.id); | 1356 /** @type {!WebInspector.ElementsPanel} */ (WebInspector.inspectorView.p
anel("elements")).revealAndSelectNode(node.id); |
| 1354 } | 1357 } |
| 1355 } | 1358 } |
| OLD | NEW |