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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 }, | 631 }, |
632 | 632 |
633 _ondragstart: function(event) | 633 _ondragstart: function(event) |
634 { | 634 { |
635 if (!window.getSelection().isCollapsed) | 635 if (!window.getSelection().isCollapsed) |
636 return false; | 636 return false; |
637 if (event.target.nodeName === "A") | 637 if (event.target.nodeName === "A") |
638 return false; | 638 return false; |
639 | 639 |
640 var treeElement = this._treeElementFromEvent(event); | 640 var treeElement = this._treeElementFromEvent(event); |
641 if (!treeElement) | |
642 return false; | |
643 | |
644 if (!this._isValidDragSourceOrTarget(treeElement)) | 641 if (!this._isValidDragSourceOrTarget(treeElement)) |
645 return false; | 642 return false; |
646 | 643 |
647 if (treeElement._node.nodeName() === "BODY" || treeElement._node.nodeNam
e() === "HEAD") | 644 if (treeElement._node.nodeName() === "BODY" || treeElement._node.nodeNam
e() === "HEAD") |
648 return false; | 645 return false; |
649 | 646 |
650 event.dataTransfer.setData("text/plain", treeElement.listItemElement.tex
tContent.replace(/\u200b/g, "")); | 647 event.dataTransfer.setData("text/plain", treeElement.listItemElement.tex
tContent.replace(/\u200b/g, "")); |
651 event.dataTransfer.effectAllowed = "copyMove"; | 648 event.dataTransfer.effectAllowed = "copyMove"; |
652 this._treeElementBeingDragged = treeElement; | 649 this._treeElementBeingDragged = treeElement; |
653 | 650 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 | 686 |
690 /** | 687 /** |
691 * @param {?TreeElement} treeElement | 688 * @param {?TreeElement} treeElement |
692 * @return {boolean} | 689 * @return {boolean} |
693 */ | 690 */ |
694 _isValidDragSourceOrTarget: function(treeElement) | 691 _isValidDragSourceOrTarget: function(treeElement) |
695 { | 692 { |
696 if (!treeElement) | 693 if (!treeElement) |
697 return false; | 694 return false; |
698 | 695 |
699 var node = treeElement.representedObject; | 696 if (!(treeElement instanceof WebInspector.ElementsTreeElement)) |
700 if (!(node instanceof WebInspector.DOMNode)) | |
701 return false; | 697 return false; |
| 698 var elementsTreeElement = /** @type {!WebInspector.ElementsTreeElement}
*/ (treeElement); |
702 | 699 |
| 700 var node = elementsTreeElement._node; |
703 if (!node.parentNode || node.parentNode.nodeType() !== Node.ELEMENT_NODE
) | 701 if (!node.parentNode || node.parentNode.nodeType() !== Node.ELEMENT_NODE
) |
704 return false; | 702 return false; |
705 | 703 |
706 return true; | 704 return true; |
707 }, | 705 }, |
708 | 706 |
709 _ondrop: function(event) | 707 _ondrop: function(event) |
710 { | 708 { |
711 event.preventDefault(); | 709 event.preventDefault(); |
712 var treeElement = this._treeElementFromEvent(event); | 710 var treeElement = this._treeElementFromEvent(event); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 "area", "base", "basefont", "br", "canvas", "col", "command", "embed", "fram
e", | 1040 "area", "base", "basefont", "br", "canvas", "col", "command", "embed", "fram
e", |
1043 "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source
", "track", "wbr" | 1041 "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source
", "track", "wbr" |
1044 ].keySet(); | 1042 ].keySet(); |
1045 | 1043 |
1046 // These tags we do not allow editing their tag name. | 1044 // These tags we do not allow editing their tag name. |
1047 WebInspector.ElementsTreeElement.EditTagBlacklist = [ | 1045 WebInspector.ElementsTreeElement.EditTagBlacklist = [ |
1048 "html", "head", "body" | 1046 "html", "head", "body" |
1049 ].keySet(); | 1047 ].keySet(); |
1050 | 1048 |
1051 WebInspector.ElementsTreeElement.prototype = { | 1049 WebInspector.ElementsTreeElement.prototype = { |
| 1050 /** |
| 1051 * @return {!WebInspector.DOMNode} |
| 1052 */ |
| 1053 node: function() |
| 1054 { |
| 1055 return this._node; |
| 1056 }, |
| 1057 |
| 1058 /** |
| 1059 * @param {string} searchQuery |
| 1060 */ |
1052 highlightSearchResults: function(searchQuery) | 1061 highlightSearchResults: function(searchQuery) |
1053 { | 1062 { |
1054 if (this._searchQuery !== searchQuery) { | 1063 if (this._searchQuery !== searchQuery) { |
1055 this._updateSearchHighlight(false); | 1064 this._updateSearchHighlight(false); |
1056 delete this._highlightResult; // A new search query. | 1065 delete this._highlightResult; // A new search query. |
1057 } | 1066 } |
1058 | 1067 |
1059 this._searchQuery = searchQuery; | 1068 this._searchQuery = searchQuery; |
1060 this._searchHighlightsVisible = true; | 1069 this._searchHighlightsVisible = true; |
1061 this.updateTitle(true); | 1070 this.updateTitle(true); |
1062 }, | 1071 }, |
1063 | 1072 |
1064 hideSearchHighlights: function() | 1073 hideSearchHighlights: function() |
1065 { | 1074 { |
1066 delete this._searchHighlightsVisible; | 1075 delete this._searchHighlightsVisible; |
1067 this._updateSearchHighlight(false); | 1076 this._updateSearchHighlight(false); |
1068 }, | 1077 }, |
1069 | 1078 |
| 1079 /** |
| 1080 * @param {boolean} show |
| 1081 */ |
1070 _updateSearchHighlight: function(show) | 1082 _updateSearchHighlight: function(show) |
1071 { | 1083 { |
1072 if (!this._highlightResult) | 1084 if (!this._highlightResult) |
1073 return; | 1085 return; |
1074 | 1086 |
1075 function updateEntryShow(entry) | 1087 function updateEntryShow(entry) |
1076 { | 1088 { |
1077 switch (entry.type) { | 1089 switch (entry.type) { |
1078 case "added": | 1090 case "added": |
1079 entry.parent.insertBefore(entry.node, entry.nextSibling); | 1091 entry.parent.insertBefore(entry.node, entry.nextSibling); |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 if (this.hasChildren && !this.expanded) | 1568 if (this.hasChildren && !this.expanded) |
1557 this.expand(); | 1569 this.expand(); |
1558 return false; | 1570 return false; |
1559 }, | 1571 }, |
1560 | 1572 |
1561 /** | 1573 /** |
1562 * @return {boolean} | 1574 * @return {boolean} |
1563 */ | 1575 */ |
1564 hasEditableNode: function() | 1576 hasEditableNode: function() |
1565 { | 1577 { |
1566 return !this.representedObject.isShadowRoot() && !this.representedObject
.ancestorUserAgentShadowRoot(); | 1578 return !this._node.isShadowRoot() && !this._node.ancestorUserAgentShadow
Root(); |
1567 }, | 1579 }, |
1568 | 1580 |
1569 _insertInLastAttributePosition: function(tag, node) | 1581 _insertInLastAttributePosition: function(tag, node) |
1570 { | 1582 { |
1571 if (tag.getElementsByClassName("webkit-html-attribute").length > 0) | 1583 if (tag.getElementsByClassName("webkit-html-attribute").length > 0) |
1572 tag.insertBefore(node, tag.lastChild); | 1584 tag.insertBefore(node, tag.lastChild); |
1573 else { | 1585 else { |
1574 var nodeName = tag.textContent.match(/^<(.*?)>$/)[1]; | 1586 var nodeName = tag.textContent.match(/^<(.*?)>$/)[1]; |
1575 tag.textContent = ''; | 1587 tag.textContent = ''; |
1576 tag.createTextChild('<' + nodeName); | 1588 tag.createTextChild('<' + nodeName); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 _populateTextContextMenu: function(contextMenu, textNode) | 1674 _populateTextContextMenu: function(contextMenu, textNode) |
1663 { | 1675 { |
1664 if (!this._editing) | 1676 if (!this._editing) |
1665 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCa
seMenuTitles() ? "Edit text" : "Edit Text"), this._startEditingTextNode.bind(thi
s, textNode)); | 1677 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCa
seMenuTitles() ? "Edit text" : "Edit Text"), this._startEditingTextNode.bind(thi
s, textNode)); |
1666 this._populateNodeContextMenu(contextMenu); | 1678 this._populateNodeContextMenu(contextMenu); |
1667 }, | 1679 }, |
1668 | 1680 |
1669 _populateNodeContextMenu: function(contextMenu) | 1681 _populateNodeContextMenu: function(contextMenu) |
1670 { | 1682 { |
1671 // Add free-form node-related actions. | 1683 // Add free-form node-related actions. |
1672 var openTagElement = this.treeOutline.getCachedTreeElement(this.represen
tedObject) || this; | 1684 var openTagElement = this.treeOutline.getCachedTreeElement(this._node) |
| this; |
1673 var isEditable = this.hasEditableNode(); | 1685 var isEditable = this.hasEditableNode(); |
1674 if (isEditable && !this._editing) | 1686 if (isEditable && !this._editing) |
1675 contextMenu.appendItem(WebInspector.UIString("Edit as HTML"), openTa
gElement._editAsHTML.bind(openTagElement)); | 1687 contextMenu.appendItem(WebInspector.UIString("Edit as HTML"), openTa
gElement._editAsHTML.bind(openTagElement)); |
1676 var isShadowRoot = this.representedObject.isShadowRoot(); | 1688 var isShadowRoot = this._node.isShadowRoot(); |
1677 | 1689 |
1678 // Place it here so that all "Copy"-ing items stick together. | 1690 // Place it here so that all "Copy"-ing items stick together. |
1679 if (this.representedObject.nodeType() === Node.ELEMENT_NODE) | 1691 if (this._node.nodeType() === Node.ELEMENT_NODE) |
1680 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCa
seMenuTitles() ? "Copy CSS path" : "Copy CSS Path"), this._copyCSSPath.bind(this
)); | 1692 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCa
seMenuTitles() ? "Copy CSS path" : "Copy CSS Path"), this._copyCSSPath.bind(this
)); |
1681 if (!isShadowRoot) | 1693 if (!isShadowRoot) |
1682 contextMenu.appendItem(WebInspector.UIString("Copy XPath"), this._co
pyXPath.bind(this)); | 1694 contextMenu.appendItem(WebInspector.UIString("Copy XPath"), this._co
pyXPath.bind(this)); |
1683 if (!isShadowRoot) { | 1695 if (!isShadowRoot) { |
1684 var treeOutline = this.treeOutline; | 1696 var treeOutline = this.treeOutline; |
1685 contextMenu.appendSeparator(); | 1697 contextMenu.appendSeparator(); |
1686 contextMenu.appendItem(WebInspector.UIString("Cut"), treeOutline._pe
rformCopyOrCut.bind(treeOutline, true, this.representedObject), !this.hasEditabl
eNode()); | 1698 contextMenu.appendItem(WebInspector.UIString("Cut"), treeOutline._pe
rformCopyOrCut.bind(treeOutline, true, this._node), !this.hasEditableNode()); |
1687 contextMenu.appendItem(WebInspector.UIString("Copy"), treeOutline._p
erformCopyOrCut.bind(treeOutline, false, this.representedObject)); | 1699 contextMenu.appendItem(WebInspector.UIString("Copy"), treeOutline._p
erformCopyOrCut.bind(treeOutline, false, this._node)); |
1688 contextMenu.appendItem(WebInspector.UIString("Paste"), treeOutline._
pasteNode.bind(treeOutline, this.representedObject), !treeOutline._canPaste(this
.representedObject)); | 1700 contextMenu.appendItem(WebInspector.UIString("Paste"), treeOutline._
pasteNode.bind(treeOutline, this._node), !treeOutline._canPaste(this._node)); |
1689 } | 1701 } |
1690 | 1702 |
1691 if (isEditable) | 1703 if (isEditable) |
1692 contextMenu.appendItem(WebInspector.UIString("Delete"), this.remove.
bind(this)); | 1704 contextMenu.appendItem(WebInspector.UIString("Delete"), this.remove.
bind(this)); |
1693 contextMenu.appendSeparator(); | 1705 contextMenu.appendSeparator(); |
1694 }, | 1706 }, |
1695 | 1707 |
1696 _startEditing: function() | 1708 _startEditing: function() |
1697 { | 1709 { |
1698 if (this.treeOutline.selectedDOMNode() !== this._node) | 1710 if (this.treeOutline.selectedDOMNode() !== this._node) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 | 1755 |
1744 if (elem.classList.contains("webkit-html-attribute-value")) | 1756 if (elem.classList.contains("webkit-html-attribute-value")) |
1745 return this._startEditingAttribute(elem.parentNode, elem
); | 1757 return this._startEditingAttribute(elem.parentNode, elem
); |
1746 } | 1758 } |
1747 } | 1759 } |
1748 } | 1760 } |
1749 }, | 1761 }, |
1750 | 1762 |
1751 _startEditingAttribute: function(attribute, elementForSelection) | 1763 _startEditingAttribute: function(attribute, elementForSelection) |
1752 { | 1764 { |
| 1765 console.assert(this.listItemElement.isAncestor(attribute)); |
| 1766 |
1753 if (WebInspector.isBeingEdited(attribute)) | 1767 if (WebInspector.isBeingEdited(attribute)) |
1754 return true; | 1768 return true; |
1755 | 1769 |
1756 var attributeNameElement = attribute.getElementsByClassName("webkit-html
-attribute-name")[0]; | 1770 var attributeNameElement = attribute.getElementsByClassName("webkit-html
-attribute-name")[0]; |
1757 if (!attributeNameElement) | 1771 if (!attributeNameElement) |
1758 return false; | 1772 return false; |
1759 | 1773 |
1760 var attributeName = attributeNameElement.textContent; | 1774 var attributeName = attributeNameElement.textContent; |
1761 var attributeValueElement = attribute.getElementsByClassName("webkit-htm
l-attribute-value")[0]; | 1775 var attributeValueElement = attribute.getElementsByClassName("webkit-htm
l-attribute-value")[0]; |
1762 | 1776 |
1763 function removeZeroWidthSpaceRecursive(node) | 1777 function removeZeroWidthSpaceRecursive(node) |
1764 { | 1778 { |
1765 if (node.nodeType === Node.TEXT_NODE) { | 1779 if (node.nodeType === Node.TEXT_NODE) { |
1766 node.nodeValue = node.nodeValue.replace(/\u200B/g, ""); | 1780 node.nodeValue = node.nodeValue.replace(/\u200B/g, ""); |
1767 return; | 1781 return; |
1768 } | 1782 } |
1769 | 1783 |
1770 if (node.nodeType !== Node.ELEMENT_NODE) | 1784 if (node.nodeType !== Node.ELEMENT_NODE) |
1771 return; | 1785 return; |
1772 | 1786 |
1773 for (var child = node.firstChild; child; child = child.nextSibling) | 1787 for (var child = node.firstChild; child; child = child.nextSibling) |
1774 removeZeroWidthSpaceRecursive(child); | 1788 removeZeroWidthSpaceRecursive(child); |
1775 } | 1789 } |
1776 | 1790 |
1777 var domNode; | 1791 var attributeValue = attributeName && attributeValueElement ? this._node
.getAttribute(attributeName) : undefined; |
1778 var listItemElement = attribute.enclosingNodeOrSelfWithNodeName("li"); | 1792 if (attributeValue !== undefined) |
1779 if (attributeName && attributeValueElement && listItemElement && listIte
mElement.treeElement) | |
1780 domNode = listItemElement.treeElement.representedObject; | |
1781 var attributeValue = domNode ? domNode.getAttribute(attributeName) : und
efined; | |
1782 if (typeof attributeValue !== "undefined") | |
1783 attributeValueElement.textContent = attributeValue; | 1793 attributeValueElement.textContent = attributeValue; |
1784 | 1794 |
1785 // Remove zero-width spaces that were added by nodeTitleInfo. | 1795 // Remove zero-width spaces that were added by nodeTitleInfo. |
1786 removeZeroWidthSpaceRecursive(attribute); | 1796 removeZeroWidthSpaceRecursive(attribute); |
1787 | 1797 |
1788 var config = new WebInspector.InplaceEditor.Config(this._attributeEditin
gCommitted.bind(this), this._editingCancelled.bind(this), attributeName); | 1798 var config = new WebInspector.InplaceEditor.Config(this._attributeEditin
gCommitted.bind(this), this._editingCancelled.bind(this), attributeName); |
1789 | 1799 |
1790 function handleKeyDownEvents(event) | 1800 function handleKeyDownEvents(event) |
1791 { | 1801 { |
1792 var isMetaOrCtrl = WebInspector.isMac() ? | 1802 var isMetaOrCtrl = WebInspector.isMac() ? |
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2964 treeOutline.rootDOMNode = node; | 2974 treeOutline.rootDOMNode = node; |
2965 if (!treeOutline.children[0].hasChildren) | 2975 if (!treeOutline.children[0].hasChildren) |
2966 treeOutline._element.classList.add("single-node"); | 2976 treeOutline._element.classList.add("single-node"); |
2967 treeOutline.setVisible(true); | 2977 treeOutline.setVisible(true); |
2968 treeOutline.element.treeElementForTest = treeOutline.children[0]
; | 2978 treeOutline.element.treeElementForTest = treeOutline.children[0]
; |
2969 resolve(treeOutline.element); | 2979 resolve(treeOutline.element); |
2970 } | 2980 } |
2971 } | 2981 } |
2972 } | 2982 } |
2973 } | 2983 } |
OLD | NEW |