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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleViewMessage.js

Issue 2568983003: Add ability to linkify substituted string
Patch Set: Comments addressed Created 3 years, 11 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
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 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 formatters.c = styleFormatter; 770 formatters.c = styleFormatter;
771 771
772 // Support %O to force object formatting, instead of the type-based %o forma tting. 772 // Support %O to force object formatting, instead of the type-based %o forma tting.
773 formatters.O = parameterFormatter.bind(this, true); 773 formatters.O = parameterFormatter.bind(this, true);
774 774
775 formatters._ = bypassFormatter; 775 formatters._ = bypassFormatter;
776 776
777 function append(a, b) { 777 function append(a, b) {
778 if (b instanceof Node) { 778 if (b instanceof Node) {
779 a.appendChild(b); 779 a.appendChild(b);
780 } else if (typeof b !== 'undefined') { 780 } else if (typeof b !== 'undefined' && b !== '') {
781 var toAppend = Components.linkifyStringAsFragment(String(b)); 781 var toAppend = createTextNode(String(b));
782 if (currentStyle) { 782 if (currentStyle) {
783 var wrapper = createElement('span'); 783 var wrapper = createElement('span');
784 wrapper.appendChild(toAppend); 784 wrapper.appendChild(toAppend);
785 applyCurrentStyle(wrapper); 785 applyCurrentStyle(wrapper);
786 for (var i = 0; i < wrapper.children.length; ++i) 786 for (var i = 0; i < wrapper.children.length; ++i)
787 applyCurrentStyle(wrapper.children[i]); 787 applyCurrentStyle(wrapper.children[i]);
788 toAppend = wrapper; 788 toAppend = wrapper;
789 } 789 }
790 a.appendChild(toAppend); 790 a.appendChild(toAppend);
791 } 791 }
792 return a; 792 return a;
793 } 793 }
794 794
795 /** 795 /**
796 * @param {!Element} element 796 * @param {!Element} element
797 */ 797 */
798 function applyCurrentStyle(element) { 798 function applyCurrentStyle(element) {
799 for (var key in currentStyle) 799 for (var key in currentStyle)
800 element.style[key] = currentStyle[key]; 800 element.style[key] = currentStyle[key];
801 } 801 }
802 802
803 // String.format does treat formattedResult like a Builder, result is an obj ect. 803 // String.format does treat formattedResult like a Builder, result is an obj ect.
804 return String.format(format, parameters, formatters, formattedResult, append ); 804 var result = String.format(format, parameters, formatters, formattedResult, append);
805 let plainText = formattedResult.textContent;
806 var linkRanges = Components.Linkifier.getLinkRanges(plainText);
pfeldman 2017/01/27 19:10:07 Instead of exposing a handful methods on Component
karabur 2017/01/27 21:21:04 How it should handle the fact what ConsoleViewMess
807
808 function linkifier(text, parent, idx) {
pfeldman 2017/01/27 19:10:07 You should annotate these parameters using jsdoc
809 var linkNode =
810 Components.Linkifier.createLinkNode(plainText.substr(linkRanges[idx].o ffset, linkRanges[idx].length), text);
811 if (parent && parent.style.cssText)
pfeldman 2017/01/27 19:10:07 Why is this necessary? That looks like something U
karabur 2017/01/27 21:21:04 I think this logic is specific for ConsoleViewMess
812 linkNode.style.cssText = parent.style.cssText;
813 return linkNode;
814 }
815 UI.highlightRangesWithStyleClass(formattedResult, linkRanges, '', [], linkif ier);
816
817 return result;
805 } 818 }
806 819
807 /** 820 /**
808 * @return {boolean} 821 * @return {boolean}
809 */ 822 */
810 matchesFilterRegex(regexObject) { 823 matchesFilterRegex(regexObject) {
811 regexObject.lastIndex = 0; 824 regexObject.lastIndex = 0;
812 var text = this.contentElement().deepTextContent(); 825 var text = this.contentElement().deepTextContent();
813 return regexObject.test(text); 826 return regexObject.test(text);
814 } 827 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 } 1070 }
1058 1071
1059 /** 1072 /**
1060 * @return {number} 1073 * @return {number}
1061 */ 1074 */
1062 searchCount() { 1075 searchCount() {
1063 return this._searchHighlightNodes.length; 1076 return this._searchHighlightNodes.length;
1064 } 1077 }
1065 1078
1066 /** 1079 /**
1067 * @return {!Element} 1080 * @return {!Array.<!Element>}
1068 */ 1081 */
1069 searchHighlightNode(index) { 1082 searchHighlightNodes(index) {
1070 return this._searchHighlightNodes[index]; 1083 return this._searchHighlightNodes[index];
1071 } 1084 }
1072 1085
1073 /** 1086 /**
1074 * @param {string} string 1087 * @param {string} string
1075 * @return {?Element} 1088 * @return {?Element}
1076 */ 1089 */
1077 _tryFormatAsError(string) { 1090 _tryFormatAsError(string) {
1078 /** 1091 /**
1079 * @param {string} prefix 1092 * @param {string} prefix
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 toMessageElement() { 1209 toMessageElement() {
1197 if (!this._element) { 1210 if (!this._element) {
1198 super.toMessageElement(); 1211 super.toMessageElement();
1199 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); 1212 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon');
1200 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); 1213 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild);
1201 this.setCollapsed(this._collapsed); 1214 this.setCollapsed(this._collapsed);
1202 } 1215 }
1203 return this._element; 1216 return this._element;
1204 } 1217 }
1205 }; 1218 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698