Bug 1287914 - Buttons in sliding panel overlay are not clickable. r=jaws
MozReview-Commit-ID: JF8LYbyubk6
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -1189,17 +1189,27 @@ const DownloadsViewController = {
// Firstly, determine if this is a command that we can handle.
if (!DownloadsViewUI.isCommandName(aCommand)) {
return false;
}
if (!(aCommand in this) &&
!(aCommand in DownloadsViewItem.prototype)) {
return false;
}
- // Secondly, determine if focus is on a control in the downloads list.
+ // The currently supported commands depend on whether the blocked subview is
+ // showing. If it is, then take the following path.
+ if (DownloadsBlockedSubview.view.showingSubView) {
+ let blockedSubviewCmds = [
+ "downloadsCmd_chooseOpen",
+ "cmd_delete",
+ ];
+ return blockedSubviewCmds.indexOf(aCommand) >= 0;
+ }
+ // If the blocked subview is not showing, then determine if focus is on a
+ // control in the downloads list.
let element = document.commandDispatcher.focusedElement;
while (element && element != DownloadsView.richListBox) {
element = element.parentNode;
}
// We should handle the command only if the downloads list is among the
// ancestors of the focused element.
return !!element;
},
@@ -1599,16 +1609,19 @@ const DownloadsBlockedSubview = {
}
},
/**
* Slides out the blocked subview and shows the main view.
*/
hide() {
this.view.showMainView();
+ // The point of this is to focus the proper element in the panel now that
+ // the main view is showing again. showPanel handles that.
+ DownloadsPanel.showPanel();
},
/**
* Deletes the download and hides the entire panel.
*/
confirmBlock() {
goDoCommand("cmd_delete");
DownloadsPanel.hidePanel();
--- a/browser/components/downloads/test/browser/browser_downloads_panel_block.js
+++ b/browser/components/downloads/test/browser/browser_downloads_panel_block.js
@@ -34,31 +34,33 @@ add_task(function* mainTest() {
// Show the subview again.
EventUtils.sendMouseEvent({ type: "click" }, item);
yield promiseSubviewShown(true);
// Click the Open button. The alert blocked-download dialog should be
// shown.
let dialogPromise = promiseAlertDialogOpen("cancel");
- DownloadsBlockedSubview.elements.openButton.click();
+ EventUtils.synthesizeMouse(DownloadsBlockedSubview.elements.openButton,
+ 10, 10, {}, window);
yield dialogPromise;
window.focus();
yield SimpleTest.promiseFocus(window);
// Reopen the panel and show the subview again.
yield openPanel();
EventUtils.sendMouseEvent({ type: "click" }, item);
yield promiseSubviewShown(true);
// Click the Remove button. The panel should close and the item should be
// removed from it.
- DownloadsBlockedSubview.elements.deleteButton.click();
+ EventUtils.synthesizeMouse(DownloadsBlockedSubview.elements.deleteButton,
+ 10, 10, {}, window);
yield promisePanelHidden();
yield openPanel();
Assert.ok(!item.parentNode);
DownloadsPanel.hidePanel();
yield promisePanelHidden();
}
@@ -146,20 +148,29 @@ function makeDownload(verdict) {
becauseBlockedByReputationCheck: true,
reputationCheckVerdict: verdict,
},
};
}
function promiseSubviewShown(shown) {
return new Promise(resolve => {
- if (shown == DownloadsBlockedSubview.view.showingSubView) {
+ if (shown == DownloadsBlockedSubview.view.showingSubView &&
+ !DownloadsBlockedSubview.view._transitioning) {
+ info("promiseSubviewShown: already showing");
resolve();
return;
}
- let event = shown ? "ViewShowing" : "ViewHiding";
- let subview = DownloadsBlockedSubview.subview;
- subview.addEventListener(event, function showing() {
- subview.removeEventListener(event, showing);
- resolve();
- });
+ let subviews = DownloadsBlockedSubview.view._subViews;
+ let onTransition = event => {
+ info("promiseSubviewShown: transitionend observed," +
+ " target=" + event.target +
+ " target.className=" + event.target.className);
+ if (event.target == subviews) {
+ info("promiseSubviewShown: got transitionend");
+ subviews.removeEventListener("transitionend", onTransition);
+ setTimeout(resolve, 0);
+ }
+ };
+ subviews.addEventListener("transitionend", onTransition);
+ info("promiseSubviewShown: waiting on transitionend");
});
}