Bug 1156615 - (Browser API) ctrl/cmd/middle-click doesn't work if <a> element has children. r=kchen

This commit is contained in:
Paul Rouget 2015-04-20 22:27:00 -04:00
parent cebfaf9b82
commit f7a3bfe4d5
2 changed files with 21 additions and 9 deletions

View File

@ -585,13 +585,25 @@ BrowserElementChild.prototype = {
},
_ClickHandler: function(e) {
let elem = e.target;
if (elem instanceof Ci.nsIDOMHTMLAnchorElement && elem.href) {
// Open in a new tab if middle click or ctrl/cmd-click.
if ((Services.appinfo.OS == 'Darwin' && e.metaKey) ||
(Services.appinfo.OS != 'Darwin' && e.ctrlKey) ||
e.button == 1) {
sendAsyncMsg('opentab', {url: elem.href});
let isHTMLLink = node =>
((node instanceof Ci.nsIDOMHTMLAnchorElement && node.href) ||
(node instanceof Ci.nsIDOMHTMLAreaElement && node.href) ||
node instanceof Ci.nsIDOMHTMLLinkElement);
// Open in a new tab if middle click or ctrl/cmd-click,
// and e.target is a link or inside a link.
if ((Services.appinfo.OS == 'Darwin' && e.metaKey) ||
(Services.appinfo.OS != 'Darwin' && e.ctrlKey) ||
e.button == 1) {
let node = e.target;
while (node && !isHTMLLink(node)) {
node = node.parentNode;
}
if (node) {
sendAsyncMsg('opentab', {url: node.href});
}
}
},

View File

@ -51,7 +51,7 @@ function runTest() {
iframe.sendMouseEvent('mouseup', x, y, 1, 1, 0);
}
let onMiddleClick= e => {
let onMiddleClick = e => {
is(e.detail.url, 'http://example.com/', 'URL matches');
iframe.removeEventListener('mozbrowseropentab', onMiddleClick);
SimpleTest.finish();
@ -63,7 +63,7 @@ function runTest() {
});
iframe.src = 'data:text/html,<body style="margin:0"><a href="http://example.com">click here</a></body>';
iframe.src = 'data:text/html,<body style="margin:0"><a href="http://example.com"><span>click here</span></a></body>';
}
addEventListener('testready', runTest);