Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(769)

Side by Side Diff: Source/devtools/front_end/sdk/DOMModel.js

Issue 1273313002: DevTools: introduce dom markers, decorate hidden, forced state and breakpoint elements using marker… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: for landing Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/devtools/front_end/sdk/CSSStyleModel.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 this._shadowRootType = payload.shadowRootType; 55 this._shadowRootType = payload.shadowRootType;
56 this._frameId = payload.frameId || null; 56 this._frameId = payload.frameId || null;
57 57
58 this._shadowRoots = []; 58 this._shadowRoots = [];
59 59
60 this._attributes = []; 60 this._attributes = [];
61 this._attributesMap = {}; 61 this._attributesMap = {};
62 if (payload.attributes) 62 if (payload.attributes)
63 this._setAttributesPayload(payload.attributes); 63 this._setAttributesPayload(payload.attributes);
64 64
65 this._userProperties = {}; 65 this._markers = {};
66 this._descendantUserPropertyCounters = {}; 66 this._subtreeMarkerCount = 0;
67 67
68 this._childNodeCount = payload.childNodeCount || 0; 68 this._childNodeCount = payload.childNodeCount || 0;
69 this._children = null; 69 this._children = null;
70 70
71 this.nextSibling = null; 71 this.nextSibling = null;
72 this.previousSibling = null; 72 this.previousSibling = null;
73 this.firstChild = null; 73 this.firstChild = null;
74 this.lastChild = null; 74 this.lastChild = null;
75 this.parentNode = null; 75 this.parentNode = null;
76 76
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } else { 642 } else {
643 var shadowRootIndex = this._shadowRoots.indexOf(node); 643 var shadowRootIndex = this._shadowRoots.indexOf(node);
644 if (shadowRootIndex !== -1) { 644 if (shadowRootIndex !== -1) {
645 this._shadowRoots.splice(shadowRootIndex, 1); 645 this._shadowRoots.splice(shadowRootIndex, 1);
646 } else { 646 } else {
647 console.assert(this._children.indexOf(node) !== -1); 647 console.assert(this._children.indexOf(node) !== -1);
648 this._children.splice(this._children.indexOf(node), 1); 648 this._children.splice(this._children.indexOf(node), 1);
649 } 649 }
650 } 650 }
651 node.parentNode = null; 651 node.parentNode = null;
652 node._updateChildUserPropertyCountsOnRemoval(this); 652 this._subtreeMarkerCount -= node._subtreeMarkerCount;
653 if (node._subtreeMarkerCount)
654 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Events .MarkersChanged, this);
653 this._renumber(); 655 this._renumber();
654 }, 656 },
655 657
656 /** 658 /**
657 * @param {!Array.<!DOMAgent.Node>} payloads 659 * @param {!Array.<!DOMAgent.Node>} payloads
658 */ 660 */
659 _setChildrenPayload: function(payloads) 661 _setChildrenPayload: function(payloads)
660 { 662 {
661 // We set children in the constructor. 663 // We set children in the constructor.
662 if (this._contentDocument) 664 if (this._contentDocument)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 }, 779 },
778 780
779 /** 781 /**
780 * @return {boolean} 782 * @return {boolean}
781 */ 783 */
782 isXMLNode: function() 784 isXMLNode: function()
783 { 785 {
784 return !!this.ownerDocument && !!this.ownerDocument.xmlVersion; 786 return !!this.ownerDocument && !!this.ownerDocument.xmlVersion;
785 }, 787 },
786 788
787 _updateChildUserPropertyCountsOnRemoval: function(parentNode) 789 /**
788 { 790 * @param {string} name
789 var result = {}; 791 * @param {?*} value
790 if (this._userProperties) { 792 */
791 for (var name in this._userProperties) 793 setMarker: function(name, value)
792 result[name] = (result[name] || 0) + 1;
793 }
794
795 if (this._descendantUserPropertyCounters) {
796 for (var name in this._descendantUserPropertyCounters) {
797 var counter = this._descendantUserPropertyCounters[name];
798 result[name] = (result[name] || 0) + counter;
799 }
800 }
801
802 for (var name in result)
803 parentNode._updateDescendantUserPropertyCount(name, -result[name]);
804 },
805
806 _updateDescendantUserPropertyCount: function(name, delta)
807 {
808 if (!this._descendantUserPropertyCounters.hasOwnProperty(name))
809 this._descendantUserPropertyCounters[name] = 0;
810 this._descendantUserPropertyCounters[name] += delta;
811 if (!this._descendantUserPropertyCounters[name])
812 delete this._descendantUserPropertyCounters[name];
813 if (this.parentNode)
814 this.parentNode._updateDescendantUserPropertyCount(name, delta);
815 },
816
817 setUserProperty: function(name, value)
818 { 794 {
819 if (value === null) { 795 if (value === null) {
820 this.removeUserProperty(name); 796 if (!this._markers.hasOwnProperty(name))
797 return;
798
799 delete this._markers[name];
800 for (var node = this; node; node = node.parentNode)
801 --node._subtreeMarkerCount;
802 for (var node = this; node; node = node.parentNode)
803 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Ev ents.MarkersChanged, node);
821 return; 804 return;
822 } 805 }
823 806
824 if (this.parentNode && !this._userProperties.hasOwnProperty(name)) 807 if (this.parentNode && !this._markers.hasOwnProperty(name)) {
825 this.parentNode._updateDescendantUserPropertyCount(name, 1); 808 for (var node = this; node; node = node.parentNode)
826 809 ++node._subtreeMarkerCount;
827 this._userProperties[name] = value; 810 }
828 }, 811 this._markers[name] = value;
829 812 for (var node = this; node; node = node.parentNode)
830 removeUserProperty: function(name) 813 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Events .MarkersChanged, node);
831 {
832 if (!this._userProperties.hasOwnProperty(name))
833 return;
834
835 delete this._userProperties[name];
836 if (this.parentNode)
837 this.parentNode._updateDescendantUserPropertyCount(name, -1);
838 }, 814 },
839 815
840 /** 816 /**
841 * @param {string} name 817 * @param {string} name
842 * @return {?T} 818 * @return {?T}
843 * @template T 819 * @template T
844 */ 820 */
845 getUserProperty: function(name) 821 marker: function(name)
846 { 822 {
847 return (this._userProperties && this._userProperties[name]) || null; 823 return this._markers[name] || null;
848 }, 824 },
849 825
850 /** 826 /**
851 * @param {string} name 827 * @return {!Array<string>}
852 * @return {number}
853 */ 828 */
854 descendantUserPropertyCount: function(name) 829 markers: function()
855 { 830 {
856 return this._descendantUserPropertyCounters && this._descendantUserPrope rtyCounters[name] ? this._descendantUserPropertyCounters[name] : 0; 831 return Object.values(this._markers);
857 }, 832 },
858 833
859 /** 834 /**
835 * @param {function(!WebInspector.DOMNode, string)} visitor
836 */
837 traverseMarkers: function(visitor)
838 {
839 /**
840 * @param {!WebInspector.DOMNode} node
841 */
842 function traverse(node)
843 {
844 if (!node._subtreeMarkerCount)
845 return;
846 for (var marker in node._markers)
847 visitor(node, marker);
848 if (!node._children)
849 return;
850 for (var child of node._children)
851 traverse(child);
852 }
853 traverse(this);
854 },
855
856 /**
860 * @param {string} url 857 * @param {string} url
861 * @return {?string} 858 * @return {?string}
862 */ 859 */
863 resolveURL: function(url) 860 resolveURL: function(url)
864 { 861 {
865 if (!url) 862 if (!url)
866 return url; 863 return url;
867 for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCand idate = frameOwnerCandidate.parentNode) { 864 for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCand idate = frameOwnerCandidate.parentNode) {
868 if (frameOwnerCandidate.baseURL) 865 if (frameOwnerCandidate.baseURL)
869 return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.ba seURL, url); 866 return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.ba seURL, url);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 DOMMutated: "DOMMutated", 1076 DOMMutated: "DOMMutated",
1080 NodeInserted: "NodeInserted", 1077 NodeInserted: "NodeInserted",
1081 NodeInspected: "NodeInspected", 1078 NodeInspected: "NodeInspected",
1082 NodeRemoved: "NodeRemoved", 1079 NodeRemoved: "NodeRemoved",
1083 DocumentUpdated: "DocumentUpdated", 1080 DocumentUpdated: "DocumentUpdated",
1084 ChildNodeCountUpdated: "ChildNodeCountUpdated", 1081 ChildNodeCountUpdated: "ChildNodeCountUpdated",
1085 UndoRedoRequested: "UndoRedoRequested", 1082 UndoRedoRequested: "UndoRedoRequested",
1086 UndoRedoCompleted: "UndoRedoCompleted", 1083 UndoRedoCompleted: "UndoRedoCompleted",
1087 DistributedNodesChanged: "DistributedNodesChanged", 1084 DistributedNodesChanged: "DistributedNodesChanged",
1088 ModelSuspended: "ModelSuspended", 1085 ModelSuspended: "ModelSuspended",
1089 InspectModeWillBeToggled: "InspectModeWillBeToggled" 1086 InspectModeWillBeToggled: "InspectModeWillBeToggled",
1087 MarkersChanged: "MarkersChanged"
1090 } 1088 }
1091 1089
1092 1090
1093 /** 1091 /**
1094 * @param {!WebInspector.RemoteObject} object 1092 * @param {!WebInspector.RemoteObject} object
1095 */ 1093 */
1096 WebInspector.DOMModel.highlightObjectAsDOMNode = function(object) 1094 WebInspector.DOMModel.highlightObjectAsDOMNode = function(object)
1097 { 1095 {
1098 var domModel = WebInspector.DOMModel.fromTarget(object.target()); 1096 var domModel = WebInspector.DOMModel.fromTarget(object.target());
1099 if (domModel) 1097 if (domModel)
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 } 2164 }
2167 2165
2168 /** 2166 /**
2169 * @param {!WebInspector.Target} target 2167 * @param {!WebInspector.Target} target
2170 * @return {?WebInspector.DOMModel} 2168 * @return {?WebInspector.DOMModel}
2171 */ 2169 */
2172 WebInspector.DOMModel.fromTarget = function(target) 2170 WebInspector.DOMModel.fromTarget = function(target)
2173 { 2171 {
2174 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); 2172 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel));
2175 } 2173 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/CSSStyleModel.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698