OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 this._defaultHighlighter = new WebInspector.DefaultDOMNodeHighlighter(this._ agent); | 1069 this._defaultHighlighter = new WebInspector.DefaultDOMNodeHighlighter(this._ agent); |
1070 this._highlighter = this._defaultHighlighter; | 1070 this._highlighter = this._defaultHighlighter; |
1071 | 1071 |
1072 this._agent.enable(); | 1072 this._agent.enable(); |
1073 } | 1073 } |
1074 | 1074 |
1075 WebInspector.DOMModel.Events = { | 1075 WebInspector.DOMModel.Events = { |
1076 AttrModified: "AttrModified", | 1076 AttrModified: "AttrModified", |
1077 AttrRemoved: "AttrRemoved", | 1077 AttrRemoved: "AttrRemoved", |
1078 CharacterDataModified: "CharacterDataModified", | 1078 CharacterDataModified: "CharacterDataModified", |
1079 DOMMutated: "DOMMutated", | |
1079 NodeInserted: "NodeInserted", | 1080 NodeInserted: "NodeInserted", |
1080 NodeInspected: "NodeInspected", | 1081 NodeInspected: "NodeInspected", |
1081 NodeRemoved: "NodeRemoved", | 1082 NodeRemoved: "NodeRemoved", |
1082 DocumentUpdated: "DocumentUpdated", | 1083 DocumentUpdated: "DocumentUpdated", |
1083 ChildNodeCountUpdated: "ChildNodeCountUpdated", | 1084 ChildNodeCountUpdated: "ChildNodeCountUpdated", |
1084 UndoRedoRequested: "UndoRedoRequested", | 1085 UndoRedoRequested: "UndoRedoRequested", |
1085 UndoRedoCompleted: "UndoRedoCompleted", | 1086 UndoRedoCompleted: "UndoRedoCompleted", |
1086 DistributedNodesChanged: "DistributedNodesChanged", | 1087 DistributedNodesChanged: "DistributedNodesChanged", |
1087 ModelSuspended: "ModelSuspended", | 1088 ModelSuspended: "ModelSuspended", |
1088 InspectModeWillBeToggled: "InspectModeWillBeToggled" | 1089 InspectModeWillBeToggled: "InspectModeWillBeToggled" |
(...skipping 30 matching lines...) Expand all Loading... | |
1119 domModel.highlightDOMNode(0); | 1120 domModel.highlightDOMNode(0); |
1120 } | 1121 } |
1121 | 1122 |
1122 WebInspector.DOMModel.cancelSearch = function() | 1123 WebInspector.DOMModel.cancelSearch = function() |
1123 { | 1124 { |
1124 for (var domModel of WebInspector.DOMModel.instances()) | 1125 for (var domModel of WebInspector.DOMModel.instances()) |
1125 domModel._cancelSearch(); | 1126 domModel._cancelSearch(); |
1126 } | 1127 } |
1127 | 1128 |
1128 WebInspector.DOMModel.prototype = { | 1129 WebInspector.DOMModel.prototype = { |
1130 | |
1131 _fireMutationEvent: function() | |
pfeldman
2015/05/05 14:13:07
_scheduleMutationEvent
sergeyv
2015/05/06 08:35:54
Done.
| |
1132 { | |
1133 if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutated)) | |
1134 return; | |
1135 | |
1136 this._lastMutationId = (this._lastMutationId || 0) + 1; | |
1137 Promise.resolve().then(callObserve.bind(this, this._lastMutationId)); | |
1138 | |
1139 /** | |
1140 * @this {WebInspector.DOMModel} | |
1141 * @param {number} mutationId | |
1142 */ | |
1143 function callObserve(mutationId) | |
1144 { | |
1145 if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutated) || this._lastMutationId !== mutationId) | |
1146 return; | |
1147 | |
1148 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DOMMutate d); | |
1149 } | |
1150 }, | |
1151 | |
1129 /** | 1152 /** |
1130 * @param {function(!WebInspector.DOMDocument)=} callback | 1153 * @param {function(!WebInspector.DOMDocument)=} callback |
1131 */ | 1154 */ |
1132 requestDocument: function(callback) | 1155 requestDocument: function(callback) |
1133 { | 1156 { |
1134 if (this._document) { | 1157 if (this._document) { |
1135 if (callback) | 1158 if (callback) |
1136 callback(this._document); | 1159 callback(this._document); |
1137 return; | 1160 return; |
1138 } | 1161 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1423 * @param {!DOMAgent.NodeId} prevId | 1446 * @param {!DOMAgent.NodeId} prevId |
1424 * @param {!DOMAgent.Node} payload | 1447 * @param {!DOMAgent.Node} payload |
1425 */ | 1448 */ |
1426 _childNodeInserted: function(parentId, prevId, payload) | 1449 _childNodeInserted: function(parentId, prevId, payload) |
1427 { | 1450 { |
1428 var parent = this._idToDOMNode[parentId]; | 1451 var parent = this._idToDOMNode[parentId]; |
1429 var prev = this._idToDOMNode[prevId]; | 1452 var prev = this._idToDOMNode[prevId]; |
1430 var node = parent._insertChild(prev, payload); | 1453 var node = parent._insertChild(prev, payload); |
1431 this._idToDOMNode[node.id] = node; | 1454 this._idToDOMNode[node.id] = node; |
1432 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1455 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1456 this._fireMutationEvent(); | |
1433 }, | 1457 }, |
1434 | 1458 |
1435 /** | 1459 /** |
1436 * @param {!DOMAgent.NodeId} parentId | 1460 * @param {!DOMAgent.NodeId} parentId |
1437 * @param {!DOMAgent.NodeId} nodeId | 1461 * @param {!DOMAgent.NodeId} nodeId |
1438 */ | 1462 */ |
1439 _childNodeRemoved: function(parentId, nodeId) | 1463 _childNodeRemoved: function(parentId, nodeId) |
1440 { | 1464 { |
1441 var parent = this._idToDOMNode[parentId]; | 1465 var parent = this._idToDOMNode[parentId]; |
1442 var node = this._idToDOMNode[nodeId]; | 1466 var node = this._idToDOMNode[nodeId]; |
1443 parent._removeChild(node); | 1467 parent._removeChild(node); |
1444 this._unbind(node); | 1468 this._unbind(node); |
1445 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: node, parent: parent}); | 1469 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: node, parent: parent}); |
1470 this._fireMutationEvent(); | |
1446 }, | 1471 }, |
1447 | 1472 |
1448 /** | 1473 /** |
1449 * @param {!DOMAgent.NodeId} hostId | 1474 * @param {!DOMAgent.NodeId} hostId |
1450 * @param {!DOMAgent.Node} root | 1475 * @param {!DOMAgent.Node} root |
1451 */ | 1476 */ |
1452 _shadowRootPushed: function(hostId, root) | 1477 _shadowRootPushed: function(hostId, root) |
1453 { | 1478 { |
1454 var host = this._idToDOMNode[hostId]; | 1479 var host = this._idToDOMNode[hostId]; |
1455 if (!host) | 1480 if (!host) |
1456 return; | 1481 return; |
1457 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root ); | 1482 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root ); |
1458 node.parentNode = host; | 1483 node.parentNode = host; |
1459 this._idToDOMNode[node.id] = node; | 1484 this._idToDOMNode[node.id] = node; |
1460 host._shadowRoots.unshift(node); | 1485 host._shadowRoots.unshift(node); |
1461 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1486 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1487 this._fireMutationEvent(); | |
1462 }, | 1488 }, |
1463 | 1489 |
1464 /** | 1490 /** |
1465 * @param {!DOMAgent.NodeId} hostId | 1491 * @param {!DOMAgent.NodeId} hostId |
1466 * @param {!DOMAgent.NodeId} rootId | 1492 * @param {!DOMAgent.NodeId} rootId |
1467 */ | 1493 */ |
1468 _shadowRootPopped: function(hostId, rootId) | 1494 _shadowRootPopped: function(hostId, rootId) |
1469 { | 1495 { |
1470 var host = this._idToDOMNode[hostId]; | 1496 var host = this._idToDOMNode[hostId]; |
1471 if (!host) | 1497 if (!host) |
1472 return; | 1498 return; |
1473 var root = this._idToDOMNode[rootId]; | 1499 var root = this._idToDOMNode[rootId]; |
1474 if (!root) | 1500 if (!root) |
1475 return; | 1501 return; |
1476 host._removeChild(root); | 1502 host._removeChild(root); |
1477 this._unbind(root); | 1503 this._unbind(root); |
1478 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: root, parent: host}); | 1504 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: root, parent: host}); |
1505 this._fireMutationEvent(); | |
1479 }, | 1506 }, |
1480 | 1507 |
1481 /** | 1508 /** |
1482 * @param {!DOMAgent.NodeId} parentId | 1509 * @param {!DOMAgent.NodeId} parentId |
1483 * @param {!DOMAgent.Node} pseudoElement | 1510 * @param {!DOMAgent.Node} pseudoElement |
1484 */ | 1511 */ |
1485 _pseudoElementAdded: function(parentId, pseudoElement) | 1512 _pseudoElementAdded: function(parentId, pseudoElement) |
1486 { | 1513 { |
1487 var parent = this._idToDOMNode[parentId]; | 1514 var parent = this._idToDOMNode[parentId]; |
1488 if (!parent) | 1515 if (!parent) |
1489 return; | 1516 return; |
1490 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p seudoElement); | 1517 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p seudoElement); |
1491 node.parentNode = parent; | 1518 node.parentNode = parent; |
1492 this._idToDOMNode[node.id] = node; | 1519 this._idToDOMNode[node.id] = node; |
1493 console.assert(!parent._pseudoElements.get(node.pseudoType())); | 1520 console.assert(!parent._pseudoElements.get(node.pseudoType())); |
1494 parent._pseudoElements.set(node.pseudoType(), node); | 1521 parent._pseudoElements.set(node.pseudoType(), node); |
1495 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1522 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1523 this._fireMutationEvent(); | |
1496 }, | 1524 }, |
1497 | 1525 |
1498 /** | 1526 /** |
1499 * @param {!DOMAgent.NodeId} parentId | 1527 * @param {!DOMAgent.NodeId} parentId |
1500 * @param {!DOMAgent.NodeId} pseudoElementId | 1528 * @param {!DOMAgent.NodeId} pseudoElementId |
1501 */ | 1529 */ |
1502 _pseudoElementRemoved: function(parentId, pseudoElementId) | 1530 _pseudoElementRemoved: function(parentId, pseudoElementId) |
1503 { | 1531 { |
1504 var parent = this._idToDOMNode[parentId]; | 1532 var parent = this._idToDOMNode[parentId]; |
1505 if (!parent) | 1533 if (!parent) |
1506 return; | 1534 return; |
1507 var pseudoElement = this._idToDOMNode[pseudoElementId]; | 1535 var pseudoElement = this._idToDOMNode[pseudoElementId]; |
1508 if (!pseudoElement) | 1536 if (!pseudoElement) |
1509 return; | 1537 return; |
1510 parent._removeChild(pseudoElement); | 1538 parent._removeChild(pseudoElement); |
1511 this._unbind(pseudoElement); | 1539 this._unbind(pseudoElement); |
1512 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: pseudoElement, parent: parent}); | 1540 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: pseudoElement, parent: parent}); |
1541 this._fireMutationEvent(); | |
1513 }, | 1542 }, |
1514 | 1543 |
1515 /** | 1544 /** |
1516 * @param {!DOMAgent.NodeId} insertionPointId | 1545 * @param {!DOMAgent.NodeId} insertionPointId |
1517 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes | 1546 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes |
1518 */ | 1547 */ |
1519 _distributedNodesUpdated: function(insertionPointId, distributedNodes) | 1548 _distributedNodesUpdated: function(insertionPointId, distributedNodes) |
1520 { | 1549 { |
1521 var insertionPoint = this._idToDOMNode[insertionPointId]; | 1550 var insertionPoint = this._idToDOMNode[insertionPointId]; |
1522 if (!insertionPoint) | 1551 if (!insertionPoint) |
1523 return; | 1552 return; |
1524 insertionPoint._setDistributedNodePayloads(distributedNodes); | 1553 insertionPoint._setDistributedNodePayloads(distributedNodes); |
1525 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo desChanged, insertionPoint); | 1554 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo desChanged, insertionPoint); |
1555 this._fireMutationEvent(); | |
1526 }, | 1556 }, |
1527 | 1557 |
1528 /** | 1558 /** |
1529 * @param {!WebInspector.DOMNode} node | 1559 * @param {!WebInspector.DOMNode} node |
1530 */ | 1560 */ |
1531 _unbind: function(node) | 1561 _unbind: function(node) |
1532 { | 1562 { |
1533 delete this._idToDOMNode[node.id]; | 1563 delete this._idToDOMNode[node.id]; |
1534 for (var i = 0; node._children && i < node._children.length; ++i) | 1564 for (var i = 0; node._children && i < node._children.length; ++i) |
1535 this._unbind(node._children[i]); | 1565 this._unbind(node._children[i]); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2188 } | 2218 } |
2189 | 2219 |
2190 /** | 2220 /** |
2191 * @param {!WebInspector.Target} target | 2221 * @param {!WebInspector.Target} target |
2192 * @return {?WebInspector.DOMModel} | 2222 * @return {?WebInspector.DOMModel} |
2193 */ | 2223 */ |
2194 WebInspector.DOMModel.fromTarget = function(target) | 2224 WebInspector.DOMModel.fromTarget = function(target) |
2195 { | 2225 { |
2196 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); | 2226 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); |
2197 } | 2227 } |
OLD | NEW |