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 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1119 domModel.highlightDOMNode(0); | 1119 domModel.highlightDOMNode(0); |
1120 } | 1120 } |
1121 | 1121 |
1122 WebInspector.DOMModel.cancelSearch = function() | 1122 WebInspector.DOMModel.cancelSearch = function() |
1123 { | 1123 { |
1124 for (var domModel of WebInspector.DOMModel.instances()) | 1124 for (var domModel of WebInspector.DOMModel.instances()) |
1125 domModel._cancelSearch(); | 1125 domModel._cancelSearch(); |
1126 } | 1126 } |
1127 | 1127 |
1128 WebInspector.DOMModel.prototype = { | 1128 WebInspector.DOMModel.prototype = { |
1129 | |
1130 _fireMutationEvent: function() | |
1131 { | |
1132 this._lastMutationId = (this._lastMutationId || 0) + 1; | |
pfeldman
2015/04/29 13:53:15
fast return if no listeners.
sergeyv
2015/04/30 12:34:13
Done.
| |
1133 Promise.resolve().then(callObserve.bind(this, this._lastMutationId)); | |
1134 | |
1135 /** | |
1136 * @this {WebInspector.DOMModel} | |
1137 * @param {number} mutationId | |
1138 */ | |
1139 function callObserve(mutationId) | |
1140 { | |
1141 if (!this._mutationsObservers || this._lastMutationId !== mutationId ) | |
1142 return; | |
1143 | |
1144 for (var observerInfo of this._mutationsObservers) | |
pfeldman
2015/04/29 13:53:15
this.dispatchEventToListeners(DOMMutated);
sergeyv
2015/04/30 12:34:13
Done.
| |
1145 observerInfo.observer.call(observerInfo.thisObject); | |
1146 } | |
1147 }, | |
1148 | |
1149 /** | |
1150 * @param {function()} observer | |
1151 * @param {!Object=} thisObject | |
1152 */ | |
1153 addDOMMutationsObserver: function(observer, thisObject) | |
1154 { | |
1155 if (!this._mutationsObservers) | |
1156 this._mutationsObservers = []; | |
1157 | |
1158 this._mutationsObservers.push({observer: observer, thisObject: thisObjec t}); | |
1159 }, | |
1160 | |
1161 /** | |
1162 * @param {function()} observer | |
1163 * @param {!Object=} thisObject | |
1164 */ | |
1165 removeDOMMutationsObserver: function(observer, thisObject) | |
1166 { | |
1167 if (!this._mutationsObservers) | |
1168 return; | |
1169 | |
1170 for (var i = 0; i < this._mutationsObservers.length; ++i) { | |
1171 if (this._mutationsObservers[i].observer === observer && this._mutat ionsObservers[i].thisObject === thisObject) | |
1172 this._mutationsObservers.splice(i--, 1); | |
1173 } | |
pfeldman
2015/04/29 13:53:15
delete if empty (along with the methods).
sergeyv
2015/04/30 12:34:13
Done.
| |
1174 | |
1175 }, | |
1176 | |
1129 /** | 1177 /** |
1130 * @param {function(!WebInspector.DOMDocument)=} callback | 1178 * @param {function(!WebInspector.DOMDocument)=} callback |
1131 */ | 1179 */ |
1132 requestDocument: function(callback) | 1180 requestDocument: function(callback) |
1133 { | 1181 { |
1134 if (this._document) { | 1182 if (this._document) { |
1135 if (callback) | 1183 if (callback) |
1136 callback(this._document); | 1184 callback(this._document); |
1137 return; | 1185 return; |
1138 } | 1186 } |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1423 * @param {!DOMAgent.NodeId} prevId | 1471 * @param {!DOMAgent.NodeId} prevId |
1424 * @param {!DOMAgent.Node} payload | 1472 * @param {!DOMAgent.Node} payload |
1425 */ | 1473 */ |
1426 _childNodeInserted: function(parentId, prevId, payload) | 1474 _childNodeInserted: function(parentId, prevId, payload) |
1427 { | 1475 { |
1428 var parent = this._idToDOMNode[parentId]; | 1476 var parent = this._idToDOMNode[parentId]; |
1429 var prev = this._idToDOMNode[prevId]; | 1477 var prev = this._idToDOMNode[prevId]; |
1430 var node = parent._insertChild(prev, payload); | 1478 var node = parent._insertChild(prev, payload); |
1431 this._idToDOMNode[node.id] = node; | 1479 this._idToDOMNode[node.id] = node; |
1432 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1480 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1481 this._fireMutationEvent(); | |
1433 }, | 1482 }, |
1434 | 1483 |
1435 /** | 1484 /** |
1436 * @param {!DOMAgent.NodeId} parentId | 1485 * @param {!DOMAgent.NodeId} parentId |
1437 * @param {!DOMAgent.NodeId} nodeId | 1486 * @param {!DOMAgent.NodeId} nodeId |
1438 */ | 1487 */ |
1439 _childNodeRemoved: function(parentId, nodeId) | 1488 _childNodeRemoved: function(parentId, nodeId) |
1440 { | 1489 { |
1441 var parent = this._idToDOMNode[parentId]; | 1490 var parent = this._idToDOMNode[parentId]; |
1442 var node = this._idToDOMNode[nodeId]; | 1491 var node = this._idToDOMNode[nodeId]; |
1443 parent._removeChild(node); | 1492 parent._removeChild(node); |
1444 this._unbind(node); | 1493 this._unbind(node); |
1445 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: node, parent: parent}); | 1494 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: node, parent: parent}); |
1495 this._fireMutationEvent(); | |
1446 }, | 1496 }, |
1447 | 1497 |
1448 /** | 1498 /** |
1449 * @param {!DOMAgent.NodeId} hostId | 1499 * @param {!DOMAgent.NodeId} hostId |
1450 * @param {!DOMAgent.Node} root | 1500 * @param {!DOMAgent.Node} root |
1451 */ | 1501 */ |
1452 _shadowRootPushed: function(hostId, root) | 1502 _shadowRootPushed: function(hostId, root) |
1453 { | 1503 { |
1454 var host = this._idToDOMNode[hostId]; | 1504 var host = this._idToDOMNode[hostId]; |
1455 if (!host) | 1505 if (!host) |
1456 return; | 1506 return; |
1457 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root ); | 1507 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root ); |
1458 node.parentNode = host; | 1508 node.parentNode = host; |
1459 this._idToDOMNode[node.id] = node; | 1509 this._idToDOMNode[node.id] = node; |
1460 host._shadowRoots.unshift(node); | 1510 host._shadowRoots.unshift(node); |
1461 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1511 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1512 this._fireMutationEvent(); | |
1462 }, | 1513 }, |
1463 | 1514 |
1464 /** | 1515 /** |
1465 * @param {!DOMAgent.NodeId} hostId | 1516 * @param {!DOMAgent.NodeId} hostId |
1466 * @param {!DOMAgent.NodeId} rootId | 1517 * @param {!DOMAgent.NodeId} rootId |
1467 */ | 1518 */ |
1468 _shadowRootPopped: function(hostId, rootId) | 1519 _shadowRootPopped: function(hostId, rootId) |
1469 { | 1520 { |
1470 var host = this._idToDOMNode[hostId]; | 1521 var host = this._idToDOMNode[hostId]; |
1471 if (!host) | 1522 if (!host) |
1472 return; | 1523 return; |
1473 var root = this._idToDOMNode[rootId]; | 1524 var root = this._idToDOMNode[rootId]; |
1474 if (!root) | 1525 if (!root) |
1475 return; | 1526 return; |
1476 host._removeChild(root); | 1527 host._removeChild(root); |
1477 this._unbind(root); | 1528 this._unbind(root); |
1478 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: root, parent: host}); | 1529 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: root, parent: host}); |
1530 this._fireMutationEvent(); | |
1479 }, | 1531 }, |
1480 | 1532 |
1481 /** | 1533 /** |
1482 * @param {!DOMAgent.NodeId} parentId | 1534 * @param {!DOMAgent.NodeId} parentId |
1483 * @param {!DOMAgent.Node} pseudoElement | 1535 * @param {!DOMAgent.Node} pseudoElement |
1484 */ | 1536 */ |
1485 _pseudoElementAdded: function(parentId, pseudoElement) | 1537 _pseudoElementAdded: function(parentId, pseudoElement) |
1486 { | 1538 { |
1487 var parent = this._idToDOMNode[parentId]; | 1539 var parent = this._idToDOMNode[parentId]; |
1488 if (!parent) | 1540 if (!parent) |
1489 return; | 1541 return; |
1490 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p seudoElement); | 1542 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p seudoElement); |
1491 node.parentNode = parent; | 1543 node.parentNode = parent; |
1492 this._idToDOMNode[node.id] = node; | 1544 this._idToDOMNode[node.id] = node; |
1493 console.assert(!parent._pseudoElements.get(node.pseudoType())); | 1545 console.assert(!parent._pseudoElements.get(node.pseudoType())); |
1494 parent._pseudoElements.set(node.pseudoType(), node); | 1546 parent._pseudoElements.set(node.pseudoType(), node); |
1495 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); | 1547 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted, node); |
1548 this._fireMutationEvent(); | |
1496 }, | 1549 }, |
1497 | 1550 |
1498 /** | 1551 /** |
1499 * @param {!DOMAgent.NodeId} parentId | 1552 * @param {!DOMAgent.NodeId} parentId |
1500 * @param {!DOMAgent.NodeId} pseudoElementId | 1553 * @param {!DOMAgent.NodeId} pseudoElementId |
1501 */ | 1554 */ |
1502 _pseudoElementRemoved: function(parentId, pseudoElementId) | 1555 _pseudoElementRemoved: function(parentId, pseudoElementId) |
1503 { | 1556 { |
1504 var parent = this._idToDOMNode[parentId]; | 1557 var parent = this._idToDOMNode[parentId]; |
1505 if (!parent) | 1558 if (!parent) |
1506 return; | 1559 return; |
1507 var pseudoElement = this._idToDOMNode[pseudoElementId]; | 1560 var pseudoElement = this._idToDOMNode[pseudoElementId]; |
1508 if (!pseudoElement) | 1561 if (!pseudoElement) |
1509 return; | 1562 return; |
1510 parent._removeChild(pseudoElement); | 1563 parent._removeChild(pseudoElement); |
1511 this._unbind(pseudoElement); | 1564 this._unbind(pseudoElement); |
1512 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: pseudoElement, parent: parent}); | 1565 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved, {node: pseudoElement, parent: parent}); |
1566 this._fireMutationEvent(); | |
1513 }, | 1567 }, |
1514 | 1568 |
1515 /** | 1569 /** |
1516 * @param {!DOMAgent.NodeId} insertionPointId | 1570 * @param {!DOMAgent.NodeId} insertionPointId |
1517 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes | 1571 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes |
1518 */ | 1572 */ |
1519 _distributedNodesUpdated: function(insertionPointId, distributedNodes) | 1573 _distributedNodesUpdated: function(insertionPointId, distributedNodes) |
1520 { | 1574 { |
1521 var insertionPoint = this._idToDOMNode[insertionPointId]; | 1575 var insertionPoint = this._idToDOMNode[insertionPointId]; |
1522 if (!insertionPoint) | 1576 if (!insertionPoint) |
1523 return; | 1577 return; |
1524 insertionPoint._setDistributedNodePayloads(distributedNodes); | 1578 insertionPoint._setDistributedNodePayloads(distributedNodes); |
1525 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo desChanged, insertionPoint); | 1579 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo desChanged, insertionPoint); |
1580 this._fireMutationEvent(); | |
1526 }, | 1581 }, |
1527 | 1582 |
1528 /** | 1583 /** |
1529 * @param {!WebInspector.DOMNode} node | 1584 * @param {!WebInspector.DOMNode} node |
1530 */ | 1585 */ |
1531 _unbind: function(node) | 1586 _unbind: function(node) |
1532 { | 1587 { |
1533 delete this._idToDOMNode[node.id]; | 1588 delete this._idToDOMNode[node.id]; |
1534 for (var i = 0; node._children && i < node._children.length; ++i) | 1589 for (var i = 0; node._children && i < node._children.length; ++i) |
1535 this._unbind(node._children[i]); | 1590 this._unbind(node._children[i]); |
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2188 } | 2243 } |
2189 | 2244 |
2190 /** | 2245 /** |
2191 * @param {!WebInspector.Target} target | 2246 * @param {!WebInspector.Target} target |
2192 * @return {?WebInspector.DOMModel} | 2247 * @return {?WebInspector.DOMModel} |
2193 */ | 2248 */ |
2194 WebInspector.DOMModel.fromTarget = function(target) | 2249 WebInspector.DOMModel.fromTarget = function(target) |
2195 { | 2250 { |
2196 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); | 2251 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); |
2197 } | 2252 } |
OLD | NEW |