Chromium Code Reviews| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 { | 419 { |
| 420 return this._selectedDOMNode; | 420 return this._selectedDOMNode; |
| 421 }, | 421 }, |
| 422 | 422 |
| 423 /** | 423 /** |
| 424 * @param {?WebInspector.DOMNode} node | 424 * @param {?WebInspector.DOMNode} node |
| 425 * @param {boolean=} focus | 425 * @param {boolean=} focus |
| 426 */ | 426 */ |
| 427 selectDOMNode: function(node, focus) | 427 selectDOMNode: function(node, focus) |
| 428 { | 428 { |
| 429 this.toggleNodeActions(false); | |
| 429 if (this._selectedDOMNode === node) { | 430 if (this._selectedDOMNode === node) { |
| 430 this._revealAndSelectNode(node, !focus); | 431 this._revealAndSelectNode(node, !focus); |
| 431 return; | 432 return; |
| 432 } | 433 } |
| 433 | 434 |
| 434 this._selectedDOMNode = node; | 435 this._selectedDOMNode = node; |
| 435 this._revealAndSelectNode(node, !focus); | 436 this._revealAndSelectNode(node, !focus); |
| 436 | 437 |
| 437 // The _revealAndSelectNode() method might find a different element if t here is inlined text, | 438 // The _revealAndSelectNode() method might find a different element if t here is inlined text, |
| 438 // and the select() call would change the selectedDOMNode and reenter th is setter. So to | 439 // and the select() call would change the selectedDOMNode and reenter th is setter. So to |
| 439 // avoid calling _selectedNodeChanged() twice, first check if _selectedD OMNode is the same | 440 // avoid calling _selectedNodeChanged() twice, first check if _selectedD OMNode is the same |
| 440 // node as the one passed in. | 441 // node as the one passed in. |
| 441 if (this._selectedDOMNode === node) | 442 if (this._selectedDOMNode === node) |
| 442 this._selectedNodeChanged(); | 443 this._selectedNodeChanged(); |
| 443 }, | 444 }, |
| 444 | 445 |
| 446 _createNodeToolbar: function() | |
|
pfeldman
2015/09/15 20:56:50
I think this all needs to be done on the elements
| |
| 447 { | |
| 448 var toolbar = new WebInspector.Toolbar(); | |
| 449 toolbar.element.classList.add("node-actions-toolbar"); | |
| 450 this._hideElementButton = new WebInspector.ToolbarButton(WebInspector.UI String("Hide element"), "visibility-off-toolbar-item"); | |
| 451 this._hideElementButton.setAction("elements.hide-element"); | |
| 452 toolbar.appendToolbarItem(this._hideElementButton); | |
| 453 this._forceElementStateButton = new WebInspector.ToolbarMenuButton(WebIn spector.UIString("Force element state"), "pin-toolbar-item", this._showForceElem entStateMenu.bind(this)); | |
| 454 toolbar.appendToolbarItem(this._forceElementStateButton); | |
| 455 this._breakpointsButton = new WebInspector.ToolbarMenuButton(WebInspecto r.UIString("Toggle breakpoints"), "add-breakpoint-toolbar-item", this._showBreak pointsMenu.bind(this)); | |
| 456 toolbar.appendToolbarItem(this._breakpointsButton); | |
| 457 toolbar.appendSeparator(); | |
| 458 this._editAsHTMLButton = new WebInspector.ToolbarButton(WebInspector.UIS tring("Edit as HTML"), "edit-toolbar-item"); | |
| 459 this._editAsHTMLButton.setAction("elements.edit-as-html"); | |
| 460 toolbar.appendToolbarItem(this._editAsHTMLButton); | |
| 461 return toolbar; | |
| 462 }, | |
| 463 | |
| 464 /** | |
| 465 * @return {!Element} | |
| 466 */ | |
| 467 nodeActionsElement: function() | |
| 468 { | |
| 469 if (this._nodeActionsElement) | |
| 470 return this._nodeActionsElement; | |
| 471 | |
| 472 this._nodeActionsElement = createElementWithClass("div", "node-actions-c ontainer"); | |
| 473 var button = this._nodeActionsElement.createChild("div", "node-actions-t oggle"); | |
| 474 button.addEventListener("click", this.toggleNodeActions.bind(this, null) ); | |
| 475 this._nodeActionsToolbar = this._createNodeToolbar(); | |
| 476 this._nodeActionsElement.appendChild(this._nodeActionsToolbar.element); | |
| 477 return this._nodeActionsElement; | |
| 478 }, | |
| 479 | |
| 480 /** | |
| 481 * @param {?boolean} toggled | |
| 482 */ | |
| 483 toggleNodeActions: function(toggled) | |
| 484 { | |
| 485 if (!this._nodeActionsElement) | |
| 486 return; | |
| 487 if (toggled === null) | |
| 488 toggled = !this.nodeActionsVisible(); | |
| 489 this._nodeActionsElement.classList.toggle("expanded", toggled); | |
| 490 var toolbarElement = this._nodeActionsToolbar.element; | |
| 491 if (toggled && toolbarElement.totalOffsetTop() < this.element.parentElem ent.totalOffsetTop()) { | |
| 492 toolbarElement.style.top = this._nodeActionsElement.parentElement.of fsetHeight + "px"; | |
| 493 toolbarElement.classList.add("node-actions-toolbar-below"); | |
| 494 } else { | |
| 495 toolbarElement.style.top = ""; | |
| 496 toolbarElement.classList.remove("node-actions-toolbar-below"); | |
| 497 } | |
| 498 }, | |
| 499 | |
| 445 /** | 500 /** |
| 446 * @return {boolean} | 501 * @return {boolean} |
| 447 */ | 502 */ |
| 503 nodeActionsVisible: function() | |
| 504 { | |
| 505 return this._nodeActionsElement.classList.contains("expanded"); | |
| 506 }, | |
| 507 | |
| 508 _updateToolbarButtons: function() | |
| 509 { | |
| 510 if (!Runtime.experiments.isEnabled("materialDesign")) | |
| 511 return; | |
| 512 var node = this.selectedDOMNode(); | |
| 513 if (!node) | |
| 514 return; | |
| 515 var classText = node.getAttribute("class"); | |
| 516 this._hideElementButton.setToggled(this.isToggledToHidden(node)); | |
| 517 this._editAsHTMLButton.setToggled(false); | |
| 518 this._breakpointsButton.setEnabled(!node.pseudoType()); | |
| 519 this._breakpointsButton.setToggled(WebInspector.domBreakpointsSidebarPan e.hasBreakpoints(node)); | |
| 520 this._forceElementStateButton.setEnabled(node.nodeType() === Node.ELEMEN T_NODE && !node.pseudoType()); | |
| 521 this._forceElementStateButton.setToggled(!!WebInspector.CSSStyleModel.fr omNode(node).pseudoState(node).length); | |
| 522 }, | |
| 523 | |
| 524 /** | |
| 525 * @param {!WebInspector.ContextMenu} contextMenu | |
| 526 */ | |
| 527 _showBreakpointsMenu: function(contextMenu) | |
| 528 { | |
| 529 var node = this.selectedDOMNode(); | |
| 530 if (!node) | |
| 531 return; | |
| 532 WebInspector.domBreakpointsSidebarPane.populateNodeContextMenu(node, con textMenu, false); | |
| 533 }, | |
| 534 | |
| 535 /** | |
| 536 * @param {!WebInspector.ContextMenu} contextMenu | |
| 537 */ | |
| 538 _showForceElementStateMenu: function(contextMenu) | |
| 539 { | |
| 540 var node = this.selectedDOMNode(); | |
| 541 if (!node) | |
| 542 return; | |
| 543 WebInspector.ElementsTreeElement.populateForcedPseudoStateItems(contextM enu, node); | |
| 544 }, | |
| 545 | |
| 546 /** | |
| 547 * @return {boolean} | |
| 548 */ | |
| 448 editing: function() | 549 editing: function() |
| 449 { | 550 { |
| 450 var node = this.selectedDOMNode(); | 551 var node = this.selectedDOMNode(); |
| 451 if (!node) | 552 if (!node) |
| 452 return false; | 553 return false; |
| 453 var treeElement = this.findTreeElement(node); | 554 var treeElement = this.findTreeElement(node); |
| 454 if (!treeElement) | 555 if (!treeElement) |
| 455 return false; | 556 return false; |
| 456 return treeElement.isEditing() || false; | 557 return treeElement.isEditing() || false; |
| 457 }, | 558 }, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 if (treeElement) | 605 if (treeElement) |
| 505 treeElement.updateTitle(this._updateRecordForHighlight(node)); | 606 treeElement.updateTitle(this._updateRecordForHighlight(node)); |
| 506 var closingTagElement = treeElement.lastChild(); | 607 var closingTagElement = treeElement.lastChild(); |
| 507 if (closingTagElement && closingTagElement.isClosingTag()) | 608 if (closingTagElement && closingTagElement.isClosingTag()) |
| 508 closingTagElement.updateTitle(this._updateRecordForHighlight(node)); | 609 closingTagElement.updateTitle(this._updateRecordForHighlight(node)); |
| 509 }, | 610 }, |
| 510 | 611 |
| 511 _selectedNodeChanged: function() | 612 _selectedNodeChanged: function() |
| 512 { | 613 { |
| 513 this.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.Se lectedNodeChanged, this._selectedDOMNode); | 614 this.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.Se lectedNodeChanged, this._selectedDOMNode); |
| 615 this._updateToolbarButtons(); | |
| 514 }, | 616 }, |
| 515 | 617 |
| 516 /** | 618 /** |
| 517 * @param {!Array.<!WebInspector.DOMNode>} nodes | 619 * @param {!Array.<!WebInspector.DOMNode>} nodes |
| 518 */ | 620 */ |
| 519 _fireElementsTreeUpdated: function(nodes) | 621 _fireElementsTreeUpdated: function(nodes) |
| 520 { | 622 { |
| 521 this.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.El ementsTreeUpdated, nodes); | 623 this.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.El ementsTreeUpdated, nodes); |
| 522 }, | 624 }, |
| 523 | 625 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 return; | 812 return; |
| 711 popover.setCanShrink(false); | 813 popover.setCanShrink(false); |
| 712 popover.showForAnchor(contents, anchor); | 814 popover.showForAnchor(contents, anchor); |
| 713 } | 815 } |
| 714 }, | 816 }, |
| 715 | 817 |
| 716 _onmousedown: function(event) | 818 _onmousedown: function(event) |
| 717 { | 819 { |
| 718 var element = this._treeElementFromEvent(event); | 820 var element = this._treeElementFromEvent(event); |
| 719 | 821 |
| 822 if (event.target.parentElement === this._nodeActionsElement) | |
| 823 return; | |
| 824 | |
| 720 if (!element || element.isEventWithinDisclosureTriangle(event)) | 825 if (!element || element.isEventWithinDisclosureTriangle(event)) |
| 721 return; | 826 return; |
| 722 | 827 |
| 723 element.select(); | 828 element.select(); |
| 724 }, | 829 }, |
| 725 | 830 |
| 726 _onmousemove: function(event) | 831 _onmousemove: function(event) |
| 727 { | 832 { |
| 728 var element = this._treeElementFromEvent(event); | 833 var element = this._treeElementFromEvent(event); |
| 729 if (element && this._previousHoveredElement === element) | 834 if (element && this._previousHoveredElement === element) |
| 730 return; | 835 return; |
| 731 | 836 |
| 732 if (this._previousHoveredElement) { | 837 if (this._previousHoveredElement) { |
| 733 this._previousHoveredElement.hovered = false; | 838 this._previousHoveredElement.hovered = false; |
| 734 delete this._previousHoveredElement; | 839 delete this._previousHoveredElement; |
| 735 } | 840 } |
| 736 | 841 |
| 842 if (Runtime.experiments.isEnabled("materialDesign") && event.target === this._nodeActionsToolbar.element) { | |
| 843 WebInspector.DOMModel.hideDOMNodeHighlight(); | |
| 844 return; | |
| 845 } | |
| 846 | |
| 737 if (element) { | 847 if (element) { |
| 738 element.hovered = true; | 848 element.hovered = true; |
| 739 this._previousHoveredElement = element; | 849 this._previousHoveredElement = element; |
| 740 } | 850 } |
| 741 | 851 |
| 742 if (element instanceof WebInspector.ElementsTreeElement) { | 852 if (element instanceof WebInspector.ElementsTreeElement) { |
| 743 this._domModel.highlightDOMNodeWithConfig(element.node().id, { mode: "all", showInfo: !WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) }); | 853 this._domModel.highlightDOMNodeWithConfig(element.node().id, { mode: "all", showInfo: !WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) }); |
| 744 return; | 854 return; |
| 745 } | 855 } |
| 746 | 856 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 if (event.keyIdentifier === "Down" && node.nextSibling) { | 1046 if (event.keyIdentifier === "Down" && node.nextSibling) { |
| 937 node.moveTo(node.parentNode, node.nextSibling.nextSibling, this. selectNodeAfterEdit.bind(this, treeElement.expanded)); | 1047 node.moveTo(node.parentNode, node.nextSibling.nextSibling, this. selectNodeAfterEdit.bind(this, treeElement.expanded)); |
| 938 event.handled = true; | 1048 event.handled = true; |
| 939 return; | 1049 return; |
| 940 } | 1050 } |
| 941 } | 1051 } |
| 942 }, | 1052 }, |
| 943 | 1053 |
| 944 /** | 1054 /** |
| 945 * @param {!WebInspector.DOMNode} node | 1055 * @param {!WebInspector.DOMNode} node |
| 946 * @param {boolean=} startEditing | |
| 947 * @param {function()=} callback | 1056 * @param {function()=} callback |
| 948 */ | 1057 */ |
| 949 toggleEditAsHTML: function(node, startEditing, callback) | 1058 toggleEditAsHTML: function(node, callback) |
| 950 { | 1059 { |
| 951 var treeElement = node[this._treeElementSymbol]; | 1060 var treeElement = node[this._treeElementSymbol]; |
| 952 if (!treeElement || !treeElement.hasEditableNode()) | 1061 if (!treeElement || !treeElement.hasEditableNode()) |
| 953 return; | 1062 return; |
| 954 | 1063 |
| 955 if (node.pseudoType()) | 1064 if (node.pseudoType()) |
| 956 return; | 1065 return; |
| 957 | 1066 |
| 958 var parentNode = node.parentNode; | 1067 var parentNode = node.parentNode; |
| 959 var index = node.index; | 1068 var index = node.index; |
| 960 var wasExpanded = treeElement.expanded; | 1069 var wasExpanded = treeElement.expanded; |
| 961 | 1070 |
| 1071 var startEditing = true; | |
| 1072 if (Runtime.experiments.isEnabled("materialDesign")) { | |
| 1073 startEditing = !this._editAsHTMLButton.toggled(); | |
| 1074 this._editAsHTMLButton.setToggled(startEditing); | |
| 1075 } | |
| 962 treeElement.toggleEditAsHTML(editingFinished.bind(this), startEditing); | 1076 treeElement.toggleEditAsHTML(editingFinished.bind(this), startEditing); |
| 963 | 1077 |
| 964 /** | 1078 /** |
| 965 * @this {WebInspector.ElementsTreeOutline} | 1079 * @this {WebInspector.ElementsTreeOutline} |
| 966 * @param {boolean} success | 1080 * @param {boolean} success |
| 967 */ | 1081 */ |
| 968 function editingFinished(success) | 1082 function editingFinished(success) |
| 969 { | 1083 { |
| 1084 this._updateToolbarButtons(); | |
| 970 if (callback) | 1085 if (callback) |
| 971 callback(); | 1086 callback(); |
| 972 if (!success) | 1087 if (!success) |
| 973 return; | 1088 return; |
| 974 | 1089 |
| 975 // Select it and expand if necessary. We force tree update so that i t processes dom events and is up to date. | 1090 // Select it and expand if necessary. We force tree update so that i t processes dom events and is up to date. |
| 976 this.runPendingUpdates(); | 1091 this.runPendingUpdates(); |
| 977 | 1092 |
| 978 var newNode = parentNode ? parentNode.children()[index] || parentNod e : null; | 1093 var newNode = parentNode ? parentNode.children()[index] || parentNod e : null; |
| 979 if (!newNode) | 1094 if (!newNode) |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 | 1696 |
| 1582 /** | 1697 /** |
| 1583 * @param {!WebInspector.Event} event | 1698 * @param {!WebInspector.Event} event |
| 1584 */ | 1699 */ |
| 1585 _markersChanged: function(event) | 1700 _markersChanged: function(event) |
| 1586 { | 1701 { |
| 1587 var node = /** @type {!WebInspector.DOMNode} */ (event.data); | 1702 var node = /** @type {!WebInspector.DOMNode} */ (event.data); |
| 1588 var treeElement = node[this._treeElementSymbol]; | 1703 var treeElement = node[this._treeElementSymbol]; |
| 1589 if (treeElement) | 1704 if (treeElement) |
| 1590 treeElement.updateDecorations(); | 1705 treeElement.updateDecorations(); |
| 1706 this._updateToolbarButtons(); | |
| 1591 }, | 1707 }, |
| 1592 | 1708 |
| 1593 __proto__: TreeOutline.prototype | 1709 __proto__: TreeOutline.prototype |
| 1594 } | 1710 } |
| 1595 | 1711 |
| 1596 /** | 1712 /** |
| 1597 * @constructor | 1713 * @constructor |
| 1598 */ | 1714 */ |
| 1599 WebInspector.ElementsTreeOutline.UpdateRecord = function() | 1715 WebInspector.ElementsTreeOutline.UpdateRecord = function() |
| 1600 { | 1716 { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 if (node) { | 1938 if (node) { |
| 1823 this.treeOutline._selectedDOMNode = node; | 1939 this.treeOutline._selectedDOMNode = node; |
| 1824 this.treeOutline._selectedNodeChanged(); | 1940 this.treeOutline._selectedNodeChanged(); |
| 1825 } | 1941 } |
| 1826 } | 1942 } |
| 1827 return true; | 1943 return true; |
| 1828 }, | 1944 }, |
| 1829 | 1945 |
| 1830 __proto__: TreeElement.prototype | 1946 __proto__: TreeElement.prototype |
| 1831 } | 1947 } |
| OLD | NEW |