Bug 1490358 - Hide menu popup when press the ctrl+t. r=birtles
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Tue, 16 Oct 2018 07:13:04 +0000
changeset 489779 d5cc1ab5bb162464e4be7593e6a71d330faf3b51
parent 489778 70daf386e9d36a170da95d59009ef953ccb6310f
child 489780 0d7e2a4ad36090bb5599afd91fe749fd85b1fa36
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbirtles
bugs1490358
milestone64.0a1
Bug 1490358 - Hide menu popup when press the ctrl+t. r=birtles If push the ctrl+t, browser will open the new tab. In this case, the XUL popup panel doesn't hide automatically(autohide=false). As the result of it, the popup menu will be displayed in the new tab content. So this patch will hide the popup when receiving the ctr+t shortcut in the MenuButton. Differential Revision: https://phabricator.services.mozilla.com/D8809
devtools/client/shared/components/menu/MenuButton.js
--- a/devtools/client/shared/components/menu/MenuButton.js
+++ b/devtools/client/shared/components/menu/MenuButton.js
@@ -10,16 +10,18 @@
 const Services = require("Services");
 const flags = require("devtools/shared/flags");
 const { createRef, PureComponent } = require("devtools/client/shared/vendor/react");
 const PropTypes = require("devtools/client/shared/vendor/react-prop-types");
 const dom = require("devtools/client/shared/vendor/react-dom-factories");
 const { button } = dom;
 const { HTMLTooltip } = require("devtools/client/shared/widgets/tooltip/HTMLTooltip");
 
+const isMacOS = Services.appinfo.OS === "Darwin";
+
 loader.lazyRequireGetter(this, "createPortal", "devtools/client/shared/vendor/react-dom", true);
 
 // Return a copy of |obj| minus |fields|.
 const omit = (obj, fields) => {
   const objCopy = { ...obj };
   for (const field of fields) {
     delete objCopy[field];
   }
@@ -341,16 +343,26 @@ class MenuButton extends PureComponent {
 
       case "ArrowUp":
         if (isButtonFocussed && this.tooltip) {
           if (this.tooltip.focusEnd()) {
             e.preventDefault();
           }
         }
         break;
+      case "t":
+        if (isMacOS && e.metaKey || !isMacOS && e.ctrlKey) {
+          // Close the menu if the user opens a new tab while it is still open.
+          //
+          // Bug 1499271: Once toolbox has been converted to XUL we should watch
+          // for the 'visibilitychange' event instead of explicitly looking for
+          // Ctrl+T.
+          this.hideMenu();
+        }
+        break;
     }
   }
 
   render() {
     const buttonProps = {
       // Pass through any props set on the button, except the ones we handle
       // here.
       ...omit(this.props, Object.keys(MenuButton.propTypes)),