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

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: 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
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 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Events.Mar kersChanged, this);
dgozman 2015/08/07 23:35:05 if (node._subtreeMarkerCount) ...
pfeldman 2015/08/10 21:35:17 Done.
653 this._renumber(); 654 this._renumber();
654 }, 655 },
655 656
656 /** 657 /**
657 * @param {!Array.<!DOMAgent.Node>} payloads 658 * @param {!Array.<!DOMAgent.Node>} payloads
658 */ 659 */
659 _setChildrenPayload: function(payloads) 660 _setChildrenPayload: function(payloads)
660 { 661 {
661 // We set children in the constructor. 662 // We set children in the constructor.
662 if (this._contentDocument) 663 if (this._contentDocument)
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 }, 778 },
778 779
779 /** 780 /**
780 * @return {boolean} 781 * @return {boolean}
781 */ 782 */
782 isXMLNode: function() 783 isXMLNode: function()
783 { 784 {
784 return !!this.ownerDocument && !!this.ownerDocument.xmlVersion; 785 return !!this.ownerDocument && !!this.ownerDocument.xmlVersion;
785 }, 786 },
786 787
787 _updateChildUserPropertyCountsOnRemoval: function(parentNode) 788 /**
788 { 789 * @param {string} name
789 var result = {}; 790 * @param {?*} value
790 if (this._userProperties) { 791 */
791 for (var name in this._userProperties) 792 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 { 793 {
819 if (value === null) { 794 if (value === null) {
820 this.removeUserProperty(name); 795 if (!this._markers.hasOwnProperty(name))
796 return;
797
798 delete this._markers[name];
799 for (var node = this; node; node = node.parentNode) {
800 --node._subtreeMarkerCount;
801 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Ev ents.MarkersChanged, node);
dgozman 2015/08/07 23:35:05 This call is done below.
pfeldman 2015/08/10 21:35:17 Done.
802 }
803 for (var node = this; node; node = node.parentNode)
804 this._domModel.dispatchEventToListeners(WebInspector.DOMModel.Ev ents.MarkersChanged, node);
dgozman 2015/08/07 23:35:05 This will make it O(n^2), since every event handle
pfeldman 2015/08/10 21:35:17 This will only be n^2 for the nodes that have mark
821 return; 805 return;
822 } 806 }
823 807
824 if (this.parentNode && !this._userProperties.hasOwnProperty(name)) 808 if (this.parentNode && !this._markers.hasOwnProperty(name)) {
825 this.parentNode._updateDescendantUserPropertyCount(name, 1); 809 for (var node = this; node; node = node.parentNode)
826 810 ++node._subtreeMarkerCount;
827 this._userProperties[name] = value; 811 }
828 }, 812 this._markers[name] = value;
829 813 for (var node = this; node; node = node.parentNode)
830 removeUserProperty: function(name) 814 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 }, 815 },
839 816
840 /** 817 /**
841 * @param {string} name 818 * @param {string} name
842 * @return {?T} 819 * @return {?T}
843 * @template T 820 * @template T
844 */ 821 */
845 getUserProperty: function(name) 822 marker: function(name)
846 { 823 {
847 return (this._userProperties && this._userProperties[name]) || null; 824 return (this._markers && this._markers[name]) || null;
dgozman 2015/08/07 23:35:05 |this._markers| is always an object.
pfeldman 2015/08/10 21:35:17 Done.
848 }, 825 },
849 826
850 /** 827 /**
851 * @param {string} name 828 * @return {!Array<string>}
852 * @return {number}
853 */ 829 */
854 descendantUserPropertyCount: function(name) 830 markers: function()
dgozman 2015/08/07 23:35:05 Is this one used?
pfeldman 2015/08/10 21:35:17 It is.
855 { 831 {
856 return this._descendantUserPropertyCounters && this._descendantUserPrope rtyCounters[name] ? this._descendantUserPropertyCounters[name] : 0; 832 return Object.values(this._markers);
857 }, 833 },
858 834
859 /** 835 /**
836 * @param {function(!WebInspector.DOMNode, string)} visitor
837 */
838 traverseMarkers: function(visitor)
839 {
840 /**
841 * @param {!WebInspector.DOMNode} node
842 */
843 function traverse(node)
844 {
845 if (!node._subtreeMarkerCount)
846 return;
847 for (var marker in node._markers)
848 visitor(node, marker);
849 if (!node._children)
850 return;
851 for (var child of node._children)
852 traverse(child);
853 }
854 traverse(this);
855 },
856
857 /**
860 * @param {string} url 858 * @param {string} url
861 * @return {?string} 859 * @return {?string}
862 */ 860 */
863 resolveURL: function(url) 861 resolveURL: function(url)
864 { 862 {
865 if (!url) 863 if (!url)
866 return url; 864 return url;
867 for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCand idate = frameOwnerCandidate.parentNode) { 865 for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCand idate = frameOwnerCandidate.parentNode) {
868 if (frameOwnerCandidate.baseURL) 866 if (frameOwnerCandidate.baseURL)
869 return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.ba seURL, url); 867 return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.ba seURL, url);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 DOMMutated: "DOMMutated", 1077 DOMMutated: "DOMMutated",
1080 NodeInserted: "NodeInserted", 1078 NodeInserted: "NodeInserted",
1081 NodeInspected: "NodeInspected", 1079 NodeInspected: "NodeInspected",
1082 NodeRemoved: "NodeRemoved", 1080 NodeRemoved: "NodeRemoved",
1083 DocumentUpdated: "DocumentUpdated", 1081 DocumentUpdated: "DocumentUpdated",
1084 ChildNodeCountUpdated: "ChildNodeCountUpdated", 1082 ChildNodeCountUpdated: "ChildNodeCountUpdated",
1085 UndoRedoRequested: "UndoRedoRequested", 1083 UndoRedoRequested: "UndoRedoRequested",
1086 UndoRedoCompleted: "UndoRedoCompleted", 1084 UndoRedoCompleted: "UndoRedoCompleted",
1087 DistributedNodesChanged: "DistributedNodesChanged", 1085 DistributedNodesChanged: "DistributedNodesChanged",
1088 ModelSuspended: "ModelSuspended", 1086 ModelSuspended: "ModelSuspended",
1089 InspectModeWillBeToggled: "InspectModeWillBeToggled" 1087 InspectModeWillBeToggled: "InspectModeWillBeToggled",
1088 MarkersChanged: "MarkersChanged"
1090 } 1089 }
1091 1090
1092 1091
1093 /** 1092 /**
1094 * @param {!WebInspector.RemoteObject} object 1093 * @param {!WebInspector.RemoteObject} object
1095 */ 1094 */
1096 WebInspector.DOMModel.highlightObjectAsDOMNode = function(object) 1095 WebInspector.DOMModel.highlightObjectAsDOMNode = function(object)
1097 { 1096 {
1098 var domModel = WebInspector.DOMModel.fromTarget(object.target()); 1097 var domModel = WebInspector.DOMModel.fromTarget(object.target());
1099 if (domModel) 1098 if (domModel)
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after
2166 } 2165 }
2167 2166
2168 /** 2167 /**
2169 * @param {!WebInspector.Target} target 2168 * @param {!WebInspector.Target} target
2170 * @return {?WebInspector.DOMModel} 2169 * @return {?WebInspector.DOMModel}
2171 */ 2170 */
2172 WebInspector.DOMModel.fromTarget = function(target) 2171 WebInspector.DOMModel.fromTarget = function(target)
2173 { 2172 {
2174 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel)); 2173 return /** @type {?WebInspector.DOMModel} */ (target.model(WebInspector.DOMM odel));
2175 } 2174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698