зеркало из https://github.com/mozilla/pjs.git
Bug 565575 - Retain location bar focus when switching tabs. r=mano a=b
This commit is contained in:
Родитель
1f97ca78b6
Коммит
e0ef8342be
|
@ -832,31 +832,48 @@
|
|||
// Focus is suppressed in the event that the main browser window is minimized - focusing a tab would restore the window
|
||||
if (!this._previewMode) {
|
||||
// We've selected the new tab, so go ahead and notify listeners.
|
||||
var event = document.createEvent("Events");
|
||||
let event = document.createEvent("Events");
|
||||
event.initEvent("TabSelect", true, false);
|
||||
this.mCurrentTab.dispatchEvent(event);
|
||||
|
||||
this._tabAttrModified(oldTab);
|
||||
this._tabAttrModified(this.mCurrentTab);
|
||||
|
||||
// Change focus to the new browser unless the findbar is focused.
|
||||
if (!gFindBarInitialized ||
|
||||
gFindBar.hidden ||
|
||||
gFindBar.getElement("findbar-textbox").getAttribute("focused") != "true") {
|
||||
// Adjust focus
|
||||
do {
|
||||
// Focus the location bar if it was previously focused for that tab.
|
||||
// In full screen mode, only bother making the location bar visible
|
||||
// if the tab is a blank one.
|
||||
oldBrowser._urlbarFocused = (gURLBar && gURLBar.focused);
|
||||
if (newBrowser._urlbarFocused && gURLBar) {
|
||||
if (!window.fullScreen) {
|
||||
gURLBar.focus();
|
||||
break;
|
||||
} else if (isTabEmpty(this.mCurrentTab)) {
|
||||
focusAndSelectUrlBar();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var fm = Components.classes["@mozilla.org/focus-manager;1"].
|
||||
getService(Components.interfaces.nsIFocusManager);
|
||||
var newFocusedElement = fm.getFocusedElementForWindow(window.content, true, {});
|
||||
// If the find bar is focused, keep it focused.
|
||||
if (gFindBarInitialized &&
|
||||
!gFindBar.hidden &&
|
||||
gFindBar.getElement("findbar-textbox").getAttribute("focused") == "true")
|
||||
break;
|
||||
|
||||
// Otherwise, focus the content area.
|
||||
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
|
||||
let newFocusedElement = fm.getFocusedElementForWindow(window.content, true, {});
|
||||
|
||||
// for anchors, use FLAG_SHOWRING so that it is clear what link was
|
||||
// last clicked when switching back to that tab
|
||||
var focusFlags = fm.FLAG_NOSCROLL;
|
||||
let focusFlags = fm.FLAG_NOSCROLL;
|
||||
if (newFocusedElement &&
|
||||
(newFocusedElement instanceof HTMLAnchorElement ||
|
||||
newFocusedElement.getAttributeNS("http://www.w3.org/1999/xlink", "type") == "simple"))
|
||||
focusFlags |= fm.FLAG_SHOWRING;
|
||||
fm.setFocus(newBrowser, focusFlags);
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
]]>
|
||||
</body>
|
||||
|
|
|
@ -145,6 +145,7 @@ _BROWSER_FILES = \
|
|||
browser_bug561636.js \
|
||||
browser_bug562649.js \
|
||||
browser_bug563588.js \
|
||||
browser_bug565575.js \
|
||||
browser_bug575561.js \
|
||||
browser_bug577121.js \
|
||||
browser_bug579872.js \
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
function test() {
|
||||
gBrowser.selectedBrowser.focus();
|
||||
BrowserOpenTab();
|
||||
ok(gURLBar.focused, "location bar is focused for a new tab");
|
||||
|
||||
gBrowser.selectedTab = gBrowser.tabs[0];
|
||||
ok(!gURLBar.focused, "location bar isn't focused for the previously selected tab");
|
||||
|
||||
gBrowser.selectedTab = gBrowser.tabs[1];
|
||||
ok(gURLBar.focused, "location bar is re-focused when selecting the new tab");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
}
|
|
@ -44,11 +44,8 @@ function test() {
|
|||
browser2.contentWindow, null, true,
|
||||
"focusedElement after tab change, focus in new tab");
|
||||
|
||||
// switching tabs when the urlbar is focused and nothing in the new tab is focused
|
||||
// switching tabs when nothing in the new tab is focused
|
||||
// should focus the browser
|
||||
expectFocusShift(function () gURLBar.focus(),
|
||||
window, gURLBar.inputField, true,
|
||||
"url field focused");
|
||||
expectFocusShift(function () gBrowser.selectedTab = tab1,
|
||||
browser1.contentWindow, null, true,
|
||||
"focusedElement after tab change, focus in new tab");
|
||||
|
@ -89,6 +86,9 @@ function test() {
|
|||
window, gURLBar.inputField, true,
|
||||
"focusedWindow after url field focused");
|
||||
is(fm.getFocusedElementForWindow(browser2.contentWindow, false, {}), button2, "url field focused, button in tab");
|
||||
expectFocusShift(function () gURLBar.blur(),
|
||||
window, null, true,
|
||||
"focusedWindow after browser focused");
|
||||
|
||||
// when a chrome element is focused, switching tabs to a tab with a button
|
||||
// with the current focus should focus the button
|
||||
|
|
Загрузка…
Ссылка в новой задаче