fix DND between the last visible bookmark and the chevron in the personal toolbar. spring loaded chevron menupopup.

This commit is contained in:
chanial%noos.fr 2002-10-13 16:56:13 +00:00
Родитель 4499ea4975
Коммит 88086f0325
2 изменённых файлов: 123 добавлений и 50 удалений

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

@ -2097,12 +2097,11 @@ var personalToolbarDNDObserver = {
// if the personal toolbar does not exist, recreate it
if (aEvent.originalTarget == "bookmarks-toolbar") {
BookmarksUtils.recreatePersonalToolbarFolder(transactionSet);
target = { parent: "NC:PersonalToolbarFolder", index: 1 };
//BookmarksUtils.recreatePersonalToolbarFolder(transactionSet);
//target = { parent: "NC:PersonalToolbarFolder", index: 1 };
} else {
var orientation = bt.getBTOrientation(aEvent);
var target = bt.getBTSelection(aEvent.originalTarget);
target = BookmarksUtils.getTargetFromSelection(target, orientation);
var target = bt.getBTTarget(aEvent.originalTarget, orientation);
}
const kDSIID = Components.interfaces.nsIDragService;
@ -2116,10 +2115,13 @@ var personalToolbarDNDObserver = {
canDrop: function (aEvent, aDragSession)
{
var target = aEvent.originalTarget;
return target.id && target.localName != "menupopup" && target.localName != "toolbar" &&
target.localName != "menuseparator" && target.localName != "toolbarseparator" &
var bt = document.getElementById("bookmarks-toolbar");
return bt.isBTBookmark(target.id) &&
target.id != "NC:SystemBookmarksStaticRoot" &&
target.id.substring(0,5) != "find:";
target.id.substring(0,5) != "find:" ||
target.id == "bookmarks-menu" ||
target.getAttribute("class") == "chevron" ||
target.localName == "hbox";
},
canHandleMultipleItems: true,
@ -2154,9 +2156,11 @@ var personalToolbarDNDObserver = {
get mObservers ()
{
if (!this._observers) {
var bt = document.getElementById("bookmarks-toolbar");
this._observers = [
document.getElementById("bookmarks-ptf"),
document.getElementById("bookmarks-menu").parentNode
document.getAnonymousElementByAttribute(bt , "anonid", "bookmarks-ptf"),
document.getElementById("bookmarks-menu").parentNode,
document.getAnonymousElementByAttribute(bt , "class", "chevron").parentNode
]
}
return this._observers;
@ -2308,23 +2312,31 @@ var personalToolbarDNDObserver = {
}
break;
case "hbox" :
aTarget.lastChild.setAttribute("dragover-right", "true");
// hit between the last visible bookmark and the chevron
var bt = document.getElementById("bookmarks-toolbar");
var newTarget = bt.getLastVisibleBookmark();
if (newTarget)
newTarget.setAttribute("dragover-right", "true");
break;
case "menupopup":
case "toolbar" : break;
case "bookmarks-toolbar": break; // no personal toolbar folder
default: dump("No feedback for: "+aTarget.localName+"\n");
case "stack" :
case "menupopup": break;
default: dump("No feedback for: "+aTarget.localName+"\n");
}
},
onDragRemoveFeedBack: function (aTarget)
{
if (aTarget.localName == "bookmarks-toolbar") {
var ptf = document.getAnonymousElementByAttribute(aTarget, "anonid", "bookmarks-ptf");
if (ptf.hasChildNodes())
ptf.lastChild.removeAttribute("dragover-right");
} else if (aTarget.localName == "hbox") {
aTarget.lastChild.removeAttribute("dragover-right");
if (aTarget.localName == "hbox") {
// hit when dropping in the bt or between the last visible bookmark
// and the chevron
var bt = document.getElementById("bookmarks-toolbar");
var newTarget = bt.getLastVisibleBookmark();
if (newTarget)
newTarget.removeAttribute("dragover-right");
} else if (aTarget.localName == "stack") {
var bt = document.getElementById("bookmarks-toolbar");
var newTarget = bt.getLastVisibleBookmark();
newTarget.removeAttribute("dragover-right");
} else {
aTarget.removeAttribute("dragover-left");
aTarget.removeAttribute("dragover-right");
@ -2340,8 +2352,9 @@ var personalToolbarDNDObserver = {
isContainer: function (aTarget)
{
return aTarget.localName == "menu" || (aTarget.localName == "toolbarbutton") &&
(aTarget.getAttribute("container") == "true" || aTarget.getAttribute("group") == "true");
return aTarget.localName == "menu" ||
aTarget.localName == "toolbarbutton" &&
aTarget.getAttribute("type") == "menu";
}
}

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

@ -65,8 +65,7 @@
for (var i=4; i<buttons.childNodes.length; i++) {
var button = buttons.childNodes[i];
if (!overflowed)
button.collapsed = false;
button.collapsed = overflowed;
if (button.boxObject.x + button.boxObject.width > width) {
overflowed = true;
@ -113,7 +112,7 @@
hbox.focus() <!-- buttons in the pt have -moz-user-focus: ignore -->
this._selection = this.getBTSelection(document.popupNode);
this._orientation = this.getBTOrientation(aEvent, document.popupNode);
this._target = BookmarksUtils.getTargetFromSelection(this._selection, this._orientation);
this._target = this.getBTTarget(document.popupNode, this._orientation);
BookmarksCommand.createContextMenu(aEvent, this._selection);
this.onCommandUpdate();
aEvent.target.addEventListener("mousemove", this.commandController.onMouseMove, false)
@ -172,7 +171,7 @@
var item;
switch (aNode.id) {
case "bookmarks-ptf":
item = "NC:PersonalToolbarFolder"
item = "NC:PersonalToolbarFolder";
break;
case "bookmarks-menu":
item = "NC:BookmarksRoot";
@ -195,6 +194,49 @@
]]></body>
</method>
<!--/////////////////////////////////////////////////////////////////////////////
// returns the insertion target from aNode -->
<method name="getBTTarget">
<parameter name="aNode"/>
<parameter name="aOrientation"/>
<body><![CDATA[
var item, parent, index;
switch (aNode.id) {
case "bookmarks-ptf":
parent = "NC:PersonalToolbarFolder";
item = this.getLastVisibleBookmark();
break;
case "bookmarks-menu":
parent = "NC:BookmarksRoot";
break;
default:
if (aNode.getAttribute("class") == "chevron") {
parent = "NC:PersonalToolbarFolder";
break;
}
if (aOrientation == BookmarksUtils.DROP_ON)
parent = aNode.id
else {
parent = this.getBTContainer(aNode);
item = aNode;
}
}
parent = RDF.GetResource(parent);
if (item && aOrientation != BookmarksUtils.DROP_ON) {
item = RDF.GetResource(item.id);
RDFC.Init(BMDS, parent);
index = RDFC.IndexOf(item);
if (aOrientation == BookmarksUtils.DROP_AFTER)
++index;
} else
index = parseInt(BookmarksUtils.getProperty(parent, RDF_NS+"nextVal"));
var target = { parent: parent, index: index };
return target;
]]></body>
</method>
<!--/////////////////////////////////////////////////////////////////////////////
// returns the parent resource of a node in the personal toolbar.
// This is determined by inspecting the source element and walking up the
@ -204,27 +246,22 @@
<body><![CDATA[
var parent;
var item = aNode.id;
if (item == "NC:PersonalToolbarFolder")
parent = BookmarksUtils.getParentOfContainer(item);
else if (item == "NC:BookmarksRoot")
parent = null;
else if (this.isBTBookmark(item)) {
parent = aNode.parentNode.parentNode;
if (parent.getAttribute("class") == "chevron")
parent = parent.parentNode;
if (parent.localName == "stack")
parent = parent.parentNode;
parent = parent.id;
switch (parent) {
case "bookmarks-toolbar":
parent = "NC:PersonalToolbarFolder"
break;
case "bookmarks-menu":
parent = "NC:BookmarksRoot";
break;
}
} else
parent = "NC:BookmarksRoot"
if (!this.isBTBookmark(item))
return "NC:BookmarksRoot"
parent = aNode.parentNode.parentNode;
if (parent.getAttribute("class") == "chevron")
parent = parent.parentNode.parentNode;
if (parent.localName == "stack")
parent = parent.parentNode;
parent = parent.id;
switch (parent) {
case "bookmarks-toolbar":
parent = "NC:PersonalToolbarFolder"
break;
case "bookmarks-menu":
parent = "NC:BookmarksRoot";
break;
}
return parent;
]]></body>
</method>
@ -268,9 +305,15 @@
target = aEvent.originalTarget;
else
target = aTarget;
if (target.localName == "menu" &&
target.parentNode.localName != "menupopup")
if (target.localName == "menu" &&
target.parentNode.localName != "menupopup" ||
target.getAttribute("class") == "chevron")
return BookmarksUtils.DROP_ON;
if (target.localName == "hbox") {
return target.childNodes.length>4?
BookmarksUtils.DROP_AFTER:BookmarksUtils.DROP_ON;
}
var overButtonBoxObject = target.boxObject.QueryInterface(Components.interfaces.nsIBoxObject);
var overParentBoxObject = target.parentNode.boxObject.QueryInterface(Components.interfaces.nsIBoxObject);
@ -316,7 +359,7 @@
</method>
<!--/////////////////////////////////////////////////////////////////////////////
// Returns true if the node is a container. -->
// expand the folder targeted by the context menu. -->
<method name="expandBTFolder">
<body><![CDATA[
var target = document.popupNode.lastChild;
@ -397,6 +440,23 @@
]]></body>
</method>
<!--/////////////////////////////////////////////////////////////////////////////
// returns the node of the last visible bookmark on the toolbar -->
<method name="getLastVisibleBookmark">
<body><![CDATA[
var buttons = (document.getAnonymousNodes(this))[0].firstChild;
var button = buttons.childNodes[3].nextSibling;
if (!button)
return null; // empty bookmarks toolbar
do {
if (button.collapsed)
return button.previousSibling;
button = button.nextSibling;
} while (button)
return buttons.lastChild;
]]></body>
</method>
<method name="updateOverflowMenu">
<parameter name="menupopup"/>
<body><![CDATA[