Now when we want to tell the XUL Window of changes in progress, or status or overlink we use the new nsIDOMWindow::GetXPConnectObject functionality. This replaces our need for the broadcaster observer stuff along with the expensive setAttribute calls.

This commit is contained in:
tbogard%aol.net 2000-03-24 03:46:15 +00:00
Родитель c846d1162a
Коммит 6c7344e692
7 изменённых файлов: 110 добавлений и 69 удалений

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

@ -27,14 +27,15 @@
// Helper Classes
#include "nsIGenericFactory.h"
// Interfaces needed to be included
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMWindow.h"
#include "nsIDOMXULElement.h"
#include "nsIPrompt.h"
#include "nsIWindowMediator.h"
#include "nsIXULBrowserWindow.h"
// CIDs
static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
@ -193,29 +194,49 @@ NS_IMETHODIMP nsContentTreeOwner::GetNewWindow(PRInt32 aChromeFlags,
NS_IMETHODIMP nsContentTreeOwner::SetJSStatus(const PRUnichar* aStatus)
{
nsCOMPtr<nsIDOMElement> window;
mXULWindow->GetDOMElementById("WebBrowserChrome", getter_AddRefs(window));
if(window)
window->SetAttribute("status", aStatus);
nsCOMPtr<nsIDOMWindow> domWindow;
mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWindow));
if(!domWindow)
return NS_OK;
nsCOMPtr<nsISupports> xpConnectObj;
domWindow->GetXPConnectObject("XULBrowserWindow", getter_AddRefs(xpConnectObj));
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow(do_QueryInterface(xpConnectObj));
if(xulBrowserWindow)
xulBrowserWindow->SetStatus(aStatus);
return NS_OK;
}
NS_IMETHODIMP nsContentTreeOwner::SetJSDefaultStatus(const PRUnichar* aStatus)
{
nsCOMPtr<nsIDOMElement> window;
mXULWindow->GetDOMElementById("WebBrowserChrome", getter_AddRefs(window));
if(window)
window->SetAttribute("defaultStatus", aStatus);
nsCOMPtr<nsIDOMWindow> domWindow;
mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWindow));
if(!domWindow)
return NS_OK;
nsCOMPtr<nsISupports> xpConnectObj;
domWindow->GetXPConnectObject("XULBrowserWindow", getter_AddRefs(xpConnectObj));
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow(do_QueryInterface(xpConnectObj));
if(xulBrowserWindow)
xulBrowserWindow->SetDefaultStatus(aStatus);
return NS_OK;
}
NS_IMETHODIMP nsContentTreeOwner::SetOverLink(const PRUnichar* aLink)
{
nsCOMPtr<nsIDOMElement> window;
mXULWindow->GetDOMElementById("WebBrowserChrome", getter_AddRefs(window));
if(window)
window->SetAttribute("overLink", aLink);
nsCOMPtr<nsIDOMWindow> domWindow;
mXULWindow->GetWindowDOMWindow(getter_AddRefs(domWindow));
if(!domWindow)
return NS_OK;
nsCOMPtr<nsISupports> xpConnectObj;
domWindow->GetXPConnectObject("XULBrowserWindow", getter_AddRefs(xpConnectObj));
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow(do_QueryInterface(xpConnectObj));
if(xulBrowserWindow)
xulBrowserWindow->SetOverLink(aLink);
return NS_OK;
}

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

@ -392,6 +392,7 @@ NS_IMETHODIMP nsXULWindow::Destroy()
ExitModalLoop();
mWindow->Show(PR_FALSE);
mDOMWindow = nsnull;
if(mDocShell)
{
nsCOMPtr<nsIBaseWindow> shellAsWin(do_QueryInterface(mDocShell));
@ -858,6 +859,19 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetWindowDOMWindow(nsIDOMWindow** aDOMWindow)
{
NS_ENSURE_STATE(mDocShell);
if(!mDOMWindow)
mDOMWindow = do_GetInterface(mDocShell);
NS_ENSURE_TRUE(mDOMWindow, NS_ERROR_FAILURE);
*aDOMWindow = mDOMWindow;
NS_ADDREF(*aDOMWindow);
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetWindowDOMElement(nsIDOMElement** aDOMElement)
{
NS_ENSURE_STATE(mDocShell);

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

@ -37,6 +37,7 @@
#include "nsIBaseWindow.h"
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDOMWindow.h"
#include "nsIEventQueueService.h"
#include "nsIInterfaceRequestor.h"
#include "nsIWidget.h"
@ -71,6 +72,7 @@ protected:
NS_IMETHOD LoadTitleFromXUL();
NS_IMETHOD PersistPositionAndSize(PRBool aPosition, PRBool aSize, PRBool aSizeMode);
NS_IMETHOD GetWindowDOMWindow(nsIDOMWindow** aDOMWindow);
NS_IMETHOD GetWindowDOMElement(nsIDOMElement** aDOMElement);
NS_IMETHOD GetDOMElementById(char* aID, nsIDOMElement** aDOMElement);
NS_IMETHOD ContentShellAdded(nsIDocShellTreeItem* aContentShell,
@ -94,6 +96,7 @@ protected:
nsContentTreeOwner* mPrimaryContentTreeOwner;
nsCOMPtr<nsIWidget> mWindow;
nsCOMPtr<nsIDocShell> mDocShell;
nsCOMPtr<nsIDOMWindow> mDOMWindow;
nsCOMPtr<nsIWeakReference> mParentWindow;
nsVoidArray mContentShells;
PRBool mContinueModalLoop;

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

@ -42,8 +42,8 @@ catch (ex) {
var appCore = null;
var defaultStatus = bundle.GetStringFromName( "defaultStatus" );
var explicitURL = false;
var webBrowserChrome = null;
var statusTextFld = null;
var xulBrowserWin = null;
function UpdateHistory(event)
@ -149,8 +149,47 @@ function createBrowserInstance()
}
}
function Startup()
function nsXULBrowserWindow()
{
}
nsXULBrowserWindow.prototype =
{
QueryInterface : function(iid)
{
if(iid.equals(Components.interfaces.nsIXULBrowserWindow))
return this;
throw Components.results.NS_NOINTERFACE;
},
setStatus : function(status)
{
if(status == "")
status = defaultStatus;
if(!statusTextFld)
statusTextFld = document.getElementById("statusText");
statusTextFld.setAttribute("value", status);
},
setDefaultStatus : function(status)
{
//XXX Should do something here.
},
setOverLink : function(link)
{
if(link == "")
link = defaultStatus;
if(!statusTextFld)
statusTextFld = document.getElementById("statusText");
statusTextFld.setAttribute("value", link);
}
}
function Startup()
{
xulBrowserWin = new nsXULBrowserWindow();
window.addXPConnectObject("XULBrowserWindow", xulBrowserWin);
// TileWindow();
// Make sure window fits on screen initially
//FitToScreen();
@ -949,46 +988,6 @@ function BrowserEditBookmarks()
var bindCount = 0;
function onStatus() {
if(!webBrowserChrome)
webBrowserChrome = document.getElementById("WebBrowserChrome");
if ( webBrowserChrome ) {
var text = webBrowserChrome.getAttribute("status");
if ( text == "" ) {
//dump( "Setting default status text\n" );
text = defaultStatus;
}
if(!statusTextFld)
statusText = document.getElementById("statusText");
if ( statusText ) {
//dump( "Setting status text: " + text + "\n" );
statusText.setAttribute( "value", text );
} else {
//dump( "Missing statusText when setting status text: " + text + "\n" );
}
} else {
dump("Can't find status broadcaster!\n");
}
}
function onOverLink() {
if(!webBrowserChrome)
webBrowserChrome = document.getElementById("WebBrowserChrome");
var text = webBrowserChrome.getAttribute("overLink");
if(text == "")
text = defaultStatus;
if(!statusTextFld)
statusTextFld = document.getElementById("statusText");
statusTextFld = statusTextFld.setAttribute("value", text);
}
function onDefaultStatus() {
// XXX Probably should do something here
}
function doTests() {
}
@ -1010,14 +1009,11 @@ function BrowserEditBookmarks()
// Update status bar.
} else if ( busy == "false" && wasBusy == "true" ) {
// Record page loading time.
var webBrowserChrome = document.getElementById("WebBrowserChrome");
if ( webBrowserChrome ) {
var elapsed = ( (new Date()).getTime() - startTime ) / 1000;
var msg = bundle.GetStringFromName("nv_done") + " (" + elapsed + " secs)";
dump( msg + "\n" );
webBrowserChrome.setAttribute("status",msg);
defaultStatus = msg;
}
xulBrowserWin.setStatus(msg);
defaultStatus = msg;
// Turn progress meter off.
meter.setAttribute("mode","normal");
}

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

@ -64,7 +64,6 @@ Contributor(s): ______________________________________. -->
<broadcaster id="canStop"/>
<broadcaster id="canPrint"/>
<broadcaster id="Browser:LoadingProgress"/>
<broadcaster id="WebBrowserChrome"/>
<broadcaster id="Browser:Throbber" busy="false"/>
<broadcaster id="args" value=""/>
</broadcasterset>
@ -433,9 +432,6 @@ Contributor(s): ______________________________________. -->
<spring style="width: 1em"/>
<titledbutton id="statusText" class="status-bar" align="left" flex="100%"
value="&statusText.label;" style="min-width: 1px">
<observes element="WebBrowserChrome" attribute="status" onbroadcast="onStatus()"/>
<observes element="WebBrowserChrome" attribute="overLink" onbroadcast="onOverLink()"/>
<observes element="WebBrowserChrome" attribute="defaultStatus" onbroadcast="onDefaultStatus()"/>
</titledbutton>
<titledbutton class="status-bar" align="left" value="&buildId.label;"/>

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

@ -32,6 +32,7 @@
#include "nsIDocShell.h"
#include "nsIDocShellTreeItem.h"
#include "nsIWebNavigation.h"
#include "nsIXULBrowserWindow.h"
// Use this trick temporarily, to minimize delta to nsBrowserAppCore.cpp.
#define nsBrowserAppCore nsBrowserInstance
@ -188,6 +189,7 @@ nsBrowserAppCore::nsBrowserAppCore() : mIsClosed(PR_FALSE)
mContentScriptContext = nsnull;
mWebShellWin = nsnull;
mDocShell = nsnull;
mDOMWindow = nsnull;
mContentAreaWebShell = nsnull;
mContentAreaDocLoader = nsnull;
mSHistory = nsnull;
@ -1285,9 +1287,8 @@ nsBrowserAppCore::SetContentWindow(nsIDOMWindow* aWin)
NS_IMETHODIMP
nsBrowserAppCore::SetWebShellWindow(nsIDOMWindow* aWin)
{
NS_PRECONDITION(aWin != nsnull, "null ptr");
if (! aWin)
return NS_ERROR_NULL_POINTER;
NS_ENSURE_ARG(aWin);
mDOMWindow = aWin;
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
if (!globalObj) {
@ -1631,8 +1632,17 @@ NS_IMETHODIMP
nsBrowserAppCore::OnStatusURLLoad(nsIDocumentLoader* loader,
nsIChannel* channel, nsString& aMsg)
{
nsresult rv = setAttribute( mDocShell, "WebBrowserChrome", "status", aMsg );
return rv;
if(!mDOMWindow)
return NS_OK;
nsCOMPtr<nsISupports> xpConnectObj;
mDOMWindow->GetXPConnectObject("XULBrowserWindow", getter_AddRefs(xpConnectObj));
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow(do_QueryInterface(xpConnectObj));
if(xulBrowserWindow)
xulBrowserWindow->SetStatus(aMsg.GetUnicode());
return NS_OK;
}

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

@ -99,6 +99,7 @@ class nsBrowserInstance : public nsIBrowserInstance,
nsIWebShellWindow *mWebShellWin; // weak reference
nsIDocShell * mDocShell; // weak reference
nsIDOMWindow* mDOMWindow; // weak reference
nsIWebShell * mContentAreaWebShell; // weak reference
nsIDocumentLoader * mContentAreaDocLoader; // weak reference