Bug 1477525 part 2 - Try hiding toolbox again when input in chrome loses the focus. r=dao
authorXidorn Quan <me@upsuper.org>
Tue, 02 Oct 2018 12:57:40 +0000
changeset 487519 cdedc6a6b40a397181b549fb3898a25cf1bb1ba3
parent 487518 1ecda91f00bfb6d8f65f3649843b91c0f1daf964
child 487520 17c314f6930d2b8d6e456aa9e9d41407a45c3008
child 487543 38327e5f0b70c835e117980b9c9cf0e00b4dd19a
push id246
push userfmarier@mozilla.com
push dateSat, 13 Oct 2018 00:15:40 +0000
reviewersdao
bugs1477525
milestone64.0a1
Bug 1477525 part 2 - Try hiding toolbox again when input in chrome loses the focus. r=dao MozReview-Commit-ID: LnwVXN4oS2Z Depends on D6750 Differential Revision: https://phabricator.services.mozilla.com/D6751
browser/base/content/browser-fullScreenAndPointerLock.js
--- a/browser/base/content/browser-fullScreenAndPointerLock.js
+++ b/browser/base/content/browser-fullScreenAndPointerLock.js
@@ -586,19 +586,35 @@ var FullScreen = {
       return;
     }
     // On OS X Lion we don't want to hide toolbars.
     if (this.useLionFullScreen) {
       return;
     }
 
     // a textbox in chrome is focused (location bar anyone?): don't collapse chrome
-    if (document.commandDispatcher.focusedElement &&
-        document.commandDispatcher.focusedElement.ownerDocument == document &&
-        document.commandDispatcher.focusedElement.localName == "input") {
+    let focused = document.commandDispatcher.focusedElement;
+    if (focused && focused.ownerDocument == document &&
+        focused.localName == "input") {
+      // But try collapse the chrome again when anything happens which can make
+      // it lose the focus. We cannot listen on "blur" event on focused here
+      // because that event can be triggered by "mousedown", and hiding chrome
+      // would cause the content to move. This combination may split a single
+      // click into two actionless halves.
+      let retryHideNavToolbox = () => {
+        // Wait for at least a frame to give it a chance to be passed down to
+        // the content.
+        requestAnimationFrame(() => {
+          setTimeout(() => this.hideNavToolbox(aAnimate), 0);
+        });
+        window.removeEventListener("keypress", retryHideNavToolbox);
+        window.removeEventListener("click", retryHideNavToolbox);
+      };
+      window.addEventListener("keypress", retryHideNavToolbox);
+      window.addEventListener("click", retryHideNavToolbox);
       return;
     }
 
     this._fullScrToggler.hidden = false;
 
     if (aAnimate && Services.prefs.getBoolPref("toolkit.cosmeticAnimations.enabled")) {
       gNavToolbox.setAttribute("fullscreenShouldAnimate", true);
       // Hide the fullscreen toggler until the transition ends.