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

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

Issue 2428823002: DevTools: properly restore selected DOMNode in Elements panel. (Closed)
Patch Set: test Created 4 years, 2 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) 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 * @param {!WebInspector.Event} event 322 * @param {!WebInspector.Event} event
323 */ 323 */
324 _selectedNodeChanged: function(event) 324 _selectedNodeChanged: function(event)
325 { 325 {
326 var selectedNode = /** @type {?WebInspector.DOMNode} */ (event.data); 326 var selectedNode = /** @type {?WebInspector.DOMNode} */ (event.data);
327 for (var i = 0; i < this._treeOutlines.length; ++i) { 327 for (var i = 0; i < this._treeOutlines.length; ++i) {
328 if (!selectedNode || selectedNode.domModel() !== this._treeOutlines[ i].domModel()) 328 if (!selectedNode || selectedNode.domModel() !== this._treeOutlines[ i].domModel())
329 this._treeOutlines[i].selectDOMNode(null); 329 this._treeOutlines[i].selectDOMNode(null);
330 } 330 }
331 331
332 if (!selectedNode && this._lastValidSelectedNode)
333 this._selectedPathOnReset = this._lastValidSelectedNode.path();
334
335 this._breadcrumbs.setSelectedNode(selectedNode); 332 this._breadcrumbs.setSelectedNode(selectedNode);
336 333
337 WebInspector.context.setFlavor(WebInspector.DOMNode, selectedNode); 334 WebInspector.context.setFlavor(WebInspector.DOMNode, selectedNode);
338 335
339 if (!selectedNode) 336 if (!selectedNode)
340 return; 337 return;
341 selectedNode.setAsInspectedNode(); 338 selectedNode.setAsInspectedNode();
342 this._lastValidSelectedNode = selectedNode; 339 if (!this._isSettingDefaultSelection) {
340 this._selectedNodeOnReset = selectedNode;
341 this._hasNonDefaultSelectedNode = true;
342 }
343 343
344 var executionContexts = selectedNode.target().runtimeModel.executionCont exts(); 344 var executionContexts = selectedNode.target().runtimeModel.executionCont exts();
345 var nodeFrameId = selectedNode.frameId(); 345 var nodeFrameId = selectedNode.frameId();
346 for (var context of executionContexts) { 346 for (var context of executionContexts) {
347 if (context.frameId === nodeFrameId) { 347 if (context.frameId === nodeFrameId) {
348 WebInspector.context.setFlavor(WebInspector.ExecutionContext, co ntext); 348 WebInspector.context.setFlavor(WebInspector.ExecutionContext, co ntext);
349 break; 349 break;
350 } 350 }
351 } 351 }
352 }, 352 },
(...skipping 22 matching lines...) Expand all
375 375
376 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(domModel) ; 376 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(domModel) ;
377 treeOutline.rootDOMNode = inspectedRootDocument; 377 treeOutline.rootDOMNode = inspectedRootDocument;
378 378
379 if (!inspectedRootDocument) { 379 if (!inspectedRootDocument) {
380 if (this.isShowing()) 380 if (this.isShowing())
381 domModel.requestDocument(); 381 domModel.requestDocument();
382 return; 382 return;
383 } 383 }
384 384
385 this._hasNonDefaultSelectedNode = false;
385 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(inspectedRootD ocument); 386 WebInspector.domBreakpointsSidebarPane.restoreBreakpoints(inspectedRootD ocument);
386 387
388 var defaultSelection = inspectedRootDocument.body || inspectedRootDocume nt.documentElement;
389 if (this._omitDefaultSelection || !defaultSelection)
390 return;
391
392 this._restoreNode(domModel, this._selectedNodeOnReset)
393 .then(onNodeRestored.bind(this, this._selectedNodeOnReset))
dgozman 2016/10/19 01:10:38 missing semicolon
lushnikov 2016/10/19 20:52:11 Done.
394
387 /** 395 /**
396 * @param {?WebInspector.DOMNode} staleNode
397 * @param {?WebInspector.DOMNode} restoredNode
388 * @this {WebInspector.ElementsPanel} 398 * @this {WebInspector.ElementsPanel}
389 * @param {?WebInspector.DOMNode} candidateFocusNode
390 */ 399 */
391 function selectNode(candidateFocusNode) 400 function onNodeRestored(staleNode, restoredNode)
392 { 401 {
393 if (!candidateFocusNode) 402 if (staleNode !== this._selectedNodeOnReset)
394 candidateFocusNode = inspectedRootDocument.body || inspectedRoot Document.documentElement;
395
396 if (!candidateFocusNode)
397 return; 403 return;
398 404 if (restoredNode) {
399 if (!this._pendingNodeReveal) { 405 this._preselectNode(restoredNode);
400 this.selectDOMNode(candidateFocusNode); 406 this._lastSelectedNodeSelectedForTest();
401 if (treeOutline.selectedTreeElement) 407 } else {
402 treeOutline.selectedTreeElement.expand(); 408 this._preselectNode(defaultSelection);
dgozman 2016/10/19 01:10:38 Should recalc default selection.
lushnikov 2016/10/19 20:52:11 Done.
403 } 409 }
404 } 410 }
405
406 /**
407 * @param {?DOMAgent.NodeId} nodeId
408 * @this {WebInspector.ElementsPanel}
409 */
410 function selectLastSelectedNode(nodeId)
411 {
412 if (this.selectedDOMNode()) {
413 // Focused node has been explicitly set while reaching out for t he last selected node.
414 return;
415 }
416 var node = nodeId ? domModel.nodeForId(nodeId) : null;
417 selectNode.call(this, node);
418 this._lastSelectedNodeSelectedForTest();
419 }
420
421 if (this._omitDefaultSelection)
422 return;
423
424 if (this._selectedPathOnReset)
425 domModel.pushNodeByPathToFrontend(this._selectedPathOnReset, selectL astSelectedNode.bind(this));
426 else
427 selectNode.call(this, null);
428 delete this._selectedPathOnReset;
429 }, 411 },
430 412
431 _lastSelectedNodeSelectedForTest: function() { }, 413 _lastSelectedNodeSelectedForTest: function() { },
432 414
433 /** 415 /**
416 * @param {!WebInspector.DOMNode} node
417 */
418 _preselectNode: function(node)
dgozman 2016/10/19 01:10:38 _setDefaultSelectedNode
dgozman 2016/10/19 01:10:38 Let's make this one responsible for default select
lushnikov 2016/10/19 20:52:11 The default selection seems to fit better in the o
lushnikov 2016/10/19 20:52:11 Done.
419 {
420 if (this._hasNonDefaultSelectedNode || this._pendingNodeReveal)
421 return;
422 var treeOutline = WebInspector.ElementsTreeOutline.forDOMModel(node.domM odel());
423 if (!treeOutline)
424 return;
425 this._isSettingDefaultSelection = true;
dgozman 2016/10/19 01:10:38 nit: _isSettingDefaultSelectedNode
lushnikov 2016/10/19 20:52:11 Done.
426 this.selectDOMNode(node);
427 this._isSettingDefaultSelection = false;
428 if (treeOutline.selectedTreeElement)
429 treeOutline.selectedTreeElement.expand();
430 },
431
432 /**
433 * @param {!WebInspector.DOMModel} domModel
434 * @param {?WebInspector.DOMNode} staleNode
435 * @return {!Promise<?WebInspector.DOMNode>}
436 */
437 _restoreNode: function(domModel, staleNode)
dgozman 2016/10/19 01:10:38 Let's make this inner function of _documentUpdated
lushnikov 2016/10/19 20:52:11 Done.
438 {
439 var nodePath = staleNode ? staleNode.path() : null;
440 if (!nodePath)
441 return Promise.resolve(/** @type {?WebInspector.DOMNode} */(null));
442 return domModel.pushNodeByPathToFrontendPromise(nodePath);
dgozman 2016/10/19 01:10:38 Let's maybe use callback version?
lushnikov 2016/10/19 20:52:11 Done.
443 },
444
445 /**
434 * @override 446 * @override
435 */ 447 */
436 searchCanceled: function() 448 searchCanceled: function()
437 { 449 {
438 delete this._searchQuery; 450 delete this._searchQuery;
439 this._hideSearchHighlights(); 451 this._hideSearchHighlights();
440 452
441 this._searchableView.updateSearchMatchesCount(0); 453 this._searchableView.updateSearchMatchesCount(0);
442 454
443 delete this._currentSearchResultIndex; 455 delete this._currentSearchResultIndex;
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 treeOutline.domModel().redo(); 724 treeOutline.domModel().redo();
713 event.handled = true; 725 event.handled = true;
714 } 726 }
715 } 727 }
716 728
717 if (WebInspector.isEditing() && event.keyCode !== WebInspector.KeyboardS hortcut.Keys.F2.code) 729 if (WebInspector.isEditing() && event.keyCode !== WebInspector.KeyboardS hortcut.Keys.F2.code)
718 return; 730 return;
719 731
720 var treeOutline = null; 732 var treeOutline = null;
721 for (var i = 0; i < this._treeOutlines.length; ++i) { 733 for (var i = 0; i < this._treeOutlines.length; ++i) {
722 if (this._treeOutlines[i].selectedDOMNode() === this._lastValidSelec tedNode) 734 if (this._treeOutlines[i].selectedDOMNode())
723 treeOutline = this._treeOutlines[i]; 735 treeOutline = this._treeOutlines[i];
724 } 736 }
725 if (!treeOutline) 737 if (!treeOutline)
726 return; 738 return;
727 739
728 if (!treeOutline.editing()) { 740 if (!treeOutline.editing()) {
729 handleUndoRedo.call(null, treeOutline); 741 handleUndoRedo.call(null, treeOutline);
730 if (event.handled) { 742 if (event.handled) {
731 this._stylesWidget.forceUpdate(); 743 this._stylesWidget.forceUpdate();
732 return; 744 return;
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 /** 1120 /**
1109 * @override 1121 * @override
1110 * @param {!WebInspector.DOMNode} node 1122 * @param {!WebInspector.DOMNode} node
1111 * @return {?{title: string, color: string}} 1123 * @return {?{title: string, color: string}}
1112 */ 1124 */
1113 decorate: function(node) 1125 decorate: function(node)
1114 { 1126 {
1115 return { color: "orange", title: WebInspector.UIString("Element state: % s", ":" + WebInspector.CSSModel.fromNode(node).pseudoState(node).join(", :")) }; 1127 return { color: "orange", title: WebInspector.UIString("Element state: % s", ":" + WebInspector.CSSModel.fromNode(node).pseudoState(node).join(", :")) };
1116 } 1128 }
1117 } 1129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698