зеркало из https://github.com/mozilla/pjs.git
Bug 139471 Rewrite of the personal toolbar drag and drop observer patch=pierrechanial@netscape.net, r=timeless, sr=ben
(maybe you should increment the version number to 2.1)
This commit is contained in:
Родитель
091b464071
Коммит
76dc6d81ed
|
@ -235,21 +235,23 @@ Contributor(s): ______________________________________. -->
|
|||
</hbox>
|
||||
</toolbar>
|
||||
|
||||
<toolbar id="PersonalToolbar" class="chromeclass-directories" persist="collapsed" dragdroparea="innermostBox"
|
||||
ondragover="nsDragAndDrop.dragOver(event, personalToolbarObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, personalToolbarObserver);"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, personalToolbarObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, personalToolbarObserver);"
|
||||
grippytooltiptext="&personalToolbar.tooltip;"
|
||||
tbalign="stretch">
|
||||
<toolbar id="PersonalToolbar" class="chromeclass-directories" persist="collapsed"
|
||||
grippytooltiptext="&personalToolbar.tooltip;" tbalign="stretch"
|
||||
oncommand="OpenBookmarkURL(event.target,document.getElementById('BookmarksMenu').database)"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, personalToolbarDNDObserver)"
|
||||
ondragdrop="nsDragAndDrop.drop(event, personalToolbarDNDObserver); event.preventBubble()"
|
||||
ondragenter="nsDragAndDrop.dragEnter(event, personalToolbarDNDObserver); event.preventBubble()"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, personalToolbarDNDObserver); event.preventBubble()"
|
||||
ondragover="nsDragAndDrop.dragOver(event, personalToolbarDNDObserver); event.preventBubble()">
|
||||
|
||||
<toolbarbutton id="home-button" class="bookmark-item"
|
||||
label="&homeButton.label;" persist="hidden"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, homeButtonObserver);"
|
||||
ondragover="nsDragAndDrop.dragOver(event, homeButtonObserver);"
|
||||
ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver);"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, homeButtonObserver);"
|
||||
oncommand="BrowserHome(); event.preventBubble();"/>
|
||||
oncommand="BrowserHome(); event.preventBubble()"
|
||||
ondraggesture="nsDragAndDrop.startDrag(event, homeButtonObserver)"
|
||||
ondragdrop="nsDragAndDrop.drop(event, homeButtonObserver); event.preventBubble()"
|
||||
ondragenter="event.preventBubble()"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, homeButtonObserver); event.preventBubble()"
|
||||
ondragover="nsDragAndDrop.dragOver(event, homeButtonObserver); event.preventBubble()"/>
|
||||
|
||||
<toolbarseparator id="home-bm-separator" persist="hidden"/>
|
||||
|
||||
|
@ -258,21 +260,13 @@ Contributor(s): ______________________________________. -->
|
|||
persist="hidden" label="&bookmarksButton.label;"
|
||||
datasources="rdf:bookmarks rdf:files rdf:localsearch rdf:internetsearch"
|
||||
ref="NC:BookmarksRoot" container="true" flags="dont-test-empty"
|
||||
oncommand="OpenBookmarkURL(event.target,document.getElementById('BookmarksMenu').database)"
|
||||
ondragover="nsDragAndDrop.dragOver(event, folderObserver);"
|
||||
template="bookmarksMenuTemplate">
|
||||
<menupopup onpopuphiding="gDidOpen = false;"
|
||||
onpopupshowing="checkBookmarksMenuTemplateBuilder();"
|
||||
ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();">
|
||||
<menuitem accesskey="&addCurPageCmd.accesskey;" key="addBookmarkKb" observes="Browser:AddBookmark"
|
||||
ondragover="event.preventBubble(); return false;"/>
|
||||
<menuitem accesskey="&addCurPageAsCmd.accesskey;" key="addBookmarkAsKb" observes="Browser:AddBookmarkAs"
|
||||
ondragover="event.preventBubble(); return false;"/>
|
||||
<menuseparator ondragover="event.preventBubble(); return false;"/>
|
||||
<menuitem accesskey="&manBookmarksCmd.accesskey;" key="manBookmarkKb" observes="Browser:ManageBookmark"
|
||||
ondragover="event.preventBubble(); return false;"/>
|
||||
template="bookmarksMenuTemplate"
|
||||
ondraggesture="if (event.target.id=='bookmarks-button') event.preventBubble()">
|
||||
<menupopup onpopupshowing="checkBookmarksMenuTemplateBuilder();">
|
||||
<menuitem accesskey="&addCurPageCmd.accesskey;" key="addBookmarkKb" observes="Browser:AddBookmark"/>
|
||||
<menuitem accesskey="&addCurPageAsCmd.accesskey;" key="addBookmarkAsKb" observes="Browser:AddBookmarkAs"/>
|
||||
<menuseparator/>
|
||||
<menuitem accesskey="&manBookmarksCmd.accesskey;" key="manBookmarkKb" observes="Browser:ManageBookmark"/>
|
||||
<menuseparator id="lastStaticSeparator"/>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
|
@ -281,8 +275,7 @@ Contributor(s): ______________________________________. -->
|
|||
<hbox id="innermostBox" flex="1" style="min-width: 1px;" context="bmContext"
|
||||
datasources="rdf:bookmarks rdf:files rdf:localsearch rdf:internetsearch"
|
||||
ref="NC:PersonalToolbarFolder" flags="dont-test-empty"
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder"
|
||||
oncommand="OpenBookmarkURL(event.target, document.getElementById('innermostBox').database)">
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder">
|
||||
<tooltip id="ptTooltip" noautohide="true" onpopupshowing="return FillInPTTooltip(document.tooltipNode)">
|
||||
<vbox id="ptTooltipTextBox" flex="1">
|
||||
<label id="ptTitleText" />
|
||||
|
@ -305,17 +298,13 @@ Contributor(s): ______________________________________. -->
|
|||
rdf:type="http://home.netscape.com/NC-rdf#Folder"
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
|
||||
</rule>
|
||||
|
||||
<rule parent="hbox" iscontainer="true" isempty="true"
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder">
|
||||
<toolbarbutton type="menu" editable="true" class="bookmark-item"
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder"
|
||||
uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#Name"
|
||||
ondraggesture="if (!event.altKey) { event.preventBubble(); return false; }"
|
||||
ondragover="nsDragAndDrop.dragOver(event, folderObserver);">
|
||||
<menupopup
|
||||
ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();">
|
||||
uri="rdf:*" label="rdf:http://home.netscape.com/NC-rdf#Name">
|
||||
<menupopup>
|
||||
<menuitem label="&emptyItem.label;" disabled="true"/>
|
||||
</menupopup>
|
||||
</toolbarbutton>
|
||||
|
@ -324,12 +313,8 @@ Contributor(s): ______________________________________. -->
|
|||
<rule parent="hbox" iscontainer="true">
|
||||
<toolbarbutton type="menu" class="bookmark-item" uri="rdf:*" editable="true"
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder"
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name"
|
||||
ondraggesture="if (!event.altKey) { event.preventBubble(); return false; }"
|
||||
ondragover="nsDragAndDrop.dragOver(event, folderObserver);">
|
||||
<menupopup ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();"/>
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name">
|
||||
<menupopup/>
|
||||
</toolbarbutton>
|
||||
</rule>
|
||||
|
||||
|
@ -352,27 +337,20 @@ Contributor(s): ______________________________________. -->
|
|||
</menupopup>
|
||||
</rule>
|
||||
|
||||
<rule iscontainer="true" isempty="true"
|
||||
rdf:type="http://home.netscape.com/NC-rdf#Folder">
|
||||
<menupopup
|
||||
ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();">
|
||||
<rule iscontainer="true" isempty="true" rdf:type="http://home.netscape.com/NC-rdf#Folder">
|
||||
<menupopup>
|
||||
<menu class="menu-iconic bookmark-item" uri="rdf:*"
|
||||
type="rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name">
|
||||
<menupopup>
|
||||
<menuitem label="&emptyItem.label;" disabled="true"
|
||||
ondraggesture="event.preventBubble(); return false;"/>
|
||||
<menuitem label="&emptyItem.label;" disabled="true"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
</menupopup>
|
||||
</rule>
|
||||
|
||||
<rule iscontainer="true">
|
||||
<menupopup ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();">
|
||||
<menupopup>
|
||||
<menu class="menu-iconic bookmark-item" uri="rdf:*"
|
||||
type="rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name">
|
||||
|
@ -388,9 +366,7 @@ Contributor(s): ______________________________________. -->
|
|||
</menupopup>
|
||||
</rule>
|
||||
<rule>
|
||||
<menupopup ondragdrop="nsDragAndDrop.drop(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragexit="nsDragAndDrop.dragExit(event, menuDNDObserver); event.preventBubble();"
|
||||
ondragover="nsDragAndDrop.dragOver(event, menuDNDObserver); event.preventBubble();">
|
||||
<menupopup>
|
||||
<menuitem class="menuitem-iconic bookmark-item" uri="rdf:*"
|
||||
label="rdf:http://home.netscape.com/NC-rdf#Name"/>
|
||||
</menupopup>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
* - Kevin Puetz (puetzk@iastate.edu)
|
||||
* - Ben Goodger <ben@netscape.com>
|
||||
* - Blake Ross <blaker@netscape.com>
|
||||
* - Pierre Chanial <pierrechanial@netscape.net>
|
||||
*
|
||||
* 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
|
||||
|
@ -38,9 +39,6 @@
|
|||
*
|
||||
* ***** 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;
|
||||
|
@ -76,230 +74,7 @@ var RDFUtils = {
|
|||
}
|
||||
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);
|
||||
|
||||
// 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)
|
||||
|
@ -319,7 +94,7 @@ var proxyIconDNDObserver = {
|
|||
aXferData.data.addDataForFlavour("text/unicode", urlBar.value);
|
||||
aXferData.data.addDataForFlavour("text/html", htmlString);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var homeButtonObserver = {
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
|
@ -364,7 +139,7 @@ var homeButtonObserver = {
|
|||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function openHomeDialog(aURL)
|
||||
{
|
||||
|
@ -408,7 +183,7 @@ var goButtonObserver = {
|
|||
flavourSet.appendFlavour("text/unicode");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var searchButtonObserver = {
|
||||
onDragOver: function(aEvent, aFlavour, aDragSession)
|
||||
|
@ -435,112 +210,129 @@ var searchButtonObserver = {
|
|||
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 = {
|
||||
var personalToolbarDNDObserver = {
|
||||
|
||||
////////////////////
|
||||
// Public methods //
|
||||
////////////////////
|
||||
|
||||
onDragStart: function (aEvent, aXferData, aDragAction)
|
||||
{
|
||||
|
||||
// Prevent dragging from an invalid region
|
||||
if (!this.canDrop(aEvent))
|
||||
return;
|
||||
|
||||
// Prevent dragging out of menupopups 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, 96504 and 139471
|
||||
// c) on Windows, there is no hang or crash associated with this, so we'll leave
|
||||
// the functionality there.
|
||||
if (navigator.platform != "Win32" && aEvent.target.localName != "toolbarbutton")
|
||||
return;
|
||||
|
||||
// prevent dragging folders in the personal toolbar and menus.
|
||||
// PCH: under linux, since containers open on mouse down, we hit bug 96504.
|
||||
// In addition, a drag start is fired when leaving an open toolbarbutton(type=menu)
|
||||
// menupopup (see bug 143031)
|
||||
if (this.isContainer(aEvent.target) && aEvent.target.getAttribute("group") != "true") {
|
||||
if (this.isPlatformNotSupported)
|
||||
return;
|
||||
if (!aEvent.shiftKey && !aEvent.altKey)
|
||||
return;
|
||||
// menus open on mouse down
|
||||
aEvent.target.firstChild.hidePopup();
|
||||
}
|
||||
|
||||
// Prevent dragging non-bookmark menuitem or menus
|
||||
var uri = aEvent.target.id;
|
||||
if (!this.isBookmark(uri))
|
||||
return;
|
||||
|
||||
//PCH: cleanup needed here, url is already calculated in isBookmark()
|
||||
var db = document.getElementById("innermostBox").database;
|
||||
var url = RDFUtils.getTarget(db, uri, NC_RDF("ID"));
|
||||
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);
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
if (aDragSession.canDrop)
|
||||
this.onDragSetFeedBack(aEvent);
|
||||
if (this.isPlatformNotSupported)
|
||||
return;
|
||||
if (this.isTimerSupported)
|
||||
return;
|
||||
this.onDragOverCheckTimers();
|
||||
return;
|
||||
},
|
||||
mCurrentDragOverItem: null,
|
||||
|
||||
onDragEnter: function (aEvent, aDragSession)
|
||||
{
|
||||
var target = aEvent.target;
|
||||
if (target.localName == "menupopup" || target.localName == "hbox")
|
||||
target = target.parentNode;
|
||||
if (aDragSession.canDrop) {
|
||||
this.onDragSetFeedBack(aEvent);
|
||||
this.onDragEnterSetTimer(target, aDragSession);
|
||||
}
|
||||
this.mCurrentDragOverTarget = target;
|
||||
return;
|
||||
},
|
||||
|
||||
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");
|
||||
}
|
||||
var target = aEvent.target;
|
||||
if (target.localName == "menupopup" || target.localName == "hbox")
|
||||
target = target.parentNode;
|
||||
this.onDragRemoveFeedBack(target);
|
||||
this.onDragExitSetTimer(target, aDragSession);
|
||||
this.mCurrentDragOverTarget = null;
|
||||
return;
|
||||
},
|
||||
|
||||
onDrop: function (aEvent, aXferData, aDragSession)
|
||||
{
|
||||
|
||||
this.onDragRemoveFeedBack(aEvent.target);
|
||||
var dropPosition = this.determineDropPosition(aEvent);
|
||||
|
||||
// PCH: BAD!!! We should use the flavor
|
||||
// this code should be merged with the one in bookmarks.xml
|
||||
var xferData = aXferData.data.split("\n");
|
||||
if (xferData[0] == "")
|
||||
return;
|
||||
var elementRes = RDFUtils.getResource(xferData[0]);
|
||||
|
||||
var bookmarksButton = document.getElementById("bookmarks-button");
|
||||
var childDB = bookmarksButton.database;
|
||||
var childDB = document.getElementById("innermostBox").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);
|
||||
var parentContainer = this.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
|
||||
|
@ -551,7 +343,6 @@ var menuDNDObserver = {
|
|||
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)
|
||||
|
@ -567,63 +358,264 @@ var menuDNDObserver = {
|
|||
linkTitle = titleFromHistory.Value;
|
||||
}
|
||||
|
||||
var dropElement = aEvent.target.id;
|
||||
var dropElementRes, dropIndex, dropPosition;
|
||||
dropElementRes = RDFUtils.getResource(dropElement);
|
||||
var dropIndex;
|
||||
if (aEvent.target.id == "bookmarks-button")
|
||||
// dropPosition is always DROP_ON
|
||||
parentContainer = RDFUtils.getResource("NC:BookmarksRoot");
|
||||
else if (aEvent.target.id == "innermostBox")
|
||||
parentContainer = RDFUtils.getResource("NC:PersonalToolbarFolder");
|
||||
else if (dropPosition == this.DROP_ON)
|
||||
parentContainer = RDFUtils.getResource(aEvent.target.id);
|
||||
else {
|
||||
parentContainer = this.findParentContainer(aEvent.target);
|
||||
rdfContainer.Init(childDB, parentContainer);
|
||||
var dropElementRes = RDFUtils.getResource(aEvent.target.id);
|
||||
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;
|
||||
case this.DROP_BEFORE:
|
||||
if (dropIndex<1) dropIndex = 1;
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, parentContainer, dropIndex);
|
||||
break;
|
||||
case DROP_ON:
|
||||
insertBookmarkAt(xferData[0], linkTitle, linkCharset, dropElementRes, -1);
|
||||
case this.DROP_ON:
|
||||
dropIndex = -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);
|
||||
case this.DROP_AFTER:
|
||||
if (dropIndex <= rdfContainer.GetCount()) ++dropIndex;
|
||||
if (dropIndex<1) dropIndex = -1;
|
||||
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;
|
||||
this.insertBookmarkAt(xferData[0], linkTitle, linkCharset, parentContainer, dropIndex);
|
||||
return;
|
||||
},
|
||||
|
||||
getSupportedFlavours: function () {
|
||||
canDrop: function (aEvent, aDragSession)
|
||||
{
|
||||
var target = aEvent.target;
|
||||
return target.id && target.localName != "menupopup" && target.localName != "toolbar" &&
|
||||
target.localName != "menuseparator" && target.localName != "toolbarseparator" &
|
||||
target.id != "NC:SystemBookmarksStaticRoot" &&
|
||||
target.id.substring(0,5) != "find:";
|
||||
},
|
||||
|
||||
getSupportedFlavours: function ()
|
||||
{
|
||||
var flavourSet = new FlavourSet();
|
||||
flavourSet.appendFlavour("moz/rdfitem");
|
||||
flavourSet.appendFlavour("text/unicode");
|
||||
flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
|
||||
flavourSet.appendFlavour("text/x-moz-url");
|
||||
return flavourSet;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
function determineDropPosition(aEvent, aAllowDropOn)
|
||||
{
|
||||
|
||||
////////////////////////////////////
|
||||
// Private methods and properties //
|
||||
////////////////////////////////////
|
||||
|
||||
DROP_BEFORE:-1,
|
||||
DROP_ON : 0,
|
||||
DROP_AFTER : 1,
|
||||
springLoadedMenuDelay: 350, // milliseconds
|
||||
isPlatformNotSupported: navigator.platform.indexOf("Linux") != -1,
|
||||
isTimerSupported: navigator.platform.indexOf("Win") == -1 && navigator.platform.indexOf("Mac") == -1,
|
||||
|
||||
mCurrentDragOverTarget: null,
|
||||
loadTimer : null,
|
||||
closeTimer : null,
|
||||
loadTarget : null,
|
||||
closeTarget: null,
|
||||
|
||||
|
||||
onDragCloseMenu: function (aNode)
|
||||
{
|
||||
var children = aNode.childNodes;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
if (children[i].id == "innermostBox") {
|
||||
this.onDragCloseMenu(children[i]);
|
||||
}
|
||||
else if (this.isContainer(children[i]) && children[i].getAttribute("open") == "true") {
|
||||
this.onDragCloseMenu(children[i].firstChild);
|
||||
if (children[i] != this.mCurrentDragOverTarget)
|
||||
children[i].firstChild.hidePopup();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onDragCloseTarget: function ()
|
||||
{
|
||||
// if the mouse is not over a menu, then close everything.
|
||||
if (!this.mCurrentDragOverTarget) {
|
||||
this.onDragCloseMenu(document.getElementById("PersonalToolbar"));
|
||||
return
|
||||
}
|
||||
// The bookmark button is not a sibling of the folders in the PT
|
||||
if (this.mCurrentDragOverTarget.parentNode.id == "innermostBox")
|
||||
this.onDragCloseMenu(document.getElementById("PersonalToolbar"));
|
||||
else
|
||||
this.onDragCloseMenu(this.mCurrentDragOverTarget.parentNode);
|
||||
},
|
||||
|
||||
onDragLoadTarget: function (aTarget)
|
||||
{
|
||||
if (!this.mCurrentDragOverTarget)
|
||||
return;
|
||||
// Load the current menu
|
||||
if (this.isContainer(aTarget) && aTarget.getAttribute("group") != "true")
|
||||
aTarget.firstChild.showPopup(aTarget, -1, -1, "menupopup");
|
||||
},
|
||||
|
||||
onDragOverCheckTimers: function ()
|
||||
{
|
||||
var now = new Date().getTime();
|
||||
if (this.closeTimer && now-this.springLoadedMenuDelay>this.closeTimer) {
|
||||
this.onDragCloseTarget();
|
||||
this.closeTimer = null;
|
||||
}
|
||||
if (this.loadTimer && (now-this.springLoadedMenuDelay>this.loadTimer)) {
|
||||
this.onDragLoadTarget(this.loadTarget);
|
||||
this.loadTimer = null;
|
||||
}
|
||||
},
|
||||
|
||||
onDragEnterSetTimer: function (aTarget, aDragSession)
|
||||
{
|
||||
if (this.isPlatformNotSupported)
|
||||
return;
|
||||
if (this.isTimerSupported) {
|
||||
var targetToBeLoaded = aTarget;
|
||||
clearTimeout(this.loadTimer);
|
||||
if (aTarget == aDragSession.sourceNode)
|
||||
return;
|
||||
//XXX Hack: see bug 139645
|
||||
var thisHack = this;
|
||||
this.loadTimer=setTimeout(function () {thisHack.onDragLoadTarget(targetToBeLoaded)}, this.springLoadedMenuDelay);
|
||||
} else {
|
||||
var now = new Date().getTime();
|
||||
this.loadTimer = now;
|
||||
this.loadTarget = aTarget;
|
||||
}
|
||||
},
|
||||
|
||||
onDragExitSetTimer: function (aTarget, aDragSession)
|
||||
{
|
||||
if (this.isPlatformNotSupported)
|
||||
return;
|
||||
var thisHack = this;
|
||||
if (this.isTimerSupported) {
|
||||
clearTimeout(this.closeTimer)
|
||||
this.closeTimer=setTimeout(function () {thisHack.onDragCloseTarget()}, this.springLoadedMenuDelay);
|
||||
} else {
|
||||
var now = new Date().getTime();
|
||||
this.closeTimer = now;
|
||||
this.closeTarget = aTarget;
|
||||
this.loadTimer = null;
|
||||
|
||||
// If user isn't rearranging within the menu, close it
|
||||
// To do so, we exploit a Mac bug: timeout set during
|
||||
// drag and drop on Windows and Mac are fired only after that the drop is released.
|
||||
// timeouts will pile up, we may have a better approach but for the moment, this one
|
||||
// correctly close the menus after a drop/cancel outside the personal toolbar.
|
||||
// The if statement in the function has been introduced to deal with rare but reproducible
|
||||
// missing Exit events.
|
||||
if (aDragSession.sourceNode.localName != "menuitem" && aDragSession.sourceNode.localName != "menu")
|
||||
setTimeout(function () { if (thisHack.mCurrentDragOverTarget) {thisHack.onDragRemoveFeedBack(thisHack.mCurrentDragOverTarget); thisHack.mCurrentDragOverTarget=null} thisHack.loadTimer=null; thisHack.onDragCloseTarget() }, 0);
|
||||
}
|
||||
},
|
||||
|
||||
onDragSetFeedBack: function (aEvent)
|
||||
{
|
||||
var target = aEvent.target
|
||||
var dropPosition = this.determineDropPosition(aEvent)
|
||||
switch (target.localName) {
|
||||
case "toolbarseparator":
|
||||
case "toolbarbutton":
|
||||
if (this.isContainer(target)) {
|
||||
target.setAttribute("dragover-left" , "true");
|
||||
target.setAttribute("dragover-right" , "true");
|
||||
target.setAttribute("dragover-top" , "true");
|
||||
target.setAttribute("dragover-bottom", "true");
|
||||
}
|
||||
else {
|
||||
switch (dropPosition) {
|
||||
case this.DROP_BEFORE:
|
||||
target.removeAttribute("dragover-right");
|
||||
target.setAttribute("dragover-left", "true");
|
||||
break;
|
||||
case this.DROP_AFTER:
|
||||
target.removeAttribute("dragover-left");
|
||||
target.setAttribute("dragover-right", "true");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "menuseparator":
|
||||
case "menu":
|
||||
case "menuitem":
|
||||
switch (dropPosition) {
|
||||
case this.DROP_BEFORE:
|
||||
target.removeAttribute("dragover-bottom");
|
||||
target.setAttribute("dragover-top", "true");
|
||||
break;
|
||||
case this.DROP_AFTER:
|
||||
target.removeAttribute("dragover-top");
|
||||
target.setAttribute("dragover-bottom", "true");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "hbox" :
|
||||
target.lastChild.setAttribute("dragover-right", "true");
|
||||
break;
|
||||
case "menupopup":
|
||||
case "toolbar" : break;
|
||||
default: dump("No feedback for: "+target.localName+"\n");
|
||||
}
|
||||
},
|
||||
|
||||
onDragRemoveFeedBack: function (aTarget)
|
||||
{
|
||||
if (aTarget.localName == "hbox") {
|
||||
aTarget.lastChild.removeAttribute("dragover-right");
|
||||
} else {
|
||||
aTarget.removeAttribute("dragover-left");
|
||||
aTarget.removeAttribute("dragover-right");
|
||||
aTarget.removeAttribute("dragover-top");
|
||||
aTarget.removeAttribute("dragover-bottom");
|
||||
}
|
||||
},
|
||||
|
||||
onDropSetFeedBack: function (aTarget)
|
||||
{
|
||||
//XXX Not yet...
|
||||
},
|
||||
|
||||
isContainer: function (aTarget)
|
||||
{
|
||||
return (aTarget.localName == "menu" || aTarget.localName == "toolbarbutton") &&
|
||||
(aTarget.getAttribute("container") == "true" || aTarget.getAttribute("group") == "true");
|
||||
},
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
// Methods that need to be moved into BookmarksUtils //
|
||||
///////////////////////////////////////////////////////
|
||||
|
||||
//XXXPCH this function returns wrong vertical positions
|
||||
//XXX skin authors could break us, we'll cross that bridge when they turn us 90degrees
|
||||
determineDropPosition: function (aEvent)
|
||||
{
|
||||
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;
|
||||
if (this.isContainer(aEvent.target))
|
||||
return this.DROP_ON;
|
||||
|
||||
var measure;
|
||||
var coordValue;
|
||||
var clientCoordValue;
|
||||
if (aEvent.target.localName == "menuitem" || aEvent.target.localName == "menu") {
|
||||
if (aEvent.target.localName == "menuitem") {
|
||||
measure = overButtonBoxObject.height/regionCount;
|
||||
coordValue = overButtonBoxObject.y;
|
||||
clientCoordValue = aEvent.clientY;
|
||||
|
@ -634,26 +626,35 @@ function determineDropPosition(aEvent, aAllowDropOn)
|
|||
clientCoordValue = aEvent.clientX;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
return this.DROP_ON;
|
||||
|
||||
// in the first region?
|
||||
if (clientCoordValue < (coordValue + measure))
|
||||
return DROP_BEFORE;
|
||||
|
||||
return this.DROP_BEFORE;
|
||||
// in the last region?
|
||||
if (clientCoordValue >= (coordValue + (regionCount - 1)*measure))
|
||||
return DROP_AFTER;
|
||||
|
||||
return this.DROP_AFTER;
|
||||
// must be in the middle somewhere
|
||||
return DROP_ON;
|
||||
}
|
||||
return this.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)
|
||||
{
|
||||
isBookmark: function (aURI)
|
||||
{
|
||||
if (!aURI)
|
||||
return false;
|
||||
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"))
|
||||
},
|
||||
|
||||
// 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.
|
||||
findParentContainer: function (aElement)
|
||||
{
|
||||
if (!aElement) return null;
|
||||
switch (aElement.localName) {
|
||||
case "toolbarbutton":
|
||||
|
@ -675,13 +676,14 @@ function findParentContainer(aElement)
|
|||
return RDFUtils.getResource(res);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
function insertBookmarkAt(aURL, aTitle, aCharset, aFolderRes, aIndex)
|
||||
{
|
||||
insertBookmarkAt: function (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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче