зеркало из https://github.com/mozilla/gecko-dev.git
Changed the code to use the nsIXULBrowserWindow interface rather than poking attributes for setting throbber activity, window activity and location changing. This should speed things up a bit and also makes the code a bit cleaner.
This commit is contained in:
Родитель
e25164fdaa
Коммит
d05eb8f1ea
|
@ -50,5 +50,21 @@ interface nsIXULBrowserWindow : nsISupports
|
|||
Tells the browser window what to use for the default status text.
|
||||
*/
|
||||
void setDefaultStatus(in wstring status);
|
||||
|
||||
/*
|
||||
Tells the browser window if there is network activity or not.
|
||||
*/
|
||||
void setNetworkActive(in boolean active);
|
||||
|
||||
/*
|
||||
Tells the browser window that there is activity in the window.
|
||||
*/
|
||||
void setWindowActive(in boolean active);
|
||||
|
||||
/*
|
||||
Tells the browser window that the location of the window has changed.
|
||||
*/
|
||||
void onLocationChange(in wstring location);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@ interface nsIBrowserInstance : nsISupports {
|
|||
// History.
|
||||
void back();
|
||||
void forward();
|
||||
readonly attribute boolean canGoBack;
|
||||
readonly attribute boolean canGoForward;
|
||||
|
||||
void reload(in PRUint32 reloadType);
|
||||
void stop();
|
||||
void loadUrl(in wstring url);
|
||||
|
|
|
@ -50,5 +50,21 @@ interface nsIXULBrowserWindow : nsISupports
|
|||
Tells the browser window what to use for the default status text.
|
||||
*/
|
||||
void setDefaultStatus(in wstring status);
|
||||
|
||||
/*
|
||||
Tells the browser window if there is network activity or not.
|
||||
*/
|
||||
void setNetworkActive(in boolean active);
|
||||
|
||||
/*
|
||||
Tells the browser window that there is activity in the window.
|
||||
*/
|
||||
void setWindowActive(in boolean active);
|
||||
|
||||
/*
|
||||
Tells the browser window that the location of the window has changed.
|
||||
*/
|
||||
void onLocationChange(in wstring location);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -40,14 +40,24 @@ catch (ex) {
|
|||
}
|
||||
|
||||
var appCore = null;
|
||||
var explicitURL = false;
|
||||
var textZoom = 1.0;
|
||||
|
||||
// Stored Status, Link and Loading values
|
||||
var defaultStatus = bundle.GetStringFromName( "defaultStatus" );
|
||||
var jsStatus = null;
|
||||
var jsDefaultStatus = null;
|
||||
var overLink = null;
|
||||
var explicitURL = false;
|
||||
var statusTextFld = null;
|
||||
var textZoom = 1.0;
|
||||
var startTime = 0;
|
||||
|
||||
//cached elements/ fields
|
||||
var statusTextFld = null;
|
||||
var throbberElement = null;
|
||||
var stopButton = null;
|
||||
var stopMenu = null;
|
||||
var locationFld = null;
|
||||
var backButton = null;
|
||||
var forwardButton = null;
|
||||
|
||||
function UpdateHistory(event)
|
||||
{
|
||||
|
@ -212,9 +222,70 @@ nsXULBrowserWindow.prototype =
|
|||
else
|
||||
overLink = link;
|
||||
UpdateStatusField();
|
||||
},
|
||||
setNetworkActive : function(active)
|
||||
{
|
||||
if(!throbberElement)
|
||||
throbberElement = document.getElementById("Throbber");
|
||||
throbberElement.setAttribute("busy", active);
|
||||
|
||||
var meter = document.getElementById("statusbar-icon");
|
||||
if(active) // starting network activity
|
||||
{
|
||||
// Remember when loading commenced.
|
||||
startTime = (new Date()).getTime();
|
||||
// Turn progress meter on.
|
||||
meter.setAttribute("mode","undetermined");
|
||||
}
|
||||
else // network activity finished
|
||||
{
|
||||
// Record page loading time.
|
||||
var elapsed = ( (new Date()).getTime() - startTime ) / 1000;
|
||||
var msg = bundle.GetStringFromName("nv_done") + " (" + elapsed + " secs)";
|
||||
dump( msg + "\n" );
|
||||
defaultStatus = msg;
|
||||
UpdateStatusField();
|
||||
window.XULBrowserWindow.setDefaultStatus(msg);
|
||||
// Turn progress meter off.
|
||||
meter.setAttribute("mode","normal");
|
||||
}
|
||||
},
|
||||
setWindowActive : function(active)
|
||||
{
|
||||
if(!stopButton)
|
||||
stopButton = document.getElementById("stop-button");
|
||||
|
||||
if(!stopMenu)
|
||||
stopMenu = document.getElementById("menuitem-stop");
|
||||
|
||||
stopButton.setAttribute("disabled", !active);
|
||||
stopMenu.setAttribute("disabled", !active);
|
||||
},
|
||||
onLocationChange : function(location)
|
||||
{
|
||||
if(!locationFld)
|
||||
locationFld = document.getElementById("urlbar");
|
||||
|
||||
// We should probably not do this if the value has changed since the user
|
||||
// searched
|
||||
locationFld.setAttribute("value", location);
|
||||
|
||||
UpdateBackForwardButtons();
|
||||
}
|
||||
}
|
||||
|
||||
function UpdateBackForwardButtons()
|
||||
{
|
||||
if(!backButton)
|
||||
backButton = document.getElementById("canGoBack");
|
||||
if(!forwardButton)
|
||||
forwardButton = document.getElementById("canGoForward");
|
||||
|
||||
backButton.setAttribute("disabled", !appCore.canGoBack);
|
||||
forwardButton.setAttribute("disabled", !appCore.canGoForward);
|
||||
dump("XXX CanGoForward = " + appCore.canGoForward + "\r\n");
|
||||
}
|
||||
|
||||
function Startup()
|
||||
{
|
||||
window.XULBrowserWindow = new nsXULBrowserWindow();
|
||||
|
@ -282,7 +353,7 @@ function Shutdown()
|
|||
|
||||
function onLoadViaOpenDialog() {
|
||||
// See if load in progress (loading default page).
|
||||
if ( document.getElementById("Browser:Throbber").getAttribute("busy") == "true" ) {
|
||||
if ( document.getElementById("Throbber").getAttribute("busy") == "true" ) {
|
||||
dump( "Stopping load of default initial page\n" );
|
||||
appCore.stop();
|
||||
}
|
||||
|
@ -390,30 +461,6 @@ function Shutdown()
|
|||
|
||||
|
||||
|
||||
function BrowserCanStop() {
|
||||
var stop = document.getElementById("canStop");
|
||||
if ( stop ) {
|
||||
var stopDisabled = stop.getAttribute("disabled");
|
||||
var stopButton = document.getElementById( "stop-button" );
|
||||
if ( stopButton ) {
|
||||
if ( stopDisabled == "true") {
|
||||
stopButton.setAttribute( "disabled", "true" );
|
||||
} else {
|
||||
stopButton.setAttribute( "disabled", "" );
|
||||
}
|
||||
}
|
||||
//Enable/disable the stop menu item
|
||||
var stopMenu = document.getElementById( "menuitem-stop" );
|
||||
if ( stopMenu ) {
|
||||
if ( stopDisabled == "true") {
|
||||
stopMenu.setAttribute( "disabled", "true" );
|
||||
} else {
|
||||
stopMenu.setAttribute( "disabled", "" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function BrowserStop() {
|
||||
// Get a handle to the "canStop" broadcast id
|
||||
var stopBElem = document.getElementById("canStop");
|
||||
|
@ -1048,45 +1095,11 @@ function BrowserEditBookmarks()
|
|||
}
|
||||
|
||||
|
||||
var bindCount = 0;
|
||||
|
||||
function doTests() {
|
||||
}
|
||||
|
||||
var startTime = 0;
|
||||
function onProgress() {
|
||||
var throbber = document.getElementById("Browser:Throbber");
|
||||
var meter = document.getElementById("Browser:LoadingProgress");
|
||||
if ( throbber && meter ) {
|
||||
var busy = throbber.getAttribute("busy");
|
||||
var wasBusy = meter.getAttribute("mode") == "undetermined" ? "true" : "false";
|
||||
if ( busy == "true" ) {
|
||||
if ( wasBusy == "false" ) {
|
||||
// Remember when loading commenced.
|
||||
startTime = (new Date()).getTime();
|
||||
// Turn progress meter on.
|
||||
meter.setAttribute("mode","undetermined");
|
||||
}
|
||||
// Update status bar.
|
||||
} else if ( busy == "false" && wasBusy == "true" ) {
|
||||
// Record page loading time.
|
||||
var elapsed = ( (new Date()).getTime() - startTime ) / 1000;
|
||||
var msg = bundle.GetStringFromName("nv_done") + " (" + elapsed + " secs)";
|
||||
dump( msg + "\n" );
|
||||
defaultStatus = msg;
|
||||
UpdateStatusField();
|
||||
window.XULBrowserWindow.setDefaultStatus(msg);
|
||||
// Turn progress meter off.
|
||||
meter.setAttribute("mode","normal");
|
||||
}
|
||||
}
|
||||
}
|
||||
function dumpProgress() {
|
||||
var broadcaster = document.getElementById("Browser:LoadingProgress");
|
||||
var meter = document.getElementById("meter");
|
||||
dump( "bindCount=" + bindCount + "\n" );
|
||||
dump( "broadcaster mode=" + broadcaster.getAttribute("mode") + "\n" );
|
||||
dump( "broadcaster value=" + broadcaster.getAttribute("value") + "\n" );
|
||||
var meter = document.getElementById("statusbar-icon");
|
||||
dump( "meter mode=" + meter.getAttribute("mode") + "\n" );
|
||||
dump( "meter value=" + meter.getAttribute("value") + "\n" );
|
||||
}
|
||||
|
|
|
@ -61,10 +61,7 @@ Contributor(s): ______________________________________. -->
|
|||
<!-- broadcasters are appended from the overlay -->
|
||||
<broadcasterset id="broadcasterset">
|
||||
<broadcaster id="canReload" oncommand="BrowserReallyReload(0);"/>
|
||||
<broadcaster id="canStop"/>
|
||||
<broadcaster id="canPrint"/>
|
||||
<broadcaster id="Browser:LoadingProgress"/>
|
||||
<broadcaster id="Browser:Throbber" busy="false"/>
|
||||
<broadcaster id="args" value=""/>
|
||||
</broadcasterset>
|
||||
|
||||
|
@ -334,12 +331,10 @@ Contributor(s): ______________________________________. -->
|
|||
|
||||
<toolbar id="nav-bar" class="decorated main-bar" chromeclass="toolbar" persist="collapsed">
|
||||
<box align="horizontal" flex="100%" style="overflow: hidden">
|
||||
<button class="large-toolbar left" id="back-button" crop="right" orient="vertical" observes="canGoBack" />
|
||||
<button class="large-toolbar left" id="forward-button" crop="right" orient="vertical" observes="canGoForward" />
|
||||
<button class="large-toolbar left" id="reload-button" crop="right" orient="vertical" observes="canReload"/>
|
||||
<button class="large-toolbar left" id="stop-button" crop="right" orient="vertical" onclick="BrowserStop()">
|
||||
<observes element="canStop" attribute="disabled" onbroadcast="BrowserCanStop()"/>
|
||||
</button>
|
||||
<button class="large-toolbar left" id="back-button" crop="right" orient="vertical" observes="canGoBack"/>
|
||||
<button class="large-toolbar left" id="forward-button" crop="right" orient="vertical" observes="canGoForward"/>
|
||||
<button class="large-toolbar left" id="reload-button" crop="right" orient="vertical" observes="canReload" />
|
||||
<button class="large-toolbar left" id="stop-button" crop="right" orient="vertical" onclick="BrowserStop()"/>
|
||||
|
||||
<!-- changed : the url field is now grouped with search -->
|
||||
<box align="vertical" flex="100%">
|
||||
|
@ -399,9 +394,7 @@ Contributor(s): ______________________________________. -->
|
|||
|
||||
<!-- throbber area of navigation toolbar -->
|
||||
<box id="toolbar_throbber_box" align="vertical">
|
||||
<titledbutton id="Throbber" onclick='goClickThrobber("browser.throbber.url")'>
|
||||
<observes element="Browser:Throbber" attribute="busy"/>
|
||||
</titledbutton>
|
||||
<titledbutton id="Throbber" onclick='goClickThrobber("browser.throbber.url")'/>
|
||||
</box>
|
||||
</toolbar>
|
||||
|
||||
|
@ -430,11 +423,7 @@ Contributor(s): ______________________________________. -->
|
|||
<box align="vertical" style="width:100px">
|
||||
<spring flex="100%"/>
|
||||
<progressmeter id="statusbar-icon" mode="normal"
|
||||
align="horizontal" value="0" onclick="dumpProgress()">
|
||||
<observes element="Browser:LoadingProgress" attribute="mode"/>
|
||||
<observes element="Browser:Throbber" attribute="busy"
|
||||
onbroadcast="onProgress()"/>
|
||||
</progressmeter>
|
||||
align="horizontal" value="0" onclick="dumpProgress()"/>
|
||||
<spring flex="100%"/>
|
||||
</box>
|
||||
<spring style="width: 1em"/>
|
||||
|
|
|
@ -329,7 +329,17 @@ nsBrowserAppCore::Forward()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::GetCanGoBack(PRBool* aCan)
|
||||
{
|
||||
return CanGoBack(aCan);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::GetCanGoForward(PRBool* aCan)
|
||||
{
|
||||
return CanGoForward(aCan);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::Stop()
|
||||
|
@ -341,10 +351,12 @@ nsBrowserAppCore::Stop()
|
|||
if (mIsLoadingHistory) {
|
||||
SetLoadingFlag(PR_FALSE);
|
||||
}
|
||||
nsAutoString v( "false" );
|
||||
|
||||
EnsureXULBrowserWindow();
|
||||
if(mXULBrowserWindow)
|
||||
mXULBrowserWindow->SetNetworkActive(PR_FALSE);
|
||||
// XXX: The throbber should be turned off when the OnStopDocumentLoad
|
||||
// notification is received
|
||||
setAttribute( mDocShell, "Browser:Throbber", "busy", v );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -787,6 +799,25 @@ nsBrowserAppCore::ClearHistoryPopup(nsIDOMNode * aParent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::EnsureXULBrowserWindow()
|
||||
{
|
||||
if(mXULBrowserWindow)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> piDOMWindow(do_QueryInterface(mDOMWindow));
|
||||
NS_ENSURE_TRUE(piDOMWindow, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
nsAutoString xulBrowserWinId("XULBrowserWindow");
|
||||
piDOMWindow->GetObjectProperty(xulBrowserWinId.GetUnicode(), getter_AddRefs(xpConnectObj));
|
||||
mXULBrowserWindow = do_QueryInterface(xpConnectObj);
|
||||
|
||||
if(mXULBrowserWindow)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBrowserAppCore::WalletPreview(nsIDOMWindow* aWin, nsIDOMWindow* aForm)
|
||||
|
@ -1467,6 +1498,8 @@ nsBrowserAppCore::OnStartDocumentLoad(nsIDocumentLoader* aLoader, nsIURI* aURL,
|
|||
}
|
||||
}
|
||||
|
||||
EnsureXULBrowserWindow();
|
||||
|
||||
if (!isFrame) {
|
||||
nsAutoString kStartDocumentLoad("StartDocumentLoad");
|
||||
rv = observer->Notify(mContentWindow,
|
||||
|
@ -1476,31 +1509,24 @@ nsBrowserAppCore::OnStartDocumentLoad(nsIDocumentLoader* aLoader, nsIURI* aURL,
|
|||
// XXX Ignore rv for now. They are using nsIEnumerator instead of
|
||||
// nsISimpleEnumerator.
|
||||
// set the url string in the urlbar only for toplevel pages, not for frames
|
||||
setAttribute( mDocShell, "urlbar", "value", url);
|
||||
if(mXULBrowserWindow)
|
||||
{
|
||||
nsAutoString uriString(url);
|
||||
mXULBrowserWindow->OnLocationChange(uriString.GetUnicode());
|
||||
}
|
||||
}
|
||||
|
||||
if(mXULBrowserWindow)
|
||||
{
|
||||
mXULBrowserWindow->SetNetworkActive(PR_TRUE);
|
||||
mXULBrowserWindow->SetWindowActive(PR_TRUE);
|
||||
}
|
||||
|
||||
// Kick start the throbber
|
||||
nsAutoString trueStr("true");
|
||||
nsAutoString emptyStr;
|
||||
setAttribute( mDocShell, "Browser:Throbber", "busy", trueStr );
|
||||
|
||||
// Enable the Stop buton
|
||||
setAttribute( mDocShell, "canStop", "disabled", emptyStr );
|
||||
|
||||
//Disable the reload button
|
||||
setAttribute(mDocShell, "canReload", "disabled", trueStr);
|
||||
|
||||
PRBool result=PR_TRUE;
|
||||
// Check with sessionHistory if you can go forward
|
||||
CanGoForward(&result);
|
||||
setAttribute(mDocShell, "canGoForward", "disabled", (result == PR_TRUE) ? "" : "true");
|
||||
|
||||
|
||||
// Check with sessionHistory if you can go back
|
||||
CanGoBack(&result);
|
||||
setAttribute(mDocShell, "canGoBack", "disabled", (result == PR_TRUE) ? "" : "true");
|
||||
|
||||
|
||||
nsCRT::free(url);
|
||||
|
||||
|
@ -1620,13 +1646,13 @@ nsBrowserAppCore::OnEndDocumentLoad(nsIDocumentLoader* aLoader, nsIChannel* chan
|
|||
nsCRT::free(urls);
|
||||
#endif
|
||||
|
||||
setAttribute( mDocShell, "Browser:Throbber", "busy", "false" );
|
||||
EnsureXULBrowserWindow();
|
||||
|
||||
//Disable the Stop button
|
||||
setAttribute( mDocShell, "canStop", "disabled", "true" );
|
||||
|
||||
//Enable the reload button
|
||||
setAttribute(mDocShell, "canReload", "disabled", "");
|
||||
if(mXULBrowserWindow)
|
||||
{
|
||||
mXULBrowserWindow->SetNetworkActive(PR_FALSE);
|
||||
mXULBrowserWindow->SetWindowActive(PR_FALSE);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1658,17 +1684,11 @@ NS_IMETHODIMP
|
|||
nsBrowserAppCore::OnStatusURLLoad(nsIDocumentLoader* loader,
|
||||
nsIChannel* channel, nsString& aMsg)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> piDOMWindow(do_QueryInterface(mDOMWindow));
|
||||
if(!piDOMWindow)
|
||||
EnsureXULBrowserWindow();
|
||||
if(!mXULBrowserWindow)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
nsAutoString xulBrowserWinId("XULBrowserWindow");
|
||||
piDOMWindow->GetObjectProperty(xulBrowserWinId.GetUnicode(), getter_AddRefs(xpConnectObj));
|
||||
nsCOMPtr<nsIXULBrowserWindow> xulBrowserWindow(do_QueryInterface(xpConnectObj));
|
||||
|
||||
if(xulBrowserWindow)
|
||||
xulBrowserWindow->SetDefaultStatus(aMsg.GetUnicode());
|
||||
mXULBrowserWindow->SetDefaultStatus(aMsg.GetUnicode());
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "nsISessionHistory.h"
|
||||
#include "nsIURIContentListener.h"
|
||||
#include "nsICmdLineHandler.h"
|
||||
#include "nsIXULBrowserWindow.h"
|
||||
|
||||
#ifdef DEBUG_radha
|
||||
#include "nsISHistory.h"
|
||||
|
@ -87,9 +88,12 @@ class nsBrowserInstance : public nsIBrowserInstance,
|
|||
NS_IMETHOD CreateMenuItem(nsIDOMNode * , PRInt32,const PRUnichar * );
|
||||
NS_IMETHOD UpdateGoMenu();
|
||||
NS_IMETHOD ClearHistoryPopup(nsIDOMNode * );
|
||||
NS_IMETHOD EnsureXULBrowserWindow();
|
||||
|
||||
PRBool mIsClosed;
|
||||
|
||||
nsCOMPtr<nsIXULBrowserWindow> mXULBrowserWindow;
|
||||
|
||||
nsIScriptContext *mToolbarScriptContext; // weak reference
|
||||
nsIScriptContext *mContentScriptContext; // weak reference
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче