Bug 1268943 - Middle mouse click on links in settings does nothing (should open in new tab). r?gijs
MozReview-Commit-ID: D8okQLio0K8
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -375,17 +375,19 @@ BrowserGlue.prototype = {
case "initial-migration-did-import-default-bookmarks":
this._initPlaces(true);
break;
case "handle-xul-text-link":
let linkHandled = subject.QueryInterface(Ci.nsISupportsPRBool);
if (!linkHandled.data) {
let win = RecentWindow.getMostRecentBrowserWindow();
if (win) {
- win.openUILinkIn(data, "tab");
+ data = JSON.parse(data);
+ let where = win.whereToOpenLink(data);
+ win.openUILinkIn(data.href, where);
linkHandled.data = true;
}
}
break;
case "profile-before-change":
// Any component depending on Places should be finalized in
// _onPlacesShutdown. Any component that doesn't need to act after
// the UI has gone should be finalized in _onQuitApplicationGranted.
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -9,16 +9,17 @@ support-files =
[browser_bug594509.js]
[browser_bug982298.js]
[browser_bug1198465.js]
[browser_contentTitle.js]
[browser_default_image_filename.js]
[browser_f7_caret_browsing.js]
skip-if = e10s
[browser_findbar.js]
+[browser_label_textlink.js]
[browser_isSynthetic.js]
support-files =
empty.png
[browser_keyevents_during_autoscrolling.js]
[browser_save_resend_postdata.js]
support-files =
common/mockTransfer.js
data/post_form_inner.sjs
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/browser/browser_label_textlink.js
@@ -0,0 +1,28 @@
+add_task(function* () {
+ yield BrowserTestUtils.withNewTab({gBrowser, url: "about:config"}, function*(browser) {
+ yield ContentTask.spawn(browser, {}, function*() {
+ let doc = content.document;
+ let label = doc.createElement("label");
+ label.href = "http://www.example.com";
+ label.id = "textlink-test";
+ label.className = "text-link";
+ label.textContent = "click me";
+ doc.documentElement.append(label);
+ });
+ let originalTabCount = gBrowser.tabs.length;
+
+ // Test that click will open tab in foreground.
+ yield BrowserTestUtils.synthesizeMouseAtCenter("#textlink-test", {}, browser);
+ is(gBrowser.tabs.length, originalTabCount + 1, "the new tab should be opened");
+ isnot(gBrowser.selectedBrowser, browser, "selected tab should be example page");
+ yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+
+ // Test that ctrl+shift+click/meta+shift+click will open tab in background.
+ yield BrowserTestUtils.synthesizeMouseAtCenter("#textlink-test",
+ {ctrlKey: true, metaKey: true, shiftKey: true},
+ browser);
+ is(gBrowser.selectedBrowser, browser, "selected tab should be original tab");
+ is(gBrowser.tabs.length, originalTabCount + 1, "the new tab should be opened");
+ yield BrowserTestUtils.removeTab(gBrowser.tabs[originalTabCount]);
+ });
+});
--- a/toolkit/content/widgets/text.xml
+++ b/toolkit/content/widgets/text.xml
@@ -351,19 +351,27 @@
aEvent.preventDefault();
href = uri ? uri.spec : href;
// Try handing off the link to the host application, e.g. for
// opening it in a tabbed browser.
var linkHandled = Components.classes["@mozilla.org/supports-PRBool;1"]
.createInstance(Components.interfaces.nsISupportsPRBool);
linkHandled.data = false;
+ let {shiftKey, ctrlKey, metaKey, altKey, button} = aEvent;
+ if (!shiftKey && !altKey && button == 0) {
+ // Preserve legacy behavior of non-modifier left-clicks
+ // opening in a new selected tab.
+ ctrlKey = true;
+ metaKey = true;
+ }
+ let data = {shiftKey, ctrlKey, metaKey, altKey, button, href};
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService)
- .notifyObservers(linkHandled, "handle-xul-text-link", href);
+ .notifyObservers(linkHandled, "handle-xul-text-link", JSON.stringify(data));
if (linkHandled.data)
return;
// otherwise, fall back to opening the anchor directly
var win = window;
if (window instanceof Components.interfaces.nsIDOMChromeWindow) {
while (win.opener && !win.opener.closed)
win = win.opener;