Bug 647886 - Pulling down Back/Forward menu requires an unnecessary delay. r=sdwilsh

--HG--
extra : rebase_source : a2628b38bd336925155bb05b53b407a11b7a3df2
This commit is contained in:
Dão Gottwald 2011-05-24 08:34:14 +02:00
Родитель d98052e70d
Коммит 1bda8bef80
3 изменённых файлов: 60 добавлений и 12 удалений

Просмотреть файл

@ -261,10 +261,10 @@ function UpdateBackForwardCommands(aWebNavigation) {
function SetClickAndHoldHandlers() {
var timer;
function timerCallback(aButton) {
function openMenu(aButton) {
cancelHold(aButton);
aButton.firstChild.hidden = false;
aButton.open = true;
timer = null;
}
function mousedownHandler(aEvent) {
@ -276,7 +276,29 @@ function SetClickAndHoldHandlers() {
// Prevent the menupopup from opening immediately
aEvent.currentTarget.firstChild.hidden = true;
timer = setTimeout(timerCallback, 500, aEvent.currentTarget);
aEvent.currentTarget.addEventListener("mouseout", mouseoutHandler, false);
aEvent.currentTarget.addEventListener("mouseup", mouseupHandler, false);
timer = setTimeout(openMenu, 500, aEvent.currentTarget);
}
function mouseoutHandler(aEvent) {
let buttonRect = aEvent.currentTarget.getBoundingClientRect();
if (aEvent.clientX >= buttonRect.left &&
aEvent.clientX <= buttonRect.right &&
aEvent.clientY >= buttonRect.bottom)
openMenu(aEvent.currentTarget);
else
cancelHold(aEvent.currentTarget);
}
function mouseupHandler(aEvent) {
cancelHold(aEvent.currentTarget);
}
function cancelHold(aButton) {
clearTimeout(timer);
aButton.removeEventListener("mouseout", mouseoutHandler, false);
aButton.removeEventListener("mouseup", mouseupHandler, false);
}
function clickHandler(aEvent) {
@ -292,17 +314,8 @@ function SetClickAndHoldHandlers() {
}
}
function stopTimer(aEvent) {
if (timer) {
clearTimeout(timer);
timer = null;
}
}
function _addClickAndHoldListenersOnElement(aElm) {
aElm.addEventListener("mousedown", mousedownHandler, true);
aElm.addEventListener("mouseup", stopTimer, false);
aElm.addEventListener("mouseout", stopTimer, false);
aElm.addEventListener("click", clickHandler, true);
}

Просмотреть файл

@ -170,6 +170,7 @@ _BROWSER_FILES = \
browser_bug616836.js \
browser_bug623893.js \
browser_bug624734.js \
browser_bug647886.js \
browser_findbarClose.js \
browser_contextSearchTabPosition.js \
browser_ctrlTab.js \

Просмотреть файл

@ -0,0 +1,34 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
waitForExplicitFinish();
gBrowser.selectedBrowser.addEventListener("load", function () {
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
content.history.pushState({}, "2", "2.html");
testBackButton();
}, true);
loadURI("http://example.com");
}
function testBackButton() {
var backButton = document.getElementById("back-button");
var rect = backButton.getBoundingClientRect();
info("waiting for the history menu to open");
backButton.addEventListener("popupshown", function (event) {
backButton.removeEventListener("popupshown", arguments.callee, false);
ok(true, "history menu opened");
event.target.hidePopup();
finish();
}, false);
EventUtils.synthesizeMouseAtCenter(backButton, {type: "mousedown"});
EventUtils.synthesizeMouse(backButton, rect.width / 2, rect.height, {type: "mouseup"});
}