From 98514abecb414cf23393ecb915538844bdb93dd5 Mon Sep 17 00:00:00 2001 From: "pfeldman@chromium.org" Date: Wed, 8 Feb 2012 16:42:23 +0000 Subject: [PATCH] Web Inspector: bind entire subtree upon childNodeInserted so that text node were accounted. https://bugs.webkit.org/show_bug.cgi?id=78116 Reviewed by Yury Semikhatsky. Source/WebCore: * inspector/front-end/DOMAgent.js: (WebInspector.DOMNode): (WebInspector.DOMDocument): (WebInspector.DOMAgent.prototype._setDocument): (WebInspector.DOMAgent.prototype._setDetachedRoot): (WebInspector.DOMAgent.prototype._setChildNodes): (WebInspector.DOMAgent.prototype._childNodeRemoved): (WebInspector.DOMAgent.prototype._unbind): LayoutTests: * inspector/elements/insert-node-expected.txt: * inspector/elements/insert-node.html: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@107093 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- LayoutTests/ChangeLog | 10 ++++++ .../inspector/elements/insert-node-expected.txt | 13 ++++++++ LayoutTests/inspector/elements/insert-node.html | 29 ++++++++++++++++- Source/WebCore/ChangeLog | 16 ++++++++++ Source/WebCore/inspector/front-end/DOMAgent.js | 37 +++++++++------------- 5 files changed, 82 insertions(+), 23 deletions(-) diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 7714167..7d92739 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,13 @@ +2012-02-08 Pavel Feldman + + Web Inspector: bind entire subtree upon childNodeInserted so that text node were accounted. + https://bugs.webkit.org/show_bug.cgi?id=78116 + + Reviewed by Yury Semikhatsky. + + * inspector/elements/insert-node-expected.txt: + * inspector/elements/insert-node.html: + 2012-02-08 Michael Brüning [Qt][WK2] Compute and set cache capacities using the current CacheModel diff --git a/LayoutTests/inspector/elements/insert-node-expected.txt b/LayoutTests/inspector/elements/insert-node-expected.txt index 62fed0c..1fc3fbd 100644 --- a/LayoutTests/inspector/elements/insert-node-expected.txt +++ b/LayoutTests/inspector/elements/insert-node-expected.txt @@ -39,3 +39,16 @@ Running: testAppend
+Running: testAppendWithText +======== Appended with text========= +-
+
+
+
+
+
+
+ +
+Success: child text is bound + diff --git a/LayoutTests/inspector/elements/insert-node.html b/LayoutTests/inspector/elements/insert-node.html index c35f9b5..d68b38b 100644 --- a/LayoutTests/inspector/elements/insert-node.html +++ b/LayoutTests/inspector/elements/insert-node.html @@ -29,6 +29,16 @@ function appendChild() container.appendChild(child); } +function appendChildWithText() +{ + var container = document.getElementById("container"); + var child = document.createElement("div"); + child.style.display = "none"; + child.innerText = "Text"; + child.setAttribute("id", "child-with-text"); + container.appendChild(child); +} + function test() { var containerNode; @@ -69,7 +79,8 @@ function test() InspectorTest.evaluateInPage("insertNode()", callback); }, - function testAppend(next) { + function testAppend(next) + { function callback() { InspectorTest.addResult("======== Appended ========="); @@ -77,6 +88,22 @@ function test() next(); } InspectorTest.evaluateInPage("appendChild()", callback); + }, + + function testAppendWithText(next) + { + function callback() + { + InspectorTest.addResult("======== Appended with text========="); + InspectorTest.dumpElementsTree(containerNode); + var newNode = InspectorTest.expandedNodeWithId("child-with-text"); + if (WebInspector.domAgent.nodeForId(newNode.firstChild.id)) + InspectorTest.addResult("Success: child text is bound"); + else + InspectorTest.addResult("Failed: child text is not bound"); + next(); + } + InspectorTest.evaluateInPage("appendChildWithText()", callback); } ]); } diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 45b8d4a..c762983 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,19 @@ +2012-02-08 Pavel Feldman + + Web Inspector: bind entire subtree upon childNodeInserted so that text node were accounted. + https://bugs.webkit.org/show_bug.cgi?id=78116 + + Reviewed by Yury Semikhatsky. + + * inspector/front-end/DOMAgent.js: + (WebInspector.DOMNode): + (WebInspector.DOMDocument): + (WebInspector.DOMAgent.prototype._setDocument): + (WebInspector.DOMAgent.prototype._setDetachedRoot): + (WebInspector.DOMAgent.prototype._setChildNodes): + (WebInspector.DOMAgent.prototype._childNodeRemoved): + (WebInspector.DOMAgent.prototype._unbind): + 2012-02-08 Peter Rybin Web Inspector: Optional out arguments are not supported in the Web Inspector protocol, which breaks the implementation diff --git a/Source/WebCore/inspector/front-end/DOMAgent.js b/Source/WebCore/inspector/front-end/DOMAgent.js index 998b726..c17f203 100644 --- a/Source/WebCore/inspector/front-end/DOMAgent.js +++ b/Source/WebCore/inspector/front-end/DOMAgent.js @@ -40,6 +40,7 @@ WebInspector.DOMNode = function(domAgent, doc, payload) { this.ownerDocument = doc; this.id = payload.nodeId; + domAgent._idToDOMNode[this.id] = this; this._nodeType = payload.nodeType; this._nodeName = payload.nodeName; this._localName = payload.localName; @@ -644,7 +645,6 @@ WebInspector.DOMDocument = function(domAgent, payload) WebInspector.DOMNode.call(this, domAgent, this, payload); this.documentURL = payload.documentURL || ""; this.xmlVersion = payload.xmlVersion; - domAgent._idToDOMNode[this.id] = this; this._listeners = {}; } @@ -876,11 +876,9 @@ WebInspector.DOMAgent.prototype = { _setDocument: function(payload) { this._idToDOMNode = {}; - if (payload && "nodeId" in payload) { + if (payload && "nodeId" in payload) this._document = new WebInspector.DOMDocument(this, payload); - if (this._document.children) - this._bindNodes(this._document.children); - } else + else this._document = null; this.dispatchEventToListeners(WebInspector.DOMAgent.Events.DocumentUpdated, this._document); }, @@ -890,8 +888,7 @@ WebInspector.DOMAgent.prototype = { */ _setDetachedRoot: function(payload) { - var root = new WebInspector.DOMNode(this, null, payload); - this._idToDOMNode[payload.nodeId] = root; + new WebInspector.DOMNode(this, null, payload); }, /** @@ -907,20 +904,6 @@ WebInspector.DOMAgent.prototype = { var parent = this._idToDOMNode[parentId]; parent._setChildrenPayload(payloads); - this._bindNodes(parent.children); - }, - - /** - * @param {Array.} children - */ - _bindNodes: function(children) - { - for (var i = 0; i < children.length; ++i) { - var child = children[i]; - this._idToDOMNode[child.id] = child; - if (child.children) - this._bindNodes(child.children); - } }, /** @@ -957,8 +940,18 @@ WebInspector.DOMAgent.prototype = { var parent = this._idToDOMNode[parentId]; var node = this._idToDOMNode[nodeId]; parent._removeChild(node); + this._unbind(node); this.dispatchEventToListeners(WebInspector.DOMAgent.Events.NodeRemoved, {node:node, parent:parent}); - delete this._idToDOMNode[nodeId]; + }, + + /** + * @param {DOMAgent.Node} node + */ + _unbind: function(node) + { + delete this._idToDOMNode[node.id]; + for (var i = 0; node.children && i < node.children.length; ++i) + this._unbind(node.children[i]); }, /** -- 2.7.4