Bug 1294799 - Don't hide the bookmark panel if the user has made a selection change. r?gijs
MozReview-Commit-ID: 9J4fYMZQXMh
--- a/browser/base/content/browser-places.js
+++ b/browser/base/content/browser-places.js
@@ -6,16 +6,17 @@
//// StarUI
var StarUI = {
_itemId: -1,
uri: null,
_batching: false,
_isNewBookmark: false,
_autoCloseTimer: 0,
+ _selectionChanged: false,
_element: function(aID) {
return document.getElementById(aID);
},
// Edit-bookmark panel
get panel() {
delete this.panel;
@@ -126,35 +127,56 @@ var StarUI = {
// be enough.
break;
}
this.panel.hidePopup();
break;
}
break;
case "mouseout":
+ if (this._selectionChanged) {
+ // Don't autoclose the popup if the user has made a selection,
+ // even if they subsequently mouseout.
+ break;
+ }
// Explicit fall-through
- case "popupshown":
+ case "popupshown": {
// Don't handle events for descendent elements.
if (aEvent.target != aEvent.currentTarget) {
break;
}
+
+ // namePicker is not added to the DOM until the overlay has been applied.
+ this._selectionChanged = false;
+ let namePicker = this._element("editBMPanel_namePicker");
+ namePicker.addEventListener("selectionchange", this, false);
+
// auto-close if new and not interacted with
if (this._isNewBookmark) {
// 3500ms matches the timeout that Pocket uses in
// browser/extensions/pocket/content/panels/js/saved.js
let delay = 3500;
if (this._closePanelQuickForTesting) {
delay /= 10;
}
this._autoCloseTimer = setTimeout(() => {
this.panel.hidePopup();
}, delay);
}
break;
+ }
+ case "selectionchange": {
+ let namePicker = this._element("editBMPanel_namePicker");
+ // window.getSelection() returns no selection for XUL windows.
+ if (!namePicker.editor.selection.isCollapsed) {
+ clearTimeout(this._autoCloseTimer);
+ this._selectionChanged = true;
+ }
+ break;
+ }
}
},
_overlayLoaded: false,
_overlayLoading: false,
showEditBookmarkPopup: Task.async(function* (aNode, aAnchorElement, aPosition, aIsNewBookmark) {
// Slow double-clicks (not true double-clicks) shouldn't
// cause the panel to flicker.
--- a/browser/base/content/test/general/browser_bookmark_popup.js
+++ b/browser/base/content/test/general/browser_bookmark_popup.js
@@ -247,11 +247,43 @@ add_task(function* ctrl_d_edit_bookmark_
shouldAutoClose: true,
popupHideFn() {
document.getElementById("editBookmarkPanelRemoveButton").click();
},
isBookmarkRemoved: true,
});
});
+add_task(function* ctrl_d_new_bookmark_selection_mouseleave_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.synthesizeSelectionSet(0, 2, false, window);
+
+ 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;
-})
+});