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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/ElementsPanel.js

Issue 2142653003: DevTools: move functionality away from ElementsPanel for better DOM tree control reuse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js » ('j') | 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) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com>
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 this.sidebarPanes.eventListeners = WebInspector.EventListenersWidget.createS idebarWrapper(); 82 this.sidebarPanes.eventListeners = WebInspector.EventListenersWidget.createS idebarWrapper();
83 83
84 this._stylesSidebarToolbar = this._createStylesSidebarToolbar(this.sidebarPa nes.styles); 84 this._stylesSidebarToolbar = this._createStylesSidebarToolbar(this.sidebarPa nes.styles);
85 85
86 WebInspector.moduleSetting("sidebarPosition").addChangeListener(this._update SidebarPosition.bind(this)); 86 WebInspector.moduleSetting("sidebarPosition").addChangeListener(this._update SidebarPosition.bind(this));
87 this._updateSidebarPosition(); 87 this._updateSidebarPosition();
88 this._loadSidebarViews(); 88 this._loadSidebarViews();
89 89
90 /** @type {!Array.<!WebInspector.ElementsTreeOutline>} */ 90 /** @type {!Array.<!WebInspector.ElementsTreeOutline>} */
91 this._treeOutlines = []; 91 this._treeOutlines = [];
92 /** @type {!Map.<!WebInspector.DOMModel, !WebInspector.ElementsTreeOutline>} */
93 this._modelToTreeOutline = new Map();
94 WebInspector.targetManager.observeTargets(this); 92 WebInspector.targetManager.observeTargets(this);
95 WebInspector.moduleSetting("showUAShadowDOM").addChangeListener(this._showUA ShadowDOMChanged.bind(this)); 93 WebInspector.moduleSetting("showUAShadowDOM").addChangeListener(this._showUA ShadowDOMChanged.bind(this));
96 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.DocumentUpdated, this._documentUpdatedEvent, this); 94 WebInspector.targetManager.addModelListener(WebInspector.DOMModel, WebInspec tor.DOMModel.Events.DocumentUpdated, this._documentUpdatedEvent, this);
97 WebInspector.extensionServer.addEventListener(WebInspector.ExtensionServer.E vents.SidebarPaneAdded, this._extensionSidebarPaneAdded, this); 95 WebInspector.extensionServer.addEventListener(WebInspector.ExtensionServer.E vents.SidebarPaneAdded, this._extensionSidebarPaneAdded, this);
98 } 96 }
99 97
100 WebInspector.ElementsPanel._elementsSidebarViewTitleSymbol = Symbol("title"); 98 WebInspector.ElementsPanel._elementsSidebarViewTitleSymbol = Symbol("title");
101 99
102 WebInspector.ElementsPanel.prototype = { 100 WebInspector.ElementsPanel.prototype = {
103 /** 101 /**
(...skipping 12 matching lines...) Expand all
116 * @return {!Element} 114 * @return {!Element}
117 */ 115 */
118 _createStylesSidebarToolbar: function(ssp) 116 _createStylesSidebarToolbar: function(ssp)
119 { 117 {
120 var container = createElementWithClass("div", "styles-sidebar-pane-toolb ar-container"); 118 var container = createElementWithClass("div", "styles-sidebar-pane-toolb ar-container");
121 var hbox = container.createChild("div", "hbox styles-sidebar-pane-toolba r"); 119 var hbox = container.createChild("div", "hbox styles-sidebar-pane-toolba r");
122 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pan e-filter-box"); 120 var filterContainerElement = hbox.createChild("div", "styles-sidebar-pan e-filter-box");
123 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterEle ment(WebInspector.UIString("Filter"), hbox, ssp.onFilterChanged.bind(ssp)); 121 var filterInput = WebInspector.StylesSidebarPane.createPropertyFilterEle ment(WebInspector.UIString("Filter"), hbox, ssp.onFilterChanged.bind(ssp));
124 filterContainerElement.appendChild(filterInput); 122 filterContainerElement.appendChild(filterInput);
125 var toolbar = new WebInspector.ExtensibleToolbar("styles-sidebarpane-too lbar", hbox); 123 var toolbar = new WebInspector.ExtensibleToolbar("styles-sidebarpane-too lbar", hbox);
126 toolbar.onLoad().then(() => toolbar.appendToolbarItem(WebInspector.Style sSidebarPane.createAddNewRuleButton(ssp)));
127 toolbar.element.classList.add("styles-pane-toolbar"); 124 toolbar.element.classList.add("styles-pane-toolbar");
128 toolbar.makeToggledGray(); 125 toolbar.makeToggledGray();
129 var toolbarPaneContainer = container.createChild("div", "styles-sidebar- toolbar-pane-container"); 126 var toolbarPaneContainer = container.createChild("div", "styles-sidebar- toolbar-pane-container");
130 this._toolbarPaneElement = createElementWithClass("div", "styles-sidebar -toolbar-pane"); 127 this._toolbarPaneElement = createElementWithClass("div", "styles-sidebar -toolbar-pane");
131 toolbarPaneContainer.appendChild(this._toolbarPaneElement); 128 toolbarPaneContainer.appendChild(this._toolbarPaneElement);
132 return container; 129 return container;
133 }, 130 },
134 131
135 /** 132 /**
136 * @param {?WebInspector.Widget} widget 133 * @param {?WebInspector.Widget} widget
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 this._currentToolbarPane.focus(); 193 this._currentToolbarPane.focus();
197 delete this._animatedToolbarPane; 194 delete this._animatedToolbarPane;
198 195
199 if (this._pendingWidget !== undefined) { 196 if (this._pendingWidget !== undefined) {
200 this._startToolbarPaneAnimation(this._pendingWidget); 197 this._startToolbarPaneAnimation(this._pendingWidget);
201 delete this._pendingWidget; 198 delete this._pendingWidget;
202 } 199 }
203 } 200 }
204 }, 201 },
205 202
206 _toggleHideElement: function()
207 {
208 var node = this.selectedDOMNode();
209 var treeOutline = this._treeOutlineForNode(node);
210 if (!node || !treeOutline)
211 return;
212 treeOutline.toggleHideElement(node);
213 },
214
215 _toggleEditAsHTML: function()
216 {
217 var node = this.selectedDOMNode();
218 var treeOutline = this._treeOutlineForNode(node);
219 if (!node || !treeOutline)
220 return;
221 treeOutline.toggleEditAsHTML(node);
222 },
223
224 _loadSidebarViews: function() 203 _loadSidebarViews: function()
225 { 204 {
226 var extensions = self.runtime.extensions("@WebInspector.Widget"); 205 var extensions = self.runtime.extensions("@WebInspector.Widget");
227 206
228 for (var i = 0; i < extensions.length; ++i) { 207 for (var i = 0; i < extensions.length; ++i) {
229 var descriptor = extensions[i].descriptor(); 208 var descriptor = extensions[i].descriptor();
230 if (descriptor["location"] !== "elements-panel") 209 if (descriptor["location"] !== "elements-panel")
231 continue; 210 continue;
232 211
233 var title = WebInspector.UIString(descriptor["title"]); 212 var title = WebInspector.UIString(descriptor["title"]);
(...skipping 25 matching lines...) Expand all
259 var domModel = WebInspector.DOMModel.fromTarget(target); 238 var domModel = WebInspector.DOMModel.fromTarget(target);
260 if (!domModel) 239 if (!domModel)
261 return; 240 return;
262 var treeOutline = new WebInspector.ElementsTreeOutline(domModel, true, t rue); 241 var treeOutline = new WebInspector.ElementsTreeOutline(domModel, true, t rue);
263 treeOutline.setWordWrap(WebInspector.moduleSetting("domWordWrap").get()) ; 242 treeOutline.setWordWrap(WebInspector.moduleSetting("domWordWrap").get()) ;
264 treeOutline.wireToDOMModel(); 243 treeOutline.wireToDOMModel();
265 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Sel ectedNodeChanged, this._selectedNodeChanged, this); 244 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Sel ectedNodeChanged, this._selectedNodeChanged, this);
266 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Ele mentsTreeUpdated, this._updateBreadcrumbIfNeeded, this); 245 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Ele mentsTreeUpdated, this._updateBreadcrumbIfNeeded, this);
267 new WebInspector.ElementsTreeElementHighlighter(treeOutline); 246 new WebInspector.ElementsTreeElementHighlighter(treeOutline);
268 this._treeOutlines.push(treeOutline); 247 this._treeOutlines.push(treeOutline);
269 this._modelToTreeOutline.set(domModel, treeOutline);
270 248
271 // Perform attach if necessary. 249 // Perform attach if necessary.
272 if (this.isShowing()) 250 if (this.isShowing())
273 this.wasShown(); 251 this.wasShown();
274 252
275 }, 253 },
276 254
277 /** 255 /**
278 * @override 256 * @override
279 * @param {!WebInspector.Target} target 257 * @param {!WebInspector.Target} target
280 */ 258 */
281 targetRemoved: function(target) 259 targetRemoved: function(target)
282 { 260 {
283 var domModel = WebInspector.DOMModel.fromTarget(target); 261 var domModel = WebInspector.DOMModel.fromTarget(target);
284 if (!domModel) 262 if (!domModel)
285 return; 263 return;
286 var treeOutline = this._modelToTreeOutline.remove(domModel); 264 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(domModel) ;
287 treeOutline.unwireFromDOMModel(); 265 treeOutline.unwireFromDOMModel();
288 this._treeOutlines.remove(treeOutline); 266 this._treeOutlines.remove(treeOutline);
289 treeOutline.element.remove(); 267 treeOutline.element.remove();
290 }, 268 },
291 269
292 _updateTreeOutlineVisibleWidth: function() 270 _updateTreeOutlineVisibleWidth: function()
293 { 271 {
294 if (!this._treeOutlines.length) 272 if (!this._treeOutlines.length)
295 return; 273 return;
296 274
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 402
425 /** 403 /**
426 * @param {!WebInspector.DOMModel} domModel 404 * @param {!WebInspector.DOMModel} domModel
427 * @param {?WebInspector.DOMDocument} inspectedRootDocument 405 * @param {?WebInspector.DOMDocument} inspectedRootDocument
428 */ 406 */
429 _documentUpdated: function(domModel, inspectedRootDocument) 407 _documentUpdated: function(domModel, inspectedRootDocument)
430 { 408 {
431 this._reset(); 409 this._reset();
432 this.searchCanceled(); 410 this.searchCanceled();
433 411
434 var treeOutline = this._modelToTreeOutline.get(domModel); 412 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(domModel) ;
435 treeOutline.rootDOMNode = inspectedRootDocument; 413 treeOutline.rootDOMNode = inspectedRootDocument;
436 414
437 if (!inspectedRootDocument) { 415 if (!inspectedRootDocument) {
438 if (this.isShowing()) 416 if (this.isShowing())
439 domModel.requestDocument(); 417 domModel.requestDocument();
440 return; 418 return;
441 } 419 }
442 420
443 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(domModel); 421 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(domModel);
444 422
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 } 675 }
698 }, 676 },
699 677
700 _hideSearchHighlights: function() 678 _hideSearchHighlights: function()
701 { 679 {
702 if (!this._searchResults || !this._searchResults.length || this._current SearchResultIndex < 0) 680 if (!this._searchResults || !this._searchResults.length || this._current SearchResultIndex < 0)
703 return; 681 return;
704 var searchResult = this._searchResults[this._currentSearchResultIndex]; 682 var searchResult = this._searchResults[this._currentSearchResultIndex];
705 if (!searchResult.node) 683 if (!searchResult.node)
706 return; 684 return;
707 var treeOutline = this._modelToTreeOutline.get(searchResult.node.domMode l()); 685 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(searchRes ult.node.domModel());
708 var treeElement = treeOutline.findTreeElement(searchResult.node); 686 var treeElement = treeOutline.findTreeElement(searchResult.node);
709 if (treeElement) 687 if (treeElement)
710 treeElement.hideSearchHighlights(); 688 treeElement.hideSearchHighlights();
711 }, 689 },
712 690
713 /** 691 /**
714 * @return {?WebInspector.DOMNode} 692 * @return {?WebInspector.DOMNode}
715 */ 693 */
716 selectedDOMNode: function() 694 selectedDOMNode: function()
717 { 695 {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 }, 786 },
809 787
810 /** 788 /**
811 * @param {?WebInspector.DOMNode} node 789 * @param {?WebInspector.DOMNode} node
812 * @return {?WebInspector.ElementsTreeOutline} 790 * @return {?WebInspector.ElementsTreeOutline}
813 */ 791 */
814 _treeOutlineForNode: function(node) 792 _treeOutlineForNode: function(node)
815 { 793 {
816 if (!node) 794 if (!node)
817 return null; 795 return null;
818 return this._modelToTreeOutline.get(node.domModel()) || null; 796 return WebInspector.ElementsTreeOutline.forDOMModel(node.domModel());
819 }, 797 },
820 798
821 /** 799 /**
822 * @return {?WebInspector.ElementsTreeOutline} 800 * @return {?WebInspector.ElementsTreeOutline}
823 */ 801 */
824 _focusedTreeOutline: function() 802 _focusedTreeOutline: function()
825 { 803 {
826 for (var i = 0; i < this._treeOutlines.length; ++i) { 804 for (var i = 0; i < this._treeOutlines.length; ++i) {
827 if (this._treeOutlines[i].hasFocus()) 805 if (this._treeOutlines[i].hasFocus())
828 return this._treeOutlines[i]; 806 return this._treeOutlines[i];
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 node.highlightForTwoSeconds(); 877 node.highlightForTwoSeconds();
900 878
901 this.selectDOMNode(node, true); 879 this.selectDOMNode(node, true);
902 delete this._omitDefaultSelection; 880 delete this._omitDefaultSelection;
903 881
904 if (!this._notFirstInspectElement) 882 if (!this._notFirstInspectElement)
905 InspectorFrontendHost.inspectElementCompleted(); 883 InspectorFrontendHost.inspectElementCompleted();
906 this._notFirstInspectElement = true; 884 this._notFirstInspectElement = true;
907 }, 885 },
908 886
909 /**
910 * @param {!Event} event
911 * @param {!WebInspector.ContextMenu} contextMenu
912 * @param {!Object} object
913 */
914 appendApplicableItems: function(event, contextMenu, object)
915 {
916 if (!(object instanceof WebInspector.RemoteObject && (/** @type {!WebIns pector.RemoteObject} */ (object)).isNode())
917 && !(object instanceof WebInspector.DOMNode)
918 && !(object instanceof WebInspector.DeferredDOMNode)) {
919 return;
920 }
921
922 // Add debbuging-related actions
923 if (object instanceof WebInspector.DOMNode) {
924 contextMenu.appendSeparator();
925 WebInspector.domBreakpointsSidebarPane.populateNodeContextMenu(objec t, contextMenu, true);
926 }
927
928 // Skip adding "Reveal..." menu item for our own tree outline.
929 if (this.element.isAncestor(/** @type {!Node} */ (event.target)))
930 return;
931 var commandCallback = WebInspector.Revealer.reveal.bind(WebInspector.Rev ealer, object);
932
933 contextMenu.appendItem(WebInspector.UIString.capitalize("Reveal in Eleme nts ^panel"), commandCallback);
934 },
935
936 _sidebarContextMenuEventFired: function(event) 887 _sidebarContextMenuEventFired: function(event)
937 { 888 {
938 var contextMenu = new WebInspector.ContextMenu(event); 889 var contextMenu = new WebInspector.ContextMenu(event);
939 contextMenu.appendApplicableItems(/** @type {!Object} */ (event.deepElem entFromPoint())); 890 contextMenu.appendApplicableItems(/** @type {!Object} */ (event.deepElem entFromPoint()));
940 contextMenu.show(); 891 contextMenu.show();
941 }, 892 },
942 893
943 _showUAShadowDOMChanged: function() 894 _showUAShadowDOMChanged: function()
944 { 895 {
945 for (var i = 0; i < this._treeOutlines.length; ++i) 896 for (var i = 0; i < this._treeOutlines.length; ++i)
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 */ 1048 */
1098 WebInspector.ElementsPanel.ContextMenuProvider = function() 1049 WebInspector.ElementsPanel.ContextMenuProvider = function()
1099 { 1050 {
1100 } 1051 }
1101 1052
1102 WebInspector.ElementsPanel.ContextMenuProvider.prototype = { 1053 WebInspector.ElementsPanel.ContextMenuProvider.prototype = {
1103 /** 1054 /**
1104 * @override 1055 * @override
1105 * @param {!Event} event 1056 * @param {!Event} event
1106 * @param {!WebInspector.ContextMenu} contextMenu 1057 * @param {!WebInspector.ContextMenu} contextMenu
1107 * @param {!Object} target 1058 * @param {!Object} object
1108 */ 1059 */
1109 appendApplicableItems: function(event, contextMenu, target) 1060 appendApplicableItems: function(event, contextMenu, object)
1110 { 1061 {
1111 WebInspector.ElementsPanel.instance().appendApplicableItems(event, conte xtMenu, target); 1062 if (!(object instanceof WebInspector.RemoteObject && (/** @type {!WebIns pector.RemoteObject} */ (object)).isNode())
1063 && !(object instanceof WebInspector.DOMNode)
1064 && !(object instanceof WebInspector.DeferredDOMNode)) {
1065 return;
1066 }
1067
1068 // Add debbuging-related actions
1069 if (object instanceof WebInspector.DOMNode) {
1070 contextMenu.appendSeparator();
1071 WebInspector.domBreakpointsSidebarPane.populateNodeContextMenu(objec t, contextMenu, true);
1072 }
1073
1074 // Skip adding "Reveal..." menu item for our own tree outline.
1075 if (WebInspector.ElementsPanel.instance().element.isAncestor(/** @type { !Node} */ (event.target)))
1076 return;
1077 var commandCallback = WebInspector.Revealer.reveal.bind(WebInspector.Rev ealer, object);
1078 contextMenu.appendItem(WebInspector.UIString.capitalize("Reveal in Eleme nts ^panel"), commandCallback);
1112 } 1079 }
1113 } 1080 }
1114 1081
1115 /** 1082 /**
1116 * @constructor 1083 * @constructor
1117 * @implements {WebInspector.Revealer} 1084 * @implements {WebInspector.Revealer}
1118 */ 1085 */
1119 WebInspector.ElementsPanel.DOMNodeRevealer = function() 1086 WebInspector.ElementsPanel.DOMNodeRevealer = function()
1120 { 1087 {
1121 } 1088 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 1181
1215 WebInspector.ElementsActionDelegate.prototype = { 1182 WebInspector.ElementsActionDelegate.prototype = {
1216 /** 1183 /**
1217 * @override 1184 * @override
1218 * @param {!WebInspector.Context} context 1185 * @param {!WebInspector.Context} context
1219 * @param {string} actionId 1186 * @param {string} actionId
1220 * @return {boolean} 1187 * @return {boolean}
1221 */ 1188 */
1222 handleAction: function(context, actionId) 1189 handleAction: function(context, actionId)
1223 { 1190 {
1191 var node = WebInspector.context.flavor(WebInspector.DOMNode);
1192 if (!node)
1193 return true;
1194 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(node.domM odel());
1195 if (!treeOutline)
1196 return true;
1197
1224 switch (actionId) { 1198 switch (actionId) {
1225 case "elements.hide-element": 1199 case "elements.hide-element":
1226 WebInspector.ElementsPanel.instance()._toggleHideElement(); 1200 treeOutline.toggleHideElement(node);
1227 return true; 1201 return true;
1228 case "elements.edit-as-html": 1202 case "elements.edit-as-html":
1229 WebInspector.ElementsPanel.instance()._toggleEditAsHTML(); 1203 treeOutline.toggleEditAsHTML(node);
1230 return true; 1204 return true;
1231 } 1205 }
1232 return false; 1206 return false;
1233 } 1207 }
1234 } 1208 }
1235 1209
1236 /** 1210 /**
1237 * @constructor 1211 * @constructor
1238 * @implements {WebInspector.DOMPresentationUtils.MarkerDecorator} 1212 * @implements {WebInspector.DOMPresentationUtils.MarkerDecorator}
1239 */ 1213 */
1240 WebInspector.ElementsPanel.PseudoStateMarkerDecorator = function() 1214 WebInspector.ElementsPanel.PseudoStateMarkerDecorator = function()
1241 { 1215 {
1242 } 1216 }
1243 1217
1244 WebInspector.ElementsPanel.PseudoStateMarkerDecorator.prototype = { 1218 WebInspector.ElementsPanel.PseudoStateMarkerDecorator.prototype = {
1245 /** 1219 /**
1246 * @override 1220 * @override
1247 * @param {!WebInspector.DOMNode} node 1221 * @param {!WebInspector.DOMNode} node
1248 * @return {?{title: string, color: string}} 1222 * @return {?{title: string, color: string}}
1249 */ 1223 */
1250 decorate: function(node) 1224 decorate: function(node)
1251 { 1225 {
1252 return { color: "orange", title: WebInspector.UIString("Element state: % s", ":" + WebInspector.CSSModel.fromNode(node).pseudoState(node).join(", :")) }; 1226 return { color: "orange", title: WebInspector.UIString("Element state: % s", ":" + WebInspector.CSSModel.fromNode(node).pseudoState(node).join(", :")) };
1253 } 1227 }
1254 } 1228 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/ElementsTreeOutline.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698