From 96b20d8fc54ab7843251f1e33e09081febfda593 Mon Sep 17 00:00:00 2001 From: "neil%parkwaycc.co.uk" Date: Fri, 17 Jun 2005 20:17:18 +0000 Subject: [PATCH] Bug 254542 Support middle-clicks in history p=trev@gtchat.de r=me sr=dmose a=asa --- .../history/resources/history-panel.xul | 2 +- xpfe/components/history/resources/history.js | 45 +++++++++++-------- .../history/resources/historyTreeOverlay.xul | 6 +-- 3 files changed, 31 insertions(+), 22 deletions(-) diff --git a/xpfe/components/history/resources/history-panel.xul b/xpfe/components/history/resources/history-panel.xul index e14b2e0b909..cb1e0c3f72e 100644 --- a/xpfe/components/history/resources/history-panel.xul +++ b/xpfe/components/history/resources/history-panel.xul @@ -61,7 +61,7 @@ - + diff --git a/xpfe/components/history/resources/history.js b/xpfe/components/history/resources/history.js index d65a9d7f8c4..b394cf02262 100644 --- a/xpfe/components/history/resources/history.js +++ b/xpfe/components/history/resources/history.js @@ -61,6 +61,10 @@ function HistoryCommonInit() var historyController = new nsHistoryController; gHistoryTree.controllers.appendController(historyController); + gPrefService = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + PREF = gPrefService; // need this for bookmarks.js + if ("arguments" in window && window.arguments[0] && window.arguments.length >= 1) { // We have been supplied a resource URI to root the tree on var uri = window.arguments[0]; @@ -77,8 +81,6 @@ function HistoryCommonInit() document.getElementById("groupingMenu").setAttribute("hidden", "true"); } else { - gPrefService = Components.classes["@mozilla.org/preferences-service;1"] - .getService(Components.interfaces.nsIPrefBranch); try { gHistoryGrouping = gPrefService.getCharPref("browser.history.grouping"); } @@ -135,17 +137,22 @@ function historyOnClick(aEvent) // This is kind of a hack but matches the currently implemented behaviour. // If a status bar is not present, assume we're in sidebar mode, and thus single clicks on containers // will open the container. Single clicks on non-containers are handled below in historyOnSelect. - if (!gHistoryStatus && aEvent.button == 0) { - var row = { }; - var col = { }; - var elt = { }; - gHistoryTree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, elt); - if (row.value >= 0 && col.value) { - if (!isContainer(gHistoryTree, row.value)) - OpenURL("current"); - else if (elt.value != "twisty") - gHistoryTree.treeBoxObject.view.toggleOpenState(row.value); - } + if (gHistoryStatus && aEvent.button == 0) + return; + + var target = BookmarksUtils.getBrowserTargetFromEvent(aEvent); + if (!target) + return; + + var row = { }; + var col = { }; + var elt = { }; + gHistoryTree.treeBoxObject.getCellAt(aEvent.clientX, aEvent.clientY, row, col, elt); + if (row.value >= 0 && col.value) { + if (!isContainer(gHistoryTree, row.value)) + OpenURL(target); + else if (aEvent.button == 0 && elt.value != "twisty") + gHistoryTree.treeBoxObject.view.toggleOpenState(row.value); } } @@ -331,9 +338,9 @@ function OpenURL(aTarget) } } else { if (URLArray.length > 0) - OpenURLArrayInTabs(URLArray); + OpenURLArrayInTabs(URLArray, aTarget == "tab_background"); } - } + } else if (!isContainer(gHistoryTree, currentIndex)) openTopWin(url); return true; @@ -341,14 +348,16 @@ function OpenURL(aTarget) // This opens the URLs contained in the given array in new tabs // of the most recent window, creates a new window if necessary. -function OpenURLArrayInTabs(aURLArray) +function OpenURLArrayInTabs(aURLArray, aBackground) { var browserWin = getTopWin(); if (browserWin) { var browser = browserWin.getBrowser(); - browser.selectedTab = browser.addTab(aURLArray[0]); + var tab = browser.addTab(aURLArray[0]); + if (!aBackground) + browser.selectedTab = tab; for (var i = 1; i < aURLArray.length; ++i) - tab = browser.addTab(aURLArray[i]); + browser.addTab(aURLArray[i]); } else { openTopWin(aURLArray.join("\n")); // Pretend that we're a home page group } diff --git a/xpfe/components/history/resources/historyTreeOverlay.xul b/xpfe/components/history/resources/historyTreeOverlay.xul index 6d2f0af82b7..2f13916f0d8 100644 --- a/xpfe/components/history/resources/historyTreeOverlay.xul +++ b/xpfe/components/history/resources/historyTreeOverlay.xul @@ -76,7 +76,7 @@ + oncommand="OpenURL(BookmarksUtils.shouldLoadTabInBackground(event) ? 'tab_background' : 'tab');"/> + ondblclick="if (validClickConditions(event)) OpenURL(BookmarksUtils.getBrowserTargetFromEvent(event));">