Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 linkIcon(uiSourceCode) {} | 586 linkIcon(uiSourceCode) {} |
| 587 }; | 587 }; |
| 588 | 588 |
| 589 Components.LinkDecorator.Events = { | 589 Components.LinkDecorator.Events = { |
| 590 LinkIconChanged: Symbol('LinkIconChanged') | 590 LinkIconChanged: Symbol('LinkIconChanged') |
| 591 }; | 591 }; |
| 592 | 592 |
| 593 /** | 593 /** |
| 594 * @param {string} string | 594 * @param {string} string |
| 595 * @param {function(string,string,number=,number=):!Node} linkifier | 595 * @param {function(string,string,number=,number=):!Node} linkifier |
| 596 * @return {?Node} | |
| 597 */ | |
| 598 Components.Linkifier.getLinkNodeWithCustomLinkifier = function(string, linkifier ) { | |
| 599 var linkString = Components.Linkifier.getLinkString(string); | |
| 600 if (!linkString || linkString[0] !== string) | |
| 601 return null; | |
| 602 | |
| 603 var title = string; | |
| 604 var realURL = (string.startsWith('www.') ? 'http://' + string : string); | |
| 605 var splitResult = Common.ParsedURL.splitLineAndColumn(realURL); | |
| 606 var linkNode; | |
| 607 if (splitResult) | |
| 608 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, splitRe sult.columnNumber); | |
| 609 else | |
| 610 linkNode = linkifier(title, realURL); | |
| 611 | |
| 612 return linkNode; | |
| 613 }; | |
| 614 | |
| 615 /** | |
| 616 * @param {string} string | |
| 617 * @return {?Node} | |
| 618 */ | |
| 619 Components.Linkifier.getLinkNode = function(string) { | |
| 620 /** | |
| 621 * @param {string} title | |
| 622 * @param {string} url | |
| 623 * @param {number=} lineNumber | |
| 624 * @param {number=} columnNumber | |
| 625 * @return {!Node} | |
| 626 */ | |
| 627 function linkifier(title, url, lineNumber, columnNumber) { | |
| 628 return Components.Linkifier.linkifyURL(url, title, undefined, lineNumber, co lumnNumber); | |
| 629 } | |
| 630 | |
| 631 return Components.Linkifier.getLinkNodeWithCustomLinkifier(string, linkifier); | |
| 632 }; | |
| 633 | |
| 634 /** | |
| 635 * @param {string} string | |
| 636 * @return {?Array|{index:number, input:string}} | |
|
luoe
2016/12/13 00:08:27
This annotation looks like an Array OR an Object,
| |
| 637 */ | |
| 638 Components.Linkifier.getLinkString = function(string) { | |
| 639 var linkStringRegEx = | |
| 640 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; | |
| 641 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; | |
| 642 return linkStringRegEx.exec(string) || pathLineRegex.exec(string); | |
| 643 }; | |
| 644 | |
| 645 /** | |
| 646 * @param {string} string | |
| 647 * @param {function(string,string,number=,number=):!Node} linkifier | |
| 596 * @return {!DocumentFragment} | 648 * @return {!DocumentFragment} |
| 597 */ | 649 */ |
| 598 Components.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifi er) { | 650 Components.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifi er) { |
| 599 var container = createDocumentFragment(); | 651 var container = createDocumentFragment(); |
| 600 var linkStringRegEx = | |
| 601 /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^% @&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; | |
| 602 var pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; | |
| 603 | 652 |
| 604 while (string && string.length < Components.Linkifier.MaxLengthToIgnoreLinkifi er) { | 653 while (string && string.length < Components.Linkifier.MaxLengthToIgnoreLinkifi er) { |
| 605 var linkString = linkStringRegEx.exec(string) || pathLineRegex.exec(string); | 654 var linkString = Components.Linkifier.getLinkString(string); |
| 606 if (!linkString) | 655 if (!linkString) |
| 607 break; | 656 break; |
| 608 | 657 |
| 609 linkString = linkString[0]; | 658 linkString = linkString[0]; |
| 610 var linkIndex = string.indexOf(linkString); | 659 var linkIndex = string.indexOf(linkString); |
| 611 var nonLink = string.substring(0, linkIndex); | 660 var nonLink = string.substring(0, linkIndex); |
| 612 container.appendChild(createTextNode(nonLink)); | 661 container.appendChild(createTextNode(nonLink)); |
| 613 | 662 |
| 614 var title = linkString; | 663 var linkNode = Components.Linkifier.getLinkNodeWithCustomLinkifier(linkStrin g, linkifier); |
| 615 var realURL = (linkString.startsWith('www.') ? 'http://' + linkString : link String); | |
| 616 var splitResult = Common.ParsedURL.splitLineAndColumn(realURL); | |
| 617 var linkNode; | |
| 618 if (splitResult) | |
| 619 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, split Result.columnNumber); | |
| 620 else | |
| 621 linkNode = linkifier(title, realURL); | |
| 622 | 664 |
| 623 container.appendChild(linkNode); | 665 container.appendChild(linkNode); |
| 624 string = string.substring(linkIndex + linkString.length, string.length); | 666 string = string.substring(linkIndex + linkString.length, string.length); |
| 625 } | 667 } |
| 626 | 668 |
| 627 if (string) | 669 if (string) |
| 628 container.appendChild(createTextNode(string)); | 670 container.appendChild(createTextNode(string)); |
| 629 | 671 |
| 630 return container; | 672 return container; |
| 631 }; | 673 }; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 contextMenu.appendSeparator(); | 813 contextMenu.appendSeparator(); |
| 772 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); | 814 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); |
| 773 | 815 |
| 774 if (contentProvider instanceof Workspace.UISourceCode) { | 816 if (contentProvider instanceof Workspace.UISourceCode) { |
| 775 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); | 817 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); |
| 776 if (!uiSourceCode.project().canSetFileContent()) | 818 if (!uiSourceCode.project().canSetFileContent()) |
| 777 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); | 819 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); |
| 778 } | 820 } |
| 779 } | 821 } |
| 780 }; | 822 }; |
| OLD | NEW |