Changeset 99401 in webkit
- Timestamp:
- Nov 7, 2011 1:59:27 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r99400 r99401 1 2011-11-07 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Cannot edit elements commented with <!-- 4 https://bugs.webkit.org/show_bug.cgi?id=71357 5 6 Reviewed by Pavel Feldman. 7 8 * inspector/elements/edit-dom-actions-expected.txt: 9 * inspector/elements/edit-dom-actions.html: 10 1 11 2011-11-07 Philippe Normand <pnormand@igalia.com> 2 12 -
trunk/LayoutTests/inspector/elements/edit-dom-actions-expected.txt
r90980 r99401 4 4 Edited Text 5 5 Span contents 6 Element 6 7 7 8 Running: testSetUp … … 76 77 </div> 77 78 79 Running: testEditCommentAsHTML 80 ==== before ==== 81 - <div id="testEditCommentAsHTML"> 82 <!-- Comment --> 83 </div> 84 <!-- Comment --> 85 ==== after ==== 86 - <div id="testEditCommentAsHTML"> 87 <div foo="bar-comment">Element</div> 88 </div> 89 78 90 Running: testEditAsHTML 79 91 ==== before ==== -
trunk/LayoutTests/inspector/elements/edit-dom-actions.html
r96711 r99401 19 19 function testRemove(next) 20 20 { 21 domActionTest ("testRemove", "node-to-remove", testBody, next);21 domActionTestForNodeId("testRemove", "node-to-remove", testBody, next); 22 22 23 23 function testBody(node, done) … … 31 31 function testSetNodeName(next) 32 32 { 33 domActionTest ("testSetNodeName", "node-to-set-name", testBody, next);33 domActionTestForNodeId("testSetNodeName", "node-to-set-name", testBody, next); 34 34 35 35 function testBody(node, done) … … 41 41 function testSetNodeNameInput(next) 42 42 { 43 domActionTest ("testSetNodeNameInput", "node-to-set-name-input", testBody, next);43 domActionTestForNodeId("testSetNodeNameInput", "node-to-set-name-input", testBody, next); 44 44 45 45 function testBody(node, done) … … 51 51 function testSetNodeValue(next) 52 52 { 53 domActionTest ("testSetNodeValue", "node-to-set-value", testBody, next);53 domActionTestForNodeId("testSetNodeValue", "node-to-set-value", testBody, next); 54 54 55 55 function testBody(node, done) … … 61 61 function testSetAttribute(next) 62 62 { 63 domActionTest ("testSetAttribute", "node-to-set-attribute", testBody, next);63 domActionTestForNodeId("testSetAttribute", "node-to-set-attribute", testBody, next); 64 64 65 65 function testBody(node, done) … … 71 71 function testRemoveAttribute(next) 72 72 { 73 domActionTest ("testRemoveAttribute", "node-to-remove-attribute", testBody, next);73 domActionTestForNodeId("testRemoveAttribute", "node-to-remove-attribute", testBody, next); 74 74 75 75 function testBody(node, done) … … 81 81 function testAddAttribute(next) 82 82 { 83 domActionTest ("testAddAttribute", "node-to-add-attribute", testBody, next);83 domActionTestForNodeId("testAddAttribute", "node-to-add-attribute", testBody, next); 84 84 85 85 function testBody(node, done) … … 100 100 }, 101 101 102 function testEditCommentAsHTML(next) 103 { 104 function commentNodeSelectionCallback(testNode, callback) 105 { 106 var childNodes = testNode.children; 107 for (var i = 0; i < childNodes.length; ++i) { 108 if (childNodes[i].nodeType() === 8) { 109 WebInspector.updateFocusedNode(childNodes[i].id); 110 callback(childNodes[i]); 111 return; 112 } 113 } 114 InspectorTest.addResult("Comment node not found"); 115 InspectorTest.completeTest(); 116 } 117 domActionTest("testEditCommentAsHTML", commentNodeSelectionCallback, testBody, next); 118 119 function testBody(node, done) 120 { 121 var treeElement = WebInspector.panels.elements.treeOutline.findTreeElement(node); 122 treeElement._editAsHTML(); 123 InspectorTest.runAfterPendingDispatches(step2); 124 125 function step2() 126 { 127 InspectorTest.addResult(treeElement._htmlEditElement.textContent); 128 treeElement._htmlEditElement.textContent = "<div foo=\"bar-comment\">Element</div>"; 129 var event = InspectorTest.createKeyEvent("Enter"); 130 event.isMetaOrCtrlForTest = true; 131 treeElement._htmlEditElement.dispatchEvent(event); 132 InspectorTest.runAfterPendingDispatches(done); 133 } 134 } 135 }, 136 102 137 function testEditAsHTML(next) 103 138 { 104 domActionTest ("testEditAsHTML", "node-to-edit-as-html", testBody, next);139 domActionTestForNodeId("testEditAsHTML", "node-to-edit-as-html", testBody, next); 105 140 106 141 function testBody(node, done) … … 117 152 event.isMetaOrCtrlForTest = true; 118 153 treeElement._htmlEditElement.dispatchEvent(event); 119 InspectorTest.runAfterPendingDispatches( done);154 InspectorTest.runAfterPendingDispatches(InspectorTest.expandElementsTree.bind(InspectorTest, done)); 120 155 } 121 156 } … … 123 158 ]); 124 159 125 function domActionTest(testName, dataNode, testBody, next) 160 function domActionTestForNodeId(testName, dataNodeId, testBody, next) 161 { 162 function callback(testNode, continuation) 163 { 164 InspectorTest.selectNodeWithId(dataNodeId, continuation); 165 } 166 domActionTest(testName, callback, testBody, next); 167 } 168 169 function domActionTest(testName, dataNodeSelectionCallback, testBody, next) 126 170 { 127 171 var testNode = InspectorTest.expandedNodeWithId(testName); … … 129 173 InspectorTest.dumpElementsTree(testNode); 130 174 131 InspectorTest.selectNodeWithId(dataNode, step0);175 dataNodeSelectionCallback(testNode, step0); 132 176 133 177 function step0(node) … … 209 253 <div id="node-to-edit-as-html"><span id="span">Text</span></div> 210 254 </div> 255 256 <div id="testEditCommentAsHTML"> 257 <!-- Comment --> 258 </div> 259 211 260 </div> 212 261 </body> -
trunk/Source/WebCore/ChangeLog
r99397 r99401 1 2011-11-07 Alexander Pavlov <apavlov@chromium.org> 2 3 Web Inspector: Cannot edit elements commented with <!-- 4 https://bugs.webkit.org/show_bug.cgi?id=71357 5 6 Reviewed by Pavel Feldman. 7 8 * inspector/InspectorDOMAgent.cpp: 9 (WebCore::InspectorDOMAgent::getOuterHTML): 10 (WebCore::InspectorDOMAgent::setOuterHTML): 11 * inspector/front-end/ElementsTreeOutline.js: 12 (WebInspector.ElementsTreeOutline.prototype.populateContextMenu): 13 (WebInspector.ElementsTreeElement.prototype._populateTagContextMenu): 14 (WebInspector.ElementsTreeElement.prototype._populateTextContextMenu): 15 (WebInspector.ElementsTreeElement.prototype._populateNodeContextMenu): 16 1 17 2011-11-06 Noel Gordon <noel.gordon@gmail.com> 2 18 -
trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp
r97771 r99401 51 51 #include "DOMWindow.h" 52 52 #include "Document.h" 53 #include "DocumentFragment.h" 53 54 #include "DocumentType.h" 54 55 #include "Event.h" … … 739 740 void InspectorDOMAgent::getOuterHTML(ErrorString* errorString, int nodeId, WTF::String* outerHTML) 740 741 { 741 HTMLElement* element = assertHTMLElement(errorString, nodeId); 742 if (element) 743 *outerHTML = element->outerHTML(); 742 Node* node = assertNode(errorString, nodeId); 743 if (!node) 744 return; 745 746 if (node->isHTMLElement()) { 747 *outerHTML = static_cast<HTMLElement*>(node)->outerHTML(); 748 return; 749 } 750 751 if (node->isCommentNode()) { 752 *outerHTML = "<!--" + node->nodeValue() + "-->"; 753 return; 754 } 755 756 if (node->isTextNode()) { 757 *outerHTML = node->nodeValue(); 758 return; 759 } 760 761 *errorString = "Only HTMLElements, Comments, and Text nodes are supported"; 744 762 } 745 763 746 764 void InspectorDOMAgent::setOuterHTML(ErrorString* errorString, int nodeId, const String& outerHTML, int* newId) 747 765 { 748 HTMLElement* htmlElement = assertHTMLElement(errorString, nodeId); 749 if (!htmlElement) 750 return; 751 752 bool requiresTotalUpdate = htmlElement->tagName() == "HTML" || htmlElement->tagName() == "BODY" || htmlElement->tagName() == "HEAD"; 753 754 bool childrenRequested = m_childrenRequested.contains(nodeId); 755 Node* previousSibling = htmlElement->previousSibling(); 756 ContainerNode* parentNode = htmlElement->parentNode(); 766 Node* node = assertNode(errorString, nodeId); 767 if (!node) 768 return; 769 770 Element* parentElement = node->parentElement(); 771 if (!parentElement) 772 return; 773 774 Document* document = node->ownerDocument(); 775 if (!document->isHTMLDocument()) { 776 *errorString = "Not an HTML document"; 777 return; 778 } 779 780 Node* previousSibling = node->previousSibling(); // Remember previous sibling before replacing node. 781 782 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); 783 fragment->parseHTML(outerHTML, parentElement); 757 784 758 785 ExceptionCode ec = 0; 759 htmlElement->setOuterHTML(outerHTML, ec); 760 if (ec) 761 return; 786 parentElement->replaceChild(fragment.release(), node, ec); 787 if (ec) { 788 *errorString = "Failed to replace Node with new contents"; 789 return; 790 } 791 792 bool requiresTotalUpdate = false; 793 if (node->isHTMLElement()) 794 requiresTotalUpdate = node->nodeName() == "HTML" || node->nodeName() == "BODY" || node->nodeName() == "HEAD"; 762 795 763 796 if (requiresTotalUpdate) { … … 769 802 } 770 803 771 Node* newNode = previousSibling ? previousSibling->nextSibling() : parent Node->firstChild();804 Node* newNode = previousSibling ? previousSibling->nextSibling() : parentElement->firstChild(); 772 805 if (!newNode) { 773 806 // The only child node has been deleted. … … 777 810 778 811 *newId = pushNodePathToFrontend(newNode); 812 813 bool childrenRequested = m_childrenRequested.contains(nodeId); 779 814 if (childrenRequested) 780 815 pushChildNodesToFrontend(*newId); -
trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js
r98945 r99401 458 458 var tag = event.target.enclosingNodeOrSelfWithClass("webkit-html-tag"); 459 459 var textNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-text-node"); 460 var commentNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-comment"); 460 461 var populated = WebInspector.populateHrefContextMenu(contextMenu, this.selectedDOMNode(), event); 461 462 if (tag && treeElement._populateTagContextMenu) { … … 468 469 contextMenu.appendSeparator(); 469 470 treeElement._populateTextContextMenu(contextMenu, textNode); 471 populated = true; 472 } else if (commentNode && treeElement._populateNodeContextMenu) { 473 if (populated) 474 contextMenu.appendSeparator(); 475 treeElement._populateNodeContextMenu(contextMenu, textNode); 470 476 populated = true; 471 477 } … … 1040 1046 contextMenu.appendSeparator(); 1041 1047 1048 this._populateNodeContextMenu(contextMenu); 1049 this.treeOutline._populateContextMenu(contextMenu, this.representedObject); 1050 }, 1051 1052 _populateTextContextMenu: function(contextMenu, textNode) 1053 { 1054 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit text" : "Edit Text"), this._startEditingTextNode.bind(this, textNode)); 1055 this._populateNodeContextMenu(contextMenu); 1056 }, 1057 1058 _populateNodeContextMenu: function(contextMenu) 1059 { 1042 1060 // Add free-form node-related actions. 1043 1061 contextMenu.appendItem(WebInspector.UIString("Edit as HTML"), this._editAsHTML.bind(this)); 1044 1062 contextMenu.appendItem(WebInspector.UIString("Copy as HTML"), this._copyHTML.bind(this)); 1045 1063 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Delete node" : "Delete Node"), this.remove.bind(this)); 1046 1047 this.treeOutline._populateContextMenu(contextMenu, this.representedObject);1048 },1049 1050 _populateTextContextMenu: function(contextMenu, textNode)1051 {1052 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit text" : "Edit Text"), this._startEditingTextNode.bind(this, textNode));1053 1064 }, 1054 1065
Note: See TracChangeset
for help on using the changeset viewer.