Bug 1294799 - Disable the autoclosing of the bookmark popup if there is any interaction with it such as mousedown or keypress. r=mak

MozReview-Commit-ID: JRo5ZVu0uFD

--HG--
extra : rebase_source : ffb0d7a8323595fe61e85fee200a2aca5bc63310
This commit is contained in:
Jared Wein 2017-02-10 11:11:57 -05:00
Родитель a35278e9a7
Коммит 3dd99bad30
2 изменённых файлов: 62 добавлений и 20 удалений

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

@ -9,6 +9,10 @@ var StarUI = {
_isNewBookmark: false,
_isComposing: false,
_autoCloseTimer: 0,
// The autoclose timer is diasbled if the user interacts with the
// popup, such as making a change through typing or clicking on
// the popup.
_autoCloseTimerEnabled: true,
_element(aID) {
return document.getElementById(aID);
@ -22,6 +26,7 @@ var StarUI = {
// to avoid impacting startup / new window performance
element.hidden = false;
element.addEventListener("keypress", this);
element.addEventListener("mousedown", this);
element.addEventListener("mouseout", this);
element.addEventListener("mousemove", this);
element.addEventListener("compositionstart", this);
@ -66,6 +71,8 @@ var StarUI = {
switch (aEvent.type) {
case "mousemove":
clearTimeout(this._autoCloseTimer);
// The autoclose timer is not disabled on generic mouseout
// because the user may not have actually interacted with the popup.
break;
case "popuphidden":
clearTimeout(this._autoCloseTimer);
@ -109,6 +116,7 @@ var StarUI = {
break;
case "keypress":
clearTimeout(this._autoCloseTimer);
this._autoCloseTimerEnabled = false;
if (aEvent.defaultPrevented) {
// The event has already been consumed inside of the panel.
@ -139,26 +147,32 @@ var StarUI = {
break;
}
break;
case "compositionstart":
if (aEvent.defaultPrevented) {
// If the composition was canceled, nothing to do here.
break;
}
// During composition, panel shouldn't be hidden automatically.
clearTimeout(this._autoCloseTimer);
this._isComposing = true;
break;
case "compositionend":
// After composition is committed, "mouseout" or something can set
// auto close timer.
this._isComposing = false;
break;
case "compositionstart":
if (aEvent.defaultPrevented) {
// If the composition was canceled, nothing to do here.
break;
}
this._isComposing = true;
// Explicit fall-through, during composition, panel shouldn't be
// hidden automatically.
case "input":
// Might be edited some text without keyboard events nor composition
// events. Let's cancel auto close in such case.
// Might have edited some text without keyboard events nor composition
// events. Fall-through to cancel auto close in such case.
case "mousedown":
clearTimeout(this._autoCloseTimer);
this._autoCloseTimerEnabled = false;
break;
case "mouseout":
if (!this._autoCloseTimerEnabled) {
// Don't autoclose the popup if the user has made a selection
// or keypress and then subsequently mouseout.
break;
}
// Explicit fall-through
case "popupshown":
// Don't handle events for descendent elements.
@ -179,6 +193,7 @@ var StarUI = {
this.panel.hidePopup();
}
}, delay);
this._autoCloseTimerEnabled = true;
}
break;
}

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

@ -263,7 +263,7 @@ add_task(function* panel_shown_for_new_bookmark_compositionstart_mouseout_no_aut
});
});
add_task(function* panel_shown_for_new_bookmark_compositionend_mouseout_autoclose() {
add_task(function* panel_shown_for_new_bookmark_compositionend_no_autoclose() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn() {
@ -278,13 +278,8 @@ add_task(function* panel_shown_for_new_bookmark_compositionend_mouseout_autoclos
EventUtils.synthesizeComposition({ type: "compositioncommit", data: "committed text" });
},
*popupHideFn() {
let mouseOutPromise = BrowserTestUtils.waitForEvent(bookmarkPanel, "mouseout");
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, {type: "mouseout"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
info("Waiting for mouseout event");
yield mouseOutPromise;
info("Got mouseout event, should autoclose now");
popupHideFn() {
bookmarkPanel.hidePopup();
},
shouldAutoClose: false,
isBookmarkRemoved: false,
@ -398,6 +393,38 @@ add_task(function* mouse_hovering_panel_should_prevent_autoclose() {
});
});
add_task(function* ctrl_d_new_bookmark_mousedown_mouseout_no_autoclose() {
yield test_bookmarks_popup({
isNewBookmark: true,
popupShowFn(browser) {
EventUtils.synthesizeKey("D", {accelKey: true}, window);
},
*popupEditFn() {
let mouseMovePromise = BrowserTestUtils.waitForEvent(bookmarkPanel, "mousemove");
EventUtils.synthesizeMouseAtCenter(bookmarkPanel, {type: "mousemove"});
info("Waiting for mousemove event");
yield mouseMovePromise;
info("Got mousemove event");
yield new Promise(resolve => setTimeout(resolve, 400));
is(bookmarkPanel.state, "open", "Panel should still be open on mousemove");
EventUtils.synthesizeMouseAtCenter(bookmarkPanelTitle, {button: 1, type: "mousedown"});
let mouseOutPromise = BrowserTestUtils.waitForEvent(bookmarkPanel, "mouseout");
EventUtils.synthesizeMouse(bookmarkPanel, 0, 0, {type: "mouseout"});
EventUtils.synthesizeMouseAtCenter(document.documentElement, {type: "mousemove"});
info("Waiting for mouseout event");
yield mouseOutPromise;
},
shouldAutoClose: false,
popupHideFn() {
document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
registerCleanupFunction(function() {
delete StarUI._closePanelQuickForTesting;
})
});