From 0733410a0c5af92e43c890c252e613b3cdf5b5ef Mon Sep 17 00:00:00 2001 From: Harry Twyford Date: Thu, 10 Oct 2019 13:51:26 +0000 Subject: [PATCH] Bug 1583535 - The Megabar should not expand when auto-focused after a panel is closed. r=dao Differential Revision: https://phabricator.services.mozilla.com/D48114 --HG-- extra : moz-landing-system : lando --- browser/components/urlbar/UrlbarInput.jsm | 2 ++ toolkit/content/widgets/panel.js | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/browser/components/urlbar/UrlbarInput.jsm b/browser/components/urlbar/UrlbarInput.jsm index 366e28995abe..6c6d2a3eb6c2 100644 --- a/browser/components/urlbar/UrlbarInput.jsm +++ b/browser/components/urlbar/UrlbarInput.jsm @@ -1801,6 +1801,8 @@ class UrlbarInput { // We handle mouse-based expansion events separately in _on_click. if (this._focusedViaMousedown) { this._focusedViaMousedown = false; + } else if (this.inputField.hasAttribute("refocused-by-panel")) { + this._maybeSelectAll(true); } else { this.startLayoutExtend(); } diff --git a/toolkit/content/widgets/panel.js b/toolkit/content/widgets/panel.js index 4af0accf5666..ee2470d6bee7 100644 --- a/toolkit/content/widgets/panel.js +++ b/toolkit/content/widgets/panel.js @@ -255,13 +255,17 @@ function doFocus() { // Focus was set on an element inside this panel, - // so we need to move it back to where it was previously + // so we need to move it back to where it was previously. + // Elements can use refocused-by-panel to change their focus behaviour + // when re-focused by a panel hiding. + prevFocus.setAttribute("refocused-by-panel", true); try { let fm = Services.focus; fm.setFocus(prevFocus, fm.FLAG_NOSCROLL); } catch (e) { prevFocus.focus(); } + prevFocus.removeAttribute("refocused-by-panel"); } var currentFocus = this._currentFocus; var prevFocus = this._prevFocus ? this._prevFocus.get() : null;