shuffling navigator code around

This commit is contained in:
ben%netscape.com 2006-09-14 05:50:13 +00:00
Родитель 81bbbcff95
Коммит 1b66251181
3 изменённых файлов: 164 добавлений и 337 удалений

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

@ -42,7 +42,6 @@ catch (ex)
}
var appCore = null;
var maxHistoryMenuItems=15;
var explicitURL = false;
var textZoom = 1.0;
@ -369,6 +368,7 @@ function Startup()
// Load it using yet another psuedo-onload handler.
onLoadViaOpenDialog();
}
gURLBar = document.getElementById("urlbar");
}
function Shutdown()
@ -473,369 +473,68 @@ function Shutdown()
document.getElementById('urlbar').value = window.content.location.href;
}
function gotoHistoryIndex(event)
function gotoHistoryIndex( aEvent )
{
dump("In gotoHistoryIndex\n");
var index = event.target.getAttribute("index");
if (index) {
dump("gotoHistoryIndex:: Index = " + index);
var index = aEvent.target.getAttribute("index");
if (index)
{
appCore.gotoHistoryIndex(index);
return true;
}
else {
var id = event.target.getAttribute("id");
if (id == "menuitem-back")
BrowserBack();
else if (id == "menuitem-forward")
BrowserForward();
}
return true;
}
else
{
var id = event.target.getAttribute("id");
if (id == "menuitem-back")
BrowserBack();
else if (id == "menuitem-forward")
BrowserForward();
}
}
function BrowserBack()
function BrowserBack()
{
// Get a handle to the back-button
var bb = document.getElementById("canGoBack");
// If the button is disabled, don't bother calling in to Appcore
if ( (bb.getAttribute("disabled")) == "true" )
return;
dump("Going Back\n");
appCore.back();
appCore.back();
UpdateBackForwardButtons();
}
function BrowserForward()
function BrowserForward()
{
// Get a handle to the back-button
var fb = document.getElementById("canGoForward");
// If the button is disabled, don't bother calling in to Appcore
if ( (fb.getAttribute("disabled")) == "true" )
return;
dump("Going Forward\n");
appCore.forward();
UpdateBackForwardButtons();
appCore.forward();
UpdateBackForwardButtons();
}
function BrowserBackMenu(event)
function BrowserBackMenu(event)
{
// dump("&&&& In BrowserbackMenu &&&&\n");
// Get a handle to the back-button
var bb = document.getElementById("canGoBack");
// If the button is disabled, don't bother calling in to Appcore
if ( (bb.getAttribute("disabled")) == "true" )
return;
if (appCore != null) {
appCore.backButtonPopup(event.target);
} else {
dump("BrowserAppCore has not been created!\n");
}
appCore.backButtonPopup(event.target);
}
function BrowserForwardMenu(event)
function BrowserForwardMenu(event)
{
// dump("&&&& In BrowserForwardMenu &&&&\n");
// Get a handle to the forward-button
var bb = document.getElementById("canGoForward");
// If the button is disabled, don't bother calling in to Appcore
if ( (bb.getAttribute("disabled")) == "true" )
return;
if (appCore != null) {
appCore.forwardButtonPopup(event.target);
} else {
dump("BrowserAppCore has not been created!\n");
}
appCore.forwardButtonPopup(event.target);
}
function BrowserStop() {
if(!stopButton)
stopButton = document.getElementById("stop-button");
// If the stop button is currently disabled, just return
if ((stopButton.getAttribute("disabled")) == "true")
return;
//Call in to BrowserAppcore to stop the current loading
appCore.stop();
function BrowserStop()
{
appCore.stop();
}
function BrowserReallyReload(reloadType) {
// Get a handle to the "canReload" broadcast id
var reloadBElem = document.getElementById("canReload");
if (!reloadBElem) {
dump("Couldn't obtain handle to reload Broadcast element\n");
return;
}
var canreload = reloadBElem.getAttribute("disabled");
// If the reload button is currently disabled, just return
if ( canreload) {
return;
}
//Call in to BrowserAppcore to reload the current loading
if (appCore != null) {
dump("Going to reload\n");
appCore.reload(reloadType);
} else {
dump("BrowserAppCore has not been created!\n");
}
function BrowserReallyReload(reloadType)
{
appCore.reload(reloadType);
}
function BrowserHome()
function BrowserHome()
{
// this eventual calls nsGlobalWIndow::Home()
window.content.home();
RefreshUrlbar();
}
function updateGoMenu(event)
{
if (appCore)
appCore.updateGoMenu(event.target);
else
dump("BrowserAppCore has not been created!\n");
}
function FillHistoryMenu(parent, menuname)
{
var shistory;
if (!appCore) {
dump("BrowserAppCore is not initialized!!\n");
return;
}
//Get the content area docshell
var docShell=null;
var result = appCore.getContentDocShell(docShell);
if (!docShell) {
dump("Couldn't get docshell from BrowserAppCore\n");
return;
}
//Get the session history component from docshell
docShell = docShell.QueryInterface(Components.interfaces.nsIWebNavigation);
if (docShell)
shistory = docShell.sessionHistory;
if (!shistory) {
dump("Session history is not initialized!!\n");
return;
}
//Remove old entries if any
DeleteHistoryItems(parent);
var count = shistory.count;
var index = shistory.index;
if (menuname == 'back')
{
var end = (index > maxHistoryMenuItems) ? index-maxHistoryMenuItems : 0;
for (j=index-1; j>=end; j--) {
var entry = shistory.getEntryAtIndex(j, false);
if (!entry) {
dump("Error accessing Session history Entries!!\n");
return;
}
var title = entry.getTitle();
CreateMenuItem(parent, j, title);
} //for
} //if(menuname==back)
else if (menuname == 'forward')
{
var end = ((count-index) > maxHistoryMenuItems) ? index+maxHistoryMenuItems : count;
for(j=index+1; j<end; j++) {
var entry = shistory.getEntryAtIndex(j, false);
if (!entry) {
dump("Error accessing Session history Entries!!\n");
return;
}
var title = entry.getTitle();
CreateMenuItem(parent, j, title);
} //for
}
else if (menuname == 'go')
{
var end = (count>maxHistoryMenuItems) ? (count-maxHistoryMenuItems) : 0;
for(j=count-1; j>=end; j--) {
var entry = shistory.getEntryAtIndex(j, false);
if (!entry) {
dump("Error accessing Session history Entries!!\n");
return;
}
var title = entry.getTitle();
CreateMenuItem(parent, j, title);
} //for
}
}
function ExecuteUBCommand(event)
{
//dump("In ExecuteUBCommand\n");
var target = event.target;
var keyword = target.getAttribute("keyword");
if (keyword){
//dump("Executing Keyword\n");
ExecuteKeyword(keyword);
return;
}
var index = target.getAttribute("index");
if (index) {
var urlbar = document.getElementById("urlbar");
var url = target.getAttribute("value");
//dump("Got History item, url = " + url + "\n");
if (url) {
urlbar.value = url;
BrowserLoadURL();
}
}
} //ExecuteUBCommand
function ExecuteKeyword(keyword)
{
urlbar = document.getElementById('urlbar');
if (!urlbar)
return;
switch(keyword) {
case 'quote':
urlbar.focus();
urlbar.value = bundle.GetStringFromName("quoteKeyword");
urlbar.setSelectionRange(14,33);
break;
case 'local':
urlbar.focus();
urlbar.value = bundle.GetStringFromName("localKeyword");
urlbar.setSelectionRange(12,27);
break;
case 'shop':
urlbar.focus();
urlbar.value = bundle.GetStringFromName("shopKeyword");
urlbar.setSelectionRange(13,22);
break;
case 'career':
urlbar.focus();
urlbar.value = bundle.GetStringFromName("careerKeyword");
urlbar.setSelectionRange(8,19);
break;
case 'webmail':
if (appCore)
appCore.loadUrl(bundle.GetStringFromName("webmailKeyword"));
else
dump("Couldn't find instance of BrowserAppCore\n");
break;
case 'list':
if (appCore)
appCore.loadUrl(bundle.GetStringFromName("keywordList"));
else
dump("Couldn't find instance of BrowserAppCore\n");
break;
}
}
function CreateUBHistoryMenu(event)
{
//dump("In CreateUBHistoryMenu\n");
if (!appCore) {
dump("BrowserInstance not Initialised\n");
return;
}
var ubHistory = appCore.urlbarHistory;
if (ubHistory) {
var len = ubHistory.count;
var end = (len>maxHistoryMenuItems) ? (len-maxHistoryMenuItems) : 0;
if (len > 0)
DeleteHistoryItems(event); // Delete old History Menus
for (i=len-1;i>=end;i--)
{
var label = ubHistory.getEntryAtIndex(i);
// dump("Got Entry At Index " + label + "\n");
var parent = event.target;
CreateMenuItem(parent, i, label);
}
}
}
function AddToUrlbarHistory()
{
// dump("In AddtoUrlbarHistory\n");
if (!appCore) {
dump("BrowserInstance not initialised\n");
return;
}
var ubHistory = appCore.urlbarHistory;
if (ubHistory) {
// dump("Got handle to the urlbar history component\n");
ubHistory.addEntry(document.getElementById('urlbar').value);
ubHistory.printHistory()
}
else
dump("Could not get handle to the urlbar Component\n");
}
function CreateMenuItem(parent, index, label)
{
var menuItem = document.createElement("menuitem");
if (label == null){
label = "Error: Title Not Available";
}
menuItem.setAttribute("value", label);
menuItem.setAttribute("index", i);
dump("Created Menuitem " + label + "\n");
parent.appendChild(menuItem);
}
function DeleteHistoryItems(event)
{
var parent = event.target;
//dump("In DeleteHistoryItems\n");
var childNodes = parent.childNodes;
if (!childNodes) {
dump("Error: UB-History menu found no Children!!\n");
return;
}
var ccount = childNodes.length;
for (i=ccount-1; i>=0; i--)
{
var menuitem = childNodes.item(i);
var index;
if (menuitem) {
index = menuitem.getAttribute("index");
}
// dump("Index for item to be deleted " + index + "\n");
if (index) {
// dump("Deleting menu item " + menuitem.getAttribute("value") + "\n");
try {
parent.removeChild(menuitem);
}
catch(e) {
dump(e);
}
}
} //for
} //DeleteHistoryItems
function OpenBookmarkURL(node, datasources)
function OpenBookmarkURL(node, datasources)
{
if (node.getAttribute('container') == "true") {
return false;

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

@ -61,6 +61,10 @@ Contributor(s): ______________________________________. -->
<script language="javascript" src="tooltip.js"></script>
<script language="javascript" src="navigatorDD.js"></script>
<!-- UI services -->
<script language="javascript" src="chrome://navigator/content/sessionHistoryUI.js"></script>
<script language="javascript" src="chrome://navigator/content/keywords.js"></script>
<commands id="commands">
<commandset id="globalEditMenuItems"/>
<commandset id="selectEditMenuItems"/>
@ -237,7 +241,7 @@ Contributor(s): ______________________________________. -->
<box class="box-toolbar-group" flex="1">
<menubutton class="menubutton-icon button-toolbar-3" id="ubhist-keyword-popup" tooltiptext="&internetKeyword.tooltip;">
<menupopup class="button-toolbar-3" oncreate="CreateUBHistoryMenu(event);" oncommand="ExecuteUBCommand(event);">
<menupopup class="button-toolbar-3" oncreate="createUBHistoryMenu(event);" oncommand="executeKeywordCommand(event);"/>
<!--
<menuitem class="button-toolbar-3 menuitem-non-iconic" value="&quoteKeyword.label;" keyword="quote"/>
<menuitem class="button-toolbar-3 menuitem-non-iconic" value="&localKeyword.label;" keyword="local"/>
@ -247,7 +251,6 @@ Contributor(s): ______________________________________. -->
<menuitem class="button-toolbar-3 menuitem-non-iconic" value="&listKeywords.label;" keyword="list"/>
<menuseparator/>
-->
</menupopup>
</menubutton>
@ -255,11 +258,18 @@ Contributor(s): ______________________________________. -->
<image id="page-proxy-button" ondraggesture="DragProxyIcon(event);"/>
<textfield autocomplete="false" timeout="300" class="plain chromeclass-location"
searchSessionType="urlbar" id="urlbar" tooltiptext="&locationBar.tooltip;"
onkeypress="if( event.which == 13 ) { AddToUrlbarHistory(); BrowserLoadURL(); }" flex="1"/>
onkeypress="if( event.which == 13 ) { addToUrlbarHistory(); BrowserLoadURL(); }" flex="1"/>
<!--
<menu id="ubhist-popup">
<image class="icon-dropmarker"/>
<menupopup oncreate="createUBHistoryMenu(event);" oncommand="executeURLBarHistoryCommand(event);"
popupalign="topright" popupanchor="bottomright"/>
</menu>
-->
<button class="button-toolbar-3" id="search-button" value="&searchButton.label;"
oncommand="OpenSearch('internet',false, document.getElementById('urlbar').value);"
tooltiptext="&searchButton.tooltip;"/>
<button class="button-toolbar-3" id="go-button" value="&goButton.label;" oncommand="BrowserLoadURL();"
<button class="button-toolbar-3" id="go-button" value="&goButton.label;" oncommand="addToUrlbarHistory(); BrowserLoadURL();"
tooltiptext="&goButton.tooltip;"/>
</box>
</box>

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

@ -0,0 +1,118 @@
const MAX_HISTORY_MENU_ITEMS = 15;
function FillHistoryMenu( aParent, aMenu )
{
var shistory;
// Get the content area docshell
var docShell = null;
var result = appCore.getContentDocShell(docShell);
if (docShell)
{
//Get the session history component from docshell
docShell = docShell.QueryInterface(Components.interfaces.nsIWebNavigation);
if (docShell)
{
shistory = docShell.sessionHistory;
if (shistory)
{
//Remove old entries if any
deleteHistoryItems( aParent );
var count = shistory.count;
var index = shistory.index;
switch (aMenu)
{
case "back":
var end = (index > MAX_HISTORY_MENU_ITEMS) ? index - MAX_HISTORY_MENU_ITEMS : 0;
for ( var j = index - 1; j >= end; j--)
{
var entry = shistory.getEntryAtIndex(j, false);
if (entry)
createMenuItem( aParent, j, entry.getTitle() );
}
break;
case "forward":
var end = ((count-index) > MAX_HISTORY_MENU_ITEMS) ? index + MAX_HISTORY_MENU_ITEMS : count;
for ( var j = index + 1; j < end; j++)
{
var entry = shistory.getEntryAtIndex(j, false);
if (entry)
createMenuItem( aParent, j, entry.getTitle() );
}
break;
case "go":
var end = count > MAX_HISTORY_MENU_ITEMS
? count - MAX_HISTORY_MENU_ITEMS
: 0;
for( var j = count - 1; j >= end; j-- )
{
var entry = shistory.getEntryAtIndex(j, false);
if (entry)
createMenuItem( aParent, j, entry.getTitle() );
}
break;
}
}
}
}
}
function executeUrlBarHistoryCommand( aEvent )
{
var index = aEvent.target.getAttribute("index");
var value = aEvent.target.value;
if (index && value)
{
gURLBar.value = value;
BrowserLoadURL();
}
}
function createUBHistoryMenu( aEvent )
{
var ubHistory = appCore.urlbarHistory;
if (ubHistory)
{
var len = ubHistory.count;
var end = (len > MAX_HISTORY_MENU_ITEMS) ? (len - MAX_HISTORY_MENU_ITEMS) : 0;
if (len > 0)
deleteHistoryItems( aEvent ); // Delete old History Menus
for (var i = len - 1; i >= end; i--)
createMenuItem( aEvent.target, i, ubHistory.getEntryAtIndex(i));
}
}
function addToUrlbarHistory()
{
var ubHistory = appCore.urlbarHistory;
if (ubHistory)
{
ubHistory.addEntry( gURLBar.value );
ubHistory.printHistory()
}
}
function createMenuItem( aParent, aIndex, aValue)
{
var menuitem = document.createElement( "menuitem" );
menuitem.setAttribute( "value", aValue );
menuitem.setAttribute( "index", aIndex );
aParent.appendChild( menuitem );
}
function deleteHistoryItems( aEvent )
{
var children = aEvent.target.childNodes;
for (var i = 0; i < children.length; i++ )
{
var index = children[i].getAttribute( "index" );
if (index)
aEvent.target.removeChild( children[i] );
}
}
function updateGoMenu(event)
{
appCore.updateGoMenu(event.target);
}