Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 rootElement.appendChild(this._previewFormatter.renderPropertyPreview(typ e, subtype, description)); | 764 rootElement.appendChild(this._previewFormatter.renderPropertyPreview(typ e, subtype, description)); |
| 765 } | 765 } |
| 766 } | 766 } |
| 767 | 767 |
| 768 return rootElement; | 768 return rootElement; |
| 769 } | 769 } |
| 770 | 770 |
| 771 /** | 771 /** |
| 772 * @param {string} format | 772 * @param {string} format |
| 773 * @param {!Array.<!SDK.RemoteObject>} parameters | 773 * @param {!Array.<!SDK.RemoteObject>} parameters |
| 774 * @param {!Element} formattedResult | 774 * @param {!Node} output |
| 775 */ | 775 */ |
| 776 _formatWithSubstitutionString(format, parameters, formattedResult) { | 776 _formatWithSubstitutionString(format, parameters, output) { |
| 777 var formatters = {}; | 777 var formatters = {}; |
| 778 | 778 |
| 779 /** | 779 /** |
| 780 * @param {boolean} force | 780 * @param {boolean} force |
| 781 * @param {!SDK.RemoteObject} obj | 781 * @param {!SDK.RemoteObject} obj |
| 782 * @return {!Element} | 782 * @return {!Element} |
| 783 * @this {Console.ConsoleViewMessage} | 783 * @this {Console.ConsoleViewMessage} |
| 784 */ | 784 */ |
| 785 function parameterFormatter(force, obj) { | 785 function parameterFormatter(force, obj) { |
| 786 return this._formatParameter(obj, force, false); | 786 return this._formatParameter(obj, force, false); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 formatters.d = integerFormatter; | 839 formatters.d = integerFormatter; |
| 840 | 840 |
| 841 // Firebug uses %c for styling the message. | 841 // Firebug uses %c for styling the message. |
| 842 formatters.c = styleFormatter; | 842 formatters.c = styleFormatter; |
| 843 | 843 |
| 844 // Support %O to force object formatting, instead of the type-based %o forma tting. | 844 // Support %O to force object formatting, instead of the type-based %o forma tting. |
| 845 formatters.O = parameterFormatter.bind(this, true); | 845 formatters.O = parameterFormatter.bind(this, true); |
| 846 | 846 |
| 847 formatters._ = bypassFormatter; | 847 formatters._ = bypassFormatter; |
| 848 | 848 |
| 849 // replace style formatter with empty formatter to get plain string | |
| 850 var plainFormatters = Object.assign({}, formatters, {'c': a => ''}); | |
| 851 var plainString = String.format(format, parameters, plainFormatters, '', (a, b) => a + b); | |
|
pfeldman
2016/12/12 22:05:45
Some of these formatters format objects, so you ar
karabur
2016/12/14 17:32:50
I would like to have output linkified only if it l
| |
| 852 | |
| 853 var linkNode = Components.Linkifier.getLinkNode(plainString.formattedResult) ; | |
|
pfeldman
2016/12/12 22:05:45
What if we
format("%s%s %s%s", "http", "://www.fb
karabur
2016/12/14 17:32:50
This is a good point, I didn't take into account s
| |
| 854 if (linkNode) { | |
| 855 linkNode.innerHTML = ''; | |
|
pfeldman
2016/12/12 22:05:45
Use .textContent = instead, we never use innerHTML
karabur
2016/12/14 17:32:50
Ok.
I'm using that node as accumulator for formatt
| |
| 856 output.appendChild(linkNode); | |
| 857 } | |
| 858 var linkifyInner = !linkNode; | |
| 859 | |
| 849 function append(a, b) { | 860 function append(a, b) { |
| 850 if (b instanceof Node) { | 861 if (b instanceof Node) { |
| 851 a.appendChild(b); | 862 a.appendChild(b); |
| 852 } else if (typeof b !== 'undefined') { | 863 } else if (typeof b !== 'undefined') { |
| 853 var toAppend = Components.linkifyStringAsFragment(String(b)); | 864 var toAppend = |
| 865 linkifyInner ? Components.linkifyStringAsFragment(String(b)) : creat eTextNode(String(b).trimMiddle(150)); | |
|
pfeldman
2016/12/12 22:05:45
That sounds like a strange heuristic.
What you sh
karabur
2016/12/14 17:32:50
not sure I understand.
in line 876 I will get sam
| |
| 854 if (currentStyle) { | 866 if (currentStyle) { |
| 855 var wrapper = createElement('span'); | 867 var wrapper = createElement('span'); |
| 856 wrapper.appendChild(toAppend); | 868 wrapper.appendChild(toAppend); |
| 857 applyCurrentStyle(wrapper); | 869 applyCurrentStyle(wrapper); |
| 858 for (var i = 0; i < wrapper.children.length; ++i) | 870 for (var i = 0; i < wrapper.children.length; ++i) |
| 859 applyCurrentStyle(wrapper.children[i]); | 871 applyCurrentStyle(wrapper.children[i]); |
| 860 toAppend = wrapper; | 872 toAppend = wrapper; |
| 861 } | 873 } |
| 862 a.appendChild(toAppend); | 874 a.appendChild(toAppend); |
| 863 } | 875 } |
| 864 return a; | 876 return a; |
| 865 } | 877 } |
| 866 | 878 |
| 867 /** | 879 /** |
| 868 * @param {!Element} element | 880 * @param {!Element} element |
| 869 */ | 881 */ |
| 870 function applyCurrentStyle(element) { | 882 function applyCurrentStyle(element) { |
| 871 for (var key in currentStyle) | 883 for (var key in currentStyle) |
| 872 element.style[key] = currentStyle[key]; | 884 element.style[key] = currentStyle[key]; |
| 873 } | 885 } |
| 874 | 886 |
| 887 var formattedResult = linkNode || output; | |
| 875 // String.format does treat formattedResult like a Builder, result is an obj ect. | 888 // String.format does treat formattedResult like a Builder, result is an obj ect. |
| 876 return String.format(format, parameters, formatters, formattedResult, append ); | 889 var result = String.format(format, parameters, formatters, formattedResult, append); |
| 890 return result; | |
| 877 } | 891 } |
| 878 | 892 |
| 879 /** | 893 /** |
| 880 * @return {boolean} | 894 * @return {boolean} |
| 881 */ | 895 */ |
| 882 matchesFilterRegex(regexObject) { | 896 matchesFilterRegex(regexObject) { |
| 883 regexObject.lastIndex = 0; | 897 regexObject.lastIndex = 0; |
| 884 var text = this.contentElement().deepTextContent(); | 898 var text = this.contentElement().deepTextContent(); |
| 885 return regexObject.test(text); | 899 return regexObject.test(text); |
| 886 } | 900 } |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1262 toMessageElement() { | 1276 toMessageElement() { |
| 1263 if (!this._element) { | 1277 if (!this._element) { |
| 1264 super.toMessageElement(); | 1278 super.toMessageElement(); |
| 1265 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); | 1279 this._expandGroupIcon = UI.Icon.create('', 'expand-group-icon'); |
| 1266 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); | 1280 this._contentElement.insertBefore(this._expandGroupIcon, this._contentElem ent.firstChild); |
| 1267 this.setCollapsed(this._collapsed); | 1281 this.setCollapsed(this._collapsed); |
| 1268 } | 1282 } |
| 1269 return this._element; | 1283 return this._element; |
| 1270 } | 1284 } |
| 1271 }; | 1285 }; |
| OLD | NEW |