Bug 181764 make page info appear faster

patch by db48x@yahoo.com r=caillon sr=jag
This commit is contained in:
timeless%mozdev.org 2003-01-16 21:46:08 +00:00
parent f038fc5fb4
commit 1ba34f0e36
2 changed files with 48 additions and 30 deletions

View File

@ -54,7 +54,6 @@ function pageInfoTreeView(columnids, copycol)
this.selection = null;
this.sortcol = null;
this.sortdir = 0;
this.initialized = 0; // set this to one once we fill in all the rows
}
pageInfoTreeView.prototype = {
@ -97,6 +96,7 @@ pageInfoTreeView.prototype = {
addRow: function(row)
{
this.rows = this.data.push(row);
this.rowCountChanged(this.rows - 1, 1);
},
addRows: function(rows)
@ -104,6 +104,7 @@ pageInfoTreeView.prototype = {
var length = rows.length;
for(var i = 0; i < length; i++)
this.rows = this.data.push(rows[i]);
this.rowCountChanged(this.rows - length, length);
},
rowCountChanged: function(index, count)
@ -179,6 +180,8 @@ var fieldView = new pageInfoTreeView(["field-label","field-field","field-type","
var linkView = new pageInfoTreeView(["link-name","link-address","link-type"], COPYCOL_LINK_ADDRESS);
var imageView = new pageInfoTreeView(["image-address","image-type","image-alt","image-node", "image-bg"], COPYCOL_IMAGE_ADDRESS);
var intervalID = null;
// localized strings (will be filled in when the document is loaded)
// this isn't all of them, these are just the ones that would otherwise have been loaded inside a loop
var gStrings = {}
@ -295,6 +298,9 @@ function onLoadPageInfo()
// do the easy stuff first
makeGeneralTab();
// and then the hard stuff
makeTabs(theDocument, theWindow);
/* Call registered overlay init functions */
for (x in onLoadRegistry)
{
@ -457,11 +463,13 @@ function makeGeneralTab()
}
//******** Generic Build-a-tab
// Assumes the views are empty. Only called once to build the tabs, and
// does so by farming the task off to another thread via setTimeout().
// The actual work is done with a TreeWalker that calls doGrab() once for
// each element node in the document.
function makeTabs(aDocument, aWindow)
{
if (formView.initialized || linkView.initialized || imageView.initialized)
return;
if (aWindow && aWindow.frames.length > 0)
{
var num = aWindow.frames.length;
@ -478,22 +486,33 @@ function makeTabs(aDocument, aWindow)
imageTree.treeBoxObject.view = imageView;
var iterator = aDocument.createTreeWalker(aDocument, NodeFilter.SHOW_ELEMENT, grabAll, true);
while (iterator.nextNode())
; // it'll never be executed anyway, since grabAll never
// accepts any nodes
formView.rowCountChanged(0, formView.rowCount);
formView.selection.select(0);
formView.initialized = 1;
var meter = document.getElementById("piProgress");
linkView.rowCountChanged(0, linkView.rowCount);
linkView.selection.select(0);
linkView.initialized = 1;
meter.setAttribute("value", 1);
imageView.rowCountChanged(0, imageView.rowCount);
imageView.selection.select(0);
imageView.initialized = 1;
setTimeout(doGrab, 1, iterator, meter, 0);
}
function doGrab(iterator, meter, i)
{
if (iterator.nextNode())
{
setTimeout(doGrab, 1, iterator, meter, i);
}
else
{
meter.setAttribute("value", 0);
meter.setAttribute("mode", "determined");
meter.setAttribute("hidden", "true");
document.getElementById("piSpacer").setAttribute("flex", 1);
}
}
function ensureSelection(view)
{
if (view.selection.count == 0) // only select something if nothing is currently selected
view.selection.select(0);
}
function grabAll(elem)
@ -506,7 +525,6 @@ function grabAll(elem)
imageView.addRow([url.getStringValue(), gStrings.mediaBGImg, gStrings.notSet, elem, true]);
// one swi^H^H^Hif-else to rule them all
// XXX: these tests should use regexes to be a little more lenient wrt whitespace, see bug 177047
if (elem instanceof nsIAnchorElement)
{
linktext = getValueText(elem);
@ -571,7 +589,7 @@ function grabAll(elem)
linkView.addRow([linktext, getAbsoluteURL(elem.href, elem), gStrings.linkX, ""]);
}
return NodeFilter.FILTER_SKIP;
return NodeFilter.FILTER_ACCEPT;
}
//******** Form Stuff

View File

@ -42,9 +42,8 @@
windowtype="Browser:page-info"
onload="onLoadPageInfo()"
align="stretch" class="dialog"
width="&pageInfoWindow.width;" height="&pageInfoWindow.height;"
screenX="10" screenY="10"
persist="screenX screenY width height sizemode">
persist="screenX screenY">
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaUtils.js"/>
<script type="application/x-javascript" src="chrome://navigator/content/pageInfo.js"/>
@ -65,11 +64,11 @@
<tab id="generalTab" label="&generalTab;"
accesskey="&generalAccesskey;"/>
<tab id="formsTab" label="&formsTab;"
accesskey="&formsAccesskey;" oncommand="makeTabs(theDocument, theWindow);"/>
accesskey="&formsAccesskey;" oncommand="ensureSelection(formView)"/>
<tab id="linksTab" label="&linksTab;"
accesskey="&linksAccesskey;" oncommand="makeTabs(theDocument, theWindow);"/>
accesskey="&linksAccesskey;" oncommand="ensureSelection(linkView)"/>
<tab id="mediaTab" label="&mediaTab;"
accesskey="&mediaAccesskey;" oncommand="makeTabs(theDocument, theWindow);"/>
accesskey="&mediaAccesskey;" oncommand="ensureSelection(imageView)"/>
<!-- Others added by overlay -->
</tabs>
<tabpanels id="tabpanels" flex="1">
@ -139,7 +138,7 @@
</grid>
<separator class="thin"/>
<text id="metahead" class="header" value="&generalMeta;"/>
<tree id="metatree" flex="1" class="inset">
<tree id="metatree" flex="1">
<treecols>
<treecol persist="hidden width" flex="1" id="meta-name" label="&generalMetaName;"/>
<splitter class="tree-splitter"/>
@ -151,7 +150,7 @@
<!-- Form information -->
<vbox>
<tree id="formtree" class="inset fixedsize" onselect="onFormSelect();">
<tree id="formtree" class="fixedsize" onselect="onFormSelect();">
<treecols>
<splitter class="tree-splitter"/>
<treecol sortSeparators="true" persist="hidden width" flex="1"
@ -188,7 +187,7 @@
</rows>
</grid>
<text class="header" value="&formFields;"/>
<tree id="formpreview" flex="1" class="inset">
<tree id="formpreview" flex="1">
<treecols>
<treecol sortSeparators="true" persist="hidden width" flex="3"
width="3" id="field-label" label="&formLabel;"/>
@ -209,7 +208,7 @@
<!-- Link info -->
<vbox>
<tree id="linktree" flex="1" class="inset" ondraggesture="onBeginLinkDrag(event,'link-address','link-name')">
<tree id="linktree" flex="1" ondraggesture="onBeginLinkDrag(event,'link-address','link-name')">
<treecols>
<treecol sortSeparators="true" persist="hidden width" flex="5"
width="5" id="link-name" label="&linkName;"/>
@ -229,7 +228,7 @@
<!-- Media information -->
<vbox>
<tree id="imagetree" class="inset fixedsize" onselect="onImageSelect();" ondraggesture="onBeginLinkDrag(event,'image-address','image-alt')">
<tree id="imagetree" class="fixedsize" onselect="onImageSelect();" ondraggesture="onBeginLinkDrag(event,'image-address','image-alt')">
<treecols>
<treecol sortSeparators="true" persist="hidden width" flex="10"
width="10" id="image-address" label="&mediaAddress;"/>
@ -316,7 +315,8 @@
</tabpanels>
</tabbox>
<box>
<spacer flex="1"/>
<progressmeter mode="undetermined" id="piProgress" flex="1"/>
<spacer id="piSpacer" flex="0"/>
<button label="&helpButton;" oncommand="doHelpButton();" />
</box>
</window>