Bug 1328740 - Focus popup notification panels on anchor icon keypress. r=florian
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 18 Jan 2017 23:12:35 +0100
changeset 375294 41914acaabea2783036faac564f4f22faacf2952
parent 375293 e685016e259743cdae7ce9f8c70a981b91e5955c
child 375295 7d3e3c0a23c64491856e905c5a43550895f0dfe7
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1328740
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1328740 - Focus popup notification panels on anchor icon keypress. r=florian MozReview-Commit-ID: 1s0RzGJGVCX
browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
toolkit/modules/PopupNotifications.jsm
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
@@ -45,9 +45,30 @@ var tests = [
     onHidden(popup) {
       ok(!this.notifyObj.mainActionClicked, "mainAction was not clicked");
       ok(!this.notifyObj.secondaryActionClicked, "secondaryAction was not clicked");
       ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
       ok(!this.notifyObj.removedCallbackTriggered, "removed callback was not triggered");
       this.notification.remove();
     }
   },
+  // Test that the space key on an anchor element focuses an active notification
+  { id: "Test#3",
+    *run() {
+      this.notifyObj = new BasicNotification(this.id);
+      this.notifyObj.anchorID = "geo-notification-icon";
+      this.notifyObj.addOptions({
+        persistent: true
+      });
+      this.notification = showNotification(this.notifyObj);
+    },
+    *onShown(popup) {
+      checkPopup(popup, this.notifyObj);
+      let anchor = document.getElementById(this.notifyObj.anchorID);
+      anchor.focus();
+      is(document.activeElement, anchor);
+      EventUtils.synthesizeKey(" ", {});
+      is(document.activeElement, popup.childNodes[0].button);
+      this.notification.remove();
+    },
+    onHidden(popup) { }
+  },
 ];
--- a/toolkit/modules/PopupNotifications.jsm
+++ b/toolkit/modules/PopupNotifications.jsm
@@ -1193,16 +1193,21 @@ PopupNotifications.prototype = {
     if (this.panel.state != "closed" && anchor != this._currentAnchorElement) {
       this._dismissOrRemoveCurrentNotifications();
     }
 
     // Ensure we move focus into the panel because it's opened through user interaction:
     this.panel.removeAttribute("noautofocus");
 
     this._reshowNotifications(anchor);
+
+    // If the user re-selects the current notification, focus it.
+    if (anchor == this._currentAnchorElement && this.panel.firstChild) {
+      this.panel.firstChild.button.focus();
+    }
   },
 
   _reshowNotifications: function PopupNotifications_reshowNotifications(anchor, browser) {
     // Mark notifications anchored to this anchor as un-dismissed
     browser = browser || this.tabbrowser.selectedBrowser;
     let notifications = this._getNotificationsForBrowser(browser);
     notifications.forEach(function(n) {
       if (n.anchorElement == anchor)