2015-12-03 21:02:22 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-09-27 08:06:56 +04:00
|
|
|
|
|
|
|
var gToolboxDocument = null;
|
|
|
|
var gToolbox = null;
|
|
|
|
var gCurrentDragOverItem = null;
|
|
|
|
var gToolboxChanged = false;
|
2009-02-16 18:27:20 +03:00
|
|
|
var gToolboxSheet = false;
|
2011-12-22 03:16:05 +04:00
|
|
|
var gPaletteBox = null;
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2014-07-03 03:14:07 +04:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2015-12-03 21:02:22 +03:00
|
|
|
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
2014-07-03 03:14:07 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
function onLoad()
|
|
|
|
{
|
2009-02-16 18:27:20 +03:00
|
|
|
if ("arguments" in window && window.arguments[0]) {
|
|
|
|
InitWithToolbox(window.arguments[0]);
|
2010-05-14 14:20:00 +04:00
|
|
|
repositionDialog(window);
|
2009-02-16 18:27:20 +03:00
|
|
|
}
|
|
|
|
else if (window.frameElement &&
|
|
|
|
"toolbox" in window.frameElement) {
|
|
|
|
gToolboxSheet = true;
|
|
|
|
InitWithToolbox(window.frameElement.toolbox);
|
2010-05-14 14:20:00 +04:00
|
|
|
repositionDialog(window.frameElement.panel);
|
2009-02-16 18:27:20 +03:00
|
|
|
}
|
2006-08-26 11:27:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function InitWithToolbox(aToolbox)
|
|
|
|
{
|
|
|
|
gToolbox = aToolbox;
|
2010-03-11 23:42:23 +03:00
|
|
|
dispatchCustomizationEvent("beforecustomization");
|
2002-09-29 05:23:02 +04:00
|
|
|
gToolboxDocument = gToolbox.ownerDocument;
|
2008-10-18 13:57:46 +04:00
|
|
|
gToolbox.customizing = true;
|
2010-11-22 13:21:43 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
toolbar.setAttribute("customizing", "true");
|
|
|
|
});
|
2011-12-22 03:16:05 +04:00
|
|
|
gPaletteBox = document.getElementById("palette-box");
|
2008-10-18 13:57:46 +04:00
|
|
|
|
2010-09-14 01:12:48 +04:00
|
|
|
var elts = getRootElements();
|
|
|
|
for (let i=0; i < elts.length; i++) {
|
|
|
|
elts[i].addEventListener("dragstart", onToolbarDragStart, true);
|
|
|
|
elts[i].addEventListener("dragover", onToolbarDragOver, true);
|
2010-12-03 19:19:55 +03:00
|
|
|
elts[i].addEventListener("dragexit", onToolbarDragExit, true);
|
2010-09-14 01:12:48 +04:00
|
|
|
elts[i].addEventListener("drop", onToolbarDrop, true);
|
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2004-09-29 11:08:24 +04:00
|
|
|
initDialog();
|
2002-09-28 19:11:50 +04:00
|
|
|
}
|
|
|
|
|
2009-02-16 18:27:20 +03:00
|
|
|
function onClose()
|
|
|
|
{
|
|
|
|
if (!gToolboxSheet)
|
|
|
|
window.close();
|
|
|
|
else
|
|
|
|
finishToolbarCustomization();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUnload()
|
|
|
|
{
|
|
|
|
if (!gToolboxSheet)
|
|
|
|
finishToolbarCustomization();
|
|
|
|
}
|
|
|
|
|
2006-08-26 11:27:54 +04:00
|
|
|
function finishToolbarCustomization()
|
2002-10-02 03:10:54 +04:00
|
|
|
{
|
|
|
|
removeToolboxListeners();
|
|
|
|
unwrapToolbarItems();
|
|
|
|
persistCurrentSets();
|
2009-06-13 10:03:02 +04:00
|
|
|
gToolbox.customizing = false;
|
2010-11-22 13:21:43 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
toolbar.removeAttribute("customizing");
|
|
|
|
});
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-10-02 03:10:54 +04:00
|
|
|
notifyParentComplete();
|
|
|
|
}
|
|
|
|
|
2002-09-28 19:11:50 +04:00
|
|
|
function initDialog()
|
|
|
|
{
|
2012-03-29 19:33:52 +04:00
|
|
|
if (!gToolbox.toolbarset) {
|
|
|
|
document.getElementById("newtoolbar").hidden = true;
|
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
var mode = gToolbox.getAttribute("mode");
|
|
|
|
document.getElementById("modelist").value = mode;
|
2002-09-29 22:25:42 +04:00
|
|
|
var smallIconsCheckbox = document.getElementById("smallicons");
|
2009-12-31 13:12:43 +03:00
|
|
|
smallIconsCheckbox.checked = gToolbox.getAttribute("iconsize") == "small";
|
2002-09-29 22:25:42 +04:00
|
|
|
if (mode == "text")
|
|
|
|
smallIconsCheckbox.disabled = true;
|
2002-09-27 08:06:56 +04:00
|
|
|
|
|
|
|
// Build up the palette of other items.
|
|
|
|
buildPalette();
|
|
|
|
|
|
|
|
// Wrap all the items on the toolbar in toolbarpaletteitems.
|
|
|
|
wrapToolbarItems();
|
|
|
|
}
|
|
|
|
|
2010-05-14 14:20:00 +04:00
|
|
|
function repositionDialog(aWindow)
|
2002-09-28 19:11:50 +04:00
|
|
|
{
|
2009-06-22 16:29:55 +04:00
|
|
|
// Position the dialog touching the bottom of the toolbox and centered with
|
2006-05-26 16:20:51 +04:00
|
|
|
// it.
|
2010-05-14 14:20:00 +04:00
|
|
|
if (!aWindow)
|
|
|
|
return;
|
|
|
|
|
2006-05-29 20:18:45 +04:00
|
|
|
var width;
|
2010-05-14 14:20:00 +04:00
|
|
|
if (aWindow != window)
|
|
|
|
width = aWindow.getBoundingClientRect().width;
|
|
|
|
else if (document.documentElement.hasAttribute("width"))
|
2006-05-29 20:18:45 +04:00
|
|
|
width = document.documentElement.getAttribute("width");
|
|
|
|
else
|
|
|
|
width = parseInt(document.documentElement.style.width);
|
2009-06-22 16:29:55 +04:00
|
|
|
var screenX = gToolbox.boxObject.screenX
|
2006-05-29 20:18:45 +04:00
|
|
|
+ ((gToolbox.boxObject.width - width) / 2);
|
2002-09-29 09:37:48 +04:00
|
|
|
var screenY = gToolbox.boxObject.screenY + gToolbox.boxObject.height;
|
2004-09-29 11:08:24 +04:00
|
|
|
|
2010-05-14 14:20:00 +04:00
|
|
|
aWindow.moveTo(screenX, screenY);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeToolboxListeners()
|
|
|
|
{
|
2010-09-14 01:12:48 +04:00
|
|
|
var elts = getRootElements();
|
|
|
|
for (let i=0; i < elts.length; i++) {
|
2010-09-14 17:19:09 +04:00
|
|
|
elts[i].removeEventListener("dragstart", onToolbarDragStart, true);
|
|
|
|
elts[i].removeEventListener("dragover", onToolbarDragOver, true);
|
2010-12-03 19:19:55 +03:00
|
|
|
elts[i].removeEventListener("dragexit", onToolbarDragExit, true);
|
2010-09-14 17:19:09 +04:00
|
|
|
elts[i].removeEventListener("drop", onToolbarDrop, true);
|
2010-09-14 01:12:48 +04:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-09-29 05:23:02 +04:00
|
|
|
* Invoke a callback on the toolbox to notify it that the dialog is done
|
|
|
|
* and going away.
|
2002-09-27 08:06:56 +04:00
|
|
|
*/
|
|
|
|
function notifyParentComplete()
|
|
|
|
{
|
2002-09-29 05:23:02 +04:00
|
|
|
if ("customizeDone" in gToolbox)
|
|
|
|
gToolbox.customizeDone(gToolboxChanged);
|
2010-03-11 23:42:23 +03:00
|
|
|
dispatchCustomizationEvent("aftercustomization");
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2011-02-04 11:09:04 +03:00
|
|
|
function toolboxChanged(aType)
|
2008-01-31 02:16:52 +03:00
|
|
|
{
|
|
|
|
gToolboxChanged = true;
|
|
|
|
if ("customizeChange" in gToolbox)
|
2011-02-04 11:09:04 +03:00
|
|
|
gToolbox.customizeChange(aType);
|
2010-03-11 23:42:23 +03:00
|
|
|
dispatchCustomizationEvent("customizationchange");
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchCustomizationEvent(aEventName) {
|
|
|
|
var evt = document.createEvent("Events");
|
|
|
|
evt.initEvent(aEventName, true, true);
|
|
|
|
gToolbox.dispatchEvent(evt);
|
2008-01-31 02:16:52 +03:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
/**
|
|
|
|
* Persist the current set of buttons in all customizable toolbars to
|
|
|
|
* localstore.
|
|
|
|
*/
|
|
|
|
function persistCurrentSets()
|
|
|
|
{
|
2008-04-05 04:20:38 +04:00
|
|
|
if (!gToolboxChanged || gToolboxDocument.defaultView.closed)
|
2002-09-27 08:06:56 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
var customCount = 0;
|
2010-03-22 11:12:32 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
// Calculate currentset and store it in the attribute.
|
|
|
|
var currentSet = toolbar.currentSet;
|
|
|
|
toolbar.setAttribute("currentset", currentSet);
|
|
|
|
|
|
|
|
var customIndex = toolbar.hasAttribute("customindex");
|
|
|
|
if (customIndex) {
|
|
|
|
if (!toolbar.hasChildNodes()) {
|
|
|
|
// Remove custom toolbars whose contents have been removed.
|
|
|
|
gToolbox.removeChild(toolbar);
|
2012-03-29 19:33:52 +04:00
|
|
|
} else if (gToolbox.toolbarset) {
|
2010-03-22 11:12:32 +03:00
|
|
|
// Persist custom toolbar info on the <toolbarset/>
|
|
|
|
gToolbox.toolbarset.setAttribute("toolbar"+(++customCount),
|
|
|
|
toolbar.toolbarName + ":" + currentSet);
|
|
|
|
gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customCount);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2010-03-22 11:12:32 +03:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2010-03-22 11:12:32 +03:00
|
|
|
if (!customIndex) {
|
|
|
|
// Persist the currentset attribute directly on hardcoded toolbars.
|
|
|
|
gToolboxDocument.persist(toolbar.id, "currentset");
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2010-03-22 11:12:32 +03:00
|
|
|
});
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// Remove toolbarX attributes for removed toolbars.
|
2012-03-29 19:33:52 +04:00
|
|
|
while (gToolbox.toolbarset && gToolbox.toolbarset.hasAttribute("toolbar"+(++customCount))) {
|
2002-09-27 08:06:56 +04:00
|
|
|
gToolbox.toolbarset.removeAttribute("toolbar"+customCount);
|
|
|
|
gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps all items in all customizable toolbars in a toolbox.
|
|
|
|
*/
|
|
|
|
function wrapToolbarItems()
|
|
|
|
{
|
2010-03-22 11:12:32 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
Array.forEach(toolbar.childNodes, function (item) {
|
2015-12-03 21:02:22 +03:00
|
|
|
if (AppConstants.platform == "macosx") {
|
|
|
|
if (item.firstChild && item.firstChild.localName == "menubar")
|
|
|
|
return;
|
|
|
|
}
|
2010-03-22 11:12:32 +03:00
|
|
|
if (isToolbarItem(item)) {
|
|
|
|
let wrapper = wrapToolbarItem(item);
|
|
|
|
cleanupItemForToolbar(item, wrapper);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2010-03-22 11:12:32 +03:00
|
|
|
});
|
|
|
|
});
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 01:12:48 +04:00
|
|
|
function getRootElements()
|
|
|
|
{
|
|
|
|
return [gToolbox].concat(gToolbox.externalToolbars);
|
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
/**
|
|
|
|
* Unwraps all items in all customizable toolbars in a toolbox.
|
|
|
|
*/
|
|
|
|
function unwrapToolbarItems()
|
|
|
|
{
|
2010-09-14 01:12:48 +04:00
|
|
|
let elts = getRootElements();
|
|
|
|
for (let i=0; i < elts.length; i++) {
|
|
|
|
let paletteItems = elts[i].getElementsByTagName("toolbarpaletteitem");
|
2010-09-14 17:19:09 +04:00
|
|
|
let paletteItem;
|
2010-09-14 01:12:48 +04:00
|
|
|
while ((paletteItem = paletteItems.item(0)) != null) {
|
|
|
|
let toolbarItem = paletteItem.firstChild;
|
|
|
|
restoreItemForToolbar(toolbarItem, paletteItem);
|
|
|
|
paletteItem.parentNode.replaceChild(toolbarItem, paletteItem);
|
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a wrapper that can be used to contain a toolbaritem and prevent
|
|
|
|
* it from receiving UI events.
|
|
|
|
*/
|
2008-12-03 15:35:34 +03:00
|
|
|
function createWrapper(aId, aDocument)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2008-12-03 15:35:34 +03:00
|
|
|
var wrapper = aDocument.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
2002-09-27 08:06:56 +04:00
|
|
|
"toolbarpaletteitem");
|
|
|
|
|
2009-06-22 16:29:55 +04:00
|
|
|
wrapper.id = "wrapper-"+aId;
|
2002-09-27 08:06:56 +04:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps an item that has been cloned from a template and adds
|
2011-12-22 03:16:05 +04:00
|
|
|
* it to the end of the palette.
|
2002-09-27 08:06:56 +04:00
|
|
|
*/
|
2011-12-22 03:16:05 +04:00
|
|
|
function wrapPaletteItem(aPaletteItem)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2008-12-03 15:35:34 +03:00
|
|
|
var wrapper = createWrapper(aPaletteItem.id, document);
|
2002-09-28 19:11:50 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
wrapper.appendChild(aPaletteItem);
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// XXX We need to call this AFTER the palette item has been appended
|
2009-06-22 16:29:55 +04:00
|
|
|
// to the wrapper or else we crash dropping certain buttons on the
|
2002-09-27 08:06:56 +04:00
|
|
|
// palette due to removal of the command and disabled attributes - JRH
|
|
|
|
cleanUpItemForPalette(aPaletteItem, wrapper);
|
|
|
|
|
2011-12-22 03:16:05 +04:00
|
|
|
gPaletteBox.appendChild(wrapper);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps an item that is currently on a toolbar and replaces the item
|
2002-09-28 19:11:50 +04:00
|
|
|
* with the wrapper. This is not used when dropping items from the palette,
|
|
|
|
* only when first starting the dialog and wrapping everything on the toolbars.
|
2002-09-27 08:06:56 +04:00
|
|
|
*/
|
|
|
|
function wrapToolbarItem(aToolbarItem)
|
|
|
|
{
|
2008-12-03 15:35:34 +03:00
|
|
|
var wrapper = createWrapper(aToolbarItem.id, gToolboxDocument);
|
2006-11-25 02:22:47 +03:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
wrapper.flex = aToolbarItem.flex;
|
|
|
|
|
2008-12-03 15:35:34 +03:00
|
|
|
aToolbarItem.parentNode.replaceChild(wrapper, aToolbarItem);
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
wrapper.appendChild(aToolbarItem);
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of ids for the current set of items on each toolbar.
|
|
|
|
*/
|
|
|
|
function getCurrentItemIds()
|
|
|
|
{
|
|
|
|
var currentItems = {};
|
2010-03-22 11:12:32 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
var child = toolbar.firstChild;
|
|
|
|
while (child) {
|
|
|
|
if (isToolbarItem(child))
|
|
|
|
currentItems[child.id] = 1;
|
|
|
|
child = child.nextSibling;
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2010-03-22 11:12:32 +03:00
|
|
|
});
|
2002-09-27 08:06:56 +04:00
|
|
|
return currentItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the palette of draggable items that are not yet in a toolbar.
|
|
|
|
*/
|
|
|
|
function buildPalette()
|
|
|
|
{
|
|
|
|
// Empty the palette first.
|
2011-12-22 03:16:05 +04:00
|
|
|
while (gPaletteBox.lastChild)
|
|
|
|
gPaletteBox.removeChild(gPaletteBox.lastChild);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
|
|
|
// Add the toolbar separator item.
|
|
|
|
var templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
|
|
|
"toolbarseparator");
|
|
|
|
templateNode.id = "separator";
|
2011-12-22 03:16:05 +04:00
|
|
|
wrapPaletteItem(templateNode);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2002-09-28 19:11:50 +04:00
|
|
|
// Add the toolbar spring item.
|
|
|
|
templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
|
|
|
"toolbarspring");
|
|
|
|
templateNode.id = "spring";
|
|
|
|
templateNode.flex = 1;
|
2011-12-22 03:16:05 +04:00
|
|
|
wrapPaletteItem(templateNode);
|
2002-09-28 19:11:50 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// Add the toolbar spacer item.
|
|
|
|
templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
2002-09-28 19:11:50 +04:00
|
|
|
"toolbarspacer");
|
2002-09-27 08:06:56 +04:00
|
|
|
templateNode.id = "spacer";
|
|
|
|
templateNode.flex = 1;
|
2011-12-22 03:16:05 +04:00
|
|
|
wrapPaletteItem(templateNode);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
|
|
|
var currentItems = getCurrentItemIds();
|
|
|
|
templateNode = gToolbox.palette.firstChild;
|
|
|
|
while (templateNode) {
|
|
|
|
// Check if the item is already in a toolbar before adding it to the palette.
|
|
|
|
if (!(templateNode.id in currentItems)) {
|
2008-12-03 15:35:34 +03:00
|
|
|
var paletteItem = document.importNode(templateNode, true);
|
2011-12-22 03:16:05 +04:00
|
|
|
wrapPaletteItem(paletteItem);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
templateNode = templateNode.nextSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure that an item that has been cloned from a template
|
2009-11-10 02:13:58 +03:00
|
|
|
* is stripped of any attributes that may adversely affect its
|
2002-09-27 08:06:56 +04:00
|
|
|
* appearance in the palette.
|
|
|
|
*/
|
|
|
|
function cleanUpItemForPalette(aItem, aWrapper)
|
|
|
|
{
|
2002-09-28 19:11:50 +04:00
|
|
|
aWrapper.setAttribute("place", "palette");
|
|
|
|
setWrapperType(aItem, aWrapper);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2002-09-28 19:11:50 +04:00
|
|
|
if (aItem.hasAttribute("title"))
|
|
|
|
aWrapper.setAttribute("title", aItem.getAttribute("title"));
|
2010-06-25 16:20:33 +04:00
|
|
|
else if (aItem.hasAttribute("label"))
|
|
|
|
aWrapper.setAttribute("title", aItem.getAttribute("label"));
|
2002-09-28 19:11:50 +04:00
|
|
|
else if (isSpecialItem(aItem)) {
|
|
|
|
var stringBundle = document.getElementById("stringBundle");
|
2008-12-03 15:35:34 +03:00
|
|
|
// Remove the common "toolbar" prefix to generate the string name.
|
|
|
|
var title = stringBundle.getString(aItem.localName.slice(7) + "Title");
|
2002-09-28 19:11:50 +04:00
|
|
|
aWrapper.setAttribute("title", title);
|
|
|
|
}
|
2011-12-22 03:16:05 +04:00
|
|
|
aWrapper.setAttribute("tooltiptext", aWrapper.getAttribute("title"));
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// Remove attributes that screw up our appearance.
|
|
|
|
aItem.removeAttribute("command");
|
|
|
|
aItem.removeAttribute("observes");
|
|
|
|
aItem.removeAttribute("type");
|
2008-06-16 05:30:16 +04:00
|
|
|
aItem.removeAttribute("width");
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-11-10 02:13:58 +03:00
|
|
|
Array.forEach(aWrapper.querySelectorAll("[disabled]"), function(aNode) {
|
|
|
|
aNode.removeAttribute("disabled");
|
|
|
|
});
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure that an item that has been cloned from a template
|
2008-10-02 10:49:45 +04:00
|
|
|
* is stripped of all properties that may adversely affect its
|
2009-06-22 16:29:55 +04:00
|
|
|
* appearance in the toolbar. Store critical properties on the
|
2002-09-27 08:06:56 +04:00
|
|
|
* wrapper so they can be put back on the item when we're done.
|
|
|
|
*/
|
|
|
|
function cleanupItemForToolbar(aItem, aWrapper)
|
|
|
|
{
|
2002-09-28 19:11:50 +04:00
|
|
|
setWrapperType(aItem, aWrapper);
|
|
|
|
aWrapper.setAttribute("place", "toolbar");
|
2002-09-27 08:06:56 +04:00
|
|
|
|
|
|
|
if (aItem.hasAttribute("command")) {
|
|
|
|
aWrapper.setAttribute("itemcommand", aItem.getAttribute("command"));
|
|
|
|
aItem.removeAttribute("command");
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:26:22 +04:00
|
|
|
if (aItem.checked) {
|
|
|
|
aWrapper.setAttribute("itemchecked", "true");
|
|
|
|
aItem.checked = false;
|
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
if (aItem.disabled) {
|
|
|
|
aWrapper.setAttribute("itemdisabled", "true");
|
|
|
|
aItem.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-05 16:33:00 +04:00
|
|
|
/**
|
|
|
|
* Restore all the properties that we stripped off above.
|
|
|
|
*/
|
|
|
|
function restoreItemForToolbar(aItem, aWrapper)
|
|
|
|
{
|
|
|
|
if (aWrapper.hasAttribute("itemdisabled"))
|
|
|
|
aItem.disabled = true;
|
|
|
|
|
|
|
|
if (aWrapper.hasAttribute("itemchecked"))
|
|
|
|
aItem.checked = true;
|
|
|
|
|
|
|
|
if (aWrapper.hasAttribute("itemcommand")) {
|
|
|
|
let commandID = aWrapper.getAttribute("itemcommand");
|
|
|
|
aItem.setAttribute("command", commandID);
|
|
|
|
|
|
|
|
//XXX Bug 309953 - toolbarbuttons aren't in sync with their commands after customizing
|
|
|
|
let command = gToolboxDocument.getElementById(commandID);
|
|
|
|
if (command && command.hasAttribute("disabled"))
|
|
|
|
aItem.setAttribute("disabled", command.getAttribute("disabled"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 19:11:50 +04:00
|
|
|
function setWrapperType(aItem, aWrapper)
|
|
|
|
{
|
|
|
|
if (aItem.localName == "toolbarseparator") {
|
|
|
|
aWrapper.setAttribute("type", "separator");
|
|
|
|
} else if (aItem.localName == "toolbarspring") {
|
|
|
|
aWrapper.setAttribute("type", "spring");
|
|
|
|
} else if (aItem.localName == "toolbarspacer") {
|
|
|
|
aWrapper.setAttribute("type", "spacer");
|
|
|
|
} else if (aItem.localName == "toolbaritem" && aItem.firstChild) {
|
|
|
|
aWrapper.setAttribute("type", aItem.firstChild.localName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
function setDragActive(aItem, aValue)
|
|
|
|
{
|
|
|
|
var node = aItem;
|
2005-03-04 21:39:12 +03:00
|
|
|
var direction = window.getComputedStyle(aItem, null).direction;
|
|
|
|
var value = direction == "ltr"? "left" : "right";
|
2002-09-27 08:06:56 +04:00
|
|
|
if (aItem.localName == "toolbar") {
|
|
|
|
node = aItem.lastChild;
|
2005-03-04 21:39:12 +03:00
|
|
|
value = direction == "ltr"? "right" : "left";
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
if (!node)
|
|
|
|
return;
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
if (aValue) {
|
|
|
|
if (!node.hasAttribute("dragover"))
|
|
|
|
node.setAttribute("dragover", value);
|
|
|
|
} else {
|
|
|
|
node.removeAttribute("dragover");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNewToolbar()
|
|
|
|
{
|
2014-07-03 03:14:07 +04:00
|
|
|
var promptService = Services.prompt;
|
2002-09-27 08:06:56 +04:00
|
|
|
var stringBundle = document.getElementById("stringBundle");
|
|
|
|
var message = stringBundle.getString("enterToolbarName");
|
|
|
|
var title = stringBundle.getString("enterToolbarTitle");
|
2005-03-05 04:22:30 +03:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
var name = {};
|
2005-03-05 04:22:30 +03:00
|
|
|
|
2008-02-06 09:45:48 +03:00
|
|
|
// Quitting from the toolbar dialog while the new toolbar prompt is up
|
|
|
|
// can cause things to become unresponsive on the Mac. Until dialog modality
|
|
|
|
// is fixed (395465), disable the "Done" button explicitly.
|
|
|
|
var doneButton = document.getElementById("donebutton");
|
|
|
|
doneButton.disabled = true;
|
|
|
|
|
2004-12-01 03:21:43 +03:00
|
|
|
while (true) {
|
2005-03-05 04:22:30 +03:00
|
|
|
|
2008-02-06 09:45:48 +03:00
|
|
|
if (!promptService.prompt(window, title, message, name, null, {})) {
|
|
|
|
doneButton.disabled = false;
|
2002-09-27 08:06:56 +04:00
|
|
|
return;
|
2008-02-06 09:45:48 +03:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2005-03-05 04:22:30 +03:00
|
|
|
if (!name.value) {
|
|
|
|
message = stringBundle.getFormattedString("enterToolbarBlank", [name.value]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-12-01 03:21:43 +03:00
|
|
|
var dupeFound = false;
|
2005-03-05 04:22:30 +03:00
|
|
|
|
2004-12-01 03:21:43 +03:00
|
|
|
// Check for an existing toolbar with the same display name
|
2010-03-22 11:12:32 +03:00
|
|
|
for (let i = 0; i < gToolbox.childNodes.length; ++i) {
|
2004-12-01 03:21:43 +03:00
|
|
|
var toolbar = gToolbox.childNodes[i];
|
|
|
|
var toolbarName = toolbar.getAttribute("toolbarname");
|
2005-03-05 04:22:30 +03:00
|
|
|
|
|
|
|
if (toolbarName == name.value &&
|
|
|
|
toolbar.getAttribute("type") != "menubar" &&
|
|
|
|
toolbar.nodeName == 'toolbar') {
|
2004-12-01 03:21:43 +03:00
|
|
|
dupeFound = true;
|
2002-09-27 08:06:56 +04:00
|
|
|
break;
|
|
|
|
}
|
2005-03-05 04:22:30 +03:00
|
|
|
}
|
2004-12-01 03:21:43 +03:00
|
|
|
|
|
|
|
if (!dupeFound)
|
|
|
|
break;
|
2005-03-05 04:22:30 +03:00
|
|
|
|
|
|
|
message = stringBundle.getFormattedString("enterToolbarDup", [name.value]);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
gToolbox.appendCustomToolbar(name.value, "");
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2008-01-31 02:16:52 +03:00
|
|
|
toolboxChanged();
|
2008-02-06 09:45:48 +03:00
|
|
|
|
|
|
|
doneButton.disabled = false;
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the default set of buttons to fixed toolbars,
|
|
|
|
* remove all custom toolbars, and rebuild the palette.
|
|
|
|
*/
|
|
|
|
function restoreDefaultSet()
|
|
|
|
{
|
2008-12-03 15:35:34 +03:00
|
|
|
// Unwrap the items on the toolbar.
|
|
|
|
unwrapToolbarItems();
|
2004-12-01 03:21:43 +03:00
|
|
|
|
2008-02-07 00:52:29 +03:00
|
|
|
// Remove all of the customized toolbars.
|
|
|
|
var child = gToolbox.lastChild;
|
|
|
|
while (child) {
|
|
|
|
if (child.hasAttribute("customindex")) {
|
|
|
|
var thisChild = child;
|
|
|
|
child = child.previousSibling;
|
2008-12-03 15:35:34 +03:00
|
|
|
thisChild.currentSet = "__empty";
|
2008-02-07 00:52:29 +03:00
|
|
|
gToolbox.removeChild(thisChild);
|
|
|
|
} else {
|
|
|
|
child = child.previousSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// Restore the defaultset for fixed toolbars.
|
2010-03-22 11:12:32 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
|
|
|
var defaultSet = toolbar.getAttribute("defaultset");
|
|
|
|
if (defaultSet)
|
|
|
|
toolbar.currentSet = defaultSet;
|
|
|
|
});
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2006-12-09 06:32:36 +03:00
|
|
|
// Restore the default icon size and mode.
|
2009-09-16 18:14:37 +04:00
|
|
|
document.getElementById("smallicons").checked = (updateIconSize() == "small");
|
|
|
|
document.getElementById("modelist").value = updateToolbarMode();
|
2008-02-07 00:52:29 +03:00
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
// Now rebuild the palette.
|
|
|
|
buildPalette();
|
2002-10-01 23:31:58 +04:00
|
|
|
|
|
|
|
// Now re-wrap the items on the toolbar.
|
|
|
|
wrapToolbarItems();
|
|
|
|
|
2009-01-31 01:05:44 +03:00
|
|
|
toolboxChanged("reset");
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-09-16 18:14:37 +04:00
|
|
|
function updateIconSize(aSize) {
|
2009-12-31 15:48:16 +03:00
|
|
|
return updateToolboxProperty("iconsize", aSize, "large");
|
2009-09-16 18:14:37 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-09-16 18:14:37 +04:00
|
|
|
function updateToolbarMode(aModeValue) {
|
2009-12-31 15:48:16 +03:00
|
|
|
var mode = updateToolboxProperty("mode", aModeValue, "icons");
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-09-16 18:14:37 +04:00
|
|
|
var iconSizeCheckbox = document.getElementById("smallicons");
|
|
|
|
iconSizeCheckbox.disabled = mode == "text";
|
|
|
|
|
|
|
|
return mode;
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-12-31 15:48:16 +03:00
|
|
|
function updateToolboxProperty(aProp, aValue, aToolkitDefault) {
|
|
|
|
var toolboxDefault = gToolbox.getAttribute("default" + aProp) ||
|
|
|
|
aToolkitDefault;
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-09-16 18:14:37 +04:00
|
|
|
gToolbox.setAttribute(aProp, aValue || toolboxDefault);
|
|
|
|
gToolboxDocument.persist(gToolbox.id, aProp);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2010-03-22 11:12:32 +03:00
|
|
|
forEachCustomizableToolbar(function (toolbar) {
|
2009-09-16 18:14:37 +04:00
|
|
|
var toolbarDefault = toolbar.getAttribute("default" + aProp) ||
|
|
|
|
toolboxDefault;
|
|
|
|
if (toolbar.getAttribute("lock" + aProp) == "true" &&
|
|
|
|
toolbar.getAttribute(aProp) == toolbarDefault)
|
|
|
|
return;
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-09-16 18:14:37 +04:00
|
|
|
toolbar.setAttribute(aProp, aValue || toolbarDefault);
|
|
|
|
gToolboxDocument.persist(toolbar.id, aProp);
|
|
|
|
});
|
|
|
|
|
2011-02-04 11:09:04 +03:00
|
|
|
toolboxChanged(aProp);
|
|
|
|
|
2009-12-31 15:48:16 +03:00
|
|
|
return aValue || toolboxDefault;
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2010-03-22 11:12:32 +03:00
|
|
|
function forEachCustomizableToolbar(callback) {
|
|
|
|
Array.filter(gToolbox.childNodes, isCustomizableToolbar).forEach(callback);
|
2010-09-14 01:12:48 +04:00
|
|
|
Array.filter(gToolbox.externalToolbars, isCustomizableToolbar).forEach(callback);
|
2010-03-22 11:12:32 +03:00
|
|
|
}
|
|
|
|
|
2002-09-27 08:06:56 +04:00
|
|
|
function isCustomizableToolbar(aElt)
|
|
|
|
{
|
2002-10-20 12:05:30 +04:00
|
|
|
return aElt.localName == "toolbar" &&
|
2002-09-27 08:06:56 +04:00
|
|
|
aElt.getAttribute("customizable") == "true";
|
|
|
|
}
|
|
|
|
|
2002-09-28 19:11:50 +04:00
|
|
|
function isSpecialItem(aElt)
|
|
|
|
{
|
|
|
|
return aElt.localName == "toolbarseparator" ||
|
|
|
|
aElt.localName == "toolbarspring" ||
|
2007-11-15 06:38:16 +03:00
|
|
|
aElt.localName == "toolbarspacer";
|
2002-09-28 19:11:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function isToolbarItem(aElt)
|
|
|
|
{
|
2002-09-27 08:06:56 +04:00
|
|
|
return aElt.localName == "toolbarbutton" ||
|
|
|
|
aElt.localName == "toolbaritem" ||
|
|
|
|
aElt.localName == "toolbarseparator" ||
|
2002-09-28 19:11:50 +04:00
|
|
|
aElt.localName == "toolbarspring" ||
|
2007-11-15 06:38:16 +03:00
|
|
|
aElt.localName == "toolbarspacer";
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Drag and Drop observers
|
|
|
|
|
2010-12-03 19:19:55 +03:00
|
|
|
function onToolbarDragExit(aEvent)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2014-06-24 18:52:28 +04:00
|
|
|
if (isUnwantedDragEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
if (gCurrentDragOverItem)
|
|
|
|
setDragActive(gCurrentDragOverItem, false);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
function onToolbarDragStart(aEvent)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2009-06-21 04:04:07 +04:00
|
|
|
var item = aEvent.target;
|
2011-06-03 00:59:10 +04:00
|
|
|
while (item && item.localName != "toolbarpaletteitem") {
|
|
|
|
if (item.localName == "toolbar")
|
|
|
|
return;
|
2009-06-21 04:04:07 +04:00
|
|
|
item = item.parentNode;
|
2011-06-03 00:59:10 +04:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
item.setAttribute("dragactive", "true");
|
|
|
|
|
|
|
|
var dt = aEvent.dataTransfer;
|
2011-06-03 00:59:10 +04:00
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
2009-06-21 04:04:07 +04:00
|
|
|
dt.setData("text/toolbarwrapper-id/" + documentId, item.firstChild.id);
|
|
|
|
dt.effectAllowed = "move";
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
function onToolbarDragOver(aEvent)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2014-06-24 18:52:28 +04:00
|
|
|
if (isUnwantedDragEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
2011-11-11 18:39:29 +04:00
|
|
|
if (!aEvent.dataTransfer.types.contains("text/toolbarwrapper-id/" + documentId.toLowerCase()))
|
2009-06-21 04:04:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
var toolbar = aEvent.target;
|
|
|
|
var dropTarget = aEvent.target;
|
|
|
|
while (toolbar && toolbar.localName != "toolbar") {
|
|
|
|
dropTarget = toolbar;
|
|
|
|
toolbar = toolbar.parentNode;
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
// Make sure we are dragging over a customizable toolbar.
|
2010-03-19 10:45:11 +03:00
|
|
|
if (!toolbar || !isCustomizableToolbar(toolbar)) {
|
2009-06-21 04:04:07 +04:00
|
|
|
gCurrentDragOverItem = null;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2010-03-19 10:45:11 +03:00
|
|
|
var previousDragItem = gCurrentDragOverItem;
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
if (dropTarget.localName == "toolbar") {
|
|
|
|
gCurrentDragOverItem = dropTarget;
|
|
|
|
} else {
|
|
|
|
gCurrentDragOverItem = null;
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
var direction = window.getComputedStyle(dropTarget.parentNode, null).direction;
|
|
|
|
var dropTargetCenter = dropTarget.boxObject.x + (dropTarget.boxObject.width / 2);
|
|
|
|
var dragAfter;
|
|
|
|
if (direction == "ltr")
|
|
|
|
dragAfter = aEvent.clientX > dropTargetCenter;
|
|
|
|
else
|
|
|
|
dragAfter = aEvent.clientX < dropTargetCenter;
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
if (dragAfter) {
|
|
|
|
gCurrentDragOverItem = dropTarget.nextSibling;
|
|
|
|
if (!gCurrentDragOverItem)
|
|
|
|
gCurrentDragOverItem = toolbar;
|
|
|
|
} else
|
2002-09-29 05:23:02 +04:00
|
|
|
gCurrentDragOverItem = dropTarget;
|
2009-06-22 16:29:55 +04:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
if (previousDragItem && gCurrentDragOverItem != previousDragItem) {
|
|
|
|
setDragActive(previousDragItem, false);
|
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
setDragActive(gCurrentDragOverItem, true);
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
aEvent.preventDefault();
|
2010-04-27 20:57:19 +04:00
|
|
|
aEvent.stopPropagation();
|
2009-06-21 04:04:07 +04:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
function onToolbarDrop(aEvent)
|
|
|
|
{
|
2014-06-24 18:52:28 +04:00
|
|
|
if (isUnwantedDragEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
if (!gCurrentDragOverItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setDragActive(gCurrentDragOverItem, false);
|
|
|
|
|
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
|
|
|
var draggedItemId = aEvent.dataTransfer.getData("text/toolbarwrapper-id/" + documentId);
|
|
|
|
if (gCurrentDragOverItem.id == draggedItemId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var toolbar = aEvent.target;
|
|
|
|
while (toolbar.localName != "toolbar")
|
|
|
|
toolbar = toolbar.parentNode;
|
|
|
|
|
2009-06-22 16:29:55 +04:00
|
|
|
var draggedPaletteWrapper = document.getElementById("wrapper-"+draggedItemId);
|
2009-06-21 04:04:07 +04:00
|
|
|
if (!draggedPaletteWrapper) {
|
|
|
|
// The wrapper has been dragged from the toolbar.
|
|
|
|
// Get the wrapper from the toolbar document and make sure that
|
|
|
|
// it isn't being dropped on itself.
|
2016-02-04 00:12:18 +03:00
|
|
|
let wrapper = gToolboxDocument.getElementById("wrapper-"+draggedItemId);
|
2009-06-21 04:04:07 +04:00
|
|
|
if (wrapper == gCurrentDragOverItem)
|
|
|
|
return;
|
|
|
|
|
2010-02-23 21:16:16 +03:00
|
|
|
// Don't allow non-removable kids (e.g., the menubar) to move.
|
|
|
|
if (wrapper.firstChild.getAttribute("removable") != "true")
|
2009-06-21 04:04:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove the item from its place in the toolbar.
|
|
|
|
wrapper.parentNode.removeChild(wrapper);
|
|
|
|
|
|
|
|
// Determine which toolbar we are dropping on.
|
|
|
|
var dropToolbar = null;
|
|
|
|
if (gCurrentDragOverItem.localName == "toolbar")
|
|
|
|
dropToolbar = gCurrentDragOverItem;
|
|
|
|
else
|
|
|
|
dropToolbar = gCurrentDragOverItem.parentNode;
|
|
|
|
|
|
|
|
// Insert the item into the toolbar.
|
|
|
|
if (gCurrentDragOverItem != dropToolbar)
|
|
|
|
dropToolbar.insertBefore(wrapper, gCurrentDragOverItem);
|
|
|
|
else
|
|
|
|
dropToolbar.appendChild(wrapper);
|
|
|
|
} else {
|
|
|
|
// The item has been dragged from the palette
|
|
|
|
|
|
|
|
// Create a new wrapper for the item. We don't know the id yet.
|
2016-02-04 00:12:18 +03:00
|
|
|
let wrapper = createWrapper("", gToolboxDocument);
|
2009-06-21 04:04:07 +04:00
|
|
|
|
|
|
|
// Ask the toolbar to clone the item's template, place it inside the wrapper, and insert it in the toolbar.
|
|
|
|
var newItem = toolbar.insertItem(draggedItemId, gCurrentDragOverItem == toolbar ? null : gCurrentDragOverItem, wrapper);
|
|
|
|
|
|
|
|
// Prepare the item and wrapper to look good on the toolbar.
|
|
|
|
cleanupItemForToolbar(newItem, wrapper);
|
|
|
|
wrapper.id = "wrapper-"+newItem.id;
|
|
|
|
wrapper.flex = newItem.flex;
|
|
|
|
|
|
|
|
// Remove the wrapper from the palette.
|
|
|
|
if (draggedItemId != "separator" &&
|
|
|
|
draggedItemId != "spring" &&
|
|
|
|
draggedItemId != "spacer")
|
2011-12-22 03:16:05 +04:00
|
|
|
gPaletteBox.removeChild(draggedPaletteWrapper);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
gCurrentDragOverItem = null;
|
2009-06-22 16:29:55 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
toolboxChanged();
|
2016-02-04 04:27:36 +03:00
|
|
|
}
|
2002-09-27 08:06:56 +04:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
function onPaletteDragOver(aEvent)
|
2002-09-27 08:06:56 +04:00
|
|
|
{
|
2014-06-24 18:52:28 +04:00
|
|
|
if (isUnwantedDragEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-21 04:04:07 +04:00
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
2011-11-11 18:39:29 +04:00
|
|
|
if (aEvent.dataTransfer.types.contains("text/toolbarwrapper-id/" + documentId.toLowerCase()))
|
2009-06-21 04:04:07 +04:00
|
|
|
aEvent.preventDefault();
|
|
|
|
}
|
2008-12-03 15:35:34 +03:00
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
function onPaletteDrop(aEvent)
|
2014-06-24 18:52:28 +04:00
|
|
|
{
|
|
|
|
if (isUnwantedDragEvent(aEvent)) {
|
|
|
|
return;
|
|
|
|
}
|
2009-06-21 04:04:07 +04:00
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
|
|
|
var itemId = aEvent.dataTransfer.getData("text/toolbarwrapper-id/" + documentId);
|
|
|
|
|
|
|
|
var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId);
|
|
|
|
if (wrapper) {
|
2010-02-23 21:16:16 +03:00
|
|
|
// Don't allow non-removable kids (e.g., the menubar) to move.
|
|
|
|
if (wrapper.firstChild.getAttribute("removable") != "true")
|
2009-06-21 04:04:07 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
var wrapperType = wrapper.getAttribute("type");
|
|
|
|
if (wrapperType != "separator" &&
|
|
|
|
wrapperType != "spacer" &&
|
|
|
|
wrapperType != "spring") {
|
2010-08-05 16:33:00 +04:00
|
|
|
restoreItemForToolbar(wrapper.firstChild, wrapper);
|
2011-12-22 03:16:05 +04:00
|
|
|
wrapPaletteItem(document.importNode(wrapper.firstChild, true));
|
2009-06-21 04:04:07 +04:00
|
|
|
gToolbox.palette.appendChild(wrapper.firstChild);
|
2002-09-27 08:06:56 +04:00
|
|
|
}
|
|
|
|
|
2009-06-21 04:04:07 +04:00
|
|
|
// The item was dragged out of the toolbar.
|
|
|
|
wrapper.parentNode.removeChild(wrapper);
|
2009-06-22 16:29:55 +04:00
|
|
|
}
|
2009-06-21 04:04:07 +04:00
|
|
|
|
|
|
|
toolboxChanged();
|
|
|
|
}
|
2014-06-24 18:52:28 +04:00
|
|
|
|
|
|
|
|
|
|
|
function isUnwantedDragEvent(aEvent) {
|
2014-07-03 03:14:07 +04:00
|
|
|
try {
|
|
|
|
if (Services.prefs.getBoolPref("toolkit.customization.unsafe_drag_events")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
|
2014-06-24 18:52:28 +04:00
|
|
|
/* Discard drag events that originated from a separate window to
|
|
|
|
prevent content->chrome privilege escalations. */
|
|
|
|
let mozSourceNode = aEvent.dataTransfer.mozSourceNode;
|
|
|
|
// mozSourceNode is null in the dragStart event handler or if
|
|
|
|
// the drag event originated in an external application.
|
|
|
|
if (!mozSourceNode) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
let sourceWindow = mozSourceNode.ownerDocument.defaultView;
|
|
|
|
return sourceWindow != window && sourceWindow != gToolboxDocument.defaultView;
|
|
|
|
}
|
|
|
|
|