Bug 566736 - Lazily initialize the findbar. r=gavin.

This commit is contained in:
Asaf Romano 2010-05-19 19:57:16 +03:00
parent a333ef25e4
commit e7a005e58c
4 changed files with 46 additions and 25 deletions

View File

@ -31,9 +31,8 @@
setOverLink: function (link, b) {
}
};
var gFindBar = {
hidden: true
};
gFindBarInitialized = false;
////////////////////////////////////////////////////////////////////////////
// Invoker implementation.

View File

@ -91,8 +91,7 @@ var gEditUIVisible = true;
["gBrowser", "content"],
["gNavToolbox", "navigator-toolbox"],
["gURLBar", "urlbar"],
["gNavigatorBundle", "bundle_browser"],
["gFindBar", "FindToolbar"]
["gNavigatorBundle", "bundle_browser"]
].forEach(function (elementGlobal) {
var [name, id] = elementGlobal;
window.__defineGetter__(name, function () {
@ -108,6 +107,24 @@ var gEditUIVisible = true;
});
});
// Smart getter for the findbar. If you don't wish to force the creation of
// the findbar, check gFindBarInitialized first.
var gFindBarInitialized = false;
XPCOMUtils.defineLazyGetter(window, "gFindBar", function() {
let XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
let findbar = document.createElementNS(XULNS, "findbar");
findbar.setAttribute("browserid", "content");
findbar.id = "FindToolbar";
let browserBottomBox = document.getElementById("browser-bottombox");
browserBottomBox.insertBefore(findbar, browserBottomBox.firstChild);
// Force a style flush to ensure that our binding is attached.
findbar.clientTop;
window.gFindBarInitialized = true;
return findbar;
});
__defineGetter__("gPrefService", function() {
delete this.gPrefService;
return this.gPrefService = Services.prefs;
@ -971,10 +988,13 @@ function BrowserStartup() {
}
if (window.opener && !window.opener.closed) {
let openerFindBar = window.opener.gFindBar;
if (openerFindBar && !openerFindBar.hidden &&
openerFindBar.findMode == gFindBar.FIND_NORMAL)
let openerFindBar = window.opener.gFindBarInitialized ?
window.opener.gFindBar : null;
if (openerFindBar &&
!openerFindBar.hidden &&
openerFindBar.findMode == openerFindBar.FIND_NORMAL) {
gFindBar.open();
}
let openerSidebarBox = window.opener.document.getElementById("sidebar-box");
// If the opener had a sidebar, open the same sidebar in our window.
@ -2598,8 +2618,9 @@ var PrintPreviewListener = {
this._chromeState.statusbarOpen = !statusbar.hidden;
statusbar.hidden = true;
this._chromeState.findOpen = !gFindBar.hidden;
gFindBar.close();
this._chromeState.findOpen = gFindBarInitialized && !gFindBar.hidden;
if (gFindBarInitialized)
gFindBar.close();
},
_showChrome: function () {
if (this._chromeState.notificationsOpen)
@ -4112,17 +4133,19 @@ var XULBrowserWindow = {
}
UpdateBackForwardCommands(gBrowser.webNavigation);
if (gFindBar.findMode != gFindBar.FIND_NORMAL) {
// Close the Find toolbar if we're in old-style TAF mode
gFindBar.close();
if (gFindBarInitialized) {
if (gFindBar.findMode != gFindBar.FIND_NORMAL) {
// Close the Find toolbar if we're in old-style TAF mode
gFindBar.close();
}
// XXXmano new-findbar, do something useful once it lands.
// Of course, this is especially wrong with bfcache on...
// fix bug 253793 - turn off highlight when page changes
gFindBar.getElement("highlight").checked = false;
}
// XXXmano new-findbar, do something useful once it lands.
// Of course, this is especially wrong with bfcache on...
// fix bug 253793 - turn off highlight when page changes
gFindBar.getElement("highlight").checked = false;
// See bug 358202, when tabs are switched during a drag operation,
// timers don't fire on windows (bug 203573)
if (aRequest)
@ -7255,7 +7278,7 @@ let gPrivateBrowsingUI = {
if (BrowserSearch.searchBar)
this._searchBarValue = BrowserSearch.searchBar.textbox.value;
if (gFindBar)
if (gFindBarInitialized)
this._findBarValue = gFindBar.getElement("findbar-textbox").value;
this._setPBMenuTitle("stop");
@ -7313,7 +7336,7 @@ let gPrivateBrowsingUI = {
// temporary fix until bug 463607 is fixed
document.getElementById("Tools:Sanitize").removeAttribute("disabled");
if (gFindBar) {
if (gFindBarInitialized) {
let findbox = gFindBar.getElement("findbar-textbox");
findbox.reset();
if (this._findBarValue) {
@ -7610,4 +7633,4 @@ var TabContextMenu = {
getService(Ci.nsISessionStore).
getClosedTabCount(window) == 0;
}
}
};

View File

@ -753,8 +753,6 @@
</hbox>
<vbox id="browser-bottombox">
<findbar browserid="content" id="FindToolbar"/>
<statusbar class="chromeclass-status" id="status-bar"
#ifdef WINCE
hidden="true"

View File

@ -904,7 +904,8 @@
this._tabAttrModified(this.mCurrentTab);
// Change focus to the new browser unless the findbar is focused.
if (gFindBar.hidden ||
if (!gFindBarInitialized ||
gFindBar.hidden ||
gFindBar.getElement("findbar-textbox").getAttribute("focused") != "true") {
var fm = Components.classes["@mozilla.org/focus-manager;1"].