Bug 1680865 - Unfocusing Urlbar after any touchbar input. r=dao

Differential Revision: https://phabricator.services.mozilla.com/D174755
This commit is contained in:
mseibert 2023-04-06 12:37:54 +00:00
parent 079f16abde
commit f57e4a82a4
3 changed files with 53 additions and 4 deletions

View file

@ -85,19 +85,28 @@ var gBuiltInInputs = {
title: "back",
image: "chrome://browser/skin/back.svg",
type: kInputTypes.BUTTON,
callback: () => execCommand("Browser:Back"),
callback: () => {
lazy.touchBarHelper.unfocusUrlbar();
execCommand("Browser:Back");
},
},
Forward: {
title: "forward",
image: "chrome://browser/skin/forward.svg",
type: kInputTypes.BUTTON,
callback: () => execCommand("Browser:Forward"),
callback: () => {
lazy.touchBarHelper.unfocusUrlbar();
execCommand("Browser:Forward");
},
},
Reload: {
title: "reload",
image: "chrome://global/skin/icons/reload.svg",
type: kInputTypes.BUTTON,
callback: () => execCommand("Browser:Reload"),
callback: () => {
lazy.touchBarHelper.unfocusUrlbar();
execCommand("Browser:Reload");
},
},
Home: {
title: "home",
@ -153,7 +162,7 @@ var gBuiltInInputs = {
title: "open-location",
image: "chrome://global/skin/icons/search-glass.svg",
type: kInputTypes.MAIN_BUTTON,
callback: () => execCommand("Browser:OpenLocation"),
callback: () => lazy.touchBarHelper.toggleFocusUrlbar(),
},
// This is a special-case `type: kInputTypes.SCRUBBER` element.
// Scrubbers are not yet generally implemented.
@ -316,6 +325,21 @@ class TouchBarHelper {
return TouchBarHelper.window.gURLBar.focused;
}
toggleFocusUrlbar() {
if (this.isUrlbarFocused) {
this.unfocusUrlbar();
} else {
execCommand("Browser:OpenLocation");
}
}
unfocusUrlbar() {
if (!this.isUrlbarFocused) {
return;
}
TouchBarHelper.window.gURLBar.blur();
}
static get baseWindow() {
return TouchBarHelper.window
? TouchBarHelper.window.docShell.treeOwner.QueryInterface(

View file

@ -8,6 +8,7 @@ XPCOMUtils.defineLazyServiceGetter(
"@mozilla.org/widget/touchbarhelper;1",
"nsITouchBarHelper"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"TouchBarInput",
@ -119,6 +120,20 @@ add_task(async function updateMainButtonInFullscreen() {
);
});
add_task(async function toggleUrlbarFocusOnOpenLocation() {
Assert.equal(TouchBarHelper.isUrlbarFocused, false, "Urlbar is unfocused.");
TouchBarHelper.toggleFocusUrlbar();
Assert.equal(TouchBarHelper.isUrlbarFocused, true, "Urlbar is unfocused.");
TouchBarHelper.toggleFocusUrlbar();
});
add_task(async function unfocusUrlbar() {
window.gURLBar.focus();
Assert.equal(TouchBarHelper.isUrlbarFocused, true, "Urlbar is unfocused.");
TouchBarHelper.unfocusUrlbar();
Assert.equal(TouchBarHelper.isUrlbarFocused, false, "Urlbar is unfocused.");
});
function waitForFullScreenState(browser, state) {
info("inside waitforfullscreenstate");
return new Promise(resolve => {

View file

@ -29,6 +29,16 @@ interface nsITouchBarHelper : nsISupports
*/
readonly attribute boolean isUrlbarFocused;
/**
* Toggles Urlbar focus.
*/
void toggleFocusUrlbar();
/**
* Unfocuses the Urlbar.
*/
void unfocusUrlbar();
/**
* Returns all available Touch Bar Inputs in an nsIArray
* of nsITouchBarInput objects.