OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Dom and DomNode are used to represent remote DOM in the | 6 * @fileoverview Dom and DomNode are used to represent remote DOM in the |
7 * web inspector. | 7 * web inspector. |
8 */ | 8 */ |
9 goog.provide('devtools.DomAgent'); | 9 goog.provide('devtools.DomAgent'); |
10 goog.provide('devtools.DomDocument'); | 10 goog.provide('devtools.DomDocument'); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 listeners[i](event); | 245 listeners[i](event); |
246 } | 246 } |
247 }; | 247 }; |
248 | 248 |
249 | 249 |
250 /** | 250 /** |
251 * Creates DomAgent Js representation. | 251 * Creates DomAgent Js representation. |
252 * @constructor | 252 * @constructor |
253 */ | 253 */ |
254 devtools.DomAgent = function() { | 254 devtools.DomAgent = function() { |
255 this.document = new devtools.DomDocument(); | |
256 this.idToDomNode_ = { 0 : this.document }; | |
257 RemoteDomAgent.DidGetChildNodes = | 255 RemoteDomAgent.DidGetChildNodes = |
258 devtools.Callback.processCallback; | 256 devtools.Callback.processCallback; |
259 RemoteDomAgent.DidPerformSearch = | 257 RemoteDomAgent.DidPerformSearch = |
260 devtools.Callback.processCallback; | 258 devtools.Callback.processCallback; |
261 RemoteDomAgent.AttributesUpdated = | 259 RemoteDomAgent.AttributesUpdated = |
262 goog.bind(this.attributesUpdated, this); | 260 goog.bind(this.attributesUpdated, this); |
263 RemoteDomAgent.SetDocumentElement = | 261 RemoteDomAgent.SetDocumentElement = |
264 goog.bind(this.setDocumentElement, this); | 262 goog.bind(this.setDocumentElement, this); |
265 RemoteDomAgent.SetChildNodes = | 263 RemoteDomAgent.SetChildNodes = |
266 goog.bind(this.setChildNodes, this); | 264 goog.bind(this.setChildNodes, this); |
267 RemoteDomAgent.HasChildrenUpdated = | 265 RemoteDomAgent.HasChildrenUpdated = |
268 goog.bind(this.hasChildrenUpdated, this); | 266 goog.bind(this.hasChildrenUpdated, this); |
269 RemoteDomAgent.ChildNodeInserted = | 267 RemoteDomAgent.ChildNodeInserted = |
270 goog.bind(this.childNodeInserted, this); | 268 goog.bind(this.childNodeInserted, this); |
271 RemoteDomAgent.ChildNodeRemoved = | 269 RemoteDomAgent.ChildNodeRemoved = |
272 goog.bind(this.childNodeRemoved, this); | 270 goog.bind(this.childNodeRemoved, this); |
| 271 |
| 272 /** |
| 273 * Top-level (and the only) document. |
| 274 * @type {devtools.DomDocument} |
| 275 * @private |
| 276 */ |
| 277 this.document_ = null; |
| 278 |
| 279 /** |
| 280 * Id to node mapping. |
| 281 * @type {Object} |
| 282 * @private |
| 283 */ |
| 284 this.idToDomNode_ = null; |
| 285 |
273 /** | 286 /** |
274 * @type {Array.<number>} Node ids for search results. | 287 * @type {Array.<number>} Node ids for search results. |
| 288 * @private |
275 */ | 289 */ |
| 290 this.searchResults_ = null; |
| 291 |
| 292 this.reset(); |
| 293 }; |
| 294 |
| 295 |
| 296 /** |
| 297 * Rests dom agent to its initial state. |
| 298 */ |
| 299 devtools.DomAgent.prototype.reset = function() { |
| 300 RemoteDomAgent.DiscardBindings(); |
| 301 this.document_ = new devtools.DomDocument(); |
| 302 this.idToDomNode_ = { 0 : this.document_ }; |
276 this.searchResults_ = []; | 303 this.searchResults_ = []; |
277 }; | 304 }; |
278 | 305 |
279 | 306 |
280 /** | 307 /** |
| 308 * @return {devtools.DomDocument} Top level (and the only) document. |
| 309 */ |
| 310 devtools.DomAgent.prototype.getDocument = function() { |
| 311 return this.document_; |
| 312 }; |
| 313 |
| 314 |
| 315 /** |
281 * Requests that the document element is sent from the agent. | 316 * Requests that the document element is sent from the agent. |
282 */ | 317 */ |
283 devtools.DomAgent.prototype.getDocumentElementAsync = function() { | 318 devtools.DomAgent.prototype.getDocumentElementAsync = function() { |
284 if (this.document.documentElement) { | 319 if (this.document_.documentElement) { |
285 return; | 320 return; |
286 } | 321 } |
287 RemoteDomAgent.GetDocumentElement(); | 322 RemoteDomAgent.GetDocumentElement(); |
288 }; | 323 }; |
289 | 324 |
290 | 325 |
291 /** | 326 /** |
292 * Asynchronously fetches children from the element with given id. | 327 * Asynchronously fetches children from the element with given id. |
293 * @param {number} parentId Element to get children for. | 328 * @param {number} parentId Element to get children for. |
294 * @param {function(devtools.DomNode):undefined} opt_callback Callback with | 329 * @param {function(devtools.DomNode):undefined} opt_callback Callback with |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 devtools.DomAgent.prototype.getNodeForId = function(nodeId) { | 365 devtools.DomAgent.prototype.getNodeForId = function(nodeId) { |
331 return this.idToDomNode_[nodeId]; | 366 return this.idToDomNode_[nodeId]; |
332 }; | 367 }; |
333 | 368 |
334 | 369 |
335 /** | 370 /** |
336 * @see DomAgentDelegate. | 371 * @see DomAgentDelegate. |
337 * {@inheritDoc}. | 372 * {@inheritDoc}. |
338 */ | 373 */ |
339 devtools.DomAgent.prototype.setDocumentElement = function(payload) { | 374 devtools.DomAgent.prototype.setDocumentElement = function(payload) { |
340 if (this.document.documentElement) { | 375 if (this.document_.documentElement) { |
341 return; | 376 return; |
342 } | 377 } |
343 this.setChildNodes(0, [payload]); | 378 this.setChildNodes(0, [payload]); |
344 this.document.documentElement = this.document.firstChild; | 379 this.document_.documentElement = this.document_.firstChild; |
345 this.document.documentElement.ownerDocument = this.document; | 380 this.document_.documentElement.ownerDocument = this.document_; |
346 this.document.fireDomEvent_("DOMContentLoaded"); | 381 this.document_.fireDomEvent_("DOMContentLoaded"); |
347 }; | 382 }; |
348 | 383 |
349 | 384 |
350 /** | 385 /** |
351 * @see DomAgentDelegate. | 386 * @see DomAgentDelegate. |
352 * {@inheritDoc}. | 387 * {@inheritDoc}. |
353 */ | 388 */ |
354 devtools.DomAgent.prototype.setChildNodes = function(parentId, payloads) { | 389 devtools.DomAgent.prototype.setChildNodes = function(parentId, payloads) { |
355 var parent = this.idToDomNode_[parentId]; | 390 var parent = this.idToDomNode_[parentId]; |
356 if (parent.children) { | 391 if (parent.children) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 * @see DomAgentDelegate. | 423 * @see DomAgentDelegate. |
389 * {@inheritDoc}. | 424 * {@inheritDoc}. |
390 */ | 425 */ |
391 devtools.DomAgent.prototype.childNodeInserted = function( | 426 devtools.DomAgent.prototype.childNodeInserted = function( |
392 parentId, prevId, payload) { | 427 parentId, prevId, payload) { |
393 var parent = this.idToDomNode_[parentId]; | 428 var parent = this.idToDomNode_[parentId]; |
394 var prev = this.idToDomNode_[prevId]; | 429 var prev = this.idToDomNode_[prevId]; |
395 var node = parent.insertChild_(prev, payload); | 430 var node = parent.insertChild_(prev, payload); |
396 this.idToDomNode_[node.id] = node; | 431 this.idToDomNode_[node.id] = node; |
397 var event = { target : node, relatedNode : parent }; | 432 var event = { target : node, relatedNode : parent }; |
398 this.document.fireDomEvent_("DOMNodeInserted", event); | 433 this.document_.fireDomEvent_("DOMNodeInserted", event); |
399 }; | 434 }; |
400 | 435 |
401 | 436 |
402 /** | 437 /** |
403 * @see DomAgentDelegate. | 438 * @see DomAgentDelegate. |
404 * {@inheritDoc}. | 439 * {@inheritDoc}. |
405 */ | 440 */ |
406 devtools.DomAgent.prototype.childNodeRemoved = function( | 441 devtools.DomAgent.prototype.childNodeRemoved = function( |
407 parentId, nodeId) { | 442 parentId, nodeId) { |
408 var parent = this.idToDomNode_[parentId]; | 443 var parent = this.idToDomNode_[parentId]; |
409 var node = this.idToDomNode_[nodeId]; | 444 var node = this.idToDomNode_[nodeId]; |
410 parent.removeChild_(node); | 445 parent.removeChild_(node); |
411 var event = { target : node, relatedNode : parent }; | 446 var event = { target : node, relatedNode : parent }; |
412 this.document.fireDomEvent_("DOMNodeRemoved", event); | 447 this.document_.fireDomEvent_("DOMNodeRemoved", event); |
413 delete this.idToDomNode_[nodeId]; | 448 delete this.idToDomNode_[nodeId]; |
414 }; | 449 }; |
415 | 450 |
416 | 451 |
417 /** | 452 /** |
418 * @see DomAgentDelegate. | 453 * @see DomAgentDelegate. |
419 * {@inheritDoc}. | 454 * {@inheritDoc}. |
420 */ | 455 */ |
421 devtools.DomAgent.prototype.performSearch = function(query, forEach) { | 456 devtools.DomAgent.prototype.performSearch = function(query, forEach) { |
422 RemoteDomAgent.PerformSearch( | 457 RemoteDomAgent.PerformSearch( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 function onlyTextChild() { | 498 function onlyTextChild() { |
464 if (!this.children) { | 499 if (!this.children) { |
465 return null; | 500 return null; |
466 } else if (this.children.length == 1 && | 501 } else if (this.children.length == 1 && |
467 this.children[0].nodeType == Node.TEXT_NODE) { | 502 this.children[0].nodeType == Node.TEXT_NODE) { |
468 return this.children[0]; | 503 return this.children[0]; |
469 } else { | 504 } else { |
470 return null; | 505 return null; |
471 } | 506 } |
472 } | 507 } |
OLD | NEW |