Add a pref observer for the "hide tab bar with only one tab" pref. Bug

112699, patch by caillon@returnzero.com (Christopher Aillon),
r=bzbarsky, sr=jag, a=asa
This commit is contained in:
bzbarsky%mit.edu 2002-03-06 22:48:41 +00:00
Родитель 9f6fa2c683
Коммит f1c1c03e0a
2 изменённых файлов: 105 добавлений и 72 удалений

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

@ -64,6 +64,69 @@ var gBrowser = null;
var gFocusedURL = null;
var gFocusedDocument = null;
// Pref listener constants
const gButtonPrefListener =
{
domain: "browser.toolbars.showbutton",
observe: function(subject, topic, prefName)
{
// verify that we're changing a button pref
if (topic != "nsPref:changed")
return;
var buttonName = prefName.substr(this.domain.length+1);
var buttonId = buttonName + "-button";
var button = document.getElementById(buttonId);
var show = pref.getBoolPref(prefName);
button.hidden = !show;
// If all buttons before the separator are hidden, also hide the separator
var bookmarkSeparator = document.getElementById("home-bm-separator");
bookmarkSeparator.hidden = allLeftButtonsAreHidden();
}
};
const gTabStripPrefListener =
{
domain: "browser.tabs.autoHide",
observe: function(subject, topic, prefName)
{
// verify that we're changing the tab browser strip auto hide pref
if (topic != "nsPref:changed")
return;
var stripVisibility = !pref.getBoolPref(prefName);
if (gBrowser.mTabContainer.childNodes.length == 1)
gBrowser.setStripVisibilityTo(stripVisibility);
}
};
/**
* Pref listener handler functions.
* Both functions assume that observer.domain is set to
* the pref domain we want to start/stop listening to.
*/
function addPrefListener(observer)
{
try {
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.addObserver(observer.domain, observer, false);
} catch(ex) {
dump("Failed to observe prefs: " + ex + "\n");
}
}
function removePrefListener(observer)
{
try {
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.removeObserver(observer.domain, observer);
} catch(ex) {
dump("Failed to remove pref observer: " + ex + "\n");
}
}
/**
* We can avoid adding multiple load event listeners and save some time by adding
* one listener that calls all real handlers.
@ -207,46 +270,6 @@ function UpdateBackForwardButtons()
}
}
function nsButtonPrefListener()
{
try {
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.addObserver(this.domain, this, false);
} catch(ex) {
dump("Failed to observe prefs: " + ex + "\n");
}
}
// implements nsIObserver
nsButtonPrefListener.prototype =
{
domain: "browser.toolbars.showbutton",
observe: function(subject, topic, prefName)
{
// verify that we're changing a button pref
if (topic != "nsPref:changed") return;
if (prefName.substr(0, this.domain.length) != this.domain) return;
var buttonName = prefName.substr(this.domain.length+1);
var buttonId = buttonName + "-button";
var button = document.getElementById(buttonId);
var show = pref.getBoolPref(prefName);
if (show)
button.setAttribute("hidden","false");
else
button.setAttribute("hidden", "true");
// If all the buttons before the separator are hidden, also hide the
// separator
if(allLeftButtonsAreHidden())
document.getElementById("home-bm-separator").setAttribute("hidden", "true");
else
document.getElementById("home-bm-separator").removeAttribute("hidden");
}
}
// Function allLeftButtonsAreHidden
// Returns true if all the buttons left of the separator in the personal
// toolbar are hidden, false otherwise.
@ -306,7 +329,9 @@ function Startup()
// initialize observers and listeners
window.XULBrowserWindow = new nsBrowserStatusHandler();
window.buttonPrefListener = new nsButtonPrefListener();
addPrefListener(gButtonPrefListener);
addPrefListener(gTabStripPrefListener);
window.browserContentListener =
new nsBrowserContentListener(window, getBrowser());
@ -493,9 +518,8 @@ function Shutdown()
BrowserFlushBookmarksAndHistory();
// unregister us as a pref listener
var pbi = pref.QueryInterface(Components.interfaces.nsIPrefBranchInternal);
pbi.removeObserver(window.buttonPrefListener.domain,
window.buttonPrefListener);
removePrefListener(gButtonPrefListener);
removePrefListener(gTabStripPrefListener);
window.browserContentListener.close();
// Close the app core.

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

@ -515,6 +515,8 @@
document.getElementById("menu_closeWindow").hidden = false;
document.getElementById("menu_closeSeparator").hidden = false;
document.getElementById("menu_close").setAttribute("label", this.mStringBundle.getString("tabs.closeTab"));
if (!this.mTabbedMode)
this.enterTabbedMode();
}
else {
// XXXdwh temporary unclean dependency on specific menu items in navigator.xul
@ -532,41 +534,48 @@
</body>
</method>
<method name="enterTabbedMode">
<body>
<![CDATA[
this.mTabbedMode = true; // Welcome to multi-tabbed mode.
// Get the first tab all hooked up with a title listener.
this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, false);
if (this.mCurrentBrowser.contentDocument.title != "")
this.mCurrentTab.label = this.mCurrentBrowser.contentDocument.title;
// Hook up our favicon.
var uri = this.mCurrentBrowser.currentURI;
if (this.shouldLoadFavIcon(uri))
this.loadFavIcon(uri, "image", this.mCurrentTab);
// Remove all our progress listeners from the active browser.
if (this.mProgressListeners) {
for (var i = 0; i < this.mProgressListeners.length; i++) {
var p = this.mProgressListeners[i];
if (p)
this.mCurrentBrowser.webProgress.removeProgressListener(p);
}
}
// Wire up a progress listener to our tab.
var listener = (this.mTabProgressListener)(this, this.mCurrentTab, false);
this.webProgress.addProgressListener(listener);
this.mTabListeners[0] = listener;
]]>
</body>
</method>
<method name="addTab">
<parameter name="aURI"/>
<parameter name="aReferrerURI"/>
<body>
<![CDATA[
var blank = (aURI == "about:blank");
if (!this.mTabbedMode) {
this.mTabbedMode = true; // Welcome to multi-tabbed mode.
// Going from one tab to two for the first time. Get the first tab all hooked up with a title listener.
this.mCurrentBrowser.addEventListener("DOMTitleChanged", this.onTitleChanged, false);
if (this.mCurrentBrowser.contentDocument.title != "")
this.mCurrentTab.label = this.mCurrentBrowser.contentDocument.title;
// Hook up our favicon.
var uri = this.mCurrentBrowser.currentURI;
if (this.shouldLoadFavIcon(uri))
this.loadFavIcon(uri, "image", this.mCurrentTab);
// Remove all our progress listeners from the active browser.
if (this.mProgressListeners) {
for (var i = 0; i < this.mProgressListeners.length; i++) {
var p = this.mProgressListeners[i];
if (p)
this.mCurrentBrowser.webProgress.removeProgressListener(p);
}
}
// Wire up a progress listener to our tab.
var listener = (this.mTabProgressListener)(this, this.mCurrentTab, false);
this.webProgress.addProgressListener(listener);
this.mTabListeners[0] = listener;
}
if (!this.mTabbedMode)
this.enterTabbedMode();
var b = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
"browser");