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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js

Issue 2512013002: [DevTools] Handle external link clicks and context menu separately. (Closed)
Patch Set: rebased Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/main/module.json ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
5 * Copyright (C) 2009 Joseph Pecoraro 5 * Copyright (C) 2009 Joseph Pecoraro
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 1894 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 Unknown: 0, 1905 Unknown: 0,
1906 Foreground: 1 << 0, 1906 Foreground: 1 << 0,
1907 Background: 1 << 1, 1907 Background: 1 << 1,
1908 Selection: 1 << 2, 1908 Selection: 1 << 2,
1909 }; 1909 };
1910 1910
1911 /** 1911 /**
1912 * @param {string} url 1912 * @param {string} url
1913 * @param {string=} linkText 1913 * @param {string=} linkText
1914 * @param {string=} className 1914 * @param {string=} className
1915 * @param {boolean=} preventClick
1915 * @return {!Element} 1916 * @return {!Element}
1916 */ 1917 */
1917 UI.createExternalLink = function(url, linkText, className) { 1918 UI.createExternalLink = function(url, linkText, className, preventClick) {
1918 if (!linkText) 1919 if (!linkText)
1919 linkText = url; 1920 linkText = url;
1920 1921
1921 var a = createElementWithClass('a', className); 1922 var a = createElementWithClass('a', className);
1922 var href = url; 1923 var href = url;
1923 if (url.trim().toLowerCase().startsWith('javascript:')) 1924 if (url.trim().toLowerCase().startsWith('javascript:'))
1924 href = null; 1925 href = null;
1925 if (Common.ParsedURL.isRelativeURL(url)) 1926 if (Common.ParsedURL.isRelativeURL(url))
1926 href = null; 1927 href = null;
1927 if (href !== null) { 1928 if (href !== null) {
1928 a.href = href; 1929 a.href = href;
1929 a.classList.add('webkit-html-external-link'); 1930 a.classList.add('webkit-html-external-link');
1931 a.addEventListener('click', (event) => {
1932 event.consume(true);
1933 if (!preventClick)
1934 InspectorFrontendHost.openInNewTab(/** @type {string} */ (href));
1935 }, false);
1936 a[UI._externalLinkSymbol] = true;
1930 } 1937 }
1931 if (linkText !== url) 1938 if (linkText !== url)
1932 a.title = url; 1939 a.title = url;
1933 a.textContent = linkText.trimMiddle(150); 1940 a.textContent = linkText.trimMiddle(150);
1934 a.setAttribute('target', '_blank'); 1941 a.setAttribute('target', '_blank');
1935 1942
1936 return a; 1943 return a;
1937 }; 1944 };
1938 1945
1946 UI._externalLinkSymbol = Symbol('UI._externalLink');
1947
1948 /**
1949 * @implements {UI.ContextMenu.Provider}
1950 * @unrestricted
1951 */
1952 UI.ExternaLinkContextMenuProvider = class {
1953 /**
1954 * @override
1955 * @param {!Event} event
1956 * @param {!UI.ContextMenu} contextMenu
1957 * @param {!Object} target
1958 */
1959 appendApplicableItems(event, contextMenu, target) {
1960 var targetNode = /** @type {!Node} */ (target);
1961 while (targetNode && !targetNode[UI._externalLinkSymbol])
1962 targetNode = targetNode.parentNodeOrShadowHost();
1963 if (!targetNode || !targetNode.href)
1964 return;
1965 contextMenu.appendItem(UI.openLinkExternallyLabel(), () => InspectorFrontend Host.openInNewTab(targetNode.href));
1966 contextMenu.appendItem(UI.copyLinkAddressLabel(), () => InspectorFrontendHos t.copyText(targetNode.href));
1967 }
1968 };
1969
1970
1939 /** 1971 /**
1940 * @param {string} article 1972 * @param {string} article
1941 * @param {string} title 1973 * @param {string} title
1942 * @return {!Element} 1974 * @return {!Element}
1943 */ 1975 */
1944 UI.createDocumentationLink = function(article, title) { 1976 UI.createDocumentationLink = function(article, title) {
1945 return UI.createExternalLink('https://developers.google.com/web/tools/chrome-d evtools/' + article, title); 1977 return UI.createExternalLink('https://developers.google.com/web/tools/chrome-d evtools/' + article, title);
1946 }; 1978 };
1947 1979
1948 /** 1980 /**
1949 * @param {string} url 1981 * @param {string} url
1950 * @return {!Promise<?Image>} 1982 * @return {!Promise<?Image>}
1951 */ 1983 */
1952 UI.loadImage = function(url) { 1984 UI.loadImage = function(url) {
1953 return new Promise(fulfill => { 1985 return new Promise(fulfill => {
1954 var image = new Image(); 1986 var image = new Image();
1955 image.addEventListener('load', () => fulfill(image)); 1987 image.addEventListener('load', () => fulfill(image));
1956 image.addEventListener('error', () => fulfill(null)); 1988 image.addEventListener('error', () => fulfill(null));
1957 image.src = url; 1989 image.src = url;
1958 }); 1990 });
1959 }; 1991 };
1960 1992
1961 /** @type {!UI.ThemeSupport} */ 1993 /** @type {!UI.ThemeSupport} */
1962 UI.themeSupport; 1994 UI.themeSupport;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/main/module.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698