Bug 949365 - [Australis] Ctrl-K/Cmd-K doesn't focus the search bar. r=Gijs

This commit is contained in:
Jared Wein 2013-12-12 15:12:01 -05:00
parent c6a78ca71c
commit 227079f6d3
2 changed files with 29 additions and 15 deletions

View File

@ -2936,27 +2936,29 @@ const BrowserSearch = {
let searchBar = this.searchBar;
let placement = CustomizableUI.getPlacementOfWidget("search-container");
let focusSearchBar = () => {
searchBar = this.searchBar;
searchBar.select();
openSearchPageIfFieldIsNotActive(searchBar);
};
if (placement && placement.area == CustomizableUI.AREA_PANEL) {
PanelUI.show().then(() => {
// The panel is not constructed until the first time it is shown.
searchBar = this.searchBar;
searchBar.select();
openSearchPageIfFieldIsNotActive(searchBar);
});
return;
} else if (placement.area == CustomizableUI.AREA_NAVBAR && searchBar &&
searchBar.parentNode.classList.contains("overflowedItem")) {
let navBar = document.getElementById(CustomizableUI.AREA_NAVBAR);
navBar.overflowable.show().then(() => {
// The searchBar gets moved when the overflow panel opens.
searchBar = this.searchBar;
searchBar.select();
openSearchPageIfFieldIsNotActive(searchBar);
focusSearchBar();
});
return;
}
if (searchBar && window.fullScreen) {
FullScreen.mouseoverToggle(true);
if (placement.area == CustomizableUI.AREA_NAVBAR && searchBar &&
searchBar.parentNode.classList.contains("overflowedItem")) {
let navBar = document.getElementById(CustomizableUI.AREA_NAVBAR);
navBar.overflowable.show().then(() => {
focusSearchBar();
});
return;
}
if (searchBar) {
if (window.fullScreen)
FullScreen.mouseoverToggle(true);
searchBar.select();
}
openSearchPageIfFieldIsNotActive(searchBar);

View File

@ -85,6 +85,18 @@ let gTests = [
ok(!navbar.hasAttribute("overflowing"), "Should not have an overflowing toolbar.");
}
},
{
desc: "Ctrl+K should focus the search bar if it is in the navbar and not overflowing.",
run: function() {
let searchbar = document.getElementById("searchbar");
let placement = CustomizableUI.getPlacementOfWidget("search-container");
is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in nav-bar");
sendWebSearchKeyCommand();
logActiveElement();
is(document.activeElement, searchbar.textbox.inputField, "The searchbar should be focused");
},
},
];
function test() {