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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 devtools.Callback.processCallback; | 476 devtools.Callback.processCallback; |
477 RemoteDomAgent.DidPerformSearch = | 477 RemoteDomAgent.DidPerformSearch = |
478 devtools.Callback.processCallback; | 478 devtools.Callback.processCallback; |
479 RemoteDomAgent.DidApplyDomChange = | 479 RemoteDomAgent.DidApplyDomChange = |
480 devtools.Callback.processCallback; | 480 devtools.Callback.processCallback; |
481 RemoteDomAgent.DidRemoveAttribute = | 481 RemoteDomAgent.DidRemoveAttribute = |
482 devtools.Callback.processCallback; | 482 devtools.Callback.processCallback; |
483 RemoteDomAgent.DidSetTextNodeValue = | 483 RemoteDomAgent.DidSetTextNodeValue = |
484 devtools.Callback.processCallback; | 484 devtools.Callback.processCallback; |
485 RemoteDomAgent.AttributesUpdated = | 485 RemoteDomAgent.AttributesUpdated = |
486 goog.bind(this.attributesUpdated, this); | 486 goog.bind(this.attributesUpdated_, this); |
487 RemoteDomAgent.SetDocumentElement = | 487 RemoteDomAgent.SetDocumentElement = |
488 goog.bind(this.setDocumentElement, this); | 488 goog.bind(this.setDocumentElement_, this); |
489 RemoteDomAgent.SetChildNodes = | 489 RemoteDomAgent.SetChildNodes = |
490 goog.bind(this.setChildNodes, this); | 490 goog.bind(this.setChildNodes_, this); |
491 RemoteDomAgent.HasChildrenUpdated = | 491 RemoteDomAgent.HasChildrenUpdated = |
492 goog.bind(this.hasChildrenUpdated, this); | 492 goog.bind(this.hasChildrenUpdated_, this); |
493 RemoteDomAgent.ChildNodeInserted = | 493 RemoteDomAgent.ChildNodeInserted = |
494 goog.bind(this.childNodeInserted, this); | 494 goog.bind(this.childNodeInserted_, this); |
495 RemoteDomAgent.ChildNodeRemoved = | 495 RemoteDomAgent.ChildNodeRemoved = |
496 goog.bind(this.childNodeRemoved, this); | 496 goog.bind(this.childNodeRemoved_, this); |
497 | 497 |
498 /** | 498 /** |
499 * Top-level (and the only) document. | 499 * Top-level (and the only) document. |
500 * @type {devtools.DomWindow} | 500 * @type {devtools.DomWindow} |
501 * @private | 501 * @private |
502 */ | 502 */ |
503 this.window_ = null; | 503 this.window_ = null; |
504 | 504 |
505 /** | 505 /** |
506 * Id to node mapping. | 506 * Id to node mapping. |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 RemoteDomAgent.SetTextNodeValue(devtools.Callback.wrap(mycallback), | 618 RemoteDomAgent.SetTextNodeValue(devtools.Callback.wrap(mycallback), |
619 node.id_, text); | 619 node.id_, text); |
620 }; | 620 }; |
621 | 621 |
622 | 622 |
623 /** | 623 /** |
624 * Universal callback wrapper for edit dom operations. | 624 * Universal callback wrapper for edit dom operations. |
625 * @param {devtools.DomNode} node Node to apply local changes on. | 625 * @param {devtools.DomNode} node Node to apply local changes on. |
626 * @param {Function} callback Post-operation call. | 626 * @param {Function} callback Post-operation call. |
627 * @param {boolean} success True iff operation has completed successfully. | 627 * @param {boolean} success True iff operation has completed successfully. |
| 628 * @private |
628 */ | 629 */ |
629 devtools.DomAgent.prototype.didApplyDomChange_ = function(node, | 630 devtools.DomAgent.prototype.didApplyDomChange_ = function(node, |
630 callback, success) { | 631 callback, success) { |
631 if (!success) { | 632 if (!success) { |
632 return; | 633 return; |
633 } | 634 } |
634 callback(); | 635 callback(); |
635 var elem = WebInspector.panels.elements.treeOutline.findTreeElement(node); | 636 var elem = WebInspector.panels.elements.treeOutline.findTreeElement(node); |
636 if (elem) { | 637 if (elem) { |
637 elem._updateTitle(); | 638 elem._updateTitle(); |
638 } | 639 } |
639 }; | 640 }; |
640 | 641 |
641 | 642 |
642 /** | 643 /** |
643 * @see DomAgentDelegate. | 644 * @see DomAgentDelegate. |
644 * {@inheritDoc}. | 645 * {@inheritDoc}. |
| 646 * @private |
645 */ | 647 */ |
646 devtools.DomAgent.prototype.attributesUpdated = function(nodeId, attrsArray) { | 648 devtools.DomAgent.prototype.attributesUpdated_ = function(nodeId, attrsArray) { |
647 var node = this.idToDomNode_[nodeId]; | 649 var node = this.idToDomNode_[nodeId]; |
648 node.setAttributesPayload_(attrsArray); | 650 node.setAttributesPayload_(attrsArray); |
649 }; | 651 }; |
650 | 652 |
651 | 653 |
652 /** | 654 /** |
653 * Returns node for id. | 655 * Returns node for id. |
654 * @param {number} nodeId Id to get node for. | 656 * @param {number} nodeId Id to get node for. |
655 * @return {devtools.DomNode} Node with given id. | 657 * @return {devtools.DomNode} Node with given id. |
656 */ | 658 */ |
657 devtools.DomAgent.prototype.getNodeForId = function(nodeId) { | 659 devtools.DomAgent.prototype.getNodeForId = function(nodeId) { |
658 return this.idToDomNode_[nodeId]; | 660 return this.idToDomNode_[nodeId]; |
659 }; | 661 }; |
660 | 662 |
661 | 663 |
662 /** | 664 /** |
663 * @see DomAgentDelegate. | 665 * @see DomAgentDelegate. |
664 * {@inheritDoc}. | 666 * {@inheritDoc}. |
| 667 * @private |
665 */ | 668 */ |
666 devtools.DomAgent.prototype.setDocumentElement = function(payload) { | 669 devtools.DomAgent.prototype.setDocumentElement_ = function(payload) { |
667 var doc = this.getDocument(); | 670 var doc = this.getDocument(); |
668 if (doc.documentElement) { | 671 if (doc.documentElement) { |
669 this.reset(); | 672 this.reset(); |
670 doc = this.getDocument(); | 673 doc = this.getDocument(); |
671 } | 674 } |
672 this.setChildNodes(0, [payload]); | 675 this.setChildNodes_(0, [payload]); |
673 doc.documentElement = doc.firstChild; | 676 doc.documentElement = doc.firstChild; |
674 doc.documentElement.ownerDocument = doc; | 677 doc.documentElement.ownerDocument = doc; |
675 WebInspector.panels.elements.reset(); | 678 WebInspector.panels.elements.reset(); |
676 }; | 679 }; |
677 | 680 |
678 | 681 |
679 /** | 682 /** |
680 * @see DomAgentDelegate. | 683 * @see DomAgentDelegate. |
681 * {@inheritDoc}. | 684 * {@inheritDoc}. |
| 685 * @private |
682 */ | 686 */ |
683 devtools.DomAgent.prototype.setChildNodes = function(parentId, payloads) { | 687 devtools.DomAgent.prototype.setChildNodes_ = function(parentId, payloads) { |
684 var parent = this.idToDomNode_[parentId]; | 688 var parent = this.idToDomNode_[parentId]; |
685 if (parent.children) { | 689 if (parent.children) { |
686 return; | 690 return; |
687 } | 691 } |
688 parent.setChildrenPayload_(payloads); | 692 parent.setChildrenPayload_(payloads); |
689 this.bindNodes_(parent.children); | 693 this.bindNodes_(parent.children); |
690 }; | 694 }; |
691 | 695 |
692 | 696 |
693 /** | 697 /** |
694 * Binds nodes to ids recursively. | 698 * Binds nodes to ids recursively. |
695 * @param {Array.<devtools.DomNode>} children Nodes to bind. | 699 * @param {Array.<devtools.DomNode>} children Nodes to bind. |
| 700 * @private |
696 */ | 701 */ |
697 devtools.DomAgent.prototype.bindNodes_ = function(children) { | 702 devtools.DomAgent.prototype.bindNodes_ = function(children) { |
698 for (var i = 0; i < children.length; ++i) { | 703 for (var i = 0; i < children.length; ++i) { |
699 var child = children[i]; | 704 var child = children[i]; |
700 this.idToDomNode_[child.id_] = child; | 705 this.idToDomNode_[child.id_] = child; |
701 if (child.children) { | 706 if (child.children) { |
702 this.bindNodes_(child.children); | 707 this.bindNodes_(child.children); |
703 } | 708 } |
704 } | 709 } |
705 }; | 710 }; |
706 | 711 |
707 | 712 |
708 /** | 713 /** |
709 * @see DomAgentDelegate. | 714 * @see DomAgentDelegate. |
710 * {@inheritDoc}. | 715 * {@inheritDoc}. |
| 716 * @private |
711 */ | 717 */ |
712 devtools.DomAgent.prototype.hasChildrenUpdated = function(nodeId, newValue) { | 718 devtools.DomAgent.prototype.hasChildrenUpdated_ = function(nodeId, newValue) { |
713 var node = this.idToDomNode_[nodeId]; | 719 var node = this.idToDomNode_[nodeId]; |
714 var outline = WebInspector.panels.elements.treeOutline; | 720 var outline = WebInspector.panels.elements.treeOutline; |
715 var treeElement = outline.findTreeElement(node); | 721 var treeElement = outline.findTreeElement(node); |
716 if (treeElement) { | 722 if (treeElement) { |
717 treeElement.hasChildren = newValue; | 723 treeElement.hasChildren = newValue; |
718 treeElement.whitespaceIgnored = Preferences.ignoreWhitespace; | 724 treeElement.whitespaceIgnored = Preferences.ignoreWhitespace; |
719 } | 725 } |
720 }; | 726 }; |
721 | 727 |
722 | 728 |
723 /** | 729 /** |
724 * @see DomAgentDelegate. | 730 * @see DomAgentDelegate. |
725 * {@inheritDoc}. | 731 * {@inheritDoc}. |
| 732 * @private |
726 */ | 733 */ |
727 devtools.DomAgent.prototype.childNodeInserted = function( | 734 devtools.DomAgent.prototype.childNodeInserted_ = function( |
728 parentId, prevId, payload) { | 735 parentId, prevId, payload) { |
729 var parent = this.idToDomNode_[parentId]; | 736 var parent = this.idToDomNode_[parentId]; |
730 var prev = this.idToDomNode_[prevId]; | 737 var prev = this.idToDomNode_[prevId]; |
731 var node = parent.insertChild_(prev, payload); | 738 var node = parent.insertChild_(prev, payload); |
732 this.idToDomNode_[node.id_] = node; | 739 this.idToDomNode_[node.id_] = node; |
733 var event = { target : node, relatedNode : parent }; | 740 var event = { target : node, relatedNode : parent }; |
734 this.getDocument().fireDomEvent_('DOMNodeInserted', event); | 741 this.getDocument().fireDomEvent_('DOMNodeInserted', event); |
735 }; | 742 }; |
736 | 743 |
737 | 744 |
738 /** | 745 /** |
739 * @see DomAgentDelegate. | 746 * @see DomAgentDelegate. |
740 * {@inheritDoc}. | 747 * {@inheritDoc}. |
| 748 * @private |
741 */ | 749 */ |
742 devtools.DomAgent.prototype.childNodeRemoved = function( | 750 devtools.DomAgent.prototype.childNodeRemoved_ = function( |
743 parentId, nodeId) { | 751 parentId, nodeId) { |
744 var parent = this.idToDomNode_[parentId]; | 752 var parent = this.idToDomNode_[parentId]; |
745 var node = this.idToDomNode_[nodeId]; | 753 var node = this.idToDomNode_[nodeId]; |
746 parent.removeChild_(node); | 754 parent.removeChild_(node); |
747 var event = { target : node, relatedNode : parent }; | 755 var event = { target : node, relatedNode : parent }; |
748 this.getDocument().fireDomEvent_('DOMNodeRemoved', event); | 756 this.getDocument().fireDomEvent_('DOMNodeRemoved', event); |
749 delete this.idToDomNode_[nodeId]; | 757 delete this.idToDomNode_[nodeId]; |
750 }; | 758 }; |
751 | 759 |
752 | 760 |
(...skipping 29 matching lines...) Expand all Loading... |
782 callback(nodes); | 790 callback(nodes); |
783 this.searchResults_ = null; | 791 this.searchResults_ = null; |
784 }; | 792 }; |
785 | 793 |
786 | 794 |
787 /** | 795 /** |
788 * Invokes callback for each node that needs to gain highlighting. | 796 * Invokes callback for each node that needs to gain highlighting. |
789 * @param {function(Array.<devtools.DomNode>)} callback to accept the result. | 797 * @param {function(Array.<devtools.DomNode>)} callback to accept the result. |
790 * @param {Array.<number>} searchResults to be populated. | 798 * @param {Array.<number>} searchResults to be populated. |
791 * @param {Array.<number>} nodeIds Ids to highlight. | 799 * @param {Array.<number>} nodeIds Ids to highlight. |
| 800 * @private |
792 */ | 801 */ |
793 devtools.DomAgent.prototype.performSearchCallback_ = function(callback, | 802 devtools.DomAgent.prototype.performSearchCallback_ = function(callback, |
794 searchResults, nodeIds) { | 803 searchResults, nodeIds) { |
795 | 804 |
796 if (this.searchResults_ !== searchResults) | 805 if (this.searchResults_ !== searchResults) |
797 return; // another search has requested and this results are obsolete | 806 return; // another search has requested and this results are obsolete |
798 | 807 |
799 var nodes = []; | 808 var nodes = []; |
800 | 809 |
801 for (var i = 0; i < nodeIds.length; ++i) { | 810 for (var i = 0; i < nodeIds.length; ++i) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 function onlyTextChild() { | 1023 function onlyTextChild() { |
1015 if (!this.children) { | 1024 if (!this.children) { |
1016 return null; | 1025 return null; |
1017 } else if (this.children.length == 1 && | 1026 } else if (this.children.length == 1 && |
1018 this.children[0].nodeType == Node.TEXT_NODE) { | 1027 this.children[0].nodeType == Node.TEXT_NODE) { |
1019 return this.children[0]; | 1028 return this.children[0]; |
1020 } else { | 1029 } else { |
1021 return null; | 1030 return null; |
1022 } | 1031 } |
1023 } | 1032 } |
OLD | NEW |