Chromium Code Reviews| Index: Source/devtools/front_end/sdk/DOMModel.js |
| diff --git a/Source/devtools/front_end/sdk/DOMModel.js b/Source/devtools/front_end/sdk/DOMModel.js |
| index 7200bb47b76b9b76449128b9f959c681aae20a35..0d6acfa7cb0c8ecf1c8d3dd475cc792084f39204 100644 |
| --- a/Source/devtools/front_end/sdk/DOMModel.js |
| +++ b/Source/devtools/front_end/sdk/DOMModel.js |
| @@ -1076,6 +1076,7 @@ WebInspector.DOMModel.Events = { |
| AttrModified: "AttrModified", |
| AttrRemoved: "AttrRemoved", |
| CharacterDataModified: "CharacterDataModified", |
| + DOMMutatedThrottled: "DOMMutatedThrottled", |
|
lushnikov
2015/05/26 18:24:30
my suggestion about renaming this into DOMMutatedT
sergeyv
2015/05/26 21:09:06
Done.
|
| NodeInserted: "NodeInserted", |
| NodeInspected: "NodeInspected", |
| NodeRemoved: "NodeRemoved", |
| @@ -1126,6 +1127,28 @@ WebInspector.DOMModel.cancelSearch = function() |
| } |
| WebInspector.DOMModel.prototype = { |
| + |
|
lushnikov
2015/05/26 18:24:30
stray line
sergeyv
2015/05/26 21:09:06
Done.
|
| + _scheduleMutationEvent: function() |
| + { |
| + if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutatedThrottled)) |
| + return; |
| + |
| + this._lastMutationId = (this._lastMutationId || 0) + 1; |
| + Promise.resolve().then(callObserve.bind(this, this._lastMutationId)); |
| + |
| + /** |
| + * @this {WebInspector.DOMModel} |
| + * @param {number} mutationId |
| + */ |
| + function callObserve(mutationId) |
| + { |
| + if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutatedThrottled) || this._lastMutationId !== mutationId) |
| + return; |
| + |
| + this.dispatchEventToListeners(WebInspector.DOMModel.Events.DOMMutatedThrottled); |
| + } |
| + }, |
| + |
| /** |
| * @param {function(!WebInspector.DOMDocument)=} callback |
| */ |
| @@ -1286,6 +1309,7 @@ WebInspector.DOMModel.prototype = { |
| node._setAttribute(name, value); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrModified, { node: node, name: name }); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1299,6 +1323,7 @@ WebInspector.DOMModel.prototype = { |
| return; |
| node._removeAttribute(name); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrRemoved, { node: node, name: name }); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1329,8 +1354,10 @@ WebInspector.DOMModel.prototype = { |
| } |
| var node = this._idToDOMNode[nodeId]; |
| if (node) { |
| - if (node._setAttributesPayload(attributes)) |
| + if (node._setAttributesPayload(attributes)) { |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrModified, { node: node, name: "style" }); |
| + this._scheduleMutationEvent(); |
| + } |
| } |
| } |
| @@ -1352,6 +1379,7 @@ WebInspector.DOMModel.prototype = { |
| var node = this._idToDOMNode[nodeId]; |
| node._nodeValue = newValue; |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.CharacterDataModified, node); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1416,6 +1444,7 @@ WebInspector.DOMModel.prototype = { |
| var node = this._idToDOMNode[nodeId]; |
| node._childNodeCount = newValue; |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.ChildNodeCountUpdated, node); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1430,6 +1459,7 @@ WebInspector.DOMModel.prototype = { |
| var node = parent._insertChild(prev, payload); |
| this._idToDOMNode[node.id] = node; |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1443,6 +1473,7 @@ WebInspector.DOMModel.prototype = { |
| parent._removeChild(node); |
| this._unbind(node); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: node, parent: parent}); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1459,6 +1490,7 @@ WebInspector.DOMModel.prototype = { |
| this._idToDOMNode[node.id] = node; |
| host._shadowRoots.unshift(node); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1476,6 +1508,7 @@ WebInspector.DOMModel.prototype = { |
| host._removeChild(root); |
| this._unbind(root); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: root, parent: host}); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1493,6 +1526,7 @@ WebInspector.DOMModel.prototype = { |
| console.assert(!parent._pseudoElements.get(node.pseudoType())); |
| parent._pseudoElements.set(node.pseudoType(), node); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1510,6 +1544,7 @@ WebInspector.DOMModel.prototype = { |
| parent._removeChild(pseudoElement); |
| this._unbind(pseudoElement); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: pseudoElement, parent: parent}); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |
| @@ -1523,6 +1558,7 @@ WebInspector.DOMModel.prototype = { |
| return; |
| insertionPoint._setDistributedNodePayloads(distributedNodes); |
| this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNodesChanged, insertionPoint); |
| + this._scheduleMutationEvent(); |
| }, |
| /** |