It's baaaaaaaaaaaaaack
git-svn-id: svn://10.0.0.236/trunk@126278 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
4736214ba3
commit
011fcc2fcb
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,696 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* - Kevin Puetz (puetzk@iastate.edu)
|
||||
* - Ben Goodger <ben@netscape.com>
|
||||
* - Blake Ross <blaker@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var DROP_BEFORE = -1;
|
||||
var DROP_ON = 0;
|
||||
var DROP_AFTER = 1;
|
||||
function _RDF(aType)
|
||||
{
|
||||
return "http://www.w3.org/1999/02/22-rdf-syntax-ns#" + aType;
|
||||
}
|
||||
function NC_RDF(aType)
|
||||
{
|
||||
return "http://home.netscape.com/NC-rdf#" + aType;
|
||||
}
|
||||
|
||||
var RDFUtils = {
|
||||
getResource: function(aString)
|
||||
{
|
||||
return this.rdf.GetResource(aString, true);
|
||||
},
|
||||
|
||||
getTarget: function(aDS, aSourceID, aPropertyID)
|
||||
{
|
||||
var source = this.getResource(aSourceID);
|
||||
var property = this.getResource(aPropertyID);
|
||||
return aDS.GetTarget(source, property, true);
|
||||
},
|
||||
|
||||
getValueFromResource: function(aResource)
|
||||
{
|
||||
aResource = aResource.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
return aResource ? aResource.Value : null;
|
||||
},
|
||||
_rdf: null,
|
||||
get rdf() {
|
||||
if (!this._rdf) {
|
||||
this._rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
}
|
||||
return this._rdf;
|
||||
}
|
||||
};
|
||||
|
||||
function isBookmark(aURI)
|
||||
{
|
||||
var db = document.getElementById("innermostBox").database;
|
||||
var typeValue = RDFUtils.getTarget(db, aURI, _RDF("type"));
|
||||
typeValue = RDFUtils.getValueFromResource(typeValue);
|
||||
return (typeValue == NC_RDF("BookmarkSeparator") ||
|
||||
typeValue == NC_RDF("Bookmark") ||
|
||||
typeValue == NC_RDF("Folder"))
|
||||
}
|
||||
|
||||
var personalToolbarObserver = {
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
{
|
||||
// Prevent dragging out of menus on non Win32 platforms.
|
||||
// a) on Mac drag from menus is generally regarded as being satanic
|
||||
// b) on Linux, this causes an X-server crash, see bug 79003.
|
||||
// Since we're not doing D&D into menus properly at this point, it seems
|
||||
// fair enough to disable it on non-Win32 platforms. There is no hang
|
||||
// or crash associated with this on Windows, so we'll leave the functionality
|
||||
// there.
|
||||
if (navigator.platform != "Win32" && aEvent.target.localName != "toolbarbutton")
|
||||
return;
|
||||
|
||||
|
||||
if (aEvent.target.localName == "menu" ||
|
||||
(aEvent.target.localName == "toolbarbutton" && aEvent.target.getAttribute("type") == "menu")) {
|
||||
if (aEvent.target.getAttribute("type") == "http://home.netscape.com/NC-rdf#Folder") {
|
||||
var child = aEvent.target.childNodes[0];
|
||||
if (child && child.localName == "menupopup")
|
||||
child.hidePopup();
|
||||
else {
|
||||
var parent = aEvent.target.parentNode;
|
||||
if (parent && parent.localName == "menupopup")
|
||||
parent.hidePopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var personalToolbar = document.getElementById("PersonalToolbar");
|
||||
if (aEvent.target == personalToolbar) return;
|
||||
|
||||
var db = document.getElementById("innermostBox").database;
|
||||
var uri = aEvent.target.id;
|
||||
if (!isBookmark(uri)) return;
|
||||
var url = RDFUtils.getTarget(db, uri, NC_RDF("URL"));
|
||||
if (url)
|
||||
url = url.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
else
|
||||
url = "";
|
||||
var name = RDFUtils.getTarget(db, uri, NC_RDF("Name"));
|
||||
if (name)
|
||||
name = name.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
else
|
||||
name = "";
|
||||
var urlString = url + "\n" + name;
|
||||
var htmlString = "<A HREF='" + uri + "'>" + name + "</A>";
|
||||
aXferData.data = new TransferData();
|
||||
aXferData.data.addDataForFlavour("moz/rdfitem", uri);
|
||||
aXferData.data.addDataForFlavour("text/x-moz-url", urlString);
|
||||
aXferData.data.addDataForFlavour("text/html", htmlString);
|
||||
aXferData.data.addDataForFlavour("text/unicode", url);
|
||||
},
|
||||
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var elementRes = RDFUtils.getResource(xferData[0]);
|
||||
var personalToolbarRes = RDFUtils.getResource("NC:PersonalToolbarFolder");
|
||||
|
||||
var inner = document.getElementById("innermostBox");
|
||||
var childDB = inner.database;
|
||||
const kCtrContractID = "@mozilla.org/rdf/container;1";
|
||||
const kCtrIID = Components.interfaces.nsIRDFContainer;
|
||||
var rdfContainer = Components.classes[kCtrContractID].createInstance(kCtrIID);
|
||||
|
||||
// Ensure that the Personal Toolbar Folder actually exists...
|
||||
try {
|
||||
rdfContainer.Init(childDB, personalToolbarRes);
|
||||
}
|
||||
catch (e) {
|
||||
// No Personal Toolbar Folder, we must create a new one.
|
||||
const kBMSContractID = "@mozilla.org/browser/bookmarks-service;1";
|
||||
const kBMSIID = Components.interfaces.nsIBookmarksService;
|
||||
var bms = Components.classes[kBMSContractID].getService(kBMSIID);
|
||||
if (bms) {
|
||||
var bookmarksRoot = RDFUtils.getResource("NC:BookmarksRoot");
|
||||
var bookmarksBundle = document.getElementById("bookmarksbundle");
|
||||
var ptFolderName = bookmarksBundle.getString("DefaultPersonalToolbarFolder");
|
||||
var ptFolder = bms.createFolder(ptFolderName, bookmarksRoot);
|
||||
BookmarksUtils.doBookmarksCommand(ptFolder.Value, NC_NS_CMD + "setpersonaltoolbarfolder", []);
|
||||
}
|
||||
}
|
||||
|
||||
// if dragged url is already bookmarked, remove it from current location first
|
||||
var parentContainer = findParentContainer(aDragSession.sourceNode);
|
||||
if (parentContainer)
|
||||
{
|
||||
rdfContainer.Init(childDB, parentContainer);
|
||||
rdfContainer.RemoveElement(elementRes, false);
|
||||
}
|
||||
|
||||
// determine charset of link
|
||||
var linkCharset = aDragSession.sourceDocument ? aDragSession.sourceDocument.characterSet : null;
|
||||
// determine title of link
|
||||
var linkTitle;
|
||||
|
||||
// look it up in bookmarks
|
||||
var bookmarksDS = RDFUtils.rdf.GetDataSource("rdf:bookmarks");
|
||||
var nameRes = RDFUtils.getResource(NC_RDF("Name"));
|
||||
var nameFromBookmarks = bookmarksDS.GetTarget(elementRes, nameRes, true);
|
||||
if (nameFromBookmarks)
|
||||
nameFromBookmarks = nameFromBookmarks.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (nameFromBookmarks) {
|
||||
linkTitle = nameFromBookmarks.Value;
|
||||
}
|
||||
else if (xferData.length >= 2)
|
||||
linkTitle = xferData[1]
|
||||
else
|
||||
{
|
||||
// look up this URL's title in global history
|
||||
var potentialTitle = null;
|
||||
var historyDS = RDFUtils.rdf.GetDataSource("rdf:history");
|
||||
var titlePropRes = RDFUtils.getResource(NC_RDF("Name"));
|
||||
var titleFromHistory = historyDS.GetTarget(elementRes, titlePropRes, true);
|
||||
if (titleFromHistory)
|
||||
titleFromHistory = titleFromHistory.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (titleFromHistory)
|
||||
potentialTitle = titleFromHistory.Value;
|
||||
linkTitle = potentialTitle;
|
||||
}
|
||||
|
||||
var dropElement = aEvent.target.id;
|
||||
var dropElementRes, dropIndex, dropPosition;
|
||||
if (dropElement == "innermostBox")
|
||||
{
|
||||
dropElementRes = personalToolbarRes;
|
||||
dropPosition = DROP_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
dropElementRes = RDFUtils.getResource(dropElement);
|
||||
rdfContainer.Init(childDB, personalToolbarRes);
|
||||
dropIndex = rdfContainer.IndexOf(dropElementRes);
|
||||
if (dropPosition == undefined)
|
||||
dropPosition = determineDropPosition(aEvent, true);
|
||||
}
|
||||
|
||||
switch (dropPosition) {
|
||||
case DROP_BEFORE:
|
||||
if (dropIndex<1) dropIndex = 1;
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, personalToolbarRes, dropIndex);
|
||||
break;
|
||||
case DROP_ON:
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, dropElementRes, -1);
|
||||
break;
|
||||
case DROP_AFTER:
|
||||
default:
|
||||
// compensate for badly calculated dropIndex
|
||||
rdfContainer.Init(childDB, personalToolbarRes);
|
||||
if (dropIndex < rdfContainer.GetCount()) ++dropIndex;
|
||||
|
||||
if (dropIndex<0) dropIndex = 0;
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, personalToolbarRes, dropIndex);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
mCurrentDragOverButton: null,
|
||||
mCurrentDragPosition: null,
|
||||
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
if (this.mCurrentDragOverButton)
|
||||
{
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-left");
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-right");
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-top");
|
||||
this.mCurrentDragOverButton.removeAttribute("open");
|
||||
}
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
var dropPosition = determineDropPosition(aEvent, true);
|
||||
|
||||
// bail if drop target is not a valid bookmark item or folder
|
||||
var inner = document.getElementById("innermostBox");
|
||||
if (aEvent.target.parentNode != inner && aEvent.target != inner)
|
||||
{
|
||||
aDragSession.canDrop = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.mCurrentDragOverButton != aEvent.target ||
|
||||
(this.mCurrentDragOverButton == aEvent.target &&
|
||||
this.mCurrentDragPosition != dropPosition))
|
||||
{
|
||||
if (this.mCurrentDragOverButton)
|
||||
{
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-left");
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-right");
|
||||
this.mCurrentDragOverButton.removeAttribute("dragover-top");
|
||||
this.mCurrentDragOverButton.removeAttribute("open");
|
||||
}
|
||||
this.mCurrentDragOverButton = aEvent.target;
|
||||
this.mCurrentDragPosition = dropPosition;
|
||||
}
|
||||
|
||||
switch (dropPosition)
|
||||
{
|
||||
case DROP_BEFORE:
|
||||
aEvent.target.setAttribute("dragover-left", "true");
|
||||
break;
|
||||
case DROP_AFTER:
|
||||
aEvent.target.setAttribute("dragover-right", "true");
|
||||
break;
|
||||
case DROP_ON:
|
||||
default:
|
||||
if (aEvent.target.getAttribute("container") == "true") {
|
||||
aEvent.target.setAttribute("dragover-top", "true");
|
||||
//cant open a menu during a drag! suck!
|
||||
//aEvent.target.setAttribute("open", "true");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("moz/rdfitem");
|
||||
// application/x-moz-file
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
var proxyIconDNDObserver = {
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
{
|
||||
var urlBar = document.getElementById("urlbar");
|
||||
|
||||
// XXX - do we want to allow the user to set a blank page to their homepage?
|
||||
// if so then we want to modify this a little to set about:blank as
|
||||
// the homepage in the event of an empty urlbar.
|
||||
if (!urlBar.value) return;
|
||||
|
||||
var urlString = urlBar.value + "\n" + window._content.document.title;
|
||||
var htmlString = "<a href=\"" + urlBar.value + "\">" + urlBar.value + "</a>";
|
||||
|
||||
aXferData.data = new TransferData();
|
||||
aXferData.data.addDataForFlavour("text/x-moz-url", urlString);
|
||||
aXferData.data.addDataForFlavour("text/unicode", urlBar.value);
|
||||
aXferData.data.addDataForFlavour("text/html", htmlString);
|
||||
}
|
||||
};
|
||||
|
||||
var homeButtonObserver = {
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var url = retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
|
||||
setTimeout(openHomeDialog, 0, url);
|
||||
},
|
||||
|
||||
onDragOver: function (aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = gNavigatorBundle.getString("droponhomebutton");
|
||||
aDragSession.dragAction = Components.interfaces.nsIDragService.DRAGDROP_ACTION_LINK;
|
||||
var button = document.getElementById("home-button");
|
||||
button.setAttribute("dragover", "true");
|
||||
},
|
||||
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
var statusTextFld = document.getElementById("statusbar-display");
|
||||
statusTextFld.label = "";
|
||||
var button = document.getElementById("home-button");
|
||||
button.removeAttribute("dragover");
|
||||
},
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
function openHomeDialog(aURL)
|
||||
{
|
||||
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
|
||||
var pressedVal = { };
|
||||
var promptTitle = gNavigatorBundle.getString("droponhometitle");
|
||||
var promptMsg = gNavigatorBundle.getString("droponhomemsg");
|
||||
var okButton = gNavigatorBundle.getString("droponhomeokbutton");
|
||||
|
||||
promptService.confirmEx(window, promptTitle, promptMsg,
|
||||
(promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) +
|
||||
(promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
|
||||
okButton, null, null, null, {value:0}, pressedVal);
|
||||
|
||||
if (pressedVal.value == 0) {
|
||||
nsPreferences.setUnicharPref("browser.startup.homepage", aURL);
|
||||
setTooltipText("home-button", aURL);
|
||||
}
|
||||
}
|
||||
|
||||
var goButtonObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
aEvent.target.setAttribute("dragover", "true");
|
||||
return true;
|
||||
},
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
aEvent.target.removeAttribute("dragover");
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var uri = xferData[0] ? xferData[0] : xferData[1];
|
||||
if (uri)
|
||||
loadURI(uri);
|
||||
},
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
var searchButtonObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
aEvent.target.setAttribute("dragover", "true");
|
||||
return true;
|
||||
},
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
aEvent.target.removeAttribute("dragover");
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var uri = xferData[1] ? xferData[1] : xferData[0];
|
||||
if (uri)
|
||||
OpenSearch('internet',false, uri);
|
||||
},
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
var gOpenFolder = null;
|
||||
var folderObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
if (aEvent.target.getAttribute("open") == "true")
|
||||
return false;
|
||||
|
||||
aEvent.target.setAttribute("dragover", "true");
|
||||
aEvent.target.firstChild.showPopup(aEvent.target, -1, -1, "menupopup", "bottomleft", "bottomleft");
|
||||
return true;
|
||||
},
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
var gCurrentTarget = null;
|
||||
var gCurrentDragOverMenu = null;
|
||||
function closeOpenMenu()
|
||||
{
|
||||
if (gCurrentDragOverMenu && gCurrentTarget.firstChild != gCurrentDragOverMenu) {
|
||||
if (gCurrentTarget.parentNode != gCurrentDragOverMenu) {
|
||||
gCurrentDragOverMenu.hidePopup();
|
||||
gCurrentDragOverMenu = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var menuDNDObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession)
|
||||
{
|
||||
// if we're a folder just one level deep, open it
|
||||
var isOneLevelDeep = aEvent.target.parentNode.parentNode.getAttribute("open") == "true" && aEvent.target.parentNode.parentNode.localName == "toolbarbutton";
|
||||
var dropPosition = determineDropPosition(aEvent, !isOneLevelDeep);
|
||||
gCurrentTarget = aEvent.target;
|
||||
if (aEvent.target.firstChild && aEvent.target.firstChild.localName == "menupopup") {
|
||||
if (isOneLevelDeep) {
|
||||
if (gCurrentDragOverMenu && gCurrentDragOverMenu != aEvent.target.firstChild)
|
||||
gCurrentDragOverMenu.hidePopup();
|
||||
if (!gCurrentDragOverMenu) {
|
||||
aEvent.target.firstChild.showPopup(aEvent.target, -1, -1, "menupopup", "topright, topright");
|
||||
gCurrentDragOverMenu = aEvent.target.firstChild;
|
||||
}
|
||||
}
|
||||
else {
|
||||
aEvent.target.setAttribute("menuactive", "true");
|
||||
}
|
||||
}
|
||||
|
||||
// remove drag attributes from old item once we move to a new item
|
||||
if (this.mCurrentDragOverItem != aEvent.target) {
|
||||
if (this.mCurrentDragOverItem) {
|
||||
this.mCurrentDragOverItem.removeAttribute("dragover-top");
|
||||
this.mCurrentDragOverItem.removeAttribute("dragover-bottom");
|
||||
this.mCurrentDragOverItem.removeAttribute("menuactive");
|
||||
}
|
||||
this.mCurrentDragOverItem = aEvent.target;
|
||||
}
|
||||
|
||||
// if there's an open submenu and we're not over it or one of its children, close it
|
||||
if (gCurrentDragOverMenu && aEvent.target.firstChild != gCurrentDragOverMenu) {
|
||||
if (aEvent.target.parentNode != gCurrentDragOverMenu) {
|
||||
setTimeout(function() { closeOpenMenu(); },500);
|
||||
}
|
||||
}
|
||||
|
||||
// ensure appropriate feedback
|
||||
switch (dropPosition) {
|
||||
case DROP_BEFORE:
|
||||
aEvent.target.setAttribute("dragover-bottom", "true");
|
||||
break;
|
||||
case DROP_AFTER:
|
||||
aEvent.target.setAttribute("dragover-top", "true");
|
||||
break;
|
||||
}
|
||||
},
|
||||
mCurrentDragOverItem: null,
|
||||
onDragExit: function (aEvent, aDragSession)
|
||||
{
|
||||
// remove drag attribute from current item once we leave the popup
|
||||
if (this.mCurrentDragOverItem) {
|
||||
this.mCurrentDragOverItem.removeAttribute("dragover-top");
|
||||
this.mCurrentDragOverItem.removeAttribute("dragover-bottom");
|
||||
}
|
||||
},
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
var xferData = aXferData.data.split("\n");
|
||||
var elementRes = RDFUtils.getResource(xferData[0]);
|
||||
|
||||
var bookmarksButton = document.getElementById("bookmarks-button");
|
||||
var childDB = bookmarksButton.database;
|
||||
var rdfContainer = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
|
||||
|
||||
// if dragged url is already bookmarked, remove it from current location first
|
||||
var parentContainer = findParentContainer(aDragSession.sourceNode);
|
||||
if (parentContainer) {
|
||||
rdfContainer.Init(childDB, parentContainer);
|
||||
rdfContainer.RemoveElement(elementRes, false);
|
||||
}
|
||||
parentContainer = findParentContainer(aEvent.target);
|
||||
// determine charset of link
|
||||
var linkCharset = aDragSession.sourceDocument ? aDragSession.sourceDocument.characterSet : null;
|
||||
// determine title of link
|
||||
var linkTitle;
|
||||
// look it up in bookmarks
|
||||
var bookmarksDS = RDFUtils.rdf.GetDataSource("rdf:bookmarks");
|
||||
var nameRes = RDFUtils.getResource(NC_RDF("Name"));
|
||||
var nameFromBookmarks = bookmarksDS.GetTarget(elementRes, nameRes, true);
|
||||
if (nameFromBookmarks)
|
||||
nameFromBookmarks = nameFromBookmarks.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
|
||||
if (nameFromBookmarks)
|
||||
linkTitle = nameFromBookmarks.Value;
|
||||
else if (xferData.length >= 2)
|
||||
linkTitle = xferData[1]
|
||||
else {
|
||||
// look up this URL's title in global history
|
||||
var historyDS = RDFUtils.rdf.GetDataSource("rdf:history");
|
||||
var titlePropRes = RDFUtils.getResource(NC_RDF("Name"));
|
||||
var titleFromHistory = historyDS.GetTarget(elementRes, titlePropRes, true);
|
||||
if (titleFromHistory)
|
||||
titleFromHistory = titleFromHistory.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
if (titleFromHistory)
|
||||
linkTitle = titleFromHistory.Value;
|
||||
}
|
||||
|
||||
var dropElement = aEvent.target.id;
|
||||
var dropElementRes, dropIndex, dropPosition;
|
||||
dropElementRes = RDFUtils.getResource(dropElement);
|
||||
rdfContainer.Init(childDB, parentContainer);
|
||||
dropIndex = rdfContainer.IndexOf(dropElementRes);
|
||||
var isOneLevelDeep = aEvent.target.parentNode.parentNode.getAttribute("open") == "true" && aEvent.target.parentNode.parentNode.localName == "toolbarbutton";
|
||||
dropPosition = determineDropPosition(aEvent, !isOneLevelDeep);
|
||||
switch (dropPosition) {
|
||||
case DROP_BEFORE:
|
||||
--dropIndex;
|
||||
if (dropIndex<1) dropIndex = 1;
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, parentContainer, dropIndex);
|
||||
break;
|
||||
case DROP_ON:
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, dropElementRes, -1);
|
||||
break;
|
||||
case DROP_AFTER:
|
||||
default:
|
||||
// compensate for badly calculated dropIndex
|
||||
if (dropIndex < rdfContainer.GetCount()) ++dropIndex;
|
||||
|
||||
if (dropIndex<0) dropIndex = 0;
|
||||
--dropIndex;
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, parentContainer, dropIndex);
|
||||
break;
|
||||
}
|
||||
|
||||
// if user isn't rearranging within the menu, close it
|
||||
if (aDragSession.sourceNode.localName != "menuitem" && aDragSession.sourceNode.localName != "menu")
|
||||
setTimeout(function() { if (gCurrentDragOverMenu) gCurrentDragOverMenu.hidePopup(); document.getElementById("bookmarks-button").firstChild.hidePopup(); gDidOpen = false; }, 190);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
getSupportedFlavours: function () {
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
|
||||
function determineDropPosition(aEvent, aAllowDropOn)
|
||||
{
|
||||
var overButtonBoxObject = aEvent.target.boxObject.QueryInterface(Components.interfaces.nsIBoxObject);
|
||||
// most things only drop on the left or right
|
||||
var regionCount = 2;
|
||||
|
||||
// you can drop ONTO containers, so there is a "middle" region
|
||||
if (aAllowDropOn && aEvent.target.getAttribute("container") == "true" &&
|
||||
aEvent.target.getAttribute("type") == "menu")
|
||||
return DROP_ON;
|
||||
|
||||
var measure;
|
||||
var coordValue;
|
||||
var clientCoordValue;
|
||||
if (aEvent.target.localName == "menuitem" || aEvent.target.localName == "menu") {
|
||||
measure = overButtonBoxObject.height/regionCount;
|
||||
coordValue = overButtonBoxObject.y;
|
||||
clientCoordValue = aEvent.clientY;
|
||||
}
|
||||
else if (aEvent.target.localName == "toolbarbutton") {
|
||||
measure = overButtonBoxObject.width/regionCount;
|
||||
coordValue = overButtonBoxObject.x;
|
||||
clientCoordValue = aEvent.clientX;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
|
||||
// in the first region?
|
||||
if (clientCoordValue < (coordValue + measure))
|
||||
return DROP_BEFORE;
|
||||
|
||||
// in the last region?
|
||||
if (clientCoordValue >= (coordValue + (regionCount - 1)*measure))
|
||||
return DROP_AFTER;
|
||||
|
||||
// must be in the middle somewhere
|
||||
return DROP_ON;
|
||||
}
|
||||
|
||||
// returns the parent resource of the dragged element. This is determined
|
||||
// by inspecting the source element of the drag and walking up the DOM tree
|
||||
// to find the appropriate containing node.
|
||||
function findParentContainer(aElement)
|
||||
{
|
||||
if (!aElement) return null;
|
||||
switch (aElement.localName) {
|
||||
case "toolbarbutton":
|
||||
var box = aElement.parentNode;
|
||||
return RDFUtils.getResource(box.getAttribute("ref"));
|
||||
case "menu":
|
||||
case "menuitem":
|
||||
var parentNode = aElement.parentNode.parentNode;
|
||||
|
||||
if (parentNode.getAttribute("type") != NC_RDF("Folder") &&
|
||||
parentNode.getAttributeNS("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "type") != "http://home.netscape.com/NC-rdf#Folder")
|
||||
return RDFUtils.getResource("NC:BookmarksRoot");
|
||||
return RDFUtils.getResource(parentNode.id);
|
||||
case "treecell":
|
||||
var treeitem = aElement.parentNode.parentNode.parentNode.parentNode;
|
||||
var res = treeitem.getAttribute("ref");
|
||||
if (!res)
|
||||
res = treeitem.id;
|
||||
return RDFUtils.getResource(res);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function insertBookmarkAt(aURL, aTitle, aCharset, aFolderRes, aIndex)
|
||||
{
|
||||
const kBMSContractID = "@mozilla.org/browser/bookmarks-service;1";
|
||||
const kBMSIID = Components.interfaces.nsIBookmarksService;
|
||||
const kBMS = Components.classes[kBMSContractID].getService(kBMSIID);
|
||||
kBMS.createBookmarkWithDetails(aTitle, aURL, aCharset, aFolderRes, aIndex);
|
||||
}
|
||||
|
||||
@ -1,170 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const mediatorContractId = "@mozilla.org/rdf/datasource;1?name=window-mediator";
|
||||
const nsIWebBrowserChrome = Components.interfaces.nsIWebBrowserChrome;
|
||||
|
||||
function nsBrowserContentListener(toplevelWindow, contentWindow)
|
||||
{
|
||||
// this one is not as easy as you would hope.
|
||||
// need to convert toplevelWindow to an XPConnected object, instead
|
||||
// of a DOM-based object, to be able to QI() it to nsIXULWindow
|
||||
|
||||
this.init(toplevelWindow, contentWindow);
|
||||
}
|
||||
|
||||
/* implements nsIURIContentListener */
|
||||
|
||||
nsBrowserContentListener.prototype =
|
||||
{
|
||||
init: function(toplevelWindow, contentWindow)
|
||||
{
|
||||
this.toplevelWindow = toplevelWindow;
|
||||
this.contentWindow = contentWindow;
|
||||
|
||||
// hook up the whole parent chain thing
|
||||
var windowDocShell = this.convertWindowToDocShell(toplevelWindow);
|
||||
if (windowDocShell)
|
||||
windowDocshell.parentURIContentListener = this;
|
||||
|
||||
var registerWindow = false;
|
||||
try {
|
||||
var treeItem = contentWindow.docShell.QueryInterface(Components.interfaces.nsIDocShellTreeItem);
|
||||
var treeOwner = treeItem.treeOwner;
|
||||
var interfaceRequestor = treeOwner.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
|
||||
var webBrowserChrome = interfaceRequestor.getInterface(nsIWebBrowserChrome);
|
||||
if (webBrowserChrome)
|
||||
{
|
||||
var chromeFlags = webBrowserChrome.chromeFlags;
|
||||
var res = chromeFlags & nsIWebBrowserChrome.CHROME_ALL;
|
||||
var res2 = chromeFlags & nsIWebBrowserChrome.CHROME_DEFAULT;
|
||||
if ( res == nsIWebBrowserChrome.CHROME_ALL || res2 == nsIWebBrowserChrome.CHROME_DEFAULT)
|
||||
{
|
||||
registerWindow = true;
|
||||
}
|
||||
}
|
||||
} catch (ex) {}
|
||||
|
||||
// register ourselves
|
||||
if (registerWindow)
|
||||
{
|
||||
var uriLoader = Components.classes["@mozilla.org/uriloader;1"].getService(Components.interfaces.nsIURILoader);
|
||||
uriLoader.registerContentListener(this);
|
||||
}
|
||||
},
|
||||
close: function()
|
||||
{
|
||||
this.contentWindow = null;
|
||||
var uriLoader = Components.classes["@mozilla.org/uriloader;1"].getService(Components.interfaces.nsIURILoader);
|
||||
|
||||
uriLoader.unRegisterContentListener(this);
|
||||
},
|
||||
QueryInterface: function(iid)
|
||||
{
|
||||
if (iid.equals(Components.interfaces.nsIURIContentListener))
|
||||
return this;
|
||||
if (iid.equals(Components.interfaces.nsISupportsWeakReference))
|
||||
return this;
|
||||
throw Components.results.NS_NOINTERFACE;
|
||||
|
||||
},
|
||||
onStartURIOpen: function(uri)
|
||||
{
|
||||
// ignore and don't abort
|
||||
return false;
|
||||
},
|
||||
|
||||
doContent: function(contentType, isContentPreferred, request, contentHandler)
|
||||
{
|
||||
// forward the doContent to our content area webshell
|
||||
var docShell = this.contentWindow.docShell;
|
||||
var contentListener;
|
||||
try {
|
||||
contentListener =
|
||||
docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIURIContentListener);
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
}
|
||||
|
||||
if (!contentListener) return false;
|
||||
|
||||
return contentListener.doContent(contentType, isContentPreferred, request, contentHandler);
|
||||
|
||||
},
|
||||
|
||||
isPreferred: function(contentType, desiredContentType)
|
||||
{
|
||||
// seems like we should be getting this from helper apps or something
|
||||
switch(contentType) {
|
||||
case "text/html":
|
||||
case "text/xul":
|
||||
case "text/rdf":
|
||||
case "text/xml":
|
||||
case "text/css":
|
||||
case "image/gif":
|
||||
case "image/jpeg":
|
||||
case "image/png":
|
||||
case "image/tiff":
|
||||
case "text/plain":
|
||||
case "application/http-index-format":
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
canHandleContent: function(contentType, isContentPreferred, desiredContentType)
|
||||
{
|
||||
var docShell = this.contentWindow.docShell;
|
||||
var contentListener;
|
||||
try {
|
||||
contentListener =
|
||||
docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIURIContentListener);
|
||||
} catch (ex) {
|
||||
dump(ex);
|
||||
}
|
||||
if (!contentListener) return false;
|
||||
|
||||
return contentListener.canHandleContent(contentType, isContentPreferred, desiredContentType);
|
||||
},
|
||||
convertWindowToDocShell: function(win) {
|
||||
// don't know how to do this
|
||||
return null;
|
||||
},
|
||||
loadCookie: null,
|
||||
parentContentListener: null
|
||||
}
|
||||
@ -1,408 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Blake Ross <blakeross@telocity.com>
|
||||
* Peter Annema <disttsc@bart.nl>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const NS_ERROR_MODULE_NETWORK = 2152398848;
|
||||
const NS_NET_STATUS_READ_FROM = NS_ERROR_MODULE_NETWORK + 8;
|
||||
const NS_NET_STATUS_WROTE_TO = NS_ERROR_MODULE_NETWORK + 9;
|
||||
|
||||
|
||||
function nsBrowserStatusHandler()
|
||||
{
|
||||
this.init();
|
||||
}
|
||||
|
||||
nsBrowserStatusHandler.prototype =
|
||||
{
|
||||
userTyped :
|
||||
{
|
||||
_value : false,
|
||||
browser : null,
|
||||
|
||||
get value() {
|
||||
if (this.browser != getBrowser().mCurrentBrowser)
|
||||
this._value = false;
|
||||
|
||||
return this._value;
|
||||
},
|
||||
|
||||
set value(aValue) {
|
||||
if (this._value != aValue) {
|
||||
this._value = aValue;
|
||||
this.browser = aValue ? getBrowser().mCurrentBrowser : null;
|
||||
}
|
||||
|
||||
return aValue;
|
||||
}
|
||||
},
|
||||
|
||||
useRealProgressFlag : false,
|
||||
totalRequests : 0,
|
||||
finishedRequests : 0,
|
||||
|
||||
// Stored Status, Link and Loading values
|
||||
status : "",
|
||||
defaultStatus : "",
|
||||
jsStatus : "",
|
||||
jsDefaultStatus : "",
|
||||
overLink : "",
|
||||
|
||||
statusTimeoutInEffect : false,
|
||||
|
||||
hideAboutBlank : true,
|
||||
|
||||
QueryInterface : function(aIID)
|
||||
{
|
||||
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
|
||||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
|
||||
aIID.equals(Components.interfaces.nsIXULBrowserWindow) ||
|
||||
aIID.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
throw Components.results.NS_NOINTERFACE;
|
||||
},
|
||||
|
||||
init : function()
|
||||
{
|
||||
// XXXjag is this still needed? It's currently just ""
|
||||
this.defaultStatus = gNavigatorBundle.getString("defaultStatus");
|
||||
|
||||
this.urlBar = document.getElementById("urlbar");
|
||||
this.throbberElement = document.getElementById("navigator-throbber");
|
||||
this.statusMeter = document.getElementById("statusbar-icon");
|
||||
this.stopCmd = document.getElementById("cmd_stop");
|
||||
this.statusTextField = document.getElementById("statusbar-display");
|
||||
this.isImage = document.getElementById("isImage");
|
||||
this.securityButton = document.getElementById("security-button");
|
||||
|
||||
// Initialize the security button's state and tooltip text
|
||||
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
|
||||
this.onSecurityChange(null, null, nsIWebProgressListener.STATE_IS_INSECURE);
|
||||
},
|
||||
|
||||
destroy : function()
|
||||
{
|
||||
// XXXjag to avoid leaks :-/, see bug 60729
|
||||
this.urlBar = null;
|
||||
this.throbberElement = null;
|
||||
this.statusMeter = null;
|
||||
this.stopCmd = null;
|
||||
this.statusTextField = null;
|
||||
this.isImage = null;
|
||||
this.securityButton = null;
|
||||
this.userTyped = null;
|
||||
},
|
||||
|
||||
setJSStatus : function(status)
|
||||
{
|
||||
this.jsStatus = status;
|
||||
this.updateStatusField();
|
||||
},
|
||||
|
||||
setJSDefaultStatus : function(status)
|
||||
{
|
||||
this.jsDefaultStatus = status;
|
||||
this.updateStatusField();
|
||||
},
|
||||
|
||||
setDefaultStatus : function(status)
|
||||
{
|
||||
this.defaultStatus = status;
|
||||
this.updateStatusField();
|
||||
},
|
||||
|
||||
setOverLink : function(link, b)
|
||||
{
|
||||
this.overLink = link;
|
||||
this.updateStatusField();
|
||||
if (link)
|
||||
this.statusTextField.setAttribute('crop', 'center');
|
||||
else
|
||||
this.statusTextField.setAttribute('crop', 'end');
|
||||
},
|
||||
|
||||
updateStatusField : function()
|
||||
{
|
||||
var text = this.overLink || this.status || this.jsStatus || this.jsDefaultStatus || this.defaultStatus;
|
||||
|
||||
// check the current value so we don't trigger an attribute change
|
||||
// and cause needless (slow!) UI updates
|
||||
if (this.statusTextField.label != text)
|
||||
this.statusTextField.label = text;
|
||||
},
|
||||
|
||||
mimeTypeIsTextBased : function(contentType)
|
||||
{
|
||||
return /^text\/|\+xml$/.test(contentType);
|
||||
},
|
||||
|
||||
onLinkIconAvailable : function(aHref) {
|
||||
if (gProxyFavIcon && pref.getBoolPref("browser.chrome.site_icons"))
|
||||
{
|
||||
gProxyFavIcon.setAttribute("src", aHref);
|
||||
|
||||
// update any bookmarks with new icon reference
|
||||
if (!gBookmarksService)
|
||||
gBookmarksService = Components.classes["@mozilla.org/browser/bookmarks-service;1"]
|
||||
.getService(Components.interfaces.nsIBookmarksService);
|
||||
gBookmarksService.updateBookmarkIcon(this.urlBar.value, aHref);
|
||||
}
|
||||
},
|
||||
|
||||
onProgressChange : function (aWebProgress, aRequest,
|
||||
aCurSelfProgress, aMaxSelfProgress,
|
||||
aCurTotalProgress, aMaxTotalProgress)
|
||||
{
|
||||
if (!this.useRealProgressFlag && aRequest)
|
||||
return;
|
||||
|
||||
if (aMaxTotalProgress > 0) {
|
||||
// This is highly optimized. Don't touch this code unless
|
||||
// you are intimately familiar with the cost of setting
|
||||
// attrs on XUL elements. -- hyatt
|
||||
var percentage = (aCurTotalProgress * 100) / aMaxTotalProgress;
|
||||
this.statusMeter.value = percentage;
|
||||
}
|
||||
},
|
||||
|
||||
onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
|
||||
{
|
||||
//ignore local/resource:/chrome: files
|
||||
if (aStatus == NS_NET_STATUS_READ_FROM || aStatus == NS_NET_STATUS_WROTE_TO)
|
||||
return;
|
||||
|
||||
const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
|
||||
const nsIChannel = Components.interfaces.nsIChannel;
|
||||
var ctype;
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_START) {
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
|
||||
if (aRequest && aWebProgress.DOMWindow == content)
|
||||
this.startDocumentLoad(aRequest);
|
||||
|
||||
// Turn the throbber on.
|
||||
this.throbberElement.setAttribute("busy", true);
|
||||
|
||||
// XXX: This needs to be based on window activity...
|
||||
this.stopCmd.removeAttribute("disabled");
|
||||
|
||||
// Initialize the progress stuff...
|
||||
this.useRealProgressFlag = false;
|
||||
this.totalRequests = 0;
|
||||
this.finishedRequests = 0;
|
||||
}
|
||||
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_REQUEST) {
|
||||
this.totalRequests += 1;
|
||||
}
|
||||
}
|
||||
else if (aStateFlags & nsIWebProgressListener.STATE_STOP) {
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_REQUEST) {
|
||||
this.finishedRequests += 1;
|
||||
if (!this.useRealProgressFlag)
|
||||
this.onProgressChange(null, null, 0, 0, this.finishedRequests, this.totalRequests);
|
||||
}
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
|
||||
if (aRequest) {
|
||||
if (aWebProgress.DOMWindow == content)
|
||||
this.endDocumentLoad(aRequest, aStatus);
|
||||
|
||||
var location = aRequest.QueryInterface(nsIChannel).URI.spec;
|
||||
this.status = "";
|
||||
if (location != "about:blank")
|
||||
this.setDefaultStatus(gNavigatorBundle.getString("nv_done"));
|
||||
try {
|
||||
ctype = aRequest.QueryInterface(nsIChannel).contentType;
|
||||
if (this.mimeTypeIsTextBased(ctype))
|
||||
this.isImage.removeAttribute('disabled');
|
||||
else
|
||||
this.isImage.setAttribute('disabled', 'true');
|
||||
}
|
||||
catch (e) {}
|
||||
}
|
||||
|
||||
// Turn the progress meter and throbber off.
|
||||
this.statusMeter.value = 0; // be sure to clear the progress bar
|
||||
this.throbberElement.removeAttribute("busy");
|
||||
|
||||
// XXX: This needs to be based on window activity...
|
||||
this.stopCmd.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
else if (aStateFlags & nsIWebProgressListener.STATE_TRANSFERRING) {
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_DOCUMENT) {
|
||||
ctype = aRequest.QueryInterface(nsIChannel).contentType;
|
||||
|
||||
if (ctype != "text/html")
|
||||
this.useRealProgressFlag = true;
|
||||
}
|
||||
|
||||
if (aStateFlags & nsIWebProgressListener.STATE_IS_REQUEST) {
|
||||
if (!this.useRealProgressFlag)
|
||||
this.onProgressChange(null, null, 0, 0, this.finishedRequests, this.totalRequests);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onLocationChange : function(aWebProgress, aRequest, aLocation)
|
||||
{
|
||||
this.setOverLink("", null);
|
||||
|
||||
var location = aLocation.spec;
|
||||
|
||||
if (this.hideAboutBlank) {
|
||||
this.hideAboutBlank = false;
|
||||
if (location == "about:blank")
|
||||
location = "";
|
||||
}
|
||||
|
||||
// Disable menu entries for images, enable otherwise
|
||||
if (this.mimeTypeIsTextBased(content.document.contentType))
|
||||
this.isImage.removeAttribute('disabled');
|
||||
else
|
||||
this.isImage.setAttribute('disabled', 'true');
|
||||
|
||||
// We should probably not do this if the value has changed since the user
|
||||
// searched
|
||||
// Update urlbar only if a new page was loaded on the primary content area
|
||||
// Do not update urlbar if there was a subframe navigation
|
||||
|
||||
if (aWebProgress.DOMWindow == content) {
|
||||
if (!this.userTyped.value) {
|
||||
// If the url has "wyciwyg://" as the protocol, strip it off.
|
||||
// Nobody wants to see it on the urlbar for dynamically generated
|
||||
// pages.
|
||||
if (/^\s*wyciwyg:\/\/\d+\//.test(location))
|
||||
location = RegExp.rightContext;
|
||||
this.urlBar.value = location;
|
||||
// the above causes userTyped.value to become true, reset it
|
||||
this.userTyped.value = false;
|
||||
}
|
||||
|
||||
SetPageProxyState("valid", aLocation);
|
||||
}
|
||||
UpdateBackForwardButtons();
|
||||
},
|
||||
|
||||
onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
|
||||
{
|
||||
//ignore local/resource:/chrome: files
|
||||
if (aStatus == NS_NET_STATUS_READ_FROM || aStatus == NS_NET_STATUS_WROTE_TO)
|
||||
return;
|
||||
|
||||
this.status = aMessage;
|
||||
|
||||
if (!this.statusTimeoutInEffect) {
|
||||
this.statusTimeoutInEffect = true;
|
||||
this.updateStatusField();
|
||||
setTimeout(function(aClosure) { aClosure.updateStatusField();
|
||||
aClosure.statusTimeoutInEffect = false; },
|
||||
400, this);
|
||||
}
|
||||
},
|
||||
|
||||
onSecurityChange : function(aWebProgress, aRequest, aState)
|
||||
{
|
||||
const wpl = Components.interfaces.nsIWebProgressListener;
|
||||
|
||||
switch (aState) {
|
||||
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_HIGH:
|
||||
this.securityButton.setAttribute("level", "high");
|
||||
break;
|
||||
case wpl.STATE_IS_SECURE | wpl.STATE_SECURE_LOW:
|
||||
this.securityButton.setAttribute("level", "low");
|
||||
break;
|
||||
case wpl.STATE_IS_BROKEN:
|
||||
this.securityButton.setAttribute("level", "broken");
|
||||
break;
|
||||
case wpl.STATE_IS_INSECURE:
|
||||
default:
|
||||
this.securityButton.removeAttribute("level");
|
||||
break;
|
||||
}
|
||||
|
||||
var securityUI = getBrowser().securityUI;
|
||||
if (securityUI)
|
||||
this.securityButton.setAttribute("tooltiptext", securityUI.tooltipText);
|
||||
else
|
||||
this.securityButton.removeAttribute("tooltiptext");
|
||||
},
|
||||
|
||||
startDocumentLoad : function(aRequest)
|
||||
{
|
||||
// Reset so we can see if the user typed after the document load
|
||||
// starting and the location changing.
|
||||
this.userTyped.value = false;
|
||||
|
||||
const nsIChannel = Components.interfaces.nsIChannel;
|
||||
var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
|
||||
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
try {
|
||||
observerService.notifyObservers(_content, "StartDocumentLoad", urlStr);
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
|
||||
endDocumentLoad : function(aRequest, aStatus)
|
||||
{
|
||||
const nsIChannel = Components.interfaces.nsIChannel;
|
||||
var urlStr = aRequest.QueryInterface(nsIChannel).originalURI.spec;
|
||||
|
||||
if (Components.isSuccessCode(aStatus))
|
||||
dump("Document "+urlStr+" loaded successfully\n"); // per QA request
|
||||
else {
|
||||
// per QA request
|
||||
var e = new Components.Exception("", aStatus);
|
||||
var name = e.name;
|
||||
dump("Error loading URL "+urlStr+" : "+
|
||||
Number(aStatus).toString(16));
|
||||
if (name)
|
||||
dump(" ("+name+")");
|
||||
dump('\n');
|
||||
}
|
||||
|
||||
var observerService = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
|
||||
var notification = Components.isSuccessCode(aStatus) ? "EndDocumentLoad" : "FailDocumentLoad";
|
||||
try {
|
||||
observerService.notifyObservers(_content, notification, urlStr);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,487 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@netscape.com> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
var gBookmarksShell = null;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Class which defines methods for a bookmarks UI implementation based around
|
||||
// a toolbar. Subclasses BookmarksBase in bookmarksOverlay.js. Some methods
|
||||
// are required by the base class, others are for event handling. Window specific
|
||||
// glue code should go into the BookmarksWindow class in bookmarks.js
|
||||
function BookmarksToolbar (aID)
|
||||
{
|
||||
this.id = aID;
|
||||
}
|
||||
|
||||
BookmarksToolbar.prototype = {
|
||||
__proto__: BookmarksUIElement.prototype,
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Personal Toolbar Specific Stuff
|
||||
|
||||
get db ()
|
||||
{
|
||||
return this.element.database;
|
||||
},
|
||||
|
||||
get element ()
|
||||
{
|
||||
return document.getElementById(this.id);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// This method constructs a menuitem for a context menu for the given command.
|
||||
// This is implemented by the client so that it can intercept menuitem naming
|
||||
// as appropriate.
|
||||
createMenuItem: function (aDisplayName, aCommandName, aItemNode)
|
||||
{
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
var xulElement = document.createElementNS(kXULNS, "menuitem");
|
||||
xulElement.setAttribute("cmd", aCommandName);
|
||||
var cmd = "cmd_" + aCommandName.substring(NC_NS_CMD.length)
|
||||
xulElement.setAttribute("command", cmd);
|
||||
|
||||
switch (aCommandName) {
|
||||
case NC_NS_CMD + "bm_open":
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
xulElement.setAttribute("default", "true");
|
||||
break;
|
||||
case NC_NS_CMD + "bm_openfolder":
|
||||
xulElement.setAttribute("default", "true");
|
||||
if (aItemNode.localName == "hbox")
|
||||
// Don't show an "Open Folder" item for clicks on the toolbar itself.
|
||||
return null;
|
||||
default:
|
||||
xulElement.setAttribute("label", aDisplayName);
|
||||
break;
|
||||
}
|
||||
return xulElement;
|
||||
},
|
||||
|
||||
// Command implementation
|
||||
commands: {
|
||||
openFolder: function (aSelectedItem)
|
||||
{
|
||||
var mbo = aSelectedItem.boxObject.QueryInterface(Components.interfaces.nsIMenuBoxObject);
|
||||
mbo.openMenu(true);
|
||||
},
|
||||
|
||||
editCell: function (aSelectedItem, aXXXLameAssIndex)
|
||||
{
|
||||
goDoCommand("cmd_bm_properties");
|
||||
return; // Disable Inline Edit for now. See bug 77125 for why this is being disabled
|
||||
// on the personal toolbar for the moment.
|
||||
|
||||
if (aSelectedItem.getAttribute("editable") != "true")
|
||||
return;
|
||||
var property = "http://home.netscape.com/NC-rdf#Name";
|
||||
aSelectedItem.setMode("edit");
|
||||
aSelectedItem.addObserver(this.postModifyCallback, "accept",
|
||||
[gBookmarksShell, aSelectedItem, property]);
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Called after an inline-edit cell has left inline-edit mode, and data
|
||||
// needs to be modified in the datasource.
|
||||
postModifyCallback: function (aParams)
|
||||
{
|
||||
var aShell = aParams[0];
|
||||
var selItemURI = NODE_ID(aParams[1]);
|
||||
aShell.propertySet(selItemURI, aParams[2], aParams[3]);
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Creates a dummy item that can be placed in edit mode to retrieve data
|
||||
// to create new bookmarks/folders.
|
||||
createBookmarkItem: function (aMode, aSelectedItem)
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// HACK HACK HACK HACK HACK
|
||||
// Disable Inline-Edit for now and just use a dialog.
|
||||
|
||||
// XXX - most of this is just copy-pasted from the other two folder
|
||||
// creation functions. Yes it's ugly, but it'll do the trick for
|
||||
// now as this is in no way intended to be a long-term solution.
|
||||
|
||||
const kPromptSvcContractID = "@mozilla.org/embedcomp/prompt-service;1";
|
||||
const kPromptSvcIID = Components.interfaces.nsIPromptService;
|
||||
const kPromptSvc = Components.classes[kPromptSvcContractID].getService(kPromptSvcIID);
|
||||
|
||||
var defaultValue = gBookmarksShell.getLocaleString("ile_newfolder");
|
||||
var dialogTitle = gBookmarksShell.getLocaleString("newfolder_dialog_title");
|
||||
var dialogMsg = gBookmarksShell.getLocaleString("newfolder_dialog_msg");
|
||||
var stringValue = { value: defaultValue };
|
||||
if (kPromptSvc.prompt(window, dialogTitle, dialogMsg, stringValue, null, { value: 0 })) {
|
||||
var relativeNode = aSelectedItem || gBookmarksShell.element;
|
||||
var parentNode = relativeNode ? gBookmarksShell.findRDFNode(relativeNode, false) : gBookmarksShell.element;
|
||||
|
||||
var args = [{ property: NC_NS + "parent",
|
||||
resource: NODE_ID(parentNode) },
|
||||
{ property: NC_NS + "Name",
|
||||
literal: stringValue.value }];
|
||||
|
||||
const kBMDS = gBookmarksShell.RDF.GetDataSource("rdf:bookmarks");
|
||||
var relId = relativeNode ? NODE_ID(relativeNode) : "NC:PersonalToolbarFolder";
|
||||
BookmarksUtils.doBookmarksCommand(relId, NC_NS_CMD + "newfolder", args);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// HACK HACK HACK HACK HACK
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const kXULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
var dummyButton = document.createElementNS(kXULNS, "menubutton");
|
||||
dummyButton = gBookmarksShell.createBookmarkFolderDecorations(dummyButton);
|
||||
dummyButton.setAttribute("class", "button-toolbar bookmark-item");
|
||||
|
||||
dummyButton.setAttribute("label", gBookmarksShell.getLocaleString("ile_newfolder") + " ");
|
||||
// By default, create adjacent to the selected button. If there is no button after
|
||||
// the selected button, or the target is the toolbar itself, just append.
|
||||
var bIsButton = aSelectedItem.localName == "button" || aSelectedItem.localName == "menubutton";
|
||||
if (aSelectedItem.nextSibling && bIsButton)
|
||||
aSelectedItem.parentNode.insertBefore(dummyButton, aSelectedItem.nextSibling);
|
||||
else
|
||||
(bIsButton ? aSelectedItem.parentNode : aSelectedItem).appendChild(dummyButton);
|
||||
|
||||
gBookmarksShell._focusElt = document.commandDispatcher.focusedElement;
|
||||
dummyButton.setMode("edit");
|
||||
// |aSelectedItem| will be the node we create the new folder relative to.
|
||||
dummyButton.addObserver(this.onEditFolderName, "accept",
|
||||
[dummyButton, aSelectedItem, dummyButton]);
|
||||
dummyButton.addObserver(this.onEditFolderName, "reject",
|
||||
[dummyButton, aSelectedItem, dummyButton]);
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Edit folder name & update the datasource if name is valid
|
||||
onEditFolderName: function (aParams, aTopic)
|
||||
{
|
||||
// Because the toolbar has no concept of selection, this function
|
||||
// is much simpler than the one in bookmarksTree.js. However it may
|
||||
// become more complex if pink ever lets me put context menus on menus ;)
|
||||
var name = aParams[3];
|
||||
var dummyButton = aParams[2];
|
||||
var relativeNode = aParams[1];
|
||||
var parentNode = gBookmarksShell.findRDFNode(relativeNode, false);
|
||||
|
||||
dummyButton.parentNode.removeChild(dummyButton);
|
||||
|
||||
if (!gBookmarksShell.commands.validateNameAndTopic(name, aTopic, relativeNode, dummyButton))
|
||||
return;
|
||||
|
||||
parentNode = relativeNode.parentNode;
|
||||
if (relativeNode.localName == "hbox") {
|
||||
parentNode = relativeNode;
|
||||
relativeNode = (gBookmarksShell.commands.nodeIsValidType(relativeNode) &&
|
||||
relativeNode.lastChild) || relativeNode;
|
||||
}
|
||||
|
||||
var args = [{ property: NC_NS + "parent",
|
||||
resource: NODE_ID(parentNode) },
|
||||
{ property: NC_NS + "Name",
|
||||
literal: name }];
|
||||
|
||||
BookmarksUtils.doBookmarksCommand(NODE_ID(relativeNode),
|
||||
NC_NS_CMD + "newfolder", args);
|
||||
// We need to do this because somehow focus shifts and no commands
|
||||
// operate any more.
|
||||
//gBookmarksShell._focusElt.focus();
|
||||
},
|
||||
|
||||
nodeIsValidType: function (aNode)
|
||||
{
|
||||
switch (aNode.localName) {
|
||||
case "button":
|
||||
case "menubutton":
|
||||
// case "menu":
|
||||
// case "menuitem":
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Performs simple validation on what the user has entered:
|
||||
// 1) prevents entering an empty string
|
||||
// 2) in the case of a canceled operation, remove the dummy item and
|
||||
// restore selection.
|
||||
validateNameAndTopic: function (aName, aTopic, aOldSelectedItem, aDummyItem)
|
||||
{
|
||||
// Don't allow user to enter an empty string "";
|
||||
if (!aName) return false;
|
||||
|
||||
// If the user hit escape, go no further.
|
||||
return !(aTopic == "reject");
|
||||
}
|
||||
},
|
||||
|
||||
_focusElt: null,
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Evaluates an event to determine whether or not it affords opening a tree
|
||||
// item. Typically, this is when the left mouse button is used, and provided
|
||||
// the click-rate matches that specified by our owning tree class. For example,
|
||||
// some trees open an item when double clicked (bookmarks/history windows) and
|
||||
// others on a single click (sidebar panels).
|
||||
isValidOpenEvent: function (aEvent)
|
||||
{
|
||||
return !(aEvent.type == "click" &&
|
||||
(aEvent.button != 0 || aEvent.detail != this.openClickCount))
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For the given selection, selects the best adjacent element. This method is
|
||||
// useful when an action such as a cut or a deletion is performed on a
|
||||
// selection, and focus/selection needs to be restored after the operation
|
||||
// is performed.
|
||||
getNextElement: function (aElement)
|
||||
{
|
||||
if (aElement.nextSibling)
|
||||
return aElement.nextSibling;
|
||||
else if (aElement.previousSibling)
|
||||
return aElement.previousSibling;
|
||||
else
|
||||
return aElement.parentNode;
|
||||
},
|
||||
|
||||
selectElement: function (aElement)
|
||||
{
|
||||
},
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Add the treeitem element specified by aURI to the tree's current selection.
|
||||
addItemToSelection: function (aURI)
|
||||
{
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Return a set of DOM nodes that represents the current item in the Bookmarks
|
||||
// Toolbar. This is always |document.popupNode|.
|
||||
getSelection: function ()
|
||||
{
|
||||
return [document.popupNode];
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Return a set of DOM nodes that represent the selection in the tree widget.
|
||||
// This method is takes a node parameter which is the popupNode for the
|
||||
// document. If the popupNode is not contained by the selection, the
|
||||
// popupNode is selected and the new selection returned.
|
||||
getContextSelection: function (aItemNode)
|
||||
{
|
||||
return [aItemNode];
|
||||
},
|
||||
|
||||
getSelectedFolder: function ()
|
||||
{
|
||||
return "NC:PersonalToolbarFolder";
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// For a given start DOM element, find the enclosing DOM element that contains
|
||||
// the template builder RDF resource decorations (id, ref, etc). In the
|
||||
// Toolbar case, this is always the popup node (until we're proven wrong ;)
|
||||
findRDFNode: function (aStartNode, aIncludeStartNodeFlag)
|
||||
{
|
||||
var temp = aStartNode;
|
||||
while (temp && temp.localName != (aIncludeStartNodeFlag ? "toolbarbutton" : "hbox"))
|
||||
temp = temp.parentNode;
|
||||
return temp || this.element;
|
||||
},
|
||||
|
||||
selectFolderItem: function (aFolderURI, aItemURI, aAdditiveFlag)
|
||||
{
|
||||
var folder = document.getElementById(aFolderURI);
|
||||
var kids = ContentUtils.childByLocalName(folder, "treechildren");
|
||||
if (!kids) return;
|
||||
|
||||
var item = kids.firstChild;
|
||||
while (item) {
|
||||
if (item.id == aItemURI) break;
|
||||
item = item.nextSibling;
|
||||
}
|
||||
if (!item) return;
|
||||
|
||||
this.tree[aAdditiveFlag ? "addItemToSelection" : "selectItem"](item);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Command handling & Updating.
|
||||
controller: {
|
||||
supportsCommand: function (aCommand)
|
||||
{
|
||||
switch(aCommand) {
|
||||
case "cmd_bm_undo":
|
||||
case "cmd_bm_redo":
|
||||
return false;
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_paste":
|
||||
case "cmd_bm_delete":
|
||||
case "cmd_bm_selectAll":
|
||||
case "cmd_bm_open":
|
||||
case "cmd_bm_openfolder":
|
||||
case "cmd_bm_openinnewwindow":
|
||||
case "cmd_bm_newbookmark":
|
||||
case "cmd_bm_newfolder":
|
||||
case "cmd_bm_newseparator":
|
||||
case "cmd_bm_find":
|
||||
case "cmd_bm_properties":
|
||||
case "cmd_bm_rename":
|
||||
case "cmd_bm_setnewbookmarkfolder":
|
||||
case "cmd_bm_setpersonaltoolbarfolder":
|
||||
case "cmd_bm_setnewsearchfolder":
|
||||
case "cmd_bm_import":
|
||||
case "cmd_bm_export":
|
||||
case "cmd_bm_fileBookmark":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
isCommandEnabled: function (aCommand)
|
||||
{
|
||||
switch(aCommand) {
|
||||
case "cmd_bm_undo":
|
||||
case "cmd_bm_redo":
|
||||
return false;
|
||||
case "cmd_bm_paste":
|
||||
var cp = gBookmarksShell.canPaste();
|
||||
return cp;
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_delete":
|
||||
return (document.popupNode != null) && (NODE_ID(document.popupNode) != "NC:PersonalToolbarFolder");
|
||||
case "cmd_bm_selectAll":
|
||||
return false;
|
||||
case "cmd_bm_open":
|
||||
var seln = gBookmarksShell.getSelection();
|
||||
return document.popupNode != null && seln[0].getAttributeNS(RDF_NS, "type") == NC_NS + "Bookmark";
|
||||
case "cmd_bm_openfolder":
|
||||
seln = gBookmarksShell.getSelection();
|
||||
return document.popupNode != null && seln[0].getAttributeNS(RDF_NS, "type") == NC_NS + "Folder";
|
||||
case "cmd_bm_openinnewwindow":
|
||||
return true;
|
||||
case "cmd_bm_find":
|
||||
case "cmd_bm_newbookmark":
|
||||
case "cmd_bm_newfolder":
|
||||
case "cmd_bm_newseparator":
|
||||
case "cmd_bm_import":
|
||||
case "cmd_bm_export":
|
||||
return true;
|
||||
case "cmd_bm_properties":
|
||||
case "cmd_bm_rename":
|
||||
return document.popupNode != null;
|
||||
case "cmd_bm_setnewbookmarkfolder":
|
||||
seln = gBookmarksShell.getSelection();
|
||||
if (!seln.length) return false;
|
||||
var folderType = seln[0].getAttributeNS(RDF_NS, "type") == (NC_NS + "Folder");
|
||||
return document.popupNode != null && !(NODE_ID(seln[0]) == "NC:NewBookmarkFolder") && folderType;
|
||||
case "cmd_bm_setpersonaltoolbarfolder":
|
||||
seln = gBookmarksShell.getSelection();
|
||||
if (!seln.length) return false;
|
||||
folderType = seln[0].getAttributeNS(RDF_NS, "type") == (NC_NS + "Folder");
|
||||
return document.popupNode != null && !(NODE_ID(seln[0]) == "NC:PersonalToolbarFolder") && folderType;
|
||||
case "cmd_bm_setnewsearchfolder":
|
||||
seln = gBookmarksShell.getSelection();
|
||||
if (!seln.length) return false;
|
||||
folderType = seln[0].getAttributeNS(RDF_NS, "type") == (NC_NS + "Folder");
|
||||
return document.popupNode != null && !(NODE_ID(seln[0]) == "NC:NewSearchFolder") && folderType;
|
||||
case "cmd_bm_fileBookmark":
|
||||
seln = gBookmarksShell.getSelection();
|
||||
return seln.length > 0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
doCommand: function (aCommand)
|
||||
{
|
||||
switch(aCommand) {
|
||||
case "cmd_bm_undo":
|
||||
case "cmd_bm_redo":
|
||||
break;
|
||||
case "cmd_bm_paste":
|
||||
case "cmd_bm_copy":
|
||||
case "cmd_bm_cut":
|
||||
case "cmd_bm_delete":
|
||||
case "cmd_bm_newbookmark":
|
||||
case "cmd_bm_newfolder":
|
||||
case "cmd_bm_newseparator":
|
||||
case "cmd_bm_properties":
|
||||
case "cmd_bm_rename":
|
||||
case "cmd_bm_open":
|
||||
case "cmd_bm_openfolder":
|
||||
case "cmd_bm_openinnewwindow":
|
||||
case "cmd_bm_setnewbookmarkfolder":
|
||||
case "cmd_bm_setpersonaltoolbarfolder":
|
||||
case "cmd_bm_setnewsearchfolder":
|
||||
case "cmd_bm_find":
|
||||
case "cmd_bm_import":
|
||||
case "cmd_bm_export":
|
||||
case "cmd_bm_fileBookmark":
|
||||
gBookmarksShell.execCommand(aCommand.substring("cmd_".length));
|
||||
break;
|
||||
case "cmd_bm_selectAll":
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
onEvent: function (aEvent)
|
||||
{
|
||||
},
|
||||
|
||||
onCommandUpdate: function ()
|
||||
{
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function BM_navigatorLoad(aEvent)
|
||||
{
|
||||
if (!gBookmarksShell) {
|
||||
gBookmarksShell = new BookmarksToolbar("innermostBox");
|
||||
controllers.appendController(gBookmarksShell.controller);
|
||||
removeEventListener("load", BM_navigatorLoad, false);
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener("load", BM_navigatorLoad, false);
|
||||
|
||||
@ -1,317 +0,0 @@
|
||||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Jason Eager <jce2@po.cwru.edu>
|
||||
* Blake Ross <BlakeR1234@aol.com>
|
||||
* Peter Annema <disttsc@bart.nl>
|
||||
* Dean Tessman <dean_tessman@hotmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
const MAX_HISTORY_MENU_ITEMS = 15;
|
||||
const MAX_HISTORY_ITEMS = 100;
|
||||
var gRDF = null;
|
||||
var gRDFC = null;
|
||||
var gGlobalHistory = null;
|
||||
var gURIFixup = null;
|
||||
var gLocalStore = null;
|
||||
|
||||
function FillHistoryMenu(aParent, aMenu)
|
||||
{
|
||||
// Remove old entries if any
|
||||
deleteHistoryItems(aParent);
|
||||
|
||||
var sessionHistory = getWebNavigation().sessionHistory;
|
||||
|
||||
var count = sessionHistory.count;
|
||||
var index = sessionHistory.index;
|
||||
var end;
|
||||
var j;
|
||||
var entry;
|
||||
|
||||
switch (aMenu)
|
||||
{
|
||||
case "back":
|
||||
end = (index > MAX_HISTORY_MENU_ITEMS) ? index - MAX_HISTORY_MENU_ITEMS : 0;
|
||||
if ((index - 1) < end) return false;
|
||||
for (j = index - 1; j >= end; j--)
|
||||
{
|
||||
entry = sessionHistory.getEntryAtIndex(j, false);
|
||||
if (entry)
|
||||
createMenuItem(aParent, j, entry.title);
|
||||
}
|
||||
break;
|
||||
case "forward":
|
||||
end = ((count-index) > MAX_HISTORY_MENU_ITEMS) ? index + MAX_HISTORY_MENU_ITEMS : count;
|
||||
if ((index + 1) >= end) return false;
|
||||
for (j = index + 1; j < end; j++)
|
||||
{
|
||||
entry = sessionHistory.getEntryAtIndex(j, false);
|
||||
if (entry)
|
||||
createMenuItem(aParent, j, entry.title);
|
||||
}
|
||||
break;
|
||||
case "go":
|
||||
if (count > 0) aParent.lastChild.removeAttribute( "hidden" );
|
||||
end = count > MAX_HISTORY_MENU_ITEMS ? count - MAX_HISTORY_MENU_ITEMS : 0;
|
||||
for (j = count - 1; j >= end; j--)
|
||||
{
|
||||
entry = sessionHistory.getEntryAtIndex(j, false);
|
||||
if (entry)
|
||||
createRadioMenuItem(aParent, j, entry.title, j==index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function executeUrlBarHistoryCommand( aTarget )
|
||||
{
|
||||
var index = aTarget.getAttribute("index");
|
||||
var label = aTarget.getAttribute("label");
|
||||
if (index != "nothing_available" && label)
|
||||
{
|
||||
var uri = getShortcutOrURI(label);
|
||||
if (gURLBar) {
|
||||
gURLBar.value = uri;
|
||||
addToUrlbarHistory();
|
||||
BrowserLoadURL();
|
||||
}
|
||||
else
|
||||
loadURI(uri);
|
||||
}
|
||||
}
|
||||
|
||||
function createUBHistoryMenu( aParent )
|
||||
{
|
||||
if (!gRDF)
|
||||
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
if (!gLocalStore)
|
||||
gLocalStore = gRDF.GetDataSource("rdf:local-store");
|
||||
|
||||
if (gLocalStore) {
|
||||
if (!gRDFC)
|
||||
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
||||
.getService(Components.interfaces.nsIRDFContainerUtils);
|
||||
|
||||
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history")).GetElements();
|
||||
var i= MAX_HISTORY_MENU_ITEMS;
|
||||
|
||||
// Delete any old menu items only if there are legitimate
|
||||
// urls to display, otherwise we want to display the
|
||||
// '(Nothing Available)' item.
|
||||
deleteHistoryItems(aParent);
|
||||
if (!entries.hasMoreElements()) {
|
||||
//Create the "Nothing Available" Menu item and disable it.
|
||||
var na = gNavigatorBundle.getString("nothingAvailable");
|
||||
createMenuItem(aParent, "nothing_available", na);
|
||||
aParent.firstChild.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
while (entries.hasMoreElements() && (i-- > 0)) {
|
||||
var entry = entries.getNext();
|
||||
if (entry) {
|
||||
try {
|
||||
entry = entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
} catch(ex) {
|
||||
// XXXbar not an nsIRDFLiteral for some reason. see 90337.
|
||||
continue;
|
||||
}
|
||||
var url = entry.Value;
|
||||
createMenuItem(aParent, i, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addToUrlbarHistory()
|
||||
{
|
||||
var urlToAdd = gURLBar.value;
|
||||
if (!urlToAdd)
|
||||
return;
|
||||
if (urlToAdd.search(/[\x00-\x1F]/) != -1) // don't store bad URLs
|
||||
return;
|
||||
|
||||
if (!gRDF)
|
||||
gRDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
|
||||
if (!gGlobalHistory)
|
||||
gGlobalHistory = Components.classes["@mozilla.org/browser/global-history;1"]
|
||||
.getService(Components.interfaces.nsIBrowserHistory);
|
||||
|
||||
if (!gURIFixup)
|
||||
gURIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
||||
.getService(Components.interfaces.nsIURIFixup);
|
||||
if (!gLocalStore)
|
||||
gLocalStore = gRDF.GetDataSource("rdf:local-store");
|
||||
|
||||
if (gLocalStore) {
|
||||
if (!gRDFC)
|
||||
gRDFC = Components.classes["@mozilla.org/rdf/container-utils;1"]
|
||||
.getService(Components.interfaces.nsIRDFContainerUtils);
|
||||
|
||||
var entries = gRDFC.MakeSeq(gLocalStore, gRDF.GetResource("nc:urlbar-history"));
|
||||
if (!entries)
|
||||
return;
|
||||
var elements = entries.GetElements();
|
||||
if (!elements)
|
||||
return;
|
||||
var index = 0;
|
||||
// create the nsIURI objects for comparing the 2 urls
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
|
||||
var entryToAdd = gRDF.GetLiteral(urlToAdd);
|
||||
|
||||
try {
|
||||
ioService.extractScheme(urlToAdd, {}, {});
|
||||
} catch(e) {
|
||||
urlToAdd = "http://" + urlToAdd;
|
||||
}
|
||||
|
||||
try {
|
||||
var uriToAdd = ioService.newURI(urlToAdd, null, null);
|
||||
}
|
||||
catch(e) {
|
||||
// it isn't a valid url
|
||||
// we'll leave uriToAdd as "undefined" and handle that later
|
||||
}
|
||||
|
||||
while(elements.hasMoreElements()) {
|
||||
var entry = elements.getNext();
|
||||
if (!entry) continue;
|
||||
|
||||
index ++;
|
||||
try {
|
||||
entry = entry.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
} catch(ex) {
|
||||
// XXXbar not an nsIRDFLiteral for some reason. see 90337.
|
||||
continue;
|
||||
}
|
||||
var rdfValue = entry.Value;
|
||||
|
||||
try {
|
||||
ioService.extractScheme(rdfValue, {}, {});
|
||||
} catch(e) {
|
||||
rdfValue = "http://" + rdfValue;
|
||||
}
|
||||
|
||||
if (uriToAdd) {
|
||||
try {
|
||||
var rdfUri = ioService.newURI(rdfValue, null, null);
|
||||
|
||||
if (rdfUri.equals(uriToAdd)) {
|
||||
// URI already present in the database
|
||||
// Remove it from its current position.
|
||||
// It is inserted to the top after the while loop.
|
||||
entries.RemoveElementAt(index, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// the uri is still not recognized by the ioservice
|
||||
catch(ex) {
|
||||
// no problem, we'll handle this below
|
||||
}
|
||||
}
|
||||
|
||||
// if we got this far, then something is funky with the URIs,
|
||||
// so we need to do a straight string compare of the raw strings
|
||||
if (urlToAdd == rdfValue) {
|
||||
entries.RemoveElementAt(index, true);
|
||||
break;
|
||||
}
|
||||
} // while
|
||||
|
||||
// Otherwise, we've got a new URL in town. Add it!
|
||||
|
||||
try {
|
||||
var url = entryToAdd.Value;
|
||||
if (url.indexOf(" ") == -1) {
|
||||
var fixedUpURI = gURIFixup.createFixupURI(url, 0);
|
||||
gGlobalHistory.markPageAsTyped(fixedUpURI.spec);
|
||||
}
|
||||
}
|
||||
catch(ex) {
|
||||
}
|
||||
|
||||
// Put the value as it was typed by the user in to RDF
|
||||
// Insert it to the beginning of the list.
|
||||
entries.InsertElementAt(entryToAdd, 1, true);
|
||||
|
||||
// Remove any expired history items so that we don't let
|
||||
// this grow without bound.
|
||||
for (index = entries.GetCount(); index > MAX_HISTORY_ITEMS; --index) {
|
||||
entries.RemoveElementAt(index, true);
|
||||
} // for
|
||||
} // localstore
|
||||
}
|
||||
|
||||
function createMenuItem( aParent, aIndex, aLabel)
|
||||
{
|
||||
var menuitem = document.createElement( "menuitem" );
|
||||
menuitem.setAttribute( "label", aLabel );
|
||||
menuitem.setAttribute( "index", aIndex );
|
||||
aParent.appendChild( menuitem );
|
||||
}
|
||||
|
||||
function createRadioMenuItem( aParent, aIndex, aLabel, aChecked)
|
||||
{
|
||||
var menuitem = document.createElement( "menuitem" );
|
||||
menuitem.setAttribute( "type", "radio" );
|
||||
menuitem.setAttribute( "label", aLabel );
|
||||
menuitem.setAttribute( "index", aIndex );
|
||||
if (aChecked==true)
|
||||
menuitem.setAttribute( "checked", "true" );
|
||||
aParent.appendChild( menuitem );
|
||||
}
|
||||
|
||||
function deleteHistoryItems(aParent)
|
||||
{
|
||||
var children = aParent.childNodes;
|
||||
for (var i = 0; i < children.length; i++ )
|
||||
{
|
||||
var index = children[i].getAttribute( "index" );
|
||||
if (index)
|
||||
aParent.removeChild( children[i] );
|
||||
}
|
||||
}
|
||||
|
||||
function updateGoMenu(event)
|
||||
{
|
||||
FillHistoryMenu(event.target, "go");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user