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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/Linkifier.js

Issue 2519213002: [DevTools] Remove preventFollow and special checks for links throughout frontend. (Closed)
Patch Set: Created 4 years 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) 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 335 }
336 info.icon = icon; 336 info.icon = icon;
337 } 337 }
338 338
339 /** 339 /**
340 * @param {string} url 340 * @param {string} url
341 * @param {string=} text 341 * @param {string=} text
342 * @param {string=} className 342 * @param {string=} className
343 * @param {number=} lineNumber 343 * @param {number=} lineNumber
344 * @param {number=} columnNumber 344 * @param {number=} columnNumber
345 * @param {boolean=} preventClick
345 * @return {!Element} 346 * @return {!Element}
346 */ 347 */
347 static linkifyURL(url, text, className, lineNumber, columnNumber) { 348 static linkifyURL(url, text, className, lineNumber, columnNumber, preventClick ) {
348 if (!url || url.trim().toLowerCase().startsWith('javascript:')) { 349 if (!url || url.trim().toLowerCase().startsWith('javascript:')) {
349 var element = createElementWithClass('span', className); 350 var element = createElementWithClass('span', className);
350 element.textContent = text || url || Common.UIString('(unknown)'); 351 element.textContent = text || url || Common.UIString('(unknown)');
351 return element; 352 return element;
352 } 353 }
353 354
354 var linkText = text || Bindings.displayNameForURL(url); 355 var linkText = text || Bindings.displayNameForURL(url);
355 if (typeof lineNumber === 'number' && !text) 356 if (typeof lineNumber === 'number' && !text)
356 linkText += ':' + (lineNumber + 1); 357 linkText += ':' + (lineNumber + 1);
357 var title = linkText !== url ? url : ''; 358 var title = linkText !== url ? url : '';
358 var link = Components.Linkifier._createLink(linkText.trimMiddle(150), classN ame || '', title, url); 359 var link = Components.Linkifier._createLink(linkText.trimMiddle(150), classN ame || '', title, url, preventClick);
359 var info = Components.Linkifier._linkInfo(link); 360 var info = Components.Linkifier._linkInfo(link);
360 if (typeof lineNumber === 'number') 361 if (typeof lineNumber === 'number')
361 info.lineNumber = lineNumber; 362 info.lineNumber = lineNumber;
362 if (typeof columnNumber === 'number') 363 if (typeof columnNumber === 'number')
363 info.columnNumber = columnNumber; 364 info.columnNumber = columnNumber;
364 return link; 365 return link;
365 } 366 }
366 367
367 /** 368 /**
368 * @param {!Object} revealable 369 * @param {!Object} revealable
369 * @param {string} text 370 * @param {string} text
370 * @param {string=} fallbackHref 371 * @param {string=} fallbackHref
371 * @return {!Element} 372 * @return {!Element}
372 */ 373 */
373 static linkifyRevealable(revealable, text, fallbackHref) { 374 static linkifyRevealable(revealable, text, fallbackHref) {
374 var link = Components.Linkifier._createLink( 375 var link = Components.Linkifier._createLink(
375 text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedURLs), '', und efined, fallbackHref); 376 text.trimMiddle(Components.Linkifier.MaxLengthForDisplayedURLs), '', und efined, fallbackHref);
376 Components.Linkifier._linkInfo(link).revealable = revealable; 377 Components.Linkifier._linkInfo(link).revealable = revealable;
377 return link; 378 return link;
378 } 379 }
379 380
380 /** 381 /**
381 * @param {string} text 382 * @param {string} text
382 * @param {string} className 383 * @param {string} className
383 * @param {string=} title 384 * @param {string=} title
384 * @param {string=} href 385 * @param {string=} href
386 * @param {boolean=} preventClick
385 * @returns{!Element} 387 * @returns{!Element}
386 */ 388 */
387 static _createLink(text, className, title, href) { 389 static _createLink(text, className, title, href, preventClick) {
388 var link = createElementWithClass('a', className); 390 var link = createElementWithClass('a', className);
389 link.classList.add('webkit-html-resource-link'); 391 link.classList.add('webkit-html-resource-link');
390 if (title) 392 if (title)
391 link.title = title; 393 link.title = title;
392 if (href) 394 if (href)
393 link.href = href; 395 link.href = href;
394 link.textContent = text; 396 link.textContent = text;
395 link[Components.Linkifier._infoSymbol] = { 397 link[Components.Linkifier._infoSymbol] = {
396 icon: null, 398 icon: null,
397 enableDecorator: false, 399 enableDecorator: false,
398 uiLocation: null, 400 uiLocation: null,
399 liveLocation: null, 401 liveLocation: null,
400 url: href || null, 402 url: href || null,
401 lineNumber: null, 403 lineNumber: null,
402 columnNumber: null, 404 columnNumber: null,
403 revealable: null, 405 revealable: null,
404 fallback: null 406 fallback: null
405 }; 407 };
406 link.addEventListener('click', Components.Linkifier._handleClick, false); 408 if (preventClick)
409 link.addEventListener('click', event => event.consume(true), false);
410 else
411 link.addEventListener('click', Components.Linkifier._handleClick, false);
407 return link; 412 return link;
408 } 413 }
409 414
410 /** 415 /**
411 * @param {?Element} link 416 * @param {?Element} link
412 * @return {?Components._LinkInfo} 417 * @return {?Components._LinkInfo}
413 */ 418 */
414 static _linkInfo(link) { 419 static _linkInfo(link) {
415 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null); 420 return /** @type {?Components._LinkInfo} */ (link ? link[Components.Linkifie r._infoSymbol] || null : null);
416 } 421 }
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false)); 772 contextMenu.appendItem(Common.UIString('Save'), save.bind(null, false));
768 773
769 if (contentProvider instanceof Workspace.UISourceCode) { 774 if (contentProvider instanceof Workspace.UISourceCode) {
770 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider ); 775 var uiSourceCode = /** @type {!Workspace.UISourceCode} */ (contentProvider );
771 if (uiSourceCode.project().type() !== Workspace.projectTypes.FileSystem && 776 if (uiSourceCode.project().type() !== Workspace.projectTypes.FileSystem &&
772 uiSourceCode.project().type() !== Workspace.projectTypes.Snippets) 777 uiSourceCode.project().type() !== Workspace.projectTypes.Snippets)
773 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true)); 778 contextMenu.appendItem(Common.UIString.capitalize('Save ^as...'), save.b ind(null, true));
774 } 779 }
775 } 780 }
776 }; 781 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698