From a46dd9fa5d8411cb78b4b204258c5f0821be8fff Mon Sep 17 00:00:00 2001 From: "mozilla.mano%sent.com" Date: Thu, 20 Apr 2006 22:35:06 +0000 Subject: [PATCH] Bug 333831 - Reimplement click-and-hold access to the back and forward session history menus. r=mconnor, uir=beltzner. --- browser/base/content/browser.js | 63 ++++++++++++++++++++ browser/base/content/browser.xul | 4 +- browser/themes/pinstripe/browser/browser.css | 6 +- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index fee4a1c63615..459678f6edcd 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -119,6 +119,10 @@ var gFormFillEnabled = true; var gURLBarAutoFillPrefListener = null; var gAutoHideTabbarPrefListener = null; +#ifdef XP_MACOSX +var gClickAndHoldTimer = null; +#endif + /** * We can avoid adding multiple load event listeners and save some time by adding * one listener that calls all real handlers. @@ -195,6 +199,58 @@ function UpdateBackForwardButtons() } } +#ifdef XP_MACOSX +/** + * Click-and-Hold implementation for the Back and Forward buttons + * XXXmano: should this live in toolbarbutton.xml? + */ +function ClickAndHoldMouseDownCallback(aButton) +{ + aButton.open = true; + gClickAndHoldTimer = null; +} + +function ClickAndHoldMouseDown(aEvent) +{ + if (aEvent.target.getAttribute("anonid") != "button") + return; + + var button = aEvent.target.parentNode.parentNode; + if (!button.disabled) + gClickAndHoldTimer = setTimeout(ClickAndHoldMouseDownCallback, 500, button); +} + +function MayStopClickAndHoldTimer(aEvent) +{ + // Note passing null here is a no-op + clearTimeout(gClickAndHoldTimer); +} + +function SetClickAndHoldHandlers() +{ + function _addClickAndHoldListenersOnElement(aElm) + { + aElm.addEventListener("mousedown", + ClickAndHoldMouseDown, + false); + aElm.addEventListener("mouseup", + MayStopClickAndHoldTimer, + false); + aElm.addEventListener("mouseout", + MayStopClickAndHoldTimer, + false); + } + + // The click-and-hold area does not include the dropmarkers of the buttons + var backButton = document.getAnonymousElementByAttribute + (document.getElementById("back-button"), "anonid", "button"); + var forwardButton = document.getAnonymousElementByAttribute + (document.getElementById("forward-button"), "anonid", "button"); + _addClickAndHoldListenersOnElement(backButton); + _addClickAndHoldListenersOnElement(forwardButton); +} +#endif + #ifndef MOZ_PLACES function UpdateBookmarkAllTabsMenuitem() { @@ -1015,6 +1071,13 @@ function delayedStartup() document.getElementById("textfieldDirection-separator").hidden = false; document.getElementById("textfieldDirection-swap").hidden = false; } + +#ifdef XP_MACOSX + // Setup click-and-hold gestures access to the session history + // menus if global click-and-hold isn't turned on + if (!getBoolPref("ui.click_hold_context_menus", false)) + SetClickAndHoldHandlers(); +#endif } function BrowserShutdown() diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index fcb7659956e6..e75c98ba47bf 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -163,7 +163,7 @@ @@ -177,7 +177,7 @@ diff --git a/browser/themes/pinstripe/browser/browser.css b/browser/themes/pinstripe/browser/browser.css index 3ba74ae7b877..f0bb37ba1884 100755 --- a/browser/themes/pinstripe/browser/browser.css +++ b/browser/themes/pinstripe/browser/browser.css @@ -274,7 +274,8 @@ menubutton:not([disabled="true"]):hover:active { #back-button { -moz-image-region: rect(0px 32px 32px 0px); } -#back-button[buttondown="true"] { +#back-button[buttondown="true"], +#back-button[open="true"] { -moz-image-region: rect(32px 32px 64px 0px); } #back-button[disabled="true"] { @@ -284,7 +285,8 @@ menubutton:not([disabled="true"]):hover:active { #forward-button { -moz-image-region: rect(0px 64px 32px 32px); } -#forward-button[buttondown="true"] { +#forward-button[buttondown="true"], +#forward-button[open="true"] { -moz-image-region: rect(32px 64px 64px 32px); } #forward-button[disabled="true"] {