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:
tbogard%aol.net 2006-09-14 05:48:04 +00:00
Родитель c4931eee9f
Коммит 1c45370591
2 изменённых файлов: 82 добавлений и 80 удалений

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

@ -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"/>