2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2009 Joseph Pecoraro
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 importScript("CSSNamedFlowCollectionsView.js");
32 importScript("CSSNamedFlowView.js");
33 importScript("EventListenersSidebarPane.js");
34 importScript("MetricsSidebarPane.js");
35 importScript("PropertiesSidebarPane.js");
36 importScript("StylesSidebarPane.js");
40 * @extends {WebInspector.Panel}
42 WebInspector.ElementsPanel = function()
44 WebInspector.Panel.call(this, "elements");
45 this.registerRequiredCSS("breadcrumbList.css");
46 this.registerRequiredCSS("elementsPanel.css");
47 this.registerRequiredCSS("textPrompt.css");
48 this.setHideOnDetach();
50 const initialSidebarWidth = 325;
51 const minimumContentWidthPercent = 34;
52 const initialSidebarHeight = 325;
53 const minimumContentHeightPercent = 34;
54 this.createSidebarView(this.element, WebInspector.SidebarView.SidebarPosition.End, initialSidebarWidth, initialSidebarHeight);
55 this.splitView.setMinimumSidebarWidth(Preferences.minElementsSidebarWidth);
56 this.splitView.setMinimumMainWidthPercent(minimumContentWidthPercent);
57 this.splitView.setMinimumSidebarHeight(Preferences.minElementsSidebarHeight);
58 this.splitView.setMinimumMainHeightPercent(minimumContentHeightPercent);
60 this.contentElement = this.splitView.mainElement;
61 this.contentElement.id = "elements-content";
62 this.contentElement.addStyleClass("outline-disclosure");
63 this.contentElement.addStyleClass("source-code");
64 if (!WebInspector.settings.domWordWrap.get())
65 this.contentElement.classList.add("nowrap");
66 WebInspector.settings.domWordWrap.addChangeListener(this._domWordWrapSettingChanged.bind(this));
68 this.contentElement.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
69 this.splitView.sidebarElement.addEventListener("contextmenu", this._sidebarContextMenuEventFired.bind(this), false);
71 this.treeOutline = new WebInspector.ElementsTreeOutline(true, true, false, this._populateContextMenu.bind(this), this._setPseudoClassForNodeId.bind(this));
72 this.treeOutline.wireToDomAgent();
74 this.treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedNodeChanged, this);
76 this.crumbsElement = document.createElement("div");
77 this.crumbsElement.className = "crumbs";
78 this.crumbsElement.addEventListener("mousemove", this._mouseMovedInCrumbs.bind(this), false);
79 this.crumbsElement.addEventListener("mouseout", this._mouseMovedOutOfCrumbs.bind(this), false);
81 this.sidebarPanes = {};
82 this.sidebarPanes.computedStyle = new WebInspector.ComputedStyleSidebarPane();
83 this.sidebarPanes.styles = new WebInspector.StylesSidebarPane(this.sidebarPanes.computedStyle, this._setPseudoClassForNodeId.bind(this));
84 this.sidebarPanes.metrics = new WebInspector.MetricsSidebarPane();
85 this.sidebarPanes.properties = new WebInspector.PropertiesSidebarPane();
86 this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane.createProxy(this);
87 this.sidebarPanes.eventListeners = new WebInspector.EventListenersSidebarPane();
89 this.sidebarPanes.styles.addEventListener(WebInspector.SidebarPane.EventTypes.wasShown, this.updateStyles.bind(this, false));
90 this.sidebarPanes.metrics.addEventListener(WebInspector.SidebarPane.EventTypes.wasShown, this.updateMetrics.bind(this));
91 this.sidebarPanes.properties.addEventListener(WebInspector.SidebarPane.EventTypes.wasShown, this.updateProperties.bind(this));
92 this.sidebarPanes.eventListeners.addEventListener(WebInspector.SidebarPane.EventTypes.wasShown, this.updateEventListeners.bind(this));
94 this.sidebarPanes.styles.addEventListener("style edited", this._stylesPaneEdited, this);
95 this.sidebarPanes.styles.addEventListener("style property toggled", this._stylesPaneEdited, this);
96 this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPaneEdited, this);
98 WebInspector.dockController.addEventListener(WebInspector.DockController.Events.DockSideChanged, this._dockSideChanged.bind(this));
99 WebInspector.settings.splitVerticallyWhenDockedToRight.addChangeListener(this._dockSideChanged.bind(this));
100 this._dockSideChanged();
102 this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this));
103 this._popoverHelper.setTimeout(0);
105 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._updateBreadcrumbIfNeeded, this);
106 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._updateBreadcrumbIfNeeded, this);
107 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeRemoved, this._nodeRemoved, this);
108 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdatedEvent, this);
109 WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.InspectElementRequested, this._inspectElementRequested, this);
111 if (WebInspector.domAgent.existingDocument())
112 this._documentUpdated(WebInspector.domAgent.existingDocument());
115 WebInspector.ElementsPanel.prototype = {
118 return [this.crumbsElement];
121 defaultFocusedElement: function()
123 return this.treeOutline.element;
126 statusBarResized: function()
128 this.updateBreadcrumbSizes();
133 // Attach heavy component lazily
134 if (this.treeOutline.element.parentElement !== this.contentElement)
135 this.contentElement.appendChild(this.treeOutline.element);
137 WebInspector.Panel.prototype.wasShown.call(this);
139 this.updateBreadcrumb();
140 this.treeOutline.updateSelection();
141 this.treeOutline.setVisible(true);
143 if (!this.treeOutline.rootDOMNode)
144 WebInspector.domAgent.requestDocument();
149 WebInspector.domAgent.hideDOMNodeHighlight();
150 this.treeOutline.setVisible(false);
151 this._popoverHelper.hidePopover();
153 // Detach heavy component on hide
154 this.contentElement.removeChild(this.treeOutline.element);
156 WebInspector.Panel.prototype.willHide.call(this);
161 this.treeOutline.updateSelection();
162 this.updateBreadcrumbSizes();
166 * @param {DOMAgent.NodeId} nodeId
167 * @param {string} pseudoClass
168 * @param {boolean} enable
170 _setPseudoClassForNodeId: function(nodeId, pseudoClass, enable)
172 var node = WebInspector.domAgent.nodeForId(nodeId);
176 var pseudoClasses = node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
178 pseudoClasses = pseudoClasses || [];
179 if (pseudoClasses.indexOf(pseudoClass) >= 0)
181 pseudoClasses.push(pseudoClass);
182 node.setUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName, pseudoClasses);
184 if (!pseudoClasses || pseudoClasses.indexOf(pseudoClass) < 0)
186 pseudoClasses.remove(pseudoClass);
187 if (!pseudoClasses.length)
188 node.removeUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
191 this.treeOutline.updateOpenCloseTags(node);
192 WebInspector.cssModel.forcePseudoState(node.id, node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName));
193 this._metricsPaneEdited();
194 this._stylesPaneEdited();
196 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
197 action: WebInspector.UserMetrics.UserActionNames.ForcedElementState,
198 selector: node.appropriateSelectorFor(false),
204 _selectedNodeChanged: function()
206 var selectedNode = this.selectedDOMNode();
207 if (!selectedNode && this._lastValidSelectedNode)
208 this._selectedPathOnReset = this._lastValidSelectedNode.path();
210 this.updateBreadcrumb(false);
212 this._updateSidebars();
215 ConsoleAgent.addInspectedNode(selectedNode.id);
216 this._lastValidSelectedNode = selectedNode;
218 WebInspector.notifications.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged);
221 _updateSidebars: function()
223 for (var pane in this.sidebarPanes)
224 this.sidebarPanes[pane].needsUpdate = true;
226 this.updateStyles(true);
227 this.updateMetrics();
228 this.updateProperties();
229 this.updateEventListeners();
234 delete this.currentQuery;
237 _documentUpdatedEvent: function(event)
239 this._documentUpdated(event.data);
242 _documentUpdated: function(inspectedRootDocument)
245 this.searchCanceled();
247 this.treeOutline.rootDOMNode = inspectedRootDocument;
249 if (!inspectedRootDocument) {
250 if (this.isShowing())
251 WebInspector.domAgent.requestDocument();
255 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints();
258 * @this {WebInspector.ElementsPanel}
259 * @param {WebInspector.DOMNode=} candidateFocusNode
261 function selectNode(candidateFocusNode)
263 if (!candidateFocusNode)
264 candidateFocusNode = inspectedRootDocument.body || inspectedRootDocument.documentElement;
266 if (!candidateFocusNode)
269 this.selectDOMNode(candidateFocusNode);
270 if (this.treeOutline.selectedTreeElement)
271 this.treeOutline.selectedTreeElement.expand();
274 function selectLastSelectedNode(nodeId)
276 if (this.selectedDOMNode()) {
277 // Focused node has been explicitly set while reaching out for the last selected node.
280 var node = nodeId ? WebInspector.domAgent.nodeForId(nodeId) : null;
281 selectNode.call(this, node);
284 if (this._selectedPathOnReset)
285 WebInspector.domAgent.pushNodeByPathToFrontend(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
287 selectNode.call(this);
288 delete this._selectedPathOnReset;
291 searchCanceled: function()
293 delete this._searchQuery;
294 this._hideSearchHighlights();
296 WebInspector.searchController.updateSearchMatchesCount(0, this);
298 delete this._currentSearchResultIndex;
299 delete this._searchResults;
300 WebInspector.domAgent.cancelSearch();
304 * @param {string} query
306 performSearch: function(query)
308 // Call searchCanceled since it will reset everything we need before doing a new search.
309 this.searchCanceled();
311 const whitespaceTrimmedQuery = query.trim();
312 if (!whitespaceTrimmedQuery.length)
315 this._searchQuery = query;
318 * @param {number} resultCount
320 function resultCountCallback(resultCount)
322 WebInspector.searchController.updateSearchMatchesCount(resultCount, this);
326 this._searchResults = new Array(resultCount);
327 this._currentSearchResultIndex = -1;
328 this.jumpToNextSearchResult();
330 WebInspector.domAgent.performSearch(whitespaceTrimmedQuery, resultCountCallback.bind(this));
333 _contextMenuEventFired: function(event)
335 function toggleWordWrap()
337 WebInspector.settings.domWordWrap.set(!WebInspector.settings.domWordWrap.get());
340 var contextMenu = new WebInspector.ContextMenu(event);
341 var populated = this.treeOutline.populateContextMenu(contextMenu, event);
343 if (WebInspector.experimentsSettings.cssRegions.isEnabled()) {
344 contextMenu.appendSeparator();
345 contextMenu.appendItem(WebInspector.UIString("CSS Named Flows..."), this._showNamedFlowCollections.bind(this));
348 contextMenu.appendSeparator();
349 contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Word wrap" : "Word Wrap"), toggleWordWrap.bind(this), WebInspector.settings.domWordWrap.get());
354 _showNamedFlowCollections: function()
356 if (!WebInspector.cssNamedFlowCollectionsView)
357 WebInspector.cssNamedFlowCollectionsView = new WebInspector.CSSNamedFlowCollectionsView();
358 WebInspector.cssNamedFlowCollectionsView.showInDrawer();
361 _domWordWrapSettingChanged: function(event)
364 this.contentElement.removeStyleClass("nowrap");
366 this.contentElement.addStyleClass("nowrap");
368 var selectedNode = this.selectedDOMNode();
372 var treeElement = this.treeOutline.findTreeElement(selectedNode);
374 treeElement.updateSelection(); // Recalculate selection highlight dimensions.
377 switchToAndFocus: function(node)
379 // Reset search restore.
380 WebInspector.searchController.cancelSearch();
381 WebInspector.inspectorView.setCurrentPanel(this);
382 this.selectDOMNode(node, true);
385 _populateContextMenu: function(contextMenu, node)
387 // Add debbuging-related actions
388 contextMenu.appendSeparator();
389 var pane = WebInspector.domBreakpointsSidebarPane;
390 pane.populateNodeContextMenu(node, contextMenu);
393 _getPopoverAnchor: function(element)
395 var anchor = element.enclosingNodeOrSelfWithClass("webkit-html-resource-link");
400 var resource = WebInspector.resourceTreeModel.resourceForURL(anchor.href);
401 if (!resource || resource.type !== WebInspector.resourceTypes.Image)
404 anchor.removeAttribute("title");
409 _loadDimensionsForNode: function(treeElement, callback)
411 // We get here for CSS properties, too, so bail out early for non-DOM treeElements.
412 if (treeElement.treeOutline !== this.treeOutline) {
417 var node = /** @type {WebInspector.DOMNode} */ (treeElement.representedObject);
419 if (!node.nodeName() || node.nodeName().toLowerCase() !== "img") {
424 WebInspector.RemoteObject.resolveNode(node, "", resolvedNode);
426 function resolvedNode(object)
433 object.callFunctionJSON(dimensions, undefined, callback);
436 function dimensions()
438 return { offsetWidth: this.offsetWidth, offsetHeight: this.offsetHeight, naturalWidth: this.naturalWidth, naturalHeight: this.naturalHeight };
444 * @param {Element} anchor
445 * @param {WebInspector.Popover} popover
447 _showPopover: function(anchor, popover)
449 var listItem = anchor.enclosingNodeOrSelfWithNodeName("li");
450 if (listItem && listItem.treeElement)
451 this._loadDimensionsForNode(listItem.treeElement, WebInspector.DOMPresentationUtils.buildImagePreviewContents.bind(WebInspector.DOMPresentationUtils, anchor.href, true, showPopover));
453 WebInspector.DOMPresentationUtils.buildImagePreviewContents(anchor.href, true, showPopover);
456 * @param {Element=} contents
458 function showPopover(contents)
462 popover.setCanShrink(false);
463 popover.show(contents, anchor);
467 jumpToNextSearchResult: function()
469 if (!this._searchResults)
472 this._hideSearchHighlights();
473 if (++this._currentSearchResultIndex >= this._searchResults.length)
474 this._currentSearchResultIndex = 0;
476 this._highlightCurrentSearchResult();
479 jumpToPreviousSearchResult: function()
481 if (!this._searchResults)
484 this._hideSearchHighlights();
485 if (--this._currentSearchResultIndex < 0)
486 this._currentSearchResultIndex = (this._searchResults.length - 1);
488 this._highlightCurrentSearchResult();
492 _highlightCurrentSearchResult: function()
494 var index = this._currentSearchResultIndex;
495 var searchResults = this._searchResults;
496 var searchResult = searchResults[index];
498 if (searchResult === null) {
499 WebInspector.searchController.updateCurrentMatchIndex(index, this);
503 if (typeof searchResult === "undefined") {
504 // No data for slot, request it.
505 function callback(node)
507 searchResults[index] = node || null;
508 this._highlightCurrentSearchResult();
510 WebInspector.domAgent.searchResult(index, callback.bind(this));
514 WebInspector.searchController.updateCurrentMatchIndex(index, this);
516 var treeElement = this.treeOutline.findTreeElement(searchResult);
518 treeElement.highlightSearchResults(this._searchQuery);
519 treeElement.reveal();
520 var matches = treeElement.listItemElement.getElementsByClassName("webkit-search-result");
522 matches[0].scrollIntoViewIfNeeded();
526 _hideSearchHighlights: function()
528 if (!this._searchResults)
530 var searchResult = this._searchResults[this._currentSearchResultIndex];
533 var treeElement = this.treeOutline.findTreeElement(searchResult);
535 treeElement.hideSearchHighlights();
538 selectedDOMNode: function()
540 return this.treeOutline.selectedDOMNode();
544 * @param {boolean=} focus
546 selectDOMNode: function(node, focus)
548 this.treeOutline.selectDOMNode(node, focus);
551 _nodeRemoved: function(event)
553 if (!this.isShowing())
556 var crumbs = this.crumbsElement;
557 for (var crumb = crumbs.firstChild; crumb; crumb = crumb.nextSibling) {
558 if (crumb.representedObject === event.data.node) {
559 this.updateBreadcrumb(true);
565 _stylesPaneEdited: function()
567 // Once styles are edited, the Metrics pane should be updated.
568 this.sidebarPanes.metrics.needsUpdate = true;
569 this.updateMetrics();
572 _metricsPaneEdited: function()
574 // Once metrics are edited, the Styles pane should be updated.
575 this.sidebarPanes.styles.needsUpdate = true;
576 this.updateStyles(true);
579 _mouseMovedInCrumbs: function(event)
581 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
582 var crumbElement = nodeUnderMouse.enclosingNodeOrSelfWithClass("crumb");
584 WebInspector.domAgent.highlightDOMNode(crumbElement ? crumbElement.representedObject.id : 0);
586 if ("_mouseOutOfCrumbsTimeout" in this) {
587 clearTimeout(this._mouseOutOfCrumbsTimeout);
588 delete this._mouseOutOfCrumbsTimeout;
592 _mouseMovedOutOfCrumbs: function(event)
594 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
595 if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.crumbsElement))
598 WebInspector.domAgent.hideDOMNodeHighlight();
600 this._mouseOutOfCrumbsTimeout = setTimeout(this.updateBreadcrumbSizes.bind(this), 1000);
603 _updateBreadcrumbIfNeeded: function(event)
605 var name = event.data.name;
606 if (name !== "class" && name !== "id")
609 var node = /** @type {WebInspector.DOMNode} */ (event.data.node);
610 var crumbs = this.crumbsElement;
611 var crumb = crumbs.firstChild;
613 if (crumb.representedObject === node) {
614 this.updateBreadcrumb(true);
617 crumb = crumb.nextSibling;
622 * @param {boolean=} forceUpdate
624 updateBreadcrumb: function(forceUpdate)
626 if (!this.isShowing())
629 var crumbs = this.crumbsElement;
632 var crumb = crumbs.firstChild;
634 if (crumb.representedObject === this.selectedDOMNode()) {
635 crumb.addStyleClass("selected");
638 crumb.removeStyleClass("selected");
641 crumb = crumb.nextSibling;
644 if (handled && !forceUpdate) {
645 // We don't need to rebuild the crumbs, but we need to adjust sizes
646 // to reflect the new focused or root node.
647 this.updateBreadcrumbSizes();
651 crumbs.removeChildren();
655 function selectCrumbFunction(event)
657 var crumb = event.currentTarget;
658 if (crumb.hasStyleClass("collapsed")) {
659 // Clicking a collapsed crumb will expose the hidden crumbs.
660 if (crumb === panel.crumbsElement.firstChild) {
661 // If the focused crumb is the first child, pick the farthest crumb
662 // that is still hidden. This allows the user to expose every crumb.
663 var currentCrumb = crumb;
664 while (currentCrumb) {
665 var hidden = currentCrumb.hasStyleClass("hidden");
666 var collapsed = currentCrumb.hasStyleClass("collapsed");
667 if (!hidden && !collapsed)
669 crumb = currentCrumb;
670 currentCrumb = currentCrumb.nextSibling;
674 panel.updateBreadcrumbSizes(crumb);
676 panel.selectDOMNode(crumb.representedObject, true);
678 event.preventDefault();
681 for (var current = this.selectedDOMNode(); current; current = current.parentNode) {
682 if (current.nodeType() === Node.DOCUMENT_NODE)
685 crumb = document.createElement("span");
686 crumb.className = "crumb";
687 crumb.representedObject = current;
688 crumb.addEventListener("mousedown", selectCrumbFunction, false);
691 switch (current.nodeType()) {
692 case Node.ELEMENT_NODE:
693 WebInspector.DOMPresentationUtils.decorateNodeLabel(current, crumb);
697 crumbTitle = WebInspector.UIString("(text)");
700 case Node.COMMENT_NODE:
701 crumbTitle = "<!-->";
704 case Node.DOCUMENT_TYPE_NODE:
705 crumbTitle = "<!DOCTYPE>";
709 crumbTitle = current.nodeNameInCorrectCase();
712 if (!crumb.childNodes.length) {
713 var nameElement = document.createElement("span");
714 nameElement.textContent = crumbTitle;
715 crumb.appendChild(nameElement);
716 crumb.title = crumbTitle;
719 if (current === this.selectedDOMNode())
720 crumb.addStyleClass("selected");
721 if (!crumbs.childNodes.length)
722 crumb.addStyleClass("end");
724 crumbs.appendChild(crumb);
727 if (crumbs.hasChildNodes())
728 crumbs.lastChild.addStyleClass("start");
730 this.updateBreadcrumbSizes();
734 * @param {Element=} focusedCrumb
736 updateBreadcrumbSizes: function(focusedCrumb)
738 if (!this.isShowing())
741 if (document.body.offsetWidth <= 0) {
742 // The stylesheet hasn't loaded yet or the window is closed,
743 // so we can't calculate what is need. Return early.
747 var crumbs = this.crumbsElement;
748 if (!crumbs.childNodes.length || crumbs.offsetWidth <= 0)
749 return; // No crumbs, do nothing.
751 // A Zero index is the right most child crumb in the breadcrumb.
752 var selectedIndex = 0;
753 var focusedIndex = 0;
757 var crumb = crumbs.firstChild;
759 // Find the selected crumb and index.
760 if (!selectedCrumb && crumb.hasStyleClass("selected")) {
761 selectedCrumb = crumb;
765 // Find the focused crumb index.
766 if (crumb === focusedCrumb)
769 // Remove any styles that affect size before
770 // deciding to shorten any crumbs.
771 if (crumb !== crumbs.lastChild)
772 crumb.removeStyleClass("start");
773 if (crumb !== crumbs.firstChild)
774 crumb.removeStyleClass("end");
776 crumb.removeStyleClass("compact");
777 crumb.removeStyleClass("collapsed");
778 crumb.removeStyleClass("hidden");
780 crumb = crumb.nextSibling;
784 // Restore the start and end crumb classes in case they got removed in coalesceCollapsedCrumbs().
785 // The order of the crumbs in the document is opposite of the visual order.
786 crumbs.firstChild.addStyleClass("end");
787 crumbs.lastChild.addStyleClass("start");
789 function crumbsAreSmallerThanContainer()
791 var rightPadding = 20;
792 var errorWarningElement = document.getElementById("error-warning-count");
793 if (!WebInspector.drawer.visible && errorWarningElement)
794 rightPadding += errorWarningElement.offsetWidth;
795 return ((crumbs.totalOffsetLeft() + crumbs.offsetWidth + rightPadding) < window.innerWidth);
798 if (crumbsAreSmallerThanContainer())
799 return; // No need to compact the crumbs, they all fit at full size.
802 var AncestorSide = -1;
806 * @param {boolean=} significantCrumb
808 function makeCrumbsSmaller(shrinkingFunction, direction, significantCrumb)
810 if (!significantCrumb)
811 significantCrumb = (focusedCrumb || selectedCrumb);
813 if (significantCrumb === selectedCrumb)
814 var significantIndex = selectedIndex;
815 else if (significantCrumb === focusedCrumb)
816 var significantIndex = focusedIndex;
818 var significantIndex = 0;
819 for (var i = 0; i < crumbs.childNodes.length; ++i) {
820 if (crumbs.childNodes[i] === significantCrumb) {
821 significantIndex = i;
827 function shrinkCrumbAtIndex(index)
829 var shrinkCrumb = crumbs.childNodes[index];
830 if (shrinkCrumb && shrinkCrumb !== significantCrumb)
831 shrinkingFunction(shrinkCrumb);
832 if (crumbsAreSmallerThanContainer())
833 return true; // No need to compact the crumbs more.
837 // Shrink crumbs one at a time by applying the shrinkingFunction until the crumbs
838 // fit in the container or we run out of crumbs to shrink.
840 // Crumbs are shrunk on only one side (based on direction) of the signifcant crumb.
841 var index = (direction > 0 ? 0 : crumbs.childNodes.length - 1);
842 while (index !== significantIndex) {
843 if (shrinkCrumbAtIndex(index))
845 index += (direction > 0 ? 1 : -1);
848 // Crumbs are shrunk in order of descending distance from the signifcant crumb,
849 // with a tie going to child crumbs.
851 var endIndex = crumbs.childNodes.length - 1;
852 while (startIndex != significantIndex || endIndex != significantIndex) {
853 var startDistance = significantIndex - startIndex;
854 var endDistance = endIndex - significantIndex;
855 if (startDistance >= endDistance)
856 var index = startIndex++;
858 var index = endIndex--;
859 if (shrinkCrumbAtIndex(index))
864 // We are not small enough yet, return false so the caller knows.
868 function coalesceCollapsedCrumbs()
870 var crumb = crumbs.firstChild;
871 var collapsedRun = false;
872 var newStartNeeded = false;
873 var newEndNeeded = false;
875 var hidden = crumb.hasStyleClass("hidden");
877 var collapsed = crumb.hasStyleClass("collapsed");
878 if (collapsedRun && collapsed) {
879 crumb.addStyleClass("hidden");
880 crumb.removeStyleClass("compact");
881 crumb.removeStyleClass("collapsed");
883 if (crumb.hasStyleClass("start")) {
884 crumb.removeStyleClass("start");
885 newStartNeeded = true;
888 if (crumb.hasStyleClass("end")) {
889 crumb.removeStyleClass("end");
896 collapsedRun = collapsed;
899 newEndNeeded = false;
900 crumb.addStyleClass("end");
904 crumb = crumb.nextSibling;
907 if (newStartNeeded) {
908 crumb = crumbs.lastChild;
910 if (!crumb.hasStyleClass("hidden")) {
911 crumb.addStyleClass("start");
914 crumb = crumb.previousSibling;
919 function compact(crumb)
921 if (crumb.hasStyleClass("hidden"))
923 crumb.addStyleClass("compact");
926 function collapse(crumb, dontCoalesce)
928 if (crumb.hasStyleClass("hidden"))
930 crumb.addStyleClass("collapsed");
931 crumb.removeStyleClass("compact");
933 coalesceCollapsedCrumbs();
937 // When not focused on a crumb we can be biased and collapse less important
938 // crumbs that the user might not care much about.
940 // Compact child crumbs.
941 if (makeCrumbsSmaller(compact, ChildSide))
944 // Collapse child crumbs.
945 if (makeCrumbsSmaller(collapse, ChildSide))
949 // Compact ancestor crumbs, or from both sides if focused.
950 if (makeCrumbsSmaller(compact, (focusedCrumb ? BothSides : AncestorSide)))
953 // Collapse ancestor crumbs, or from both sides if focused.
954 if (makeCrumbsSmaller(collapse, (focusedCrumb ? BothSides : AncestorSide)))
960 // Compact the selected crumb.
961 compact(selectedCrumb);
962 if (crumbsAreSmallerThanContainer())
965 // Collapse the selected crumb as a last resort. Pass true to prevent coalescing.
966 collapse(selectedCrumb, true);
970 * @param {boolean=} forceUpdate
972 updateStyles: function(forceUpdate)
974 var stylesSidebarPane = this.sidebarPanes.styles;
975 var computedStylePane = this.sidebarPanes.computedStyle;
976 if ((!stylesSidebarPane.isShowing() && !computedStylePane.isShowing()) || !stylesSidebarPane.needsUpdate)
979 stylesSidebarPane.update(this.selectedDOMNode(), forceUpdate);
980 stylesSidebarPane.needsUpdate = false;
983 updateMetrics: function()
985 var metricsSidebarPane = this.sidebarPanes.metrics;
986 if (!metricsSidebarPane.isShowing() || !metricsSidebarPane.needsUpdate)
989 metricsSidebarPane.update(this.selectedDOMNode());
990 metricsSidebarPane.needsUpdate = false;
993 updateProperties: function()
995 var propertiesSidebarPane = this.sidebarPanes.properties;
996 if (!propertiesSidebarPane.isShowing() || !propertiesSidebarPane.needsUpdate)
999 propertiesSidebarPane.update(this.selectedDOMNode());
1000 propertiesSidebarPane.needsUpdate = false;
1003 updateEventListeners: function()
1005 var eventListenersSidebarPane = this.sidebarPanes.eventListeners;
1006 if (!eventListenersSidebarPane.isShowing() || !eventListenersSidebarPane.needsUpdate)
1009 eventListenersSidebarPane.update(this.selectedDOMNode());
1010 eventListenersSidebarPane.needsUpdate = false;
1013 handleShortcut: function(event)
1015 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !event.shiftKey && event.keyIdentifier === "U+005A") { // Z key
1016 WebInspector.domAgent.undo(this._updateSidebars.bind(this));
1017 event.handled = true;
1021 var isRedoKey = WebInspector.isMac() ? event.metaKey && event.shiftKey && event.keyIdentifier === "U+005A" : // Z key
1022 event.ctrlKey && event.keyIdentifier === "U+0059"; // Y key
1024 DOMAgent.redo(this._updateSidebars.bind(this));
1025 event.handled = true;
1029 this.treeOutline.handleShortcut(event);
1032 handleCopyEvent: function(event)
1034 // Don't prevent the normal copy if the user has a selection.
1035 if (!window.getSelection().isCollapsed)
1037 event.clipboardData.clearData();
1038 event.preventDefault();
1039 this.selectedDOMNode().copyNode();
1042 sidebarResized: function(event)
1044 this.treeOutline.updateSelection();
1047 _inspectElementRequested: function(event)
1049 var node = event.data;
1050 this.revealAndSelectNode(node.id);
1053 revealAndSelectNode: function(nodeId)
1055 WebInspector.inspectorView.setCurrentPanel(this);
1057 var node = WebInspector.domAgent.nodeForId(nodeId);
1061 WebInspector.domAgent.highlightDOMNodeForTwoSeconds(nodeId);
1062 this.selectDOMNode(node, true);
1066 * @param {WebInspector.ContextMenu} contextMenu
1067 * @param {Object} target
1069 appendApplicableItems: function(event, contextMenu, target)
1071 if (!(target instanceof WebInspector.RemoteObject))
1073 var remoteObject = /** @type {WebInspector.RemoteObject} */ (target);
1074 if (remoteObject.subtype !== "node")
1077 function selectNode(nodeId)
1080 WebInspector.domAgent.inspectElement(nodeId);
1083 function revealElement()
1085 remoteObject.pushNodeToFrontend(selectNode);
1088 contextMenu.appendItem(WebInspector.UIString("Reveal in Elements Panel"), revealElement.bind(this));
1091 _sidebarContextMenuEventFired: function(event)
1093 var contextMenu = new WebInspector.ContextMenu(event);
1097 _dockSideChanged: function()
1099 var dockSide = WebInspector.dockController.dockSide();
1100 var vertically = dockSide === WebInspector.DockController.State.DockedToRight && WebInspector.settings.splitVerticallyWhenDockedToRight.get();
1101 this._splitVertically(vertically);
1105 * @param {boolean} vertically
1107 _splitVertically: function(vertically)
1109 if (this.sidebarPaneView && vertically === !this.splitView.isVertical())
1112 if (this.sidebarPaneView)
1113 this.sidebarPaneView.detach();
1115 this.splitView.setVertical(!vertically);
1118 this.sidebarPaneView = new WebInspector.SidebarPaneStack();
1119 for (var pane in this.sidebarPanes)
1120 this.sidebarPaneView.addPane(this.sidebarPanes[pane]);
1122 this.sidebarPaneView = new WebInspector.SplitView(true, this.name + "PanelSplitSidebarRatio", 0.5);
1124 var group1 = new WebInspector.SidebarTabbedPane();
1125 group1.show(this.sidebarPaneView.firstElement());
1126 group1.addPane(this.sidebarPanes.computedStyle);
1127 group1.addPane(this.sidebarPanes.styles);
1128 group1.addPane(this.sidebarPanes.metrics);
1130 var group2 = new WebInspector.SidebarTabbedPane();
1131 group2.show(this.sidebarPaneView.secondElement());
1132 group2.addPane(this.sidebarPanes.properties);
1133 group2.addPane(this.sidebarPanes.domBreakpoints);
1134 group2.addPane(this.sidebarPanes.eventListeners);
1136 this.sidebarPaneView.extensionPaneContainer = group2;
1138 this.sidebarPaneView.show(this.splitView.sidebarElement);
1139 this.sidebarPanes.styles.expand();
1143 * @param {string} id
1144 * @param {WebInspector.SidebarPane} pane
1146 addExtensionSidebarPane: function(id, pane)
1148 this.sidebarPanes[id] = pane;
1149 var container = this.sidebarPaneView.extensionPaneContainer || this.sidebarPaneView;
1150 container.addPane(pane);
1153 __proto__: WebInspector.Panel.prototype