more nsBrowserInstance lovin' - move the show/hide button junk into JavaScript using the now-working pref-change-observer system. bug 46200.

a=ben, r=jag
This commit is contained in:
alecf%netscape.com 2001-01-18 07:50:06 +00:00
Родитель da147fa26e
Коммит 82ba7c0aff
3 изменённых файлов: 52 добавлений и 112 удалений

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

@ -371,9 +371,43 @@ function UpdateBackForwardButtons()
forwardBroadcaster.setAttribute("disabled", !webNavigation.canGoForward);
}
function nsButtonPrefListener()
{
try {
pref.addObserver(this.domain, this);
} 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.removeAttribute("hidden");
else
button.setAttribute("hidden", "true");
}
}
function Startup()
{
window.XULBrowserWindow = new nsXULBrowserWindow();
window.buttonPrefListener = new nsButtonPrefListener();
var webNavigation;
try {
@ -490,6 +524,11 @@ function Shutdown()
} catch (ex) {
}
// unregister us as a pref listener
pref.removeObserver(window.buttonPrefListener.domain,
window.buttonPrefListener);
window.offlineObserver.unload();
// Close the app core.
if (appCore)
appCore.close();
@ -1020,18 +1059,20 @@ var consoleListener = {
function initConsoleListener()
{
/**
* XXX - console launch hookup requires some work that I'm not sure how to
* do.
* XXX - console launch hookup requires some work that I'm not sure
* how to do.
*
* 1) ideally, the notification would disappear when the document that had the
* error was flushed. how do I know when this happens? All the nsIScriptError
* object I get tells me is the URL. Where is it located in the content area?
* 2) the notification service should not display chrome script errors.
* web developers and users are not interested in the failings of our shitty,
* exception unsafe js. One could argue that this should also extend to
* the console by default (although toggle-able via setting for chrome authors)
* At any rate, no status indication should be given for chrome script
* errors.
* 1) ideally, the notification would disappear when the
* document that had the error was flushed. how do I know when
* this happens? All the nsIScriptError object I get tells me
* is the URL. Where is it located in the content area?
* 2) the notification service should not display chrome
* script errors. web developers and users are not interested
* in the failings of our shitty, exception unsafe js. One
* could argue that this should also extend to the console by
* default (although toggle-able via setting for chrome
* authors) At any rate, no status indication should be given
* for chrome script errors.
*
* As a result I am commenting out this for the moment.
*

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

@ -421,10 +421,7 @@ void TimesUp(nsITimer *aTimer, void *aClosure)
#endif //ENABLE_PAGE_CYCLER
PRUint32 nsBrowserInstance::gRefCnt = 0;
PRBool nsBrowserInstance::sCmdLineURLUsed = PR_FALSE;
int PR_CALLBACK ButtonShowHideCallback(const char* aPref, void* aClosure);
static const char kShowToolbarElts[] = "browser.toolbars.showbutton";
//*****************************************************************************
//*** nsBrowserInstance: Object Management
@ -437,29 +434,11 @@ nsBrowserInstance::nsBrowserInstance() : mIsClosed(PR_FALSE)
mDOMWindow = nsnull;
mContentAreaDocShellWeak = nsnull;
NS_INIT_REFCNT();
gRefCnt++;
if (gRefCnt == 1) {
nsresult rv;
// Add callback listeners for toolbar buttons showing/hiding.
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
prefs->RegisterCallback(kShowToolbarElts, ButtonShowHideCallback, nsnull);
}
}
}
nsBrowserInstance::~nsBrowserInstance()
{
Close();
gRefCnt--;
if (gRefCnt == 0) {
// Remove callback listeners for toolbar buttons showing/hiding.
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
prefs->UnregisterCallback(kShowToolbarElts, ButtonShowHideCallback, nsnull);
}
}
}
void
@ -1810,82 +1789,6 @@ static nsModuleComponentInfo components[] = {
NS_IMPL_NSGETMODULE("nsBrowserModule", components)
// =================================================================================
// Toolbar button pref callback
// =================================================================================
int PR_CALLBACK ButtonShowHideCallback(const char* aPref, void* aClosure)
{
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv))
return 0;
// There is an intelligent mapping from
// the name of the pref to the id of the element in the XUL.
//
// browser.toolbars.showbutton.XXX maps to
// an element with an ID of XXX-button. If the ID is of the
// correct form, then this code will scale tolerably
// as new buttons are added, and I won't need to have special
// "My Netscape" and "Net2Phone" cases in the Netscape tree (which
// would be non-ideal to say the least).
//
// hyatt
nsAutoString pref; pref.AssignWithConversion(aPref);
PRInt32 index = pref.RFindChar('.');
if (index == -1)
return 0;
nsAutoString element;
pref.Right(element, pref.Length()-index-1);
element += NS_LITERAL_STRING("-button");
PRBool show = PR_TRUE;
prefs->GetBoolPref(aPref, &show);
// Get the window mediator and loop over all navigator windows.
NS_WITH_SERVICE(nsIWindowMediator, windowMediator, kWindowMediatorCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
if (NS_SUCCEEDED(windowMediator->GetEnumerator(NS_LITERAL_STRING("navigator:browser").get(),
getter_AddRefs(windowEnumerator)))) {
// Get each dom window
PRBool more;
windowEnumerator->HasMoreElements(&more);
while (more) {
nsCOMPtr<nsISupports> protoWindow;
windowEnumerator->GetNext(getter_AddRefs(protoWindow));
if (protoWindow) {
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(protoWindow);
if (domWindow) {
nsCOMPtr<nsIDOMDocument> doc;
domWindow->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMElement> elt;
doc->GetElementById(element, getter_AddRefs(elt));
if (elt) {
if (show)
elt->SetAttribute(NS_LITERAL_STRING("hidden"), NS_LITERAL_STRING("false"));
else elt->SetAttribute(NS_LITERAL_STRING("hidden"), NS_LITERAL_STRING("true"));
// Modality issues with the (sigh) modal prefs dialog necessitate a synchronous
// reflow. Otherwise the reflow seems to get "lost".
// Do that here by flushing all pending reflows.
nsCOMPtr<nsIDocument> document(do_QueryInterface(doc));
document->FlushPendingNotifications();
}
}
}
windowEnumerator->HasMoreElements(&more);
}
}
}
return 0;
}
NS_IMETHODIMP
nsBrowserInstance::GetPostData( nsIInputStream **aResult ) {

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

@ -30,8 +30,6 @@
#include "nsIBrowserInstance.h"
#include "nsIURIContentListener.h"
#include "nsIAppShellComponentImpl.h"
#include "nscore.h"
@ -83,8 +81,6 @@ class nsBrowserInstance : public nsIBrowserInstance,
// WebProgress listener
NS_DECL_NSIWEBPROGRESSLISTENER
static PRUint32 gRefCnt;
protected:
nsresult GetContentAreaDocShell(nsIDocShell** outDocShell);