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

Side by Side Diff: Source/devtools/front_end/ElementsPanel.js

Issue 218703002: DevTools: [wip] move Elements panel off WebInspector.domModel and single tree outline. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review comment addressed (and much more) Created 6 years, 8 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 | Annotate | Revision Log
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 23 matching lines...) Expand all
34 importScript("MetricsSidebarPane.js"); 34 importScript("MetricsSidebarPane.js");
35 importScript("OverridesView.js"); 35 importScript("OverridesView.js");
36 importScript("PlatformFontsSidebarPane.js"); 36 importScript("PlatformFontsSidebarPane.js");
37 importScript("PropertiesSidebarPane.js"); 37 importScript("PropertiesSidebarPane.js");
38 importScript("RenderingOptionsView.js"); 38 importScript("RenderingOptionsView.js");
39 importScript("StylesSidebarPane.js"); 39 importScript("StylesSidebarPane.js");
40 40
41 /** 41 /**
42 * @constructor 42 * @constructor
43 * @implements {WebInspector.Searchable} 43 * @implements {WebInspector.Searchable}
44 * @implements {WebInspector.TargetManager.Observer}
44 * @extends {WebInspector.Panel} 45 * @extends {WebInspector.Panel}
45 */ 46 */
46 WebInspector.ElementsPanel = function() 47 WebInspector.ElementsPanel = function()
47 { 48 {
48 WebInspector.Panel.call(this, "elements"); 49 WebInspector.Panel.call(this, "elements");
49 this.registerRequiredCSS("breadcrumbList.css"); 50 this.registerRequiredCSS("breadcrumbList.css");
50 this.registerRequiredCSS("elementsPanel.css"); 51 this.registerRequiredCSS("elementsPanel.css");
51 this.registerRequiredCSS("textPrompt.css"); 52 this.registerRequiredCSS("textPrompt.css");
52 this.setHideOnDetach(); 53 this.setHideOnDetach();
53 54
(...skipping 10 matching lines...) Expand all
64 this.contentElement.id = "elements-content"; 65 this.contentElement.id = "elements-content";
65 this.contentElement.classList.add("outline-disclosure"); 66 this.contentElement.classList.add("outline-disclosure");
66 this.contentElement.classList.add("source-code"); 67 this.contentElement.classList.add("source-code");
67 if (!WebInspector.settings.domWordWrap.get()) 68 if (!WebInspector.settings.domWordWrap.get())
68 this.contentElement.classList.add("nowrap"); 69 this.contentElement.classList.add("nowrap");
69 WebInspector.settings.domWordWrap.addChangeListener(this._domWordWrapSetting Changed.bind(this)); 70 WebInspector.settings.domWordWrap.addChangeListener(this._domWordWrapSetting Changed.bind(this));
70 71
71 this.contentElement.addEventListener("contextmenu", this._contextMenuEventFi red.bind(this), true); 72 this.contentElement.addEventListener("contextmenu", this._contextMenuEventFi red.bind(this), true);
72 this._splitView.sidebarElement().addEventListener("contextmenu", this._sideb arContextMenuEventFired.bind(this), false); 73 this._splitView.sidebarElement().addEventListener("contextmenu", this._sideb arContextMenuEventFired.bind(this), false);
73 74
74 this.treeOutline = new WebInspector.ElementsTreeOutline(true, true, this._po pulateContextMenu.bind(this), this._setPseudoClassForNodeId.bind(this));
75 this.treeOutline.wireToDomAgent();
76
77 this.treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Se lectedNodeChanged, this._selectedNodeChanged, this);
78 this.treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.El ementsTreeUpdated, this._updateBreadcrumbIfNeeded, this);
79
80 var crumbsContainer = stackElement.createChild("div"); 75 var crumbsContainer = stackElement.createChild("div");
81 crumbsContainer.id = "elements-crumbs"; 76 crumbsContainer.id = "elements-crumbs";
82 this.crumbsElement = crumbsContainer.createChild("div", "crumbs"); 77 this.crumbsElement = crumbsContainer.createChild("div", "crumbs");
83 this.crumbsElement.addEventListener("mousemove", this._mouseMovedInCrumbs.bi nd(this), false); 78 this.crumbsElement.addEventListener("mousemove", this._mouseMovedInCrumbs.bi nd(this), false);
84 this.crumbsElement.addEventListener("mouseout", this._mouseMovedOutOfCrumbs. bind(this), false); 79 this.crumbsElement.addEventListener("mouseout", this._mouseMovedOutOfCrumbs. bind(this), false);
85 80
86 this.sidebarPanes = {}; 81 this.sidebarPanes = {};
87 this.sidebarPanes.platformFonts = new WebInspector.PlatformFontsSidebarPane( ); 82 this.sidebarPanes.platformFonts = new WebInspector.PlatformFontsSidebarPane( );
88 this.sidebarPanes.computedStyle = new WebInspector.ComputedStyleSidebarPane( ); 83 this.sidebarPanes.computedStyle = new WebInspector.ComputedStyleSidebarPane( );
89 this.sidebarPanes.styles = new WebInspector.StylesSidebarPane(this.sidebarPa nes.computedStyle, this._setPseudoClassForNodeId.bind(this)); 84 this.sidebarPanes.styles = new WebInspector.StylesSidebarPane(this.sidebarPa nes.computedStyle, this._setPseudoClassForNode.bind(this));
90 85
91 this._matchedStylesFilterBoxContainer = document.createElement("div"); 86 this._matchedStylesFilterBoxContainer = document.createElement("div");
92 this._matchedStylesFilterBoxContainer.className = "sidebar-pane-filter-box"; 87 this._matchedStylesFilterBoxContainer.className = "sidebar-pane-filter-box";
93 this._computedStylesFilterBoxContainer = document.createElement("div"); 88 this._computedStylesFilterBoxContainer = document.createElement("div");
94 this._computedStylesFilterBoxContainer.className = "sidebar-pane-filter-box" ; 89 this._computedStylesFilterBoxContainer.className = "sidebar-pane-filter-box" ;
95 this.sidebarPanes.styles.setFilterBoxContainers(this._matchedStylesFilterBox Container, this._computedStylesFilterBoxContainer); 90 this.sidebarPanes.styles.setFilterBoxContainers(this._matchedStylesFilterBox Container, this._computedStylesFilterBoxContainer);
96 91
97 this.sidebarPanes.metrics = new WebInspector.MetricsSidebarPane(); 92 this.sidebarPanes.metrics = new WebInspector.MetricsSidebarPane();
98 this.sidebarPanes.properties = new WebInspector.PropertiesSidebarPane(); 93 this.sidebarPanes.properties = new WebInspector.PropertiesSidebarPane();
99 this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane.cr eateProxy(this); 94 this.sidebarPanes.domBreakpoints = WebInspector.domBreakpointsSidebarPane.cr eateProxy(this);
(...skipping 10 matching lines...) Expand all
110 this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPa neEdited, this); 105 this.sidebarPanes.metrics.addEventListener("metrics edited", this._metricsPa neEdited, this);
111 this._extensionSidebarPanes = []; 106 this._extensionSidebarPanes = [];
112 107
113 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.DockSideChanged, this._dockSideChanged.bind(this)); 108 WebInspector.dockController.addEventListener(WebInspector.DockController.Eve nts.DockSideChanged, this._dockSideChanged.bind(this));
114 WebInspector.settings.splitVerticallyWhenDockedToRight.addChangeListener(thi s._dockSideChanged.bind(this)); 109 WebInspector.settings.splitVerticallyWhenDockedToRight.addChangeListener(thi s._dockSideChanged.bind(this));
115 this._dockSideChanged(); 110 this._dockSideChanged();
116 111
117 this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._get PopoverAnchor.bind(this), this._showPopover.bind(this)); 112 this._popoverHelper = new WebInspector.PopoverHelper(this.element, this._get PopoverAnchor.bind(this), this._showPopover.bind(this));
118 this._popoverHelper.setTimeout(0); 113 this._popoverHelper.setTimeout(0);
119 114
120 WebInspector.domModel.addEventListener(WebInspector.DOMModel.Events.Document Updated, this._documentUpdatedEvent, this); 115 /** @type {!Array.<!WebInspector.ElementsTreeOutline>} */
116 this._treeOutlines = [];
117 /** @type {!Map.<!WebInspector.Target, !WebInspector.ElementsTreeOutline>} * /
118 this._targetToTreeOutline = new Map();
119 WebInspector.targetManager.observeTargets(this);
121 WebInspector.settings.showUAShadowDOM.addChangeListener(this._showUAShadowDO MChanged.bind(this)); 120 WebInspector.settings.showUAShadowDOM.addChangeListener(this._showUAShadowDO MChanged.bind(this));
122
123 WebInspector.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Mod elWasEnabled, this._updateSidebars, this);
124 } 121 }
125 122
126 WebInspector.ElementsPanel.prototype = { 123 WebInspector.ElementsPanel.prototype = {
124 /**
125 * @param {!WebInspector.Target} target
126 */
127 targetAdded: function(target)
128 {
129 var treeOutline = new WebInspector.ElementsTreeOutline(target, true, tru e, this._populateContextMenu.bind(this), this._setPseudoClassForNode.bind(this)) ;
130 treeOutline.wireToDOMModel();
131 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Sel ectedNodeChanged, this._selectedNodeChanged, this);
132 treeOutline.addEventListener(WebInspector.ElementsTreeOutline.Events.Ele mentsTreeUpdated, this._updateBreadcrumbIfNeeded, this);
133 this._treeOutlines.push(treeOutline);
134 this._targetToTreeOutline.put(target, treeOutline);
135
136 target.domModel.addEventListener(WebInspector.DOMModel.Events.DocumentUp dated, this._documentUpdatedEvent.bind(this, target));
137 target.cssModel.addEventListener(WebInspector.CSSStyleModel.Events.Model WasEnabled, this._updateSidebars, this);
138
139 // Perform attach if necessary.
140 if (this.isShowing())
141 this.wasShown();
142 },
143
144 /**
145 * @param {!WebInspector.Target} target
146 */
147 targetRemoved: function(target) { },
148
149 /**
150 * @param {?WebInspector.Target} target
151 */
152 activeTargetChanged: function(target) { },
153
154 /**
155 * @return {?WebInspector.ElementsTreeOutline}
156 */
157 _firstTreeOutlineDeprecated: function()
158 {
159 return this._treeOutlines[0] || null;
160 },
161
127 _updateTreeOutlineVisibleWidth: function() 162 _updateTreeOutlineVisibleWidth: function()
128 { 163 {
129 if (!this.treeOutline) 164 if (!this._treeOutlines.length)
130 return; 165 return;
131 166
132 var width = this._splitView.element.offsetWidth; 167 var width = this._splitView.element.offsetWidth;
133 if (this._splitView.isVertical()) 168 if (this._splitView.isVertical())
134 width -= this._splitView.sidebarSize(); 169 width -= this._splitView.sidebarSize();
135 this.treeOutline.setVisibleWidth(width); 170 for (var i = 0; i > this._treeOutlines.length; ++i) {
136 this.treeOutline.updateSelection(); 171 this._treeOutlines[i].setVisibleWidth(width);
172 this._treeOutlines[i].updateSelection();
173 }
137 this.updateBreadcrumbSizes(); 174 this.updateBreadcrumbSizes();
138 }, 175 },
139 176
140 /** 177 /**
141 * @return {!Element} 178 * @return {!Element}
142 */ 179 */
143 defaultFocusedElement: function() 180 defaultFocusedElement: function()
144 { 181 {
145 return this.treeOutline.element; 182 return this._treeOutlines.length ? this._treeOutlines[0].element : this. element;
146 }, 183 },
147 184
148 /** 185 /**
149 * @return {!WebInspector.SearchableView} 186 * @return {!WebInspector.SearchableView}
150 */ 187 */
151 searchableView: function() 188 searchableView: function()
152 { 189 {
153 return this._searchableView; 190 return this._searchableView;
154 }, 191 },
155 192
156 wasShown: function() 193 wasShown: function()
157 { 194 {
158 // Attach heavy component lazily 195 for (var i = 0; i < this._treeOutlines.length; ++i) {
159 if (this.treeOutline.element.parentElement !== this.contentElement) 196 var treeOutline = this._treeOutlines[i];
160 this.contentElement.appendChild(this.treeOutline.element); 197 // Attach heavy component lazily
198 if (treeOutline.element.parentElement !== this.contentElement)
199 this.contentElement.appendChild(treeOutline.element);
200 }
201 WebInspector.Panel.prototype.wasShown.call(this);
202 this.updateBreadcrumb();
161 203
162 WebInspector.Panel.prototype.wasShown.call(this); 204 for (var i = 0; i < this._treeOutlines.length; ++i) {
205 var treeOutline = this._treeOutlines[i];
206 treeOutline.updateSelection();
207 treeOutline.setVisible(true);
163 208
164 this.updateBreadcrumb(); 209 if (!treeOutline.rootDOMNode)
165 this.treeOutline.updateSelection(); 210 if (treeOutline.domModel().existingDocument())
166 this.treeOutline.setVisible(true); 211 this._documentUpdated(treeOutline.target(), treeOutline.domM odel().existingDocument());
212 else
213 treeOutline.domModel().requestDocument();
214 }
167 215
168 if (!this.treeOutline.rootDOMNode)
169 if (WebInspector.domModel.existingDocument())
170 this._documentUpdated(WebInspector.domModel.existingDocument());
171 else
172 WebInspector.domModel.requestDocument();
173 }, 216 },
174 217
175 willHide: function() 218 willHide: function()
176 { 219 {
177 WebInspector.domModel.hideDOMNodeHighlight(); 220 for (var i = 0; i < this._treeOutlines.length; ++i) {
178 this.treeOutline.setVisible(false); 221 var treeOutline = this._treeOutlines[i];
222 treeOutline.domModel().hideDOMNodeHighlight();
223 treeOutline.setVisible(false);
224 // Detach heavy component on hide
225 this.contentElement.removeChild(treeOutline.element);
226 }
179 this._popoverHelper.hidePopover(); 227 this._popoverHelper.hidePopover();
180
181 // Detach heavy component on hide
182 this.contentElement.removeChild(this.treeOutline.element);
183
184 WebInspector.Panel.prototype.willHide.call(this); 228 WebInspector.Panel.prototype.willHide.call(this);
185 }, 229 },
186 230
187 onResize: function() 231 onResize: function()
188 { 232 {
189 this._updateTreeOutlineVisibleWidth(); 233 this._updateTreeOutlineVisibleWidth();
190 }, 234 },
191 235
192 omitDefaultSelection: function() 236 omitDefaultSelection: function()
193 { 237 {
194 this._omitDefaultSelection = true; 238 this._omitDefaultSelection = true;
195 }, 239 },
196 240
197 stopOmittingDefaultSelection: function() 241 stopOmittingDefaultSelection: function()
198 { 242 {
199 delete this._omitDefaultSelection; 243 delete this._omitDefaultSelection;
200 }, 244 },
201 245
202 /** 246 /**
203 * @param {!DOMAgent.NodeId} nodeId 247 * @param {!WebInspector.DOMNode} node
204 * @param {string} pseudoClass 248 * @param {string} pseudoClass
205 * @param {boolean} enable 249 * @param {boolean} enable
206 */ 250 */
207 _setPseudoClassForNodeId: function(nodeId, pseudoClass, enable) 251 _setPseudoClassForNode: function(node, pseudoClass, enable)
208 { 252 {
209 var node = WebInspector.domModel.nodeForId(nodeId); 253 if (!node || !node.target().cssModel.forcePseudoState(node, pseudoClass, enable))
210 if (!node)
211 return; 254 return;
212 255
213 var pseudoClasses = node.getUserProperty(WebInspector.ElementsTreeOutlin e.PseudoStateDecorator.PropertyName); 256 this._targetToTreeOutline.get(node.target()).updateOpenCloseTags(node);
214 if (enable) {
215 pseudoClasses = pseudoClasses || [];
216 if (pseudoClasses.indexOf(pseudoClass) >= 0)
217 return;
218 pseudoClasses.push(pseudoClass);
219 node.setUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDec orator.PropertyName, pseudoClasses);
220 } else {
221 if (!pseudoClasses || pseudoClasses.indexOf(pseudoClass) < 0)
222 return;
223 pseudoClasses.remove(pseudoClass);
224 if (!pseudoClasses.length)
225 node.removeUserProperty(WebInspector.ElementsTreeOutline.PseudoS tateDecorator.PropertyName);
226 }
227
228 this.treeOutline.updateOpenCloseTags(node);
229 WebInspector.cssModel.forcePseudoState(node.id, node.getUserProperty(Web Inspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName));
230 this._metricsPaneEdited(); 257 this._metricsPaneEdited();
231 this._stylesPaneEdited(); 258 this._stylesPaneEdited();
232 259
233 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet rics.UserAction, { 260 WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMet rics.UserAction, {
234 action: WebInspector.UserMetrics.UserActionNames.ForcedElementState, 261 action: WebInspector.UserMetrics.UserActionNames.ForcedElementState,
235 selector: WebInspector.DOMPresentationUtils.fullQualifiedSelector(no de, false), 262 selector: WebInspector.DOMPresentationUtils.fullQualifiedSelector(no de, false),
236 enabled: enable, 263 enabled: enable,
237 state: pseudoClass 264 state: pseudoClass
238 }); 265 });
239 }, 266 },
(...skipping 25 matching lines...) Expand all
265 this.updatePlatformFonts(); 292 this.updatePlatformFonts();
266 this.updateProperties(); 293 this.updateProperties();
267 this.updateEventListeners(); 294 this.updateEventListeners();
268 }, 295 },
269 296
270 _reset: function() 297 _reset: function()
271 { 298 {
272 delete this.currentQuery; 299 delete this.currentQuery;
273 }, 300 },
274 301
275 _documentUpdatedEvent: function(event) 302 /**
303 * @param {!WebInspector.Target} target
304 * @param {!WebInspector.Event} event
305 */
306 _documentUpdatedEvent: function(target, event)
276 { 307 {
277 this._documentUpdated(event.data); 308 this._documentUpdated(target, /** @type {?WebInspector.DOMDocument} */ ( event.data));
278 }, 309 },
279 310
280 _documentUpdated: function(inspectedRootDocument) 311 /**
312 * @param {!WebInspector.Target} target
313 * @param {?WebInspector.DOMDocument} inspectedRootDocument
314 */
315 _documentUpdated: function(target, inspectedRootDocument)
281 { 316 {
282 this._reset(); 317 this._reset();
283 this.searchCanceled(); 318 this.searchCanceled();
284 319
285 this.treeOutline.rootDOMNode = inspectedRootDocument; 320 var treeOutline = this._targetToTreeOutline.get(target);
321 treeOutline.rootDOMNode = inspectedRootDocument;
286 322
287 if (!inspectedRootDocument) { 323 if (!inspectedRootDocument) {
288 if (this.isShowing()) 324 if (this.isShowing())
289 WebInspector.domModel.requestDocument(); 325 target.domModel.requestDocument();
290 return; 326 return;
291 } 327 }
292 328
293 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(); 329 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints();
294 330
295 /** 331 /**
296 * @this {WebInspector.ElementsPanel} 332 * @this {WebInspector.ElementsPanel}
297 * @param {?WebInspector.DOMNode} candidateFocusNode 333 * @param {?WebInspector.DOMNode} candidateFocusNode
298 */ 334 */
299 function selectNode(candidateFocusNode) 335 function selectNode(candidateFocusNode)
300 { 336 {
301 if (!candidateFocusNode) 337 if (!candidateFocusNode)
302 candidateFocusNode = inspectedRootDocument.body || inspectedRoot Document.documentElement; 338 candidateFocusNode = inspectedRootDocument.body || inspectedRoot Document.documentElement;
303 339
304 if (!candidateFocusNode) 340 if (!candidateFocusNode)
305 return; 341 return;
306 342
307 this.selectDOMNode(candidateFocusNode); 343 this.selectDOMNode(candidateFocusNode);
308 if (this.treeOutline.selectedTreeElement) 344 if (treeOutline.selectedTreeElement)
309 this.treeOutline.selectedTreeElement.expand(); 345 treeOutline.selectedTreeElement.expand();
310 } 346 }
311 347
312 /** 348 /**
313 * @param {?DOMAgent.NodeId} nodeId 349 * @param {?DOMAgent.NodeId} nodeId
314 * @this {WebInspector.ElementsPanel} 350 * @this {WebInspector.ElementsPanel}
315 */ 351 */
316 function selectLastSelectedNode(nodeId) 352 function selectLastSelectedNode(nodeId)
317 { 353 {
318 if (this.selectedDOMNode()) { 354 if (this.selectedDOMNode()) {
319 // Focused node has been explicitly set while reaching out for t he last selected node. 355 // Focused node has been explicitly set while reaching out for t he last selected node.
320 return; 356 return;
321 } 357 }
322 var node = nodeId ? WebInspector.domModel.nodeForId(nodeId) : null; 358 var node = nodeId ? target.domModel.nodeForId(nodeId) : null;
323 selectNode.call(this, node); 359 selectNode.call(this, node);
324 } 360 }
325 361
326 if (this._omitDefaultSelection) 362 if (this._omitDefaultSelection)
327 return; 363 return;
328 364
329 if (this._selectedPathOnReset) 365 if (this._selectedPathOnReset)
330 WebInspector.domModel.pushNodeByPathToFrontend(this._selectedPathOnR eset, selectLastSelectedNode.bind(this)); 366 target.domModel.pushNodeByPathToFrontend(this._selectedPathOnReset, selectLastSelectedNode.bind(this));
331 else 367 else
332 selectNode.call(this, null); 368 selectNode.call(this, null);
333 delete this._selectedPathOnReset; 369 delete this._selectedPathOnReset;
334 }, 370 },
335 371
336 searchCanceled: function() 372 searchCanceled: function()
337 { 373 {
338 delete this._searchQuery; 374 delete this._searchQuery;
339 this._hideSearchHighlights(); 375 this._hideSearchHighlights();
340 376
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 this._currentSearchResultIndex = -1; 410 this._currentSearchResultIndex = -1;
375 if (shouldJump) 411 if (shouldJump)
376 this.jumpToNextSearchResult(); 412 this.jumpToNextSearchResult();
377 } 413 }
378 WebInspector.domModel.performSearch(whitespaceTrimmedQuery, resultCountC allback.bind(this)); 414 WebInspector.domModel.performSearch(whitespaceTrimmedQuery, resultCountC allback.bind(this));
379 }, 415 },
380 416
381 _contextMenuEventFired: function(event) 417 _contextMenuEventFired: function(event)
382 { 418 {
383 var contextMenu = new WebInspector.ContextMenu(event); 419 var contextMenu = new WebInspector.ContextMenu(event);
384 this.treeOutline.populateContextMenu(contextMenu, event); 420 for (var i = 0; i < this._treeOutlines.length; ++i)
421 this._treeOutlines[i].populateContextMenu(contextMenu, event);
385 contextMenu.show(); 422 contextMenu.show();
386 }, 423 },
387 424
388 _domWordWrapSettingChanged: function(event) 425 _domWordWrapSettingChanged: function(event)
389 { 426 {
390 if (event.data) 427 if (event.data)
391 this.contentElement.classList.remove("nowrap"); 428 this.contentElement.classList.remove("nowrap");
392 else 429 else
393 this.contentElement.classList.add("nowrap"); 430 this.contentElement.classList.add("nowrap");
394 431
395 var selectedNode = this.selectedDOMNode(); 432 var selectedNode = this.selectedDOMNode();
396 if (!selectedNode) 433 if (!selectedNode)
397 return; 434 return;
398 435
399 var treeElement = this.treeOutline.findTreeElement(selectedNode); 436 var treeOutline = this._targetToTreeOutline.get(selectedNode.target());
437 var treeElement = treeOutline.findTreeElement(selectedNode);
400 if (treeElement) 438 if (treeElement)
401 treeElement.updateSelection(); // Recalculate selection highlight di mensions. 439 treeElement.updateSelection(); // Recalculate selection highlight di mensions.
402 }, 440 },
403 441
404 switchToAndFocus: function(node) 442 switchToAndFocus: function(node)
405 { 443 {
406 // Reset search restore. 444 // Reset search restore.
407 this._searchableView.cancelSearch(); 445 this._searchableView.cancelSearch();
408 WebInspector.inspectorView.setCurrentPanel(this); 446 WebInspector.inspectorView.setCurrentPanel(this);
409 this.selectDOMNode(node, true); 447 this.selectDOMNode(node, true);
(...skipping 19 matching lines...) Expand all
429 return null; 467 return null;
430 468
431 anchor.removeAttribute("title"); 469 anchor.removeAttribute("title");
432 } 470 }
433 return anchor; 471 return anchor;
434 }, 472 },
435 473
436 _loadDimensionsForNode: function(treeElement, callback) 474 _loadDimensionsForNode: function(treeElement, callback)
437 { 475 {
438 // We get here for CSS properties, too, so bail out early for non-DOM tr eeElements. 476 // We get here for CSS properties, too, so bail out early for non-DOM tr eeElements.
439 if (treeElement.treeOutline !== this.treeOutline) { 477 if (!(treeElement.treeOutline instanceof WebInspector.ElementsTreeOutlin e)) {
440 callback(); 478 callback();
441 return; 479 return;
442 } 480 }
443 481
444 var node = /** @type {!WebInspector.DOMNode} */ (treeElement.represented Object); 482 var node = /** @type {!WebInspector.DOMNode} */ (treeElement.represented Object);
445 483
446 if (!node.nodeName() || node.nodeName().toLowerCase() !== "img") { 484 if (!node.nodeName() || node.nodeName().toLowerCase() !== "img") {
447 callback(); 485 callback();
448 return; 486 return;
449 } 487 }
450 488
451 WebInspector.RemoteObject.resolveNode(node, "", resolvedNode); 489 node.resolveToObject("", resolvedNode);
452 490
453 function resolvedNode(object) 491 function resolvedNode(object)
454 { 492 {
455 if (!object) { 493 if (!object) {
456 callback(); 494 callback();
457 return; 495 return;
458 } 496 }
459 497
460 object.callFunctionJSON(dimensions, undefined, callback); 498 object.callFunctionJSON(dimensions, undefined, callback);
461 object.release(); 499 object.release();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 553
516 this._hideSearchHighlights(); 554 this._hideSearchHighlights();
517 if (--this._currentSearchResultIndex < 0) 555 if (--this._currentSearchResultIndex < 0)
518 this._currentSearchResultIndex = (this._searchResults.length - 1); 556 this._currentSearchResultIndex = (this._searchResults.length - 1);
519 557
520 this._highlightCurrentSearchResult(); 558 this._highlightCurrentSearchResult();
521 }, 559 },
522 560
523 _highlightCurrentSearchResult: function() 561 _highlightCurrentSearchResult: function()
524 { 562 {
563 var treeOutline = this._firstTreeOutlineDeprecated();
564 if (!treeOutline)
565 return;
566
525 var index = this._currentSearchResultIndex; 567 var index = this._currentSearchResultIndex;
526 var searchResults = this._searchResults; 568 var searchResults = this._searchResults;
527 var searchResult = searchResults[index]; 569 var searchResult = searchResults[index];
528 570
529 if (searchResult === null) { 571 if (searchResult === null) {
530 this._searchableView.updateCurrentMatchIndex(index); 572 this._searchableView.updateCurrentMatchIndex(index);
531 return; 573 return;
532 } 574 }
533 575
534 /** 576 /**
535 * @param {?WebInspector.DOMNode} node 577 * @param {?WebInspector.DOMNode} node
536 * @this {WebInspector.ElementsPanel} 578 * @this {WebInspector.ElementsPanel}
537 */ 579 */
538 function searchCallback(node) 580 function searchCallback(node)
539 { 581 {
540 searchResults[index] = node; 582 searchResults[index] = node;
541 this._highlightCurrentSearchResult(); 583 this._highlightCurrentSearchResult();
542 } 584 }
543 585
544 if (typeof searchResult === "undefined") { 586 if (typeof searchResult === "undefined") {
545 // No data for slot, request it. 587 // No data for slot, request it.
546 WebInspector.domModel.searchResult(index, searchCallback.bind(this)) ; 588 WebInspector.domModel.searchResult(index, searchCallback.bind(this)) ;
547 return; 589 return;
548 } 590 }
549 591
550 this._searchableView.updateCurrentMatchIndex(index); 592 this._searchableView.updateCurrentMatchIndex(index);
551 593
552 var treeElement = this.treeOutline.findTreeElement(searchResult); 594 var treeElement = treeOutline.findTreeElement(searchResult);
553 if (treeElement) { 595 if (treeElement) {
554 treeElement.highlightSearchResults(this._searchQuery); 596 treeElement.highlightSearchResults(this._searchQuery);
555 treeElement.reveal(); 597 treeElement.reveal();
556 var matches = treeElement.listItemElement.getElementsByClassName("hi ghlighted-search-result"); 598 var matches = treeElement.listItemElement.getElementsByClassName("hi ghlighted-search-result");
557 if (matches.length) 599 if (matches.length)
558 matches[0].scrollIntoViewIfNeeded(); 600 matches[0].scrollIntoViewIfNeeded();
559 } 601 }
560 }, 602 },
561 603
562 _hideSearchHighlights: function() 604 _hideSearchHighlights: function()
563 { 605 {
564 if (!this._searchResults) 606 if (!this._searchResults)
565 return; 607 return;
566 var searchResult = this._searchResults[this._currentSearchResultIndex]; 608 var searchResult = this._searchResults[this._currentSearchResultIndex];
567 if (!searchResult) 609 if (!searchResult)
568 return; 610 return;
569 var treeElement = this.treeOutline.findTreeElement(searchResult); 611 var treeOutline = this._targetToTreeOutline.get(searchResult.target());
612 var treeElement = treeOutline.findTreeElement(searchResult);
570 if (treeElement) 613 if (treeElement)
571 treeElement.hideSearchHighlights(); 614 treeElement.hideSearchHighlights();
572 }, 615 },
573 616
574 /** 617 /**
575 * @return {?WebInspector.DOMNode} 618 * @return {?WebInspector.DOMNode}
576 */ 619 */
577 selectedDOMNode: function() 620 selectedDOMNode: function()
578 { 621 {
579 return this.treeOutline.selectedDOMNode(); 622 for (var i = 0; i < this._treeOutlines.length; ++i) {
623 var treeOutline = this._treeOutlines[i];
624 if (treeOutline.selectedDOMNode())
625 return treeOutline.selectedDOMNode();
626 }
627 return null;
580 }, 628 },
581 629
582 /** 630 /**
583 * @param {boolean=} focus 631 * @param {boolean=} focus
584 */ 632 */
585 selectDOMNode: function(node, focus) 633 selectDOMNode: function(node, focus)
586 { 634 {
587 this.treeOutline.selectDOMNode(node, focus); 635 for (var i = 0; i < this._treeOutlines.length; ++i) {
636 var treeOutline = this._treeOutlines[i];
637 if (treeOutline.target() === node.target())
638 treeOutline.selectDOMNode(node, focus);
639 else
640 treeOutline.selectDOMNode(null);
641 }
588 }, 642 },
589 643
590 /** 644 /**
591 * @param {!WebInspector.Event} event 645 * @param {!WebInspector.Event} event
592 */ 646 */
593 _updateBreadcrumbIfNeeded: function(event) 647 _updateBreadcrumbIfNeeded: function(event)
594 { 648 {
595 var nodes = /** @type {!Array.<!WebInspector.DOMNode>} */ (event.data || []); 649 var nodes = /** @type {!Array.<!WebInspector.DOMNode>} */ (event.data || []);
596 if (!nodes.length) 650 if (!nodes.length)
597 return; 651 return;
(...skipping 20 matching lines...) Expand all
618 { 672 {
619 // Once metrics are edited, the Styles pane should be updated. 673 // Once metrics are edited, the Styles pane should be updated.
620 this.sidebarPanes.styles.needsUpdate = true; 674 this.sidebarPanes.styles.needsUpdate = true;
621 this.updateStyles(true); 675 this.updateStyles(true);
622 }, 676 },
623 677
624 _mouseMovedInCrumbs: function(event) 678 _mouseMovedInCrumbs: function(event)
625 { 679 {
626 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY) ; 680 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY) ;
627 var crumbElement = nodeUnderMouse.enclosingNodeOrSelfWithClass("crumb"); 681 var crumbElement = nodeUnderMouse.enclosingNodeOrSelfWithClass("crumb");
628 682 var node = /** @type {?WebInspector.DOMNode} */ (crumbElement ? crumbEle ment.representedObject : null);
629 WebInspector.domModel.highlightDOMNode(crumbElement ? crumbElement.repre sentedObject.id : 0); 683 if (node)
630 684 node.highlight();
631 if ("_mouseOutOfCrumbsTimeout" in this) {
632 clearTimeout(this._mouseOutOfCrumbsTimeout);
633 delete this._mouseOutOfCrumbsTimeout;
634 }
635 }, 685 },
636 686
637 _mouseMovedOutOfCrumbs: function(event) 687 _mouseMovedOutOfCrumbs: function(event)
638 { 688 {
639 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY) ; 689 var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY) ;
640 if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.crumbsElement)) 690 if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.crumbsElement))
641 return; 691 return;
642 692
643 WebInspector.domModel.hideDOMNodeHighlight(); 693 for (var i = 0; i < this._treeOutlines.length; ++i)
644 694 this._treeOutlines[i].domModel().hideDOMNodeHighlight();
645 this._mouseOutOfCrumbsTimeout = setTimeout(this.updateBreadcrumbSizes.bi nd(this), 1000);
646 }, 695 },
647 696
648 /** 697 /**
649 * @param {boolean=} forceUpdate 698 * @param {boolean=} forceUpdate
650 */ 699 */
651 updateBreadcrumb: function(forceUpdate) 700 updateBreadcrumb: function(forceUpdate)
652 { 701 {
653 if (!this.isShowing()) 702 if (!this.isShowing())
654 return; 703 return;
655 704
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 { 1122 {
1074 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !even t.shiftKey && event.keyIdentifier === "U+005A") { // Z key 1123 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && !even t.shiftKey && event.keyIdentifier === "U+005A") { // Z key
1075 WebInspector.domModel.undo(this._updateSidebars.bind(this)); 1124 WebInspector.domModel.undo(this._updateSidebars.bind(this));
1076 event.handled = true; 1125 event.handled = true;
1077 return; 1126 return;
1078 } 1127 }
1079 1128
1080 var isRedoKey = WebInspector.isMac() ? event.metaKey && event.shiftK ey && event.keyIdentifier === "U+005A" : // Z key 1129 var isRedoKey = WebInspector.isMac() ? event.metaKey && event.shiftK ey && event.keyIdentifier === "U+005A" : // Z key
1081 event.ctrlKey && event.keyIde ntifier === "U+0059"; // Y key 1130 event.ctrlKey && event.keyIde ntifier === "U+0059"; // Y key
1082 if (isRedoKey) { 1131 if (isRedoKey) {
1083 DOMAgent.redo(this._updateSidebars.bind(this)); 1132 WebInspector.domModel.redo(this._updateSidebars.bind(this));
1084 event.handled = true; 1133 event.handled = true;
1085 } 1134 }
1086 } 1135 }
1087 1136
1088 if (!this.treeOutline.editing()) { 1137 var treeOutline = this._firstTreeOutlineDeprecated();
1138 if (!treeOutline)
1139 return;
1140
1141 if (!treeOutline.editing()) {
1089 handleUndoRedo.call(this); 1142 handleUndoRedo.call(this);
1090 if (event.handled) 1143 if (event.handled)
1091 return; 1144 return;
1092 } 1145 }
1093 1146
1094 this.treeOutline.handleShortcut(event); 1147 treeOutline.handleShortcut(event);
1095 }, 1148 },
1096 1149
1097 handleCopyEvent: function(event) 1150 handleCopyEvent: function(event)
1098 { 1151 {
1099 var currentFocusElement = WebInspector.currentFocusElement(); 1152 var currentFocusElement = WebInspector.currentFocusElement();
1100 if (currentFocusElement && WebInspector.isBeingEdited(currentFocusElemen t)) 1153 if (currentFocusElement && WebInspector.isBeingEdited(currentFocusElemen t))
1101 return; 1154 return;
1102 1155
1103 // Don't prevent the normal copy if the user has a selection. 1156 // Don't prevent the normal copy if the user has a selection.
1104 if (!window.getSelection().isCollapsed) 1157 if (!window.getSelection().isCollapsed)
1105 return; 1158 return;
1106 event.clipboardData.clearData(); 1159 event.clipboardData.clearData();
1107 event.preventDefault(); 1160 event.preventDefault();
1108 this.selectedDOMNode().copyNode(); 1161 this.selectedDOMNode().copyNode();
1109 }, 1162 },
1110 1163
1111 /** 1164 /**
1112 * @param {!WebInspector.DOMNode} node 1165 * @param {!WebInspector.DOMNode} node
1113 * @return {!WebInspector.DOMNode} 1166 * @return {!WebInspector.DOMNode}
1114 */ 1167 */
1115 _leaveUserAgentShadowDOM: function(node) 1168 _leaveUserAgentShadowDOM: function(node)
1116 { 1169 {
1117 var userAgentShadowRoot = node.ancestorUserAgentShadowRoot(); 1170 var userAgentShadowRoot = node.ancestorUserAgentShadowRoot();
1118 return userAgentShadowRoot ? /** @type {!WebInspector.DOMNode} */ (userA gentShadowRoot.parentNode) : node; 1171 return userAgentShadowRoot ? /** @type {!WebInspector.DOMNode} */ (userA gentShadowRoot.parentNode) : node;
1119 }, 1172 },
1120 1173
1121 /** 1174 /**
1122 * @param {!DOMAgent.NodeId} nodeId 1175 * @param {!WebInspector.DOMNode} node
1123 */ 1176 */
1124 revealAndSelectNode: function(nodeId) 1177 revealAndSelectNode: function(node)
1125 { 1178 {
1126 WebInspector.inspectorView.setCurrentPanel(this); 1179 WebInspector.inspectorView.setCurrentPanel(this);
1127
1128 var node = WebInspector.domModel.nodeForId(nodeId);
1129 if (!node)
1130 return;
1131
1132 node = WebInspector.settings.showUAShadowDOM.get() ? node : this._leaveU serAgentShadowDOM(node); 1180 node = WebInspector.settings.showUAShadowDOM.get() ? node : this._leaveU serAgentShadowDOM(node);
1133 WebInspector.domModel.highlightDOMNodeForTwoSeconds(nodeId); 1181 node.highlightForTwoSeconds();
1134 this.selectDOMNode(node, true); 1182 this.selectDOMNode(node, true);
1135 }, 1183 },
1136 1184
1137 /** 1185 /**
1138 * @param {!WebInspector.ContextMenu} contextMenu 1186 * @param {!WebInspector.ContextMenu} contextMenu
1139 * @param {!Object} target 1187 * @param {!Object} object
1140 */ 1188 */
1141 appendApplicableItems: function(event, contextMenu, target) 1189 appendApplicableItems: function(event, contextMenu, object)
1142 { 1190 {
1143 /** 1191 /**
1192 * @param {!WebInspector.Target} target
1144 * @param {?DOMAgent.NodeId} nodeId 1193 * @param {?DOMAgent.NodeId} nodeId
1145 */ 1194 */
1146 function selectNode(nodeId) 1195 function selectNode(target, nodeId)
1147 { 1196 {
1148 if (nodeId) 1197 if (nodeId)
1149 WebInspector.domModel.inspectElement(nodeId); 1198 target.domModel.inspectElement(nodeId);
1150 } 1199 }
1151 1200
1152 /** 1201 /**
1153 * @param {!WebInspector.RemoteObject} remoteObject 1202 * @param {!WebInspector.RemoteObject} remoteObject
1154 */ 1203 */
1155 function revealElement(remoteObject) 1204 function revealElement(remoteObject)
1156 { 1205 {
1157 remoteObject.pushNodeToFrontend(selectNode); 1206 remoteObject.pushNodeToFrontend(selectNode.bind(null, /** @type {!We bInspector.Target} */ (remoteObject.target())));
1158 } 1207 }
1159 1208
1160 var commandCallback; 1209 var commandCallback;
1161 if (target instanceof WebInspector.RemoteObject) { 1210 if (object instanceof WebInspector.RemoteObject) {
1162 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target ); 1211 var remoteObject = /** @type {!WebInspector.RemoteObject} */ (object );
1163 if (remoteObject.subtype === "node") 1212 if (remoteObject.subtype === "node")
1164 commandCallback = revealElement.bind(null, remoteObject); 1213 commandCallback = revealElement.bind(null, remoteObject);
1165 } else if (target instanceof WebInspector.DOMNode) { 1214 } else if (object instanceof WebInspector.DOMNode) {
1166 var domNode = /** @type {!WebInspector.DOMNode} */ (target); 1215 var domNode = /** @type {!WebInspector.DOMNode} */ (object);
1167 if (domNode.id) 1216 commandCallback = domNode.reveal.bind(domNode);
1168 commandCallback = WebInspector.domModel.inspectElement.bind(WebI nspector.domModel, domNode.id);
1169 } 1217 }
1170 if (!commandCallback) 1218 if (!commandCallback)
1171 return; 1219 return;
1172 // Skip adding "Reveal..." menu item for our own tree outline. 1220 // Skip adding "Reveal..." menu item for our own tree outline.
1173 if (this.treeOutline.element.isAncestor(event.target)) 1221 if (this.element.isAncestor(event.target))
1174 return; 1222 return;
1175 contextMenu.appendItem(WebInspector.useLowerCaseMenuTitles() ? "Reveal i n Elements panel" : "Reveal in Elements Panel", commandCallback); 1223 contextMenu.appendItem(WebInspector.useLowerCaseMenuTitles() ? "Reveal i n Elements panel" : "Reveal in Elements Panel", commandCallback);
1176 }, 1224 },
1177 1225
1178 _sidebarContextMenuEventFired: function(event) 1226 _sidebarContextMenuEventFired: function(event)
1179 { 1227 {
1180 var contextMenu = new WebInspector.ContextMenu(event); 1228 var contextMenu = new WebInspector.ContextMenu(event);
1181 contextMenu.show(); 1229 contextMenu.show();
1182 }, 1230 },
1183 1231
1184 _dockSideChanged: function() 1232 _dockSideChanged: function()
1185 { 1233 {
1186 var vertically = WebInspector.dockController.isVertical() && WebInspecto r.settings.splitVerticallyWhenDockedToRight.get(); 1234 var vertically = WebInspector.dockController.isVertical() && WebInspecto r.settings.splitVerticallyWhenDockedToRight.get();
1187 this._splitVertically(vertically); 1235 this._splitVertically(vertically);
1188 }, 1236 },
1189 1237
1190 _showUAShadowDOMChanged: function() 1238 _showUAShadowDOMChanged: function()
1191 { 1239 {
1192 this.treeOutline.update(); 1240 for (var i = 0; i < this._treeOutlines.length; ++i)
1241 this._treeOutlines[i].update();
1193 }, 1242 },
1194 1243
1195 /** 1244 /**
1196 * @param {boolean} vertically 1245 * @param {boolean} vertically
1197 */ 1246 */
1198 _splitVertically: function(vertically) 1247 _splitVertically: function(vertically)
1199 { 1248 {
1200 if (this.sidebarPaneView && vertically === !this._splitView.isVertical() ) 1249 if (this.sidebarPaneView && vertically === !this._splitView.isVertical() )
1201 return; 1250 return;
1202 1251
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1359 reveal: function(node) 1408 reveal: function(node)
1360 { 1409 {
1361 if (!(node instanceof WebInspector.DOMNode)) 1410 if (!(node instanceof WebInspector.DOMNode))
1362 return; 1411 return;
1363 1412
1364 if (WebInspector.inspectElementModeController && WebInspector.inspectEle mentModeController.enabled()) { 1413 if (WebInspector.inspectElementModeController && WebInspector.inspectEle mentModeController.enabled()) {
1365 InspectorFrontendHost.bringToFront(); 1414 InspectorFrontendHost.bringToFront();
1366 WebInspector.inspectElementModeController.disable(); 1415 WebInspector.inspectElementModeController.disable();
1367 } 1416 }
1368 1417
1369 /** @type {!WebInspector.ElementsPanel} */ (WebInspector.inspectorView.p anel("elements")).revealAndSelectNode(node.id); 1418 /** @type {!WebInspector.ElementsPanel} */ (WebInspector.inspectorView.p anel("elements")).revealAndSelectNode(node);
1370 } 1419 }
1371 } 1420 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/DOMPresentationUtils.js ('k') | Source/devtools/front_end/ElementsTreeOutline.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698