Changeset 99401 in webkit


Ignore:
Timestamp:
Nov 7, 2011 1:59:27 AM (12 years ago)
Author:
apavlov@chromium.org
Message:

Web Inspector: Cannot edit elements commented with <!--
https://bugs.webkit.org/show_bug.cgi?id=71357

Reviewed by Pavel Feldman.

Source/WebCore:

  • inspector/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::getOuterHTML):
(WebCore::InspectorDOMAgent::setOuterHTML):

  • inspector/front-end/ElementsTreeOutline.js:

(WebInspector.ElementsTreeOutline.prototype.populateContextMenu):
(WebInspector.ElementsTreeElement.prototype._populateTagContextMenu):
(WebInspector.ElementsTreeElement.prototype._populateTextContextMenu):
(WebInspector.ElementsTreeElement.prototype._populateNodeContextMenu):

LayoutTests:

  • inspector/elements/edit-dom-actions-expected.txt:
  • inspector/elements/edit-dom-actions.html:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r99400 r99401  
     12011-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
    1112011-11-07  Philippe Normand  <pnormand@igalia.com>
    212
  • trunk/LayoutTests/inspector/elements/edit-dom-actions-expected.txt

    r90980 r99401  
    44Edited Text
    55Span contents
     6Element
    67
    78Running: testSetUp
     
    7677  </div>
    7778
     79Running: 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
    7890Running: testEditAsHTML
    7991==== before ====
  • trunk/LayoutTests/inspector/elements/edit-dom-actions.html

    r96711 r99401  
    1919        function testRemove(next)
    2020        {
    21             domActionTest("testRemove", "node-to-remove", testBody, next);
     21            domActionTestForNodeId("testRemove", "node-to-remove", testBody, next);
    2222
    2323            function testBody(node, done)
     
    3131        function testSetNodeName(next)
    3232        {
    33             domActionTest("testSetNodeName", "node-to-set-name", testBody, next);
     33            domActionTestForNodeId("testSetNodeName", "node-to-set-name", testBody, next);
    3434
    3535            function testBody(node, done)
     
    4141        function testSetNodeNameInput(next)
    4242        {
    43             domActionTest("testSetNodeNameInput", "node-to-set-name-input", testBody, next);
     43            domActionTestForNodeId("testSetNodeNameInput", "node-to-set-name-input", testBody, next);
    4444
    4545            function testBody(node, done)
     
    5151        function testSetNodeValue(next)
    5252        {
    53             domActionTest("testSetNodeValue", "node-to-set-value", testBody, next);
     53            domActionTestForNodeId("testSetNodeValue", "node-to-set-value", testBody, next);
    5454
    5555            function testBody(node, done)
     
    6161        function testSetAttribute(next)
    6262        {
    63             domActionTest("testSetAttribute", "node-to-set-attribute", testBody, next);
     63            domActionTestForNodeId("testSetAttribute", "node-to-set-attribute", testBody, next);
    6464         
    6565            function testBody(node, done)
     
    7171        function testRemoveAttribute(next)
    7272        {
    73             domActionTest("testRemoveAttribute", "node-to-remove-attribute", testBody, next);
     73            domActionTestForNodeId("testRemoveAttribute", "node-to-remove-attribute", testBody, next);
    7474         
    7575            function testBody(node, done)
     
    8181        function testAddAttribute(next)
    8282        {
    83             domActionTest("testAddAttribute", "node-to-add-attribute", testBody, next);
     83            domActionTestForNodeId("testAddAttribute", "node-to-add-attribute", testBody, next);
    8484         
    8585            function testBody(node, done)
     
    100100        },
    101101
     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
    102137        function testEditAsHTML(next)
    103138        {
    104             domActionTest("testEditAsHTML", "node-to-edit-as-html", testBody, next);
     139            domActionTestForNodeId("testEditAsHTML", "node-to-edit-as-html", testBody, next);
    105140
    106141            function testBody(node, done)
     
    117152                    event.isMetaOrCtrlForTest = true;
    118153                    treeElement._htmlEditElement.dispatchEvent(event);
    119                     InspectorTest.runAfterPendingDispatches(done);
     154                    InspectorTest.runAfterPendingDispatches(InspectorTest.expandElementsTree.bind(InspectorTest, done));
    120155                }
    121156            }
     
    123158    ]);
    124159
    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)
    126170    {
    127171        var testNode = InspectorTest.expandedNodeWithId(testName);
     
    129173        InspectorTest.dumpElementsTree(testNode);
    130174
    131         InspectorTest.selectNodeWithId(dataNode, step0);
     175        dataNodeSelectionCallback(testNode, step0);
    132176
    133177        function step0(node)
     
    209253        <div id="node-to-edit-as-html"><span id="span">Text</span></div>
    210254    </div>
     255
     256    <div id="testEditCommentAsHTML">
     257        <!-- Comment -->
     258    </div>
     259
    211260</div>
    212261</body>
  • trunk/Source/WebCore/ChangeLog

    r99397 r99401  
     12011-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
    1172011-11-06  Noel Gordon  <noel.gordon@gmail.com>
    218
  • trunk/Source/WebCore/inspector/InspectorDOMAgent.cpp

    r97771 r99401  
    5151#include "DOMWindow.h"
    5252#include "Document.h"
     53#include "DocumentFragment.h"
    5354#include "DocumentType.h"
    5455#include "Event.h"
     
    739740void InspectorDOMAgent::getOuterHTML(ErrorString* errorString, int nodeId, WTF::String* outerHTML)
    740741{
    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";
    744762}
    745763
    746764void InspectorDOMAgent::setOuterHTML(ErrorString* errorString, int nodeId, const String& outerHTML, int* newId)
    747765{
    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);
    757784
    758785    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";
    762795
    763796    if (requiresTotalUpdate) {
     
    769802    }
    770803
    771     Node* newNode = previousSibling ? previousSibling->nextSibling() : parentNode->firstChild();
     804    Node* newNode = previousSibling ? previousSibling->nextSibling() : parentElement->firstChild();
    772805    if (!newNode) {
    773806        // The only child node has been deleted.
     
    777810
    778811    *newId = pushNodePathToFrontend(newNode);
     812
     813    bool childrenRequested = m_childrenRequested.contains(nodeId);
    779814    if (childrenRequested)
    780815        pushChildNodesToFrontend(*newId);
  • trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js

    r98945 r99401  
    458458        var tag = event.target.enclosingNodeOrSelfWithClass("webkit-html-tag");
    459459        var textNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-text-node");
     460        var commentNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-comment");
    460461        var populated = WebInspector.populateHrefContextMenu(contextMenu, this.selectedDOMNode(), event);
    461462        if (tag && treeElement._populateTagContextMenu) {
     
    468469                contextMenu.appendSeparator();
    469470            treeElement._populateTextContextMenu(contextMenu, textNode);
     471            populated = true;
     472        } else if (commentNode && treeElement._populateNodeContextMenu) {
     473            if (populated)
     474                contextMenu.appendSeparator();
     475            treeElement._populateNodeContextMenu(contextMenu, textNode);
    470476            populated = true;
    471477        }
     
    10401046        contextMenu.appendSeparator();
    10411047
     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    {
    10421060        // Add free-form node-related actions.
    10431061        contextMenu.appendItem(WebInspector.UIString("Edit as HTML"), this._editAsHTML.bind(this));
    10441062        contextMenu.appendItem(WebInspector.UIString("Copy as HTML"), this._copyHTML.bind(this));
    10451063        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));
    10531064    },
    10541065
Note: See TracChangeset for help on using the changeset viewer.