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 _scheduleMutationEvent: function() |
| 1131 { |
| 1132 if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutated)) |
| 1133 return; |
| 1134 |
| 1135 this._lastMutationId = (this._lastMutationId || 0) + 1; |
| 1136 Promise.resolve().then(callObserve.bind(this, this._lastMutationId)); |
| 1137 |
| 1138 /** |
| 1139 * @this {WebInspector.DOMModel} |
| 1140 * @param {number} mutationId |
| 1141 */ |
| 1142 function callObserve(mutationId) |
| 1143 { |
| 1144 if (!this.hasEventListeners(WebInspector.DOMModel.Events.DOMMutated)
|| this._lastMutationId !== mutationId) |
| 1145 return; |
| 1146 |
| 1147 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DOMMutate
d); |
| 1148 } |
| 1149 }, |
| 1150 |
1129 /** | 1151 /** |
1130 * @param {function(!WebInspector.DOMDocument)=} callback | 1152 * @param {function(!WebInspector.DOMDocument)=} callback |
1131 */ | 1153 */ |
1132 requestDocument: function(callback) | 1154 requestDocument: function(callback) |
1133 { | 1155 { |
1134 if (this._document) { | 1156 if (this._document) { |
1135 if (callback) | 1157 if (callback) |
1136 callback(this._document); | 1158 callback(this._document); |
1137 return; | 1159 return; |
1138 } | 1160 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 * @param {string} value | 1301 * @param {string} value |
1280 */ | 1302 */ |
1281 _attributeModified: function(nodeId, name, value) | 1303 _attributeModified: function(nodeId, name, value) |
1282 { | 1304 { |
1283 var node = this._idToDOMNode[nodeId]; | 1305 var node = this._idToDOMNode[nodeId]; |
1284 if (!node) | 1306 if (!node) |
1285 return; | 1307 return; |
1286 | 1308 |
1287 node._setAttribute(name, value); | 1309 node._setAttribute(name, value); |
1288 this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrModified,
{ node: node, name: name }); | 1310 this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrModified,
{ node: node, name: name }); |
| 1311 this._scheduleMutationEvent(); |
1289 }, | 1312 }, |
1290 | 1313 |
1291 /** | 1314 /** |
1292 * @param {!DOMAgent.NodeId} nodeId | 1315 * @param {!DOMAgent.NodeId} nodeId |
1293 * @param {string} name | 1316 * @param {string} name |
1294 */ | 1317 */ |
1295 _attributeRemoved: function(nodeId, name) | 1318 _attributeRemoved: function(nodeId, name) |
1296 { | 1319 { |
1297 var node = this._idToDOMNode[nodeId]; | 1320 var node = this._idToDOMNode[nodeId]; |
1298 if (!node) | 1321 if (!node) |
1299 return; | 1322 return; |
1300 node._removeAttribute(name); | 1323 node._removeAttribute(name); |
1301 this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrRemoved,
{ node: node, name: name }); | 1324 this.dispatchEventToListeners(WebInspector.DOMModel.Events.AttrRemoved,
{ node: node, name: name }); |
| 1325 this._scheduleMutationEvent(); |
1302 }, | 1326 }, |
1303 | 1327 |
1304 /** | 1328 /** |
1305 * @param {!Array.<!DOMAgent.NodeId>} nodeIds | 1329 * @param {!Array.<!DOMAgent.NodeId>} nodeIds |
1306 */ | 1330 */ |
1307 _inlineStyleInvalidated: function(nodeIds) | 1331 _inlineStyleInvalidated: function(nodeIds) |
1308 { | 1332 { |
1309 for (var i = 0; i < nodeIds.length; ++i) | 1333 for (var i = 0; i < nodeIds.length; ++i) |
1310 this._attributeLoadNodeIds[nodeIds[i]] = true; | 1334 this._attributeLoadNodeIds[nodeIds[i]] = true; |
1311 if ("_loadNodeAttributesTimeout" in this) | 1335 if ("_loadNodeAttributesTimeout" in this) |
(...skipping 10 matching lines...) Expand all Loading... |
1322 * @param {!Array.<string>} attributes | 1346 * @param {!Array.<string>} attributes |
1323 */ | 1347 */ |
1324 function callback(nodeId, error, attributes) | 1348 function callback(nodeId, error, attributes) |
1325 { | 1349 { |
1326 if (error) { | 1350 if (error) { |
1327 // We are calling _loadNodeAttributes asynchronously, it is ok i
f node is not found. | 1351 // We are calling _loadNodeAttributes asynchronously, it is ok i
f node is not found. |
1328 return; | 1352 return; |
1329 } | 1353 } |
1330 var node = this._idToDOMNode[nodeId]; | 1354 var node = this._idToDOMNode[nodeId]; |
1331 if (node) { | 1355 if (node) { |
1332 if (node._setAttributesPayload(attributes)) | 1356 if (node._setAttributesPayload(attributes)) { |
1333 this.dispatchEventToListeners(WebInspector.DOMModel.Events.A
ttrModified, { node: node, name: "style" }); | 1357 this.dispatchEventToListeners(WebInspector.DOMModel.Events.A
ttrModified, { node: node, name: "style" }); |
| 1358 this._scheduleMutationEvent(); |
| 1359 } |
1334 } | 1360 } |
1335 } | 1361 } |
1336 | 1362 |
1337 delete this._loadNodeAttributesTimeout; | 1363 delete this._loadNodeAttributesTimeout; |
1338 | 1364 |
1339 for (var nodeId in this._attributeLoadNodeIds) { | 1365 for (var nodeId in this._attributeLoadNodeIds) { |
1340 var nodeIdAsNumber = parseInt(nodeId, 10); | 1366 var nodeIdAsNumber = parseInt(nodeId, 10); |
1341 this._agent.getAttributes(nodeIdAsNumber, callback.bind(this, nodeId
AsNumber)); | 1367 this._agent.getAttributes(nodeIdAsNumber, callback.bind(this, nodeId
AsNumber)); |
1342 } | 1368 } |
1343 this._attributeLoadNodeIds = {}; | 1369 this._attributeLoadNodeIds = {}; |
1344 }, | 1370 }, |
1345 | 1371 |
1346 /** | 1372 /** |
1347 * @param {!DOMAgent.NodeId} nodeId | 1373 * @param {!DOMAgent.NodeId} nodeId |
1348 * @param {string} newValue | 1374 * @param {string} newValue |
1349 */ | 1375 */ |
1350 _characterDataModified: function(nodeId, newValue) | 1376 _characterDataModified: function(nodeId, newValue) |
1351 { | 1377 { |
1352 var node = this._idToDOMNode[nodeId]; | 1378 var node = this._idToDOMNode[nodeId]; |
1353 node._nodeValue = newValue; | 1379 node._nodeValue = newValue; |
1354 this.dispatchEventToListeners(WebInspector.DOMModel.Events.CharacterData
Modified, node); | 1380 this.dispatchEventToListeners(WebInspector.DOMModel.Events.CharacterData
Modified, node); |
| 1381 this._scheduleMutationEvent(); |
1355 }, | 1382 }, |
1356 | 1383 |
1357 /** | 1384 /** |
1358 * @param {!DOMAgent.NodeId} nodeId | 1385 * @param {!DOMAgent.NodeId} nodeId |
1359 * @return {?WebInspector.DOMNode} | 1386 * @return {?WebInspector.DOMNode} |
1360 */ | 1387 */ |
1361 nodeForId: function(nodeId) | 1388 nodeForId: function(nodeId) |
1362 { | 1389 { |
1363 return this._idToDOMNode[nodeId] || null; | 1390 return this._idToDOMNode[nodeId] || null; |
1364 }, | 1391 }, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 | 1436 |
1410 /** | 1437 /** |
1411 * @param {!DOMAgent.NodeId} nodeId | 1438 * @param {!DOMAgent.NodeId} nodeId |
1412 * @param {number} newValue | 1439 * @param {number} newValue |
1413 */ | 1440 */ |
1414 _childNodeCountUpdated: function(nodeId, newValue) | 1441 _childNodeCountUpdated: function(nodeId, newValue) |
1415 { | 1442 { |
1416 var node = this._idToDOMNode[nodeId]; | 1443 var node = this._idToDOMNode[nodeId]; |
1417 node._childNodeCount = newValue; | 1444 node._childNodeCount = newValue; |
1418 this.dispatchEventToListeners(WebInspector.DOMModel.Events.ChildNodeCoun
tUpdated, node); | 1445 this.dispatchEventToListeners(WebInspector.DOMModel.Events.ChildNodeCoun
tUpdated, node); |
| 1446 this._scheduleMutationEvent(); |
1419 }, | 1447 }, |
1420 | 1448 |
1421 /** | 1449 /** |
1422 * @param {!DOMAgent.NodeId} parentId | 1450 * @param {!DOMAgent.NodeId} parentId |
1423 * @param {!DOMAgent.NodeId} prevId | 1451 * @param {!DOMAgent.NodeId} prevId |
1424 * @param {!DOMAgent.Node} payload | 1452 * @param {!DOMAgent.Node} payload |
1425 */ | 1453 */ |
1426 _childNodeInserted: function(parentId, prevId, payload) | 1454 _childNodeInserted: function(parentId, prevId, payload) |
1427 { | 1455 { |
1428 var parent = this._idToDOMNode[parentId]; | 1456 var parent = this._idToDOMNode[parentId]; |
1429 var prev = this._idToDOMNode[prevId]; | 1457 var prev = this._idToDOMNode[prevId]; |
1430 var node = parent._insertChild(prev, payload); | 1458 var node = parent._insertChild(prev, payload); |
1431 this._idToDOMNode[node.id] = node; | 1459 this._idToDOMNode[node.id] = node; |
1432 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); | 1460 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); |
| 1461 this._scheduleMutationEvent(); |
1433 }, | 1462 }, |
1434 | 1463 |
1435 /** | 1464 /** |
1436 * @param {!DOMAgent.NodeId} parentId | 1465 * @param {!DOMAgent.NodeId} parentId |
1437 * @param {!DOMAgent.NodeId} nodeId | 1466 * @param {!DOMAgent.NodeId} nodeId |
1438 */ | 1467 */ |
1439 _childNodeRemoved: function(parentId, nodeId) | 1468 _childNodeRemoved: function(parentId, nodeId) |
1440 { | 1469 { |
1441 var parent = this._idToDOMNode[parentId]; | 1470 var parent = this._idToDOMNode[parentId]; |
1442 var node = this._idToDOMNode[nodeId]; | 1471 var node = this._idToDOMNode[nodeId]; |
1443 parent._removeChild(node); | 1472 parent._removeChild(node); |
1444 this._unbind(node); | 1473 this._unbind(node); |
1445 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: node, parent: parent}); | 1474 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: node, parent: parent}); |
| 1475 this._scheduleMutationEvent(); |
1446 }, | 1476 }, |
1447 | 1477 |
1448 /** | 1478 /** |
1449 * @param {!DOMAgent.NodeId} hostId | 1479 * @param {!DOMAgent.NodeId} hostId |
1450 * @param {!DOMAgent.Node} root | 1480 * @param {!DOMAgent.Node} root |
1451 */ | 1481 */ |
1452 _shadowRootPushed: function(hostId, root) | 1482 _shadowRootPushed: function(hostId, root) |
1453 { | 1483 { |
1454 var host = this._idToDOMNode[hostId]; | 1484 var host = this._idToDOMNode[hostId]; |
1455 if (!host) | 1485 if (!host) |
1456 return; | 1486 return; |
1457 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root
); | 1487 var node = new WebInspector.DOMNode(this, host.ownerDocument, true, root
); |
1458 node.parentNode = host; | 1488 node.parentNode = host; |
1459 this._idToDOMNode[node.id] = node; | 1489 this._idToDOMNode[node.id] = node; |
1460 host._shadowRoots.unshift(node); | 1490 host._shadowRoots.unshift(node); |
1461 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); | 1491 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); |
| 1492 this._scheduleMutationEvent(); |
1462 }, | 1493 }, |
1463 | 1494 |
1464 /** | 1495 /** |
1465 * @param {!DOMAgent.NodeId} hostId | 1496 * @param {!DOMAgent.NodeId} hostId |
1466 * @param {!DOMAgent.NodeId} rootId | 1497 * @param {!DOMAgent.NodeId} rootId |
1467 */ | 1498 */ |
1468 _shadowRootPopped: function(hostId, rootId) | 1499 _shadowRootPopped: function(hostId, rootId) |
1469 { | 1500 { |
1470 var host = this._idToDOMNode[hostId]; | 1501 var host = this._idToDOMNode[hostId]; |
1471 if (!host) | 1502 if (!host) |
1472 return; | 1503 return; |
1473 var root = this._idToDOMNode[rootId]; | 1504 var root = this._idToDOMNode[rootId]; |
1474 if (!root) | 1505 if (!root) |
1475 return; | 1506 return; |
1476 host._removeChild(root); | 1507 host._removeChild(root); |
1477 this._unbind(root); | 1508 this._unbind(root); |
1478 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: root, parent: host}); | 1509 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: root, parent: host}); |
| 1510 this._scheduleMutationEvent(); |
1479 }, | 1511 }, |
1480 | 1512 |
1481 /** | 1513 /** |
1482 * @param {!DOMAgent.NodeId} parentId | 1514 * @param {!DOMAgent.NodeId} parentId |
1483 * @param {!DOMAgent.Node} pseudoElement | 1515 * @param {!DOMAgent.Node} pseudoElement |
1484 */ | 1516 */ |
1485 _pseudoElementAdded: function(parentId, pseudoElement) | 1517 _pseudoElementAdded: function(parentId, pseudoElement) |
1486 { | 1518 { |
1487 var parent = this._idToDOMNode[parentId]; | 1519 var parent = this._idToDOMNode[parentId]; |
1488 if (!parent) | 1520 if (!parent) |
1489 return; | 1521 return; |
1490 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p
seudoElement); | 1522 var node = new WebInspector.DOMNode(this, parent.ownerDocument, false, p
seudoElement); |
1491 node.parentNode = parent; | 1523 node.parentNode = parent; |
1492 this._idToDOMNode[node.id] = node; | 1524 this._idToDOMNode[node.id] = node; |
1493 console.assert(!parent._pseudoElements.get(node.pseudoType())); | 1525 console.assert(!parent._pseudoElements.get(node.pseudoType())); |
1494 parent._pseudoElements.set(node.pseudoType(), node); | 1526 parent._pseudoElements.set(node.pseudoType(), node); |
1495 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); | 1527 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeInserted,
node); |
| 1528 this._scheduleMutationEvent(); |
1496 }, | 1529 }, |
1497 | 1530 |
1498 /** | 1531 /** |
1499 * @param {!DOMAgent.NodeId} parentId | 1532 * @param {!DOMAgent.NodeId} parentId |
1500 * @param {!DOMAgent.NodeId} pseudoElementId | 1533 * @param {!DOMAgent.NodeId} pseudoElementId |
1501 */ | 1534 */ |
1502 _pseudoElementRemoved: function(parentId, pseudoElementId) | 1535 _pseudoElementRemoved: function(parentId, pseudoElementId) |
1503 { | 1536 { |
1504 var parent = this._idToDOMNode[parentId]; | 1537 var parent = this._idToDOMNode[parentId]; |
1505 if (!parent) | 1538 if (!parent) |
1506 return; | 1539 return; |
1507 var pseudoElement = this._idToDOMNode[pseudoElementId]; | 1540 var pseudoElement = this._idToDOMNode[pseudoElementId]; |
1508 if (!pseudoElement) | 1541 if (!pseudoElement) |
1509 return; | 1542 return; |
1510 parent._removeChild(pseudoElement); | 1543 parent._removeChild(pseudoElement); |
1511 this._unbind(pseudoElement); | 1544 this._unbind(pseudoElement); |
1512 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: pseudoElement, parent: parent}); | 1545 this.dispatchEventToListeners(WebInspector.DOMModel.Events.NodeRemoved,
{node: pseudoElement, parent: parent}); |
| 1546 this._scheduleMutationEvent(); |
1513 }, | 1547 }, |
1514 | 1548 |
1515 /** | 1549 /** |
1516 * @param {!DOMAgent.NodeId} insertionPointId | 1550 * @param {!DOMAgent.NodeId} insertionPointId |
1517 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes | 1551 * @param {!Array.<!DOMAgent.BackendNode>} distributedNodes |
1518 */ | 1552 */ |
1519 _distributedNodesUpdated: function(insertionPointId, distributedNodes) | 1553 _distributedNodesUpdated: function(insertionPointId, distributedNodes) |
1520 { | 1554 { |
1521 var insertionPoint = this._idToDOMNode[insertionPointId]; | 1555 var insertionPoint = this._idToDOMNode[insertionPointId]; |
1522 if (!insertionPoint) | 1556 if (!insertionPoint) |
1523 return; | 1557 return; |
1524 insertionPoint._setDistributedNodePayloads(distributedNodes); | 1558 insertionPoint._setDistributedNodePayloads(distributedNodes); |
1525 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo
desChanged, insertionPoint); | 1559 this.dispatchEventToListeners(WebInspector.DOMModel.Events.DistributedNo
desChanged, insertionPoint); |
| 1560 this._scheduleMutationEvent(); |
1526 }, | 1561 }, |
1527 | 1562 |
1528 /** | 1563 /** |
1529 * @param {!WebInspector.DOMNode} node | 1564 * @param {!WebInspector.DOMNode} node |
1530 */ | 1565 */ |
1531 _unbind: function(node) | 1566 _unbind: function(node) |
1532 { | 1567 { |
1533 delete this._idToDOMNode[node.id]; | 1568 delete this._idToDOMNode[node.id]; |
1534 for (var i = 0; node._children && i < node._children.length; ++i) | 1569 for (var i = 0; node._children && i < node._children.length; ++i) |
1535 this._unbind(node._children[i]); | 1570 this._unbind(node._children[i]); |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 } | 2163 } |
2129 | 2164 |
2130 /** | 2165 /** |
2131 * @param {!WebInspector.Target} target | 2166 * @param {!WebInspector.Target} target |
2132 * @return {?WebInspector.DOMModel} | 2167 * @return {?WebInspector.DOMModel} |
2133 */ | 2168 */ |
2134 WebInspector.DOMModel.fromTarget = function(target) | 2169 WebInspector.DOMModel.fromTarget = function(target) |
2135 { | 2170 { |
2136 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM
odel)); | 2171 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM
odel)); |
2137 } | 2172 } |
OLD | NEW |