Bug 599048 - Search results lose focus and search is closed on switch back to window with search results (window tab matching) r=tim

This commit is contained in:
Raymond Lee 2011-10-10 15:59:54 +08:00
Родитель b4bd992162
Коммит 46cc41fc07
3 изменённых файлов: 73 добавлений и 5 удалений

Просмотреть файл

@ -406,7 +406,7 @@ let TabHandlers = {
// A object that handles the search feature.
let Search = {
_initiatedBy: "",
_blockClick: false,
_currentHandler: null,
// ----------
@ -422,22 +422,32 @@ let Search = {
// and to have everything have the appropriate event handlers.
init: function Search_init() {
let self = this;
iQ("#search").hide();
iQ("#searchshade").hide().click(function(event) {
if (event.target.id != "searchbox")
iQ("#searchshade").hide().mousedown(function Search_init_shade_mousedown(event) {
if (event.target.id != "searchbox" && !self._blockClick)
self.hide();
});
iQ("#searchbox").keyup(function() {
iQ("#searchbox").keyup(function Search_init_box_keyup() {
self.perform();
});
iQ("#searchbutton").mousedown(function() {
iQ("#searchbutton").mousedown(function Search_init_button_mousedown() {
self._initiatedBy = "buttonclick";
self.ensureShown();
self.switchToInMode();
});
window.addEventListener("focus", function Search_init_window_focus() {
if (self.isEnabled()) {
self._blockClick = true;
setTimeout(function() {
self._blockClick = false;
}, 0);
}
}, false);
this.switchToBeforeMode();
},

Просмотреть файл

@ -78,6 +78,7 @@ _BROWSER_FILES = \
browser_tabview_bug597980.js \
browser_tabview_bug598375.js \
browser_tabview_bug598600.js \
browser_tabview_bug599048.js \
browser_tabview_bug599626.js \
browser_tabview_bug600645.js \
browser_tabview_bug600812.js \

Просмотреть файл

@ -0,0 +1,57 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
let cw;
function test() {
waitForExplicitFinish();
showTabView(function() {
cw = TabView.getContentWindow();
whenSearchIsEnabled(function() {
ok(cw.Search.isEnabled(), "The search is disabled");
// open a new window and it would have the focus
newWindowWithTabView(function(win) {
registerCleanupFunction(function() {
win.close();
hideTabView();
});
testClickOnSearchShade(win);
});
});
EventUtils.synthesizeKey("VK_SLASH", {}, cw);
});
}
function testClickOnSearchShade(win) {
// click on the window with search enabled.
let searchshade = cw.document.getElementById("searchshade");
EventUtils.sendMouseEvent({ type: "click" }, searchshade, cw);
waitForFocus(function() {
ok(cw.Search.isEnabled(), "The search is still enabled after the search shade is clicked");
testFocusInactiveWindow(win, cw);
});
}
function testFocusInactiveWindow(win) {
win.focus();
// focus inactive window
window.focus();
// need to use exeuteSoon as the _blockClick would be set to false after a setTimeout(,0)
executeSoon(function() {
ok(cw.Search.isEnabled(), "The search is still enabled when inactive window has focus");
whenSearchIsDisabled(function() {
hideTabView(finish);
});
let searchshade = cw.document.getElementById("searchshade");
EventUtils.synthesizeMouseAtCenter(searchshade, {}, cw);
});
}