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

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

Issue 2932543002: DevTools: reveal and highlight dom nodes when searching in elements panel. (Closed)
Patch Set: rebaseline Created 3 years, 6 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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 popover.contentElement.appendChild(preview); 543 popover.contentElement.appendChild(preview);
544 return !!preview; 544 return !!preview;
545 } 545 }
546 }; 546 };
547 } 547 }
548 548
549 /** 549 /**
550 * @param {!SDK.DOMNode} node 550 * @param {!SDK.DOMNode} node
551 * @return {!Promise<!Object|undefined>} 551 * @return {!Promise<!Object|undefined>}
552 */ 552 */
553 _loadDimensionsForNode(node) { 553 async _loadDimensionsForNode(node) {
554 if (!node.nodeName() || node.nodeName().toLowerCase() !== 'img') 554 if (!node.nodeName() || node.nodeName().toLowerCase() !== 'img')
555 return Promise.resolve(); 555 return;
556 556
557 var fulfill; 557 var object = await node.resolveToObject('');
558 var promise = new Promise(x => fulfill = x); 558
559 node.resolveToObject('', resolvedNode); 559 if (!object)
560 return;
561
562 var promise = object.callFunctionJSONPromise(features, undefined);
563 object.release();
560 return promise; 564 return promise;
561 565
562 function resolvedNode(object) { 566 /**
563 if (!object) { 567 * @return {!{offsetWidth: number, offsetHeight: number, naturalWidth: numbe r, naturalHeight: number, currentSrc: (string|undefined)}}
564 fulfill(); 568 * @suppressReceiverCheck
565 return; 569 * @this {!Element}
566 } 570 */
567 571 function features() {
568 object.callFunctionJSON(features, undefined, fulfill); 572 return {
569 object.release(); 573 offsetWidth: this.offsetWidth,
570 574 offsetHeight: this.offsetHeight,
571 /** 575 naturalWidth: this.naturalWidth,
572 * @return {!{offsetWidth: number, offsetHeight: number, naturalWidth: num ber, naturalHeight: number, currentSrc: (string|undefined)}} 576 naturalHeight: this.naturalHeight,
573 * @suppressReceiverCheck 577 currentSrc: this.currentSrc
574 * @this {!Element} 578 };
575 */
576 function features() {
577 return {
578 offsetWidth: this.offsetWidth,
579 offsetHeight: this.offsetHeight,
580 naturalWidth: this.naturalWidth,
581 naturalHeight: this.naturalHeight,
582 currentSrc: this.currentSrc
583 };
584 }
585 } 579 }
586 } 580 }
587 581
588 _onmousedown(event) { 582 _onmousedown(event) {
589 var element = this._treeElementFromEvent(event); 583 var element = this._treeElementFromEvent(event);
590 584
591 if (!element || element.isEventWithinDisclosureTriangle(event)) 585 if (!element || element.isEventWithinDisclosureTriangle(event))
592 return; 586 return;
593 587
594 element.select(); 588 element.select();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return newTreeItem; 883 return newTreeItem;
890 } 884 }
891 885
892 /** 886 /**
893 * Runs a script on the node's remote object that toggles a class name on 887 * Runs a script on the node's remote object that toggles a class name on
894 * the node and injects a stylesheet into the head of the node's document 888 * the node and injects a stylesheet into the head of the node's document
895 * containing a rule to set "visibility: hidden" on the class and all it's 889 * containing a rule to set "visibility: hidden" on the class and all it's
896 * ancestors. 890 * ancestors.
897 * 891 *
898 * @param {!SDK.DOMNode} node 892 * @param {!SDK.DOMNode} node
899 * @param {function(?SDK.RemoteObject, boolean=)=} userCallback
900 */ 893 */
901 toggleHideElement(node, userCallback) { 894 async toggleHideElement(node) {
902 var pseudoType = node.pseudoType(); 895 var pseudoType = node.pseudoType();
903 var effectiveNode = pseudoType ? node.parentNode : node; 896 var effectiveNode = pseudoType ? node.parentNode : node;
904 if (!effectiveNode) 897 if (!effectiveNode)
905 return; 898 return;
906 899
907 var hidden = node.marker('hidden-marker'); 900 var hidden = node.marker('hidden-marker');
901 var object = await effectiveNode.resolveToObject('');
908 902
909 function resolvedNode(object) { 903 if (!object)
910 if (!object) 904 return;
905
906 var result = object.callFunction(toggleClassAndInjectStyleRule, [{value: pse udoType}, {value: !hidden}]);
907 object.release();
908 node.setMarker('hidden-marker', hidden ? null : true);
909 return result;
910
911 /**
912 * @param {?string} pseudoType
913 * @param {boolean} hidden
914 * @suppressGlobalPropertiesCheck
915 * @suppressReceiverCheck
916 * @this {!Element}
917 */
918 function toggleClassAndInjectStyleRule(pseudoType, hidden) {
919 const classNamePrefix = '__web-inspector-hide';
920 const classNameSuffix = '-shortcut__';
921 const styleTagId = '__web-inspector-hide-shortcut-style__';
922 var selectors = [];
923 selectors.push('.__web-inspector-hide-shortcut__');
924 selectors.push('.__web-inspector-hide-shortcut__ *');
925 selectors.push('.__web-inspector-hidebefore-shortcut__::before');
926 selectors.push('.__web-inspector-hideafter-shortcut__::after');
927 var selector = selectors.join(', ');
928 var ruleBody = ' visibility: hidden !important;';
929 var rule = '\n' + selector + '\n{\n' + ruleBody + '\n}\n';
930 var className = classNamePrefix + (pseudoType || '') + classNameSuffix;
931 this.classList.toggle(className, hidden);
932
933 var localRoot = this;
934 while (localRoot.parentNode)
935 localRoot = localRoot.parentNode;
936 if (localRoot.nodeType === Node.DOCUMENT_NODE)
937 localRoot = document.head;
938
939 var style = localRoot.querySelector('style#' + styleTagId);
940 if (style)
911 return; 941 return;
912 942
913 /** 943 style = document.createElement('style');
914 * @param {?string} pseudoType 944 style.id = styleTagId;
915 * @param {boolean} hidden 945 style.type = 'text/css';
916 * @suppressGlobalPropertiesCheck 946 style.textContent = rule;
917 * @suppressReceiverCheck
918 * @this {!Element}
919 */
920 function toggleClassAndInjectStyleRule(pseudoType, hidden) {
921 const classNamePrefix = '__web-inspector-hide';
922 const classNameSuffix = '-shortcut__';
923 const styleTagId = '__web-inspector-hide-shortcut-style__';
924 var selectors = [];
925 selectors.push('.__web-inspector-hide-shortcut__');
926 selectors.push('.__web-inspector-hide-shortcut__ *');
927 selectors.push('.__web-inspector-hidebefore-shortcut__::before');
928 selectors.push('.__web-inspector-hideafter-shortcut__::after');
929 var selector = selectors.join(', ');
930 var ruleBody = ' visibility: hidden !important;';
931 var rule = '\n' + selector + '\n{\n' + ruleBody + '\n}\n';
932 var className = classNamePrefix + (pseudoType || '') + classNameSuffix;
933 this.classList.toggle(className, hidden);
934 947
935 var localRoot = this; 948 localRoot.appendChild(style);
936 while (localRoot.parentNode)
937 localRoot = localRoot.parentNode;
938 if (localRoot.nodeType === Node.DOCUMENT_NODE)
939 localRoot = document.head;
940
941 var style = localRoot.querySelector('style#' + styleTagId);
942 if (style)
943 return;
944
945 style = document.createElement('style');
946 style.id = styleTagId;
947 style.type = 'text/css';
948 style.textContent = rule;
949
950 localRoot.appendChild(style);
951 }
952
953 object.callFunction(toggleClassAndInjectStyleRule, [{value: pseudoType}, { value: !hidden}], userCallback);
954 object.release();
955 node.setMarker('hidden-marker', hidden ? null : true);
956 } 949 }
957
958 effectiveNode.resolveToObject('', resolvedNode);
959 } 950 }
960 951
961 /** 952 /**
962 * @param {!SDK.DOMNode} node 953 * @param {!SDK.DOMNode} node
963 * @return {boolean} 954 * @return {boolean}
964 */ 955 */
965 isToggledToHidden(node) { 956 isToggledToHidden(node) {
966 return !!node.marker('hidden-marker'); 957 return !!node.marker('hidden-marker');
967 } 958 }
968 959
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 */ 1659 */
1669 function resolved(node) { 1660 function resolved(node) {
1670 if (node) { 1661 if (node) {
1671 this.treeOutline._selectedDOMNode = node; 1662 this.treeOutline._selectedDOMNode = node;
1672 this.treeOutline._selectedNodeChanged(); 1663 this.treeOutline._selectedNodeChanged();
1673 } 1664 }
1674 } 1665 }
1675 return true; 1666 return true;
1676 } 1667 }
1677 }; 1668 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698